summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-07-30 15:36:49 -0700
committerYorke Lee <yorkelee@google.com>2014-07-30 15:36:49 -0700
commit5b3f5ed7d9ffa02c2255a68e6a4be969f0116104 (patch)
tree0c79b5fd839d3a446be8443229c209b863cb97ff
parent75dec7e7bf2814c19dddabf5950aa185363c2afc (diff)
Fix activity leaks in InCallUI
We were holding a reference to anonymous inner classes in CallCardPresenter in an static instance of ContactInfoCache, which was causing activity leaks. Refactor ContactInfoCacheCallback into a static inner class so that this fixes the problem. Bug: 16657866 Change-Id: I4da5cecd556f80fafd27f919b0aaa7f00b2a96f5
-rw-r--r--InCallUI/src/com/android/incallui/CallCardPresenter.java74
-rw-r--r--InCallUI/src/com/android/incallui/ContactInfoCache.java2
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;
}