Use no backup android & ios

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2019-08-26 09:39:13 +02:00
parent 4c545cb70d
commit b0dc2dd4f5
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
2 changed files with 14 additions and 46 deletions

View File

@ -114,6 +114,10 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
public String getNoBackupDirectory() {
return this.getReactApplicationContext().getNoBackupFilesDir().getAbsolutePath();
}
public void handleSignal(String jsonEvent) {
Log.d(TAG, "Signal event: " + jsonEvent);
WritableMap params = Arguments.createMap();
@ -201,7 +205,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Activity currentActivity = getCurrentActivity();
final String absRootDirPath = currentActivity.getApplicationInfo().dataDir;
final String absRootDirPath = this.getNoBackupDirectory();
final String dataFolder = this.getTestnetDataDir(absRootDirPath);
Log.d(TAG, "Starting Geth node in folder: " + dataFolder);
@ -312,16 +316,6 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
}
private String getOldExternalDir() {
File extStore = Environment.getExternalStorageDirectory();
return extStore.exists() ? pathCombine(extStore.getAbsolutePath(), "ethereum/testnet") : getNewInternalDir();
}
private String getNewInternalDir() {
Activity currentActivity = getCurrentActivity();
return pathCombine(currentActivity.getApplicationInfo().dataDir, "ethereum/testnet");
}
private void deleteDirectory(File folder) {
File[] files = folder.listFiles();
if (files != null) {
@ -365,40 +359,14 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
}
}
@ReactMethod
public void shouldMoveToInternalStorage(Callback callback) {
String oldDir = getOldExternalDir();
String newDir = getNewInternalDir();
File oldDirFile = new File(oldDir);
File newDirFile = new File(newDir);
callback.invoke(oldDirFile.exists() && !newDirFile.exists());
}
@ReactMethod
public void moveToInternalStorage(Callback callback) {
String oldDir = getOldExternalDir();
String newDir = getNewInternalDir();
try {
File oldDirFile = new File(oldDir);
copyDirectory(oldDirFile, new File(newDir));
deleteDirectory(oldDirFile);
} catch (IOException e) {
Log.d(TAG, "Moving error: " + e);
}
callback.invoke();
}
@ReactMethod
private void initKeystore() {
Log.d(TAG, "initKeystore");
Activity currentActivity = getCurrentActivity();
final String keydir = pathCombine(currentActivity.getApplicationInfo().dataDir, "/keystore");
final String keydir = pathCombine(this.getNoBackupDirectory(), "/keystore");
if (!checkAvailability()) {
Log.e(TAG, "[initKeystore] Activity doesn't exist, cannot init keystore");
System.exit(0);
@ -419,7 +387,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
private void openAccounts(final Callback callback) {
Activity currentActivity = getCurrentActivity();
final String rootDir = currentActivity.getApplicationInfo().dataDir;
final String rootDir = this.getNoBackupDirectory();
Log.d(TAG, "openAccounts");
if (!checkAvailability()) {
Log.e(TAG, "[openAccounts] Activity doesn't exist, cannot call openAccounts");
@ -448,7 +416,7 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
Activity currentActivity = getCurrentActivity();
final String absRootDirPath = currentActivity.getApplicationInfo().dataDir;
final String absRootDirPath = this.getNoBackupDirectory();
final String newKeystoreDir = pathCombine(absRootDirPath, "keystore");
Runnable r = new Runnable() {

View File

@ -116,7 +116,7 @@ RCT_EXPORT_METHOD(initKeystore) {
#endif
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
lastObject];
NSURL *keystoreDir = [rootUrl URLByAppendingPathComponent:@"keystore"];
@ -166,7 +166,7 @@ RCT_EXPORT_METHOD(sendLogs:(NSString *)dbJson
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
lastObject];
NSURL *zipFile = [rootUrl URLByAppendingPathComponent:@"logs.zip"];
@ -326,7 +326,7 @@ RCT_EXPORT_METHOD(multiAccountDeriveAddresses:(NSString *)json
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error = nil;
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
lastObject];
NSURL *absTestnetFolderName = [rootUrl URLByAppendingPathComponent:@"ethereum/testnet"];
@ -444,7 +444,7 @@ RCT_EXPORT_METHOD(openAccounts:(RCTResponseSenderBlock)callback) {
#endif
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
lastObject];
NSString *result = StatusgoOpenAccounts(rootUrl.path);
@ -460,7 +460,7 @@ RCT_EXPORT_METHOD(verify:(NSString *)address
#endif
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *rootUrl =[[fileManager
URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask]
URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]
lastObject];
NSURL *absKeystoreUrl = [rootUrl URLByAppendingPathComponent:@"keystore"];