From 7b2248bfff11c50e208908cb74b5f94b3ad7a3c0 Mon Sep 17 00:00:00 2001 From: Sailesh Nepal Date: Tue, 1 Apr 2014 12:33:49 -0700 Subject: InCallUI - Use String IDs Change-Id: Ibacb79658c146466d4f23bfcf7af0ebfb6e84dd0 --- .../src/com/android/incallui/AnswerPresenter.java | 10 ++--- InCallUI/src/com/android/incallui/Call.java | 22 +++-------- .../com/android/incallui/CallCardPresenter.java | 10 ++--- .../com/android/incallui/CallHandlerService.java | 2 +- InCallUI/src/com/android/incallui/CallList.java | 43 ++++++++-------------- .../incallui/ConferenceManagerPresenter.java | 6 +-- .../src/com/android/incallui/ContactInfoCache.java | 31 ++++++++-------- .../src/com/android/incallui/InCallActivity.java | 6 +-- .../src/com/android/incallui/InCallPresenter.java | 2 +- .../android/incallui/PostCharDialogFragment.java | 4 +- .../com/android/incallui/StatusBarNotifier.java | 6 +-- .../src/com/android/incallui/TelecommAdapter.java | 38 +++++++++---------- 12 files changed, 75 insertions(+), 105 deletions(-) diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java index 093815822..44485e9a5 100644 --- a/InCallUI/src/com/android/incallui/AnswerPresenter.java +++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java @@ -26,7 +26,7 @@ public class AnswerPresenter extends Presenter private static final String TAG = AnswerPresenter.class.getSimpleName(); - private int mCallId = Call.INVALID_CALL_ID; + private String mCallId; private Call mCall = null; @Override @@ -52,7 +52,7 @@ public class AnswerPresenter extends Presenter // This is necessary because the activity can be destroyed while an incoming call exists. // This happens when back button is pressed while incoming call is still being shown. - if (mCallId != Call.INVALID_CALL_ID) { + if (mCallId != null) { CallList.getInstance().removeCallUpdateListener(mCallId, this); } } @@ -73,7 +73,7 @@ public class AnswerPresenter extends Presenter // getting updates here. Log.d(this, "onIncomingCall: " + this); if (getUi() != null) { - if (call.getCallId() != mCallId) { + if (!call.getCallId().equals(mCallId)) { // A new call is coming in. processIncomingCall(call); } @@ -111,12 +111,12 @@ public class AnswerPresenter extends Presenter // mCallId will hold the state of the call. We don't clear the mCall variable here as // it may be useful for sending text messages after phone disconnects. - mCallId = Call.INVALID_CALL_ID; + mCallId = null; } } public void onAnswer() { - if (mCallId == Call.INVALID_CALL_ID) { + if (mCallId == null) { return; } diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java index b328d058c..f0d187776 100644 --- a/InCallUI/src/com/android/incallui/Call.java +++ b/InCallUI/src/com/android/incallui/Call.java @@ -36,9 +36,6 @@ import java.util.TreeSet; */ public final class Call { - public static final int INVALID_CALL_ID = -1; - public static final int MAX_CONFERENCED_CALLS = 5; - /* Defines different states of this call */ public static class State { public static final int INVALID = 0; @@ -135,9 +132,7 @@ public final class Call { public static int PRESENTATION_PAYPHONE = PhoneConstants.PRESENTATION_PAYPHONE; // Unique identifier for the call - private int mCallId; - - private String mTelecommCallId; + private String mCallId; // The current state of the call private int mState = State.INVALID; @@ -166,22 +161,15 @@ public final class Call { // Gateway service package name private String mGatewayPackage; - private static int sNextAvailableCallId = 100000; - - public Call(String telecommCallId, String number) { - mTelecommCallId = telecommCallId; - mCallId = sNextAvailableCallId++; + public Call(String callId, String number) { + mCallId = callId; mNumber = number; } - public int getCallId() { + public String getCallId() { return mCallId; } - public String getTelecommCallId() { - return mTelecommCallId; - } - public String getNumber() { return mNumber; } @@ -270,6 +258,6 @@ public final class Call { @Override public String toString() { - return String.format(Locale.US, "[%d, %s]", mCallId, State.toString(mState)); + return String.format(Locale.US, "[%s, %s]", mCallId, State.toString(mState)); } } diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 598e69af5..272c6c12f 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -246,7 +246,7 @@ public class CallCardPresenter extends Presenter } // otherwise compare call Ids - return call1.getCallId() == call2.getCallId(); + return call1.getCallId().equals(call2.getCallId()); } private void maybeStartSearch(Call call, boolean isPrimary) { @@ -265,7 +265,7 @@ public class CallCardPresenter extends Presenter cache.findInfo(call, isIncoming, new ContactInfoCacheCallback() { @Override - public void onContactInfoComplete(int callId, ContactCacheEntry entry) { + public void onContactInfoComplete(String callId, ContactCacheEntry entry) { updateContactEntry(entry, isPrimary, false); if (entry.name != null) { Log.d(TAG, "Contact found: " + entry); @@ -276,14 +276,14 @@ public class CallCardPresenter extends Presenter } @Override - public void onImageLoadComplete(int callId, ContactCacheEntry entry) { + public void onImageLoadComplete(String callId, ContactCacheEntry entry) { if (getUi() == null) { return; } if (entry.photo != null) { - if (mPrimary != null && callId == mPrimary.getCallId()) { + if (mPrimary != null && callId.equals(mPrimary.getCallId())) { getUi().setPrimaryImage(entry.photo); - } else if (mSecondary != null && callId == mSecondary.getCallId()) { + } else if (mSecondary != null && callId.equals(mSecondary.getCallId())) { getUi().setSecondaryImage(entry.photo); } } diff --git a/InCallUI/src/com/android/incallui/CallHandlerService.java b/InCallUI/src/com/android/incallui/CallHandlerService.java index cc463d03f..14b9f1fec 100644 --- a/InCallUI/src/com/android/incallui/CallHandlerService.java +++ b/InCallUI/src/com/android/incallui/CallHandlerService.java @@ -280,7 +280,7 @@ public class CallHandlerService extends Service { //mCallList.onDisconnect((Call) msg.obj); break; case ON_POST_CHAR_WAIT: - mInCallPresenter.onPostDialCharWait(msg.arg1, (String) msg.obj); + //mInCallPresenter.onPostDialCharWait(msg.arg1, (String) msg.obj); break; case ON_AUDIO_MODE: Log.i(TAG, "ON_AUDIO_MODE: " + diff --git a/InCallUI/src/com/android/incallui/CallList.java b/InCallUI/src/com/android/incallui/CallList.java index f7ac66e21..df993f544 100644 --- a/InCallUI/src/com/android/incallui/CallList.java +++ b/InCallUI/src/com/android/incallui/CallList.java @@ -44,10 +44,10 @@ public class CallList { private static CallList sInstance = new CallList(); - private final HashMap mCallMap = Maps.newHashMap(); - private final HashMap> mCallTextReponsesMap = Maps.newHashMap(); + private final HashMap mCallMap = Maps.newHashMap(); + private final HashMap> mCallTextReponsesMap = Maps.newHashMap(); private final Set mListeners = Sets.newHashSet(); - private final HashMap> mCallUpdateListenerMap = Maps + private final HashMap> mCallUpdateListenerMap = Maps .newHashMap(); @@ -134,7 +134,7 @@ public class CallList { * @param callId The call id to get updates for. * @param listener The listener to add. */ - public void addCallUpdateListener(int callId, CallUpdateListener listener) { + public void addCallUpdateListener(String callId, CallUpdateListener listener) { List listeners = mCallUpdateListenerMap.get(callId); if (listeners == null) { listeners = Lists.newArrayList(); @@ -149,7 +149,7 @@ public class CallList { * @param callId The call id to remove the listener for. * @param listener The listener to remove. */ - public void removeCallUpdateListener(int callId, CallUpdateListener listener) { + public void removeCallUpdateListener(String callId, CallUpdateListener listener) { List listeners = mCallUpdateListenerMap.get(callId); if (listeners != null) { listeners.remove(listener); @@ -245,17 +245,8 @@ public class CallList { return result; } - public Call getCall(int callId) { - return mCallMap.get(callId); - } - public Call getCall(String callId) { - for (Call call : mCallMap.values()) { - if (call.getTelecommCallId().equals(callId)) { - return call; - } - } - return null; + return mCallMap.get(callId); } public boolean existsLiveCall() { @@ -267,7 +258,7 @@ public class CallList { return false; } - public List getTextResponses(int callId) { + public List getTextResponses(String callId) { return mCallTextReponsesMap.get(callId); } @@ -357,11 +348,9 @@ public class CallList { boolean updated = false; - final Integer id = new Integer(call.getCallId()); - if (call.getState() == Call.State.DISCONNECTED) { // update existing (but do not add!!) disconnected calls - if (mCallMap.containsKey(id)) { + if (mCallMap.containsKey(call.getCallId())) { // For disconnected calls, we want to keep them alive for a few seconds so that the // UI has a chance to display anything it needs when a call is disconnected. @@ -370,14 +359,14 @@ public class CallList { final Message msg = mHandler.obtainMessage(EVENT_DISCONNECTED_TIMEOUT, call); mHandler.sendMessageDelayed(msg, getDelayForDisconnect(call)); - mCallMap.put(id, call); + mCallMap.put(call.getCallId(), call); updated = true; } } else if (!isCallDead(call)) { - mCallMap.put(id, call); + mCallMap.put(call.getCallId(), call); updated = true; - } else if (mCallMap.containsKey(id)) { - mCallMap.remove(id); + } else if (mCallMap.containsKey(call.getCallId())) { + mCallMap.remove(call.getCallId()); updated = true; } @@ -413,14 +402,12 @@ public class CallList { private void updateCallTextMap(Call call, List textResponses) { Preconditions.checkNotNull(call); - final Integer id = new Integer(call.getCallId()); - if (!isCallDead(call)) { if (textResponses != null) { - mCallTextReponsesMap.put(id, textResponses); + mCallTextReponsesMap.put(call.getCallId(), textResponses); } - } else if (mCallMap.containsKey(id)) { - mCallTextReponsesMap.remove(id); + } else if (mCallMap.containsKey(call.getCallId())) { + mCallTextReponsesMap.remove(call.getCallId()); } } diff --git a/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java b/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java index ec706d074..b505e29f4 100644 --- a/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java +++ b/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java @@ -34,7 +34,7 @@ public class ConferenceManagerPresenter private static final int MAX_CALLERS_IN_CONFERENCE = 5; - private Integer[] mCallerIds; + private String[] mCallerIds; private Context mContext; @Override @@ -82,9 +82,9 @@ public class ConferenceManagerPresenter final Call currentCall = callList.getActiveOrBackgroundCall(); if (currentCall != null) { // getChildCallIds() always returns a valid Set - mCallerIds = currentCall.getChildCallIds().toArray(new Integer[0]); + mCallerIds = currentCall.getChildCallIds().toArray(new String[0]); } else { - mCallerIds = new Integer[0]; + mCallerIds = new String[0]; } Log.d(this, "Number of calls is " + String.valueOf(mCallerIds.length)); diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java index 2b6dd5b09..8efa79171 100644 --- a/InCallUI/src/com/android/incallui/ContactInfoCache.java +++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java @@ -54,8 +54,8 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete private final Context mContext; private final PhoneNumberService mPhoneNumberService; - private final HashMap mInfoMap = Maps.newHashMap(); - private final HashMap> mCallBacks = Maps.newHashMap(); + private final HashMap mInfoMap = Maps.newHashMap(); + private final HashMap> mCallBacks = Maps.newHashMap(); private static ContactInfoCache sCache = null; @@ -71,7 +71,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete mPhoneNumberService = ServiceFactory.newPhoneNumberService(context); } - public ContactCacheEntry getInfo(int callId) { + public ContactCacheEntry getInfo(String callId) { return mInfoMap.get(callId); } @@ -111,7 +111,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete Preconditions.checkState(Looper.getMainLooper().getThread() == Thread.currentThread()); Preconditions.checkNotNull(callback); - final int callId = call.getCallId(); + final String callId = call.getCallId(); final ContactCacheEntry cacheEntry = mInfoMap.get(callId); Set callBacks = mCallBacks.get(callId); @@ -151,7 +151,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete private void findInfoQueryComplete(Call call, CallerInfo callerInfo, boolean isIncoming, boolean didLocalLookup) { - final int callId = call.getCallId(); + final String callId = call.getCallId(); int presentationMode = call.getNumberPresentation(); if (callerInfo.contactExists || callerInfo.isEmergencyNumber() || callerInfo.isVoiceMailNumber()) { presentationMode = Call.PRESENTATION_ALLOWED; @@ -193,9 +193,9 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete class PhoneNumberServiceListener implements PhoneNumberService.NumberLookupListener, PhoneNumberService.ImageLookupListener { - private final int mCallId; + private final String mCallId; - PhoneNumberServiceListener(int callId) { + PhoneNumberServiceListener(String callId) { mCallId = callId; } @@ -250,8 +250,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete @Override public void onImageFetchComplete(Bitmap bitmap) { - onImageLoadComplete(TOKEN_UPDATE_PHOTO_FOR_CALL_STATE, null, - bitmap, (Integer) mCallId); + onImageLoadComplete(TOKEN_UPDATE_PHOTO_FOR_CALL_STATE, null, bitmap, mCallId); } } @@ -265,7 +264,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete // TODO: may be nice to update the image view again once the newer one // is available on contacts database. - final int callId = (Integer) cookie; + final String callId = (String) cookie; final ContactCacheEntry entry = mInfoMap.get(callId); if (entry == null) { @@ -299,7 +298,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete mCallBacks.clear(); } - private ContactCacheEntry buildEntry(Context context, int callId, + private ContactCacheEntry buildEntry(Context context, String callId, CallerInfo info, int presentation, boolean isIncoming) { // The actual strings we're going to display onscreen: Drawable photo = null; @@ -452,7 +451,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete /** * Sends the updated information to call the callbacks for the entry. */ - private void sendInfoNotifications(int callId, ContactCacheEntry entry) { + private void sendInfoNotifications(String callId, ContactCacheEntry entry) { final Set callBacks = mCallBacks.get(callId); if (callBacks != null) { for (ContactInfoCacheCallback callBack : callBacks) { @@ -461,7 +460,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete } } - private void sendImageNotifications(int callId, ContactCacheEntry entry) { + private void sendImageNotifications(String callId, ContactCacheEntry entry) { final Set callBacks = mCallBacks.get(callId); if (callBacks != null && entry.photo != null) { for (ContactInfoCacheCallback callBack : callBacks) { @@ -470,7 +469,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete } } - private void clearCallbacks(int callId) { + private void clearCallbacks(String callId) { mCallBacks.remove(callId); } @@ -491,8 +490,8 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete * Callback interface for the contact query. */ public interface ContactInfoCacheCallback { - public void onContactInfoComplete(int callId, ContactCacheEntry entry); - public void onImageLoadComplete(int callId, ContactCacheEntry entry); + public void onContactInfoComplete(String callId, ContactCacheEntry entry); + public void onImageLoadComplete(String callId, ContactCacheEntry entry); } public static class ContactCacheEntry { diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index 1b351d545..5262045f2 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -57,7 +57,7 @@ public class InCallActivity extends Activity { /** Use to pass parameters for showing the PostCharDialog to {@link #onResume} */ private boolean mShowPostCharWaitDialogOnResume; - private int mShowPostCharWaitDialogCallId; + private String mShowPostCharWaitDialogCallId; private String mShowPostCharWaitDialogChars; @Override @@ -435,13 +435,13 @@ public class InCallActivity extends Activity { } } - public void showPostCharWaitDialog(int callId, String chars) { + public void showPostCharWaitDialog(String callId, String chars) { if (isForegroundActivity()) { final PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars); fragment.show(getFragmentManager(), "postCharWait"); mShowPostCharWaitDialogOnResume = false; - mShowPostCharWaitDialogCallId = 0; + mShowPostCharWaitDialogCallId = null; mShowPostCharWaitDialogChars = null; } else { mShowPostCharWaitDialogOnResume = true; diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index ce2bcbb3f..a114d708e 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -455,7 +455,7 @@ public class InCallPresenter implements CallList.Listener { } } - public void onPostDialCharWait(int callId, String chars) { + public void onPostDialCharWait(String callId, String chars) { if (isActivityStarted()) { mInCallActivity.showPostCharWaitDialog(callId, chars); } diff --git a/InCallUI/src/com/android/incallui/PostCharDialogFragment.java b/InCallUI/src/com/android/incallui/PostCharDialogFragment.java index 5c7d8eac2..be7b2ec19 100644 --- a/InCallUI/src/com/android/incallui/PostCharDialogFragment.java +++ b/InCallUI/src/com/android/incallui/PostCharDialogFragment.java @@ -30,10 +30,10 @@ import android.view.WindowManager; */ public class PostCharDialogFragment extends DialogFragment { - private int mCallId; + private String mCallId; private String mPostDialStr; - public PostCharDialogFragment(int callId, String postDialStr) { + public PostCharDialogFragment(String callId, String postDialStr) { mCallId = callId; mPostDialStr = postDialStr; } diff --git a/InCallUI/src/com/android/incallui/StatusBarNotifier.java b/InCallUI/src/com/android/incallui/StatusBarNotifier.java index 2702dcf82..a86837f32 100644 --- a/InCallUI/src/com/android/incallui/StatusBarNotifier.java +++ b/InCallUI/src/com/android/incallui/StatusBarNotifier.java @@ -225,7 +225,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { // call into the contacts provider for more data. mContactInfoCache.findInfo(call, isIncoming, new ContactInfoCacheCallback() { @Override - public void onContactInfoComplete(int callId, ContactCacheEntry entry) { + public void onContactInfoComplete(String callId, ContactCacheEntry entry) { Call call = CallList.getInstance().getCall(callId); if (call != null) { buildAndSendNotification(call, entry); @@ -233,7 +233,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { } @Override - public void onImageLoadComplete(int callId, ContactCacheEntry entry) { + public void onImageLoadComplete(String callId, ContactCacheEntry entry) { Call call = CallList.getInstance().getCall(callId); if (call != null) { buildAndSendNotification(call, entry); @@ -250,7 +250,7 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { // back. However, it can happen much later. Before we continue, we need to make sure that // the call being passed in is still the one we want to show in the notification. final Call call = getCallToShow(CallList.getInstance()); - if (call == null || call.getCallId() != originalCall.getCallId()) { + if (call == null || !call.getCallId().equals(originalCall.getCallId())) { return; } diff --git a/InCallUI/src/com/android/incallui/TelecommAdapter.java b/InCallUI/src/com/android/incallui/TelecommAdapter.java index deb633e26..67f5fc1bc 100644 --- a/InCallUI/src/com/android/incallui/TelecommAdapter.java +++ b/InCallUI/src/com/android/incallui/TelecommAdapter.java @@ -41,42 +41,42 @@ final class TelecommAdapter { mAdapter = adapter; } - void answerCall(int callId) { + void answerCall(String callId) { if (mAdapter != null) { - mAdapter.answerCall(getTelecommCallId(callId)); + mAdapter.answerCall(callId); } else { Log.e(this, "error answerCall, mAdapter is null"); } } - void rejectCall(int callId, boolean rejectWithMessage, String message) { + void rejectCall(String callId, boolean rejectWithMessage, String message) { if (mAdapter != null) { // TODO(sail): Add support for reject with message. - mAdapter.rejectCall(getTelecommCallId(callId)); + mAdapter.rejectCall(callId); } else { Log.e(this, "error rejectCall, mAdapter is null"); } } - void disconnectCall(int callId) { + void disconnectCall(String callId) { if (mAdapter != null) { - mAdapter.disconnectCall(getTelecommCallId(callId)); + mAdapter.disconnectCall(callId); } else { Log.e(this, "error disconnectCall, mAdapter is null"); } } - void holdCall(int callId) { + void holdCall(String callId) { if (mAdapter != null) { - mAdapter.holdCall(getTelecommCallId(callId)); + mAdapter.holdCall(callId); } else { Log.e(this, "error holdCall, mAdapter is null"); } } - void unholdCall(int callId) { + void unholdCall(String callId) { if (mAdapter != null) { - mAdapter.unholdCall(getTelecommCallId(callId)); + mAdapter.unholdCall(callId); } else { Log.e(this, "error unholdCall, mAdapter is null"); } @@ -98,7 +98,7 @@ final class TelecommAdapter { } } - void separateCall(int callId) { + void separateCall(String callId) { Log.wtf(this, "separateCall not implemented"); } @@ -114,35 +114,31 @@ final class TelecommAdapter { Log.wtf(this, "addCall not implemented"); } - void playDtmfTone(int callId, char digit) { + void playDtmfTone(String callId, char digit) { if (mAdapter != null) { - mAdapter.playDtmfTone(getTelecommCallId(callId), digit); + mAdapter.playDtmfTone(callId, digit); } else { Log.e(this, "error playDtmfTone, mAdapter is null"); } } - void stopDtmfTone(int callId) { + void stopDtmfTone(String callId) { if (mAdapter != null) { - mAdapter.stopDtmfTone(getTelecommCallId(callId)); + mAdapter.stopDtmfTone(callId); } else { Log.e(this, "error stopDtmfTone, mAdapter is null"); } } - void postDialWaitContinue(int callId) { + void postDialWaitContinue(String callId) { Log.wtf(this, "postDialWaitContinue not implemented"); } - void postDialCancel(int callId) { + void postDialCancel(String callId) { Log.wtf(this, "postDialCancel not implemented"); } void setSystemBarNavigationEnabled(boolean enable) { // TODO(sail): Implement this. } - - private String getTelecommCallId(int callId) { - return CallList.getInstance().getCall(callId).getTelecommCallId(); - } } -- cgit v1.2.3