2019-02-07 22:39:33 +01:00
|
|
|
package com.beemdevelopment.aegis.ui;
|
2016-08-15 21:29:41 +02:00
|
|
|
|
2017-12-13 19:00:58 +01:00
|
|
|
import android.Manifest;
|
2016-08-21 22:32:07 +02:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
2016-08-21 22:24:04 +02:00
|
|
|
import android.content.Context;
|
2016-08-15 22:31:28 +02:00
|
|
|
import android.content.Intent;
|
2019-04-19 23:10:18 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.BitmapFactory;
|
2018-01-01 21:11:40 +01:00
|
|
|
import android.graphics.Rect;
|
2019-04-19 23:10:18 +02:00
|
|
|
import android.net.Uri;
|
2016-08-15 21:29:41 +02:00
|
|
|
import android.os.Bundle;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.view.Menu;
|
2019-08-03 16:15:39 +02:00
|
|
|
import android.view.MenuInflater;
|
2016-08-16 14:14:17 +02:00
|
|
|
import android.view.MenuItem;
|
2018-01-01 21:11:40 +01:00
|
|
|
import android.view.MotionEvent;
|
2018-12-11 11:44:36 +01:00
|
|
|
import android.view.SubMenu;
|
2016-08-17 01:14:25 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-08-03 16:15:39 +02:00
|
|
|
import androidx.appcompat.view.ActionMode;
|
2019-09-10 23:10:11 +02:00
|
|
|
import androidx.appcompat.widget.SearchView;
|
2019-08-03 16:15:39 +02:00
|
|
|
|
2019-04-04 14:07:36 +02:00
|
|
|
import com.beemdevelopment.aegis.AegisApplication;
|
2019-12-25 19:21:34 +01:00
|
|
|
import com.beemdevelopment.aegis.CancelAction;
|
2019-04-04 14:07:36 +02:00
|
|
|
import com.beemdevelopment.aegis.R;
|
|
|
|
import com.beemdevelopment.aegis.SortCategory;
|
|
|
|
import com.beemdevelopment.aegis.ViewMode;
|
2019-04-20 01:25:04 +02:00
|
|
|
import com.beemdevelopment.aegis.helpers.FabScrollHelper;
|
2019-02-07 22:39:33 +01:00
|
|
|
import com.beemdevelopment.aegis.helpers.PermissionHelper;
|
2019-04-19 23:10:18 +02:00
|
|
|
import com.beemdevelopment.aegis.otp.GoogleAuthInfo;
|
|
|
|
import com.beemdevelopment.aegis.otp.GoogleAuthInfoException;
|
2019-02-07 22:39:33 +01:00
|
|
|
import com.beemdevelopment.aegis.ui.views.EntryListView;
|
2019-12-25 19:21:34 +01:00
|
|
|
import com.beemdevelopment.aegis.vault.VaultEntry;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultFileCredentials;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultManager;
|
|
|
|
import com.beemdevelopment.aegis.vault.VaultManagerException;
|
2019-04-04 14:07:36 +02:00
|
|
|
import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
2019-04-19 23:10:18 +02:00
|
|
|
import com.google.zxing.BinaryBitmap;
|
|
|
|
import com.google.zxing.ChecksumException;
|
|
|
|
import com.google.zxing.FormatException;
|
|
|
|
import com.google.zxing.LuminanceSource;
|
|
|
|
import com.google.zxing.MultiFormatReader;
|
|
|
|
import com.google.zxing.NotFoundException;
|
|
|
|
import com.google.zxing.RGBLuminanceSource;
|
|
|
|
import com.google.zxing.Reader;
|
|
|
|
import com.google.zxing.Result;
|
|
|
|
import com.google.zxing.common.HybridBinarizer;
|
2017-12-30 00:26:16 +01:00
|
|
|
|
2019-04-19 23:10:18 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
2018-12-11 11:44:36 +01:00
|
|
|
import java.util.ArrayList;
|
2019-03-31 19:57:45 +02:00
|
|
|
import java.util.List;
|
2018-12-11 11:44:36 +01:00
|
|
|
import java.util.TreeSet;
|
2016-08-16 20:04:38 +02:00
|
|
|
|
2018-06-06 16:15:31 +02:00
|
|
|
public class MainActivity extends AegisActivity implements EntryListView.Listener {
|
2017-12-13 19:00:58 +01:00
|
|
|
// activity request codes
|
2018-06-06 16:15:31 +02:00
|
|
|
private static final int CODE_SCAN = 0;
|
|
|
|
private static final int CODE_ADD_ENTRY = 1;
|
|
|
|
private static final int CODE_EDIT_ENTRY = 2;
|
|
|
|
private static final int CODE_ENTER_ENTRY = 3;
|
2017-12-30 00:26:16 +01:00
|
|
|
private static final int CODE_DO_INTRO = 4;
|
|
|
|
private static final int CODE_DECRYPT = 5;
|
2018-05-10 14:50:47 +02:00
|
|
|
private static final int CODE_PREFERENCES = 6;
|
2019-04-19 23:10:18 +02:00
|
|
|
private static final int CODE_SCAN_IMAGE = 7;
|
2016-08-24 23:48:25 +02:00
|
|
|
|
2017-12-13 19:00:58 +01:00
|
|
|
// permission request codes
|
2018-05-10 19:34:42 +02:00
|
|
|
private static final int CODE_PERM_CAMERA = 0;
|
2019-07-03 18:57:03 +02:00
|
|
|
private static final int CODE_PERM_READ_STORAGE = 1;
|
2017-12-13 19:00:58 +01:00
|
|
|
|
2017-12-23 22:33:32 +01:00
|
|
|
private AegisApplication _app;
|
2019-12-25 19:21:34 +01:00
|
|
|
private VaultManager _vault;
|
2018-06-09 20:23:39 +02:00
|
|
|
private boolean _loaded;
|
2019-08-31 13:46:18 +02:00
|
|
|
private String _selectedGroup;
|
2019-05-30 02:07:30 +02:00
|
|
|
private boolean _searchSubmitted;
|
2016-09-30 01:08:03 +02:00
|
|
|
|
2020-01-04 20:38:40 +01:00
|
|
|
private List<VaultEntry> _selectedEntries;
|
2019-08-03 16:15:39 +02:00
|
|
|
private ActionMode _actionMode;
|
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
private Menu _menu;
|
2019-05-30 02:07:30 +02:00
|
|
|
private SearchView _searchView;
|
2018-01-01 21:11:40 +01:00
|
|
|
private FloatingActionsMenu _fabMenu;
|
2018-06-09 20:23:39 +02:00
|
|
|
private EntryListView _entryListView;
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2019-04-20 01:25:04 +02:00
|
|
|
private FabScrollHelper _fabScrollHelper;
|
2019-04-04 14:07:36 +02:00
|
|
|
|
2019-08-03 16:15:39 +02:00
|
|
|
private ActionMode.Callback _actionModeCallbacks = new ActionModeCallbacks();
|
|
|
|
|
2016-08-15 21:29:41 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2019-09-05 00:24:33 +02:00
|
|
|
|
2017-12-23 22:33:32 +01:00
|
|
|
_app = (AegisApplication) getApplication();
|
2019-12-25 19:21:34 +01:00
|
|
|
_vault = _app.getVaultManager();
|
2018-06-09 20:23:39 +02:00
|
|
|
_loaded = false;
|
2016-09-29 12:31:55 +02:00
|
|
|
|
2017-12-23 22:33:32 +01:00
|
|
|
// set up the main view
|
2016-08-15 21:29:41 +02:00
|
|
|
setContentView(R.layout.activity_main);
|
2017-12-03 16:47:27 +01:00
|
|
|
|
2018-06-06 16:15:31 +02:00
|
|
|
// set up the entry view
|
|
|
|
_entryListView = (EntryListView) getSupportFragmentManager().findFragmentById(R.id.key_profiles);
|
|
|
|
_entryListView.setListener(this);
|
2020-04-23 23:19:38 +02:00
|
|
|
_entryListView.setCodeGroupSize(getPreferences().getCodeGroupSize());
|
2018-09-19 00:10:03 +02:00
|
|
|
_entryListView.setShowAccountName(getPreferences().isAccountNameVisible());
|
2019-09-11 20:51:02 +02:00
|
|
|
_entryListView.setSearchAccountName(getPreferences().isSearchAccountNameEnabled());
|
2019-09-07 22:26:34 +02:00
|
|
|
_entryListView.setHighlightEntry(getPreferences().isEntryHighlightEnabled());
|
2019-03-25 21:32:29 +01:00
|
|
|
_entryListView.setTapToReveal(getPreferences().isTapToRevealEnabled());
|
2019-03-26 00:06:39 +01:00
|
|
|
_entryListView.setTapToRevealTime(getPreferences().getTapToRevealTime());
|
2019-05-15 21:29:45 +02:00
|
|
|
_entryListView.setSortCategory(getPreferences().getCurrentSortCategory(), false);
|
|
|
|
_entryListView.setViewMode(getPreferences().getCurrentViewMode());
|
2017-12-25 15:36:29 +01:00
|
|
|
|
2017-12-23 22:33:32 +01:00
|
|
|
// set up the floating action button
|
2018-01-01 21:11:40 +01:00
|
|
|
_fabMenu = findViewById(R.id.fab);
|
2017-12-30 00:26:16 +01:00
|
|
|
findViewById(R.id.fab_enter).setOnClickListener(view -> {
|
2018-01-01 21:11:40 +01:00
|
|
|
_fabMenu.collapse();
|
2018-06-09 20:23:39 +02:00
|
|
|
startEditProfileActivity(CODE_ENTER_ENTRY, null, true);
|
2017-12-30 00:26:16 +01:00
|
|
|
});
|
2019-04-19 23:10:18 +02:00
|
|
|
findViewById(R.id.fab_scan_image).setOnClickListener(view -> {
|
|
|
|
_fabMenu.collapse();
|
2019-07-03 18:57:03 +02:00
|
|
|
startScanImageActivity();
|
2019-04-19 23:10:18 +02:00
|
|
|
});
|
2017-12-30 00:26:16 +01:00
|
|
|
findViewById(R.id.fab_scan).setOnClickListener(view -> {
|
2018-01-01 21:11:40 +01:00
|
|
|
_fabMenu.collapse();
|
2018-06-09 20:23:39 +02:00
|
|
|
startScanActivity();
|
2017-12-30 00:26:16 +01:00
|
|
|
});
|
2019-04-20 01:25:04 +02:00
|
|
|
|
|
|
|
_fabScrollHelper = new FabScrollHelper(_fabMenu);
|
2020-01-04 20:38:40 +01:00
|
|
|
_selectedEntries = new ArrayList<>();
|
2016-08-15 21:29:41 +02:00
|
|
|
}
|
2016-08-16 00:08:01 +02:00
|
|
|
|
2019-06-22 12:12:26 +02:00
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
_entryListView.setListener(null);
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
|
2018-01-01 21:11:40 +01:00
|
|
|
@Override
|
|
|
|
public boolean dispatchTouchEvent(MotionEvent event) {
|
|
|
|
// collapse the fab menu on touch
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
if (_fabMenu.isExpanded()) {
|
|
|
|
Rect rect = new Rect();
|
|
|
|
_fabMenu.getGlobalVisibleRect(rect);
|
|
|
|
|
|
|
|
if (!rect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
|
|
|
_fabMenu.collapse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.dispatchTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
2017-12-25 20:01:58 +01:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
setIntent(intent);
|
|
|
|
|
2019-04-08 23:13:11 +02:00
|
|
|
doShortcutActions();
|
2017-12-25 20:01:58 +01:00
|
|
|
}
|
|
|
|
|
2017-12-24 21:42:08 +01:00
|
|
|
@Override
|
2016-08-16 00:08:01 +02:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2017-12-25 20:01:58 +01:00
|
|
|
if (data == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:12:09 +02:00
|
|
|
// don't process any activity results if the vault is locked
|
2019-12-25 19:21:34 +01:00
|
|
|
if (requestCode != CODE_DECRYPT && requestCode != CODE_DO_INTRO && _vault.isLocked()) {
|
2019-05-12 17:12:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-06 16:03:36 +02:00
|
|
|
switch (requestCode) {
|
2018-06-06 16:15:31 +02:00
|
|
|
case CODE_SCAN:
|
|
|
|
onScanResult(resultCode, data);
|
2017-08-06 16:03:36 +02:00
|
|
|
break;
|
2018-06-06 16:15:31 +02:00
|
|
|
case CODE_ADD_ENTRY:
|
|
|
|
onAddEntryResult(resultCode, data);
|
2017-08-06 16:03:36 +02:00
|
|
|
break;
|
2018-06-06 16:15:31 +02:00
|
|
|
case CODE_EDIT_ENTRY:
|
|
|
|
onEditEntryResult(resultCode, data);
|
2017-12-27 22:04:22 +01:00
|
|
|
break;
|
2018-06-06 16:15:31 +02:00
|
|
|
case CODE_ENTER_ENTRY:
|
|
|
|
onEnterEntryResult(resultCode, data);
|
2017-12-30 00:26:16 +01:00
|
|
|
break;
|
2017-08-06 16:03:36 +02:00
|
|
|
case CODE_DO_INTRO:
|
|
|
|
onDoIntroResult(resultCode, data);
|
|
|
|
break;
|
2017-08-06 18:15:47 +02:00
|
|
|
case CODE_DECRYPT:
|
|
|
|
onDecryptResult(resultCode, data);
|
|
|
|
break;
|
2017-12-10 19:19:48 +01:00
|
|
|
case CODE_PREFERENCES:
|
|
|
|
onPreferencesResult(resultCode, data);
|
|
|
|
break;
|
2019-04-19 23:10:18 +02:00
|
|
|
case CODE_SCAN_IMAGE:
|
|
|
|
onScanImageResult(resultCode, data);
|
2017-12-10 19:19:48 +01:00
|
|
|
}
|
2019-09-14 15:20:02 +02:00
|
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2017-12-10 19:19:48 +01:00
|
|
|
}
|
|
|
|
|
2017-12-13 19:00:58 +01:00
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
|
|
if (!PermissionHelper.checkResults(grantResults)) {
|
2018-10-09 23:13:51 +02:00
|
|
|
Toast.makeText(this, getString(R.string.permission_denied), Toast.LENGTH_SHORT).show();
|
2017-12-13 19:00:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (requestCode) {
|
|
|
|
case CODE_PERM_CAMERA:
|
2018-06-09 19:23:30 +02:00
|
|
|
startScanActivity();
|
2017-12-13 19:00:58 +01:00
|
|
|
break;
|
2019-07-03 18:57:03 +02:00
|
|
|
case CODE_PERM_READ_STORAGE:
|
|
|
|
startScanImageActivity();
|
|
|
|
break;
|
2017-12-13 19:00:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-10 19:19:48 +01:00
|
|
|
private void onPreferencesResult(int resultCode, Intent data) {
|
2018-06-06 16:15:31 +02:00
|
|
|
// refresh the entire entry list if needed
|
2018-05-11 19:33:20 +02:00
|
|
|
if (data.getBooleanExtra("needsRecreate", false)) {
|
|
|
|
recreate();
|
|
|
|
} else if (data.getBooleanExtra("needsRefresh", false)) {
|
2018-09-19 00:10:03 +02:00
|
|
|
boolean showAccountName = getPreferences().isAccountNameVisible();
|
2020-04-23 23:19:38 +02:00
|
|
|
int codeGroupSize = getPreferences().getCodeGroupSize();
|
2019-09-11 20:51:02 +02:00
|
|
|
boolean searchAccountName = getPreferences().isSearchAccountNameEnabled();
|
2019-09-07 22:26:34 +02:00
|
|
|
boolean highlightEntry = getPreferences().isEntryHighlightEnabled();
|
2019-03-25 21:40:08 +01:00
|
|
|
boolean tapToReveal = getPreferences().isTapToRevealEnabled();
|
2019-03-26 00:06:39 +01:00
|
|
|
int tapToRevealTime = getPreferences().getTapToRevealTime();
|
2019-05-15 21:29:45 +02:00
|
|
|
ViewMode viewMode = getPreferences().getCurrentViewMode();
|
2018-09-19 00:10:03 +02:00
|
|
|
_entryListView.setShowAccountName(showAccountName);
|
2020-04-23 23:19:38 +02:00
|
|
|
_entryListView.setCodeGroupSize(codeGroupSize);
|
2019-09-11 20:51:02 +02:00
|
|
|
_entryListView.setSearchAccountName(searchAccountName);
|
2019-09-07 22:26:34 +02:00
|
|
|
_entryListView.setHighlightEntry(highlightEntry);
|
2019-03-25 21:40:08 +01:00
|
|
|
_entryListView.setTapToReveal(tapToReveal);
|
2019-03-26 00:06:39 +01:00
|
|
|
_entryListView.setTapToRevealTime(tapToRevealTime);
|
2019-05-15 21:29:45 +02:00
|
|
|
_entryListView.setViewMode(viewMode);
|
2018-06-09 21:40:18 +02:00
|
|
|
_entryListView.refresh(true);
|
2017-12-10 19:19:48 +01:00
|
|
|
}
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
2016-08-16 00:08:01 +02:00
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
private void startEditProfileActivity(int requestCode, VaultEntry entry, boolean isNew) {
|
2018-06-06 16:15:31 +02:00
|
|
|
Intent intent = new Intent(this, EditEntryActivity.class);
|
2019-12-25 19:21:34 +01:00
|
|
|
intent.putExtra("entry", entry != null ? entry : VaultEntry.getDefault());
|
2018-01-02 21:50:07 +01:00
|
|
|
intent.putExtra("isNew", isNew);
|
2019-08-31 13:46:18 +02:00
|
|
|
intent.putExtra("selectedGroup", _selectedGroup);
|
2019-12-25 19:21:34 +01:00
|
|
|
intent.putExtra("groups", new ArrayList<>(_vault.getGroups()));
|
2018-01-02 21:50:07 +01:00
|
|
|
startActivityForResult(intent, requestCode);
|
|
|
|
}
|
|
|
|
|
2018-06-06 16:15:31 +02:00
|
|
|
private void onScanResult(int resultCode, Intent data) {
|
2017-12-03 16:47:27 +01:00
|
|
|
if (resultCode == RESULT_OK) {
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry entry = (VaultEntry) data.getSerializableExtra("entry");
|
2018-06-06 16:15:31 +02:00
|
|
|
startEditProfileActivity(CODE_ADD_ENTRY, entry, true);
|
2016-08-16 00:08:01 +02:00
|
|
|
}
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 16:15:31 +02:00
|
|
|
private void onAddEntryResult(int resultCode, Intent data) {
|
2017-12-03 16:47:27 +01:00
|
|
|
if (resultCode == RESULT_OK) {
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry entry = (VaultEntry) data.getSerializableExtra("entry");
|
2018-06-06 16:15:31 +02:00
|
|
|
addEntry(entry);
|
2019-12-25 19:21:34 +01:00
|
|
|
saveVault();
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
2017-08-26 15:47:57 +02:00
|
|
|
}
|
|
|
|
|
2018-06-06 16:15:31 +02:00
|
|
|
private void onEditEntryResult(int resultCode, Intent data) {
|
2017-12-27 22:04:22 +01:00
|
|
|
if (resultCode == RESULT_OK) {
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry entry = (VaultEntry) data.getSerializableExtra("entry");
|
2018-12-11 11:44:36 +01:00
|
|
|
if (data.getBooleanExtra("delete", false)) {
|
|
|
|
deleteEntry(entry);
|
|
|
|
} else {
|
2018-01-02 14:36:56 +01:00
|
|
|
// this profile has been serialized/deserialized and is no longer the same instance it once was
|
2018-06-06 16:15:31 +02:00
|
|
|
// to deal with this, the replaceEntry functions are used
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry oldEntry = _vault.replaceEntry(entry);
|
Introduce UUIDMap for storing objects that are keyed by a UUID
This patch introduces the new ``UUIDMap`` type, reducing code duplication and
making UUID lookups faster. We currently already use UUIDs as the identifier for
the ``DatabaseEntry`` and ``Slot`` types, but the way lookups by UUID work are
kind of ugly, as we simply iterate over the list until we find a match. As we're
probably going to have more types like this soon (groups and icons, for
example), I figured it'd be good to abstract this away into a separate type and
make it a map instead of a list.
The only thing that has gotten slower is the ``swap`` method. The internal
``LinkedHashMap`` retains insertion order with a linked list, but does not know
about the position of the values, so we basically have to copy the entire map to
simply swap two values. I don't think it's too big of a deal, because swap
operations still take less than a millisecond even with large vaults, but
suggestions for improving this are welcome.
I had to update gradle and JUnit to be able to use the new ``assertThrows``
assertion method, so this patch includes that as well.
2019-06-10 18:25:44 +02:00
|
|
|
_entryListView.replaceEntry(oldEntry, entry);
|
2019-12-25 19:21:34 +01:00
|
|
|
saveVault();
|
2018-01-01 22:53:10 +01:00
|
|
|
}
|
2017-12-27 22:04:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-06 16:15:31 +02:00
|
|
|
private void onEnterEntryResult(int resultCode, Intent data) {
|
2017-12-30 00:26:16 +01:00
|
|
|
if (resultCode == RESULT_OK) {
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry entry = (VaultEntry) data.getSerializableExtra("entry");
|
2018-06-06 16:15:31 +02:00
|
|
|
addEntry(entry);
|
2019-12-25 19:21:34 +01:00
|
|
|
saveVault();
|
2017-12-30 00:26:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-19 23:10:18 +02:00
|
|
|
private void onScanImageResult(int resultCode, Intent intent) {
|
|
|
|
if (resultCode == RESULT_OK) {
|
|
|
|
Uri inputFile = (intent.getData());
|
|
|
|
Bitmap bitmap;
|
|
|
|
|
|
|
|
try {
|
|
|
|
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
|
|
|
|
|
|
|
|
try (InputStream inputStream = getContentResolver().openInputStream(inputFile)) {
|
|
|
|
bitmap = BitmapFactory.decodeStream(inputStream, null, bmOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
|
|
|
|
bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
|
|
|
|
|
|
|
|
LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
|
|
|
|
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
|
|
|
|
|
|
|
|
Reader reader = new MultiFormatReader();
|
|
|
|
Result result = reader.decode(binaryBitmap);
|
|
|
|
|
|
|
|
GoogleAuthInfo info = GoogleAuthInfo.parseUri(result.getText());
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry entry = new VaultEntry(info);
|
2019-04-19 23:10:18 +02:00
|
|
|
|
|
|
|
startEditProfileActivity(CODE_ADD_ENTRY, entry, true);
|
|
|
|
} catch (NotFoundException | IOException | ChecksumException | FormatException | GoogleAuthInfoException e) {
|
|
|
|
Toast.makeText(this, getString(R.string.unable_to_read_qrcode), Toast.LENGTH_SHORT).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-11 11:44:36 +01:00
|
|
|
private void updateGroupFilterMenu() {
|
|
|
|
SubMenu menu = _menu.findItem(R.id.action_filter).getSubMenu();
|
|
|
|
for (int i = menu.size() - 1; i >= 0; i--) {
|
|
|
|
MenuItem item = menu.getItem(i);
|
|
|
|
if (item.getItemId() == R.id.menu_filter_all) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
menu.removeItem(item.getItemId());
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the group no longer exists, switch back to 'All'
|
2019-12-25 19:21:34 +01:00
|
|
|
TreeSet<String> groups = _vault.getGroups();
|
2019-08-31 13:46:18 +02:00
|
|
|
if (_selectedGroup != null && !groups.contains(_selectedGroup)) {
|
2018-12-11 11:44:36 +01:00
|
|
|
menu.findItem(R.id.menu_filter_all).setChecked(true);
|
|
|
|
setGroupFilter(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String group : groups) {
|
|
|
|
MenuItem item = menu.add(R.id.action_filter_group, Menu.NONE, Menu.NONE, group);
|
2019-08-31 13:46:18 +02:00
|
|
|
if (group.equals(_selectedGroup)) {
|
2018-12-11 11:44:36 +01:00
|
|
|
item.setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 23:02:48 +02:00
|
|
|
if (groups.size() > 0) {
|
|
|
|
menu.add(R.id.action_filter_group, Menu.NONE, 10, R.string.filter_ungrouped);
|
|
|
|
}
|
|
|
|
|
2018-12-11 11:44:36 +01:00
|
|
|
menu.setGroupCheckable(R.id.action_filter_group, true, true);
|
|
|
|
}
|
|
|
|
|
2019-05-15 21:29:45 +02:00
|
|
|
private void updateSortCategoryMenu() {
|
|
|
|
SortCategory category = getPreferences().getCurrentSortCategory();
|
|
|
|
_menu.findItem(category.getMenuItem()).setChecked(true);
|
|
|
|
}
|
|
|
|
|
2018-12-11 11:44:36 +01:00
|
|
|
private void setGroupFilter(String group) {
|
2018-12-17 23:09:07 +01:00
|
|
|
getSupportActionBar().setSubtitle(group);
|
2019-08-31 13:46:18 +02:00
|
|
|
_selectedGroup = group;
|
2019-05-15 21:29:45 +02:00
|
|
|
_entryListView.setGroupFilter(group, true);
|
2019-03-31 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
private void addEntry(VaultEntry entry) {
|
|
|
|
_vault.addEntry(entry);
|
2018-06-06 16:15:31 +02:00
|
|
|
_entryListView.addEntry(entry);
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onDoIntroResult(int resultCode, Intent data) {
|
|
|
|
if (resultCode == IntroActivity.RESULT_EXCEPTION) {
|
|
|
|
// TODO: user feedback
|
|
|
|
Exception e = (Exception) data.getSerializableExtra("exception");
|
2019-04-04 14:07:36 +02:00
|
|
|
throw new RuntimeException(e);
|
2017-08-06 16:03:36 +02:00
|
|
|
}
|
2016-11-13 18:21:00 +01:00
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultFileCredentials creds = (VaultFileCredentials) data.getSerializableExtra("creds");
|
|
|
|
unlockVault(creds);
|
2017-08-06 18:15:47 +02:00
|
|
|
}
|
|
|
|
|
2017-12-25 19:02:46 +01:00
|
|
|
private void onDecryptResult(int resultCode, Intent intent) {
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultFileCredentials creds = (VaultFileCredentials) intent.getSerializableExtra("creds");
|
|
|
|
boolean unlocked = unlockVault(creds);
|
2019-05-26 23:52:20 +02:00
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
// save the vault in case a slot was repaired
|
2019-05-26 23:52:20 +02:00
|
|
|
if (unlocked && intent.getBooleanExtra("repairedSlot", false)) {
|
2019-12-25 19:21:34 +01:00
|
|
|
_vault.setCredentials(creds);
|
|
|
|
saveVault();
|
2019-05-26 23:52:20 +02:00
|
|
|
}
|
2017-08-06 18:15:47 +02:00
|
|
|
|
2017-12-03 16:47:27 +01:00
|
|
|
doShortcutActions();
|
|
|
|
}
|
|
|
|
|
2017-12-25 19:02:46 +01:00
|
|
|
private void startScanActivity() {
|
2018-06-09 19:23:30 +02:00
|
|
|
if (!PermissionHelper.request(this, CODE_PERM_CAMERA, Manifest.permission.CAMERA)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-25 19:02:46 +01:00
|
|
|
Intent scannerActivity = new Intent(getApplicationContext(), ScannerActivity.class);
|
2018-06-06 16:15:31 +02:00
|
|
|
startActivityForResult(scannerActivity, CODE_SCAN);
|
2017-12-25 19:02:46 +01:00
|
|
|
}
|
|
|
|
|
2019-07-03 18:57:03 +02:00
|
|
|
private void startScanImageActivity() {
|
|
|
|
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
|
|
|
|
galleryIntent.setDataAndType(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
|
|
|
|
|
|
|
|
Intent chooserIntent = Intent.createChooser(galleryIntent, getString(R.string.select_picture));
|
|
|
|
startActivityForResult(Intent.createChooser(chooserIntent, getString(R.string.select_picture)), CODE_SCAN_IMAGE);
|
|
|
|
}
|
|
|
|
|
2019-04-08 23:13:11 +02:00
|
|
|
private void doShortcutActions() {
|
2017-12-03 16:47:27 +01:00
|
|
|
Intent intent = getIntent();
|
2017-12-25 19:02:46 +01:00
|
|
|
String action = intent.getStringExtra("action");
|
2019-12-25 19:21:34 +01:00
|
|
|
if (action == null || _vault.isLocked()) {
|
2019-04-08 23:13:11 +02:00
|
|
|
return;
|
2017-12-03 16:47:27 +01:00
|
|
|
}
|
|
|
|
|
2017-12-25 19:02:46 +01:00
|
|
|
switch (action) {
|
|
|
|
case "scan":
|
|
|
|
startScanActivity();
|
2017-12-03 16:47:27 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-12-25 20:01:58 +01:00
|
|
|
|
|
|
|
intent.removeExtra("action");
|
2016-08-16 00:08:01 +02:00
|
|
|
}
|
2016-08-16 14:14:17 +02:00
|
|
|
|
2019-08-02 22:36:12 +02:00
|
|
|
private void handleDeeplink() {
|
2019-12-25 19:21:34 +01:00
|
|
|
if (_vault.isLocked()) {
|
2019-08-02 22:36:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-10 23:10:11 +02:00
|
|
|
|
2019-08-02 22:36:12 +02:00
|
|
|
Intent intent = getIntent();
|
|
|
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
|
Uri uri = intent.getData();
|
|
|
|
getIntent().setData(null);
|
|
|
|
getIntent().setAction(null);
|
|
|
|
|
|
|
|
GoogleAuthInfo info = null;
|
|
|
|
try {
|
|
|
|
info = GoogleAuthInfo.parseUri(uri);
|
|
|
|
} catch (GoogleAuthInfoException e) {
|
|
|
|
Toast.makeText(this, getString(R.string.unable_to_read_qrcode), Toast.LENGTH_SHORT).show();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info != null) {
|
2019-12-25 19:21:34 +01:00
|
|
|
VaultEntry entry = new VaultEntry(info);
|
2019-08-02 22:36:12 +02:00
|
|
|
startEditProfileActivity(CODE_ADD_ENTRY, entry, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-09-30 01:08:03 +02:00
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2017-12-24 21:42:08 +01:00
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
if (_vault.isLocked()) {
|
|
|
|
// start the intro if the vault file doesn't exist
|
|
|
|
if (!_vault.isLoaded() && !_vault.fileExists()) {
|
|
|
|
// the vault doesn't exist, start the intro
|
2018-06-09 20:23:39 +02:00
|
|
|
if (getPreferences().isIntroDone()) {
|
2018-10-09 23:13:51 +02:00
|
|
|
Toast.makeText(this, getString(R.string.vault_not_found), Toast.LENGTH_SHORT).show();
|
2018-06-09 20:23:39 +02:00
|
|
|
}
|
|
|
|
Intent intro = new Intent(this, IntroActivity.class);
|
|
|
|
startActivityForResult(intro, CODE_DO_INTRO);
|
|
|
|
return;
|
|
|
|
} else {
|
2019-12-25 19:21:34 +01:00
|
|
|
unlockVault(null);
|
2018-06-09 20:23:39 +02:00
|
|
|
}
|
|
|
|
} else if (_loaded) {
|
2018-12-11 11:44:36 +01:00
|
|
|
// update the list of groups in the filter menu
|
|
|
|
if (_menu != null) {
|
|
|
|
updateGroupFilterMenu();
|
|
|
|
}
|
|
|
|
|
2018-06-09 20:23:39 +02:00
|
|
|
// refresh all codes to prevent showing old ones
|
2019-05-15 21:29:45 +02:00
|
|
|
_entryListView.refresh(false);
|
2018-06-09 20:23:39 +02:00
|
|
|
} else {
|
|
|
|
loadEntries();
|
|
|
|
}
|
|
|
|
|
2019-08-02 22:36:12 +02:00
|
|
|
handleDeeplink();
|
2018-06-09 20:23:39 +02:00
|
|
|
updateLockIcon();
|
2019-04-08 23:13:11 +02:00
|
|
|
doShortcutActions();
|
2016-09-30 01:08:03 +02:00
|
|
|
}
|
|
|
|
|
2019-04-07 18:18:50 +02:00
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2019-09-10 23:10:11 +02:00
|
|
|
if (!_searchView.isIconified() || _searchSubmitted) {
|
2019-05-30 02:07:30 +02:00
|
|
|
_searchSubmitted = false;
|
|
|
|
_entryListView.setSearchFilter(null);
|
|
|
|
|
|
|
|
collapseSearchView();
|
|
|
|
setTitle("Aegis");
|
2019-08-31 13:46:18 +02:00
|
|
|
setGroupFilter(_selectedGroup);
|
2019-05-30 02:07:30 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-07 18:18:50 +02:00
|
|
|
if (_app.isAutoLockEnabled()) {
|
2019-05-12 17:12:09 +02:00
|
|
|
_app.lock();
|
2019-06-22 12:12:26 +02:00
|
|
|
return;
|
2019-04-07 18:18:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
super.onBackPressed();
|
|
|
|
}
|
|
|
|
|
2020-01-04 20:38:40 +01:00
|
|
|
private void deleteEntries(List<VaultEntry> entries) {
|
|
|
|
for (VaultEntry entry: entries) {
|
|
|
|
VaultEntry oldEntry = _vault.removeEntry(entry);
|
|
|
|
_entryListView.removeEntry(oldEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveVault();
|
|
|
|
}
|
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
private void deleteEntry(VaultEntry entry) {
|
|
|
|
VaultEntry oldEntry = _vault.removeEntry(entry);
|
|
|
|
saveVault();
|
2017-12-12 21:08:30 +01:00
|
|
|
|
Introduce UUIDMap for storing objects that are keyed by a UUID
This patch introduces the new ``UUIDMap`` type, reducing code duplication and
making UUID lookups faster. We currently already use UUIDs as the identifier for
the ``DatabaseEntry`` and ``Slot`` types, but the way lookups by UUID work are
kind of ugly, as we simply iterate over the list until we find a match. As we're
probably going to have more types like this soon (groups and icons, for
example), I figured it'd be good to abstract this away into a separate type and
make it a map instead of a list.
The only thing that has gotten slower is the ``swap`` method. The internal
``LinkedHashMap`` retains insertion order with a linked list, but does not know
about the position of the values, so we basically have to copy the entire map to
simply swap two values. I don't think it's too big of a deal, because swap
operations still take less than a millisecond even with large vaults, but
suggestions for improving this are welcome.
I had to update gradle and JUnit to be able to use the new ``assertThrows``
assertion method, so this patch includes that as well.
2019-06-10 18:25:44 +02:00
|
|
|
_entryListView.removeEntry(oldEntry);
|
2016-11-01 22:16:54 +01:00
|
|
|
}
|
|
|
|
|
2016-08-16 14:14:17 +02:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2017-08-26 21:15:53 +02:00
|
|
|
_menu = menu;
|
2016-08-16 14:14:17 +02:00
|
|
|
getMenuInflater().inflate(R.menu.menu_main, menu);
|
2017-08-26 21:15:53 +02:00
|
|
|
updateLockIcon();
|
2018-12-12 16:20:35 +01:00
|
|
|
if (_loaded) {
|
|
|
|
updateGroupFilterMenu();
|
2019-05-15 21:29:45 +02:00
|
|
|
updateSortCategoryMenu();
|
2018-12-12 16:20:35 +01:00
|
|
|
}
|
2019-05-30 02:07:30 +02:00
|
|
|
|
|
|
|
MenuItem searchViewMenuItem = menu.findItem(R.id.mi_search);
|
|
|
|
|
|
|
|
_searchView = (SearchView) searchViewMenuItem.getActionView();
|
2019-09-10 23:10:11 +02:00
|
|
|
_searchView.setFocusable(false);
|
|
|
|
_searchView.setQueryHint(getString(R.string.search));
|
|
|
|
_searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onQueryTextSubmit(String s) {
|
|
|
|
setTitle(getString(R.string.search));
|
|
|
|
getSupportActionBar().setSubtitle(s);
|
|
|
|
_searchSubmitted = true;
|
|
|
|
collapseSearchView();
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-30 02:07:30 +02:00
|
|
|
|
2019-09-10 23:10:11 +02:00
|
|
|
@Override
|
|
|
|
public boolean onQueryTextChange(String s) {
|
|
|
|
if (!_searchSubmitted) {
|
|
|
|
_entryListView.setSearchFilter(s);
|
2019-05-30 02:07:30 +02:00
|
|
|
}
|
2019-09-10 23:10:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
_searchView.setOnSearchClickListener(v -> {
|
|
|
|
if (_searchSubmitted) {
|
|
|
|
_searchSubmitted = false;
|
|
|
|
_entryListView.setSearchFilter(null);
|
|
|
|
}
|
|
|
|
});
|
2019-05-30 02:07:30 +02:00
|
|
|
|
2016-08-16 14:14:17 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2017-08-14 00:04:06 +02:00
|
|
|
switch (item.getItemId()) {
|
2019-09-05 00:24:33 +02:00
|
|
|
case R.id.action_settings: {
|
2018-02-09 17:31:07 +01:00
|
|
|
Intent intent = new Intent(this, PreferencesActivity.class);
|
|
|
|
startActivityForResult(intent, CODE_PREFERENCES);
|
2017-08-14 00:04:06 +02:00
|
|
|
return true;
|
2019-09-05 00:24:33 +02:00
|
|
|
}
|
|
|
|
case R.id.action_about: {
|
|
|
|
Intent intent = new Intent(this, AboutActivity.class);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
}
|
2017-08-14 00:04:06 +02:00
|
|
|
case R.id.action_lock:
|
2019-05-12 17:12:09 +02:00
|
|
|
_app.lock();
|
2017-08-14 00:04:06 +02:00
|
|
|
return true;
|
|
|
|
default:
|
2018-12-11 11:44:36 +01:00
|
|
|
if (item.getGroupId() == R.id.action_filter_group) {
|
|
|
|
item.setChecked(true);
|
|
|
|
|
|
|
|
String group = null;
|
|
|
|
if (item.getItemId() != R.id.menu_filter_all) {
|
|
|
|
group = item.getTitle().toString();
|
|
|
|
}
|
|
|
|
setGroupFilter(group);
|
|
|
|
}
|
2019-03-31 19:57:45 +02:00
|
|
|
|
|
|
|
if (item.getGroupId() == R.id.action_sort_category) {
|
|
|
|
item.setChecked(true);
|
|
|
|
|
|
|
|
SortCategory sortCategory;
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_sort_alphabetically:
|
|
|
|
sortCategory = SortCategory.ISSUER;
|
|
|
|
break;
|
|
|
|
case R.id.menu_sort_alphabetically_reverse:
|
2019-05-15 21:29:45 +02:00
|
|
|
sortCategory = SortCategory.ISSUER_REVERSED;
|
2019-03-31 19:57:45 +02:00
|
|
|
break;
|
|
|
|
case R.id.menu_sort_alphabetically_name:
|
|
|
|
sortCategory = SortCategory.ACCOUNT;
|
|
|
|
break;
|
|
|
|
case R.id.menu_sort_alphabetically_name_reverse:
|
2019-05-15 21:29:45 +02:00
|
|
|
sortCategory = SortCategory.ACCOUNT_REVERSED;
|
2019-03-31 19:57:45 +02:00
|
|
|
break;
|
2019-03-31 22:34:25 +02:00
|
|
|
case R.id.menu_sort_custom:
|
2019-03-31 19:57:45 +02:00
|
|
|
default:
|
2019-03-31 21:23:14 +02:00
|
|
|
sortCategory = SortCategory.CUSTOM;
|
2019-03-31 19:57:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-05-15 21:29:45 +02:00
|
|
|
_entryListView.setSortCategory(sortCategory, true);
|
2019-03-31 22:34:25 +02:00
|
|
|
getPreferences().setCurrentSortCategory(sortCategory);
|
2019-03-31 19:57:45 +02:00
|
|
|
}
|
2017-08-14 00:04:06 +02:00
|
|
|
return super.onOptionsItemSelected(item);
|
2016-08-16 14:14:17 +02:00
|
|
|
}
|
|
|
|
}
|
2016-09-30 01:08:03 +02:00
|
|
|
|
2019-05-30 02:07:30 +02:00
|
|
|
private void collapseSearchView() {
|
|
|
|
_searchView.setQuery(null, false);
|
|
|
|
_searchView.setIconified(true);
|
|
|
|
}
|
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
private boolean unlockVault(VaultFileCredentials creds) {
|
2018-06-09 20:23:39 +02:00
|
|
|
try {
|
2019-12-25 19:21:34 +01:00
|
|
|
if (!_vault.isLoaded()) {
|
|
|
|
_vault.load();
|
2018-06-09 20:23:39 +02:00
|
|
|
}
|
2019-12-25 19:21:34 +01:00
|
|
|
if (_vault.isLocked()) {
|
2018-10-06 22:23:38 +02:00
|
|
|
if (creds == null) {
|
2018-06-09 20:23:39 +02:00
|
|
|
startAuthActivity();
|
2019-05-26 23:52:20 +02:00
|
|
|
return false;
|
2018-06-09 20:23:39 +02:00
|
|
|
} else {
|
2019-12-25 19:21:34 +01:00
|
|
|
_vault.unlock(creds);
|
2018-06-09 20:23:39 +02:00
|
|
|
}
|
|
|
|
}
|
2019-12-25 19:21:34 +01:00
|
|
|
} catch (VaultManagerException e) {
|
2018-10-09 23:13:51 +02:00
|
|
|
Toast.makeText(this, getString(R.string.decryption_error), Toast.LENGTH_LONG).show();
|
2018-06-09 20:23:39 +02:00
|
|
|
startAuthActivity();
|
2019-05-26 23:52:20 +02:00
|
|
|
return false;
|
2018-06-09 20:23:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
loadEntries();
|
2019-05-26 23:52:20 +02:00
|
|
|
return true;
|
2018-06-09 20:23:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void loadEntries() {
|
|
|
|
// load all entries
|
2019-12-25 19:21:34 +01:00
|
|
|
List<VaultEntry> entries = new ArrayList<VaultEntry>(_vault.getEntries());
|
2019-03-31 19:57:45 +02:00
|
|
|
_entryListView.addEntries(entries);
|
2019-05-15 21:29:45 +02:00
|
|
|
_entryListView.runEntriesAnimation();
|
2018-06-09 20:23:39 +02:00
|
|
|
_loaded = true;
|
|
|
|
}
|
|
|
|
|
2017-12-24 21:42:08 +01:00
|
|
|
private void startAuthActivity() {
|
|
|
|
Intent intent = new Intent(this, AuthActivity.class);
|
2019-12-25 19:21:34 +01:00
|
|
|
intent.putExtra("slots", _vault.getFileHeader().getSlots());
|
2019-05-12 17:12:09 +02:00
|
|
|
intent.putExtra("requiresUnlock", false);
|
2019-09-06 21:41:55 +02:00
|
|
|
intent.putExtra("cancelAction", CancelAction.KILL);
|
2017-12-24 21:42:08 +01:00
|
|
|
startActivityForResult(intent, CODE_DECRYPT);
|
|
|
|
}
|
|
|
|
|
2019-12-25 19:21:34 +01:00
|
|
|
private void saveVault() {
|
2017-05-03 21:08:38 +02:00
|
|
|
try {
|
2019-12-25 19:21:34 +01:00
|
|
|
_vault.save();
|
|
|
|
} catch (VaultManagerException e) {
|
2018-10-09 23:13:51 +02:00
|
|
|
Toast.makeText(this, getString(R.string.saving_error), Toast.LENGTH_LONG).show();
|
2016-11-13 18:21:00 +01:00
|
|
|
}
|
2017-08-06 18:15:47 +02:00
|
|
|
}
|
2016-11-13 18:21:00 +01:00
|
|
|
|
2017-08-26 21:15:53 +02:00
|
|
|
private void updateLockIcon() {
|
2019-12-25 19:21:34 +01:00
|
|
|
// hide the lock icon if the vault is not unlocked
|
|
|
|
if (_menu != null && !_vault.isLocked()) {
|
2017-08-26 21:15:53 +02:00
|
|
|
MenuItem item = _menu.findItem(R.id.action_lock);
|
2019-12-25 19:21:34 +01:00
|
|
|
item.setVisible(_vault.isEncryptionEnabled());
|
2017-08-26 21:15:53 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-12 01:50:00 +01:00
|
|
|
|
|
|
|
@Override
|
2019-12-25 19:21:34 +01:00
|
|
|
public void onEntryClick(VaultEntry entry) {
|
2020-01-04 20:38:40 +01:00
|
|
|
if (_actionMode != null) {
|
|
|
|
if (_selectedEntries.isEmpty()) {
|
2019-08-03 16:15:39 +02:00
|
|
|
_actionMode.finish();
|
2020-01-04 20:38:40 +01:00
|
|
|
} else {
|
|
|
|
setIsMultipleSelected(_selectedEntries.size() > 1);
|
2019-08-03 16:15:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-07 18:59:49 +01:00
|
|
|
copyEntryCode(entry);
|
2019-08-03 16:15:39 +02:00
|
|
|
}
|
|
|
|
|
2020-01-04 20:38:40 +01:00
|
|
|
@Override
|
|
|
|
public void onSelect(VaultEntry entry) {
|
|
|
|
_selectedEntries.add(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDeselect(VaultEntry entry) {
|
|
|
|
_selectedEntries.remove(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setIsMultipleSelected(boolean multipleSelected) {
|
|
|
|
_entryListView.setIsLongPressDragEnabled(!multipleSelected);
|
|
|
|
_actionMode.getMenu().findItem(R.id.action_edit).setVisible(!multipleSelected);
|
|
|
|
_actionMode.getMenu().findItem(R.id.action_copy).setVisible(!multipleSelected);
|
|
|
|
}
|
|
|
|
|
2019-08-03 16:15:39 +02:00
|
|
|
@Override
|
2019-12-25 19:21:34 +01:00
|
|
|
public void onLongEntryClick(VaultEntry entry) {
|
2020-01-04 20:38:40 +01:00
|
|
|
if (!_selectedEntries.isEmpty()) {
|
2019-08-03 16:15:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-04 20:38:40 +01:00
|
|
|
_selectedEntries.add(entry);
|
2019-08-03 16:15:39 +02:00
|
|
|
_entryListView.setActionModeState(true, entry);
|
|
|
|
_actionMode = this.startSupportActionMode(_actionModeCallbacks);
|
2017-12-12 01:50:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-12-25 19:21:34 +01:00
|
|
|
public void onEntryMove(VaultEntry entry1, VaultEntry entry2) {
|
|
|
|
_vault.swapEntries(entry1, entry2);
|
2017-12-12 01:50:00 +01:00
|
|
|
}
|
2017-12-12 03:14:26 +01:00
|
|
|
|
|
|
|
@Override
|
2019-12-25 19:21:34 +01:00
|
|
|
public void onEntryDrop(VaultEntry entry) {
|
|
|
|
saveVault();
|
2017-12-12 03:14:26 +01:00
|
|
|
}
|
2018-06-06 17:23:40 +02:00
|
|
|
|
|
|
|
@Override
|
2019-12-25 19:21:34 +01:00
|
|
|
public void onEntryChange(VaultEntry entry) {
|
|
|
|
saveVault();
|
2018-06-06 17:23:40 +02:00
|
|
|
}
|
2019-03-26 00:53:32 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(int dx, int dy) {
|
2019-04-20 01:25:04 +02:00
|
|
|
_fabScrollHelper.onScroll(dx, dy);
|
2019-03-26 00:53:32 +01:00
|
|
|
}
|
2019-05-12 17:12:09 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLocked() {
|
2019-08-03 16:15:39 +02:00
|
|
|
if (_actionMode != null) {
|
|
|
|
_actionMode.finish();
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:12:09 +02:00
|
|
|
_entryListView.clearEntries();
|
|
|
|
_loaded = false;
|
2019-05-26 21:45:36 +02:00
|
|
|
|
|
|
|
if (isOpen()) {
|
|
|
|
startAuthActivity();
|
|
|
|
}
|
|
|
|
|
2019-05-12 17:12:09 +02:00
|
|
|
super.onLocked();
|
|
|
|
}
|
2019-08-03 16:15:39 +02:00
|
|
|
|
2019-12-26 22:17:32 +01:00
|
|
|
private void copyEntryCode(VaultEntry entry) {
|
2019-12-07 18:59:49 +01:00
|
|
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
ClipData clip = ClipData.newPlainText("text/plain", entry.getInfo().getOtp());
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
}
|
|
|
|
|
2019-08-03 16:15:39 +02:00
|
|
|
private class ActionModeCallbacks implements ActionMode.Callback {
|
|
|
|
@Override
|
|
|
|
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
|
|
MenuInflater inflater = mode.getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.menu_action_mode, menu);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
2019-12-07 18:59:49 +01:00
|
|
|
case R.id.action_copy:
|
2020-01-04 20:38:40 +01:00
|
|
|
copyEntryCode(_selectedEntries.get(0));
|
2019-12-07 18:59:49 +01:00
|
|
|
mode.finish();
|
|
|
|
return true;
|
|
|
|
|
2019-08-03 16:15:39 +02:00
|
|
|
case R.id.action_edit:
|
2020-01-04 20:38:40 +01:00
|
|
|
startEditProfileActivity(CODE_EDIT_ENTRY, _selectedEntries.get(0), false);
|
2019-08-03 16:15:39 +02:00
|
|
|
mode.finish();
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case R.id.action_delete:
|
2020-01-04 20:38:40 +01:00
|
|
|
Dialogs.showDeleteEntriesDialog(MainActivity.this, (d, which) -> {
|
|
|
|
deleteEntries(_selectedEntries);
|
|
|
|
|
|
|
|
for (VaultEntry entry : _selectedEntries) {
|
|
|
|
if (entry.getGroup() != null) {
|
|
|
|
if (!_vault.getGroups().contains(entry.getGroup())) {
|
|
|
|
updateGroupFilterMenu();
|
|
|
|
}
|
2019-08-03 16:15:39 +02:00
|
|
|
}
|
|
|
|
}
|
2020-01-04 20:38:40 +01:00
|
|
|
|
2019-08-03 16:15:39 +02:00
|
|
|
mode.finish();
|
2020-01-04 20:38:40 +01:00
|
|
|
}, _selectedEntries.size());
|
2019-08-03 16:15:39 +02:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyActionMode(ActionMode mode) {
|
|
|
|
_entryListView.setActionModeState(false, null);
|
2020-01-04 20:38:40 +01:00
|
|
|
_selectedEntries.clear();
|
2019-08-03 16:15:39 +02:00
|
|
|
_actionMode = null;
|
|
|
|
}
|
|
|
|
}
|
2016-08-15 21:29:41 +02:00
|
|
|
}
|