Browse Source

Try to fix it

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
91c429bf20

+ 19 - 2
src/main/java/com/owncloud/android/MainApp.java

@@ -33,11 +33,13 @@ import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Environment;
 import android.os.StrictMode;
 import android.support.annotation.StringRes;
 import android.support.multidex.MultiDexApplication;
 import android.support.v4.util.Pair;
 import android.support.v7.app.AlertDialog;
+import android.text.TextUtils;
 import android.view.WindowManager;
 
 import com.evernote.android.job.JobManager;
@@ -99,6 +101,7 @@ public class MainApp extends MultiDexApplication {
 
     private static boolean mOnlyOnDevice = false;
 
+    private SharedPreferences appPrefs;
     @SuppressWarnings("unused")
     private boolean mBound;
 
@@ -112,8 +115,10 @@ public class MainApp extends MultiDexApplication {
             AnalyticsUtils.disableAnalytics();
         }
 
-        SharedPreferences appPrefs =
-                PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+        appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+
+        fixStoragePath();
+
         MainApp.storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH,
                 getApplicationContext().getFilesDir().getAbsolutePath());
 
@@ -208,6 +213,18 @@ public class MainApp extends MultiDexApplication {
 
     }
 
+    private void fixStoragePath() {
+        if (!PreferenceManager.getStoragePathFix(this)) {
+            String storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH, "");
+            if (TextUtils.isEmpty(storagePath)) {
+                storagePath = Environment.getExternalStorageDirectory().getAbsolutePath();
+                appPrefs.edit().putString(Preferences.PreferenceKeys.STORAGE_PATH, storagePath).commit();
+                appPrefs.edit().remove(PreferenceManager.PREF__KEYS_MIGRATION).commit();
+            }
+            PreferenceManager.setStoragePathFix(this, true);
+        }
+    }
+
     public static void initAutoUpload() {
         updateToAutoUpload();
         cleanOldEntries();

+ 10 - 1
src/main/java/com/owncloud/android/db/PreferenceManager.java

@@ -53,7 +53,8 @@ public abstract class PreferenceManager {
     private static final String PREF__INSTANT_VIDEO_UPLOAD_PATH_USE_SUBFOLDERS
             = "instant_video_upload_path_use_subfolders";
     private static final String PREF__LEGACY_CLEAN = "legacyClean";
-    private static final String PREF__KEYS_MIGRATION = "keysMigration";
+    public static final String PREF__KEYS_MIGRATION = "keysMigration";
+    private static final String PREF__FIX_STORAGE_PATH = "storagePathFix";
     private static final String PREF__AUTO_UPLOAD_UPDATE_PATH = "autoUploadPathUpdate";
     private static final String PREF__PUSH_TOKEN = "pushToken";
     private static final String PREF__AUTO_UPLOAD_SPLIT_OUT = "autoUploadEntriesSplitOut";
@@ -291,6 +292,10 @@ public abstract class PreferenceManager {
         return getDefaultSharedPreferences(context).getBoolean(PREF__KEYS_MIGRATION, false);
     }
 
+    public static boolean getStoragePathFix(Context context) {
+        return getDefaultSharedPreferences(context).getBoolean(PREF__FIX_STORAGE_PATH, false);
+    }
+
 
     /**
      * Gets the auto upload paths flag last set.
@@ -326,6 +331,10 @@ public abstract class PreferenceManager {
         saveBooleanPreference(context, PREF__KEYS_MIGRATION, keysMigration);
     }
 
+    public static void setStoragePathFix(Context context, boolean storagePathFix) {
+        saveBooleanPreference(context, PREF__FIX_STORAGE_PATH, storagePathFix);
+    }
+
     public static void setAutoUploadInit(Context context, boolean autoUploadInit) {
         saveBooleanPreference(context, PREF__AUTO_UPLOAD_INIT, autoUploadInit);
     }