From 506e38690fe5e3b627e243fdc20948c514b87680 Mon Sep 17 00:00:00 2001 From: Sailesh Nepal Date: Wed, 25 Jun 2014 13:35:14 -0700 Subject: [PATCH] Add API to cancel outgoing calls This replaces CallServiceSelectorAdapter.cancelOutgoingCall Change-Id: I9e5da9c607675bc3c230f6eb6d1cc149a38bf905 --- api/current.txt | 13 +++- .../android/telecomm/CallServiceAdapter.java | 14 +++++ .../android/telecomm/ConnectionService.java | 63 +++++++++++++------ .../telecomm/RemoteConnectionManager.java | 2 +- .../telecomm/RemoteConnectionService.java | 28 ++++++--- .../telecomm/ICallServiceAdapter.aidl | 2 + 6 files changed, 89 insertions(+), 33 deletions(-) diff --git a/api/current.txt b/api/current.txt index 5e48e37dd1777..4b7fa23cd4de0 100644 --- a/api/current.txt +++ b/api/current.txt @@ -27601,6 +27601,7 @@ package android.telecomm { public final class CallServiceAdapter implements android.os.IBinder.DeathRecipient { method public void addConferenceCall(java.lang.String); method public void binderDied(); + method public void cancelOutgoingCall(java.lang.String); method public void handleFailedOutgoingCall(android.telecomm.ConnectionRequest, int, java.lang.String); method public void handleSuccessfulOutgoingCall(java.lang.String); method public void handoffCall(java.lang.String); @@ -27747,7 +27748,7 @@ package android.telecomm { method public final void abort(java.lang.String); method public final void answer(java.lang.String); method public final void call(android.telecomm.CallInfo); - method public void createRemoteOutgoingConnection(android.telecomm.ConnectionRequest, android.telecomm.SimpleResponse); + method public void createRemoteOutgoingConnection(android.telecomm.ConnectionRequest, android.telecomm.ConnectionService.OutgoingCallResponse); method public final void disconnect(java.lang.String); method public java.util.Collection getAllConnections(); method public final void hold(java.lang.String); @@ -27757,7 +27758,7 @@ package android.telecomm { method public void onConnectionAdded(android.telecomm.Connection); method public void onConnectionRemoved(android.telecomm.Connection); method public void onCreateConferenceConnection(java.lang.String, android.telecomm.Connection, android.telecomm.Response); - method public void onCreateConnections(android.telecomm.ConnectionRequest, android.telecomm.Response); + method public void onCreateConnections(android.telecomm.ConnectionRequest, android.telecomm.ConnectionService.OutgoingCallResponse); method public void onCreateIncomingConnection(android.telecomm.ConnectionRequest, android.telecomm.Response); method public final void onPostDialContinue(java.lang.String, boolean); method public final void onPostDialWait(android.telecomm.Connection, java.lang.String); @@ -27768,6 +27769,12 @@ package android.telecomm { method public final void unhold(java.lang.String); } + public static abstract interface ConnectionService.OutgoingCallResponse { + method public abstract void onCancel(android.telecomm.ConnectionRequest); + method public abstract void onFailure(android.telecomm.ConnectionRequest, int, java.lang.String); + method public abstract void onSuccess(android.telecomm.ConnectionRequest, CONNECTION); + } + public class GatewayInfo implements android.os.Parcelable { method public int describeContents(); method public android.net.Uri getGatewayHandle(); @@ -27848,7 +27855,7 @@ package android.telecomm { public class RemoteConnectionService implements android.os.IBinder.DeathRecipient { method public void binderDied(); - method public void createOutgoingConnection(android.telecomm.ConnectionRequest, android.telecomm.SimpleResponse); + method public void createOutgoingConnection(android.telecomm.ConnectionRequest, android.telecomm.ConnectionService.OutgoingCallResponse); method public java.util.List lookupSubscriptions(android.net.Uri); } diff --git a/telecomm/java/android/telecomm/CallServiceAdapter.java b/telecomm/java/android/telecomm/CallServiceAdapter.java index 30084d04da96c..31e37c4e59582 100644 --- a/telecomm/java/android/telecomm/CallServiceAdapter.java +++ b/telecomm/java/android/telecomm/CallServiceAdapter.java @@ -134,6 +134,20 @@ public final class CallServiceAdapter implements DeathRecipient { } } + /** + * Tells Telecomm to cancel the call. + * + * @param callId The ID of the outgoing call. + */ + public void cancelOutgoingCall(String callId) { + for (ICallServiceAdapter adapter : mAdapters) { + try { + adapter.cancelOutgoingCall(callId); + } catch (RemoteException e) { + } + } + } + /** * Sets a call's state to active (e.g., an ongoing call where two parties can actively * communicate). diff --git a/telecomm/java/android/telecomm/ConnectionService.java b/telecomm/java/android/telecomm/ConnectionService.java index 4b69a3c8247ac..23b99fac05be4 100644 --- a/telecomm/java/android/telecomm/ConnectionService.java +++ b/telecomm/java/android/telecomm/ConnectionService.java @@ -52,6 +52,35 @@ public abstract class ConnectionService extends CallService { private Uri mSubscriptionLookupHandle; private boolean mAreSubscriptionsInitialized = false; + /** + * A callback for providing the resuilt of creating a connection. + */ + public interface OutgoingCallResponse { + /** + * Tells Telecomm that an attempt to place the specified outgoing call succeeded. + * + * @param request The original request. + * @param connection The connection. + */ + void onSuccess(ConnectionRequest request, CONNECTION connection); + + /** + * Tells Telecomm that an attempt to place the specified outgoing call failed. + * + * @param request The original request. + * @param code An integer code indicating the reason for failure. + * @param msg A message explaining the reason for failure. + */ + void onFailure(ConnectionRequest request, int code, String msg); + + /** + * Tells Telecomm to cancel the call. + * + * @param request The original request. + */ + void onCancel(ConnectionRequest request); + } + private final Connection.Listener mConnectionListener = new Connection.Listener() { @Override public void onStateChanged(Connection c, int state) { @@ -136,30 +165,24 @@ public abstract class ConnectionService extends CallService { callInfo.getId(), callInfo.getHandle(), callInfo.getExtras()), - new Response() { + new OutgoingCallResponse() { @Override - public void onResult(ConnectionRequest request, Connection... result) { - if (result != null && result.length != 1) { - Log.d(this, "adapter handleFailedOutgoingCall %s", callInfo); - getAdapter().handleFailedOutgoingCall( - request, - DisconnectCause.ERROR_UNSPECIFIED, - "Created " + result.length + " Connections, expected 1"); - for (Connection c : result) { - c.abort(); - } - } else { - Log.d(this, "adapter handleSuccessfulOutgoingCall %s", - callInfo.getId()); - getAdapter().handleSuccessfulOutgoingCall(callInfo.getId()); - addConnection(callInfo.getId(), result[0]); - } + public void onSuccess(ConnectionRequest request, Connection connection) { + Log.d(this, "adapter handleSuccessfulOutgoingCall %s", + callInfo.getId()); + getAdapter().handleSuccessfulOutgoingCall(callInfo.getId()); + addConnection(callInfo.getId(), connection); } @Override - public void onError(ConnectionRequest request, int code, String msg) { + public void onFailure(ConnectionRequest request, int code, String msg) { getAdapter().handleFailedOutgoingCall(request, code, msg); } + + @Override + public void onCancel(ConnectionRequest request) { + getAdapter().cancelOutgoingCall(callInfo.getId()); + } } ); } @@ -389,7 +412,7 @@ public abstract class ConnectionService extends CallService { public void createRemoteOutgoingConnection( ConnectionRequest request, - SimpleResponse response) { + OutgoingCallResponse response) { mRemoteConnectionManager.createOutgoingConnection(request, response); } @@ -408,7 +431,7 @@ public abstract class ConnectionService extends CallService { */ public void onCreateConnections( ConnectionRequest request, - Response callback) {} + OutgoingCallResponse callback) {} /** * Returns a new or existing conference connection when the the user elects to convert the diff --git a/telecomm/java/android/telecomm/RemoteConnectionManager.java b/telecomm/java/android/telecomm/RemoteConnectionManager.java index 4201f23e42901..465fae0fc82ce 100644 --- a/telecomm/java/android/telecomm/RemoteConnectionManager.java +++ b/telecomm/java/android/telecomm/RemoteConnectionManager.java @@ -57,7 +57,7 @@ public class RemoteConnectionManager { public void createOutgoingConnection( ConnectionRequest request, - final SimpleResponse response) { + final ConnectionService.OutgoingCallResponse response) { Subscription subscription = request.getSubscription(); if (subscription == null) { throw new IllegalArgumentException("subscription must be specified."); diff --git a/telecomm/java/android/telecomm/RemoteConnectionService.java b/telecomm/java/android/telecomm/RemoteConnectionService.java index 86a43cb90f39c..7658a76d56d34 100644 --- a/telecomm/java/android/telecomm/RemoteConnectionService.java +++ b/telecomm/java/android/telecomm/RemoteConnectionService.java @@ -43,7 +43,7 @@ public class RemoteConnectionService implements DeathRecipient { private String mConnectionId; private ConnectionRequest mPendingRequest; - private SimpleResponse mPendingResponse; + private ConnectionService.OutgoingCallResponse mPendingOutgoingCallResponse; // Remote connection services only support a single connection. private RemoteConnection mConnection; @@ -60,7 +60,7 @@ public class RemoteConnectionService implements DeathRecipient { public void handleSuccessfulOutgoingCall(String connectionId) { if (isPendingConnection(connectionId)) { mConnection = new RemoteConnection(mCallService, connectionId); - mPendingResponse.onResult(mPendingRequest, mConnection); + mPendingOutgoingCallResponse.onSuccess(mPendingRequest, mConnection); clearPendingInformation(); } } @@ -72,7 +72,17 @@ public class RemoteConnectionService implements DeathRecipient { if (isPendingConnection(request.getCallId())) { // Use mPendingRequest instead of request so that we use the same object that was // passed in to us. - mPendingResponse.onError(request); + mPendingOutgoingCallResponse.onFailure(mPendingRequest, errorCode, errorMessage); + mConnectionId = null; + clearPendingInformation(); + } + } + + /** ${inheritDoc} */ + @Override + public void cancelOutgoingCall(String connectionId) { + if (isPendingConnection(connectionId)) { + mPendingOutgoingCallResponse.onCancel(mPendingRequest); mConnectionId = null; clearPendingInformation(); } @@ -208,7 +218,7 @@ public class RemoteConnectionService implements DeathRecipient { */ public void createOutgoingConnection( ConnectionRequest request, - SimpleResponse response) { + ConnectionService.OutgoingCallResponse response) { if (mConnectionId == null) { String id = UUID.randomUUID().toString(); @@ -216,13 +226,13 @@ public class RemoteConnectionService implements DeathRecipient { try { mCallService.call(callInfo); mConnectionId = id; - mPendingResponse = response; + mPendingOutgoingCallResponse = response; mPendingRequest = request; } catch (RemoteException e) { - response.onError(request); + response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, e.toString()); } } else { - response.onError(request); + response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED, null); } } @@ -254,7 +264,7 @@ public class RemoteConnectionService implements DeathRecipient { } private boolean isPendingConnection(String id) { - return TextUtils.equals(mConnectionId, id) && mPendingResponse != null; + return TextUtils.equals(mConnectionId, id) && mPendingOutgoingCallResponse != null; } private boolean isCurrentConnection(String id) { @@ -263,7 +273,7 @@ public class RemoteConnectionService implements DeathRecipient { private void clearPendingInformation() { mPendingRequest = null; - mPendingResponse = null; + mPendingOutgoingCallResponse = null; } private void destroyConnection() { diff --git a/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl b/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl index 87c8859cb24a4..373fb160ebd76 100644 --- a/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl +++ b/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl @@ -35,6 +35,8 @@ oneway interface ICallServiceAdapter { void handleFailedOutgoingCall(in ConnectionRequest request, int errorCode, String errorMessage); + void cancelOutgoingCall(String callId); + void setActive(String callId); void setRinging(String callId);