2019-01-30 00:59:07 +01:00
|
|
|
import keyring
|
2019-01-31 00:55:37 +01:00
|
|
|
import logging
|
2017-08-13 03:24:00 +02:00
|
|
|
import platform
|
2018-10-28 19:12:40 +01:00
|
|
|
from jnius import autoclass
|
2019-01-30 00:59:07 +01:00
|
|
|
from keyring.backend import KeyringBackend
|
|
|
|
from lbrynet import build_type
|
|
|
|
from lbrynet.extras.cli import conf, log_support, check_connection, Daemon, reactor
|
|
|
|
from lbrynet.extras.daemon.Components import DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT
|
|
|
|
from lbrynet.extras.daemon.Components import REFLECTOR_COMPONENT
|
2017-08-22 23:03:05 +02:00
|
|
|
|
2017-08-25 05:59:35 +02:00
|
|
|
|
2019-01-30 00:59:07 +01:00
|
|
|
lbrynet_android_utils = autoclass('io.lbry.browser.Utils')
|
|
|
|
service = autoclass('io.lbry.browser.LbrynetService').serviceInstance
|
|
|
|
platform.platform = lambda: 'Android %s (API %s)' % (lbrynet_android_utils.getAndroidRelease(), lbrynet_android_utils.getAndroidSdk())
|
|
|
|
build_type.BUILD = 'dev' if lbrynet_android_utils.isDebug() else 'release'
|
2019-01-31 00:55:37 +01:00
|
|
|
log = logging.getLogger(__name__)
|
2017-08-25 05:59:35 +02:00
|
|
|
|
2017-12-20 17:10:30 +01:00
|
|
|
# Keyring backend
|
2019-01-30 00:59:07 +01:00
|
|
|
class LbryAndroidKeyring(KeyringBackend):
|
2017-12-20 17:10:30 +01:00
|
|
|
priority = 1
|
|
|
|
|
2019-01-30 00:59:07 +01:00
|
|
|
def __init__(self):
|
|
|
|
self._keystore = lbrynet_android_utils.initKeyStore(service.getApplicationContext())
|
|
|
|
|
2017-12-20 17:10:30 +01:00
|
|
|
def set_password(self, servicename, username, password):
|
|
|
|
context = service.getApplicationContext()
|
2019-01-30 00:59:07 +01:00
|
|
|
lbrynet_android_utils.setPassword(servicename, username, password, context, self._keystore)
|
2017-12-20 17:10:30 +01:00
|
|
|
|
|
|
|
def get_password(self, servicename, username):
|
|
|
|
context = service.getApplicationContext()
|
2019-01-30 00:59:07 +01:00
|
|
|
return lbrynet_android_utils.getPassword(servicename, username, context, self._keystore)
|
2017-12-20 17:10:30 +01:00
|
|
|
|
|
|
|
def delete_password(self, servicename, username):
|
|
|
|
context = service.getApplicationContext()
|
2019-01-30 00:59:07 +01:00
|
|
|
lbrynet_android_utils.deletePassword(servicename, username, context, self._keystore)
|
2017-12-20 17:10:30 +01:00
|
|
|
|
2017-08-13 03:24:00 +02:00
|
|
|
|
|
|
|
def start():
|
2019-01-30 00:59:07 +01:00
|
|
|
keyring.set_keyring(LbryAndroidKeyring())
|
|
|
|
|
|
|
|
private_storage_dir = lbrynet_android_utils.getAppInternalStorageDir(service.getApplicationContext())
|
|
|
|
conf.initialize_settings(
|
|
|
|
data_dir=f'{private_storage_dir}/lbrynet',
|
|
|
|
wallet_dir=f'{private_storage_dir}/lbryum',
|
2019-01-30 19:27:29 +01:00
|
|
|
download_dir=f'{lbrynet_android_utils.getInternalStorageDir(service.getApplicationContext())}/Download'
|
2019-01-30 00:59:07 +01:00
|
|
|
)
|
2018-08-13 08:12:13 +02:00
|
|
|
conf.settings.update({
|
2019-01-30 00:59:07 +01:00
|
|
|
'components_to_skip': [
|
|
|
|
DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT,
|
|
|
|
REFLECTOR_COMPONENT
|
|
|
|
],
|
|
|
|
'use_upnp': False,
|
|
|
|
# 'use_https': True, # TODO: does this work on android?
|
|
|
|
# 'use_auth_http': True
|
2018-08-13 08:12:13 +02:00
|
|
|
})
|
|
|
|
|
2019-01-30 00:59:07 +01:00
|
|
|
log_support.configure_logging(conf.settings.get_log_filename(), True, [])
|
|
|
|
log_support.configure_loggly_handler()
|
2017-08-13 03:24:00 +02:00
|
|
|
|
2019-01-31 00:55:37 +01:00
|
|
|
log.info('Final Settings: %s', conf.settings.get_current_settings_dict())
|
|
|
|
log.info('Starting lbrynet-daemon');
|
|
|
|
|
2019-01-30 00:59:07 +01:00
|
|
|
if check_connection():
|
2018-08-13 08:12:13 +02:00
|
|
|
daemon = Daemon()
|
|
|
|
daemon.start_listening()
|
2017-08-13 03:24:00 +02:00
|
|
|
reactor.run()
|
|
|
|
else:
|
2019-01-30 00:59:07 +01:00
|
|
|
print("Not connected to internet, unable to start")
|
2017-08-22 23:03:05 +02:00
|
|
|
|
2017-08-13 03:24:00 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
start()
|