diff options
author | Jay Shrauner <shrauner@google.com> | 2013-02-27 14:53:41 -0800 |
---|---|---|
committer | Jay Shrauner <shrauner@google.com> | 2013-03-04 17:16:37 -0800 |
commit | 2d2e22626b698b2484026ae18eca3c2c6340f2d1 (patch) | |
tree | ea6320a5cda746895ad992bdde4150d6d5fbfd6f /src/com/android/providers/contacts/ContactsProvider2.java | |
parent | 21cfa6019b9fb82c23edf978d27904757207d9b0 (diff) | |
download | packages_providers_ContactsProvider-2d2e22626b698b2484026ae18eca3c2c6340f2d1.zip packages_providers_ContactsProvider-2d2e22626b698b2484026ae18eca3c2c6340f2d1.tar.gz packages_providers_ContactsProvider-2d2e22626b698b2484026ae18eca3c2c6340f2d1.tar.bz2 |
Auto-update ContactsDB on ICU version change
Save current ICU version into the ContactsDB and rebuild
locale specific data whenever the version changes.
Bug:
Change-Id: Id5fd3e178558dc903b522b2655c75e6aa353f6e5
Diffstat (limited to 'src/com/android/providers/contacts/ContactsProvider2.java')
-rw-r--r-- | src/com/android/providers/contacts/ContactsProvider2.java | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 1d88298..b9eb4dc 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -1390,7 +1390,7 @@ public class ContactsProvider2 extends AbstractContactsProvider StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); - mFastScrollingIndexCache = new FastScrollingIndexCache(getContext()); + mFastScrollingIndexCache = FastScrollingIndexCache.getInstance(getContext()); mContactsHelper = getDatabaseHelper(getContext()); mDbHelper.set(mContactsHelper); @@ -1623,6 +1623,26 @@ public class ContactsProvider2 extends AbstractContactsProvider scheduleBackgroundTask(BACKGROUND_TASK_CHANGE_LOCALE); } + private static boolean needsToUpdateLocaleData(SharedPreferences prefs, + Locale locale,ContactsDatabaseHelper contactsHelper, + ProfileDatabaseHelper profileHelper) { + final String providerLocale = prefs.getString(PREF_LOCALE, null); + + // If locale matches that of the provider, and neither DB needs + // updating, there's nothing to do. A DB might require updating + // as a result of a system upgrade. + if (!locale.toString().equals(providerLocale)) { + Log.i(TAG, "Locale has changed from " + providerLocale + + " to " + locale.toString()); + return true; + } + if (contactsHelper.needsToUpdateLocaleData(locale) || + profileHelper.needsToUpdateLocaleData(locale)) { + return true; + } + return false; + } + /** * Verifies that the contacts database is properly configured for the current locale. * If not, changes the database locale to the current locale using an asynchronous task. @@ -1637,23 +1657,44 @@ public class ContactsProvider2 extends AbstractContactsProvider return; } - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - final String providerLocale = prefs.getString(PREF_LOCALE, null); final Locale currentLocale = mCurrentLocale; - if (currentLocale.toString().equals(providerLocale)) { + final SharedPreferences prefs = + PreferenceManager.getDefaultSharedPreferences(getContext()); + if (!needsToUpdateLocaleData(prefs, currentLocale, + mContactsHelper, mProfileHelper)) { return; } int providerStatus = mProviderStatus; setProviderStatus(ProviderStatus.STATUS_CHANGING_LOCALE); - mContactsHelper.setLocale(this, currentLocale); - mProfileHelper.setLocale(this, currentLocale); + mContactsHelper.setLocale(currentLocale); + mProfileHelper.setLocale(currentLocale); mSearchIndexManager.updateIndex(true); - prefs.edit().putString(PREF_LOCALE, currentLocale.toString()).apply(); - invalidateFastScrollingIndexCache(); + prefs.edit().putString(PREF_LOCALE, currentLocale.toString()).commit(); setProviderStatus(providerStatus); } + // Static update routine for use by ContactsUpgradeReceiver during startup. + // This clears the search index and marks it to be rebuilt, but doesn't + // actually rebuild it. That is done later by + // BACKGROUND_TASK_UPDATE_SEARCH_INDEX. + protected static void updateLocaleOffline(Context context, + ContactsDatabaseHelper contactsHelper, + ProfileDatabaseHelper profileHelper) { + final Locale currentLocale = Locale.getDefault(); + final SharedPreferences prefs = + PreferenceManager.getDefaultSharedPreferences(context); + if (!needsToUpdateLocaleData(prefs, currentLocale, + contactsHelper, profileHelper)) { + return; + } + + contactsHelper.setLocale(currentLocale); + profileHelper.setLocale(currentLocale); + contactsHelper.rebuildSearchIndex(); + prefs.edit().putString(PREF_LOCALE, currentLocale.toString()).commit(); + } + /** * Reinitializes the provider for a new locale. */ |