Skip to content

Commit a27e3c6

Browse files
Merge pull request #642 from alexbakker/block-minimize-lock
Fix an issue where the app would lock when showing DocumentsUI
2 parents 8f7b152 + 6e5a80a commit a27e3c6

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

app/src/main/java/com/beemdevelopment/aegis/AegisApplication.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class AegisApplication extends Application {
4040
private VaultManager _manager;
4141
private Preferences _prefs;
4242
private List<LockListener> _lockListeners;
43+
private boolean _blockAutoLock;
4344

4445
private static final String CODE_LOCK_STATUS_ID = "lock_status_channel";
4546
private static final String CODE_LOCK_VAULT_ACTION = "lock_vault";
@@ -141,6 +142,15 @@ public void unregisterLockListener(LockListener listener) {
141142
_lockListeners.remove(listener);
142143
}
143144

145+
/**
146+
* Sets whether to block automatic lock on minimization. This should only be called
147+
* by activities before invoking an intent that shows a DocumentsUI, because that
148+
* action leads AppLifecycleObserver to believe that the app has been minimized.
149+
*/
150+
public void setBlockAutoLock(boolean block) {
151+
_blockAutoLock = block;
152+
}
153+
144154
/**
145155
* Locks the vault and the app.
146156
* @param userInitiated whether or not the user initiated the lock in MainActivity.
@@ -195,7 +205,9 @@ private void initNotificationChannels() {
195205
private class AppLifecycleObserver implements LifecycleEventObserver {
196206
@Override
197207
public void onStateChanged(@NonNull LifecycleOwner source, @NonNull Lifecycle.Event event) {
198-
if (event == Lifecycle.Event.ON_STOP && isAutoLockEnabled(Preferences.AUTO_LOCK_ON_MINIMIZE)) {
208+
if (event == Lifecycle.Event.ON_STOP
209+
&& isAutoLockEnabled(Preferences.AUTO_LOCK_ON_MINIMIZE)
210+
&& !_blockAutoLock) {
199211
lock(false);
200212
}
201213
}

app/src/main/java/com/beemdevelopment/aegis/ui/AegisActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ protected void onDestroy() {
5555
super.onDestroy();
5656
}
5757

58+
@Override
59+
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
60+
super.onActivityResult(requestCode, resultCode, data);
61+
_app.setBlockAutoLock(false);
62+
}
63+
5864
@Override
5965
public void onLocked(boolean userInitiated) {
6066
setResult(RESULT_CANCELED, null);

app/src/main/java/com/beemdevelopment/aegis/ui/MainActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,8 @@ private void startScanActivity() {
407407
}
408408

409409
private void startScanImageActivity() {
410+
_app.setBlockAutoLock(true);
411+
410412
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
411413
galleryIntent.setDataAndType(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
412414

app/src/main/java/com/beemdevelopment/aegis/ui/PreferencesFragment.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
8787
private static final int CODE_BACKUPS = 8;
8888

8989
private Intent _result;
90+
private AegisApplication _app;
9091
private Preferences _prefs;
9192
private VaultManager _vault;
9293

@@ -112,9 +113,9 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
112113
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
113114
addPreferencesFromResource(R.xml.preferences);
114115

115-
AegisApplication app = (AegisApplication) getActivity().getApplication();
116-
_prefs = app.getPreferences();
117-
_vault = app.getVaultManager();
116+
_app = (AegisApplication) getActivity().getApplication();
117+
_prefs = _app.getPreferences();
118+
_vault = _app.getVaultManager();
118119

119120
// set the result intent in advance
120121
setResult(new Intent());
@@ -190,6 +191,8 @@ public boolean onPreferenceClick(Preference preference) {
190191

191192
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
192193
intent.setType("*/*");
194+
195+
_app.setBlockAutoLock(true);
193196
startActivityForResult(intent, CODE_IMPORT);
194197
});
195198
return true;
@@ -282,14 +285,14 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
282285
});
283286

284287
Preference tapToRevealTimePreference = findPreference("pref_tap_to_reveal_time");
285-
tapToRevealTimePreference.setSummary(app.getPreferences().getTapToRevealTime() + " seconds");
288+
tapToRevealTimePreference.setSummary(_app.getPreferences().getTapToRevealTime() + " seconds");
286289
tapToRevealTimePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
287290
@Override
288291
public boolean onPreferenceClick(Preference preference) {
289292
Dialogs.showNumberPickerDialog(getActivity(), new Dialogs.NumberInputListener() {
290293
@Override
291294
public void onNumberInputResult(int number) {
292-
app.getPreferences().setTapToRevealTime(number);
295+
_app.getPreferences().setTapToRevealTime(number);
293296
tapToRevealTimePreference.setSummary(number + " seconds");
294297
_result.putExtra("needsRefresh", true);
295298
}
@@ -735,6 +738,7 @@ public void onNothingSelected(AdapterView<?> parent) {
735738
.setType(getExportMimeType(requestCode))
736739
.putExtra(Intent.EXTRA_TITLE, fileInfo.toString());
737740

741+
_app.setBlockAutoLock(true);
738742
startActivityForResult(intent, requestCode);
739743
});
740744

@@ -771,6 +775,8 @@ public void onNothingSelected(AdapterView<?> parent) {
771775
.setType(getExportMimeType(requestCode))
772776
.putExtra(Intent.EXTRA_STREAM, uri);
773777
Intent chooser = Intent.createChooser(intent, getString(R.string.pref_export_summary));
778+
779+
_app.setBlockAutoLock(true);
774780
startActivity(chooser);
775781
});
776782
});
@@ -1014,6 +1020,7 @@ private void selectBackupsLocation() {
10141020
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
10151021
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
10161022

1023+
_app.setBlockAutoLock(true);
10171024
startActivityForResult(intent, CODE_BACKUPS);
10181025
}
10191026

0 commit comments

Comments
 (0)