Merge branch 'daquexian-issue_1846'

This commit is contained in:
Dominik Schürmann
2017-01-27 00:53:06 +01:00
18 changed files with 213 additions and 136 deletions

View File

@@ -109,6 +109,40 @@ public class CachedPublicKeyRing extends KeyRing {
return getPrimaryUserId();
}
public String getName() throws PgpKeyNotFoundException {
try {
Object data = mProviderHelper.getGenericData(mUri,
KeyRings.NAME,
ProviderHelper.FIELD_TYPE_STRING);
return (String) data;
} catch(ProviderHelper.NotFoundException e) {
throw new PgpKeyNotFoundException(e);
}
}
public String getEmail() throws PgpKeyNotFoundException {
try {
Object data = mProviderHelper.getGenericData(mUri,
KeyRings.EMAIL,
ProviderHelper.FIELD_TYPE_STRING);
return (String) data;
} catch(ProviderHelper.NotFoundException e) {
throw new PgpKeyNotFoundException(e);
}
}
public String getComment() throws PgpKeyNotFoundException {
try {
Object data = mProviderHelper.getGenericData(mUri,
KeyRings.COMMENT,
ProviderHelper.FIELD_TYPE_STRING);
return (String) data;
} catch(ProviderHelper.NotFoundException e) {
throw new PgpKeyNotFoundException(e);
}
}
@Override
public boolean isRevoked() throws PgpKeyNotFoundException {
try {

View File

@@ -526,6 +526,9 @@ public class KeychainProvider extends ContentProvider {
projectionMap.put(UserPackets.MASTER_KEY_ID, Tables.USER_PACKETS + "." + UserPackets.MASTER_KEY_ID);
projectionMap.put(UserPackets.TYPE, Tables.USER_PACKETS + "." + UserPackets.TYPE);
projectionMap.put(UserPackets.USER_ID, Tables.USER_PACKETS + "." + UserPackets.USER_ID);
projectionMap.put(UserPackets.NAME, Tables.USER_PACKETS + "." + UserPackets.NAME);
projectionMap.put(UserPackets.EMAIL, Tables.USER_PACKETS + "." + UserPackets.EMAIL);
projectionMap.put(UserPackets.COMMENT, Tables.USER_PACKETS + "." + UserPackets.COMMENT);
projectionMap.put(UserPackets.ATTRIBUTE_DATA, Tables.USER_PACKETS + "." + UserPackets.ATTRIBUTE_DATA);
projectionMap.put(UserPackets.RANK, Tables.USER_PACKETS + "." + UserPackets.RANK);
projectionMap.put(UserPackets.IS_PRIMARY, Tables.USER_PACKETS + "." + UserPackets.IS_PRIMARY);

View File

@@ -174,16 +174,6 @@ public class SelectPublicKeyFragment extends RecyclerFragment<SelectEncryptKeyAd
getAdapter().getMasterKeyIds() : new long[0];
}
public String[] getSelectedRawUserIds() {
return getAdapter() != null ?
getAdapter().getRawUserIds() : new String[0];
}
public OpenPgpUtils.UserId[] getSelectedUserIds() {
return getAdapter() != null ?
getAdapter().getUserIds() : new OpenPgpUtils.UserId[0];
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri baseUri = KeyRings.buildUnifiedKeyRingsUri();
@@ -199,6 +189,9 @@ public class SelectPublicKeyFragment extends RecyclerFragment<SelectEncryptKeyAd
KeyRings.VERIFIED,
KeyRings.HAS_DUPLICATE_USER_ID,
KeyRings.CREATION,
KeyRings.NAME,
KeyRings.EMAIL,
KeyRings.COMMENT
};
String inMasterKeyList = null;

View File

@@ -121,6 +121,9 @@ public class SelectSignKeyIdListFragment extends RecyclerFragment<SelectSignKeyA
KeyRings.HAS_ANY_SECRET,
KeyRings.HAS_DUPLICATE_USER_ID,
KeyRings.CREATION,
KeyRings.NAME,
KeyRings.EMAIL,
KeyRings.COMMENT
};
String selection = KeyRings.HAS_ANY_SECRET + " != 0";

View File

@@ -30,7 +30,6 @@ import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import org.openintents.openpgp.util.OpenPgpUtils;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.ui.adapter.KeyCursorAdapter;
@@ -113,34 +112,6 @@ public class SelectEncryptKeyAdapter extends KeyCursorAdapter<SelectEncryptKeyAd
}
}
public String[] getRawUserIds() {
String[] selected = new String[mSelected.size()];
for (int i = 0; i < selected.length; i++) {
int position = mSelected.get(i);
if (!moveCursor(position)) {
return selected;
}
selected[i] = getCursor().getRawUserId();
}
return selected;
}
public OpenPgpUtils.UserId[] getUserIds() {
OpenPgpUtils.UserId[] selected = new OpenPgpUtils.UserId[mSelected.size()];
for (int i = 0; i < selected.length; i++) {
int position = mSelected.get(i);
if (!moveCursor(position)) {
return selected;
}
selected[i] = getCursor().getUserId();
}
return selected;
}
@Override
public void onContentChanged() {
mSelected.clear();
@@ -181,14 +152,15 @@ public class SelectEncryptKeyAdapter extends KeyCursorAdapter<SelectEncryptKeyAd
Context context = itemView.getContext();
{ // set name and stuff, common to both key types
OpenPgpUtils.UserId userIdSplit = cursor.getUserId();
if (userIdSplit.name != null) {
mUserIdText.setText(highlighter.highlight(userIdSplit.name));
String name = cursor.getName();
String email = cursor.getEmail();
if (name != null) {
mUserIdText.setText(highlighter.highlight(name));
} else {
mUserIdText.setText(R.string.user_id_no_name);
}
if (userIdSplit.email != null) {
mUserIdRestText.setText(highlighter.highlight(userIdSplit.email));
if (email != null) {
mUserIdRestText.setText(highlighter.highlight(email));
mUserIdRestText.setVisibility(View.VISIBLE);
} else {
mUserIdRestText.setVisibility(View.GONE);

View File

@@ -141,14 +141,15 @@ public class SelectSignKeyAdapter extends KeyCursorAdapter<CursorAdapter.KeyCurs
Context context = itemView.getContext();
{ // set name and stuff, common to both key types
OpenPgpUtils.UserId userIdSplit = cursor.getUserId();
if (userIdSplit.name != null) {
mUserIdText.setText(highlighter.highlight(userIdSplit.name));
String name = cursor.getName();
String email = cursor.getEmail();
if (name != null) {
mUserIdText.setText(highlighter.highlight(name));
} else {
mUserIdText.setText(R.string.user_id_no_name);
}
if (userIdSplit.email != null) {
mUserIdRestText.setText(highlighter.highlight(userIdSplit.email));
if (email != null) {
mUserIdRestText.setText(highlighter.highlight(email));
mUserIdRestText.setVisibility(View.VISIBLE);
} else {
mUserIdRestText.setVisibility(View.GONE);

View File

@@ -275,6 +275,9 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
KeychainContract.KeyRings.USER_ID,
KeychainContract.KeyRings.VERIFIED,
KeychainContract.KeyRings.HAS_ANY_SECRET,
KeyRings.NAME,
KeyRings.EMAIL,
KeyRings.COMMENT,
};
@SuppressWarnings("unused")
@@ -282,6 +285,9 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
static final int INDEX_USER_ID = 2;
static final int INDEX_VERIFIED = 3;
static final int INDEX_HAS_ANY_SECRET = 4;
static final int INDEX_NAME = 5;
static final int INDEX_EMAIL = 6;
static final int INDEX_COMMENT = 7;
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
@@ -309,15 +315,15 @@ public abstract class DecryptFragment extends Fragment implements LoaderManager.
long signatureKeyId = mSignatureResult.getKeyId();
String userId = data.getString(INDEX_USER_ID);
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit.name != null) {
mSignatureName.setText(userIdSplit.name);
String name = data.getString(INDEX_NAME);
String email = data.getString(INDEX_EMAIL);
if (name != null) {
mSignatureName.setText(name);
} else {
mSignatureName.setText(R.string.user_id_no_name);
}
if (userIdSplit.email != null) {
mSignatureEmail.setText(userIdSplit.email);
if (email != null) {
mSignatureEmail.setText(email);
} else {
mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(
mSignatureResult.getKeyId()));

View File

@@ -93,7 +93,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
try {
HashMap<String, Object> data = new ProviderHelper(this).getUnifiedData(
mMasterKeyIds[0], new String[]{
KeychainContract.KeyRings.USER_ID,
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.IS_REVOKED
}, new int[]{
ProviderHelper.FIELD_TYPE_STRING,
@@ -102,11 +102,10 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
);
String name;
OpenPgpUtils.UserId mainUserId = KeyRing.splitUserId(
(String) data.get(KeychainContract.KeyRings.USER_ID));
if (mainUserId.name != null) {
name = mainUserId.name;
} else {
name = (String) data.get(KeychainContract.KeyRings.NAME);
if (name == null) {
name = getString(R.string.user_id_no_name);
}
@@ -274,7 +273,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
try {
HashMap<String, Object> data = new ProviderHelper(activity).getUnifiedData(
masterKeyId, new String[]{
KeychainContract.KeyRings.USER_ID,
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.HAS_ANY_SECRET
}, new int[]{
ProviderHelper.FIELD_TYPE_STRING,
@@ -282,10 +281,9 @@ public class DeleteKeyDialogActivity extends FragmentActivity {
}
);
String name;
OpenPgpUtils.UserId mainUserId = KeyRing.splitUserId((String) data.get(KeychainContract.KeyRings.USER_ID));
if (mainUserId.name != null) {
name = mainUserId.name;
} else {
name = (String) data.get(KeychainContract.KeyRings.NAME);
if (name == null) {
name = getString(R.string.user_id_no_name);
}

View File

@@ -59,7 +59,10 @@ public class MultiUserIdsFragment extends Fragment implements LoaderManager.Load
KeychainContract.UserPackets.MASTER_KEY_ID,
KeychainContract.UserPackets.USER_ID,
KeychainContract.UserPackets.IS_PRIMARY,
KeychainContract.UserPackets.IS_REVOKED
KeychainContract.UserPackets.IS_REVOKED,
KeychainContract.UserPackets.NAME,
KeychainContract.UserPackets.EMAIL,
KeychainContract.UserPackets.COMMENT,
};
private static final int INDEX_MASTER_KEY_ID = 1;
private static final int INDEX_USER_ID = 2;
@@ -67,6 +70,9 @@ public class MultiUserIdsFragment extends Fragment implements LoaderManager.Load
private static final int INDEX_IS_PRIMARY = 3;
@SuppressWarnings("unused")
private static final int INDEX_IS_REVOKED = 4;
private static final int INDEX_NAME = 5;
private static final int INDEX_EMAIL = 6;
private static final int INDEX_COMMENT = 7;
@Nullable
@Override
@@ -169,14 +175,14 @@ public class MultiUserIdsFragment extends Fragment implements LoaderManager.Load
while (!data.isAfterLast()) {
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
String userId = data.getString(INDEX_USER_ID);
OpenPgpUtils.UserId pieces = KeyRing.splitUserId(userId);
String name = data.getString(INDEX_NAME);
// Two cases:
boolean grouped = masterKeyId == lastMasterKeyId;
boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name);
boolean subGrouped = data.isFirst() || grouped && lastName.equals(name);
// Remember for next loop
lastName = pieces.name;
lastName = name;
Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped"));

View File

@@ -822,7 +822,10 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
KeychainContract.KeyRings.VERIFIED,
KeychainContract.KeyRings.HAS_ANY_SECRET,
KeychainContract.KeyRings.FINGERPRINT,
KeychainContract.KeyRings.HAS_ENCRYPT
KeychainContract.KeyRings.HAS_ENCRYPT,
KeyRings.NAME,
KeyRings.EMAIL,
KeyRings.COMMENT
};
static final int INDEX_MASTER_KEY_ID = 1;
@@ -833,6 +836,9 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
static final int INDEX_HAS_ANY_SECRET = 6;
static final int INDEX_FINGERPRINT = 7;
static final int INDEX_HAS_ENCRYPT = 8;
static final int INDEX_NAME = 9;
static final int INDEX_EMAIL = 10;
static final int INDEX_COMMENT = 11;
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
@@ -885,12 +891,10 @@ public class ViewKeyActivity extends BaseSecurityTokenActivity implements
if (data.moveToFirst()) {
// get name, email, and comment from USER_ID
OpenPgpUtils.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
if (mainUserId.name != null) {
mCollapsingToolbarLayout.setTitle(mainUserId.name);
} else {
mCollapsingToolbarLayout.setTitle(getString(R.string.user_id_no_name));
}
String name = data.getString(INDEX_NAME);
mCollapsingToolbarLayout.setTitle(name != null ? name : getString(R.string.user_id_no_name));
mMasterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
mFingerprint = data.getBlob(INDEX_FINGERPRINT);

View File

@@ -179,6 +179,9 @@ public class ViewKeyAdvActivity extends BaseActivity implements
KeychainContract.KeyRings.VERIFIED,
KeychainContract.KeyRings.HAS_ANY_SECRET,
KeychainContract.KeyRings.FINGERPRINT,
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.EMAIL,
KeychainContract.KeyRings.COMMENT,
};
static final int INDEX_MASTER_KEY_ID = 1;
@@ -188,6 +191,9 @@ public class ViewKeyAdvActivity extends BaseActivity implements
static final int INDEX_VERIFIED = 5;
static final int INDEX_HAS_ANY_SECRET = 6;
static final int INDEX_FINGERPRINT = 7;
static final int INDEX_NAME = 8;
static final int INDEX_EMAIL = 9;
static final int INDEX_COMMENT = 10;
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
@@ -214,9 +220,10 @@ public class ViewKeyAdvActivity extends BaseActivity implements
case LOADER_ID_UNIFIED: {
if (data.moveToFirst()) {
// get name, email, and comment from USER_ID
OpenPgpUtils.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
if (mainUserId.name != null) {
setTitle(mainUserId.name);
String name = data.getString(INDEX_NAME);
if (name != null) {
setTitle(name);
} else {
setTitle(R.string.user_id_no_name);
}

View File

@@ -233,8 +233,19 @@ public class CertSectionedListAdapter extends SectionCursorAdapter<CertSectioned
return getString(index);
}
public OpenPgpUtils.UserId getUserId() {
return KeyRing.splitUserId(getRawUserId());
public String getName() {
int index = getColumnIndexOrThrow(KeychainContract.Certs.NAME);
return getString(index);
}
public String getEmail() {
int index = getColumnIndexOrThrow(KeychainContract.Certs.EMAIL);
return getString(index);
}
public String getComment() {
int index = getColumnIndexOrThrow(KeychainContract.Certs.COMMENT);
return getString(index);
}
public OpenPgpUtils.UserId getSignerUserId() {

View File

@@ -66,7 +66,10 @@ public class KeyAdapter extends CursorAdapter {
KeyRings.HAS_DUPLICATE_USER_ID,
KeyRings.FINGERPRINT,
KeyRings.CREATION,
KeyRings.HAS_ENCRYPT
KeyRings.HAS_ENCRYPT,
KeyRings.NAME,
KeyRings.EMAIL,
KeyRings.COMMENT
};
public static final int INDEX_MASTER_KEY_ID = 1;
@@ -79,6 +82,9 @@ public class KeyAdapter extends CursorAdapter {
public static final int INDEX_FINGERPRINT = 8;
public static final int INDEX_CREATION = 9;
public static final int INDEX_HAS_ENCRYPT = 10;
public static final int INDEX_NAME = 11;
public static final int INDEX_EMAIL = 12;
public static final int INDEX_COMMENT = 13;
public KeyAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
@@ -266,6 +272,9 @@ public class KeyAdapter extends CursorAdapter {
public final String mUserIdFull;
public final OpenPgpUtils.UserId mUserId;
public final String mName;
public final String mEmail;
public final String mComment;
public final long mKeyId;
public final boolean mHasDuplicate;
public final boolean mHasEncrypt;
@@ -276,6 +285,9 @@ public class KeyAdapter extends CursorAdapter {
private KeyItem(Cursor cursor) {
String userId = cursor.getString(INDEX_USER_ID);
mUserId = KeyRing.splitUserId(userId);
mName = cursor.getString(INDEX_NAME);
mEmail = cursor.getString(INDEX_EMAIL);
mComment = cursor.getString(INDEX_COMMENT);
mUserIdFull = userId;
mKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
mHasDuplicate = cursor.getLong(INDEX_HAS_DUPLICATE_USER_ID) > 0;
@@ -293,6 +305,9 @@ public class KeyAdapter extends CursorAdapter {
CanonicalizedPublicKey key = ring.getPublicKey();
String userId = key.getPrimaryUserIdWithFallback();
mUserId = KeyRing.splitUserId(userId);
mName = mUserId.name;
mEmail = mUserId.email;
mComment = mUserId.comment;
mUserIdFull = userId;
mKeyId = ring.getMasterKeyId();
mHasDuplicate = false;
@@ -309,10 +324,10 @@ public class KeyAdapter extends CursorAdapter {
}
public String getReadableName() {
if (mUserId.name != null) {
return mUserId.name;
if (mName != null) {
return mName;
} else {
return mUserId.email;
return mEmail;
}
}
}

View File

@@ -192,11 +192,11 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
return '#';
} else {
String userId = cursor.getRawUserId();
if (TextUtils.isEmpty(userId)) {
return '?';
String name = cursor.getName();
if (name != null) {
return Character.toUpperCase(name.charAt(0));
} else {
return Character.toUpperCase(userId.charAt(0));
return '?';
}
}
}
@@ -313,11 +313,11 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
return "My";
} else {
String userId = cursor.getRawUserId();
if (TextUtils.isEmpty(userId)) {
return null;
String name = cursor.getName();
if (name != null) {
return name.substring(0, 1).toUpperCase();
} else {
return userId.substring(0, 1).toUpperCase();
return null;
}
}
} else {
@@ -380,14 +380,15 @@ public class KeySectionedListAdapter extends SectionCursorAdapter<KeySectionedLi
Context context = itemView.getContext();
{ // set name and stuff, common to both key types
OpenPgpUtils.UserId userIdSplit = keyItem.getUserId();
if (userIdSplit.name != null) {
mMainUserId.setText(highlighter.highlight(userIdSplit.name));
String name = keyItem.getName();
String email = keyItem.getEmail();
if (name != null) {
mMainUserId.setText(highlighter.highlight(name));
} else {
mMainUserId.setText(R.string.user_id_no_name);
}
if (userIdSplit.email != null) {
mMainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
if (email != null) {
mMainUserIdRest.setText(highlighter.highlight(email));
mMainUserIdRest.setVisibility(View.VISIBLE);
} else {
mMainUserIdRest.setVisibility(View.GONE);

View File

@@ -33,7 +33,10 @@ public abstract class UserAttributesAdapter extends CursorAdapter {
UserPackets.RANK,
UserPackets.VERIFIED,
UserPackets.IS_PRIMARY,
UserPackets.IS_REVOKED
UserPackets.IS_REVOKED,
UserPackets.NAME,
UserPackets.EMAIL,
UserPackets.COMMENT,
};
public static final int INDEX_ID = 0;
public static final int INDEX_TYPE = 1;
@@ -43,6 +46,9 @@ public abstract class UserAttributesAdapter extends CursorAdapter {
public static final int INDEX_VERIFIED = 5;
public static final int INDEX_IS_PRIMARY = 6;
public static final int INDEX_IS_REVOKED = 7;
public static final int INDEX_NAME = 8;
public static final int INDEX_EMAIL = 9;
public static final int INDEX_COMMENT = 10;
public UserAttributesAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);

View File

@@ -71,20 +71,22 @@ public class UserIdsAdapter extends UserAttributesAdapter {
vDeleteButton.setVisibility(View.GONE); // not used
String userId = cursor.getString(INDEX_USER_ID);
OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId);
if (splitUserId.name != null) {
vName.setText(splitUserId.name);
String name = cursor.getString(INDEX_NAME);
String email = cursor.getString(INDEX_EMAIL);
String comment = cursor.getString(INDEX_COMMENT);
if (name != null) {
vName.setText(name);
} else {
vName.setText(R.string.user_id_no_name);
}
if (splitUserId.email != null) {
vAddress.setText(splitUserId.email);
if (email != null) {
vAddress.setText(email);
vAddress.setVisibility(View.VISIBLE);
} else {
vAddress.setVisibility(View.GONE);
}
if (splitUserId.comment != null) {
vComment.setText(splitUserId.comment);
if (comment != null) {
vComment.setText(comment);
vComment.setVisibility(View.VISIBLE);
} else {
vComment.setVisibility(View.GONE);

View File

@@ -32,7 +32,6 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.util.Log;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -65,7 +64,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
* When using this constructor, {@link #FLAG_REGISTER_CONTENT_OBSERVER}
* will always be set.
*
* @param c The cursor from which to get the data.
* @param c The cursor from which to get the data.
* @param context The context
*/
public CursorAdapter(Context context, C c) {
@@ -76,9 +75,9 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
/**
* Recommended constructor.
*
* @param c The cursor from which to get the data.
* @param c The cursor from which to get the data.
* @param context The context
* @param flags Flags used to determine the behavior of the adapter
* @param flags Flags used to determine the behavior of the adapter
* @see #FLAG_REGISTER_CONTENT_OBSERVER
*/
public CursorAdapter(Context context, C c, int flags) {
@@ -109,6 +108,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
/**
* Returns the cursor.
*
* @return the cursor.
*/
public C getCursor() {
@@ -147,10 +147,9 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
}
/**
* @see android.support.v7.widget.RecyclerView.Adapter#getItemId(int)
*
* @param position Adapter position to query
* @return the id of the item
* @see android.support.v7.widget.RecyclerView.Adapter#getItemId(int)
*/
@Override
public long getItemId(int position) {
@@ -168,11 +167,12 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
/**
* Return the id of the item represented by the row the cursor
* is currently moved to.
*
* @param cursor The cursor moved to the correct position.
* @return The id of the dataset
*/
public long getIdFromCursor(C cursor) {
if(cursor != null) {
if (cursor != null) {
return cursor.getEntryId();
} else {
return RecyclerView.NO_ID;
@@ -182,28 +182,28 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
public void moveCursorOrThrow(int position)
throws IndexOutOfBoundsException, IllegalStateException {
if(position >= getItemCount() || position < -1) {
if (position >= getItemCount() || position < -1) {
throw new IndexOutOfBoundsException("Position: " + position
+ " is invalid for this data set!");
}
if(!mDataValid) {
if (!mDataValid) {
throw new IllegalStateException("Attempt to move cursor over invalid data set!");
}
if(!mCursor.moveToPosition(position)) {
if (!mCursor.moveToPosition(position)) {
throw new IllegalStateException("Couldn't move cursor from position: "
+ mCursor.getPosition() + " to position: " + position + "!");
}
}
public boolean moveCursor(int position) {
if(position >= getItemCount() || position < -1) {
if (position >= getItemCount() || position < -1) {
Log.w(TAG, "Position: %d is invalid for this data set!");
return false;
}
if(!mDataValid) {
if (!mDataValid) {
Log.d(TAG, "Attempt to move cursor over invalid data set!");
}
@@ -315,7 +315,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
}
public static abstract class AbstractCursor extends CursorWrapper {
public static final String[] PROJECTION = { "_id" };
public static final String[] PROJECTION = {"_id"};
public static <T extends AbstractCursor> T wrap(Cursor cursor, Class<T> type) {
if (cursor != null) {
@@ -356,10 +356,10 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
@Override
public final int getColumnIndexOrThrow(String colName) {
Integer colIndex = mColumnIndices.get(colName);
if(colIndex == null) {
if (colIndex == null) {
colIndex = super.getColumnIndexOrThrow(colName);
mColumnIndices.put(colName, colIndex);
} else if (colIndex < 0){
} else if (colIndex < 0) {
throw new IllegalArgumentException("Could not get column index for name: \"" + colName + "\"");
}
@@ -369,7 +369,7 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
@Override
public final int getColumnIndex(String colName) {
Integer colIndex = mColumnIndices.get(colName);
if(colIndex == null) {
if (colIndex == null) {
colIndex = super.getColumnIndex(colName);
mColumnIndices.put(colName, colIndex);
}
@@ -390,7 +390,10 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
KeychainContract.KeyRings.IS_REVOKED,
KeychainContract.KeyRings.IS_EXPIRED,
KeychainContract.KeyRings.HAS_DUPLICATE_USER_ID,
KeychainContract.KeyRings.CREATION
KeychainContract.KeyRings.CREATION,
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.EMAIL,
KeychainContract.KeyRings.COMMENT
));
PROJECTION = arr.toArray(new String[arr.size()]);
@@ -418,13 +421,19 @@ public abstract class CursorAdapter<C extends CursorAdapter.AbstractCursor, VH e
return getLong(index);
}
public String getRawUserId() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.USER_ID);
public String getName() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.NAME);
return getString(index);
}
public OpenPgpUtils.UserId getUserId() {
return KeyRing.splitUserId(getRawUserId());
public String getEmail() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.EMAIL);
return getString(index);
}
public String getComment() {
int index = getColumnIndexOrThrow(KeychainContract.KeyRings.COMMENT);
return getString(index);
}
public boolean hasDuplicate() {

View File

@@ -451,7 +451,10 @@ public class ContactHelper {
KeychainContract.KeyRings.IS_REVOKED,
KeychainContract.KeyRings.VERIFIED,
KeychainContract.KeyRings.HAS_SECRET,
KeychainContract.KeyRings.HAS_ANY_SECRET};
KeychainContract.KeyRings.HAS_ANY_SECRET,
KeychainContract.KeyRings.NAME,
KeychainContract.KeyRings.EMAIL,
KeychainContract.KeyRings.COMMENT };
public static final int INDEX_MASTER_KEY_ID = 0;
public static final int INDEX_USER_ID = 1;
@@ -460,6 +463,9 @@ public class ContactHelper {
public static final int INDEX_VERIFIED = 4;
public static final int INDEX_HAS_SECRET = 5;
public static final int INDEX_HAS_ANY_SECRET = 6;
public static final int INDEX_NAME = 7;
public static final int INDEX_EMAIL = 8;
public static final int INDEX_COMMENT = 9;
/**
* Write/Update the current OpenKeychain keys to the contact db
@@ -504,7 +510,7 @@ public class ContactHelper {
if (cursor != null) {
while (cursor.moveToNext()) {
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
String name = cursor.getString(INDEX_NAME);
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
@@ -523,7 +529,7 @@ public class ContactHelper {
if (masterKeyId != -1) {
deleteRawContactByMasterKeyId(masterKeyId);
}
} else if (userIdSplit.name != null) {
} else if (name != null) {
// get raw contact to this master key id
long rawContactId = findRawContactId(masterKeyId);
@@ -534,12 +540,12 @@ public class ContactHelper {
Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId);
insertContact(ops, masterKeyId);
writeContactKey(ops, rawContactId, masterKeyId, userIdSplit.name);
writeContactKey(ops, rawContactId, masterKeyId, name);
}
// We always update the display name (which is derived from primary user id)
// and email addresses from user id
writeContactDisplayName(ops, rawContactId, userIdSplit.name);
writeContactDisplayName(ops, rawContactId, name);
writeContactEmail(ops, rawContactId, masterKeyId);
try {
mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
@@ -579,9 +585,9 @@ public class ContactHelper {
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
OpenPgpUtils.UserId userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
String name = cursor.getString(INDEX_NAME);
if (!isExpired && !isRevoked && userIdSplit.name != null) {
if (!isExpired && !isRevoked && name != null) {
// if expired or revoked will not be removed from keysToDelete or inserted
// into main profile ("me" contact)
boolean existsInMainProfile = keysToDelete.remove(masterKeyId);
@@ -592,7 +598,7 @@ public class ContactHelper {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
insertMainProfileRawContact(ops, masterKeyId);
writeContactKey(ops, rawContactId, masterKeyId, userIdSplit.name);
writeContactKey(ops, rawContactId, masterKeyId, name);
try {
mContentResolver.applyBatch(ContactsContract.AUTHORITY, ops);