electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 4c7bbb4e865aaf533d4c37d967771e0ac2ca6ede
parent 671fe7378888117b6ade0a941a8bba2779702999
Author: ThomasV <thomasv@electrum.org>
Date:   Tue,  8 Mar 2016 04:55:28 +0100

android: move wallet data to internal storage.

Diffstat:
Mgui/kivy/Readme.txt | 5+++++
Mlib/blockchain.py | 2+-
Mlib/util.py | 47+++++++++++++++++++++++++++++++++++++++--------
3 files changed, 45 insertions(+), 9 deletions(-)

diff --git a/gui/kivy/Readme.txt b/gui/kivy/Readme.txt @@ -11,3 +11,8 @@ If something in included modules like kivy or any other module changes then you need to rebuild the distribution. To do so: `rm -rf electrum/.buildozer/android/platform/python-for-android/dist` + + +Note: + python-for-android must be patched with: + git pull git@github.com:denys-duchier/python-for-android.git fix-recursive-delete diff --git a/lib/blockchain.py b/lib/blockchain.py @@ -102,7 +102,7 @@ class Blockchain(util.PrintError): return hash_encode(Hash(self.serialize_header(header).decode('hex'))) def path(self): - return os.path.join(self.config.path, 'blockchain_headers') + return util.get_headers_path(self.config) def init_headers_file(self): filename = self.path() diff --git a/lib/util.py b/lib/util.py @@ -196,6 +196,44 @@ def profiler(func): return lambda *args, **kw_args: do_profile(func, 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.renpy.android.PythonActivity') + return PythonActivity.mActivity.getFilesDir().getPath() + '/data' + +def android_headers_path(): + path = android_ext_dir() + '/org.electrum.electrum/blockchain_headers' + d = os.path.dirname(path) + if not os.path.exists(d): + os.mkdir(d) + return path + +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_path() + 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 get_headers_path(config): + if 'ANDROID_DATA' in os.environ: + return android_headers_path() + else: + return os.path.join(config.path, 'blockchain_headers') def user_dir(): if "HOME" in os.environ: @@ -205,14 +243,7 @@ def user_dir(): elif "LOCALAPPDATA" in os.environ: return os.path.join(os.environ["LOCALAPPDATA"], "Electrum") elif 'ANDROID_DATA' in os.environ: - try: - import jnius - env = jnius.autoclass('android.os.Environment') - _dir = env.getExternalStorageDirectory().getPath() - return _dir + '/electrum/' - except ImportError: - pass - return "/sdcard/electrum/" + return android_check_data_dir() else: #raise Exception("No home directory found in environment variables.") return