Skip to content

Commit

Permalink
Use legacy mode for external storage access
Browse files Browse the repository at this point in the history
Android 10 (api 29) deprecates the external storage methods, and instead
recommend using the getExternalDir methods to store app-specific files.
However for backups this is not good enought since these files are
removed when the application is uninstalled.

The legacy option lets the app use the previous API while a better
solution is found. Note that with Android 11 (R) which is not yet
released, this flag will not work.

A possible solution could be to use the Shared storage with the
MediaStore.Files API, however this would requires additionals
permissions: MANAGE_EXTERNAL_STORAGE +
ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION
  • Loading branch information
dpad85 committed Apr 15, 2020
1 parent f2165d5 commit f58af64
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
android:name=".App"
android:allowBackup="false"
android:fullBackupContent="false"
android:requestLegacyExternalStorage="true"
android:icon="@mipmap/ic_launcher_testnet"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package fr.acinq.eclair.wallet.activities;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Handler;

Expand All @@ -29,16 +28,11 @@
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.tasks.Task;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.Drive;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -59,7 +53,7 @@ public abstract class ChannelsBackupBaseActivity extends EclairActivity {
* - If the value is None, the source's access status is pending.
* - If the value is Some(true), access is granted.
* - If the value is Some(false), access is denied.
*
* <p>
* Value should never be null.
*/
protected Map<BackupTypes, Option<Boolean>> accessRequestsMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ static boolean isExternalStorageWritable() {
}

static boolean hasLocalAccess(final Context context) {
return ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
return ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& isExternalStorageWritable()
&& Environment.getExternalStorageDirectory().canWrite();
}

static File getBackupFile(final String backupFileName) throws EclairException.ExternalStorageUnavailableException {
Expand Down

0 comments on commit f58af64

Please sign in to comment.