diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/AegisActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/AegisActivity.java index 1fad3570..6d3a057c 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/AegisActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/AegisActivity.java @@ -1,11 +1,14 @@ package com.beemdevelopment.aegis.ui; +import android.content.ActivityNotFoundException; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; import android.view.WindowManager; import android.widget.Toast; +import androidx.annotation.CallSuper; +import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.beemdevelopment.aegis.AegisApplication; @@ -55,12 +58,32 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp super.onDestroy(); } + @CallSuper @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); + protected void onResume() { + super.onResume(); _app.setBlockAutoLock(false); } + @Override + public void startActivityForResult(Intent intent, int requestCode, Bundle bundle) { + if (isAutoLockBypassedForAction(intent.getAction())) { + _app.setBlockAutoLock(true); + } + + try { + super.startActivityForResult(intent, requestCode, bundle); + } catch (ActivityNotFoundException e) { + e.printStackTrace(); + + if (isDocsAction(intent.getAction())) { + Dialogs.showErrorDialog(this, R.string.documentsui_error, e); + } else { + throw e; + } + } + } + @Override public void onLocked(boolean userInitiated) { setResult(RESULT_CANCELED, null); @@ -135,4 +158,17 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp protected boolean isOrphan() { return !(this instanceof MainActivity) && !(this instanceof AuthActivity) && !(this instanceof IntroActivity) && _app.isVaultLocked(); } + + private static boolean isDocsAction(@Nullable String action) { + return action != null && (action.equals(Intent.ACTION_GET_CONTENT) + || action.equals(Intent.ACTION_CREATE_DOCUMENT) + || action.equals(Intent.ACTION_OPEN_DOCUMENT) + || action.equals(Intent.ACTION_OPEN_DOCUMENT_TREE)); + } + + private static boolean isAutoLockBypassedForAction(@Nullable String action) { + return isDocsAction(action) || (action != null && (action.equals(Intent.ACTION_PICK) + || action.equals(Intent.ACTION_SEND) + || action.equals(Intent.ACTION_CHOOSER))); + } } diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java index 33820408..8f949740 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java @@ -407,8 +407,6 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene } private void startScanImageActivity() { - _app.setBlockAutoLock(true); - Intent galleryIntent = new Intent(Intent.ACTION_PICK); galleryIntent.setDataAndType(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*"); diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java b/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java index 58704da2..9cdfb5cd 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java @@ -191,8 +191,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); - - _app.setBlockAutoLock(true); startActivityForResult(intent, CODE_IMPORT); }); return true; @@ -737,8 +735,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat { .addCategory(Intent.CATEGORY_OPENABLE) .setType(getExportMimeType(requestCode)) .putExtra(Intent.EXTRA_TITLE, fileInfo.toString()); - - _app.setBlockAutoLock(true); startActivityForResult(intent, requestCode); }); @@ -775,8 +771,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat { .setType(getExportMimeType(requestCode)) .putExtra(Intent.EXTRA_STREAM, uri); Intent chooser = Intent.createChooser(intent, getString(R.string.pref_export_summary)); - - _app.setBlockAutoLock(true); startActivity(chooser); }); }); @@ -1019,8 +1013,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat { | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION); - - _app.setBlockAutoLock(true); startActivityForResult(intent, CODE_BACKUPS); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8cc7c302..b842c76a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -168,6 +168,7 @@ An error occurred while disabling encryption The backup was scheduled successfully An error occurred while trying to create a backup + DocumentsUI appears to be missing from your device. This is an important system component necessary for the selection and creation of documents. If you used a tool to "debloat" your device, you may have accidentally deleted it and will have to reinstall it. Permission denied New format (v0.6.3 or newer) Old format (v0.6.2 or older)