summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-04-02 11:21:40 -0700
committerYorke Lee <yorkelee@google.com>2013-04-02 16:25:10 -0700
commitf43f537a0100693570606c436a81a12e21fb5b9e (patch)
tree0ed24ad3bd6fd80e104d929cc5ffeae5f9f0b782 /src
parent2eb493c61878d936bed055930a921fbea7b7e2b4 (diff)
Remove smart dialing content observer
The content observer doesn't help to detect changes that happen outside the application (e.g. user modifies a contact in the People app), and seems to be called multiple times while in the dialer for no reason, causing multiple unnecessary recaches. Instead, just force a recache in onResume upon startup to refresh the cache. Bug 8527847 Change-Id: I52f5c435ad573ce8b195d7b7828f19501e068c60
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/dialpad/DialpadFragment.java31
-rw-r--r--src/com/android/dialer/dialpad/SmartDialCache.java32
2 files changed, 21 insertions, 42 deletions
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index 123d700b7..3693e6aa0 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -79,7 +79,6 @@ import com.android.contacts.common.util.StopWatch;
import com.android.dialer.DialtactsActivity;
import com.android.dialer.R;
import com.android.dialer.SpecialCharSequenceMgr;
-import com.android.dialer.dialpad.SmartDialCache.SmartDialContentObserver;
import com.android.dialer.interactions.PhoneNumberInteraction;
import com.android.dialer.util.OrientationUtil;
import com.android.internal.telephony.ITelephony;
@@ -154,7 +153,6 @@ public class DialpadFragment extends Fragment
* Will be set only if the view has the smart dialing section.
*/
private SmartDialAdapter mSmartDialAdapter;
- private SmartDialContentObserver mSmartDialObserver;
/**
* Regular expression prohibiting manual phone call. Can be empty, which means "no rule".
@@ -226,6 +224,7 @@ public class DialpadFragment extends Fragment
private boolean mDigitsFilledByIntent;
private boolean mStartedFromNewIntent = false;
+ private boolean mFirstLaunch = false;
private static final String PREF_DIGITS_FILLED_BY_INTENT = "pref_digits_filled_by_intent";
@@ -280,7 +279,7 @@ public class DialpadFragment extends Fragment
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
-
+ mFirstLaunch = true;
mContactsPrefs = new ContactsPreferences(getActivity());
mCurrentCountryIso = GeoUtil.getCurrentCountryIso(getActivity());
mSmartDialCache = SmartDialCache.getInstance(getActivity(),
@@ -300,10 +299,6 @@ public class DialpadFragment extends Fragment
if (state != null) {
mDigitsFilledByIntent = state.getBoolean(PREF_DIGITS_FILLED_BY_INTENT);
}
-
- mSmartDialObserver = new SmartDialContentObserver(new Handler(), mSmartDialCache);
- this.getActivity().getContentResolver().registerContentObserver(
- SmartDialCache.PhoneQuery.URI, true, mSmartDialObserver);
}
@Override
@@ -614,6 +609,19 @@ public class DialpadFragment extends Fragment
showDialpadChooser(false);
}
+ // Don't force recache if this is the first time onResume is being called, since caching
+ // should already happen in setUserVisibleHint.
+ if (!mFirstLaunch) {
+ // This forced recache covers the case where the dialer was previously running, and
+ // was brought back into the foreground. If the dialpad fragment hasn't actually
+ // become visible throughout the entire activity's lifecycle, it is possible that
+ // caching hasn't happened yet. In this case, we can force a recache anyway, since we
+ // are not worried about startup performance anymore.
+ mSmartDialCache.cacheIfNeeded(true);
+ }
+
+ mFirstLaunch = false;
+
stopWatch.lap("hnt");
updateDialAndDeleteButtonEnabledState();
@@ -621,9 +629,6 @@ public class DialpadFragment extends Fragment
stopWatch.lap("bes");
stopWatch.stopAndLog(TAG, 50);
-
- this.getActivity().getContentResolver().registerContentObserver(
- SmartDialCache.PhoneQuery.URI, true, mSmartDialObserver);
}
@Override
@@ -651,8 +656,6 @@ public class DialpadFragment extends Fragment
mLastNumberDialed = EMPTY_NUMBER; // Since we are going to query again, free stale number.
SpecialCharSequenceMgr.cleanup();
-
- getActivity().getContentResolver().unregisterContentObserver(mSmartDialObserver);
}
@Override
@@ -1661,6 +1664,10 @@ public class DialpadFragment extends Fragment
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
+ // This is called if the dialpad fragment is swiped into to view for the very first
+ // time in the activity's lifecycle, or the user starts the dialer for the first time
+ // and the dialpad fragment is displayed immediately, and is what causes the initial
+ // caching process to happen.
mSmartDialCache.cacheIfNeeded(false);
}
}
diff --git a/src/com/android/dialer/dialpad/SmartDialCache.java b/src/com/android/dialer/dialpad/SmartDialCache.java
index dbec5a6b1..4f4ce1469 100644
--- a/src/com/android/dialer/dialpad/SmartDialCache.java
+++ b/src/com/android/dialer/dialpad/SmartDialCache.java
@@ -243,8 +243,8 @@ public class SmartDialCache {
/**
* Cache contacts only if there is a need to (forced cache refresh or no attempt to cache yet).
- * This method is called in 2 places: whenever the DialpadFragment comes into view, and when the
- * ContentObserver observes a change in contacts.
+ * This method is called in 2 places: whenever the DialpadFragment comes into view, and in
+ * onResume.
*
* @param forceRecache If true, force a cache refresh.
*/
@@ -284,32 +284,4 @@ public class SmartDialCache {
}
}
-
- public static class SmartDialContentObserver extends ContentObserver {
- private final SmartDialCache mCache;
- // throttle updates in case onChange is called too often due to syncing, etc.
- private final long mThresholdBetweenUpdates = 5000;
- private long mLastCalled = 0;
- private long mLastUpdated = 0;
- public SmartDialContentObserver(Handler handler, SmartDialCache cache) {
- super(handler);
- mCache = cache;
- }
-
- @Override
- public void onChange(boolean selfChange) {
- mLastCalled = System.currentTimeMillis();
- if (DEBUG) {
- Log.d(LOG_TAG, "Contacts change observed");
- }
- if (mLastCalled - mLastUpdated > mThresholdBetweenUpdates) {
- mLastUpdated = mLastCalled;
- if (DEBUG) {
- Log.d(LOG_TAG, "More than 5 seconds since last cache, forcing recache");
- }
- mCache.cacheIfNeeded(true);
- }
- super.onChange(selfChange);
- }
- }
}