Revert "Add supports for SIM and Phone account"
This reverts commit fc091a15bd8c26b6dc4c5020f12867a04e597bfc.
Change-Id: I244cc9542566f303b2ef8929f08a1d0137810cf8
diff --git a/src/com/android/providers/contacts/AccountWithDataSet.java b/src/com/android/providers/contacts/AccountWithDataSet.java
index a654f50..bfae112 100644
--- a/src/com/android/providers/contacts/AccountWithDataSet.java
+++ b/src/com/android/providers/contacts/AccountWithDataSet.java
@@ -25,11 +25,7 @@
* Account information that includes the data set, if any.
*/
public class AccountWithDataSet {
- public static final String PHONE_NAME = "PHONE";
- public static final String ACCOUNT_TYPE_PHONE = "com.android.localphone";
- public static final String ACCOUNT_TYPE_SIM = "com.android.sim";
- public static final AccountWithDataSet LOCAL = new AccountWithDataSet(
- PHONE_NAME, ACCOUNT_TYPE_PHONE, null);
+ public static final AccountWithDataSet LOCAL = new AccountWithDataSet(null, null, null);
private final String mAccountName;
private final String mAccountType;
@@ -66,7 +62,7 @@
}
public boolean isLocalAccount() {
- return (PHONE_NAME.equals(mAccountName)) && (ACCOUNT_TYPE_PHONE.equals(mAccountType));
+ return (mAccountName == null) && (mAccountType == null);
}
@Override
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index 1d43fbc..aac37ba 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -335,8 +335,9 @@
"(SELECT " + AccountsColumns._ID +
" FROM " + Tables.ACCOUNTS +
" WHERE " +
- AccountsColumns.ACCOUNT_TYPE + "='" +
- AccountWithDataSet.ACCOUNT_TYPE_PHONE + "')";
+ AccountsColumns.ACCOUNT_NAME + " IS NULL AND " +
+ AccountsColumns.ACCOUNT_TYPE + " IS NULL AND " +
+ AccountsColumns.DATA_SET + " IS NULL)";
final String RAW_CONTACT_IS_LOCAL = RawContactsColumns.CONCRETE_ACCOUNT_ID
+ "=" + LOCAL_ACCOUNT_ID;
@@ -350,6 +351,8 @@
"SELECT " +
"MAX((SELECT (CASE WHEN " +
"(CASE" +
+ " WHEN " + RAW_CONTACT_IS_LOCAL +
+ " THEN 1 " +
" WHEN " + ZERO_GROUP_MEMBERSHIPS +
" THEN " + Settings.UNGROUPED_VISIBLE +
" ELSE MAX(" + Groups.GROUP_VISIBLE + ")" +
@@ -2019,18 +2022,13 @@
String contactsSelect = "SELECT "
+ ContactsColumns.CONCRETE_ID + " AS " + Contacts._ID + ","
+ contactsColumns + ", "
- + AccountsColumns.ACCOUNT_NAME + ", "
- + AccountsColumns.ACCOUNT_TYPE + ", "
+ buildDisplayPhotoUriAlias(ContactsColumns.CONCRETE_ID, Contacts.PHOTO_URI) + ", "
+ buildThumbnailPhotoUriAlias(ContactsColumns.CONCRETE_ID,
Contacts.PHOTO_THUMBNAIL_URI) + ", "
+ dbForProfile() + " AS " + Contacts.IS_USER_PROFILE
+ " FROM " + Tables.CONTACTS
+ " JOIN " + Tables.RAW_CONTACTS + " AS name_raw_contact ON("
- + Contacts.NAME_RAW_CONTACT_ID + "=name_raw_contact." + RawContacts._ID + ")"
- + " JOIN " + Tables.ACCOUNTS + " AS name_accounts ON("
- + "name_raw_contact." + RawContactsColumns.ACCOUNT_ID + "=name_accounts."
- + AccountsColumns._ID + ")";
+ + Contacts.NAME_RAW_CONTACT_ID + "=name_raw_contact." + RawContacts._ID + ")";
db.execSQL("CREATE VIEW " + Views.CONTACTS + " AS " + contactsSelect);
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java
index 94bf413..7dc7e7e 100644
--- a/src/com/android/providers/contacts/ContactsProvider2.java
+++ b/src/com/android/providers/contacts/ContactsProvider2.java
@@ -300,7 +300,6 @@
private static final String FREQUENT_ORDER_BY = DataUsageStatColumns.TIMES_USED + " DESC,"
+ Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
- private static String WITHOUT_SIM_FLAG = "no_sim";
private static final int CONTACTS = 1000;
private static final int CONTACTS_ID = 1001;
@@ -772,8 +771,6 @@
.add(Contacts.IS_USER_PROFILE)
.addAll(sContactsColumns)
.addAll(sContactsPresenceColumns)
- .add(RawContacts.ACCOUNT_TYPE)
- .add(RawContacts.ACCOUNT_NAME)
.build();
/** Contains just the contacts columns */
@@ -920,7 +917,6 @@
.addAll(sDataColumns)
.addAll(sDataPresenceColumns)
.addAll(sContactsColumns)
- .addAll(sRawContactColumns)
.addAll(sContactPresenceColumns)
.addAll(sDataUsageColumns)
.build();
@@ -2755,7 +2751,7 @@
final long rawContactId = db.insert(Tables.RAW_CONTACTS, RawContacts.CONTACT_ID, values);
final int aggregationMode = getIntValue(values, RawContacts.AGGREGATION_MODE,
- RawContacts.AGGREGATION_MODE_SUSPENDED);
+ RawContacts.AGGREGATION_MODE_DEFAULT);
mAggregator.get().markNewForAggregation(rawContactId, aggregationMode);
// Trigger creation of a Contact based on this RawContact at the end of transaction.
@@ -7326,58 +7322,6 @@
StringBuilder sb = new StringBuilder();
sb.append(Views.CONTACTS);
- /* Do not show contacts when SIM card is disabled for CONTACTS_FILTER */
- StringBuilder sbWhere = new StringBuilder();
- String withoutSim = getQueryParameter(uri, WITHOUT_SIM_FLAG );
- if ("true".equals(withoutSim)) {
- final long[] accountId = getAccountIdWithoutSim(uri);
- if (accountId == null) {
- // No such account.
- sbWhere.setLength(0);
- sbWhere.append("(1=2)");
- } else {
- if (accountId.length > 0) {
- sbWhere.append(" (" + Contacts._ID + " not IN (" + "SELECT "
- + RawContacts.CONTACT_ID + " FROM "
- + Tables.RAW_CONTACTS + " WHERE "
- + RawContacts.CONTACT_ID + " not NULL AND ( ");
- for (int i = 0; i < accountId.length; i++) {
- sbWhere.append(RawContactsColumns.ACCOUNT_ID + "="
- + accountId[i]);
- if (i != accountId.length - 1) {
- sbWhere.append(" OR ");
- }
- }
- sbWhere.append(")))");
- }
- }
- } else {
- final AccountWithDataSet accountWithDataSet = getAccountWithDataSetFromUri(uri);
- // Accounts are valid by only checking one parameter, since we've
- // already ruled out partial accounts.
- final boolean validAccount = !TextUtils.isEmpty(accountWithDataSet.getAccountName());
- if (validAccount) {
- final Long accountId = mDbHelper.get().getAccountIdOrNull(accountWithDataSet);
- if (accountId != null) {
- sbWhere.append(" INNER JOIN (SELECT "
- + RawContacts.CONTACT_ID
- + " AS raw_contact_contact_id FROM "
- + Tables.RAW_CONTACTS + " WHERE "
- + RawContactsColumns.ACCOUNT_ID + " = "
- + accountId
- + ") ON raw_contact_contact_id = " + Contacts._ID);
- }
- }
- }
-
- if (!TextUtils.isEmpty(sbWhere.toString())) {
- if ("true".equals(withoutSim)) {
- qb.appendWhere(sbWhere.toString());
- } else {
- sb.append(sbWhere.toString());
- }
- }
-
if (filter != null) {
filter = filter.trim();
}
@@ -7802,50 +7746,22 @@
sb.append("(1)");
}
- String withoutSim = getQueryParameter(uri, WITHOUT_SIM_FLAG );
- if ("true".equals(withoutSim)) {
- final long[] accountId = getAccountIdWithoutSim(uri);
-
+ final AccountWithDataSet accountWithDataSet = getAccountWithDataSetFromUri(uri);
+ // Accounts are valid by only checking one parameter, since we've
+ // already ruled out partial accounts.
+ final boolean validAccount = !TextUtils.isEmpty(accountWithDataSet.getAccountName());
+ if (validAccount) {
+ final Long accountId = mDbHelper.get().getAccountIdOrNull(accountWithDataSet);
if (accountId == null) {
// No such account.
sb.setLength(0);
sb.append("(1=2)");
} else {
- if (accountId.length > 0) {
- sb.append(
- " AND (" + Contacts._ID + " not IN (" +
- "SELECT " + RawContacts.CONTACT_ID + " FROM "
- + Tables.RAW_CONTACTS +
- " WHERE " + RawContacts.CONTACT_ID + " not NULL AND ( ");
- for (int i = 0; i < accountId.length; i++) {
- sb.append(RawContactsColumns.ACCOUNT_ID + "="
- + accountId[i]);
- if (i != accountId.length - 1) {
- sb.append(" or ");
- }
- }
- sb.append(")))");
- }
- }
- }
- else {
- final AccountWithDataSet accountWithDataSet = getAccountWithDataSetFromUri(uri);
- // Accounts are valid by only checking one parameter, since we've
- // already ruled out partial accounts.
- final boolean validAccount = !TextUtils.isEmpty(accountWithDataSet.getAccountName());
- if (validAccount) {
- final Long accountId = mDbHelper.get().getAccountIdOrNull(accountWithDataSet);
- if (accountId == null) {
- // No such account.
- sb.setLength(0);
- sb.append("(1=2)");
- } else {
- sb.append(
- " AND (" + Contacts._ID + " IN (" +
- "SELECT " + RawContacts.CONTACT_ID + " FROM " + Tables.RAW_CONTACTS +
- " WHERE " + RawContactsColumns.ACCOUNT_ID + "=" + accountId.toString() +
- "))");
- }
+ sb.append(
+ " AND (" + Contacts._ID + " IN (" +
+ "SELECT " + RawContacts.CONTACT_ID + " FROM " + Tables.RAW_CONTACTS +
+ " WHERE " + RawContactsColumns.ACCOUNT_ID + "=" + accountId.toString() +
+ "))");
}
}
qb.appendWhere(sb.toString());
@@ -7895,56 +7811,6 @@
}
}
- private long[] getAccountIdWithoutSim(Uri uri) {
- final String accountType = getQueryParameter(uri, RawContacts.ACCOUNT_TYPE);
- final String accountName = getQueryParameter(uri, RawContacts.ACCOUNT_NAME);
- Cursor c = null;
- SQLiteDatabase db = mContactsHelper.getWritableDatabase();
- long[] accountId = null;
- try {
- if (null != accountType) {
- c = db.query(Tables.ACCOUNTS,
- new String[] { AccountsColumns._ID },
- AccountsColumns.ACCOUNT_TYPE + "=?",
- new String[] { String.valueOf(accountType) }, null,
- null, null);
- } else if (!TextUtils.isEmpty(accountName)) {
- String[] names = accountName.split(",");
- int nameCount = names.length;
- String where = AccountsColumns.ACCOUNT_NAME + "=?";
- StringBuilder selection = new StringBuilder();
- String[] selectionArgs = new String[nameCount];
- for (int i = 0; i < nameCount; i++) {
- selection.append(where);
- if (i != nameCount - 1) {
- selection.append(" OR ");
- }
- selectionArgs[i] = names[i];
- }
- c = db.query(Tables.ACCOUNTS,
- new String[] { AccountsColumns._ID },
- selection.toString(),
- selectionArgs, null,
- null, null);
- }
-
- if (c != null) {
- accountId = new long[c.getCount()];
-
- for (int i = 0; i < c.getCount(); i++) {
- if (c.moveToNext()) {
- accountId[c.getPosition()] = c.getInt(0);
- }
- }
- }
- } finally {
- if (c != null) {
- c.close();
- }
- }
- return accountId;
- }
-
private AccountWithDataSet getAccountWithDataSetFromUri(Uri uri) {
final String accountName = getQueryParameter(uri, RawContacts.ACCOUNT_NAME);
final String accountType = getQueryParameter(uri, RawContacts.ACCOUNT_TYPE);
diff --git a/src/com/android/providers/contacts/LegacyApiSupport.java b/src/com/android/providers/contacts/LegacyApiSupport.java
index 060f87e..598a4a0 100644
--- a/src/com/android/providers/contacts/LegacyApiSupport.java
+++ b/src/com/android/providers/contacts/LegacyApiSupport.java
@@ -1937,7 +1937,8 @@
sb.append(" AND " + RawContacts.ACCOUNT_TYPE + "=");
DatabaseUtils.appendEscapedSQLString(sb, mAccount.type);
} else {
- sb.append("1=1");
+ sb.append(RawContacts.ACCOUNT_NAME + " IS NULL" +
+ " AND " + RawContacts.ACCOUNT_TYPE + " IS NULL");
}
}
@@ -1954,10 +1955,8 @@
sb.append(" AND " + Groups.ACCOUNT_TYPE + "=");
DatabaseUtils.appendEscapedSQLString(sb, mAccount.type);
} else {
- sb.append(Groups.ACCOUNT_NAME + " = '"
- + AccountWithDataSet.LOCAL.getAccountName() + "' AND "
- + Groups.ACCOUNT_TYPE + " = '"
- + AccountWithDataSet.LOCAL.getAccountType() + "'");
+ sb.append(Groups.ACCOUNT_NAME + " IS NULL" +
+ " AND " + Groups.ACCOUNT_TYPE + " IS NULL");
}
}