diff options
author | Sailesh Nepal <sail@google.com> | 2014-04-01 11:48:07 -0700 |
---|---|---|
committer | Sailesh Nepal <sail@google.com> | 2014-04-01 13:58:52 -0700 |
commit | 248a6687e8075e9730217be73c54ee4f95501a0e (patch) | |
tree | 4f8ec9114772499c8431c10613212ae1e53c5128 /InCallUI/src/com/android/incallui | |
parent | d11c7a03578697637f97e26758ac5bd96c85e967 (diff) |
InCallUI - Use custom object to track Calls
This is the first step in completely moving away from Telephony.
This CL creates a custom Call object. Currently this is just a
copy of the telephony Call object. I'll update various fields
in individual CLs.
This CL also deletes the old Telephony services.
Bug: 13643568
Change-Id: Id1860a5df9706f2a7fddd40e70f0d693af7b04bd
Diffstat (limited to 'InCallUI/src/com/android/incallui')
19 files changed, 572 insertions, 398 deletions
diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java index 5b263f8a8..093815822 100644 --- a/InCallUI/src/com/android/incallui/AnswerPresenter.java +++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java @@ -16,10 +16,6 @@ package com.android.incallui; -import android.telecomm.InCallAdapter; - -import com.android.services.telephony.common.Call; - import java.util.List; /** @@ -125,21 +121,7 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi> } Log.d(this, "onAnswer " + mCallId); - - CallCommandClient.getInstance().answerCall(mCallId); - - // TODO(santoscordon): Need a TelecommAdapter wrapper object so that we dont have to check - // for null like this everywhere. - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - // TODO(santoscordon): Remove translator by using only String-based IDs in all of the - // in-call app. - String callId = CallInfoTranslator.getTelecommCallId(mCall); - if (callId != null) { - Log.i(this, "Answering the call: " + callId); - telecommAdapter.answerCall(callId); - } - } + TelecommAdapter.getInstance().answerCall(mCall.getCallId()); } /** @@ -148,17 +130,7 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi> */ public void onDecline() { Log.d(this, "onDecline " + mCallId); - - CallCommandClient.getInstance().rejectCall(mCall, false, null); - - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - String callId = CallInfoTranslator.getTelecommCallId(mCall); - if (callId != null) { - Log.i(this, "Rejecting the call: " + callId); - telecommAdapter.rejectCall(callId); - } - } + TelecommAdapter.getInstance().rejectCall(mCall.getCallId(), false, null); } public void onText() { @@ -169,8 +141,7 @@ public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi> public void rejectCallWithMessage(String message) { Log.d(this, "sendTextToDefaultActivity()..."); - - CallCommandClient.getInstance().rejectCall(mCall, true, message); + TelecommAdapter.getInstance().rejectCall(mCall.getCallId(), true, message); onDismissDialog(); } diff --git a/InCallUI/src/com/android/incallui/Call.java b/InCallUI/src/com/android/incallui/Call.java new file mode 100644 index 000000000..b328d058c --- /dev/null +++ b/InCallUI/src/com/android/incallui/Call.java @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.incallui; + +import android.telephony.DisconnectCause; + +import com.android.internal.telephony.PhoneConstants; +import com.google.android.collect.Sets; +import com.google.common.base.Objects; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.primitives.Ints; + +import java.util.Locale; +import java.util.Map; +import java.util.SortedSet; +import java.util.TreeSet; + +/** + * Class object used across CallHandlerService APIs. + * Describes a single call and its state. + */ +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; + public static final int IDLE = 1; /* The call is idle. Nothing active */ + public static final int ACTIVE = 2; /* There is an active call */ + public static final int INCOMING = 3; /* A normal incoming phone call */ + public static final int CALL_WAITING = 4; /* Incoming call while another is active */ + public static final int DIALING = 5; /* An outgoing call during dial phase */ + public static final int REDIALING = 6; /* Subsequent dialing attempt after a failure */ + public static final int ONHOLD = 7; /* An active phone call placed on hold */ + public static final int DISCONNECTING = 8; /* A call is being ended. */ + public static final int DISCONNECTED = 9; /* State after a call disconnects */ + public static final int CONFERENCED = 10; /* Call part of a conference call */ + + public static boolean isConnected(int state) { + switch(state) { + case ACTIVE: + case INCOMING: + case CALL_WAITING: + case DIALING: + case REDIALING: + case ONHOLD: + case CONFERENCED: + return true; + default: + } + return false; + } + + public static boolean isDialing(int state) { + return state == DIALING || state == REDIALING; + } + + public static String toString(int state) { + switch (state) { + case INVALID: + return "INVALID"; + case IDLE: + return "IDLE"; + case ACTIVE: + return "ACTIVE"; + case INCOMING: + return "INCOMING"; + case CALL_WAITING: + return "CALL_WAITING"; + case DIALING: + return "DIALING"; + case REDIALING: + return "REDIALING"; + case ONHOLD: + return "ONHOLD"; + case DISCONNECTING: + return "DISCONNECTING"; + case DISCONNECTED: + return "DISCONNECTED"; + case CONFERENCED: + return "CONFERENCED"; + default: + return "UNKOWN"; + } + } + } + + /** + * Defines a set of capabilities that a call can have as a bit mask. + * TODO: Should some of these be capabilities of the Phone instead of the call? + * TODO: This is starting to be a mix of capabilities and call properties. Capabilities + * and properties should be separated. + */ + public static class Capabilities { + public static final int HOLD = 0x00000001; /* has ability to hold the call */ + public static final int SUPPORT_HOLD = 0x00000002; /* can show the hold button */ + public static final int MERGE_CALLS = 0x00000004; /* has ability to merge calls */ + public static final int SWAP_CALLS = 0x00000008; /* swap with a background call */ + public static final int ADD_CALL = 0x00000010; /* add another call to this one */ + public static final int RESPOND_VIA_TEXT = 0x00000020; /* has respond via text option */ + public static final int MUTE = 0x00000040; /* can mute the call */ + public static final int GENERIC_CONFERENCE = 0x00000080; /* generic conference mode */ + public static final int VIDEO_HANDOFF = 0x00000100; /* handoff to video */ + public static final int CONNECTION_HANDOFF = 0x00000200; /* handoff between wifi and cell */ + + public static final int ALL = HOLD | SUPPORT_HOLD | MERGE_CALLS | SWAP_CALLS | ADD_CALL + | RESPOND_VIA_TEXT | MUTE | GENERIC_CONFERENCE | VIDEO_HANDOFF | CONNECTION_HANDOFF; + } + + // Number presentation type for caller id display + // normal + public static int PRESENTATION_ALLOWED = PhoneConstants.PRESENTATION_ALLOWED; + // block by user + public static int PRESENTATION_RESTRICTED = PhoneConstants.PRESENTATION_RESTRICTED; + // no specified or unknown by network + public static int PRESENTATION_UNKNOWN = PhoneConstants.PRESENTATION_UNKNOWN; + // show pay phone info + public static int PRESENTATION_PAYPHONE = PhoneConstants.PRESENTATION_PAYPHONE; + + // Unique identifier for the call + private int mCallId; + + private String mTelecommCallId; + + // The current state of the call + private int mState = State.INVALID; + + // TODO: Probably need to change to wifi call state. Re-use mState? + // State.WIFI_CONNECTING + // State.WIFI_CONNECTED + // Using this simple boolean for now so we can see the UI mock. + private boolean mIsWifiCall = false; + + // Reason for disconnect. Valid when the call state is DISCONNECTED. + // Valid values are defined in {@link DisconnectCause}. + private int mDisconnectCause = DisconnectCause.NOT_VALID; + + // Bit mask of capabilities unique to this call. + private int mCapabilities; + + // Time that this call transitioned into ACTIVE state from INCOMING, WAITING, or OUTGOING. + private long mConnectTime = 0; + + private String mNumber; + + // Gateway number used to dial this call + private String mGatewayNumber; + + // Gateway service package name + private String mGatewayPackage; + + private static int sNextAvailableCallId = 100000; + + public Call(String telecommCallId, String number) { + mTelecommCallId = telecommCallId; + mCallId = sNextAvailableCallId++; + mNumber = number; + } + + public int getCallId() { + return mCallId; + } + + public String getTelecommCallId() { + return mTelecommCallId; + } + + public String getNumber() { + return mNumber; + } + + public int getState() { + return mState; + } + + public void setState(int state) { + mState = state; + } + + public boolean isWifiCall() { + return mIsWifiCall; + } + + public int getNumberPresentation() { + return PRESENTATION_ALLOWED; + } + + public int getCnapNamePresentation() { + return PRESENTATION_ALLOWED; + } + + public String getCnapName() { + return ""; + } + + /** Returns call disconnect cause; values are defined in {@link DisconnectCause}. */ + public int getDisconnectCause() { + if (mState == State.DISCONNECTED || mState == State.IDLE) { + return mDisconnectCause; + } + + return DisconnectCause.NOT_DISCONNECTED; + } + + /** Sets the call disconnect cause; values are defined in {@link DisconnectCause}. */ + public void setDisconnectCause(int cause) { + mDisconnectCause = cause; + } + + public void setCapabilities(int capabilities) { + mCapabilities = (Capabilities.ALL & capabilities); + } + + public boolean can(int capabilities) { + return (capabilities == (capabilities & mCapabilities)); + } + + public void addCapabilities(int capabilities) { + setCapabilities(capabilities | mCapabilities); + } + + public void setConnectTime(long connectTime) { + mConnectTime = connectTime; + } + + public long getConnectTime() { + return mConnectTime; + } + + public ImmutableSortedSet<Integer> getChildCallIds() { + return ImmutableSortedSet.of(); + } + + public boolean isConferenceCall() { + return false; + } + + public String getGatewayNumber() { + return mGatewayNumber; + } + + public void setGatewayNumber(String number) { + mGatewayNumber = number; + } + + public String getGatewayPackage() { + return mGatewayPackage; + } + + public void setGatewayPackage(String packageName) { + mGatewayPackage = packageName; + } + + @Override + public String toString() { + return String.format(Locale.US, "[%d, %s]", mCallId, State.toString(mState)); + } +} diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java index 544746bc3..7eabe7a18 100644 --- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java +++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java @@ -22,17 +22,15 @@ import android.graphics.drawable.Drawable; import com.android.contacts.common.util.PhoneNumberHelper; import com.android.contacts.common.util.TelephonyManagerUtils; import com.android.incallui.AudioModeProvider.AudioModeListener; +import com.android.incallui.Call.Capabilities; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.InCallPresenter.IncomingCallListener; import com.android.incallui.service.AuxiliaryActionService; import com.android.incalluibind.ServiceFactory; import com.android.services.telephony.common.AudioMode; -import com.android.services.telephony.common.Call; -import com.android.services.telephony.common.Call.Capabilities; import android.app.Fragment; -import android.telecomm.InCallAdapter; /** * Logic for call buttons. @@ -164,13 +162,7 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto // if it turns out to be slow Log.d(this, "Sending new Audio Mode: " + AudioMode.toString(mode)); - CallCommandClient.getInstance().setAudioMode(mode); - - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - Log.v(this, "Setting audio route"); - telecommAdapter.setAudioRoute(mode); - } + TelecommAdapter.getInstance().setAudioRoute(mode); } /** @@ -200,18 +192,7 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto if (mCall == null) { return; } - - CallCommandClient.getInstance().disconnectCall(mCall.getCallId()); - - // Notify Telecomm that the user hit end-call. - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - String callId = CallInfoTranslator.getTelecommCallId(mCall); - if (callId != null) { - Log.i(this, "Disconnecting the call: " + callId); - telecommAdapter.disconnectCall(callId); - } - } + TelecommAdapter.getInstance().disconnectCall(mCall.getCallId()); } public void manageConferenceButtonClicked() { @@ -220,41 +201,24 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto public void muteClicked(boolean checked) { Log.d(this, "turning on mute: " + checked); - - CallCommandClient.getInstance().mute(checked); - - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - Log.i(this, "Setting mute"); - telecommAdapter.mute(checked); - } + TelecommAdapter.getInstance().mute(checked); } public void holdClicked(boolean checked) { if (mCall == null) { return; } - - // Notify Telecomm that the user hit the hold button. - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - String callId = CallInfoTranslator.getTelecommCallId(mCall); - if (callId != null) { - if (checked) { - Log.i(this, "Putting the call on hold: " + callId); - telecommAdapter.holdCall(callId); - } else { - Log.i(this, "Removing the call from hold: " + callId); - telecommAdapter.unholdCall(callId); - } - } else { - Log.wtf(this, "Telecomm callId not found for call: " + mCall.getCallId()); - } + if (checked) { + Log.i(this, "Putting the call on hold: " + mCall); + TelecommAdapter.getInstance().holdCall(mCall.getCallId()); + } else { + Log.i(this, "Removing the call from hold: " + mCall); + TelecommAdapter.getInstance().unholdCall(mCall.getCallId()); } } public void mergeClicked() { - CallCommandClient.getInstance().merge(); + TelecommAdapter.getInstance().merge(); } public void addCallClicked() { @@ -264,11 +228,11 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto // Simulate a click on the mute button muteClicked(true); - CallCommandClient.getInstance().addCall(); + TelecommAdapter.getInstance().addCall(); } public void swapClicked() { - CallCommandClient.getInstance().swap(); + TelecommAdapter.getInstance().swap(); } public void showDialpadClicked(boolean checked) { diff --git a/InCallUI/src/com/android/incallui/CallCardFragment.java b/InCallUI/src/com/android/incallui/CallCardFragment.java index 1a5cabd4c..198937fcb 100644 --- a/InCallUI/src/com/android/incallui/CallCardFragment.java +++ b/InCallUI/src/com/android/incallui/CallCardFragment.java @@ -34,8 +34,6 @@ import android.view.accessibility.AccessibilityEvent; import android.widget.ImageView; import android.widget.TextView; -import com.android.services.telephony.common.Call; - import java.util.List; /** diff --git a/InCallUI/src/com/android/incallui/CallCardPresenter.java b/InCallUI/src/com/android/incallui/CallCardPresenter.java index 81dee250b..598e69af5 100644 --- a/InCallUI/src/com/android/incallui/CallCardPresenter.java +++ b/InCallUI/src/com/android/incallui/CallCardPresenter.java @@ -23,22 +23,19 @@ import android.graphics.drawable.Drawable; import android.graphics.Bitmap; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; -import android.telecomm.InCallAdapter; import android.telephony.DisconnectCause; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.text.format.DateUtils; import com.android.incallui.AudioModeProvider.AudioModeListener; +import com.android.incallui.Call.Capabilities; import com.android.incallui.ContactInfoCache.ContactCacheEntry; import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; import com.android.incallui.InCallPresenter.IncomingCallListener; import com.android.services.telephony.common.AudioMode; -import com.android.services.telephony.common.Call; -import com.android.services.telephony.common.Call.Capabilities; -import com.android.services.telephony.common.CallIdentification; import com.google.common.base.Preconditions; /** @@ -77,12 +74,9 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> if (call != null) { mPrimary = call; - final CallIdentification identification = call.getIdentification(); - // start processing lookups right away. if (!call.isConferenceCall()) { - startContactInfoSearch(identification, true, - call.getState() == Call.State.INCOMING); + startContactInfoSearch(call, true, call.getState() == Call.State.INCOMING); } else { updateContactEntry(null, true, true); } @@ -160,8 +154,8 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> if (primaryChanged && mPrimary != null) { // primary call has changed - mPrimaryContactInfo = ContactInfoCache.buildCacheEntryFromCall(mContext, - mPrimary.getIdentification(), mPrimary.getState() == Call.State.INCOMING); + mPrimaryContactInfo = ContactInfoCache.buildCacheEntryFromCall(mContext, mPrimary, + mPrimary.getState() == Call.State.INCOMING); updatePrimaryDisplayInfo(mPrimaryContactInfo, isConference(mPrimary)); maybeStartSearch(mPrimary, true); } @@ -172,8 +166,8 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> updateSecondaryDisplayInfo(false); } else if (secondaryChanged) { // secondary call has changed - mSecondaryContactInfo = ContactInfoCache.buildCacheEntryFromCall(mContext, - mSecondary.getIdentification(), mSecondary.getState() == Call.State.INCOMING); + mSecondaryContactInfo = ContactInfoCache.buildCacheEntryFromCall(mContext, mSecondary, + mSecondary.getState() == Call.State.INCOMING); updateSecondaryDisplayInfo(mSecondary.isConferenceCall()); maybeStartSearch(mSecondary, false); } @@ -258,19 +252,18 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> private void maybeStartSearch(Call call, boolean isPrimary) { // no need to start search for conference calls which show generic info. if (call != null && !call.isConferenceCall()) { - startContactInfoSearch(call.getIdentification(), isPrimary, - call.getState() == Call.State.INCOMING); + startContactInfoSearch(call, isPrimary, call.getState() == Call.State.INCOMING); } } /** * Starts a query for more contact data for the save primary and secondary calls. */ - private void startContactInfoSearch(final CallIdentification identification, - final boolean isPrimary, boolean isIncoming) { + private void startContactInfoSearch(final Call call, final boolean isPrimary, + boolean isIncoming) { final ContactInfoCache cache = ContactInfoCache.getInstance(mContext); - cache.findInfo(identification, isIncoming, new ContactInfoCacheCallback() { + cache.findInfo(call, isIncoming, new ContactInfoCacheCallback() { @Override public void onContactInfoComplete(int callId, ContactCacheEntry entry) { updateContactEntry(entry, isPrimary, false); @@ -473,13 +466,8 @@ public class CallCardPresenter extends Presenter<CallCardPresenter.CallCardUi> return; } - String callId = CallInfoTranslator.getTelecommCallId(mSecondary); - if (callId != null) { - Log.i(this, "Swapping call to foreground: " + callId); - InCallPresenter.getInstance().getTelecommAdapter().unholdCall(callId); - } else { - Log.wtf(this, "Telecomm callId not found for call: " + callId); - } + Log.i(this, "Swapping call to foreground: " + mSecondary); + TelecommAdapter.getInstance().unholdCall(mSecondary.getCallId()); } public interface CallCardUi extends Ui { diff --git a/InCallUI/src/com/android/incallui/CallHandlerService.java b/InCallUI/src/com/android/incallui/CallHandlerService.java index ebd20c307..cc463d03f 100644 --- a/InCallUI/src/com/android/incallui/CallHandlerService.java +++ b/InCallUI/src/com/android/incallui/CallHandlerService.java @@ -263,21 +263,21 @@ public class CallHandlerService extends Service { switch (msg.what) { case ON_UPDATE_CALL: Log.i(TAG, "ON_UPDATE_CALL: " + msg.obj); - mCallList.onUpdate((Call) msg.obj); + //mCallList.onUpdate((Call) msg.obj); break; case ON_UPDATE_MULTI_CALL: Log.i(TAG, "ON_UPDATE_MULTI_CALL: " + msg.obj); - mCallList.onUpdate((List<Call>) msg.obj); + //mCallList.onUpdate((List<Call>) msg.obj); break; case ON_UPDATE_CALL_WITH_TEXT_RESPONSES: AbstractMap.SimpleEntry<Call, List<String>> entry = (AbstractMap.SimpleEntry<Call, List<String>>) msg.obj; Log.i(TAG, "ON_INCOMING_CALL: " + entry.getKey()); - mCallList.onIncoming(entry.getKey(), entry.getValue()); + //mCallList.onIncoming(entry.getKey(), entry.getValue()); break; case ON_DISCONNECT_CALL: Log.i(TAG, "ON_DISCONNECT_CALL: " + msg.obj); - mCallList.onDisconnect((Call) msg.obj); + //mCallList.onDisconnect((Call) msg.obj); break; case ON_POST_CHAR_WAIT: mInCallPresenter.onPostDialCharWait(msg.arg1, (String) msg.obj); diff --git a/InCallUI/src/com/android/incallui/CallInfoTranslator.java b/InCallUI/src/com/android/incallui/CallInfoTranslator.java deleted file mode 100644 index 827c54d40..000000000 --- a/InCallUI/src/com/android/incallui/CallInfoTranslator.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2014 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.incallui; - -import android.telecomm.CallInfo; -import android.telecomm.CallState; -import android.telecomm.GatewayInfo; - -import com.android.services.telephony.common.Call; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; - -import java.util.Map; - -/** - * Translates {@link CallInfo} objects into {@link Call} objects so that call-infos received from - * Telecomm can be used easily with {@link CallList}. Manages Telecomm call ID to {@link Call} - * mappings. This class uses IDs for both {@link Call} objects and {@link CallInfo} objects which - * are both normally referred to as "call ID". To distinguish the two, the code and comments refer - * to them as "call ID" and "Telecomm call ID" respectively. - * TODO(santoscordon): This class is a temporary solution until all calls are coming in through - * Telecomm at which point we can rewrite the standard Call object format. - */ -final class CallInfoTranslator { - /** - * Maps String-based Telecomm call IDs to call objects and back. Entries are added with calls to - * {@link #getCall} and removed with explicit calls to {@link #removeCall}. - */ - private static final BiMap<String, Call> sCallsByTelecommId = HashBiMap.create(); - - /** - * Stores the next available ID usable by Call objects. IDs start at 100000 and increase by one - * with each use. 100000 is used so as not to conflict with traditional call IDs which start - * at 1. Non-conflict theory based on the notion that a user is highly unlikely to receive - * 100000 more traditional phone calls than those of type CallInfo (from Telecom). - * TODO(santoscordon): Remove this once Telecomm is the only source of phone calls. - */ - private static int sNextAvailableCallId = 100000; - - /** - * Performs the translation from a {@link CallInfo} into a {@link Call}. Looks up the Telecomm - * call ID to see if an integer call ID has been assigned. If it has not, then a new call ID - * will be created for the call. - * - * @param callInfo The call-info object from which to create a Call. - */ - static Call getCall(CallInfo callInfo) { - String telecommCallId = callInfo.getId(); - Call call = getCall(telecommCallId); - if (call == null) { - call = new Call(sNextAvailableCallId++); - sCallsByTelecommId.put(telecommCallId, call); - } - - call.setState(translateCallState(callInfo.getState())); - call.setNumber(callInfo.getOriginalHandle().getSchemeSpecificPart()); - - GatewayInfo gatewayInfo = callInfo.getGatewayInfo(); - if (gatewayInfo != null) { - call.setGatewayNumber(gatewayInfo.getGatewayHandle().getSchemeSpecificPart()); - call.setGatewayPackage(gatewayInfo.getGatewayProviderPackageName()); - } - - // TODO: Each CallService needs to provide information what kind of call capabilities they - // support. For now, always assume that all calls support hold by default. - call.addCapabilities(Call.Capabilities.HOLD | Call.Capabilities.MUTE); - - return call; - } - - /** - * Returns the call which maps from the specified Telecomm call ID. - * - * @param telecommCallId The Telecomm call ID to map. - * @return The call associated with the specified Telecomm call ID, or null if no association - * exists. - */ - static Call getCall(String telecommCallId) { - Preconditions.checkState(!Strings.isNullOrEmpty(telecommCallId)); - return sCallsByTelecommId.get(telecommCallId); - } - - /** - * Returns the Telecomm call ID for the given call object. - * - * @param call The call object associated with the Telecomm call ID. - * @return The telecomm call ID or null if it cannot be found. - */ - static String getTelecommCallId(Call call) { - return sCallsByTelecommId.inverse().get(call); - } - - /** - * Removes the specified Telecomm call ID from the map. - * - * @param telecommCallId The Telecomm call ID to remove. - */ - static void removeCall(String telecommCallId) { - sCallsByTelecommId.remove(telecommCallId); - } - - /** - * Converts {@link CallState} to its {@link Call#State} equivalent. - * - * @param callState The call state from Telecomm. - */ - private static int translateCallState(CallState callState) { - switch(callState) { - case RINGING: - return Call.State.INCOMING; - case DIALING: - return Call.State.DIALING; - case ACTIVE: - return Call.State.ACTIVE; - default: - return Call.State.INVALID; - } - } -} diff --git a/InCallUI/src/com/android/incallui/CallList.java b/InCallUI/src/com/android/incallui/CallList.java index c0303254c..f7ac66e21 100644 --- a/InCallUI/src/com/android/incallui/CallList.java +++ b/InCallUI/src/com/android/incallui/CallList.java @@ -25,8 +25,6 @@ import android.os.Handler; import android.os.Message; import android.telephony.DisconnectCause; -import com.android.services.telephony.common.Call; - import java.util.HashMap; import java.util.List; import java.util.Set; @@ -251,6 +249,15 @@ public class CallList { return mCallMap.get(callId); } + public Call getCall(String callId) { + for (Call call : mCallMap.values()) { + if (call.getTelecommCallId().equals(callId)) { + return call; + } + } + return null; + } + public boolean existsLiveCall() { for (Call call : mCallMap.values()) { if (!isCallDead(call)) { diff --git a/InCallUI/src/com/android/incallui/CallerInfoUtils.java b/InCallUI/src/com/android/incallui/CallerInfoUtils.java index 3d2c5c4a7..d1238a37f 100644 --- a/InCallUI/src/com/android/incallui/CallerInfoUtils.java +++ b/InCallUI/src/com/android/incallui/CallerInfoUtils.java @@ -5,9 +5,6 @@ import android.content.Intent; import android.net.Uri; import android.text.TextUtils; -import com.android.services.telephony.common.Call; -import com.android.services.telephony.common.CallIdentification; - import java.util.Arrays; /** @@ -37,7 +34,7 @@ public class CallerInfoUtils { * more information is returned to the OnQueryCompleteListener (which contains * information about the phone number label, user's name, etc). */ - public static CallerInfo getCallerInfoForCall(Context context, CallIdentification call, + public static CallerInfo getCallerInfoForCall(Context context, Call call, CallerInfoAsyncQuery.OnQueryCompleteListener listener) { CallerInfo info = buildCallerInfo(context, call); String number = info.phoneNumber; @@ -52,17 +49,17 @@ public class CallerInfoUtils { return info; } - public static CallerInfo buildCallerInfo(Context context, CallIdentification identification) { + public static CallerInfo buildCallerInfo(Context context, Call call) { CallerInfo info = new CallerInfo(); // Store CNAP information retrieved from the Connection (we want to do this // here regardless of whether the number is empty or not). - info.cnapName = identification.getCnapName(); + info.cnapName = call.getCnapName(); info.name = info.cnapName; - info.numberPresentation = identification.getNumberPresentation(); - info.namePresentation = identification.getCnapNamePresentation(); + info.numberPresentation = call.getNumberPresentation(); + info.namePresentation = call.getCnapNamePresentation(); - String number = identification.getNumber(); + String number = call.getNumber(); if (!TextUtils.isEmpty(number)) { final String[] numbers = number.split("&"); number = numbers[0]; diff --git a/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java b/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java index 6e73a69e0..ec706d074 100644 --- a/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java +++ b/InCallUI/src/com/android/incallui/ConferenceManagerPresenter.java @@ -21,7 +21,6 @@ import android.content.Context; import com.android.incallui.ContactInfoCache.ContactCacheEntry; import com.android.incallui.InCallPresenter.InCallState; import com.android.incallui.InCallPresenter.InCallStateListener; -import com.android.services.telephony.common.Call; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSortedSet; @@ -154,13 +153,13 @@ public class ConferenceManagerPresenter public void separateConferenceConnection(int rowId) { if (rowId < mCallerIds.length) { - CallCommandClient.getInstance().separateCall(mCallerIds[rowId]); + TelecommAdapter.getInstance().separateCall(mCallerIds[rowId]); } } public void endConferenceConnection(int rowId) { if (rowId < mCallerIds.length) { - CallCommandClient.getInstance().disconnectCall(mCallerIds[rowId]); + TelecommAdapter.getInstance().disconnectCall(mCallerIds[rowId]); } } diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java index 54de7057d..2b6dd5b09 100644 --- a/InCallUI/src/com/android/incallui/ContactInfoCache.java +++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java @@ -30,8 +30,6 @@ import android.text.TextUtils; import com.android.contacts.common.util.PhoneNumberHelper; import com.android.incallui.service.PhoneNumberService; import com.android.incalluibind.ServiceFactory; -import com.android.services.telephony.common.Call; -import com.android.services.telephony.common.CallIdentification; import com.android.services.telephony.common.MoreStrings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; @@ -77,14 +75,14 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete return mInfoMap.get(callId); } - public static ContactCacheEntry buildCacheEntryFromCall(Context context, - CallIdentification identification, boolean isIncoming) { + public static ContactCacheEntry buildCacheEntryFromCall(Context context, Call call, + boolean isIncoming) { final ContactCacheEntry entry = new ContactCacheEntry(); // TODO: get rid of caller info. - final CallerInfo info = CallerInfoUtils.buildCallerInfo(context, identification); - ContactInfoCache.populateCacheEntry(context, info, entry, - identification.getNumberPresentation(), isIncoming); + final CallerInfo info = CallerInfoUtils.buildCallerInfo(context, call); + ContactInfoCache.populateCacheEntry(context, info, entry, call.getNumberPresentation(), + isIncoming); return entry; } @@ -97,8 +95,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete @Override public void onQueryComplete(int token, Object cookie, CallerInfo callerInfo) { - final CallIdentification identification = (CallIdentification) cookie; - findInfoQueryComplete(identification, callerInfo, mIsIncoming, true); + findInfoQueryComplete((Call) cookie, callerInfo, mIsIncoming, true); } } @@ -107,15 +104,14 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete * Returns the data through callback. If callback is null, no response is made, however the * query is still performed and cached. * - * @param identification The call identification * @param callback The function to call back when the call is found. Can be null. */ - public void findInfo(final CallIdentification identification, final boolean isIncoming, + public void findInfo(final Call call, final boolean isIncoming, ContactInfoCacheCallback callback) { Preconditions.checkState(Looper.getMainLooper().getThread() == Thread.currentThread()); Preconditions.checkNotNull(callback); - final int callId = identification.getCallId(); + final int callId = call.getCallId(); final ContactCacheEntry cacheEntry = mInfoMap.get(callId); Set<ContactInfoCacheCallback> callBacks = mCallBacks.get(callId); @@ -148,15 +144,15 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete * emergency call information, will not perform an additional asynchronous query. */ final CallerInfo callerInfo = CallerInfoUtils.getCallerInfoForCall( - mContext, identification, new FindInfoCallback(isIncoming)); + mContext, call, new FindInfoCallback(isIncoming)); - findInfoQueryComplete(identification, callerInfo, isIncoming, false); + findInfoQueryComplete(call, callerInfo, isIncoming, false); } - private void findInfoQueryComplete(CallIdentification identification, - CallerInfo callerInfo, boolean isIncoming, boolean didLocalLookup) { - final int callId = identification.getCallId(); - int presentationMode = identification.getNumberPresentation(); + private void findInfoQueryComplete(Call call, CallerInfo callerInfo, boolean isIncoming, + boolean didLocalLookup) { + final int callId = call.getCallId(); + int presentationMode = call.getNumberPresentation(); if (callerInfo.contactExists || callerInfo.isEmergencyNumber() || callerInfo.isVoiceMailNumber()) { presentationMode = Call.PRESENTATION_ALLOWED; } @@ -340,7 +336,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete } /** - * Populate a cache entry from a caller identification (which got converted into a caller info). + * Populate a cache entry from a call (which got converted into a caller info). */ public static void populateCacheEntry(Context context, CallerInfo info, ContactCacheEntry cce, int presentation, boolean isIncoming) { diff --git a/InCallUI/src/com/android/incallui/DialpadPresenter.java b/InCallUI/src/com/android/incallui/DialpadPresenter.java index e426a6a18..53a21d090 100644 --- a/InCallUI/src/com/android/incallui/DialpadPresenter.java +++ b/InCallUI/src/com/android/incallui/DialpadPresenter.java @@ -19,8 +19,6 @@ package com.android.incallui; import android.telecomm.InCallAdapter; import android.telephony.PhoneNumberUtils; -import com.android.services.telephony.common.Call; - /** * Logic for call buttons. */ @@ -50,17 +48,12 @@ public class DialpadPresenter extends Presenter<DialpadPresenter.DialpadUi> Log.d(this, "Processing dtmf key " + c); // if it is a valid key, then update the display and send the dtmf tone. if (PhoneNumberUtils.is12Key(c) && mCall != null) { - // Plays the tone through Telecomm - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - String callId = CallInfoTranslator.getTelecommCallId(mCall); - if (callId != null) { - Log.d(this, "updating display and sending dtmf tone for '" + c + "'"); - // Append this key to the "digits" widget. - getUi().appendDigitsToField(c); - telecommAdapter.playDtmfTone(callId, c); - } - } + Log.d(this, "updating display and sending dtmf tone for '" + c + "'"); + + // Append this key to the "digits" widget. + getUi().appendDigitsToField(c); + // Plays the tone through Telecomm. + TelecommAdapter.getInstance().playDtmfTone(mCall.getCallId(), c); } else { Log.d(this, "ignoring dtmf request for '" + c + "'"); } @@ -72,14 +65,7 @@ public class DialpadPresenter extends Presenter<DialpadPresenter.DialpadUi> public void stopTone() { if (mCall != null) { Log.d(this, "stopping remote tone"); - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - String callId = CallInfoTranslator.getTelecommCallId(mCall); - if (callId != null) { - Log.d(this, "stopping remote tone: " + callId); - telecommAdapter.stopDtmfTone(callId); - } - } + TelecommAdapter.getInstance().stopDtmfTone(mCall.getCallId()); } } diff --git a/InCallUI/src/com/android/incallui/InCallActivity.java b/InCallUI/src/com/android/incallui/InCallActivity.java index f4af51280..1b351d545 100644 --- a/InCallUI/src/com/android/incallui/InCallActivity.java +++ b/InCallUI/src/com/android/incallui/InCallActivity.java @@ -16,9 +16,6 @@ package com.android.incallui; -import com.android.services.telephony.common.Call; -import com.android.services.telephony.common.Call.State; - import android.app.Activity; import android.app.AlertDialog; import android.app.FragmentTransaction; @@ -28,7 +25,6 @@ import android.content.DialogInterface.OnCancelListener; import android.content.Intent; import android.content.res.Configuration; import android.os.Bundle; -import android.telecomm.InCallAdapter; import android.telephony.DisconnectCause; import android.view.KeyEvent; import android.view.View; @@ -37,6 +33,8 @@ import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.widget.Toast; +import com.android.incallui.Call.State; + /** * Phone app "in call" screen. */ @@ -269,8 +267,7 @@ public class InCallActivity extends Activity { case KeyEvent.KEYCODE_MUTE: // toggle mute - setMute(!AudioModeProvider.getInstance().getMute()); - CallCommandClient.getInstance().mute(!AudioModeProvider.getInstance().getMute()); + TelecommAdapter.getInstance().mute(!AudioModeProvider.getInstance().getMute()); return true; // Various testing/debugging features, enabled ONLY when VERBOSE == true. @@ -296,16 +293,6 @@ public class InCallActivity extends Activity { return super.onKeyDown(keyCode, event); } - private void setMute(boolean shouldMute) { - CallCommandClient.getInstance().mute(shouldMute); - - InCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); - if (telecommAdapter != null) { - Log.i(this, "Setting mute"); - telecommAdapter.mute(shouldMute); - } - } - private boolean handleDialerKeyDown(int keyCode, KeyEvent event) { Log.v(this, "handleDialerKeyDown: keyCode " + keyCode + ", event " + event + "..."); @@ -367,7 +354,7 @@ public class InCallActivity extends Activity { // wants to use the dialpad toward the exact line, so un-hold the holding line. final Call call = CallList.getInstance().getActiveOrBackgroundCall(); if (call != null && call.getState() == State.ONHOLD) { - CallCommandClient.getInstance().hold(call.getCallId(), false); + TelecommAdapter.getInstance().unholdCall(call.getCallId()); } } } diff --git a/InCallUI/src/com/android/incallui/InCallApp.java b/InCallUI/src/com/android/incallui/InCallApp.java index 01bdf3bf1..759f391b8 100644 --- a/InCallUI/src/com/android/incallui/InCallApp.java +++ b/InCallUI/src/com/android/incallui/InCallApp.java @@ -63,9 +63,7 @@ public class InCallApp extends Application { final String action = intent.getAction(); Log.i(this, "Broadcast from Notification: " + action); - // TODO: Commands of this nature should exist in the CallList or a - // CallController class that has access to CallCommandClient and - // CallList. + // TODO: Commands of this nature should exist in the CallList. if (action.equals(ACTION_HANG_UP_ONGOING_CALL)) { InCallPresenter.getInstance().hangUpOngoingCall(context); } else if (action.equals(ACTION_ANSWER_INCOMING_CALL)) { diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 271ba4012..ce2bcbb3f 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -21,10 +21,8 @@ import com.google.common.base.Preconditions; import android.content.Context; import android.content.Intent; -import android.telecomm.InCallAdapter; -import com.android.services.telephony.common.Call; -import com.android.services.telephony.common.Call.Capabilities; +import com.android.incallui.Call.Capabilities; import com.google.common.collect.Lists; import java.util.ArrayList; @@ -56,9 +54,6 @@ public class InCallPresenter implements CallList.Listener { private ProximitySensor mProximitySensor; private boolean mServiceConnected = false; - /** Used to send call-related commands and updates back to Telecomm. */ - private InCallAdapter mTelecommAdapter; - /** * Is true when the activity has been previously started. Some code needs to know not just if * the activity is currently up, but if it had been previously shown in foreground for this @@ -232,7 +227,7 @@ public class InCallPresenter implements CallList.Listener { // Renable notification shade and soft navigation buttons, if we are no longer in the // incoming call screen if (!newState.isIncoming()) { - CallCommandClient.getInstance().setSystemBarNavigationEnabled(true); + TelecommAdapter.getInstance().setSystemBarNavigationEnabled(true); } // Set the new state before announcing it to the world @@ -363,7 +358,7 @@ public class InCallPresenter implements CallList.Listener { } if (call != null) { - CallCommandClient.getInstance().disconnectCall(call.getCallId()); + TelecommAdapter.getInstance().disconnectCall(call.getCallId()); } } @@ -380,7 +375,7 @@ public class InCallPresenter implements CallList.Listener { Call call = mCallList.getIncomingCall(); if (call != null) { - CallCommandClient.getInstance().answerCall(call.getCallId()); + TelecommAdapter.getInstance().answerCall(call.getCallId()); showInCall(false); } } @@ -398,7 +393,7 @@ public class InCallPresenter implements CallList.Listener { Call call = mCallList.getIncomingCall(); if (call != null) { - CallCommandClient.getInstance().rejectCall(call, false, null); + TelecommAdapter.getInstance().rejectCall(call.getCallId(), false, null); } } @@ -443,7 +438,7 @@ public class InCallPresenter implements CallList.Listener { } final boolean shouldLockBars = showing && mInCallState.isIncoming(); - CallCommandClient.getInstance().setSystemBarNavigationEnabled(!shouldLockBars); + TelecommAdapter.getInstance().setSystemBarNavigationEnabled(!shouldLockBars); } /** @@ -486,7 +481,7 @@ public class InCallPresenter implements CallList.Listener { // (1) Attempt to answer a call if (incomingCall != null) { - CallCommandClient.getInstance().answerCall(incomingCall.getCallId()); + TelecommAdapter.getInstance().answerCall(incomingCall.getCallId()); return true; } @@ -507,17 +502,17 @@ public class InCallPresenter implements CallList.Listener { // (2) Attempt actions on Generic conference calls if (activeCall.isConferenceCall() && isGeneric) { if (canMerge) { - CallCommandClient.getInstance().merge(); + TelecommAdapter.getInstance().merge(); return true; } else if (canSwap) { - CallCommandClient.getInstance().swap(); + TelecommAdapter.getInstance().swap(); return true; } } // (3) Swap calls if (canSwap) { - CallCommandClient.getInstance().swap(); + TelecommAdapter.getInstance().swap(); return true; } } @@ -535,7 +530,7 @@ public class InCallPresenter implements CallList.Listener { // (4) unhold call if (heldCall.getState() == Call.State.ONHOLD && canHold) { - CallCommandClient.getInstance().hold(heldCall.getCallId(), false); + TelecommAdapter.getInstance().unholdCall(heldCall.getCallId()); return true; } } @@ -558,19 +553,6 @@ public class InCallPresenter implements CallList.Listener { } /** - * Persists the current instance of InCallAdapter. - * - * @param telecommAdapter The adapter to the Telecomm system used to send call-related commands. - */ - void setTelecommAdapter(InCallAdapter telecommAdapter) { - mTelecommAdapter = telecommAdapter; - } - - InCallAdapter getTelecommAdapter() { - return mTelecommAdapter; - } - - /** * For some disconnected causes, we show a dialog. This calls into the activity to show * the dialog if appropriate for the call. */ diff --git a/InCallUI/src/com/android/incallui/InCallServiceImpl.java b/InCallUI/src/com/android/incallui/InCallServiceImpl.java index ca04993e0..e2e377cb6 100644 --- a/InCallUI/src/com/android/incallui/InCallServiceImpl.java +++ b/InCallUI/src/com/android/incallui/InCallServiceImpl.java @@ -18,10 +18,10 @@ package com.android.incallui; import android.telecomm.CallAudioState; import android.telecomm.CallInfo; +import android.telecomm.GatewayInfo; import android.telecomm.InCallAdapter; import android.telephony.DisconnectCause; -import com.android.services.telephony.common.Call; import com.google.common.collect.ImmutableList; /** @@ -36,6 +36,7 @@ public class InCallServiceImpl extends android.telecomm.InCallService { /** {@inheritDoc} */ @Override public void onCreate() { + Log.v(this, "onCreate"); InCallPresenter inCallPresenter = InCallPresenter.getInstance(); inCallPresenter.setUp( getApplicationContext(), CallList.getInstance(), AudioModeProvider.getInstance()); @@ -43,6 +44,7 @@ public class InCallServiceImpl extends android.telecomm.InCallService { /** {@inheritDoc} */ @Override public void onDestroy() { + Log.v(this, "onDestroy"); // Tear down the InCall system CallList.getInstance().clearOnDisconnect(); InCallPresenter.getInstance().tearDown(); @@ -53,12 +55,40 @@ public class InCallServiceImpl extends android.telecomm.InCallService { * {@inheritDoc} */ @Override protected void setInCallAdapter(InCallAdapter inCallAdapter) { - InCallPresenter.getInstance().setTelecommAdapter(inCallAdapter); + Log.v(this, "setInCallAdapter"); + TelecommAdapter.getInstance().setAdapter(inCallAdapter); } /** {@inheritDoc} */ @Override protected void addCall(CallInfo callInfo) { - Call call = CallInfoTranslator.getCall(callInfo); + Log.v(this, "addCall, state: " + callInfo.getState()); + Call call = new Call(callInfo.getId(), + callInfo.getOriginalHandle().getSchemeSpecificPart()); + switch(callInfo.getState()) { + case RINGING: + call.setState(Call.State.INCOMING); + break; + case DIALING: + call.setState(Call.State.DIALING); + break; + case ACTIVE: + call.setState(Call.State.ACTIVE); + break; + case DISCONNECTED: + call.setState(Call.State.DISCONNECTED); + break; + default: + call.setState(Call.State.INVALID); + break; + } + + GatewayInfo gatewayInfo = callInfo.getGatewayInfo(); + if (gatewayInfo != null) { + call.setGatewayNumber(gatewayInfo.getGatewayHandle().getSchemeSpecificPart()); + call.setGatewayPackage(gatewayInfo.getGatewayProviderPackageName()); + } + + call.addCapabilities(Call.Capabilities.HOLD | Call.Capabilities.MUTE); if (call.getState() == Call.State.INCOMING) { CallList.getInstance().onIncoming(call, EMPTY_RESPONSE_TEXTS); @@ -69,7 +99,8 @@ public class InCallServiceImpl extends android.telecomm.InCallService { /** {@inheritDoc} */ @Override protected void setActive(String callId) { - Call call = CallInfoTranslator.getCall(callId); + Call call = CallList.getInstance().getCall(callId); + Log.v(this, "setActive: " + call); if (null != call) { call.setState(Call.State.ACTIVE); if (call.getConnectTime() == 0) { @@ -81,7 +112,8 @@ public class InCallServiceImpl extends android.telecomm.InCallService { /** {@inheritDoc} */ @Override protected void setDialing(String callId) { - Call call = CallInfoTranslator.getCall(callId); + Call call = CallList.getInstance().getCall(callId); + Log.v(this, "setDialing: " + call); if (null != call) { call.setState(Call.State.DIALING); CallList.getInstance().onUpdate(call); @@ -90,52 +122,36 @@ public class InCallServiceImpl extends android.telecomm.InCallService { /** {@inheritDoc} */ @Override protected void setRinging(String callId) { - Call call = CallInfoTranslator.getCall(callId); - if (null != call) { - call.setState(Call.State.RINGING); - CallList.getInstance().onUpdate(call); - } + // TODO(ihab): Implement this. + Log.v(this, "setRinging"); } /** {@inheritDoc} */ @Override protected void setPostDial(String callId, String remaining) { - Call call = CallInfoTranslator.getCall(callId); - if (null != call) { - // TODO(ihab): Add post-dial state to user interface - // TODO(ihab: Do the equivalent in the new framework: - // call.setState(Call.State.POST_DIAL); - CallList.getInstance().onUpdate(call); - } + // TODO(ihab): Add post-dial state to user interface + // TODO(ihab: Do the equivalent in the new framework: } /** {@inheritDoc} */ @Override protected void setPostDialWait(String callId, String remaining) { - Call call = CallInfoTranslator.getCall(callId); - if (null != call) { - // TODO(ihab): Add post-dial state to user interface - // TODO(ihab): Do the equivalent in the new framework: - // call.setState(Call.State.POST_DIAL_WAIT); - CallList.getInstance().onUpdate(call); - } + // TODO(ihab): Add post-dial state to user interface + // TODO(ihab): Do the equivalent in the new framework: } /** {@inheritDoc} */ @Override protected void setDisconnected(String callId, int disconnectCause) { - Call call = CallInfoTranslator.getCall(callId); + Log.v(this, "setDisconnected"); + Call call = CallList.getInstance().getCall(callId); if (null != call) { call.setDisconnectCause(DisconnectCause.NORMAL); call.setState(Call.State.DISCONNECTED); CallList.getInstance().onDisconnect(call); - - // Remove it from the mapping since we no longer need to interact - // with the Call. - CallInfoTranslator.removeCall(callId); } } /** {@inheritDoc} */ @Override protected void setOnHold(String callId) { - Call call = CallInfoTranslator.getCall(callId); + Call call = CallList.getInstance().getCall(callId); if (null != call) { call.setState(Call.State.ONHOLD); CallList.getInstance().onUpdate(call); diff --git a/InCallUI/src/com/android/incallui/PostCharDialogFragment.java b/InCallUI/src/com/android/incallui/PostCharDialogFragment.java index 41940ff34..5c7d8eac2 100644 --- a/InCallUI/src/com/android/incallui/PostCharDialogFragment.java +++ b/InCallUI/src/com/android/incallui/PostCharDialogFragment.java @@ -52,7 +52,7 @@ public class PostCharDialogFragment extends DialogFragment { builder.setPositiveButton(R.string.pause_prompt_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { - CallCommandClient.getInstance().postDialWaitContinue(mCallId); + TelecommAdapter.getInstance().postDialWaitContinue(mCallId); } }); builder.setNegativeButton(R.string.pause_prompt_no, new DialogInterface.OnClickListener() { @@ -71,6 +71,6 @@ public class PostCharDialogFragment extends DialogFragment { public void onCancel(DialogInterface dialog) { super.onCancel(dialog); - CallCommandClient.getInstance().postDialCancel(mCallId); + TelecommAdapter.getInstance().postDialCancel(mCallId); } } diff --git a/InCallUI/src/com/android/incallui/StatusBarNotifier.java b/InCallUI/src/com/android/incallui/StatusBarNotifier.java index 807e44b3d..2702dcf82 100644 --- a/InCallUI/src/com/android/incallui/StatusBarNotifier.java +++ b/InCallUI/src/com/android/incallui/StatusBarNotifier.java @@ -34,7 +34,6 @@ import com.android.incallui.ContactInfoCache.ContactCacheEntry; import com.android.incallui.ContactInfoCache.ContactInfoCacheCallback; import com.android.incallui.InCallApp.NotificationBroadcastReceiver; import com.android.incallui.InCallPresenter.InCallState; -import com.android.services.telephony.common.Call; /** * This class adds Notifications to the status bar for the in-call experience. @@ -224,24 +223,22 @@ public class StatusBarNotifier implements InCallPresenter.InCallStateListener { // This callback will always get called immediately and synchronously with whatever data // it has available, and may make a subsequent call later (same thread) if it had to // call into the contacts provider for more data. - mContactInfoCache.findInfo(call.getIdentification(), isIncoming, - new ContactInfoCacheCallback() { - - @Override - public void onContactInfoComplete(int callId, ContactCacheEntry entry) { - Call call = CallList.getInstance().getCall(callId); - if (call != null) { - buildAndSendNotification(call, entry); - } + mContactInfoCache.findInfo(call, isIncoming, new ContactInfoCacheCallback() { + @Override + public void onContactInfoComplete(int callId, ContactCacheEntry entry) { + Call call = CallList.getInstance().getCall(callId); + if (call != null) { + buildAndSendNotification(call, entry); } + } - @Override - public void onImageLoadComplete(int callId, ContactCacheEntry entry) { - Call call = CallList.getInstance().getCall(callId); - if (call != null) { - buildAndSendNotification(call, entry); - } - } }); + @Override + public void onImageLoadComplete(int callId, ContactCacheEntry entry) { + Call call = CallList.getInstance().getCall(callId); + if (call != null) { + buildAndSendNotification(call, entry); + } + } }); } /** diff --git a/InCallUI/src/com/android/incallui/TelecommAdapter.java b/InCallUI/src/com/android/incallui/TelecommAdapter.java new file mode 100644 index 000000000..deb633e26 --- /dev/null +++ b/InCallUI/src/com/android/incallui/TelecommAdapter.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui; + +import android.os.Looper; +import android.telecomm.InCallAdapter; + +import com.google.common.base.Preconditions; + +/** Wrapper around {@link InCallAdapter} that only forwards calls to the adapter when it's valid. */ +final class TelecommAdapter { + private static TelecommAdapter sInstance; + private InCallAdapter mAdapter; + + static TelecommAdapter getInstance() { + Preconditions.checkState(Looper.getMainLooper().getThread() == Thread.currentThread()); + if (sInstance == null) { + sInstance = new TelecommAdapter(); + } + return sInstance; + } + + private TelecommAdapter() { + } + + void setAdapter(InCallAdapter adapter) { + mAdapter = adapter; + } + + void answerCall(int callId) { + if (mAdapter != null) { + mAdapter.answerCall(getTelecommCallId(callId)); + } else { + Log.e(this, "error answerCall, mAdapter is null"); + } + } + + void rejectCall(int callId, boolean rejectWithMessage, String message) { + if (mAdapter != null) { + // TODO(sail): Add support for reject with message. + mAdapter.rejectCall(getTelecommCallId(callId)); + } else { + Log.e(this, "error rejectCall, mAdapter is null"); + } + } + + void disconnectCall(int callId) { + if (mAdapter != null) { + mAdapter.disconnectCall(getTelecommCallId(callId)); + } else { + Log.e(this, "error disconnectCall, mAdapter is null"); + } + } + + void holdCall(int callId) { + if (mAdapter != null) { + mAdapter.holdCall(getTelecommCallId(callId)); + } else { + Log.e(this, "error holdCall, mAdapter is null"); + } + } + + void unholdCall(int callId) { + if (mAdapter != null) { + mAdapter.unholdCall(getTelecommCallId(callId)); + } else { + Log.e(this, "error unholdCall, mAdapter is null"); + } + } + + void mute(boolean shouldMute) { + if (mAdapter != null) { + mAdapter.mute(shouldMute); + } else { + Log.e(this, "error mute, mAdapter is null"); + } + } + + void setAudioRoute(int route) { + if (mAdapter != null) { + mAdapter.setAudioRoute(route); + } else { + Log.e(this, "error setAudioRoute, mAdapter is null"); + } + } + + void separateCall(int callId) { + Log.wtf(this, "separateCall not implemented"); + } + + void merge() { + Log.wtf(this, "merge not implemented"); + } + + void swap() { + Log.wtf(this, "swap not implemented"); + } + + void addCall() { + Log.wtf(this, "addCall not implemented"); + } + + void playDtmfTone(int callId, char digit) { + if (mAdapter != null) { + mAdapter.playDtmfTone(getTelecommCallId(callId), digit); + } else { + Log.e(this, "error playDtmfTone, mAdapter is null"); + } + } + + void stopDtmfTone(int callId) { + if (mAdapter != null) { + mAdapter.stopDtmfTone(getTelecommCallId(callId)); + } else { + Log.e(this, "error stopDtmfTone, mAdapter is null"); + } + } + + void postDialWaitContinue(int callId) { + Log.wtf(this, "postDialWaitContinue not implemented"); + } + + void postDialCancel(int 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(); + } +} |