mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 22:12:55 +00:00
Don't rely on the intent action to decide whether to block auto lock
This commit is contained in:
parent
813bf292fa
commit
ad0088eca6
6 changed files with 71 additions and 37 deletions
|
@ -11,6 +11,7 @@ import android.widget.Toast;
|
|||
import androidx.annotation.CallSuper;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.beemdevelopment.aegis.AegisApplication;
|
||||
import com.beemdevelopment.aegis.Preferences;
|
||||
|
@ -70,25 +71,6 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
|
|||
_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);
|
||||
|
@ -168,16 +150,66 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
|
|||
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));
|
||||
}
|
||||
public static class Helper {
|
||||
private Helper() {
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an external activity, temporarily blocks automatic lock of Aegis and
|
||||
* shows an error dialog if the target activity is not found.
|
||||
*/
|
||||
public static void startExtActivityForResult(Activity activity, Intent intent, int requestCode) {
|
||||
AegisApplication app = (AegisApplication) activity.getApplication();
|
||||
app.setBlockAutoLock(true);
|
||||
|
||||
try {
|
||||
activity.startActivityForResult(intent, requestCode, null);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
if (isDocsAction(intent.getAction())) {
|
||||
Dialogs.showErrorDialog(activity, R.string.documentsui_error, e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an external activity, temporarily blocks automatic lock of Aegis and
|
||||
* shows an error dialog if the target activity is not found.
|
||||
*/
|
||||
public static void startExtActivity(Fragment fragment, Intent intent) {
|
||||
startExtActivityForResult(fragment, intent, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts an external activity, temporarily blocks automatic lock of Aegis and
|
||||
* shows an error dialog if the target activity is not found.
|
||||
*/
|
||||
public static void startExtActivityForResult(Fragment fragment, Intent intent, int requestCode) {
|
||||
AegisApplication app = (AegisApplication) fragment.getActivity().getApplication();
|
||||
app.setBlockAutoLock(true);
|
||||
|
||||
try {
|
||||
fragment.startActivityForResult(intent, requestCode, null);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
if (isDocsAction(intent.getAction())) {
|
||||
Dialogs.showErrorDialog(fragment.getContext(), R.string.documentsui_error, e);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -427,7 +427,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
|
||||
Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.select_icon));
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { fileIntent });
|
||||
startActivityForResult(chooserIntent, PICK_IMAGE_REQUEST);
|
||||
AegisActivity.Helper.startExtActivityForResult(this, chooserIntent, PICK_IMAGE_REQUEST);
|
||||
}
|
||||
|
||||
private void startIconSelection() {
|
||||
|
|
|
@ -377,7 +377,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
|
|||
|
||||
Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.select_picture));
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { fileIntent });
|
||||
startActivityForResult(chooserIntent, CODE_SCAN_IMAGE);
|
||||
AegisActivity.Helper.startExtActivityForResult(this, chooserIntent, CODE_SCAN_IMAGE);
|
||||
}
|
||||
|
||||
private void startPreferencesActivity() {
|
||||
|
|
|
@ -11,6 +11,7 @@ import androidx.preference.SwitchPreferenceCompat;
|
|||
|
||||
import com.beemdevelopment.aegis.Preferences;
|
||||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.ui.AegisActivity;
|
||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||
import com.beemdevelopment.aegis.vault.VaultManagerException;
|
||||
|
||||
|
@ -133,7 +134,6 @@ public class BackupsPreferencesFragment extends PreferencesFragment {
|
|||
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
||||
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
|
||||
|
||||
getApp().setBlockAutoLock(true);
|
||||
startActivityForResult(intent, CODE_BACKUPS);
|
||||
AegisActivity.Helper.startExtActivityForResult(this, intent, CODE_BACKUPS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.beemdevelopment.aegis.icons.IconPack;
|
|||
import com.beemdevelopment.aegis.icons.IconPackException;
|
||||
import com.beemdevelopment.aegis.icons.IconPackExistsException;
|
||||
import com.beemdevelopment.aegis.icons.IconPackManager;
|
||||
import com.beemdevelopment.aegis.ui.AegisActivity;
|
||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||
import com.beemdevelopment.aegis.ui.tasks.ImportIconPackTask;
|
||||
import com.beemdevelopment.aegis.ui.views.IconPackAdapter;
|
||||
|
@ -144,7 +145,7 @@ public class IconPacksManagerFragment extends Fragment implements IconPackAdapte
|
|||
private void startImportIconPack() {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("application/zip");
|
||||
startActivityForResult(intent, CODE_IMPORT);
|
||||
AegisActivity.Helper.startExtActivityForResult(this, intent, CODE_IMPORT);
|
||||
}
|
||||
|
||||
private void updateEmptyState() {
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.beemdevelopment.aegis.BuildConfig;
|
|||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.helpers.DropdownHelper;
|
||||
import com.beemdevelopment.aegis.importers.DatabaseImporter;
|
||||
import com.beemdevelopment.aegis.ui.AegisActivity;
|
||||
import com.beemdevelopment.aegis.ui.ImportEntriesActivity;
|
||||
import com.beemdevelopment.aegis.ui.dialogs.Dialogs;
|
||||
import com.beemdevelopment.aegis.ui.tasks.ExportTask;
|
||||
|
@ -60,7 +61,7 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
|||
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
startActivityForResult(intent, CODE_IMPORT_SELECT);
|
||||
AegisActivity.Helper.startExtActivityForResult(this, intent, CODE_IMPORT_SELECT);
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
@ -183,7 +184,7 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
|||
.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
.setType(getExportMimeType(requestCode))
|
||||
.putExtra(Intent.EXTRA_TITLE, fileInfo.toString());
|
||||
startActivityForResult(intent, requestCode);
|
||||
AegisActivity.Helper.startExtActivityForResult(this, intent, requestCode);
|
||||
});
|
||||
|
||||
btnNeutral.setOnClickListener(v -> {
|
||||
|
@ -220,7 +221,7 @@ public class ImportExportPreferencesFragment extends PreferencesFragment {
|
|||
.setType(getExportMimeType(requestCode))
|
||||
.putExtra(Intent.EXTRA_STREAM, uri);
|
||||
Intent chooser = Intent.createChooser(intent, getString(R.string.pref_export_summary));
|
||||
startActivity(chooser);
|
||||
AegisActivity.Helper.startExtActivity(this, chooser);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue