aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcus Hagerott <mhagerott@google.com>2021-11-03 05:38:14 -0700
committerMarcus Hagerott <mhagerott@google.com>2021-12-13 16:24:26 -0800
commitc0da280272a578461c9d1698feba4491db39fcc8 (patch)
tree15d6957002d333f0cd7687e4388cffc210e93299 /src
parent5f48b2ce4c02fc18c205479add7b8451ce63317c (diff)
downloadContactsProvider-c0da280272a578461c9d1698feba4491db39fcc8.tar.gz
Use the config strings for the local contacts account
This allows custom local accounts to be handled the same as the AOSP local account. BUG=188858351 Test: atest ContactsProviderTestCases CtsContactsProviderTestCases Change-Id: Icf8b18c2713b8958e5b7150033794289d328907c
Diffstat (limited to 'src')
-rw-r--r--src/com/android/providers/contacts/AccountWithDataSet.java20
-rw-r--r--src/com/android/providers/contacts/ContactsDatabaseHelper.java42
-rw-r--r--src/com/android/providers/contacts/LegacyApiSupport.java17
-rw-r--r--src/com/android/providers/contacts/database/MoreDatabaseUtils.java32
4 files changed, 91 insertions, 20 deletions
diff --git a/src/com/android/providers/contacts/AccountWithDataSet.java b/src/com/android/providers/contacts/AccountWithDataSet.java
index e1f633ea..c20edce7 100644
--- a/src/com/android/providers/contacts/AccountWithDataSet.java
+++ b/src/com/android/providers/contacts/AccountWithDataSet.java
@@ -17,11 +17,15 @@
package com.android.providers.contacts;
import android.accounts.Account;
-import android.provider.ContactsContract;
+import android.content.res.Resources;
+import android.database.DatabaseUtils;
import android.provider.ContactsContract.SimAccount;
import android.text.TextUtils;
+import com.android.internal.R;
+
import com.google.common.base.Objects;
+import com.google.common.base.Strings;
import java.util.List;
@@ -29,7 +33,16 @@ import java.util.List;
* Account information that includes the data set, if any.
*/
public class AccountWithDataSet {
- public static final AccountWithDataSet LOCAL = new AccountWithDataSet(null, null, null);
+ public static final AccountWithDataSet LOCAL;
+
+ static {
+ Resources resources = Resources.getSystem();
+ String accountName = Strings.nullToEmpty(
+ resources.getString(R.string.config_rawContactsLocalAccountName));
+ String accountType = Strings.nullToEmpty(
+ resources.getString(R.string.config_rawContactsLocalAccountType));
+ LOCAL = new AccountWithDataSet(accountName, accountType, null);
+ }
private final String mAccountName;
private final String mAccountType;
@@ -66,7 +79,8 @@ public class AccountWithDataSet {
}
public boolean isLocalAccount() {
- return (mAccountName == null) && (mAccountType == null);
+ return LOCAL.equals(this) || (
+ mAccountName == null && mAccountType == null && mDataSet == null);
}
@Override
diff --git a/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
index e9b830a8..89dcaea1 100644
--- a/src/com/android/providers/contacts/ContactsDatabaseHelper.java
+++ b/src/com/android/providers/contacts/ContactsDatabaseHelper.java
@@ -92,6 +92,7 @@ import android.util.Log;
import android.util.Slog;
import com.android.common.content.SyncStateContentProviderHelper;
+import com.android.internal.R;
import com.android.internal.R.bool;
import com.android.internal.annotations.VisibleForTesting;
import com.android.providers.contacts.aggregation.util.CommonNicknameCache;
@@ -104,6 +105,8 @@ import com.android.providers.contacts.sqlite.SqlChecker.InvalidSqlException;
import com.android.providers.contacts.util.NeededForTesting;
import com.android.providers.contacts.util.PropertyUtils;
+import com.google.common.base.Strings;
+
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -355,18 +358,30 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
}
public interface Clauses {
+
final String HAVING_NO_GROUPS = "COUNT(" + DataColumns.CONCRETE_GROUP_ID + ") == 0";
final String GROUP_BY_ACCOUNT_CONTACT_ID = AccountsColumns.CONCRETE_ID + ","
+ RawContacts.CONTACT_ID;
String LOCAL_ACCOUNT_ID =
- "(SELECT " + AccountsColumns._ID +
- " FROM " + Tables.ACCOUNTS +
- " WHERE " +
- AccountsColumns.ACCOUNT_NAME + " IS NULL AND " +
- AccountsColumns.ACCOUNT_TYPE + " IS NULL AND " +
- AccountsColumns.DATA_SET + " IS NULL)";
+ "(SELECT "
+ + AccountsColumns._ID
+ + " FROM "
+ + Tables.ACCOUNTS
+ + " WHERE "
+ + AccountsColumns.ACCOUNT_NAME
+ + " IS "
+ + MoreDatabaseUtils.sqlEscapeNullableString(
+ AccountWithDataSet.LOCAL.getAccountName())
+ + " AND "
+ + AccountsColumns.ACCOUNT_TYPE
+ + " IS "
+ + MoreDatabaseUtils.sqlEscapeNullableString(
+ AccountWithDataSet.LOCAL.getAccountType())
+ + " AND "
+ + AccountsColumns.DATA_SET
+ + " IS NULL)";
final String ZERO_GROUP_MEMBERSHIPS = "COUNT(" + GroupsColumns.CONCRETE_ID + ")=0";
@@ -2276,16 +2291,21 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper {
+ AccountsColumns.SHOULD_SYNC + " = NEW." + Settings.SHOULD_SYNC + " "
+ "WHERE _id = OLD." + ViewSettingsColumns.ACCOUNT_ID + "; "
+ "END;");
+
// Unlike other accounts ungrouped contacts in the local account are visible by default and
// it is not syncable.
+ String localAccountNameSqlLiteral = MoreDatabaseUtils.sqlEscapeNullableString(
+ AccountWithDataSet.LOCAL.getAccountName());
+ String localAccountTypeSqlLiteral = MoreDatabaseUtils.sqlEscapeNullableString(
+ AccountWithDataSet.LOCAL.getAccountType());
db.execSQL("CREATE TRIGGER " + Tables.ACCOUNTS + "_insert_local_account "
+ "AFTER INSERT ON " + Tables.ACCOUNTS + " "
- + "WHEN NEW." + AccountsColumns.ACCOUNT_NAME + " IS NULL AND "
- + "NEW." + AccountsColumns.ACCOUNT_TYPE + " IS NULL AND "
- + "NEW." + AccountsColumns.DATA_SET + " IS NULL "
+ + "WHEN NEW." + AccountsColumns.ACCOUNT_NAME + " IS " + localAccountNameSqlLiteral
+ + " AND NEW." + AccountsColumns.ACCOUNT_TYPE + " IS " + localAccountTypeSqlLiteral
+ + " AND NEW." + AccountsColumns.DATA_SET + " IS NULL "
+ "BEGIN UPDATE " + Tables.ACCOUNTS + " SET "
- + Settings.UNGROUPED_VISIBLE + " = 1, "
- + Settings.SHOULD_SYNC + " = 0 "
+ + Settings.UNGROUPED_VISIBLE + " = 1, "
+ + Settings.SHOULD_SYNC + " = 0 "
+ "WHERE " + AccountsColumns._ID + " = NEW." + AccountsColumns._ID + "; "
+ "END;"
);
diff --git a/src/com/android/providers/contacts/LegacyApiSupport.java b/src/com/android/providers/contacts/LegacyApiSupport.java
index deff98a3..3120fae2 100644
--- a/src/com/android/providers/contacts/LegacyApiSupport.java
+++ b/src/com/android/providers/contacts/LegacyApiSupport.java
@@ -66,6 +66,7 @@ import com.android.providers.contacts.ContactsDatabaseHelper.RawContactsColumns;
import com.android.providers.contacts.ContactsDatabaseHelper.StatusUpdatesColumns;
import com.android.providers.contacts.ContactsDatabaseHelper.Tables;
import com.android.providers.contacts.ContactsDatabaseHelper.Views;
+import com.android.providers.contacts.database.MoreDatabaseUtils;
import java.util.Locale;
@@ -1860,8 +1861,12 @@ public class LegacyApiSupport {
sb.append(" AND " + RawContacts.ACCOUNT_TYPE + "=");
DatabaseUtils.appendEscapedSQLString(sb, mAccount.type);
} else {
- sb.append(RawContacts.ACCOUNT_NAME + " IS NULL" +
- " AND " + RawContacts.ACCOUNT_TYPE + " IS NULL");
+ sb.append(RawContacts.ACCOUNT_NAME + " IS ");
+ MoreDatabaseUtils.appendEscapedSQLStringOrLiteralNull(
+ sb, AccountWithDataSet.LOCAL.getAccountName());
+ sb.append(" AND ").append(RawContacts.ACCOUNT_TYPE + " IS ");
+ MoreDatabaseUtils.appendEscapedSQLStringOrLiteralNull(
+ sb, AccountWithDataSet.LOCAL.getAccountType());
}
}
@@ -1878,8 +1883,12 @@ public class LegacyApiSupport {
sb.append(" AND " + Groups.ACCOUNT_TYPE + "=");
DatabaseUtils.appendEscapedSQLString(sb, mAccount.type);
} else {
- sb.append(Groups.ACCOUNT_NAME + " IS NULL" +
- " AND " + Groups.ACCOUNT_TYPE + " IS NULL");
+ sb.append(Groups.ACCOUNT_NAME + " IS ");
+ MoreDatabaseUtils.appendEscapedSQLStringOrLiteralNull(
+ sb, AccountWithDataSet.LOCAL.getAccountName());
+ sb.append(" AND " + Groups.ACCOUNT_TYPE + " IS ");
+ MoreDatabaseUtils.appendEscapedSQLStringOrLiteralNull(
+ sb, AccountWithDataSet.LOCAL.getAccountType());
}
}
diff --git a/src/com/android/providers/contacts/database/MoreDatabaseUtils.java b/src/com/android/providers/contacts/database/MoreDatabaseUtils.java
index 3dadb3fb..61ffb9f1 100644
--- a/src/com/android/providers/contacts/database/MoreDatabaseUtils.java
+++ b/src/com/android/providers/contacts/database/MoreDatabaseUtils.java
@@ -16,11 +16,13 @@
package com.android.providers.contacts.database;
-import com.android.providers.contacts.util.NeededForTesting;
-
+import android.annotation.Nullable;
import android.database.Cursor;
+import android.database.DatabaseUtils;
import android.util.Log;
+import com.android.providers.contacts.util.NeededForTesting;
+
/**
* Static methods for database operations.
*/
@@ -108,4 +110,30 @@ public class MoreDatabaseUtils {
Log.d(logTag, sb.toString());
}
}
+
+ /**
+ * Same as {@link DatabaseUtils#sqlEscapeString(String)} but handles a null argument by
+ * returning the string "NULL".
+ *
+ * @return the SQL-escaped string or "NULL" if the argument is null.
+ */
+ @Nullable
+ public static String sqlEscapeNullableString(@Nullable String s) {
+ return s == null
+ ? "NULL"
+ : DatabaseUtils.sqlEscapeString(s);
+ }
+
+ /**
+ * Same as {@link DatabaseUtils#appendEscapedSQLString(StringBuilder, String)} but handles a
+ * null argument by appending the literal string "NULL".
+ */
+ @Nullable
+ public static void appendEscapedSQLStringOrLiteralNull(StringBuilder sb, @Nullable String s) {
+ if (s == null) {
+ sb.append("NULL");
+ } else {
+ DatabaseUtils.appendEscapedSQLString(sb, s);
+ }
+ }
}