Lock TrustKeys if no trusted keys are available
This commit is contained in:
parent
012f036840
commit
19a0ae42d6
|
@ -281,6 +281,10 @@ public class AxolotlService {
|
|||
return mXmppConnectionService.databaseBackend.loadIdentityKeys(account, bareJid, Trust.UNDECIDED);
|
||||
}
|
||||
|
||||
public long getContactNumTrustedKeys(String bareJid) {
|
||||
return mXmppConnectionService.databaseBackend.numTrustedKeys(account, bareJid);
|
||||
}
|
||||
|
||||
// --------------------------------------
|
||||
// SessionStore
|
||||
// --------------------------------------
|
||||
|
@ -672,6 +676,10 @@ public class AxolotlService {
|
|||
return axolotlStore.getContactUndecidedKeys(contact.getJid().toBareJid().toString());
|
||||
}
|
||||
|
||||
public long getNumTrustedKeys(Contact contact) {
|
||||
return axolotlStore.getContactNumTrustedKeys(contact.getJid().toBareJid().toString());
|
||||
}
|
||||
|
||||
private AxolotlAddress getAddressForJid(Jid jid) {
|
||||
return new AxolotlAddress(jid.toString(), 0);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.siacs.conversations.persistance;
|
|||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteCantOpenDatabaseException;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
@ -858,6 +859,19 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
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) {
|
||||
storeIdentityKey(account, name, own, fingerprint, base64Serialized, AxolotlService.SQLiteAxolotlStore.Trust.UNDECIDED);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import eu.siacs.conversations.xmpp.jid.Jid;
|
|||
public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailable {
|
||||
private Jid accountJid;
|
||||
private Jid contactJid;
|
||||
private boolean hasOtherTrustedKeys = false;
|
||||
private boolean hasPendingFetches = false;
|
||||
|
||||
private Contact contact;
|
||||
private TextView ownKeysTitle;
|
||||
|
@ -153,6 +155,17 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||
foreignKeysTitle.setText(contactJid.toString());
|
||||
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) {
|
||||
|
@ -183,9 +196,12 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||
foreignKeysToTrust.clear();
|
||||
getFingerprints(account);
|
||||
|
||||
if(account.getAxolotlService().getNumTrustedKeys(contact) > 0) {
|
||||
hasOtherTrustedKeys = true;
|
||||
}
|
||||
Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contactJid, false);
|
||||
if(account.getAxolotlService().hasPendingKeyFetches(conversation)) {
|
||||
lock();
|
||||
hasPendingFetches = true;
|
||||
}
|
||||
|
||||
populateView();
|
||||
|
@ -199,7 +215,7 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||
public void run() {
|
||||
final Account account = xmppConnectionService
|
||||
.findAccountByJid(accountJid);
|
||||
unlock();
|
||||
hasPendingFetches = false;
|
||||
getFingerprints(account);
|
||||
refreshUi();
|
||||
}
|
||||
|
@ -221,13 +237,19 @@ public class TrustKeysActivity extends XmppActivity implements OnNewKeysAvailabl
|
|||
|
||||
private void unlock() {
|
||||
mSaveButton.setEnabled(true);
|
||||
mSaveButton.setText(getString(R.string.done));
|
||||
mSaveButton.setTextColor(getPrimaryTextColor());
|
||||
}
|
||||
|
||||
private void lock() {
|
||||
mSaveButton.setEnabled(false);
|
||||
mSaveButton.setText(getString(R.string.fetching_keys));
|
||||
mSaveButton.setTextColor(getSecondaryTextColor());
|
||||
}
|
||||
|
||||
private void setDone() {
|
||||
mSaveButton.setText(getString(R.string.done));
|
||||
}
|
||||
|
||||
private void setFetching() {
|
||||
mSaveButton.setText(getString(R.string.fetching_keys));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue