show 'clear devices' button underneath own devices

This commit is contained in:
Daniel Gultsch 2016-11-18 21:49:52 +01:00
parent a86a36f570
commit 2b9b3be3f1
7 changed files with 55 additions and 53 deletions

View File

@ -15,6 +15,7 @@ import android.widget.Toast;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.XmppActivity; import eu.siacs.conversations.ui.XmppActivity;
import eu.siacs.conversations.ui.widget.Switch; import eu.siacs.conversations.ui.widget.Switch;
@ -60,9 +61,17 @@ public abstract class OmemoActivity extends XmppActivity {
} }
} }
protected boolean addFingerprintRow(LinearLayout keys, final Account account, final String fingerprint, boolean highlight) { protected void addFingerprintRow(LinearLayout keys, final XmppAxolotlSession session, boolean highlight) {
final FingerprintStatus status = account.getAxolotlService().getFingerprintTrust(fingerprint); final Account account = session.getAccount();
return status != null && addFingerprintRowWithListeners(keys, account, fingerprint, highlight, status, true, true, new CompoundButton.OnCheckedChangeListener() { final String fingerprint = session.getFingerprint();
addFingerprintRowWithListeners(keys,
session.getAccount(),
session.getFingerprint(),
highlight,
session.getTrust(),
true,
true,
new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked)); account.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(isChecked));
@ -70,7 +79,7 @@ public abstract class OmemoActivity extends XmppActivity {
}); });
} }
protected boolean addFingerprintRowWithListeners(LinearLayout keys, final Account account, protected void addFingerprintRowWithListeners(LinearLayout keys, final Account account,
final String fingerprint, final String fingerprint,
boolean highlight, boolean highlight,
FingerprintStatus status, FingerprintStatus status,
@ -78,9 +87,6 @@ public abstract class OmemoActivity extends XmppActivity {
boolean undecidedNeedEnablement, boolean undecidedNeedEnablement,
CompoundButton.OnCheckedChangeListener CompoundButton.OnCheckedChangeListener
onCheckedChangeListener) { onCheckedChangeListener) {
if (status.isCompromised()) {
return false;
}
View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false); View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key); TextView key = (TextView) view.findViewById(R.id.key);
TextView keyType = (TextView) view.findViewById(R.id.key_type); TextView keyType = (TextView) view.findViewById(R.id.key_type);
@ -184,7 +190,6 @@ public abstract class OmemoActivity extends XmppActivity {
key.setText(CryptoHelper.prettifyFingerprint(fingerprint.substring(2))); key.setText(CryptoHelper.prettifyFingerprint(fingerprint.substring(2)));
keys.addView(view); keys.addView(view);
return true;
} }
public void showPurgeKeyDialog(final Account account, final String fingerprint) { public void showPurgeKeyDialog(final Account account, final String fingerprint) {

View File

@ -303,7 +303,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
private Set<XmppAxolotlSession> findSessionsForContact(Contact contact) { public Set<XmppAxolotlSession> findSessionsForContact(Contact contact) {
AxolotlAddress contactAddress = getAddressForJid(contact.getJid()); AxolotlAddress contactAddress = getAddressForJid(contact.getJid());
return new HashSet<>(this.sessions.getAll(contactAddress).values()); return new HashSet<>(this.sessions.getAll(contactAddress).values());
} }
@ -316,22 +316,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
return sessions; return sessions;
} }
public Set<String> getFingerprintsForOwnSessions() {
Set<String> fingerprints = new HashSet<>();
for (XmppAxolotlSession session : findOwnSessions()) {
fingerprints.add(session.getFingerprint());
}
return fingerprints;
}
public Set<String> getFingerprintsForContact(final Contact contact) {
Set<String> fingerprints = new HashSet<>();
for (XmppAxolotlSession session : findSessionsForContact(contact)) {
fingerprints.add(session.getFingerprint());
}
return fingerprints;
}
private boolean hasAny(Jid jid) { private boolean hasAny(Jid jid) {
return sessions.hasAny(getAddressForJid(jid)); return sessions.hasAny(getAddressForJid(jid));
} }
@ -417,12 +401,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
deviceIds.add(getOwnDeviceId()); deviceIds.add(getOwnDeviceId());
IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds); IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds);
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Wiping all other devices from Pep:" + publish); Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Wiping all other devices from Pep:" + publish);
mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() { mXmppConnectionService.sendIqPacket(account, publish, null);
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
// TODO: implement this!
}
});
} }
public void purgeKey(final String fingerprint) { public void purgeKey(final String fingerprint) {

View File

@ -132,4 +132,8 @@ public class XmppAxolotlSession {
return null; return null;
} }
} }
public Account getAccount() {
return account;
}
} }

View File

@ -41,6 +41,7 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpEngine; import eu.siacs.conversations.crypto.PgpEngine;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
@ -445,9 +446,12 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
} }
} }
if (Config.supportOmemo()) { if (Config.supportOmemo()) {
for (final String fingerprint : contact.getAccount().getAxolotlService().getFingerprintsForContact(contact)) { for (final XmppAxolotlSession session : contact.getAccount().getAxolotlService().findSessionsForContact(contact)) {
boolean highlight = fingerprint.equals(messageFingerprint); if (!session.getTrust().isCompromised()) {
hasKeys |= addFingerprintRow(keys, contact.getAccount(), fingerprint, highlight); boolean highlight = session.getFingerprint().equals(messageFingerprint);
hasKeys = true;
addFingerprintRow(keys, session, highlight);
}
} }
} }
if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) { if (Config.supportOpenPgp() && contact.getPgpKeyId() != 0) {

View File

@ -44,6 +44,7 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.OmemoActivity; import eu.siacs.conversations.OmemoActivity;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested; import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
@ -251,6 +252,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private TableRow mPushRow; private TableRow mPushRow;
private String mSavedInstanceAccount; private String mSavedInstanceAccount;
private boolean mSavedInstanceInit = false; private boolean mSavedInstanceInit = false;
private Button mClearDevicesButton;
public void refreshUiReal() { public void refreshUiReal() {
invalidateOptionsMenu(); invalidateOptionsMenu();
@ -502,6 +504,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mNamePort = (LinearLayout) findViewById(R.id.name_port); this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
this.mHostname = (EditText) findViewById(R.id.hostname); this.mHostname = (EditText) findViewById(R.id.hostname);
this.mHostname.addTextChangedListener(mTextWatcher); this.mHostname.addTextChangedListener(mTextWatcher);
this.mClearDevicesButton = (Button) findViewById(R.id.clear_devices);
this.mClearDevicesButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showWipePepDialog();
}
});
this.mPort = (EditText) findViewById(R.id.port); this.mPort = (EditText) findViewById(R.id.port);
this.mPort.setText("5222"); this.mPort.setText("5222");
this.mPort.addTextChangedListener(mTextWatcher); this.mPort.addTextChangedListener(mTextWatcher);
@ -540,7 +549,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more); final MenuItem showMoreInfo = menu.findItem(R.id.action_server_info_show_more);
final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server); final MenuItem changePassword = menu.findItem(R.id.action_change_password_on_server);
final MenuItem showPassword = menu.findItem(R.id.action_show_password); final MenuItem showPassword = menu.findItem(R.id.action_show_password);
final MenuItem clearDevices = menu.findItem(R.id.action_clear_devices);
final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate); final MenuItem renewCertificate = menu.findItem(R.id.action_renew_certificate);
final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs); final MenuItem mamPrefs = menu.findItem(R.id.action_mam_prefs);
final MenuItem changePresence = menu.findItem(R.id.action_change_presence); final MenuItem changePresence = menu.findItem(R.id.action_change_presence);
@ -554,17 +562,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
changePassword.setVisible(false); changePassword.setVisible(false);
} }
mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam()); mamPrefs.setVisible(mAccount.getXmppConnection().getFeatures().mam());
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
if (otherDevices == null || otherDevices.isEmpty() || !Config.supportOmemo()) {
clearDevices.setVisible(false);
}
changePresence.setVisible(manuallyChangePresence()); changePresence.setVisible(manuallyChangePresence());
} else { } else {
showQrCode.setVisible(false); showQrCode.setVisible(false);
showBlocklist.setVisible(false); showBlocklist.setVisible(false);
showMoreInfo.setVisible(false); showMoreInfo.setVisible(false);
changePassword.setVisible(false); changePassword.setVisible(false);
clearDevices.setVisible(false);
mamPrefs.setVisible(false); mamPrefs.setVisible(false);
changePresence.setVisible(false); changePresence.setVisible(false);
} }
@ -706,9 +709,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
case R.id.action_mam_prefs: case R.id.action_mam_prefs:
editMamPrefs(); editMamPrefs();
break; break;
case R.id.action_clear_devices:
showWipePepDialog();
break;
case R.id.action_renew_certificate: case R.id.action_renew_certificate:
renewCertificate(); renewCertificate();
break; break;
@ -904,15 +904,21 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
} }
boolean hasKeys = false; boolean hasKeys = false;
keys.removeAllViews(); keys.removeAllViews();
for (final String fingerprint : mAccount.getAxolotlService().getFingerprintsForOwnSessions()) { for(XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
if (ownAxolotlFingerprint.equals(fingerprint)) { if (!session.getTrust().isCompromised()) {
continue; boolean highlight = session.getFingerprint().equals(messageFingerprint);
addFingerprintRow(keys,session,highlight);
hasKeys = true;
} }
boolean highlight = fingerprint.equals(messageFingerprint);
hasKeys |= addFingerprintRow(keys, mAccount, fingerprint, highlight);
} }
if (hasKeys && Config.supportOmemo()) { if (hasKeys && Config.supportOmemo()) {
keysCard.setVisibility(View.VISIBLE); keysCard.setVisibility(View.VISIBLE);
Set<Integer> otherDevices = mAccount.getAxolotlService().getOwnDeviceIds();
if (otherDevices == null || otherDevices.isEmpty()) {
mClearDevicesButton.setVisibility(View.GONE);
} else {
mClearDevicesButton.setVisibility(View.VISIBLE);
}
} else { } else {
keysCard.setVisibility(View.GONE); keysCard.setVisibility(View.GONE);
} }

View File

@ -591,7 +591,7 @@
android:background="?attr/infocard_border" android:background="?attr/infocard_border"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/infocard_padding" android:padding="@dimen/infocard_padding"
android:visibility="gone"> android:visibility="visible">
<TextView <TextView
android:id="@+id/other_device_keys_title" android:id="@+id/other_device_keys_title"
@ -610,6 +610,14 @@
android:orientation="vertical" android:orientation="vertical"
android:showDividers="middle"> android:showDividers="middle">
</LinearLayout> </LinearLayout>
<Button
android:id="@+id/clear_devices"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clear_other_devices"
android:layout_gravity="center_horizontal"
android:textColor="@color/accent"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@ -43,10 +43,6 @@
android:showAsAction="never" android:showAsAction="never"
android:title="@string/change_password"/> android:title="@string/change_password"/>
<item
android:id="@+id/action_clear_devices"
android:showAsAction="never"
android:title="@string/clear_other_devices"/>
<item <item
android:id="@+id/action_settings" android:id="@+id/action_settings"
android:orderInCategory="100" android:orderInCategory="100"