diff options
author | Rohit Yengisetty <rohit@cyngn.com> | 2016-05-12 16:23:05 -0700 |
---|---|---|
committer | Rohit Yengisetty <rohit@cyngn.com> | 2016-05-24 10:02:42 -0700 |
commit | e78a3c7f548ae8d1914927d1f86b0435a4d6f1de (patch) | |
tree | 1eacce9d97910342cfa1aaa56611b7a5622b8b1a | |
parent | 23ea70b81a50f7e7dfd2bf39449abbb4375820d2 (diff) | |
download | packages_providers_ContactsProvider-e78a3c7f548ae8d1914927d1f86b0435a4d6f1de.zip packages_providers_ContactsProvider-e78a3c7f548ae8d1914927d1f86b0435a4d6f1de.tar.gz packages_providers_ContactsProvider-e78a3c7f548ae8d1914927d1f86b0435a4d6f1de.tar.bz2 |
Obtain region config from system-property for Contacts pre-loading
If Telephony isn't ready during the first boot, then the Resource
configuration for Contacts pre-loading does't have the right
information to determine whether or not to add the default contacts.
This patch adds a check on the "ro.prebundled.mcc" system-property
to help determine the region specific configuration to use.
Issue-Id: PAELLA-50
Change-Id: I57f131bbf1cc41679c2ce76a6956b40a35093439
-rw-r--r-- | src/com/android/providers/contacts/ContactsProvider2.java | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/src/com/android/providers/contacts/ContactsProvider2.java b/src/com/android/providers/contacts/ContactsProvider2.java index 7c1f543..9d8f0ff 100644 --- a/src/com/android/providers/contacts/ContactsProvider2.java +++ b/src/com/android/providers/contacts/ContactsProvider2.java @@ -36,6 +36,8 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ProviderInfo; import android.content.res.AssetFileDescriptor; +import android.content.res.AssetManager; +import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.database.AbstractCursor; @@ -112,6 +114,7 @@ import android.provider.SyncStateContract; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; import android.text.TextUtils; +import android.util.DisplayMetrics; import android.util.Log; import com.android.common.content.ProjectionMap; import com.android.common.content.SyncStateContentProviderHelper; @@ -1834,10 +1837,13 @@ public class ContactsProvider2 extends AbstractContactsProvider } case BACKGROUND_TASK_ADD_DEFAULT_CONTACT: { - if (shouldAttemptPreloadingContacts()) { + Resources res = getRegionLockedResources(); + if (res == null) { + res = getContext().getResources(); + } + if (shouldAttemptPreloadingContacts(res)) { try { - InputStream inputStream = getContext().getResources().openRawResource( - R.raw.preloaded_contacts); + InputStream inputStream = res.openRawResource(R.raw.preloaded_contacts); PreloadedContactsFileParser pcfp = new PreloadedContactsFileParser(inputStream); ArrayList<ContentProviderOperation> cpOperations = pcfp.parseForContacts(); @@ -1849,7 +1855,6 @@ public class ContactsProvider2 extends AbstractContactsProvider onPreloadingContactsComplete(); } catch (NotFoundException nfe) { - System.out.println(); nfe.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); @@ -1866,9 +1871,46 @@ public class ContactsProvider2 extends AbstractContactsProvider } } - private boolean shouldAttemptPreloadingContacts() { + private Resources getRegionLockedResources() { + String mcc = SystemProperties.get("ro.prebundled.mcc"); + Resources customResources = null; + if (!TextUtils.isEmpty(mcc)) { + Configuration tempConfiguration = new Configuration(getContext().getResources(). + getConfiguration()); + boolean shouldUseTempConfig = false; + + try { + tempConfiguration.mcc = Integer.parseInt(mcc); + shouldUseTempConfig = true; + } catch (NumberFormatException e) { + Log.e(TAG, "Unable to parse mcc within ro.prebundled.mcc", e); + } + + if (shouldUseTempConfig) { + String publicSrcDir = null; + try { + String packageName = getContext().getPackageName(); + publicSrcDir = getContext().getPackageManager(). + getApplicationInfo(packageName, 0).publicSourceDir; + } catch (PackageManager.NameNotFoundException e) { + Log.e(TAG, "Failed getting source dir", e); + } + + AssetManager assetManager = new AssetManager(); + if (!TextUtils.isEmpty(publicSrcDir)) { + assetManager.addAssetPath(publicSrcDir); + } + customResources = new Resources(assetManager, new DisplayMetrics(), + tempConfiguration); + } + } + + return customResources; + } + + private boolean shouldAttemptPreloadingContacts(Resources res) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - return getContext().getResources().getBoolean(R.bool.config_preload_contacts) && + return res.getBoolean(R.bool.config_preload_contacts) && !prefs.getBoolean(PREF_PRELOADED_CONTACTS_ADDED, false); } |