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 eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.ui.XmppActivity;
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) {
final FingerprintStatus status = account.getAxolotlService().getFingerprintTrust(fingerprint);
return status != null && addFingerprintRowWithListeners(keys, account, fingerprint, highlight, status, true, true, new CompoundButton.OnCheckedChangeListener() {
protected void addFingerprintRow(LinearLayout keys, final XmppAxolotlSession session, boolean highlight) {
final Account account = session.getAccount();
final String fingerprint = session.getFingerprint();
addFingerprintRowWithListeners(keys,
session.getAccount(),
session.getFingerprint(),
highlight,
session.getTrust(),
true,
true,
new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean 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,
boolean highlight,
FingerprintStatus status,
@ -78,9 +87,6 @@ public abstract class OmemoActivity extends XmppActivity {
boolean undecidedNeedEnablement,
CompoundButton.OnCheckedChangeListener
onCheckedChangeListener) {
if (status.isCompromised()) {
return false;
}
View view = getLayoutInflater().inflate(R.layout.contact_key, keys, false);
TextView key = (TextView) view.findViewById(R.id.key);
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)));
keys.addView(view);
return true;
}
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());
return new HashSet<>(this.sessions.getAll(contactAddress).values());
}
@ -316,22 +316,6 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
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) {
return sessions.hasAny(getAddressForJid(jid));
}
@ -417,12 +401,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
deviceIds.add(getOwnDeviceId());
IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIds);
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Wiping all other devices from Pep:" + publish);
mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
// TODO: implement this!
}
});
mXmppConnectionService.sendIqPacket(account, publish, null);
}
public void purgeKey(final String fingerprint) {

View File

@ -132,4 +132,8 @@ public class XmppAxolotlSession {
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.axolotl.AxolotlService;
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.Contact;
import eu.siacs.conversations.entities.ListItem;
@ -445,9 +446,12 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
}
}
if (Config.supportOmemo()) {
for (final String fingerprint : contact.getAccount().getAxolotlService().getFingerprintsForContact(contact)) {
boolean highlight = fingerprint.equals(messageFingerprint);
hasKeys |= addFingerprintRow(keys, contact.getAccount(), fingerprint, highlight);
for (final XmppAxolotlSession session : contact.getAccount().getAxolotlService().findSessionsForContact(contact)) {
if (!session.getTrust().isCompromised()) {
boolean highlight = session.getFingerprint().equals(messageFingerprint);
hasKeys = true;
addFingerprintRow(keys, session, highlight);
}
}
}
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.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.services.XmppConnectionService.OnCaptchaRequested;
import eu.siacs.conversations.services.XmppConnectionService;
@ -251,6 +252,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
private TableRow mPushRow;
private String mSavedInstanceAccount;
private boolean mSavedInstanceInit = false;
private Button mClearDevicesButton;
public void refreshUiReal() {
invalidateOptionsMenu();
@ -502,6 +504,13 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
this.mNamePort = (LinearLayout) findViewById(R.id.name_port);
this.mHostname = (EditText) findViewById(R.id.hostname);
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.setText("5222");
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 changePassword = menu.findItem(R.id.action_change_password_on_server);
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 mamPrefs = menu.findItem(R.id.action_mam_prefs);
final MenuItem changePresence = menu.findItem(R.id.action_change_presence);
@ -554,17 +562,12 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
changePassword.setVisible(false);
}
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());
} else {
showQrCode.setVisible(false);
showBlocklist.setVisible(false);
showMoreInfo.setVisible(false);
changePassword.setVisible(false);
clearDevices.setVisible(false);
mamPrefs.setVisible(false);
changePresence.setVisible(false);
}
@ -706,9 +709,6 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
case R.id.action_mam_prefs:
editMamPrefs();
break;
case R.id.action_clear_devices:
showWipePepDialog();
break;
case R.id.action_renew_certificate:
renewCertificate();
break;
@ -904,15 +904,21 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
}
boolean hasKeys = false;
keys.removeAllViews();
for (final String fingerprint : mAccount.getAxolotlService().getFingerprintsForOwnSessions()) {
if (ownAxolotlFingerprint.equals(fingerprint)) {
continue;
for(XmppAxolotlSession session : mAccount.getAxolotlService().findOwnSessions()) {
if (!session.getTrust().isCompromised()) {
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()) {
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 {
keysCard.setVisibility(View.GONE);
}

View File

@ -591,7 +591,7 @@
android:background="?attr/infocard_border"
android:orientation="vertical"
android:padding="@dimen/infocard_padding"
android:visibility="gone">
android:visibility="visible">
<TextView
android:id="@+id/other_device_keys_title"
@ -610,6 +610,14 @@
android:orientation="vertical"
android:showDividers="middle">
</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>
</ScrollView>

View File

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