From b0dc2dd4f574678d2beb87f2e0732a039f288179 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 26 Aug 2019 09:39:13 +0200 Subject: [PATCH] Use no backup android & ios Signed-off-by: Andrea Maria Piana --- .../status/ethereum/module/StatusModule.java | 50 ++++--------------- .../ios/RCTStatus/RCTStatus.m | 10 ++-- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java index 28ac61864d..1ea52b1deb 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusModule.java @@ -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() { diff --git a/modules/react-native-status/ios/RCTStatus/RCTStatus.m b/modules/react-native-status/ios/RCTStatus/RCTStatus.m index dddb7fe644..9cd5d59110 100644 --- a/modules/react-native-status/ios/RCTStatus/RCTStatus.m +++ b/modules/react-native-status/ios/RCTStatus/RCTStatus.m @@ -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"];