(WIP) ImportKeys: Check if key is already present and verified
This commit is contained in:
@@ -173,7 +173,7 @@ public class CachedPublicKeyRing extends KeyRing {
|
|||||||
Object data = mProviderHelper.getGenericData(mUri,
|
Object data = mProviderHelper.getGenericData(mUri,
|
||||||
KeychainContract.KeyRings.VERIFIED,
|
KeychainContract.KeyRings.VERIFIED,
|
||||||
ProviderHelper.FIELD_TYPE_INTEGER);
|
ProviderHelper.FIELD_TYPE_INTEGER);
|
||||||
return (Integer) data;
|
return ((Long) data).intValue();
|
||||||
} catch(ProviderHelper.NotFoundException e) {
|
} catch(ProviderHelper.NotFoundException e) {
|
||||||
throw new PgpKeyNotFoundException(e);
|
throw new PgpKeyNotFoundException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ import org.sufficientlysecure.keychain.keyimport.processing.ImportKeysResultList
|
|||||||
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
|
import org.sufficientlysecure.keychain.ui.ViewKeyActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||||
@@ -58,23 +61,41 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
private boolean mNonInteractive;
|
private boolean mNonInteractive;
|
||||||
|
|
||||||
private List<ImportKeysListEntry> mData;
|
private List<ImportKeysListEntry> mData;
|
||||||
|
|
||||||
private KeyState[] mKeyStates;
|
private KeyState[] mKeyStates;
|
||||||
private int mCurrent;
|
private int mCurrent;
|
||||||
|
|
||||||
|
private ProviderHelper mProviderHelper;
|
||||||
|
|
||||||
public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener,
|
public ImportKeysAdapter(FragmentActivity activity, ImportKeysListener listener,
|
||||||
boolean nonInteractive) {
|
boolean nonInteractive) {
|
||||||
|
|
||||||
this.mActivity = activity;
|
mActivity = activity;
|
||||||
this.mListener = listener;
|
mListener = listener;
|
||||||
this.mNonInteractive = nonInteractive;
|
mNonInteractive = nonInteractive;
|
||||||
|
|
||||||
|
mProviderHelper = new ProviderHelper(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(List<ImportKeysListEntry> data) {
|
public void setData(List<ImportKeysListEntry> data) {
|
||||||
this.mData = data;
|
mData = data;
|
||||||
this.mKeyStates = new KeyState[data.size()];
|
|
||||||
|
mKeyStates = new KeyState[data.size()];
|
||||||
for (int i = 0; i < mKeyStates.length; i++) {
|
for (int i = 0; i < mKeyStates.length; i++) {
|
||||||
mKeyStates[i] = new KeyState();
|
mKeyStates[i] = new KeyState();
|
||||||
|
|
||||||
|
ImportKeysListEntry entry = mData.get(i);
|
||||||
|
long keyId = KeyFormattingUtils.convertKeyIdHexToKeyId(entry.getKeyIdHex());
|
||||||
|
try {
|
||||||
|
KeyRing keyRing;
|
||||||
|
if (entry.isSecretKey()) {
|
||||||
|
keyRing = mProviderHelper.getCanonicalizedSecretKeyRing(keyId);
|
||||||
|
} else {
|
||||||
|
keyRing = mProviderHelper.getCachedPublicKeyRing(keyId);
|
||||||
|
}
|
||||||
|
mKeyStates[i].mAlreadyPresent = true;
|
||||||
|
mKeyStates[i].mVerified = keyRing.getVerified() > 0;
|
||||||
|
} catch (ProviderHelper.NotFoundException | PgpKeyNotFoundException ignored) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is only one key, get it automatically
|
// If there is only one key, get it automatically
|
||||||
@@ -259,6 +280,9 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class KeyState {
|
private class KeyState {
|
||||||
|
public boolean mAlreadyPresent = false;
|
||||||
|
public boolean mVerified = false;
|
||||||
|
|
||||||
public boolean mDownloaded = false;
|
public boolean mDownloaded = false;
|
||||||
public boolean mShowed = false;
|
public boolean mShowed = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,9 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingBottom="8dp">
|
android:paddingBottom="8dp">
|
||||||
|
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingBottom="16dp"
|
android:paddingBottom="16dp"
|
||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
@@ -35,6 +34,7 @@
|
|||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentLeft="true"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/extra_container"
|
android:id="@+id/extra_container"
|
||||||
|
|||||||
Reference in New Issue
Block a user