Use existence of editor as indicator whether source is editable.
Bug:3093621
Change-Id: I3ba344667ce1b0f2da6847d783c0ac90f36ebd8f
diff --git a/src/com/android/contacts/detail/ContactDetailFragment.java b/src/com/android/contacts/detail/ContactDetailFragment.java
index 775b50a..9659c01 100644
--- a/src/com/android/contacts/detail/ContactDetailFragment.java
+++ b/src/com/android/contacts/detail/ContactDetailFragment.java
@@ -551,7 +551,7 @@
mRawContactIds.add(rawContactId);
}
AccountType type = accountTypes.getAccountType(accountType, dataSet);
- if (type == null || !type.readOnly) {
+ if (type == null || type.areContactsWritable()) {
mWritableRawContactIds.add(rawContactId);
}
@@ -1944,7 +1944,7 @@
AccountTypeManager.getInstance(mContext);
final AccountType type = accountTypes.getAccountType(accountType, dataSet);
// Offline or non-writeable account? Nothing to fix
- if (type == null || type.readOnly) return false;
+ if (type == null || !type.areContactsWritable()) return false;
// Check whether the contact is in the default group
boolean isInDefaultGroup = false;
diff --git a/src/com/android/contacts/editor/AggregationSuggestionView.java b/src/com/android/contacts/editor/AggregationSuggestionView.java
index 996dbc4..9d7e16a 100644
--- a/src/com/android/contacts/editor/AggregationSuggestionView.java
+++ b/src/com/android/contacts/editor/AggregationSuggestionView.java
@@ -120,7 +120,7 @@
return true;
}
AccountType type = accountTypes.getAccountType(accountType, dataSet);
- if (!type.readOnly) {
+ if (type.areContactsWritable()) {
return true;
}
}
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 2e54642..22fc3fc 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -519,7 +519,7 @@
final String accountType = state.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
final String dataSet = state.getValues().getAsString(RawContacts.DATA_SET);
final AccountType type = accountTypes.getAccountType(accountType, dataSet);
- if (!type.readOnly) {
+ if (type.areContactsWritable()) {
// Apply extras to the first writable raw contact only
EntityModifier.parseExtras(mContext, type, state, extras);
break;
@@ -698,7 +698,7 @@
editor.setState(entity, type, mViewIdGenerator, isEditingUserProfile());
editor.getPhotoEditor().setEditorListener(
- new PhotoEditorListener(editor, type.readOnly));
+ new PhotoEditorListener(editor, type.areContactsWritable()));
if (editor instanceof RawContactEditorView) {
final RawContactEditorView rawContactEditor = (RawContactEditorView) editor;
EditorListener listener = new EditorListener() {
@@ -1154,7 +1154,7 @@
final String accountType = values.getAsString(RawContacts.ACCOUNT_TYPE);
final String dataSet = values.getAsString(RawContacts.DATA_SET);
final AccountType type = accountTypes.getAccountType(accountType, dataSet);
- if (!type.readOnly) {
+ if (type.areContactsWritable()) {
return true;
}
}
@@ -1234,9 +1234,9 @@
final AccountType type2 = accountTypes.getAccountType(accountType2, dataSet2);
// Check read-only
- if (type1.readOnly && !type2.readOnly) {
+ if (!type1.areContactsWritable() && type2.areContactsWritable()) {
return 1;
- } else if (!type1.readOnly && type2.readOnly) {
+ } else if (type1.areContactsWritable() && !type2.areContactsWritable()) {
return -1;
}
@@ -1693,11 +1693,11 @@
private final class PhotoEditorListener
implements EditorListener, PhotoActionPopup.Listener {
private final BaseRawContactEditorView mEditor;
- private final boolean mAccountReadOnly;
+ private final boolean mAccountWritable;
- private PhotoEditorListener(BaseRawContactEditorView editor, boolean accountReadOnly) {
+ private PhotoEditorListener(BaseRawContactEditorView editor, boolean accountWritable) {
mEditor = editor;
- mAccountReadOnly = accountReadOnly;
+ mAccountWritable = accountWritable;
}
@Override
@@ -1707,14 +1707,7 @@
if (request == EditorListener.REQUEST_PICK_PHOTO) {
// Determine mode
final int mode;
- if (mAccountReadOnly) {
- if (mEditor.hasSetPhoto() && hasMoreThanOnePhoto()) {
- mode = PhotoActionPopup.MODE_READ_ONLY_ALLOW_PRIMARY;
- } else {
- // Read-only and either no photo or the only photo ==> no options
- return;
- }
- } else {
+ if (mAccountWritable) {
if (mEditor.hasSetPhoto()) {
if (hasMoreThanOnePhoto()) {
mode = PhotoActionPopup.MODE_PHOTO_ALLOW_PRIMARY;
@@ -1724,6 +1717,13 @@
} else {
mode = PhotoActionPopup.MODE_NO_PHOTO;
}
+ } else {
+ if (mEditor.hasSetPhoto() && hasMoreThanOnePhoto()) {
+ mode = PhotoActionPopup.MODE_READ_ONLY_ALLOW_PRIMARY;
+ } else {
+ // Read-only and either no photo or the only photo ==> no options
+ return;
+ }
}
PhotoActionPopup.createPopupMenu(mContext, mEditor.getPhotoEditor(), this, mode)
.show();
diff --git a/src/com/android/contacts/editor/ExternalRawContactEditorView.java b/src/com/android/contacts/editor/ExternalRawContactEditorView.java
index 9b4f988..21517ed 100644
--- a/src/com/android/contacts/editor/ExternalRawContactEditorView.java
+++ b/src/com/android/contacts/editor/ExternalRawContactEditorView.java
@@ -172,7 +172,7 @@
boolean hasPhotoEditor = type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null;
setHasPhotoEditor(hasPhotoEditor);
primary = state.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE);
- getPhotoEditor().setValues(kind, primary, state, type.readOnly, vig);
+ getPhotoEditor().setValues(kind, primary, state, !type.areContactsWritable(), vig);
if (!hasPhotoEditor || !getPhotoEditor().hasSetPhoto()) {
mPhotoStub.setVisibility(View.GONE);
} else {
@@ -187,7 +187,11 @@
mName.setText(primary != null ? primary.getAsString(StructuredName.DISPLAY_NAME) :
mContext.getString(R.string.missing_name));
- if (type.readOnly) {
+ if (type.areContactsWritable()) {
+ mAccountContainer.setBackgroundDrawable(null);
+ mAccountContainer.setEnabled(false);
+ mEditExternallyButton.setVisibility(View.VISIBLE);
+ } else {
mAccountContainer.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@@ -196,10 +200,6 @@
}
});
mEditExternallyButton.setVisibility(View.GONE);
- } else {
- mAccountContainer.setBackgroundDrawable(null);
- mAccountContainer.setEnabled(false);
- mEditExternallyButton.setVisibility(View.VISIBLE);
}
final Resources res = mContext.getResources();
diff --git a/src/com/android/contacts/interactions/ContactDeletionInteraction.java b/src/com/android/contacts/interactions/ContactDeletionInteraction.java
index 86f4eda..7e880a4 100644
--- a/src/com/android/contacts/interactions/ContactDeletionInteraction.java
+++ b/src/com/android/contacts/interactions/ContactDeletionInteraction.java
@@ -240,11 +240,11 @@
contactId = cursor.getLong(COLUMN_INDEX_CONTACT_ID);
lookupKey = cursor.getString(COLUMN_INDEX_LOOKUP_KEY);
AccountType type = accountTypes.getAccountType(accountType, dataSet);
- boolean readonly = type != null && type.readOnly;
- if (readonly) {
- readOnlyRawContacts.add(rawContactId);
- } else {
+ boolean writable = type == null || type.areContactsWritable();
+ if (writable) {
writableRawContacts.add(rawContactId);
+ } else {
+ readOnlyRawContacts.add(rawContactId);
}
}
diff --git a/src/com/android/contacts/model/AccountType.java b/src/com/android/contacts/model/AccountType.java
index 879a89f..eef8049 100644
--- a/src/com/android/contacts/model/AccountType.java
+++ b/src/com/android/contacts/model/AccountType.java
@@ -71,8 +71,6 @@
public int titleRes;
public int iconRes;
- public boolean readOnly;
-
/**
* Set of {@link DataKind} supported by this source.
*/
@@ -92,6 +90,11 @@
}
/**
+ * @return True if contacts can be created and edited using this app
+ */
+ public abstract boolean areContactsWritable();
+
+ /**
* Returns an optional custom edit activity. The activity class should reside
* in the sync adapter package as determined by {@link #resPackageName}.
*/
diff --git a/src/com/android/contacts/model/AccountTypeManager.java b/src/com/android/contacts/model/AccountTypeManager.java
index 33d6c97..bdd8a50 100644
--- a/src/com/android/contacts/model/AccountTypeManager.java
+++ b/src/com/android/contacts/model/AccountTypeManager.java
@@ -329,7 +329,6 @@
// Skip external account types that couldn't be initialized.
continue;
}
- accountType.readOnly = !sync.supportsUploading();
}
accountType.accountType = auth.type;
@@ -395,7 +394,7 @@
AccountWithDataSet accountWithDataSet = new AccountWithDataSet(
account.name, account.type, accountType.dataSet);
allAccounts.add(accountWithDataSet);
- if (!accountType.readOnly) {
+ if (accountType.areContactsWritable()) {
writableAccounts.add(accountWithDataSet);
}
}
diff --git a/src/com/android/contacts/model/BaseAccountType.java b/src/com/android/contacts/model/BaseAccountType.java
index e6c0400..b599c66 100644
--- a/src/com/android/contacts/model/BaseAccountType.java
+++ b/src/com/android/contacts/model/BaseAccountType.java
@@ -40,7 +40,7 @@
import android.provider.ContactsContract.CommonDataKinds.Website;
import android.view.inputmethod.EditorInfo;
-public class BaseAccountType extends AccountType {
+public abstract class BaseAccountType extends AccountType {
protected static final int FLAGS_PHONE = EditorInfo.TYPE_CLASS_PHONE;
protected static final int FLAGS_EMAIL = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
diff --git a/src/com/android/contacts/model/ExchangeAccountType.java b/src/com/android/contacts/model/ExchangeAccountType.java
index 240df47..4a0e7a0 100644
--- a/src/com/android/contacts/model/ExchangeAccountType.java
+++ b/src/com/android/contacts/model/ExchangeAccountType.java
@@ -339,4 +339,9 @@
public boolean isGroupMembershipEditable() {
return true;
}
+
+ @Override
+ public boolean areContactsWritable() {
+ return true;
+ }
}
diff --git a/src/com/android/contacts/model/ExternalAccountType.java b/src/com/android/contacts/model/ExternalAccountType.java
index 7fefc44..9718ce2 100644
--- a/src/com/android/contacts/model/ExternalAccountType.java
+++ b/src/com/android/contacts/model/ExternalAccountType.java
@@ -65,7 +65,6 @@
// The following attributes should only be set in non-sync-adapter account types. They allow
// for the account type and resource IDs to be specified without an associated authenticator.
private static final String ATTR_ACCOUNT_TYPE = "accountType";
- private static final String ATTR_READ_ONLY = "readOnly";
private static final String ATTR_ACCOUNT_LABEL = "accountTypeLabel";
private static final String ATTR_ACCOUNT_ICON = "accountTypeIcon";
@@ -143,6 +142,11 @@
return mInitSuccessful;
}
+ @Override
+ public boolean areContactsWritable() {
+ return getCreateContactActivityClassName() != null;
+ }
+
/**
* Whether this account type has the android.provider.CONTACTS_STRUCTURE metadata xml.
*/
@@ -251,8 +255,6 @@
mExtensionPackageNames.add(value);
} else if (ATTR_ACCOUNT_TYPE.equals(attr)) {
accountType = value;
- } else if (ATTR_READ_ONLY.equals(attr)) {
- readOnly = !"0".equals(value) && !"false".equals(value);
} else if (ATTR_ACCOUNT_LABEL.equals(attr)) {
mAccountTypeLabelAttribute = value;
} else if (ATTR_ACCOUNT_ICON.equals(attr)) {
diff --git a/src/com/android/contacts/model/FallbackAccountType.java b/src/com/android/contacts/model/FallbackAccountType.java
index 8bb3992..3b56b04 100644
--- a/src/com/android/contacts/model/FallbackAccountType.java
+++ b/src/com/android/contacts/model/FallbackAccountType.java
@@ -55,4 +55,9 @@
public int getSideBarColor(Context context) {
return 0xffbdc7b8;
}
+
+ @Override
+ public boolean areContactsWritable() {
+ return true;
+ }
}
diff --git a/src/com/android/contacts/model/GoogleAccountType.java b/src/com/android/contacts/model/GoogleAccountType.java
index a5fab96..cee43dd 100644
--- a/src/com/android/contacts/model/GoogleAccountType.java
+++ b/src/com/android/contacts/model/GoogleAccountType.java
@@ -183,4 +183,9 @@
public boolean isGroupMembershipEditable() {
return true;
}
+
+ @Override
+ public boolean areContactsWritable() {
+ return true;
+ }
}
diff --git a/tests/src/com/android/contacts/ContactLoaderTest.java b/tests/src/com/android/contacts/ContactLoaderTest.java
index 5d44cf1..f88b64e 100644
--- a/tests/src/com/android/contacts/ContactLoaderTest.java
+++ b/tests/src/com/android/contacts/ContactLoaderTest.java
@@ -51,7 +51,12 @@
mContactsProvider = mMockContext.getContactsProvider();
InjectedServices services = new InjectedServices();
- AccountType accountType = new BaseAccountType();
+ AccountType accountType = new BaseAccountType() {
+ @Override
+ public boolean areContactsWritable() {
+ return false;
+ }
+ };
accountType.accountType = "mockAccountType";
AccountWithDataSet account =
diff --git a/tests/src/com/android/contacts/EntityModifierTests.java b/tests/src/com/android/contacts/EntityModifierTests.java
index cf6fefe..76d3d84 100644
--- a/tests/src/com/android/contacts/EntityModifierTests.java
+++ b/tests/src/com/android/contacts/EntityModifierTests.java
@@ -153,6 +153,11 @@
public boolean isGroupMembershipEditable() {
return false;
}
+
+ @Override
+ public boolean areContactsWritable() {
+ return true;
+ }
}
/**
diff --git a/tests/src/com/android/contacts/activities/PeopleActivityTest.java b/tests/src/com/android/contacts/activities/PeopleActivityTest.java
index f419842..66c2c5a 100644
--- a/tests/src/com/android/contacts/activities/PeopleActivityTest.java
+++ b/tests/src/com/android/contacts/activities/PeopleActivityTest.java
@@ -94,7 +94,12 @@
services.setSharedPreferences(new MockSharedPreferences());
services.setSystemService(ContactPhotoManager.CONTACT_PHOTO_SERVICE,
new MockContactPhotoManager());
- AccountType accountType = new BaseAccountType();
+ AccountType accountType = new BaseAccountType() {
+ @Override
+ public boolean areContactsWritable() {
+ return false;
+ }
+ };
accountType.accountType = TEST_ACCOUNT_TYPE;
AccountWithDataSet account = new AccountWithDataSet(TEST_ACCOUNT, TEST_ACCOUNT_TYPE, null);
diff --git a/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java b/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java
index a6222db..2c4b74c 100644
--- a/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java
+++ b/tests/src/com/android/contacts/interactions/ContactDeletionInteractionTest.java
@@ -83,11 +83,20 @@
InjectedServices services = new InjectedServices();
services.setContentResolver(mContext.getContentResolver());
- AccountType readOnlyAccountType = new BaseAccountType();
+ AccountType readOnlyAccountType = new BaseAccountType() {
+ @Override
+ public boolean areContactsWritable() {
+ return false;
+ }
+ };
readOnlyAccountType.accountType = READONLY_ACCOUNT_TYPE;
- readOnlyAccountType.readOnly = true;
- AccountType writableAccountType = new BaseAccountType();
+ AccountType writableAccountType = new BaseAccountType() {
+ @Override
+ public boolean areContactsWritable() {
+ return true;
+ }
+ };
writableAccountType.accountType = WRITABLE_ACCOUNT_TYPE;
services.setSystemService(AccountTypeManager.ACCOUNT_TYPE_SERVICE,
diff --git a/tests/src/com/android/contacts/model/AccountTypeManagerTest.java b/tests/src/com/android/contacts/model/AccountTypeManagerTest.java
index 81c270f..aadf411 100644
--- a/tests/src/com/android/contacts/model/AccountTypeManagerTest.java
+++ b/tests/src/com/android/contacts/model/AccountTypeManagerTest.java
@@ -196,5 +196,10 @@
public boolean isGroupMembershipEditable() {
return false;
}
+
+ @Override
+ public boolean areContactsWritable() {
+ return false;
+ }
}
}
diff --git a/tests/src/com/android/contacts/model/AccountTypeTest.java b/tests/src/com/android/contacts/model/AccountTypeTest.java
index 3d80b52..9f7e7a2 100644
--- a/tests/src/com/android/contacts/model/AccountTypeTest.java
+++ b/tests/src/com/android/contacts/model/AccountTypeTest.java
@@ -84,6 +84,10 @@
@Override public boolean isGroupMembershipEditable() {
return false;
}
+
+ @Override public boolean areContactsWritable() {
+ return false;
+ }
};
assertEquals(getTestContext().getString(externalResID),
@@ -137,5 +141,10 @@
public boolean isGroupMembershipEditable() {
return false;
}
+
+ @Override
+ public boolean areContactsWritable() {
+ return false;
+ }
}
}