BUG现象:
1:恢复出厂设置,重启开机后在设置向导中设置为中文,打开wifi,同步google联系人,此时可以搜索出联系人,同步完成后拔电池重新开机,进入拨号盘或联系人,此时搜索不出联系人。
2:恢复出厂设置,重启开机后在设置向导中设置为中文,此时可以搜索出卡中的联系人,放置一段时间后,约半个小时(吃个午饭),进入拨号盘或联系人,此时搜索不出联系人。(此时与google帐户联系人无关)
原因:
电话号码的搜索关键字的编码与Locale相关,Locale变化后手机中的搜索索引表的name字段的编码没有更新,与搜索关键字的编码不对应。
导入对策:
1、google的修改方案,切换语言时重建搜索索引表。
2、开机时检查Locale,搜索索引表中编码与关键字编码不一致时重建搜索索引表。
3、每次搜索时,搜索索引表中编码与关键字编码不一致时重建搜索索引表。
影响范围:
修改的内容均为联系人的数据支持部分
以下为修改代码的patch:
commit f054692f0d2cf09dbfed7ff0bcc391baf9295576Author: wutuo <[email protected]>Date: Sun Feb 17 09:25:50 2013 +0000 解决问题:google帐户同步后重启搜索不到联系人 git-svn-id: svn:[email protected] e89ae1c7-cfc9-4d8c-8e5a-bd7b9746a3badiff --git a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsDatabaseHelper.java b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsDatabaseHelper.javaindex 3392b38..40430dd 100644--- a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsDatabaseHelper.java+++ b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsDatabaseHelper.java@@ -2597,6 +2597,7 @@ public class ContactsDatabaseHelper extends SQLiteOpenHelper { if (upgradeSearchIndex) { createSearchIndexTable(db); setProperty(db, SearchIndexManager.PROPERTY_SEARCH_INDEX_VERSION, "0");+ setProperty(db, SearchIndexManager.PROPERTY_SEARCH_INDEX_LOCALE, ""); } if (rescanDirectories) {diff --git a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsProvider2.java b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsProvider2.javaindex 040cc79..8fc4e54 100644--- a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsProvider2.java+++ b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/ContactsProvider2.java@@ -1791,6 +1791,7 @@ public class ContactsProvider2 extends AbstractContactsProvider setProviderStatus(ProviderStatus.STATUS_CHANGING_LOCALE); mContactsHelper.setLocale(this, currentLocale); mProfileHelper.setLocale(this, currentLocale);+ mSearchIndexManager.updateIndex(true); prefs.edit().putString(PREF_LOCALE, currentLocale.toString()).apply(); invalidateFastScrollingIndexCache(); setProviderStatus(providerStatus);@@ -1821,7 +1822,7 @@ public class ContactsProvider2 extends AbstractContactsProvider } protected void updateSearchIndexInBackground() {- mSearchIndexManager.updateIndex();+ mSearchIndexManager.updateIndex(false); } protected void updateDirectoriesInBackground(boolean rescan) {@@ -5792,6 +5793,10 @@ public class ContactsProvider2 extends AbstractContactsProvider case PHONES_FILTER: case CALLABLES_FILTER: {+ if(!mSearchIndexManager.getSearchIndexLocale().equals(NameNormalizer.getLocale().toString()))+ {+ scheduleBackgroundTask(BACKGROUND_TASK_UPDATE_SEARCH_INDEX);+ } final String mimeTypeIsPhoneExpression = DataColumns.MIMETYPE_ID + "=" + mDbHelper.get().getMimeTypeIdForPhone(); final String mimeTypeIsSipExpression =diff --git a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/NameNormalizer.java b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/NameNormalizer.javaindex d91bd7c..193f449 100644--- a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/NameNormalizer.java+++ b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/NameNormalizer.java@@ -29,11 +29,13 @@ import java.text.RuleBasedCollator; public class NameNormalizer { private static final RuleBasedCollator sCompressingCollator;+ private static final Locale mLocale; static { sCompressingCollator = (RuleBasedCollator)Collator.getInstance(Locale.getDefault()); sCompressingCollator.setStrength(Collator.PRIMARY); sCompressingCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);+ mLocale = Locale.getDefault(); } private static final RuleBasedCollator sComplexityCollator; static {@@ -41,6 +43,10 @@ public class NameNormalizer { sComplexityCollator.setStrength(Collator.SECONDARY); } + public static Locale getLocale() {+ return mLocale;+ }+ /** * Converts the supplied name to a string that can be used to perform approximate matching * of names. It ignores non-letter, non-digit characters, and removes accents.diff --git a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/SearchIndexManager.java b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/SearchIndexManager.javaindex bd4e1cc..c9d6fe3 100644--- a/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/SearchIndexManager.java+++ b/alps/packages/providers/ContactsProvider/src/com/android/providers/contacts/SearchIndexManager.java@@ -42,6 +42,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.regex.Pattern;+import java.util.Locale; /** * Maintains a search index for comprehensive contact search.@@ -52,6 +53,7 @@ public class SearchIndexManager { private static final boolean VERBOSE_LOGGING = Log.isLoggable(TAG, Log.VERBOSE); public static final String PROPERTY_SEARCH_INDEX_VERSION = "search_index";+ public static final String PROPERTY_SEARCH_INDEX_LOCALE = "search_index_locale"; private static final int SEARCH_INDEX_VERSION = 1; private static final class ContactIndexQuery {@@ -243,16 +245,26 @@ public class SearchIndexManager { mDbHelper = (ContactsDatabaseHelper) mContactsProvider.getDatabaseHelper(); } - public void updateIndex() {- if (getSearchIndexVersion() == SEARCH_INDEX_VERSION) {- return;- }+ public void updateIndex(boolean force) {+ if(!getSearchIndexLocale().equals(NameNormalizer.getLocale().toString()))+ {+ setSearchIndexVersion(0);+ }+ if(force) {+ setSearchIndexVersion(0);+ }+ else {+ if (getSearchIndexVersion() == SEARCH_INDEX_VERSION) {+ return;+ }+ } SQLiteDatabase db = mDbHelper.getWritableDatabase(); db.beginTransaction(); try { if (getSearchIndexVersion() != SEARCH_INDEX_VERSION) { rebuildIndex(db); setSearchIndexVersion(SEARCH_INDEX_VERSION);+ setSearchIndexLocale(NameNormalizer.getLocale().toString()); db.setTransactionSuccessful(); } } finally {@@ -394,6 +406,14 @@ public class SearchIndexManager { mDbHelper.setProperty(PROPERTY_SEARCH_INDEX_VERSION, String.valueOf(version)); } + public String getSearchIndexLocale() {+ return mDbHelper.getProperty(PROPERTY_SEARCH_INDEX_LOCALE , "0");+ }++ public void setSearchIndexLocale(String locale) {+ mDbHelper.setProperty(PROPERTY_SEARCH_INDEX_LOCALE , locale);+ }+ /** * Token separator that matches SQLite's "simple" tokenizer. * - Unicode codepoints >= 128: Everything