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