summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java
diff options
context:
space:
mode:
authorMakoto Onuki <omakoto@google.com>2011-08-28 15:25:28 -0700
committerMakoto Onuki <omakoto@google.com>2011-08-30 11:33:26 -0700
commitc4144727cd740079f47e74ae5078d1613874f72a (patch)
tree6b253a3bb0b78c6fee5059655e75a6764bdad79c /src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java
parent663b8b8ce7a29fb2796dc6431f2cd5992934f315 (diff)
downloadpackages_providers_ContactsProvider-c4144727cd740079f47e74ae5078d1613874f72a.zip
packages_providers_ContactsProvider-c4144727cd740079f47e74ae5078d1613874f72a.tar.gz
packages_providers_ContactsProvider-c4144727cd740079f47e74ae5078d1613874f72a.tar.bz2
Lazily-initialize PhoneNumberOfflineGeocoder/PhoneNumberUtil
- They were indirectly created in VoicemailContentProvider.onCreate and CallLogProvider.onCreate, and were slow. It was taking ~300ms on my measurement on a nexus-s. Also it touched the filesystem, so it can be much slower on worn-out flash or when flash is busy. - Doing it in a provider's onCreate means it affects auto-complete performance if acore is not started. Also it'll affect app-startup when we merge processes. - But they were actually only used when inserting a call log, so we don't have to initialize them at startup. - Inserting a call-log should be done in a worker thread, so lazy- initialization shouldn't cause laggy UI. (Alternatively, we could initialize them in a worker thread at startup, but I don't think it's worth it.) - Also, now CallLogProvider and VoicemailContentProvider share the same instance of DefaultCallLogInsertionHelper. (They used to have their own) same instance of DefaultCallLogInsertionHelper doesn't have any instance specific state, so this should be safe. Bug 5220669 Change-Id: Ibcd664ed683507c5dcac88bec736e4903a4a7032
Diffstat (limited to 'src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java')
-rw-r--r--src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java b/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java
index 2552999..6777e43 100644
--- a/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java
+++ b/src/com/android/providers/contacts/DefaultCallLogInsertionHelper.java
@@ -24,6 +24,7 @@ import com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
import android.content.ContentValues;
import android.content.Context;
import android.provider.CallLog.Calls;
+import android.util.Log;
import java.util.Locale;
@@ -35,15 +36,22 @@ import java.util.Locale;
* It uses {@link PhoneNumberOfflineGeocoder} to compute the geocoded location of a phone number.
*/
/*package*/ class DefaultCallLogInsertionHelper implements CallLogInsertionHelper {
+ private static DefaultCallLogInsertionHelper sInstance;
+
private final CountryMonitor mCountryMonitor;
- private final PhoneNumberUtil mPhoneNumberUtil;
- private final PhoneNumberOfflineGeocoder mPhoneNumberOfflineGeocoder;
+ private PhoneNumberUtil mPhoneNumberUtil;
+ private PhoneNumberOfflineGeocoder mPhoneNumberOfflineGeocoder;
private final Locale mLocale;
- public DefaultCallLogInsertionHelper(Context context) {
+ public static synchronized DefaultCallLogInsertionHelper getInstance(Context context) {
+ if (sInstance == null) {
+ sInstance = new DefaultCallLogInsertionHelper(context);
+ }
+ return sInstance;
+ }
+
+ private DefaultCallLogInsertionHelper(Context context) {
mCountryMonitor = new CountryMonitor(context);
- mPhoneNumberUtil = PhoneNumberUtil.getInstance();
- mPhoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
mLocale = context.getResources().getConfiguration().locale;
}
@@ -61,19 +69,33 @@ import java.util.Locale;
return mCountryMonitor.getCountryIso();
}
+ private synchronized PhoneNumberUtil getPhoneNumberUtil() {
+ if (mPhoneNumberUtil == null) {
+ mPhoneNumberUtil = PhoneNumberUtil.getInstance();
+ }
+ return mPhoneNumberUtil;
+ }
+
private PhoneNumber parsePhoneNumber(String number, String countryIso) {
try {
- return mPhoneNumberUtil.parse(number, countryIso);
+ return getPhoneNumberUtil().parse(number, countryIso);
} catch (NumberParseException e) {
return null;
}
}
+ private synchronized PhoneNumberOfflineGeocoder getPhoneNumberOfflineGeocoder() {
+ if (mPhoneNumberOfflineGeocoder == null) {
+ mPhoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
+ }
+ return mPhoneNumberOfflineGeocoder;
+ }
+
@Override
public String getGeocodedLocationFor(String number, String countryIso) {
PhoneNumber structuredPhoneNumber = parsePhoneNumber(number, countryIso);
if (structuredPhoneNumber != null) {
- return mPhoneNumberOfflineGeocoder.getDescriptionForNumber(
+ return getPhoneNumberOfflineGeocoder().getDescriptionForNumber(
structuredPhoneNumber, mLocale);
} else {
return null;