@ -354,41 +354,11 @@ def profiler(func):
return lambda * args , * * kw_args : do_profile ( args , kw_args )
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 ( ) :
def android_data_dir ( ) :
import jnius
import jnius
PythonActivity = jnius . autoclass ( ' org.kivy.android.PythonActivity ' )
PythonActivity = jnius . autoclass ( ' org.kivy.android.PythonActivity ' )
return PythonActivity . mActivity . getFilesDir ( ) . getPath ( ) + ' /data '
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 ) :
def ensure_sparse_file ( filename ) :
# On modern Linux, no need to do anything.
# On modern Linux, no need to do anything.
@ -401,7 +371,7 @@ def ensure_sparse_file(filename):
def get_headers_dir ( config ) :
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 ) :
def assert_datadir_available ( config_path ) :
@ -484,7 +454,7 @@ def bh2u(x: bytes) -> str:
def user_dir ( ) :
def user_dir ( ) :
if ' ANDROID_DATA ' in os . environ :
if ' ANDROID_DATA ' in os . environ :
return android_check_ data_dir ( )
return android_data_dir ( )
elif os . name == ' posix ' :
elif os . name == ' posix ' :
return os . path . join ( os . environ [ " HOME " ] , " .electrum " )
return os . path . join ( os . environ [ " HOME " ] , " .electrum " )
elif " APPDATA " in os . environ :
elif " APPDATA " in os . environ :