Lock TrustKeys if no trusted keys are available

This commit is contained in:
Andreas Straub 2015-07-20 14:56:41 +02:00
parent 012f036840
commit 19a0ae42d6
3 changed files with 48 additions and 4 deletions

View File

@ -281,6 +281,10 @@ public class AxolotlService {
return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, Trust.UNDECIDED); return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, Trust.UNDECIDED);
} }
public long getContactNumTrustedKeys(String bareJid) {
return mXmppConnectionService.databaseBackend.numTrustedKeys(account, bareJid);
}
// -------------------------------------- // --------------------------------------
// SessionStore // SessionStore
// -------------------------------------- // --------------------------------------
@ -672,6 +676,10 @@ public class AxolotlService {
return axolotlStore.getContactUndecidedKeys(contact.getJid().toBareJid().toString()); return axolotlStore.getContactUndecidedKeys(contact.getJid().toBareJid().toString());
} }
public long getNumTrustedKeys(Contact contact) {
return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString());
}
private AxolotlAddress getAddressForJid(Jid jid) { private AxolotlAddress getAddressForJid(Jid jid) {
return new AxolotlAddress(jid.toString(), 0); return new AxolotlAddress(jid.toString(), 0);
} }

View File

@ -3,6 +3,7 @@ package eu.siacs.conversations.persistance;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteCantOpenDatabaseException; import android.database.sqlite.SQLiteCantOpenDatabaseException;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
@ -858,6 +859,19 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return identityKeys; return identityKeys;
} }
public long numTrustedKeys(Account account, String name) {
SQLiteDatabase db = getReadableDatabase();
String[] args = {
account.getUuid(),
name
};
return DatabaseUtils.queryNumEntries(db, AxolotlService.SQLiteAxolotlStore.IDENTITIES_TABLENAME,
AxolotlService.SQLiteAxolotlStore.ACCOUNT + " = ?"
+ " AND " + AxolotlService.SQLiteAxolotlStore.NAME + " = ?",
args
);
}
private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized) { private void storeIdentityKey(Account account, String name, boolean own, String fingerprint, String base64Serialized) {
storeIdentityKey(account, name, own, fingerprint, base64Serialized, AxolotlService.SQLiteAxolotlStore.Trust.UNDECIDED); storeIdentityKey(account, name, own, fingerprint, base64Serialized, AxolotlService.SQLiteAxolotlStore.Trust.UNDECIDED);
} }

View File

@ -27,6 +27,8 @@ import eu.siacs.conversations.xmpp.jid.Jid;
public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailable { public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailable {
private Jid accountJid; private Jid accountJid;
private Jid contactJid; private Jid contactJid;
private boolean hasOtherTrustedKeys = false;
private boolean hasPendingFetches = false;
private Contact contact; private Contact contact;
private TextView ownKeysTitle; private TextView ownKeysTitle;
@ -153,6 +155,17 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
foreignKeysTitle.setText(contactJid.toString()); foreignKeysTitle.setText(contactJid.toString());
foreignKeysCard.setVisibility(View.VISIBLE); foreignKeysCard.setVisibility(View.VISIBLE);
} }
if(hasPendingFetches) {
setFetching();
lock();
} else {
if (!hasOtherTrustedKeys && !foreignKeysToTrust.values().contains(true)){
lock();
} else {
unlock();
}
setDone();
}
} }
private void getFingerprints(final Account account) { private void getFingerprints(final Account account) {
@ -183,9 +196,12 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
foreignKeysToTrust.clear(); foreignKeysToTrust.clear();
getFingerprints(account); getFingerprints(account);
if(account.getAxolotlService().getNumTrustedKeys(contact) > 0) {
hasOtherTrustedKeys = true;
}
Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false); Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false);
if(account.getAxolotlService().hasPendingKeyFetches(conversation)) { if(account.getAxolotlService().hasPendingKeyFetches(conversation)) {
lock(); hasPendingFetches = true;
} }
populateView(); populateView();
@ -199,7 +215,7 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
public void run() { public void run() {
final Account account = xmppConnectionService final Account account = xmppConnectionService
.findAccountByJid(accountJid); .findAccountByJid(accountJid);
unlock(); hasPendingFetches = false;
getFingerprints(account); getFingerprints(account);
refreshUi(); refreshUi();
} }
@ -221,13 +237,19 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
private void unlock() { private void unlock() {
mSaveButton.setEnabled(true); mSaveButton.setEnabled(true);
mSaveButton.setText(getString(R.string.done));
mSaveButton.setTextColor(getPrimaryTextColor()); mSaveButton.setTextColor(getPrimaryTextColor());
} }
private void lock() { private void lock() {
mSaveButton.setEnabled(false); mSaveButton.setEnabled(false);
mSaveButton.setText(getString(R.string.fetching_keys));
mSaveButton.setTextColor(getSecondaryTextColor()); mSaveButton.setTextColor(getSecondaryTextColor());
} }
private void setDone() {
mSaveButton.setText(getString(R.string.done));
}
private void setFetching() {
mSaveButton.setText(getString(R.string.fetching_keys));
}
} }