object oriented split user id

This commit is contained in:
Dominik Schürmann 2015-03-16 13:54:01 +01:00
parent 0e71fcd638
commit a655664c0b
26 changed files with 140 additions and 149 deletions

View File

@ -307,24 +307,22 @@ public class ImportKeysListEntry implements Serializable, Parcelable {
public void updateMergedUserIds() {
mMergedUserIds = new HashMap<>();
for (String userId : mUserIds) {
String[] userIdSplit = KeyRing.splitUserId(userId);
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
// TODO: comment field?
// name
if (userIdSplit[0] != null) {
// email
if (userIdSplit[1] != null) {
if (!mMergedUserIds.containsKey(userIdSplit[0])) {
if (userIdSplit.name != null) {
if (userIdSplit.email != null) {
if (!mMergedUserIds.containsKey(userIdSplit.name)) {
HashSet<String> emails = new HashSet<>();
emails.add(userIdSplit[1]);
mMergedUserIds.put(userIdSplit[0], emails);
emails.add(userIdSplit.email);
mMergedUserIds.put(userIdSplit.name, emails);
} else {
mMergedUserIds.get(userIdSplit[0]).add(userIdSplit[1]);
mMergedUserIds.get(userIdSplit.name).add(userIdSplit.email);
}
} else {
// name only
mMergedUserIds.put(userIdSplit[0], new HashSet<String>());
mMergedUserIds.put(userIdSplit.name, new HashSet<String>());
}
} else {
// fallback

View File

@ -44,7 +44,7 @@ public abstract class KeyRing {
abstract public String getPrimaryUserIdWithFallback() throws PgpKeyNotFoundException;
public String[] getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException {
public UserId getSplitPrimaryUserIdWithFallback() throws PgpKeyNotFoundException {
return splitUserId(getPrimaryUserIdWithFallback());
}
@ -62,35 +62,21 @@ public abstract class KeyRing {
/**
* Splits userId string into naming part, email part, and comment part
* <p/>
* User ID matching:
* http://fiddle.re/t4p6f
*
* @param userId
* @return array with naming (0), email (1), comment (2)
* @return theParsedUserInfo
*/
public static String[] splitUserId(String userId) {
String[] result = new String[]{null, null, null};
if (userId == null || userId.equals("")) {
return result;
public static UserId splitUserId(final String userId) {
if (!TextUtils.isEmpty(userId)) {
final Matcher matcher = USER_ID_PATTERN.matcher(userId);
if (matcher.matches()) {
return new UserId(matcher.group(1), matcher.group(3), matcher.group(2));
}
}
/*
* User ID matching:
* http://fiddle.re/t4p6f
*
* test cases:
* "Max Mustermann (this is a comment) <max@example.com>"
* "Max Mustermann <max@example.com>"
* "Max Mustermann (this is a comment)"
* "Max Mustermann [this is nothing]"
*/
Matcher matcher = USER_ID_PATTERN.matcher(userId);
if (matcher.matches()) {
result[0] = matcher.group(1);
result[1] = matcher.group(3);
result[2] = matcher.group(2);
}
return result;
return new UserId(null, null, null);
}
/**
@ -101,16 +87,28 @@ public abstract class KeyRing {
* @param comment
* @return
*/
public static String createUserId(String name, String email, String comment) {
String userId = name; // consider name a required value
if (userId != null && !TextUtils.isEmpty(comment)) {
userId += " (" + comment + ")";
public static String createUserId(UserId userId) {
String userIdString = userId.name; // consider name a required value
if (userIdString != null && !TextUtils.isEmpty(userId.comment)) {
userIdString += " (" + userId.comment + ")";
}
if (userId != null && !TextUtils.isEmpty(email)) {
userId += " <" + email + ">";
if (userIdString != null && !TextUtils.isEmpty(userId.email)) {
userIdString += " <" + userId.email + ">";
}
return userId;
return userIdString;
}
public static class UserId {
public final String name;
public final String email;
public final String comment;
public UserId(String name, String email, String comment) {
this.name = name;
this.email = email;
this.comment = comment;
}
}
}

View File

@ -92,11 +92,11 @@ public class AccountSettingsFragment extends Fragment {
}
private void createKey() {
String[] userId = KeyRing.splitUserId(mAccSettings.getAccountName());
KeyRing.UserId userId = KeyRing.splitUserId(mAccSettings.getAccountName());
Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userId[0]);
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userId[1]);
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userId.name);
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userId.email);
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
}

View File

@ -96,11 +96,11 @@ public class SelectSignKeyIdActivity extends BaseActivity {
}
private void createKey(String userId) {
String[] userIdSplit = KeyRing.splitUserId(userId);
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
Intent intent = new Intent(this, CreateKeyActivity.class);
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userIdSplit[0]);
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userIdSplit[1]);
intent.putExtra(CreateKeyActivity.EXTRA_NAME, userIdSplit.name);
intent.putExtra(CreateKeyActivity.EXTRA_EMAIL, userIdSplit.email);
startActivityForResult(intent, REQUEST_CODE_CREATE_KEY);
}

View File

@ -31,7 +31,6 @@ import android.os.Bundle;
import android.os.Message;
import android.os.Messenger;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
@ -247,14 +246,14 @@ public class CertifyKeyFragment extends LoaderFragment
while (!data.isAfterLast()) {
long masterKeyId = data.getLong(INDEX_MASTER_KEY_ID);
String userId = data.getString(INDEX_USER_ID);
String[] pieces = KeyRing.splitUserId(userId);
KeyRing.UserId pieces = KeyRing.splitUserId(userId);
// Two cases:
boolean grouped = masterKeyId == lastMasterKeyId;
boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces[0]);
boolean subGrouped = data.isFirst() || grouped && lastName.equals(pieces.name);
// Remember for next loop
lastName = pieces[0];
lastName = pieces.name;
Log.d(Constants.TAG, Long.toString(masterKeyId, 16) + (grouped ? "grouped" : "not grouped"));

View File

@ -186,12 +186,12 @@ public class CreateKeyFinalFragment extends Fragment {
Algorithm.RSA, 4096, null, KeyFlags.SIGN_DATA, 0L));
mSaveKeyringParcel.mAddSubKeys.add(new SaveKeyringParcel.SubkeyAdd(
Algorithm.RSA, 4096, null, KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE, 0L));
String userId = KeyRing.createUserId(mName, mEmail, null);
String userId = KeyRing.createUserId(new KeyRing.UserId(mName, mEmail, null));
mSaveKeyringParcel.mAddUserIds.add(userId);
mSaveKeyringParcel.mChangePrimaryUserId = userId;
if (mAdditionalEmails != null && mAdditionalEmails.size() > 0) {
for (String email : mAdditionalEmails) {
String thisUserId = KeyRing.createUserId(mName, email, null);
String thisUserId = KeyRing.createUserId(new KeyRing.UserId(mName, email, null));
mSaveKeyringParcel.mAddUserIds.add(thisUserId);
}
}

View File

@ -128,14 +128,14 @@ public abstract class DecryptFragment extends Fragment {
mSignatureKeyId = signatureResult.getKeyId();
String userId = signatureResult.getPrimaryUserId();
String[] userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit[0] != null) {
mSignatureName.setText(userIdSplit[0]);
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit.name != null) {
mSignatureName.setText(userIdSplit.name);
} else {
mSignatureName.setText(R.string.user_id_no_name);
}
if (userIdSplit[1] != null) {
mSignatureEmail.setText(userIdSplit[1]);
if (userIdSplit.email != null) {
mSignatureEmail.setText(userIdSplit.email);
} else {
mSignatureEmail.setText(KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), mSignatureKeyId));
}

View File

@ -545,7 +545,7 @@ public class EditKeyFragment extends LoaderFragment implements
Messenger messenger = new Messenger(returnHandler);
// pre-fill out primary name
String predefinedName = KeyRing.splitUserId(mPrimaryUserId)[0];
String predefinedName = KeyRing.splitUserId(mPrimaryUserId).name;
AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger,
predefinedName);

View File

@ -273,9 +273,9 @@ public class EncryptFilesActivity extends EncryptActivity implements EncryptActi
if (!isModeSymmetric() && mEncryptionUserIds != null) {
Set<String> users = new HashSet<>();
for (String user : mEncryptionUserIds) {
String[] userId = KeyRing.splitUserId(user);
if (userId[1] != null) {
users.add(userId[1]);
KeyRing.UserId userId = KeyRing.splitUserId(user);
if (userId.email != null) {
users.add(userId.email);
}
}
sendIntent.putExtra(Intent.EXTRA_EMAIL, users.toArray(new String[users.size()]));

View File

@ -36,7 +36,6 @@ import org.sufficientlysecure.keychain.pgp.PgpConstants;
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.Preferences;
import org.sufficientlysecure.keychain.util.ShareHelper;
import java.util.ArrayList;
@ -253,9 +252,9 @@ public class EncryptTextActivity extends EncryptActivity implements EncryptActiv
if (!isModeSymmetric() && mEncryptionUserIds != null) {
Set<String> users = new HashSet<>();
for (String user : mEncryptionUserIds) {
String[] userId = KeyRing.splitUserId(user);
if (userId[1] != null) {
users.add(userId[1]);
KeyRing.UserId userId = KeyRing.splitUserId(user);
if (userId.email != null) {
users.add(userId.email);
}
}
// pass trough email addresses as extra for email applications

View File

@ -688,14 +688,14 @@ public class KeyListFragment extends LoaderFragment
{ // set name and stuff, common to both key types
String userId = cursor.getString(INDEX_USER_ID);
String[] userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit[0] != null) {
h.mMainUserId.setText(highlighter.highlight(userIdSplit[0]));
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit.name != null) {
h.mMainUserId.setText(highlighter.highlight(userIdSplit.name));
} else {
h.mMainUserId.setText(R.string.user_id_no_name);
}
if (userIdSplit[1] != null) {
h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit[1]));
if (userIdSplit.email != null) {
h.mMainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
h.mMainUserIdRest.setVisibility(View.VISIBLE);
} else {
h.mMainUserIdRest.setVisibility(View.GONE);

View File

@ -211,9 +211,9 @@ public class PassphraseDialogActivity extends FragmentActivity {
// the catch clause doesn't return.
try {
String mainUserId = mSecretRing.getPrimaryUserIdWithFallback();
String[] mainUserIdSplit = KeyRing.splitUserId(mainUserId);
if (mainUserIdSplit[0] != null) {
userId = mainUserIdSplit[0];
KeyRing.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId);
if (mainUserIdSplit.name != null) {
userId = mainUserIdSplit.name;
} else {
userId = getString(R.string.user_id_no_name);
}

View File

@ -841,9 +841,9 @@ public class ViewKeyActivity extends BaseActivity implements
case LOADER_ID_UNIFIED: {
if (data.moveToFirst()) {
// get name, email, and comment from USER_ID
String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
if (mainUserId[0] != null) {
mName.setText(mainUserId[0]);
KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
if (mainUserId.name != null) {
mName.setText(mainUserId.name);
} else {
mName.setText(R.string.user_id_no_name);
}

View File

@ -197,9 +197,9 @@ public class ViewKeyAdvActivity extends BaseActivity implements
case LOADER_ID_UNIFIED: {
if (data.moveToFirst()) {
// get name, email, and comment from USER_ID
String[] mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
if (mainUserId[0] != null) {
setTitle(mainUserId[0]);
KeyRing.UserId mainUserId = KeyRing.splitUserId(data.getString(INDEX_USER_ID));
if (mainUserId.name != null) {
setTitle(mainUserId.name);
} else {
setTitle(R.string.user_id_no_name);
}

View File

@ -237,9 +237,9 @@ public class ViewKeyAdvCertsFragment extends LoaderFragment implements
TextView wSignStatus = (TextView) view.findViewById(R.id.signStatus);
String signerKeyId = KeyFormattingUtils.beautifyKeyIdWithPrefix(getActivity(), cursor.getLong(mIndexSignerKeyId));
String[] userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId));
if (userId[0] != null) {
wSignerName.setText(userId[0]);
KeyRing.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexSignerUserId));
if (userId.name != null) {
wSignerName.setText(userId.name);
} else {
wSignerName.setText(R.string.user_id_no_name);
}

View File

@ -140,25 +140,25 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> {
// main user id
String userId = entry.getUserIds().get(0);
String[] userIdSplit = KeyRing.splitUserId(userId);
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
// name
if (userIdSplit[0] != null) {
if (userIdSplit.name != null) {
// show red user id if it is a secret key
if (entry.isSecretKey()) {
holder.mainUserId.setText(mActivity.getString(R.string.secret_key)
+ " " + userIdSplit[0]);
+ " " + userIdSplit.name);
} else {
holder.mainUserId.setText(highlighter.highlight(userIdSplit[0]));
holder.mainUserId.setText(highlighter.highlight(userIdSplit.name));
}
} else {
holder.mainUserId.setText(R.string.user_id_no_name);
}
// email
if (userIdSplit[1] != null) {
if (userIdSplit.email != null) {
holder.mainUserIdRest.setVisibility(View.VISIBLE);
holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1]));
holder.mainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
} else {
holder.mainUserIdRest.setVisibility(View.GONE);
}

View File

@ -33,7 +33,6 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import java.util.ArrayList;
@ -83,9 +82,9 @@ public class MultiUserIdsAdapter extends CursorAdapter {
{ // first one
String userId = uids.get(0);
String[] splitUserId = KeyRing.splitUserId(userId);
if (splitUserId[0] != null) {
vName.setText(splitUserId[0]);
KeyRing.UserId splitUserId = KeyRing.splitUserId(userId);
if (splitUserId.name != null) {
vName.setText(splitUserId.name);
} else {
vName.setText(R.string.user_id_no_name);
}
@ -93,9 +92,9 @@ public class MultiUserIdsAdapter extends CursorAdapter {
if (isHeader == 1) {
vHeaderId.setVisibility(View.VISIBLE);
String message;
if (splitUserId[0] != null) {
if (splitUserId.name != null) {
message = mContext.getString(R.string.section_uids_to_certify) +
splitUserId[0];
splitUserId.name;
} else {
message = mContext.getString(R.string.section_uids_to_certify) +
context.getString(R.string.user_id_no_name);
@ -108,13 +107,13 @@ public class MultiUserIdsAdapter extends CursorAdapter {
StringBuilder lines = new StringBuilder();
for (String uid : uids) {
String[] splitUserId = KeyRing.splitUserId(uid);
if (splitUserId[1] == null) {
KeyRing.UserId splitUserId = KeyRing.splitUserId(uid);
if (splitUserId.email == null) {
continue;
}
lines.append(splitUserId[1]);
if (splitUserId[2] != null) {
lines.append(" (").append(splitUserId[2]).append(")");
lines.append(splitUserId.email);
if (splitUserId.comment != null) {
lines.append(" (").append(splitUserId.comment).append(")");
}
lines.append('\n');
}

View File

@ -122,16 +122,16 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter {
ViewHolderItem h = (ViewHolderItem) view.getTag();
String userId = cursor.getString(mIndexUserId);
String[] userIdSplit = KeyRing.splitUserId(userId);
KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
if (userIdSplit[0] != null) {
h.mainUserId.setText(highlighter.highlight(userIdSplit[0]));
if (userIdSplit.name != null) {
h.mainUserId.setText(highlighter.highlight(userIdSplit.name));
} else {
h.mainUserId.setText(R.string.user_id_no_name);
}
if (userIdSplit[1] != null) {
if (userIdSplit.email != null) {
h.mainUserIdRest.setVisibility(View.VISIBLE);
h.mainUserIdRest.setText(highlighter.highlight(userIdSplit[1]));
h.mainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
} else {
h.mainUserIdRest.setVisibility(View.GONE);
}

View File

@ -72,20 +72,20 @@ public class UserIdsAdapter extends UserAttributesAdapter {
vDeleteButton.setVisibility(View.GONE); // not used
String userId = cursor.getString(INDEX_USER_ID);
String[] splitUserId = KeyRing.splitUserId(userId);
if (splitUserId[0] != null) {
vName.setText(splitUserId[0]);
KeyRing.UserId splitUserId = KeyRing.splitUserId(userId);
if (splitUserId.name != null) {
vName.setText(splitUserId.name);
} else {
vName.setText(R.string.user_id_no_name);
}
if (splitUserId[1] != null) {
vAddress.setText(splitUserId[1]);
if (splitUserId.email != null) {
vAddress.setText(splitUserId.email);
vAddress.setVisibility(View.VISIBLE);
} else {
vAddress.setVisibility(View.GONE);
}
if (splitUserId[2] != null) {
vComment.setText(splitUserId[2]);
if (splitUserId.comment != null) {
vComment.setText(splitUserId.comment);
vComment.setVisibility(View.VISIBLE);
} else {
vComment.setVisibility(View.GONE);

View File

@ -92,20 +92,20 @@ public class UserIdsAddedAdapter extends ArrayAdapter<String> {
// save reference to model item
holder.mModel = getItem(position);
String[] splitUserId = KeyRing.splitUserId(holder.mModel);
if (splitUserId[0] != null) {
holder.vName.setText(splitUserId[0]);
KeyRing.UserId splitUserId = KeyRing.splitUserId(holder.mModel);
if (splitUserId.name != null) {
holder.vName.setText(splitUserId.name);
} else {
holder.vName.setText(R.string.user_id_no_name);
}
if (splitUserId[1] != null) {
holder.vAddress.setText(splitUserId[1]);
if (splitUserId.email != null) {
holder.vAddress.setText(splitUserId.email);
holder.vAddress.setVisibility(View.VISIBLE);
} else {
holder.vAddress.setVisibility(View.GONE);
}
if (splitUserId[2] != null) {
holder.vComment.setText(splitUserId[2]);
if (splitUserId.comment != null) {
holder.vComment.setText(splitUserId.comment);
holder.vComment.setVisibility(View.VISIBLE);
} else {
holder.vComment.setVisibility(View.GONE);

View File

@ -100,8 +100,8 @@ public class AddUserIdDialogFragment extends DialogFragment implements OnEditorA
// return new user id back to activity
Bundle data = new Bundle();
String userId = KeyRing.createUserId(mName.getText().toString(),
mEmail.getText().toString(), mComment.getText().toString());
String userId = KeyRing.createUserId(new KeyRing.UserId(mName.getText().toString(),
mEmail.getText().toString(), mComment.getText().toString()));
data.putString(MESSAGE_DATA_USER_ID, userId);
sendMessageToHandler(MESSAGE_OKAY, data);
}

View File

@ -100,9 +100,9 @@ public class DeleteKeyDialogFragment extends DialogFragment {
}
);
String name;
String[] mainUserId = KeyRing.splitUserId((String) data.get(KeyRings.USER_ID));
if (mainUserId[0] != null) {
name = mainUserId[0];
KeyRing.UserId mainUserId = KeyRing.splitUserId((String) data.get(KeyRings.USER_ID));
if (mainUserId.name != null) {
name = mainUserId.name;
} else {
name = getString(R.string.user_id_no_name);
}

View File

@ -184,7 +184,7 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
public class EncryptionKey {
private String mUserIdFull;
private String[] mUserId;
private KeyRing.UserId mUserId;
private long mKeyId;
private boolean mHasDuplicate;
private Date mCreation;
@ -222,23 +222,23 @@ public class EncryptKeyCompletionView extends TokenCompleteTextView {
}
public String getPrimary() {
if (mUserId[0] != null) {
return mUserId[0];
if (mUserId.name != null) {
return mUserId.name;
} else {
return mUserId[1];
return mUserId.email;
}
}
public String getSecondary() {
if (mUserId[1] != null) {
return mUserId[1];
if (mUserId.email != null) {
return mUserId.email;
} else {
return getCreationDate();
}
}
public String getTertiary() {
if (mUserId[0] != null) {
if (mUserId.name != null) {
return getCreationDate();
} else {
return null;

View File

@ -39,7 +39,6 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.Log;
import java.util.Calendar;
@ -162,9 +161,9 @@ public abstract class KeySpinner extends TintSpinner implements LoaderManager.Lo
TextView vKeyEmail = (TextView) view.findViewById(R.id.keyspinner_key_email);
TextView vDuplicate = (TextView) view.findViewById(R.id.keyspinner_duplicate);
String[] userId = KeyRing.splitUserId(cursor.getString(mIndexUserId));
vKeyName.setText(userId[2] == null ? userId[0] : (userId[0] + " (" + userId[2] + ")"));
vKeyEmail.setText(userId[1]);
KeyRing.UserId userId = KeyRing.splitUserId(cursor.getString(mIndexUserId));
vKeyName.setText(userId.name);
vKeyEmail.setText(userId.email);
boolean duplicate = cursor.getLong(mIndexDuplicate) > 0;
if (duplicate) {

View File

@ -37,7 +37,6 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import java.io.InputStream;
import java.util.ArrayList;
@ -447,7 +446,7 @@ public class ContactHelper {
if (cursor != null) {
while (cursor.moveToNext()) {
long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
String[] userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
KeyRing.UserId userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
@ -470,19 +469,19 @@ public class ContactHelper {
if (rawContactId != -1) {
deleteRawContactById(resolver, rawContactId);
}
} else if (userIdSplit[0] != null) {
} else if (userIdSplit.name != null) {
// Create a new rawcontact with corresponding key if it does not exist yet
if (rawContactId == -1) {
Log.d(Constants.TAG, "Insert new raw contact with masterKeyId " + masterKeyId);
insertContact(ops, context, masterKeyId);
writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit[0]);
writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit.name);
}
// We always update the display name (which is derived from primary user id)
// and email addresses from user id
writeContactDisplayName(ops, rawContactId, userIdSplit[0]);
writeContactDisplayName(ops, rawContactId, userIdSplit.name);
writeContactEmail(ops, resolver, rawContactId, masterKeyId);
try {
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
@ -521,9 +520,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;
String[] userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
KeyRing.UserId userIdSplit = KeyRing.splitUserId(cursor.getString(INDEX_USER_ID));
if (!isExpired && !isRevoked && userIdSplit[0] != null) {
if (!isExpired && !isRevoked && userIdSplit.name != null) {
// if expired or revoked will not be removed from keysToDelete or inserted
// into main profile ("me" contact)
boolean existsInMainProfile = keysToDelete.remove(masterKeyId);
@ -534,7 +533,7 @@ public class ContactHelper {
ArrayList<ContentProviderOperation> ops = new ArrayList<>();
insertMainProfileRawContact(ops, masterKeyId);
writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit[0]);
writeContactKey(ops, context, rawContactId, masterKeyId, userIdSplit.name);
try {
resolver.applyBatch(ContactsContract.AUTHORITY, ops);
@ -776,14 +775,14 @@ public class ContactHelper {
null, null);
if (ids != null) {
while (ids.moveToNext()) {
String[] userId = KeyRing.splitUserId(ids.getString(0));
if (userId[1] != null) {
KeyRing.UserId userId = KeyRing.splitUserId(ids.getString(0));
if (userId.email != null) {
ops.add(referenceRawContact(
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI),
rawContactId)
.withValue(ContactsContract.Data.MIMETYPE,
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
.withValue(ContactsContract.CommonDataKinds.Email.DATA, userId[1])
.withValue(ContactsContract.CommonDataKinds.Email.DATA, userId.email)
.build());
}
}

@ -1 +1 @@
Subproject commit bc177ed5e3f110cf372d6303c8e9d21e46fc76d2
Subproject commit 10be5948d68bb5e80aed77fdf93cada598ee7667