diff options
author | kaishu-sahu <kaishusahu101@gmail.com> | 2019-04-15 12:19:35 +0530 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2019-04-15 11:18:11 +0200 |
commit | 97d659d480ad7fed0583f9fad705e5781b66c539 (patch) | |
tree | d879ac05ee9296cc6539c2d8c993ad08abddf7b6 | |
parent | 184654581c82be479f2c278d5c23d1d0b81f812a (diff) |
android: Update handling of the storage permission.
If the user does these steps: install -> open a document(from app's file manager) -> close the app -> remove storage permission
-> open the document from the launcher shortcuts, he/she gets an error(from loolwsd).Expected behaviour should be to ask for
storage permission. Same behaviour can be observed if the user tries to open the document via file uri provided by 3rd party
file managers on api < 24.
Change-Id: Idfc3d55a81ccd269a2251aef57935eff2569ea94
Reviewed-on: https://gerrit.libreoffice.org/70759
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r-- | android/.gitignore | 1 | ||||
-rw-r--r-- | android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java | 37 | ||||
-rw-r--r-- | android/app/src/main/res/values/strings.xml | 1 |
3 files changed, 36 insertions, 3 deletions
diff --git a/android/.gitignore b/android/.gitignore index 290fd83d8..6e50fa55a 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -6,6 +6,7 @@ /app/src/main/assets/etc/ /app/src/main/assets/example.odt /app/src/main/assets/license.txt +/app/src/main/assets/license.html /app/src/main/assets/notice.txt /app/src/main/assets/program/ /app/src/main/assets/share/ diff --git a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java index fd1431939..127b122e4 100644 --- a/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java +++ b/android/app/src/main/java/org/libreoffice/androidapp/MainActivity.java @@ -9,9 +9,11 @@ package org.libreoffice.androidapp; +import android.Manifest; import android.content.ContentResolver; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.os.Build; @@ -45,7 +47,7 @@ public class MainActivity extends AppCompatActivity { final static String TAG = "MainActivity"; private static final String ASSETS_EXTRACTED_PREFS_KEY = "ASSETS_EXTRACTED"; - private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 777; + private static final int PERMISSION_READ_EXTERNAL_STORAGE = 777; private File mTempFile = null; @@ -56,7 +58,7 @@ public class MainActivity extends AppCompatActivity { private WebView mWebView; private boolean isDocEditable = false; - private boolean isDocDebuggable = true; + private boolean isDocDebuggable = BuildConfig.DEBUG; private static boolean copyFromAssets(AssetManager assetManager, String fromAssetPath, String targetDir) { @@ -184,8 +186,37 @@ public class MainActivity extends AppCompatActivity { WebView.setWebContentsDebuggingEnabled(true); } } + } + - loadDocument(); + @Override + protected void onStart() { + super.onStart(); + if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + Log.i(TAG, "asking for read storage permission"); + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, + PERMISSION_READ_EXTERNAL_STORAGE); + } else { + loadDocument(); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + switch (requestCode) { + case PERMISSION_READ_EXTERNAL_STORAGE: + if (permissions.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + loadDocument(); + } else { + Toast.makeText(this, getString(R.string.storage_permission_required), Toast.LENGTH_SHORT).show(); + finish(); + break; + } + break; + default: + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + } } private boolean copyFileToTemp() { diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index fb98b77cb..5b94ca5c6 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -10,6 +10,7 @@ <string name="temp_file_saving_disabled">This file is read-only, saving is disabled.</string> <string name="file_exists_warning">A file with this name already exists, and it will be overwritten.</string> <string name="file_creation_failed">File creation failed</string> + <string name="storage_permission_required">Storage permission is required</string> <string name="about_license">Show License</string> <string name="about_notice">Show Notice</string> |