diff options
author | Mert Tumer <merttumer@outlook.com> | 2018-10-24 11:41:25 +0300 |
---|---|---|
committer | Gülşah Köse <gulsah.1004@gmail.com> | 2018-11-02 01:31:59 +0100 |
commit | 187a3db08ecc0e42787aa57d8b4ed67aa9c37e74 (patch) | |
tree | 4d33a878aab086b9f6c4f5f467e2aff66589139d /android/source | |
parent | 612a107464c1889fdc4806a3c86da8c2fbf452c8 (diff) |
Fix permission settings on Android Viewer
We ask READ_EXTERNAL_STORAGE permission on first start
then check WRITE_EXTERNAL_STORAGE permission on switching
between document providers. This causes problems on Android 8+
Signed-off-by: Mert Tumer <merttumer@outlook.com>
Change-Id: Ia7290e33b2a55f5a2197374ca39c60998edfff72
Reviewed-on: https://gerrit.libreoffice.org/62269
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Tested-by: Jenkins
Diffstat (limited to 'android/source')
-rw-r--r-- | android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java | 3 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 10 |
2 files changed, 5 insertions, 8 deletions
diff --git a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java index c2e03dfc7bdd..15522e93a45e 100644 --- a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java +++ b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java @@ -48,9 +48,6 @@ public class LocalDocumentsDirectoryProvider extends LocalDocumentsProvider { public IFile getRootDirectory(Context context) { File documentsDirectory = getDocumentsDir(); if (!documentsDirectory.exists()) { - // might be a little counter-intuitive: if we were granted READ permission already, we're also granted the write-permission - // when we ask for it, since they are both in the same storage group (for 5.1 and lower it is granted at install-time already) - // see https://developer.android.com/guide/topics/permissions/requesting.html#perm-groups if (ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { if(!documentsDirectory.mkdirs()) { // fallback to the toplevel dir - might be due to the dir not mounted/used as USB-Mass-Storage or similar diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index d6501f08bd85..3fb715e46778 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -99,7 +99,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings private String displayLanguage; // dynamic permissions IDs - private static final int PERMISSION_READ_EXTERNAL_STORAGE = 0; + private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 0; FileFilter fileFilter; FilenameFilter filenameFilter; @@ -949,11 +949,11 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings @Override protected void onStart() { super.onStart(); - if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + 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.READ_EXTERNAL_STORAGE}, - PERMISSION_READ_EXTERNAL_STORAGE); + new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + PERMISSION_WRITE_EXTERNAL_STORAGE); } else { switchToDocumentProvider(documentProviderFactory.getDefaultProvider()); setEditFABVisibility(View.VISIBLE); @@ -1207,7 +1207,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch(requestCode){ - case PERMISSION_READ_EXTERNAL_STORAGE: + case PERMISSION_WRITE_EXTERNAL_STORAGE: if(permissions.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){ switchToDocumentProvider(documentProviderFactory.getDefaultProvider()); setEditFABVisibility(View.VISIBLE); |