diff options
author | Christian Schneppe <christian@pix-art.de> | 2016-09-28 21:40:51 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2016-09-28 21:40:51 +0200 |
commit | 314bc117bff752d98f51be8cd2f82285d32393f1 (patch) | |
tree | f5f0498bee3fba5c386ea3ca8f2537c0e0c7a7fe /src/main/java/de/pixart | |
parent | 6fdaed555ebcb18a313b78cebeab5c376861544d (diff) |
expert 'setting' to remove omemo identity
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java | 4 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/SettingsActivity.java | 62 |
2 files changed, 61 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 79eecd869..05d4d33ea 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -1183,10 +1183,6 @@ public class DatabaseBackend extends SQLiteOpenHelper { storeIdentityKey(account, account.getJid().toBareJid().toString(), true, identityKeyPair.getPublicKey().getFingerprint().replaceAll("\\s", ""), Base64.encodeToString(identityKeyPair.serialize(), Base64.DEFAULT), XmppAxolotlSession.Trust.TRUSTED); } - public void recreateAxolotlDb() { - recreateAxolotlDb(getWritableDatabase()); - } - public void recreateAxolotlDb(SQLiteDatabase db) { Log.d(Config.LOGTAG, AxolotlService.LOGPREFIX + " : " + ">>> (RE)CREATING AXOLOTL DATABASE <<<"); db.execSQL("DROP TABLE IF EXISTS " + SQLiteAxolotlStore.SESSION_TABLENAME); diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 150a1d779..737f10c86 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -29,6 +29,8 @@ import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; import de.pixart.messenger.services.ExportLogsService; import de.pixart.messenger.xmpp.XmppConnection; +import de.pixart.messenger.xmpp.jid.InvalidJidException; +import de.pixart.messenger.xmpp.jid.Jid; public class SettingsActivity extends XmppActivity implements OnSharedPreferenceChangeListener { @@ -84,7 +86,7 @@ public class SettingsActivity extends XmppActivity implements displayToast(getString(R.string.toast_no_trusted_certs)); return true; } - final ArrayList selectedItems = new ArrayList<Integer>(); + final ArrayList selectedItems = new ArrayList<>(); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this); dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title)); dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, @@ -144,6 +146,64 @@ public class SettingsActivity extends XmppActivity implements return true; } }); + + final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities"); + deleteOmemoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + deleteOmemoIdentities(); + return true; + } + }); + } + + private void deleteOmemoIdentities() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.pref_delete_omemo_identities); + final List<CharSequence> accounts = new ArrayList<>(); + for(Account account : xmppConnectionService.getAccounts()) { + if (!account.isOptionSet(Account.OPTION_DISABLED)) { + accounts.add(account.getJid().toBareJid().toString()); + } + } + final boolean[] checkedItems = new boolean[accounts.size()]; + builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, new DialogInterface.OnMultiChoiceClickListener() { + @Override + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + checkedItems[which] = isChecked; + final AlertDialog alertDialog = (AlertDialog) dialog; + for(boolean item : checkedItems) { + if (item) { + alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true); + return; + } + } + alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); + } + }); + builder.setNegativeButton(R.string.cancel,null); + builder.setPositiveButton(R.string.delete_selected_keys, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + for(int i = 0; i < checkedItems.length; ++i) { + if (checkedItems[i]) { + try { + Jid jid = Jid.fromString(accounts.get(i).toString()); + Account account = xmppConnectionService.findAccountByJid(jid); + if (account != null) { + account.getAxolotlService().regenerateKeys(true); + } + } catch (InvalidJidException e) { + // + } + + } + } + } + }); + AlertDialog dialog = builder.create(); + dialog.show(); + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } @Override |