Simplify the auto lock block logic and show an error if DocumentsUI is missing

pull/643/head
Alexander Bakker 4 years ago
parent 1748e2221f
commit 4482a21a54

@ -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)));
}
}

@ -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/*");

@ -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);
}

@ -168,6 +168,7 @@
<string name="disable_encryption_error">An error occurred while disabling encryption</string>
<string name="backup_successful">The backup was scheduled successfully</string>
<string name="backup_error">An error occurred while trying to create a backup</string>
<string name="documentsui_error">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 &quot;debloat&quot; your device, you may have accidentally deleted it and will have to reinstall it.</string>
<string name="permission_denied">Permission denied</string>
<string name="andotp_new_format">New format (v0.6.3 or newer) </string>
<string name="andotp_old_format">Old format (v0.6.2 or older) </string>

Loading…
Cancel
Save