mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 08:58:30 +03:00
Fix edge case when app is restored during backup and storage path does not exist
Fix #4151 Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
96e9ae7f77
commit
975841735b
4 changed files with 49 additions and 2 deletions
|
@ -329,9 +329,14 @@ public interface AppPreferences {
|
|||
|
||||
void setStoragePath(String path);
|
||||
|
||||
void setStoragePathValid();
|
||||
|
||||
boolean isStoragePathValid();
|
||||
|
||||
void removeKeysMigrationPreference();
|
||||
|
||||
String getCurrentAccountName();
|
||||
|
||||
void setCurrentAccountName(String accountName);
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
*/
|
||||
public static final String AUTO_PREF__LAST_SEEN_VERSION_CODE = "lastSeenVersionCode";
|
||||
public static final String STORAGE_PATH = "storage_path";
|
||||
public static final String STORAGE_PATH_VALID = "storage_path_valid";
|
||||
public static final String PREF__DARK_THEME = "dark_theme_mode";
|
||||
public static final float DEFAULT_GRID_COLUMN = 3f;
|
||||
|
||||
|
@ -526,6 +527,17 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
preferences.edit().putString(STORAGE_PATH, path).commit(); // commit synchronously
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
@Override
|
||||
public void setStoragePathValid() {
|
||||
preferences.edit().putBoolean(STORAGE_PATH_VALID, true).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStoragePathValid() {
|
||||
return preferences.getBoolean(STORAGE_PATH_VALID, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes keys migration key from shared preferences.
|
||||
*/
|
||||
|
|
|
@ -40,6 +40,7 @@ import android.content.pm.PackageManager;
|
|||
import android.content.res.Resources.NotFoundException;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
|
@ -48,6 +49,7 @@ import android.view.MenuInflater;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
@ -272,7 +274,7 @@ public class FileDisplayActivity extends FileActivity
|
|||
if (taskRetainerFragment == null) {
|
||||
taskRetainerFragment = new TaskRetainerFragment();
|
||||
fm.beginTransaction()
|
||||
.add(taskRetainerFragment, TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT).commit();
|
||||
.add(taskRetainerFragment, TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT).commit();
|
||||
} // else, Fragment already created and retained across configuration change
|
||||
|
||||
if (Intent.ACTION_VIEW.equals(getIntent().getAction())) {
|
||||
|
@ -280,6 +282,30 @@ public class FileDisplayActivity extends FileActivity
|
|||
}
|
||||
|
||||
mPlayerConnection = new PlayerServiceConnection(this);
|
||||
|
||||
checkStoragePath();
|
||||
}
|
||||
|
||||
private void checkStoragePath() {
|
||||
String newStorage = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
String storagePath = preferences.getStoragePath(newStorage);
|
||||
if (!preferences.isStoragePathValid() && !new File(storagePath).exists()) {
|
||||
// falling back to default
|
||||
preferences.setStoragePath(newStorage);
|
||||
preferences.setStoragePathValid();
|
||||
MainApp.setStoragePath(newStorage);
|
||||
|
||||
try {
|
||||
new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog)
|
||||
.setTitle(R.string.wrong_storage_path)
|
||||
.setMessage(R.string.wrong_storage_path_desc)
|
||||
.setNegativeButton(R.string.dialog_close, (dialog, which) -> dialog.dismiss())
|
||||
.setIcon(R.drawable.ic_settings)
|
||||
.show();
|
||||
} catch (WindowManager.BadTokenException e) {
|
||||
Log_OC.e(TAG, "Error showing wrong storage info, so skipping it: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -290,7 +316,7 @@ public class FileDisplayActivity extends FileActivity
|
|||
if (!PermissionUtil.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// Check if we should show an explanation
|
||||
if (PermissionUtil.shouldShowRequestPermissionRationale(this,
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
||||
// Show explanation to the user and then request permission
|
||||
Snackbar snackbar = Snackbar.make(binding.rootLayout,
|
||||
R.string.permission_storage_access,
|
||||
|
|
|
@ -948,4 +948,8 @@
|
|||
<string name="player_toggle">toggle</string>
|
||||
<string name="in_folder">in folder %1$s</string>
|
||||
<string name="choose_which_file">Choose which file to keep!</string>
|
||||
<string name="wrong_storage_path">Storage path does not exist!</string>
|
||||
<string name="wrong_storage_path_desc">This might be due to a backup restore on another device. Falling back to
|
||||
default. Please check settings to adjust storage path.</string>
|
||||
<string name="dialog_close">Close</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue