summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2021-04-09 11:24:16 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2021-04-12 07:32:27 +0200
commitdeeb5854c0eba2d81a5dce6be8b8fcb56fa968b5 (patch)
tree18378bd8c7860fabbf58160141d8b670e44dc0c6
parent34cb883d525e2f6f18d6c68f97dfdb2c8e214e33 (diff)
android: Request PERMISSION_WRITE_EXTERNAL_STORAGE again
Requesting the permission on app start had been dropped in commit a23bd42e9b2f6401c710ac95afcc3aa8f360d65c Date: Tue Apr 6 14:26:06 2021 +0200 android: Drop custom file abstraction + UI Since the app now uses the Android Storage Access Framework [1] in order to open or create files from within the app, it not longer needs PERMISSION_WRITE_EXTERNAL_STORAGE for this. However, at least PDF export currently still directly writes to local storage ("Documents" directory), which fails without that permission being granted. In addition, opening files passed with a 'file://' URI in an 'Intent.ACTION_VIEW' also did not work anymore. I'm not sure whether this use case is particularly relevant in practice, though; at least all of the (few) apps I used during testing passed 'content://' URIs in their Intent. In addition, in Android 11 (API level 30) or higher, PERMISSION_WRITE_EXTERNAL_STORAGE no longer has any effect; from [2]: > More recent versions of Android rely more on a file's purpose than its > location for determining an app's ability to access, and write to, a > given file. In particular, if your app targets Android 11 (API level 30) > or higher, the WRITE_EXTERNAL_STORAGE permission doesn't have any > effect on your app's access to storage. This purpose-based storage > model improves user privacy because apps are given access only to > the areas of the device's file system that they actually use. > > Android 11 introduces the MANAGE_EXTERNAL_STORAGE permission, which > provides write access to files outside the app-specific directory and > MediaStore. To learn more about this permission, and why most apps don't > need to declare it to fulfill their use cases, see the guide on how to > manage all files [3] on a storage device. For now, request the permission again, at least as long as PDF export doesn't use the storage framework to ask where to save files. It certainly makes sense to reconsider this in the future (and decide to either drop the permission completely or request MANAGE_EXTERNAL_STORAGE for API level >=30). [1] https://developer.android.com/training/data-storage/shared/documents-files [2] https://developer.android.com/training/data-storage#permissions [3] https://developer.android.com/training/data-storage/manage-all-files Change-Id: Icc4c9c9b7b315d2a0b6a025439ae7e431cdd5b37 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113840 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> (cherry picked from commit 7d9db806d65cb814af1e99a1e79c3db5aa7c17d5)
-rw-r--r--android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 9f89bbedc525..e7bb998bb826 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -9,11 +9,13 @@
package org.libreoffice.ui;
+import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
@@ -21,7 +23,10 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
+import android.support.v4.app.ActivityCompat;
+import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -120,6 +125,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private static final int REQUEST_CODE_OPEN_FILECHOOSER = 12345;
private static final int REQUEST_CODE_CREATE_NEW_DOCUMENT = 12346;
+ private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 0;
+
private Animation fabOpenAnimation;
private Animation fabCloseAnimation;
private boolean isFabMenuOpen = false;
@@ -147,6 +154,17 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
@Override
+ protected void onStart() {
+ super.onStart();
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ Log.i(LOGTAG, "no permission to read external storage - asking for permission");
+ ActivityCompat.requestPermissions(this,
+ new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
+ PERMISSION_WRITE_EXTERNAL_STORAGE);
+ }
+ }
+
+ @Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(LocaleHelper.onAttach(newBase));
}