summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMert Tümer <merttumer7@gmail.com>2018-04-14 12:00:59 +0300
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2018-06-01 04:28:30 +0200
commit22ef830aa01bfe1e74d649d3ad01ece29a72c44d (patch)
treefa6427d910cdccd903cfeb3bfa9898ed9ad4153d /android
parent9e1a58a5d317215f91c3fa7745a2dab73783bc24 (diff)
Added Storage permission handling on the Android Viewer
This patch prevents document browsing and creating a new document from happening when write external storage permission is denied by the user. Signed-off-by: Mert Tümer <merttumer7@gmail.com> Change-Id: Idf39a291a15a9dac023f4318329baed1baa90e14 Reviewed-on: https://gerrit.libreoffice.org/52868 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'android')
-rw-r--r--android/source/res/layout/activity_document_browser.xml1
-rw-r--r--android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java4
-rw-r--r--android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java2
-rw-r--r--android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java2
-rw-r--r--android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java5
-rw-r--r--android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java5
-rw-r--r--android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java53
7 files changed, 55 insertions, 17 deletions
diff --git a/android/source/res/layout/activity_document_browser.xml b/android/source/res/layout/activity_document_browser.xml
index 1f26195c2025..63f72346c0c6 100644
--- a/android/source/res/layout/activity_document_browser.xml
+++ b/android/source/res/layout/activity_document_browser.xml
@@ -125,6 +125,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
+ android:visibility="invisible"
app:backgroundTint="@color/background_normal"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
diff --git a/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java
index f21dc258474a..e45929374bbd 100644
--- a/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java
@@ -1,8 +1,10 @@
package org.libreoffice.storage.external;
+import android.Manifest;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
@@ -160,7 +162,7 @@ public class ExtsdDocumentsProvider implements IExternalDocumentProvider,
// getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && isExternalStorageRemovable()
// but they refer to the primary external storage anyway, so what currently is covered by the
// "LocalDocumentsProvider"
- return rootPathURI!=null;
+ return rootPathURI!=null && ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
@Override
diff --git a/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java
index 138ec9479755..4341bc3541e6 100644
--- a/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java
@@ -85,6 +85,6 @@ public class OTGDocumentsProvider implements IExternalDocumentProvider,
@Override
public boolean checkProviderAvailability(Context context) {
// check if system supports USB Host
- return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST);
+ return rootPathURI.length()>0 && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST);
}
}
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 d8e6e1870044..c2e03dfc7bdd 100644
--- a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsDirectoryProvider.java
@@ -71,6 +71,6 @@ public class LocalDocumentsDirectoryProvider extends LocalDocumentsProvider {
@Override
public boolean checkProviderAvailability(Context context) {
File documentsDirectory = getDocumentsDir();
- return documentsDirectory.exists() || ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
+ return documentsDirectory.exists() && ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
}
diff --git a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
index 39c91dc951e0..1a10fad424db 100644
--- a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
@@ -16,8 +16,11 @@ import org.libreoffice.storage.IFile;
import org.libreoffice.R;
+import android.Manifest;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.Environment;
+import android.support.v4.content.ContextCompat;
/**
* Implementation of IDocumentProvider for the local file system.
@@ -52,6 +55,6 @@ public class LocalDocumentsProvider implements IDocumentProvider {
@Override
public boolean checkProviderAvailability(Context context) {
- return true;
+ return ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
}
diff --git a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
index 335a34aeb361..3a4e63b5a798 100644
--- a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
@@ -38,6 +38,7 @@ public class OwnCloudProvider implements IDocumentProvider,
private String serverUrl;
private String userName;
private String password;
+ private RemoteOperationResult result;
public OwnCloudProvider(int id, Context context) {
this.id = id;
@@ -80,7 +81,7 @@ public class OwnCloudProvider implements IDocumentProvider,
public IFile createFromUri(Context context, URI uri) {
ReadRemoteFileOperation refreshOperation = new ReadRemoteFileOperation(
uri.getPath());
- RemoteOperationResult result = refreshOperation.execute(client);
+ this.result = refreshOperation.execute(client);
if (!result.isSuccess()) {
throw buildRuntimeExceptionForResultCode(result.getCode());
}
@@ -180,6 +181,6 @@ public class OwnCloudProvider implements IDocumentProvider,
@Override
public boolean checkProviderAvailability(Context context) {
- return true;
+ return result != null && this.result.isSuccess();
}
}
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 706ce25344e9..c2b939383d20 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -65,6 +65,7 @@ import android.widget.TextView;
import android.widget.Toast;
import org.libreoffice.AboutDialogFragment;
+import org.libreoffice.LOKitShell;
import org.libreoffice.LibreOfficeMainActivity;
import org.libreoffice.R;
import org.libreoffice.SettingsActivity;
@@ -95,7 +96,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private int sortMode;
private boolean showHiddenFiles;
// dynamic permissions IDs
- private static int PERMISSION_READ_EXTERNAL_STORAGE = 0;
+ private static final int PERMISSION_READ_EXTERNAL_STORAGE = 0;
FileFilter fileFilter;
FilenameFilter filenameFilter;
@@ -166,16 +167,15 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
registerReceiver(mUSBReceiver, filter);
// init UI and populate with contents from the provider
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
- // TODO: remove local document providers if really is denied, code right now assumes it is granted/
- // there is no onRequestPermissionsResult evaluating the callback
- // without the read permissions, LO could only load documents passed via intent from other apps
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);
+ } else {
+ switchToDocumentProvider(documentProviderFactory.getDefaultProvider());
+ setEditFABVisibility(View.VISIBLE);
}
- switchToDocumentProvider(documentProviderFactory.getDefaultProvider());
createUI();
fabOpenAnimation = AnimationUtils.loadAnimation(this, R.anim.fab_open);
fabCloseAnimation = AnimationUtils.loadAnimation(this, R.anim.fab_close);
@@ -215,7 +215,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
final ArrayList<IFile> recentFiles = new ArrayList<IFile>();
for (String recentFileString : recentFileStrings) {
try {
- recentFiles.add(documentProvider.createFromUri(this, new URI(recentFileString)));
+ if(documentProvider != null)
+ recentFiles.add(documentProvider.createFromUri(this, new URI(recentFileString)));
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (RuntimeException e){
@@ -347,7 +348,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
private void refreshView() {
// enable home icon as "up" if required
- if (!currentDirectory.equals(homeDirectory)) {
+ if (currentDirectory != null && homeDirectory != null && !currentDirectory.equals(homeDirectory)) {
drawerToggle.setDrawerIndicatorEnabled(false);
} else {
drawerToggle.setDrawerIndicatorEnabled(true);
@@ -371,7 +372,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
if (isFabMenuOpen) {
collapseFabMenu();
}
- } else if (!currentDirectory.equals(homeDirectory)) {
+ } else if (currentDirectory != null && homeDirectory != null && !currentDirectory.equals(homeDirectory)) {
// navigate upwards in directory hierarchy
openParentDirectory();
} else if (isFabMenuOpen) {
@@ -864,13 +865,18 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
- outState.putString(CURRENT_DIRECTORY_KEY, currentDirectory.getUri().toString());
+
+ if(currentDirectory != null) {
+ outState.putString(CURRENT_DIRECTORY_KEY, currentDirectory.getUri().toString());
+ Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode) + Integer.toString(viewMode));
+ }
outState.putInt(FILTER_MODE_KEY, filterMode);
outState.putInt(EXPLORER_VIEW_TYPE_KEY , viewMode);
- outState.putInt(DOC_PROVIDER_KEY, documentProvider.getId());
+ if(documentProvider != null)
+ outState.putInt(DOC_PROVIDER_KEY, documentProvider.getId());
+
outState.putBoolean(ENABLE_SHOW_HIDDEN_FILES_KEY , showHiddenFiles);
- Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode) + Integer.toString(viewMode));
//prefs.edit().putInt(EXPLORER_VIEW_TYPE, viewType).commit();
Log.d(LOGTAG, "savedInstanceState");
}
@@ -1165,6 +1171,31 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
}
}
}
+
+ private void setEditFABVisibility(final int visibility){
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ editFAB.setVisibility(visibility);
+ }
+ });
+ }
+
+ @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){
+ switchToDocumentProvider(documentProviderFactory.getDefaultProvider());
+ setEditFABVisibility(View.VISIBLE);
+ } else {
+ setEditFABVisibility(View.INVISIBLE);
+ }
+ break;
+ default:
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ }
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */