Browse Source

android: don't use external storage

so that we don't need the extra permission.
also because phones these days have enough internal storage for
the headers; and maybe it's better even for security reasons to
store it there.
no upgrade path is provided for the headers stored on external storage,
we will litter the filesystem and leave them there. they will be
downloaded again into internal storage.
3.3.3.1
SomberNight 6 years ago
parent
commit
b21064f16f
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/gui/kivy/tools/buildozer.spec
  2. 34
      electrum/util.py

2
electrum/gui/kivy/tools/buildozer.spec

@ -52,7 +52,7 @@ fullscreen = False
#
# (list) Permissions
android.permissions = INTERNET, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE, CAMERA
android.permissions = INTERNET, CAMERA
# (int) Android API to use
android.api = 28

34
electrum/util.py

@ -354,41 +354,11 @@ def profiler(func):
return lambda *args, **kw_args: do_profile(args, kw_args)
def android_ext_dir():
import jnius
env = jnius.autoclass('android.os.Environment')
return env.getExternalStorageDirectory().getPath()
def android_data_dir():
import jnius
PythonActivity = jnius.autoclass('org.kivy.android.PythonActivity')
return PythonActivity.mActivity.getFilesDir().getPath() + '/data'
def android_headers_dir():
d = android_ext_dir() + '/org.electrum.electrum'
if not os.path.exists(d):
try:
os.mkdir(d)
except FileExistsError:
pass # in case of race
return d
def android_check_data_dir():
""" if needed, move old directory to sandbox """
ext_dir = android_ext_dir()
data_dir = android_data_dir()
old_electrum_dir = ext_dir + '/electrum'
if not os.path.exists(data_dir) and os.path.exists(old_electrum_dir):
import shutil
new_headers_path = android_headers_dir() + '/blockchain_headers'
old_headers_path = old_electrum_dir + '/blockchain_headers'
if not os.path.exists(new_headers_path) and os.path.exists(old_headers_path):
print_error("Moving headers file to", new_headers_path)
shutil.move(old_headers_path, new_headers_path)
print_error("Moving data to", data_dir)
shutil.move(old_electrum_dir, data_dir)
return data_dir
def ensure_sparse_file(filename):
# On modern Linux, no need to do anything.
@ -401,7 +371,7 @@ def ensure_sparse_file(filename):
def get_headers_dir(config):
return android_headers_dir() if 'ANDROID_DATA' in os.environ else config.path
return config.path
def assert_datadir_available(config_path):
@ -484,7 +454,7 @@ def bh2u(x: bytes) -> str:
def user_dir():
if 'ANDROID_DATA' in os.environ:
return android_check_data_dir()
return android_data_dir()
elif os.name == 'posix':
return os.path.join(os.environ["HOME"], ".electrum")
elif "APPDATA" in os.environ:

Loading…
Cancel
Save