mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-24 15:56:07 +00:00
Merge pull request #642 from alexbakker/block-minimize-lock
Fix an issue where the app would lock when showing DocumentsUI
This commit is contained in:
commit
a27e3c6364
4 changed files with 33 additions and 6 deletions
|
@ -40,6 +40,7 @@ public class AegisApplication extends Application {
|
|||
private VaultManager _manager;
|
||||
private Preferences _prefs;
|
||||
private List<LockListener> _lockListeners;
|
||||
private boolean _blockAutoLock;
|
||||
|
||||
private static final String CODE_LOCK_STATUS_ID = "lock_status_channel";
|
||||
private static final String CODE_LOCK_VAULT_ACTION = "lock_vault";
|
||||
|
@ -141,6 +142,15 @@ public class AegisApplication extends Application {
|
|||
_lockListeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to block automatic lock on minimization. This should only be called
|
||||
* by activities before invoking an intent that shows a DocumentsUI, because that
|
||||
* action leads AppLifecycleObserver to believe that the app has been minimized.
|
||||
*/
|
||||
public void setBlockAutoLock(boolean block) {
|
||||
_blockAutoLock = block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks the vault and the app.
|
||||
* @param userInitiated whether or not the user initiated the lock in MainActivity.
|
||||
|
@ -195,7 +205,9 @@ public class AegisApplication extends Application {
|
|||
private class AppLifecycleObserver implements LifecycleEventObserver {
|
||||
@Override
|
||||
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
|
||||
if (event == Lifecycle.Event.ON_STOP && isAutoLockEnabled(Preferences.AUTO_LOCK_ON_MINIMIZE)) {
|
||||
if (event == Lifecycle.Event.ON_STOP
|
||||
&& isAutoLockEnabled(Preferences.AUTO_LOCK_ON_MINIMIZE)
|
||||
&& !_blockAutoLock) {
|
||||
lock(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,12 @@ public abstract class AegisActivity extends AppCompatActivity implements AegisAp
|
|||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
_app.setBlockAutoLock(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocked(boolean userInitiated) {
|
||||
setResult(RESULT_CANCELED, null);
|
||||
|
|
|
@ -407,6 +407,8 @@ 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/*");
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
private static final int CODE_BACKUPS = 8;
|
||||
|
||||
private Intent _result;
|
||||
private AegisApplication _app;
|
||||
private Preferences _prefs;
|
||||
private VaultManager _vault;
|
||||
|
||||
|
@ -112,9 +113,9 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
|
||||
AegisApplication app = (AegisApplication) getActivity().getApplication();
|
||||
_prefs = app.getPreferences();
|
||||
_vault = app.getVaultManager();
|
||||
_app = (AegisApplication) getActivity().getApplication();
|
||||
_prefs = _app.getPreferences();
|
||||
_vault = _app.getVaultManager();
|
||||
|
||||
// set the result intent in advance
|
||||
setResult(new Intent());
|
||||
|
@ -190,6 +191,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("*/*");
|
||||
|
||||
_app.setBlockAutoLock(true);
|
||||
startActivityForResult(intent, CODE_IMPORT);
|
||||
});
|
||||
return true;
|
||||
|
@ -282,14 +285,14 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
});
|
||||
|
||||
Preference tapToRevealTimePreference = findPreference("pref_tap_to_reveal_time");
|
||||
tapToRevealTimePreference.setSummary(app.getPreferences().getTapToRevealTime() + " seconds");
|
||||
tapToRevealTimePreference.setSummary(_app.getPreferences().getTapToRevealTime() + " seconds");
|
||||
tapToRevealTimePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
Dialogs.showNumberPickerDialog(getActivity(), new Dialogs.NumberInputListener() {
|
||||
@Override
|
||||
public void onNumberInputResult(int number) {
|
||||
app.getPreferences().setTapToRevealTime(number);
|
||||
_app.getPreferences().setTapToRevealTime(number);
|
||||
tapToRevealTimePreference.setSummary(number + " seconds");
|
||||
_result.putExtra("needsRefresh", true);
|
||||
}
|
||||
|
@ -735,6 +738,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
.setType(getExportMimeType(requestCode))
|
||||
.putExtra(Intent.EXTRA_TITLE, fileInfo.toString());
|
||||
|
||||
_app.setBlockAutoLock(true);
|
||||
startActivityForResult(intent, requestCode);
|
||||
});
|
||||
|
||||
|
@ -771,6 +775,8 @@ 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);
|
||||
});
|
||||
});
|
||||
|
@ -1014,6 +1020,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
|||
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
||||
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
|
||||
|
||||
_app.setBlockAutoLock(true);
|
||||
startActivityForResult(intent, CODE_BACKUPS);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue