Clean up listing of Autocrypt along identities
This commit is contained in:
@@ -39,7 +39,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
|||||||
import org.sufficientlysecure.keychain.ui.adapter.IdentityAdapter.ViewHolder;
|
import org.sufficientlysecure.keychain.ui.adapter.IdentityAdapter.ViewHolder;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.LinkedIdInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.LinkedIdInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.TrustIdInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.AutocryptPeerInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.UserIdInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.UserIdInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||||
@@ -79,8 +79,8 @@ public class IdentityAdapter extends RecyclerView.Adapter<ViewHolder> {
|
|||||||
|
|
||||||
int viewType = getItemViewType(position);
|
int viewType = getItemViewType(position);
|
||||||
if (viewType == VIEW_TYPE_USER_ID) {
|
if (viewType == VIEW_TYPE_USER_ID) {
|
||||||
if (info instanceof TrustIdInfo) {
|
if (info instanceof AutocryptPeerInfo) {
|
||||||
((UserIdViewHolder) holder).bind((TrustIdInfo) info);
|
((UserIdViewHolder) holder).bind((AutocryptPeerInfo) info);
|
||||||
} else {
|
} else {
|
||||||
((UserIdViewHolder) holder).bind((UserIdInfo) info);
|
((UserIdViewHolder) holder).bind((UserIdInfo) info);
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ public class IdentityAdapter extends RecyclerView.Adapter<ViewHolder> {
|
|||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
IdentityInfo info = data.get(position);
|
IdentityInfo info = data.get(position);
|
||||||
if (info instanceof UserIdInfo || info instanceof TrustIdInfo) {
|
if (info instanceof UserIdInfo || info instanceof AutocryptPeerInfo) {
|
||||||
return VIEW_TYPE_USER_ID;
|
return VIEW_TYPE_USER_ID;
|
||||||
} else if (info instanceof LinkedIdInfo) {
|
} else if (info instanceof LinkedIdInfo) {
|
||||||
return VIEW_TYPE_LINKED_ID;
|
return VIEW_TYPE_LINKED_ID;
|
||||||
@@ -236,21 +236,21 @@ public class IdentityAdapter extends RecyclerView.Adapter<ViewHolder> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(TrustIdInfo info) {
|
public void bind(AutocryptPeerInfo info) {
|
||||||
if (info.getUserIdInfo() != null) {
|
if (info.getUserIdInfo() != null) {
|
||||||
bindUserIdInfo(info.getUserIdInfo());
|
bindUserIdInfo(info.getUserIdInfo());
|
||||||
} else {
|
} else {
|
||||||
vName.setVisibility(View.GONE);
|
vName.setVisibility(View.GONE);
|
||||||
vComment.setVisibility(View.GONE);
|
vComment.setVisibility(View.GONE);
|
||||||
|
|
||||||
vAddress.setText(info.getTrustId());
|
vAddress.setText(info.getIdentity());
|
||||||
vAddress.setTypeface(null, Typeface.NORMAL);
|
vAddress.setTypeface(null, Typeface.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
vIcon.setImageDrawable(info.getAppIcon());
|
vIcon.setImageDrawable(info.getAppIcon());
|
||||||
vMore.setVisibility(View.VISIBLE);
|
vMore.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
itemView.setClickable(info.getTrustIdIntent() != null);
|
itemView.setClickable(info.getAutocryptPeerIntent() != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(UserIdInfo info) {
|
public void bind(UserIdInfo info) {
|
||||||
|
|||||||
@@ -31,14 +31,11 @@ import android.database.Cursor;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.AsyncTaskLoader;
|
import android.support.v4.content.AsyncTaskLoader;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import com.google.auto.value.AutoValue;
|
import com.google.auto.value.AutoValue;
|
||||||
import org.openintents.openpgp.util.OpenPgpApi;
|
import org.openintents.openpgp.util.OpenPgpApi;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.linked.LinkedAttribute;
|
import org.sufficientlysecure.keychain.linked.LinkedAttribute;
|
||||||
import org.sufficientlysecure.keychain.linked.UriAttribute;
|
import org.sufficientlysecure.keychain.linked.UriAttribute;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeer;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAutocryptPeer;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
@@ -76,6 +73,15 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
|
|||||||
|
|
||||||
private static final String USER_IDS_WHERE = UserPackets.IS_REVOKED + " = 0";
|
private static final String USER_IDS_WHERE = UserPackets.IS_REVOKED + " = 0";
|
||||||
|
|
||||||
|
private static final String[] AUTOCRYPT_PEER_PROJECTION = new String[] {
|
||||||
|
ApiAutocryptPeer._ID,
|
||||||
|
ApiAutocryptPeer.PACKAGE_NAME,
|
||||||
|
ApiAutocryptPeer.IDENTIFIER,
|
||||||
|
};
|
||||||
|
private static final int INDEX_PACKAGE_NAME = 1;
|
||||||
|
private static final int INDEX_IDENTIFIER = 2;
|
||||||
|
|
||||||
|
|
||||||
private final ContentResolver contentResolver;
|
private final ContentResolver contentResolver;
|
||||||
private final PackageIconGetter packageIconGetter;
|
private final PackageIconGetter packageIconGetter;
|
||||||
private final long masterKeyId;
|
private final long masterKeyId;
|
||||||
@@ -85,6 +91,7 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
|
|||||||
|
|
||||||
private ForceLoadContentObserver identityObserver;
|
private ForceLoadContentObserver identityObserver;
|
||||||
|
|
||||||
|
|
||||||
public IdentityLoader(Context context, ContentResolver contentResolver, long masterKeyId, boolean showLinkedIds) {
|
public IdentityLoader(Context context, ContentResolver contentResolver, long masterKeyId, boolean showLinkedIds) {
|
||||||
super(context);
|
super(context);
|
||||||
|
|
||||||
@@ -106,42 +113,36 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
|
|||||||
loadLinkedIds(identities);
|
loadLinkedIds(identities);
|
||||||
}
|
}
|
||||||
loadUserIds(identities);
|
loadUserIds(identities);
|
||||||
correlateOrAddTrustIds(identities);
|
correlateOrAddAutocryptPeers(identities);
|
||||||
|
|
||||||
return Collections.unmodifiableList(identities);
|
return Collections.unmodifiableList(identities);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] TRUST_IDS_PROJECTION = new String[] {
|
private void correlateOrAddAutocryptPeers(ArrayList<IdentityInfo> identities) {
|
||||||
ApiAutocryptPeer._ID,
|
|
||||||
ApiAutocryptPeer.PACKAGE_NAME,
|
|
||||||
ApiAutocryptPeer.IDENTIFIER,
|
|
||||||
};
|
|
||||||
private static final int INDEX_PACKAGE_NAME = 1;
|
|
||||||
private static final int INDEX_TRUST_ID = 2;
|
|
||||||
|
|
||||||
private void correlateOrAddTrustIds(ArrayList<IdentityInfo> identities) {
|
|
||||||
Cursor cursor = contentResolver.query(ApiAutocryptPeer.buildByMasterKeyId(masterKeyId),
|
Cursor cursor = contentResolver.query(ApiAutocryptPeer.buildByMasterKeyId(masterKeyId),
|
||||||
TRUST_IDS_PROJECTION, null, null, null);
|
AUTOCRYPT_PEER_PROJECTION, null, null, null);
|
||||||
if (cursor == null) {
|
if (cursor == null) {
|
||||||
Timber.e("Error loading trust ids!");
|
Timber.e("Error loading Autocrypt peers");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
String packageName = cursor.getString(INDEX_PACKAGE_NAME);
|
String packageName = cursor.getString(INDEX_PACKAGE_NAME);
|
||||||
String autocryptPeer = cursor.getString(INDEX_TRUST_ID);
|
String autocryptPeer = cursor.getString(INDEX_IDENTIFIER);
|
||||||
|
|
||||||
Drawable drawable = packageIconGetter.getDrawableForPackageName(packageName);
|
Drawable drawable = packageIconGetter.getDrawableForPackageName(packageName);
|
||||||
Intent autocryptPeerIntent = getTrustIdActivityIntentIfResolvable(packageName, autocryptPeer);
|
Intent autocryptPeerIntent = getAutocryptPeerActivityIntentIfResolvable(packageName, autocryptPeer);
|
||||||
|
|
||||||
UserIdInfo associatedUserIdInfo = findUserIdMatchingTrustId(identities, autocryptPeer);
|
UserIdInfo associatedUserIdInfo = findUserIdMatchingAutocryptPeer(identities, autocryptPeer);
|
||||||
if (associatedUserIdInfo != null) {
|
if (associatedUserIdInfo != null) {
|
||||||
int position = identities.indexOf(associatedUserIdInfo);
|
int position = identities.indexOf(associatedUserIdInfo);
|
||||||
TrustIdInfo autocryptPeerInfo = TrustIdInfo.create(associatedUserIdInfo, autocryptPeer, packageName, drawable, autocryptPeerIntent);
|
AutocryptPeerInfo autocryptPeerInfo = AutocryptPeerInfo
|
||||||
|
.create(associatedUserIdInfo, autocryptPeer, packageName, drawable, autocryptPeerIntent);
|
||||||
identities.set(position, autocryptPeerInfo);
|
identities.set(position, autocryptPeerInfo);
|
||||||
} else {
|
} else {
|
||||||
TrustIdInfo autocryptPeerInfo = TrustIdInfo.create(autocryptPeer, packageName, drawable, autocryptPeerIntent);
|
AutocryptPeerInfo autocryptPeerInfo = AutocryptPeerInfo
|
||||||
|
.create(autocryptPeer, packageName, drawable, autocryptPeerIntent);
|
||||||
identities.add(autocryptPeerInfo);
|
identities.add(autocryptPeerInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +151,7 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent getTrustIdActivityIntentIfResolvable(String packageName, String autocryptPeer) {
|
private Intent getAutocryptPeerActivityIntentIfResolvable(String packageName, String autocryptPeer) {
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.setAction("org.autocrypt.PEER_ACTION");
|
intent.setAction("org.autocrypt.PEER_ACTION");
|
||||||
intent.setPackage(packageName);
|
intent.setPackage(packageName);
|
||||||
@@ -165,7 +166,7 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UserIdInfo findUserIdMatchingTrustId(List<IdentityInfo> identities, String autocryptPeer) {
|
private static UserIdInfo findUserIdMatchingAutocryptPeer(List<IdentityInfo> identities, String autocryptPeer) {
|
||||||
for (IdentityInfo identityInfo : identities) {
|
for (IdentityInfo identityInfo : identities) {
|
||||||
if (identityInfo instanceof UserIdInfo) {
|
if (identityInfo instanceof UserIdInfo) {
|
||||||
UserIdInfo userIdInfo = (UserIdInfo) identityInfo;
|
UserIdInfo userIdInfo = (UserIdInfo) identityInfo;
|
||||||
@@ -304,28 +305,28 @@ public class IdentityLoader extends AsyncTaskLoader<List<IdentityInfo>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AutoValue
|
@AutoValue
|
||||||
public abstract static class TrustIdInfo implements IdentityInfo {
|
public abstract static class AutocryptPeerInfo implements IdentityInfo {
|
||||||
public abstract int getRank();
|
public abstract int getRank();
|
||||||
public abstract int getVerified();
|
public abstract int getVerified();
|
||||||
public abstract boolean isPrimary();
|
public abstract boolean isPrimary();
|
||||||
|
|
||||||
public abstract String getTrustId();
|
public abstract String getIdentity();
|
||||||
public abstract String getPackageName();
|
public abstract String getPackageName();
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract Drawable getAppIcon();
|
public abstract Drawable getAppIcon();
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract UserIdInfo getUserIdInfo();
|
public abstract UserIdInfo getUserIdInfo();
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract Intent getTrustIdIntent();
|
public abstract Intent getAutocryptPeerIntent();
|
||||||
|
|
||||||
static TrustIdInfo create(UserIdInfo userIdInfo, String autocryptPeer, String packageName,
|
static AutocryptPeerInfo create(UserIdInfo userIdInfo, String autocryptPeer, String packageName,
|
||||||
Drawable appIcon, Intent autocryptPeerIntent) {
|
Drawable appIcon, Intent autocryptPeerIntent) {
|
||||||
return new AutoValue_IdentityLoader_TrustIdInfo(userIdInfo.getRank(), userIdInfo.getVerified(),
|
return new AutoValue_IdentityLoader_AutocryptPeerInfo(userIdInfo.getRank(), userIdInfo.getVerified(),
|
||||||
userIdInfo.isPrimary(), autocryptPeer, packageName, appIcon, userIdInfo, autocryptPeerIntent);
|
userIdInfo.isPrimary(), autocryptPeer, packageName, appIcon, userIdInfo, autocryptPeerIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
static TrustIdInfo create(String autocryptPeer, String packageName, Drawable appIcon, Intent autocryptPeerIntent) {
|
static AutocryptPeerInfo create(String autocryptPeer, String packageName, Drawable appIcon, Intent autocryptPeerIntent) {
|
||||||
return new AutoValue_IdentityLoader_TrustIdInfo(
|
return new AutoValue_IdentityLoader_AutocryptPeerInfo(
|
||||||
0, Certs.VERIFIED_SELF, false, autocryptPeer, packageName, appIcon, null, autocryptPeerIntent);
|
0, Certs.VERIFIED_SELF, false, autocryptPeer, packageName, appIcon, null, autocryptPeerIntent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import org.sufficientlysecure.keychain.ui.keyview.LinkedIdViewFragment;
|
|||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.IdentityInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.LinkedIdInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.LinkedIdInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.TrustIdInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.AutocryptPeerInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.UserIdInfo;
|
import org.sufficientlysecure.keychain.ui.keyview.loader.IdentityLoader.UserIdInfo;
|
||||||
import org.sufficientlysecure.keychain.ui.linked.LinkedIdWizard;
|
import org.sufficientlysecure.keychain.ui.linked.LinkedIdWizard;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
@@ -129,8 +129,8 @@ public class IdentitiesPresenter implements LoaderCallbacks<List<IdentityInfo>>
|
|||||||
showLinkedId((LinkedIdInfo) info);
|
showLinkedId((LinkedIdInfo) info);
|
||||||
} else if (info instanceof UserIdInfo) {
|
} else if (info instanceof UserIdInfo) {
|
||||||
showUserIdInfo((UserIdInfo) info);
|
showUserIdInfo((UserIdInfo) info);
|
||||||
} else if (info instanceof TrustIdInfo) {
|
} else if (info instanceof AutocryptPeerInfo) {
|
||||||
Intent autocryptPeerIntent = ((TrustIdInfo) info).getTrustIdIntent();
|
Intent autocryptPeerIntent = ((AutocryptPeerInfo) info).getAutocryptPeerIntent();
|
||||||
if (autocryptPeerIntent != null) {
|
if (autocryptPeerIntent != null) {
|
||||||
viewKeyMvpView.startActivity(autocryptPeerIntent);
|
viewKeyMvpView.startActivity(autocryptPeerIntent);
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ public class IdentitiesPresenter implements LoaderCallbacks<List<IdentityInfo>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClickForgetIdentity(int position) {
|
public void onClickForgetIdentity(int position) {
|
||||||
TrustIdInfo info = (TrustIdInfo) identitiesAdapter.getInfo(position);
|
AutocryptPeerInfo info = (AutocryptPeerInfo) identitiesAdapter.getInfo(position);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
Timber.e("got a 'forget' click on a bad trust id");
|
Timber.e("got a 'forget' click on a bad trust id");
|
||||||
return;
|
return;
|
||||||
@@ -184,7 +184,7 @@ public class IdentitiesPresenter implements LoaderCallbacks<List<IdentityInfo>>
|
|||||||
|
|
||||||
AutocryptPeerDataAccessObject autocryptPeerDao =
|
AutocryptPeerDataAccessObject autocryptPeerDao =
|
||||||
new AutocryptPeerDataAccessObject(context, info.getPackageName());
|
new AutocryptPeerDataAccessObject(context, info.getPackageName());
|
||||||
autocryptPeerDao.delete(info.getTrustId());
|
autocryptPeerDao.delete(info.getIdentity());
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IdentitiesMvpView {
|
public interface IdentitiesMvpView {
|
||||||
|
|||||||
Reference in New Issue
Block a user