diff options
-rw-r--r-- | InCallUI/src/com/android/incallui/AnswerPresenter.java | 39 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallInfoTranslator.java | 21 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallList.java | 47 |
3 files changed, 86 insertions, 21 deletions
diff --git a/InCallUI/src/com/android/incallui/AnswerPresenter.java b/InCallUI/src/com/android/incallui/AnswerPresenter.java index dd4deeb6a..664692347 100644 --- a/InCallUI/src/com/android/incallui/AnswerPresenter.java +++ b/InCallUI/src/com/android/incallui/AnswerPresenter.java @@ -16,6 +16,9 @@ package com.android.incallui; +import android.os.RemoteException; +import android.telecomm.IInCallAdapter; + import com.android.services.telephony.common.Call; import java.util.ArrayList; @@ -126,12 +129,48 @@ 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. + IInCallAdapter 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) { + // TODO(santoscordon): TelecommAdapter wrapper would also eliminate much of this + // try-catch code. + try { + Log.i(this, "Answering the call: " + callId); + telecommAdapter.answerCall(callId); + } catch (RemoteException e) { + Log.e(this, "Failed to send answer command.", e); + } + } + } } + /** + * TODO(santoscordon): We are using reject and decline interchangeably. We should settle on + * reject since it seems to be more prevalent. + */ public void onDecline() { Log.d(this, "onDecline " + mCallId); CallCommandClient.getInstance().rejectCall(mCall, false, null); + + IInCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); + if (telecommAdapter != null) { + String callId = CallInfoTranslator.getTelecommCallId(mCall); + if (callId != null) { + try { + Log.i(this, "Rejecting the call: " + callId); + telecommAdapter.rejectCall(callId); + } catch (RemoteException e) { + Log.e(this, "Failed to send reject command.", e); + } + } + } } public void onText() { diff --git a/InCallUI/src/com/android/incallui/CallInfoTranslator.java b/InCallUI/src/com/android/incallui/CallInfoTranslator.java index ba44c450b..fc4bd4940 100644 --- a/InCallUI/src/com/android/incallui/CallInfoTranslator.java +++ b/InCallUI/src/com/android/incallui/CallInfoTranslator.java @@ -17,6 +17,7 @@ package com.android.incallui; import android.telecomm.CallInfo; +import android.telecomm.CallState; import com.android.services.telephony.common.Call; import com.google.common.base.Preconditions; @@ -68,7 +69,7 @@ final class CallInfoTranslator { // TODO(santoscordon): Remove assumption that all calls are dialing by default once // CallInfo supports Call States - call.setState(Call.State.DIALING); + call.setState(translateCallState(callInfo.getState())); call.setNumber(callInfo.getHandle()); return call; @@ -104,4 +105,22 @@ final class CallInfoTranslator { 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 d4bf7bf13..3692bbfd3 100644 --- a/InCallUI/src/com/android/incallui/CallList.java +++ b/InCallUI/src/com/android/incallui/CallList.java @@ -69,16 +69,6 @@ public class CallList { } /** - * Called when a single call has changed. - */ - public void onUpdate(Call call) { - Log.d(this, "onUpdate - ", call); - - updateCallInMap(call); - notifyListenersOfChange(); - } - - /** * Called when a single call disconnects. */ public void onDisconnect(Call call) { @@ -110,6 +100,16 @@ public class CallList { } /** + * Called when a single call has changed. + */ + public void onUpdate(Call call) { + Log.d(this, "onUpdate - ", call); + + onUpdateCall(call); + notifyGenericListeners(); + } + + /** * Called when multiple calls have changed. */ public void onUpdate(List<Call> callsToUpdate) { @@ -117,15 +117,10 @@ public class CallList { Preconditions.checkNotNull(callsToUpdate); for (Call call : callsToUpdate) { - Log.d(this, "\t" + call); - - updateCallInMap(call); - updateCallTextMap(call, null); - - notifyCallUpdateListeners(call); + onUpdateCall(call); } - notifyListenersOfChange(); + notifyGenericListeners(); } public void notifyCallUpdateListeners(Call call) { @@ -317,14 +312,26 @@ public class CallList { updateCallInMap(call); } } - notifyListenersOfChange(); + notifyGenericListeners(); + } + + /** + * Processes an update for a single call. + * + * @param call The call to update. + */ + private void onUpdateCall(Call call) { + Log.d(this, "\t" + call); + updateCallInMap(call); + updateCallTextMap(call, null); + notifyCallUpdateListeners(call); } /** * Sends a generic notification to all listeners that something has changed. * It is up to the listeners to call back to determine what changed. */ - private void notifyListenersOfChange() { + private void notifyGenericListeners() { for (Listener listener : mListeners) { listener.onCallListChange(this); } @@ -423,7 +430,7 @@ public class CallList { private void finishDisconnectedCall(Call call) { call.setState(Call.State.IDLE); updateCallInMap(call); - notifyListenersOfChange(); + notifyGenericListeners(); } /** |