From ff82047527cc3322876dc0525fc14d1010f4c59f Mon Sep 17 00:00:00 2001 From: Richard MacGregor Date: Tue, 26 Jan 2016 10:25:53 -0800 Subject: Use CallMethodHelper for plugin info Simplify contact specific plugin lookup by using CallMethodHelper. Allow CallMethodHelper update broadcasts to update incallui buttons when plugins are loaded. Change-Id: I541944771b9c7787951c51470fa70056df49611d --- src/com/android/incallui/CallButtonPresenter.java | 47 +++++++-- src/com/android/incallui/ContactInfoCache.java | 111 +++++++++++++-------- src/com/android/incallui/InCallPresenter.java | 57 ++++++++++- .../incallapi/InCallPluginInfoAsyncTask.java | 92 ++++++----------- 4 files changed, 194 insertions(+), 113 deletions(-) diff --git a/src/com/android/incallui/CallButtonPresenter.java b/src/com/android/incallui/CallButtonPresenter.java index cd8c9415..c62d61a2 100644 --- a/src/com/android/incallui/CallButtonPresenter.java +++ b/src/com/android/incallui/CallButtonPresenter.java @@ -42,9 +42,11 @@ import android.text.TextUtils; import com.android.incallui.AudioModeProvider.AudioModeListener; import com.android.incallui.ContactInfoCache; import com.android.incallui.ContactInfoCache.ContactCacheEntry; +import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; import com.android.incallui.incallapi.InCallPluginInfo; import com.android.incallui.InCallCameraManager.Listener; import com.android.incallui.InCallPresenter.CanAddCallListener; +import com.android.incallui.InCallPresenter.InCallPluginUpdateListener; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.InCallPresenter.IncomingCallListener; @@ -68,7 +70,7 @@ import java.util.Objects; public class CallButtonPresenter extends Presenter implements InCallStateListener, AudioModeListener, IncomingCallListener, InCallDetailsListener, CanAddCallListener, CallList.ActiveSubChangeListener, Listener, - StartInCallCallReceiver.Receiver { + StartInCallCallReceiver.Receiver, ContactInfoCacheCallback, InCallPluginUpdateListener { private static final String TAG = CallButtonPresenter.class.getSimpleName(); private static final String KEY_AUTOMATICALLY_MUTED = "incall_key_automatically_muted"; @@ -116,6 +118,7 @@ public class CallButtonPresenter extends Presenter getContactInCallPluginInfoList() { List inCallPluginInfoList = null; if (mCall != null) { - ContactCacheEntry contactInfo = - ContactInfoCache.getInstance(getUi().getContext()).getInfo(mCall.getId()); - if (contactInfo != null) { - inCallPluginInfoList = contactInfo.inCallPluginInfoList; + final ContactInfoCache cache = ContactInfoCache.getInstance(getUi().getContext()); + if (cache != null) { + ContactCacheEntry contactInfo = cache.getInfo(mCall.getId()); + if (contactInfo != null) { + inCallPluginInfoList = contactInfo.inCallPluginInfoList; + } + if (inCallPluginInfoList == null) { + cache.refreshPluginInfo(mCall, this); + } } } return inCallPluginInfoList; @@ -346,7 +355,7 @@ public class CallButtonPresenter extends Presenter mCallback; + + public InCallPluginInfoCallback(String callId, ContactInfoCacheCallback callback) { + mCallId = callId; + if (callback != null) { + mCallback = new WeakReference(callback); + } + } + + @Override + public void onPostExecuteTask(List inCallPluginInfoList) { + synchronized (mInfoMap) { + final ContactCacheEntry oldEntry = mInfoMap.get(mCallId); + ContactCacheEntry entry = new ContactCacheEntry(oldEntry); + entry.inCallPluginInfoList = inCallPluginInfoList; + + // Add the contact info to the cache. + mInfoMap.put(mCallId, entry); + if (mCallback != null) { + ContactInfoCacheCallback callback = mCallback.get(); + if (callback != null) { + callback.onContactInfoComplete(mCallId, entry); + } + } + } + } + } + class PhoneNumberServiceListener implements PhoneNumberService.NumberLookupListener, PhoneNumberService.ImageLookupListener { private final String mCallId; @@ -343,34 +391,6 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete } } - class InCallPluginInfoCallback implements InCallPluginInfoAsyncTask.IInCallPostExecute { - - private String mCallId; - - public InCallPluginInfoCallback(String callId) { - mCallId = callId; - } - - @Override - public void onPostExecuteTask(List inCallPluginInfoList) { - // If we got a miss, return. - if (inCallPluginInfoList == null || inCallPluginInfoList.isEmpty()) { - Log.d(TAG, "No InCall plugins associated with this contact."); - return; - } - - synchronized (mInfoMap) { - final ContactCacheEntry oldEntry = mInfoMap.get(mCallId); - ContactCacheEntry entry = new ContactCacheEntry(oldEntry); - entry.inCallPluginInfoList = inCallPluginInfoList; - - // Add the contact info to the cache. - mInfoMap.put(mCallId, entry); - sendInfoNotifications(mCallId, entry); - } - } - } - /** * Implemented for ContactsAsyncHelper.OnImageLoadCompleteListener interface. * make sure that the call state is reflected after the image is loaded. @@ -563,6 +583,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete cce.location = displayLocation; cce.label = label; cce.isSipCall = isSipCall; + cce.isEmergencyNumber = info.isEmergencyNumber(); } /** @@ -648,6 +669,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete public Uri displayPhotoUri; public Uri lookupUri; // Sent to NotificationMananger public String lookupKey; + public boolean isEmergencyNumber; public List inCallPluginInfoList; public ContactCacheEntry() {} @@ -664,6 +686,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete this.displayPhotoUri = entry.displayPhotoUri; this.lookupUri = entry.lookupUri; this.lookupKey = entry.lookupKey; + this.isEmergencyNumber = entry.isEmergencyNumber; this.inCallPluginInfoList = entry.inCallPluginInfoList; } } diff --git a/src/com/android/incallui/InCallPresenter.java b/src/com/android/incallui/InCallPresenter.java index 07da827b..1ca93272 100644 --- a/src/com/android/incallui/InCallPresenter.java +++ b/src/com/android/incallui/InCallPresenter.java @@ -18,6 +18,7 @@ package com.android.incallui; import android.app.ActivityManager.TaskDescription; import android.app.FragmentManager; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ActivityNotFoundException; @@ -42,9 +43,12 @@ import com.android.contacts.common.interactions.TouchPointManager; import com.android.contacts.common.testing.NeededForTesting; import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette; import com.android.incalluibind.ObjectFactory; +import com.android.phone.common.incall.CallMethodHelper; +import com.android.phone.common.incall.CallMethodInfo; import com.google.common.base.Preconditions; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Set; @@ -61,8 +65,12 @@ import java.util.concurrent.CopyOnWriteArrayList; * TODO: This class has become more of a state machine at this point. Consider renaming. */ public class InCallPresenter implements CallList.Listener, - CircularRevealFragment.OnCircularRevealCompleteListener { + CircularRevealFragment.OnCircularRevealCompleteListener, + ContactInfoCache.ContactInfoCacheCallback, + CallMethodHelper.CallMethodReceiver { + private static final boolean DEBUG = false; + private static final String AMBIENT_SUBSCRIPTION_ID = InCallPresenter.class.getSimpleName(); private static final String EXTRA_FIRST_TIME_SHOWN = "com.android.incallui.intent.extra.FIRST_TIME_SHOWN"; @@ -88,6 +96,9 @@ public class InCallPresenter implements CallList.Listener, new ConcurrentHashMap(8, 0.9f, 1)); private final Set mInCallEventListeners = Collections.newSetFromMap( new ConcurrentHashMap(8, 0.9f, 1)); + private final Set mInCallPluginUpdateListeners = + Collections.newSetFromMap( + new ConcurrentHashMap(8, 0.9f, 1)); private AudioModeProvider mAudioModeProvider; private StatusBarNotifier mStatusBarNotifier; @@ -243,6 +254,8 @@ public class InCallPresenter implements CallList.Listener, // This only gets called by the service so this is okay. mServiceConnected = true; + CallMethodHelper.subscribe(AMBIENT_SUBSCRIPTION_ID, this); + // The final thing we do in this set up is add ourselves as a listener to CallList. This // will kick off an update and the whole process can start. mCallList.addListener(this); @@ -532,6 +545,30 @@ public class InCallPresenter implements CallList.Listener, wakeUpScreen(); } + @Override + public void onChanged(HashMap callMethodInfo) { + if (DEBUG) Log.i(this, "InCall plugins updated"); + // Update ContactInfoCache then notify listeners + final CallList calls = CallList.getInstance(); + final Call call = calls.getFirstCall(); + if (call != null && mContactInfoCache != null) { + mContactInfoCache.refreshPluginInfo(call, this); + } + } + + @Override + public void onContactInfoComplete(String callId, ContactInfoCache.ContactCacheEntry entry) { + if (DEBUG) Log.i(this, "onContactInfoComplete"); + for (InCallPluginUpdateListener listener : mInCallPluginUpdateListeners) { + listener.onInCallPluginUpdated(); + } + } + + @Override + public void onImageLoadComplete(String callId, ContactInfoCache.ContactCacheEntry entry) { + // Stub + } + /** * Given the call list, return the state in which the in-call screen should be. */ @@ -664,6 +701,17 @@ public class InCallPresenter implements CallList.Listener, } } + public void addInCallPluginUpdateListener(InCallPluginUpdateListener listener) { + Preconditions.checkNotNull(listener); + mInCallPluginUpdateListeners.add(listener); + } + + public void removeInCallPluginUpdateListener(InCallPluginUpdateListener listener) { + if (listener != null) { + mInCallPluginUpdateListeners.remove(listener); + } + } + public ProximitySensor getProximitySensor() { return mProximitySensor; } @@ -1394,6 +1442,9 @@ public class InCallPresenter implements CallList.Listener, mCanAddCallListeners.clear(); mOrientationListeners.clear(); mInCallEventListeners.clear(); + mInCallPluginUpdateListeners.clear(); + + CallMethodHelper.unsubscribe(AMBIENT_SUBSCRIPTION_ID); Log.d(this, "Finished InCallPresenter.CleanUp"); } @@ -1773,6 +1824,10 @@ public class InCallPresenter implements CallList.Listener, public void onDeviceOrientationChanged(int orientation); } + public interface InCallPluginUpdateListener { + public void onInCallPluginUpdated(); + } + /** * Interface implemented by classes that need to know about events which occur within the * In-Call UI. Used as a means of communicating between fragments that make up the UI. diff --git a/src/com/android/incallui/incallapi/InCallPluginInfoAsyncTask.java b/src/com/android/incallui/incallapi/InCallPluginInfoAsyncTask.java index aa22d972..ad4aef37 100644 --- a/src/com/android/incallui/incallapi/InCallPluginInfoAsyncTask.java +++ b/src/com/android/incallui/incallapi/InCallPluginInfoAsyncTask.java @@ -30,6 +30,8 @@ import android.provider.ContactsContract.Data; import android.text.TextUtils; import android.util.Log; import com.android.phone.common.ambient.AmbientConnection; +import com.android.phone.common.incall.CallMethodHelper; +import com.android.phone.common.incall.CallMethodInfo; import com.cyanogen.ambient.common.api.AmbientApiClient; import com.cyanogen.ambient.incall.InCallApi; import com.cyanogen.ambient.incall.InCallServices; @@ -85,11 +87,8 @@ public class InCallPluginInfoAsyncTask extends AsyncTask inCallPluginInfoBuilderList = new ArrayList(); Map pluginIndex = new HashMap(); - AmbientApiClient client = AmbientConnection.CLIENT.get(mContext.getApplicationContext()); - InCallApi inCallServices = InCallServices.getInstance(); - List plugins = inCallServices.getInstalledPlugins(client).await().components; - MimeTypeListResult mimeTypeListResult = - inCallServices.getVideoCallableMimeTypeList(client).await(); + HashMap plugins = CallMethodHelper.getAllCallMethods(); + String mimeTypes = CallMethodHelper.getAllEnabledVideoCallableMimeTypes(); if (mContactInfo == null) { return inCallPluginList; @@ -115,12 +114,11 @@ public class InCallPluginInfoAsyncTask extends AsyncTask mimeTypesList) { + private String constructSelection(String mimeTypes) { StringBuilder selection = new StringBuilder(); - if (mimeTypesList != null && !mimeTypesList.isEmpty()) { + if (!TextUtils.isEmpty(mimeTypes)) { selection.append(Data.MIMETYPE + " IN ('"); - selection.append(Joiner.on("', '").skipNulls().join(mimeTypesList)); + selection.append(mimeTypes); selection.append("') AND " + Data.DATA1 + " NOT NULL"); } return selection.toString(); -- cgit v1.2.3