Add PHONEBOOK_COLLATOR toward SQLite so that database users are able to sort based on phonebook
in ja_JP locale.
In the future, we may able to use PHONEBOOK_COLLATOR in the other locales, but we don't use
the other phonebook collator now since we cannot estimate how impactful the change is.
Now we have a customized phonebook collator in Japanese and we need it in ContactsProvider,
we'll use only the collator.
Do not use this collator in the other packages and locales now. We may decide revert it in the
near future after furter investigatons.
Need to submit I4dd1b047 to make this change actually effective. Without the change,
we will have a phonebook collator for "previous" locale, not the current one.
Bug: 2514026
Bug: 2373557
Bug: 2373553
Change-Id: If6f548c0a80fe01e779b4dfc46f74224003f1798
diff --git a/android/sqlite3_android.cpp b/android/sqlite3_android.cpp
index a937573..11de1f7 100644
--- a/android/sqlite3_android.cpp
+++ b/android/sqlite3_android.cpp
@@ -420,6 +420,9 @@
#define LOCALIZED_COLLATOR_NAME "LOCALIZED"
+// This collator may be removed in the near future, so you MUST not use now.
+#define PHONEBOOK_COLLATOR_NAME "PHONEBOOK"
+
extern "C" int register_localized_collators(sqlite3* handle, const char* systemLocale, int utf16Storage)
{
int err;
@@ -438,7 +441,7 @@
status = U_ZERO_ERROR;
char buf[1024];
- int n = ucol_getShortDefinitionString(collator, NULL, buf, 1024, &status);
+ ucol_getShortDefinitionString(collator, NULL, buf, 1024, &status);
if (utf16Storage) {
err = sqlite3_create_collation_v2(handle, LOCALIZED_COLLATOR_NAME, SQLITE_UTF16, collator,
@@ -447,6 +450,7 @@
err = sqlite3_create_collation_v2(handle, LOCALIZED_COLLATOR_NAME, SQLITE_UTF8, collator,
collate8, (void(*)(void*))localized_collator_dtor);
}
+
if (err != SQLITE_OK) {
return err;
}
@@ -465,6 +469,41 @@
return err;
}
+
+ //// PHONEBOOK_COLLATOR
+ // The collator may be removed in the near future. Do not depend on it.
+ // TODO: it might be better to have another function for registering phonebook collator.
+ status = U_ZERO_ERROR;
+ if (strcmp(systemLocale, "ja") == 0 || strcmp(systemLocale, "ja_JP") == 0) {
+ collator = ucol_open("ja@collation=phonebook", &status);
+ } else {
+ collator = ucol_open(systemLocale, &status);
+ }
+ if (U_FAILURE(status)) {
+ return -1;
+ }
+
+ status = U_ZERO_ERROR;
+ ucol_setAttribute(collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
+ if (U_FAILURE(status)) {
+ return -1;
+ }
+
+ status = U_ZERO_ERROR;
+ // ucol_getShortDefinitionString(collator, NULL, buf, 1024, &status);
+ if (utf16Storage) {
+ err = sqlite3_create_collation_v2(handle, PHONEBOOK_COLLATOR_NAME, SQLITE_UTF16, collator,
+ collate16, (void(*)(void*))localized_collator_dtor);
+ } else {
+ err = sqlite3_create_collation_v2(handle, PHONEBOOK_COLLATOR_NAME, SQLITE_UTF8, collator,
+ collate8, (void(*)(void*))localized_collator_dtor);
+ }
+
+ if (err != SQLITE_OK) {
+ return err;
+ }
+ //// PHONEBOOK_COLLATOR
+
return SQLITE_OK;
}