diff options
author | Yorke Lee <yorkelee@google.com> | 2014-07-30 22:48:31 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-07-29 21:36:00 +0000 |
commit | 49e24bf10151b64a55cc8d5d4727e27b752e07bc (patch) | |
tree | 86ceaf105034277e91a41211045a5195f4a5afe0 | |
parent | 240cc2a13c80a8246421cbd41ceaea7d18b2bafc (diff) | |
parent | 5b3f5ed7d9ffa02c2255a68e6a4be969f0116104 (diff) |
Merge "Fix activity leaks in InCallUI" into lmp-dev
-rw-r--r-- | InCallUI/src/com/android/incallui/CallCardPresenter.java | 74 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/ContactInfoCache.java | 2 |
2 files changed, 52 insertions, 24 deletions
diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 7018db9d1..bb6edfb7a 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -41,6 +41,9 @@ import com.android.incallui.InCallPresenter.InCallEventListener; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.InCallPresenter.IncomingCallListener; + +import java.lang.ref.WeakReference; + import com.google.common.base.Preconditions; /** @@ -63,6 +66,33 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> private Context mContext; private TelecommManager mTelecommManager; + public static class ContactLookupCallback implements ContactInfoCacheCallback { + private final WeakReference<CallCardPresenter> mCallCardPresenter; + private final boolean mIsPrimary; + + public ContactLookupCallback(CallCardPresenter callCardPresenter, boolean isPrimary) { + mCallCardPresenter = new WeakReference<CallCardPresenter>(callCardPresenter); + mIsPrimary = isPrimary; + } + + @Override + public void onContactInfoComplete(String callId, ContactCacheEntry entry) { + CallCardPresenter presenter = mCallCardPresenter.get(); + if (presenter != null) { + presenter.onContactInfoComplete(callId, entry, mIsPrimary); + } + } + + @Override + public void onImageLoadComplete(String callId, ContactCacheEntry entry) { + CallCardPresenter presenter = mCallCardPresenter.get(); + if (presenter != null) { + presenter.onImageLoadComplete(callId, entry); + } + } + + } + public CallCardPresenter() { // create the call timer mCallTimer = new CallTimer(new Runnable() { @@ -347,30 +377,28 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> boolean isIncoming) { final ContactInfoCache cache = ContactInfoCache.getInstance(mContext); - cache.findInfo(call, isIncoming, new ContactInfoCacheCallback() { - @Override - public void onContactInfoComplete(String callId, ContactCacheEntry entry) { - updateContactEntry(entry, isPrimary, false); - if (entry.name != null) { - Log.d(TAG, "Contact found: " + entry); - } - if (entry.contactUri != null) { - CallerInfoUtils.sendViewNotification(mContext, entry.contactUri); - } - } + cache.findInfo(call, isIncoming, new ContactLookupCallback(this, isPrimary)); + } - @Override - public void onImageLoadComplete(String callId, ContactCacheEntry entry) { - if (getUi() == null) { - return; - } - if (entry.photo != null) { - if (mPrimary != null && callId.equals(mPrimary.getId())) { - getUi().setPrimaryImage(entry.photo); - } - } - } - }); + private void onContactInfoComplete(String callId, ContactCacheEntry entry, boolean isPrimary) { + updateContactEntry(entry, isPrimary, false); + if (entry.name != null) { + Log.d(TAG, "Contact found: " + entry); + } + if (entry.contactUri != null) { + CallerInfoUtils.sendViewNotification(mContext, entry.contactUri); + } + } + + private void onImageLoadComplete(String callId, ContactCacheEntry entry) { + if (getUi() == null) { + return; + } + if (entry.photo != null) { + if (mPrimary != null && callId.equals(mPrimary.getId())) { + getUi().setPrimaryImage(entry.photo); + } + } } private static boolean isConference(Call call) { diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java index ba1dca706..d02c8c837 100644 --- a/InCallUI/src/com/android/incallui/ContactInfoCache.java +++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java @@ -59,7 +59,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete public static synchronized ContactInfoCache getInstance(Context mContext) { if (sCache == null) { - sCache = new ContactInfoCache(mContext); + sCache = new ContactInfoCache(mContext.getApplicationContext()); } return sCache; } |