From b21064f16f49b554c64a7c2e9fc895f686f863f9 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 26 Nov 2018 17:52:30 +0100 Subject: [PATCH] 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. --- electrum/gui/kivy/tools/buildozer.spec | 2 +- electrum/util.py | 34 ++------------------------ 2 files changed, 3 insertions(+), 33 deletions(-) diff --git a/electrum/gui/kivy/tools/buildozer.spec b/electrum/gui/kivy/tools/buildozer.spec index 5b8dfb11c..dca6daab8 100644 --- a/electrum/gui/kivy/tools/buildozer.spec +++ b/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 diff --git a/electrum/util.py b/electrum/util.py index 92526980f..9a0e81d2c 100644 --- a/electrum/util.py +++ b/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: