android: move wallet data to internal storage.
This commit is contained in:
parent
671fe73788
commit
4c7bbb4e86
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
47
lib/util.py
47
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
|
||||
|
|
Loading…
Reference in New Issue