Make incoming calls work.
This is a CL of random changes. Ties of loose ends which were previously
commented and adds new wiring to connect all the pieces together.
After this CL, incoming calls are functional for call services.
Change-Id: I6fa1e70b816094587849329790236f9289ec260b
diff --git a/src/com/android/telecomm/IncomingCallsManager.java b/src/com/android/telecomm/IncomingCallsManager.java
index 063469d..1539cbf 100644
--- a/src/com/android/telecomm/IncomingCallsManager.java
+++ b/src/com/android/telecomm/IncomingCallsManager.java
@@ -18,24 +18,26 @@
import android.os.Handler;
import android.os.Looper;
+import android.telecomm.CallInfo;
+import android.util.Log;
-import com.android.telecomm.ServiceBinder.BindCallback;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import java.util.Map;
/**
- * Utility class to confirm the existence of an incoming call after receiving an incoming-call
- * intent, see {@link TelecommReceiver}. Binds with the specified call services and requests
- * confirmation of incoming calls using call tokens provided as part of the intent. Upon receipt of
- * the confirmation, yields execution back to the switchboard to complete the incoming sequence. The
- * entire process is timeboxed to protect against unresponsive call services.
+ * Utility class to retrieve details of an incoming call after receiving an incoming-call intent,
+ * see {@link CallActivity}. Binds with the specified call services and requests details of incoming
+ * calls. Upon receipt of the details, yields execution back to the switchboard to complete the
+ * incoming sequence. The entire process is timeboxed to protect against unresponsive call services.
*/
final class IncomingCallsManager {
+ private static final String TAG = IncomingCallsManager.class.getSimpleName();
+
/**
- * The amount of time to wait for confirmation of an incoming call, in milliseconds.
+ * The amount of time to wait for details of an incoming call, in milliseconds.
* TODO(santoscordon): Likely needs adjustment.
*/
private static final int INCOMING_CALL_TIMEOUT_MS = 1000;
@@ -44,8 +46,8 @@
private final Handler mHandler = new Handler(Looper.getMainLooper());
- /** Maps incoming calls to their call services. */
- private final Map<Call, CallServiceWrapper> mPendingIncomingCalls = Maps.newHashMap();
+ /** Maps call ID to the call. */
+ private final Map<String, Call> mPendingIncomingCalls = Maps.newHashMap();
/**
* Persists the specified parameters.
@@ -57,63 +59,44 @@
}
/**
- * Confirms the existence of an incoming call with the specified call service (asynchronously).
+ * Retrieves details of an incoming call through its associated call service (asynchronously).
* Starts the timeout sequence in case the call service is unresponsive.
*
* @param call The call object.
- * @param callService The call service.
- * @param callToken The token used by the call service to identify the incoming call.
*/
- void confirmIncomingCall(
- final Call call, final CallServiceWrapper callService, String callToken) {
-
+ void retrieveIncomingCall(Call call) {
ThreadUtil.checkOnMainThread();
- // Just to be safe, lets make sure we're not already processing this call.
- Preconditions.checkState(!mPendingIncomingCalls.containsKey(call));
+ Log.d(TAG, "retrieveIncomingCall");
- mPendingIncomingCalls.put(call, callService);
+ final String callId = call.getId();
+ // Just to be safe, lets make sure we're not already processing this call.
+ Preconditions.checkState(!mPendingIncomingCalls.containsKey(callId));
+
+ mPendingIncomingCalls.put(callId, call);
+
+ // TODO(santoscordon): Timeout will not be necessary after cleanup via tick() is implemented
+ // in Switchboard.
startTimeoutForCall(call);
- BindCallback callback = new BindCallback() {
- @Override public void onSuccess() {
- // TODO(santoscordon): ICallService needs to be updated with the following method.
- // Confirmation won't work until this method is filled in.
- // callService.confirmIncomingCall(call.toCallInfo(), callToken);
- }
- @Override public void onFailure() {
- handleFailedIncomingCall(call);
- }
- };
-
- callService.bind(callback);
- }
-
- /**
- * Starts a timeout to timebox the confirmation of an incoming call. When the timeout expires,
- * it will notify switchboard that the incoming call was not confirmed and thus does not exist
- * as far as Telecomm is concerned.
- *
- * @param call The call.
- */
- void startTimeoutForCall(final Call call) {
- Runnable timeoutCallback = new Runnable() {
- @Override public void run() {
- handleFailedIncomingCall(call);
- }
- };
- mHandler.postDelayed(timeoutCallback, INCOMING_CALL_TIMEOUT_MS);
+ Runnable errorCallback = getFailedIncomingCallback(call);
+ call.getCallService().retrieveIncomingCall(callId, errorCallback);
}
/**
* Notifies the switchboard of a successful incoming call after removing it from the pending
* list.
- * TODO(santoscordon): Needs code in CallServiceAdapter to call this method.
*
- * @param call The call.
+ * @param callInfo The details of the call.
*/
- void handleSuccessfulIncomingCall(Call call) {
+ void handleSuccessfulIncomingCall(CallInfo callInfo) {
ThreadUtil.checkOnMainThread();
- if (mPendingIncomingCalls.remove(call) != null) {
+
+ Call call = mPendingIncomingCalls.remove(callInfo.getId());
+ if (call != null) {
+ Log.d(TAG, "Incoming call " + call.getId() + " found.");
+ call.setHandle(callInfo.getHandle());
+ call.setState(callInfo.getState());
+
mSwitchboard.handleSuccessfulIncomingCall(call);
}
}
@@ -123,11 +106,38 @@
*
* @param call The call.
*/
- void handleFailedIncomingCall(Call call) {
+ private void handleFailedIncomingCall(Call call) {
ThreadUtil.checkOnMainThread();
- if (mPendingIncomingCalls.remove(call) != null) {
- // The call was found still waiting for confirmation. Consider it failed.
+
+ if (mPendingIncomingCalls.remove(call.getId()) != null) {
+ Log.i(TAG, "Failed to get details for incoming call " + call);
+ // The call was found still waiting for details. Consider it failed.
mSwitchboard.handleFailedIncomingCall(call);
}
}
+
+ /**
+ * Starts a timeout to timebox the retrieval of an incoming call. When the timeout expires,
+ * it will notify switchboard that the incoming call was not retrieved and thus does not exist
+ * as far as Telecomm is concerned.
+ *
+ * @param call The call.
+ */
+ private void startTimeoutForCall(Call call) {
+ Runnable timeoutCallback = getFailedIncomingCallback(call);
+ mHandler.postDelayed(timeoutCallback, INCOMING_CALL_TIMEOUT_MS);
+ }
+
+ /**
+ * Returns a runnable to be invoked upon failure to get details for an incoming call.
+ *
+ * @param call The failed incoming call.
+ */
+ private Runnable getFailedIncomingCallback(final Call call) {
+ return new Runnable() {
+ @Override public void run() {
+ handleFailedIncomingCall(call);
+ }
+ };
+ }
}