From b632e5b122d82333c390cc334ab17100bc2af7a2 Mon Sep 17 00:00:00 2001 From: Sailesh Nepal Date: Thu, 3 Apr 2014 12:54:33 -0700 Subject: Handoff: Add APIs to allow handoff between call services This CL adds: - CallInfo.mExtra and CallInfo.mCurrentCallServiceDescriptor. These can be used by the selector to perform handoff. - InCallService.setHandoffEnabled to enform the in-call UI that handoff is allowed. - InCallAdapater.handoffCall to initiate handoff. Bug: 13643568 Change-Id: I94c28b10c0e0a253450f14d31ecdc416d5b44ca4 --- telecomm/java/android/telecomm/CallInfo.java | 43 ++++++++++++++++++++-- .../java/android/telecomm/CallServiceSelector.java | 22 +++++++++++ telecomm/java/android/telecomm/InCallAdapter.java | 12 ++++++ telecomm/java/android/telecomm/InCallService.java | 19 ++++++++++ .../internal/telecomm/ICallServiceSelector.aidl | 4 ++ .../android/internal/telecomm/IInCallAdapter.aidl | 2 + .../android/internal/telecomm/IInCallService.aidl | 2 + 7 files changed, 101 insertions(+), 3 deletions(-) (limited to 'telecomm') diff --git a/telecomm/java/android/telecomm/CallInfo.java b/telecomm/java/android/telecomm/CallInfo.java index bb08c2a..b0a7a99 100644 --- a/telecomm/java/android/telecomm/CallInfo.java +++ b/telecomm/java/android/telecomm/CallInfo.java @@ -17,6 +17,7 @@ package android.telecomm; import android.net.Uri; +import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; @@ -51,6 +52,15 @@ public final class CallInfo implements Parcelable { */ private final GatewayInfo mGatewayInfo; + /** + * Additional information that can be persisted. For example, extra handoff information can + * attached to a call using {@link CallServiceSelectorAdapter#setHandoffInfo(String,Uri,Bundle). + */ + private final Bundle mExtras; + + /** The descriptor for the call service currently routing this call. */ + private final CallServiceDescriptor mCurrentCallServiceDescriptor; + // There are 4 timestamps that are important to a call: // 1) Created timestamp - The time at which the user explicitly chose to make the call. // 2) Connected timestamp - The time at which a call service confirms that it has connected @@ -64,7 +74,7 @@ public final class CallInfo implements Parcelable { // 4) Disconnected timestamp - The time at which the call was disconnected. public CallInfo(String id, CallState state, Uri handle) { - this(id, state, handle, null); + this(id, state, handle, null, Bundle.EMPTY, null); } /** @@ -74,14 +84,25 @@ public final class CallInfo implements Parcelable { * @param state The state of the call. * @param handle The handle to the other party in this call. * @param gatewayInfo Gateway information pertaining to this call. + * @param extras Additional information that can be persisted. + * @param currentCallServiceDescriptor The descriptor for the call service currently routing + * this call. * * @hide */ - public CallInfo(String id, CallState state, Uri handle, GatewayInfo gatewayInfo) { + public CallInfo( + String id, + CallState state, + Uri handle, + GatewayInfo gatewayInfo, + Bundle extras, + CallServiceDescriptor currentCallServiceDescriptor) { mId = id; mState = state; mHandle = handle; mGatewayInfo = gatewayInfo; + mExtras = extras; + mCurrentCallServiceDescriptor = currentCallServiceDescriptor; } public String getId() { @@ -112,6 +133,14 @@ public final class CallInfo implements Parcelable { return mGatewayInfo; } + public Bundle getExtras() { + return mExtras; + } + + public CallServiceDescriptor getCurrentCallServiceDescriptor() { + return mCurrentCallServiceDescriptor; + } + // // Parceling related code below here. // @@ -127,13 +156,17 @@ public final class CallInfo implements Parcelable { String id = source.readString(); CallState state = CallState.valueOf(source.readString()); Uri handle = Uri.CREATOR.createFromParcel(source); + boolean gatewayInfoPresent = source.readByte() != 0; GatewayInfo gatewayInfo = null; if (gatewayInfoPresent) { gatewayInfo = GatewayInfo.CREATOR.createFromParcel(source); } - return new CallInfo(id, state, handle, gatewayInfo); + ClassLoader classLoader = CallInfo.class.getClassLoader(); + Bundle extras = source.readParcelable(classLoader); + CallServiceDescriptor descriptor = source.readParcelable(classLoader); + return new CallInfo(id, state, handle, gatewayInfo, extras, descriptor); } @Override @@ -158,11 +191,15 @@ public final class CallInfo implements Parcelable { destination.writeString(mId); destination.writeString(mState.name()); mHandle.writeToParcel(destination, 0); + if (mGatewayInfo != null) { destination.writeByte((byte) 1); mGatewayInfo.writeToParcel(destination, 0); } else { destination.writeByte((byte) 0); } + + destination.writeParcelable(mExtras, 0); + destination.writeParcelable(mCurrentCallServiceDescriptor, 0); } } diff --git a/telecomm/java/android/telecomm/CallServiceSelector.java b/telecomm/java/android/telecomm/CallServiceSelector.java index 73bcfcd..9e714b4 100644 --- a/telecomm/java/android/telecomm/CallServiceSelector.java +++ b/telecomm/java/android/telecomm/CallServiceSelector.java @@ -28,6 +28,9 @@ import com.android.internal.os.SomeArgs; import com.android.internal.telecomm.ICallServiceSelector; import com.android.internal.telecomm.ICallServiceSelectorAdapter; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; import java.util.List; /** @@ -39,6 +42,8 @@ public abstract class CallServiceSelector extends Service { private static final int MSG_SET_CALL_SERVICE_SELECTOR_ADAPTER = 0; private static final int MSG_SELECT = 1; + private final HashMap mCalls = new HashMap(); + /** Handler to move client-bound method calls to the main thread. */ private final Handler mHandler = new Handler(Looper.getMainLooper()) { @Override @@ -76,6 +81,16 @@ public abstract class CallServiceSelector extends Service { args.arg2 = descriptors; mHandler.obtainMessage(MSG_SELECT, args).sendToTarget(); } + + @Override + public void onCallUpdated(CallInfo callInfo) { + mCalls.put(callInfo.getId(), callInfo); + } + + @Override + public void onCallRemoved(String callId) { + mCalls.remove(callId); + } } private final CallServiceSelectorBinder mBinder; @@ -90,6 +105,13 @@ public abstract class CallServiceSelector extends Service { } /** + * Returns a list of all calls managed by this selector. + */ + protected final Collection getCalls() { + return Collections.unmodifiableCollection(mCalls.values()); + } + + /** * Sets an adapter that allows the selector to communicate with Telecomm. * * @param adapter Adapter object for communicating with Telecomm. diff --git a/telecomm/java/android/telecomm/InCallAdapter.java b/telecomm/java/android/telecomm/InCallAdapter.java index 2933f17..e41d3f6 100644 --- a/telecomm/java/android/telecomm/InCallAdapter.java +++ b/telecomm/java/android/telecomm/InCallAdapter.java @@ -184,4 +184,16 @@ public final class InCallAdapter { } catch (RemoteException e) { } } + + /** + * Instructs Telecomm to handoff the call to another call service. + * + * @param callId The identifier of the call to handoff. + */ + public void handoffCall(String callId) { + try { + mAdapter.handoffCall(callId); + } catch (RemoteException e) { + } + } } diff --git a/telecomm/java/android/telecomm/InCallService.java b/telecomm/java/android/telecomm/InCallService.java index 3942d70..c70f56e 100644 --- a/telecomm/java/android/telecomm/InCallService.java +++ b/telecomm/java/android/telecomm/InCallService.java @@ -46,6 +46,7 @@ public abstract class InCallService extends Service { private static final int MSG_SET_RINGING = 8; private static final int MSG_SET_POST_DIAL = 9; private static final int MSG_SET_POST_DIAL_WAIT = 10; + private static final int MSG_SET_HANDOFF_ENABLED = 11; /** Default Handler used to consolidate binder method calls onto a single thread. */ private final Handler mHandler = new Handler(Looper.getMainLooper()) { @@ -98,6 +99,10 @@ public abstract class InCallService extends Service { break; case MSG_ON_AUDIO_STATE_CHANGED: onAudioStateChanged((CallAudioState) msg.obj); + break; + case MSG_SET_HANDOFF_ENABLED: + setHandoffEnabled((String) msg.obj, msg.arg1 == 1 ? true : false); + break; default: break; } @@ -167,6 +172,12 @@ public abstract class InCallService extends Service { args.arg2 = remaining; mHandler.obtainMessage(MSG_SET_POST_DIAL_WAIT, args).sendToTarget(); } + + @Override + public void setHandoffEnabled(String callId, boolean isHandoffEnabled) { + mHandler.obtainMessage(MSG_SET_HANDOFF_ENABLED, isHandoffEnabled ? 1 : 0, 0, + callId).sendToTarget(); + } } private final InCallServiceBinder mBinder; @@ -277,4 +288,12 @@ public abstract class InCallService extends Service { * @param remaining The remaining postdial string to be dialed. */ protected abstract void setPostDialWait(String callId, String remaining); + + /** + * Called when the call's handoff state has changed. + * + * @param callId The identifier of the call whose handoff state was changed. + * @param isHandoffEnabled True if handoff is enabled. + */ + protected abstract void setHandoffEnabled(String callId, boolean isHandoffEnabled); } diff --git a/telecomm/java/com/android/internal/telecomm/ICallServiceSelector.aidl b/telecomm/java/com/android/internal/telecomm/ICallServiceSelector.aidl index 0dd3855..9597dc1 100644 --- a/telecomm/java/com/android/internal/telecomm/ICallServiceSelector.aidl +++ b/telecomm/java/com/android/internal/telecomm/ICallServiceSelector.aidl @@ -35,4 +35,8 @@ oneway interface ICallServiceSelector { void setCallServiceSelectorAdapter(in ICallServiceSelectorAdapter adapter); void select(in CallInfo callInfo, in List callServiceDescriptors); + + void onCallUpdated(in CallInfo callInfo); + + void onCallRemoved(String callId); } diff --git a/telecomm/java/com/android/internal/telecomm/IInCallAdapter.aidl b/telecomm/java/com/android/internal/telecomm/IInCallAdapter.aidl index e0cdb83..512e898 100644 --- a/telecomm/java/com/android/internal/telecomm/IInCallAdapter.aidl +++ b/telecomm/java/com/android/internal/telecomm/IInCallAdapter.aidl @@ -45,4 +45,6 @@ oneway interface IInCallAdapter { void stopDtmfTone(String callId); void postDialContinue(String callId); + + void handoffCall(String callId); } diff --git a/telecomm/java/com/android/internal/telecomm/IInCallService.aidl b/telecomm/java/com/android/internal/telecomm/IInCallService.aidl index f5847df..4187fa8 100644 --- a/telecomm/java/com/android/internal/telecomm/IInCallService.aidl +++ b/telecomm/java/com/android/internal/telecomm/IInCallService.aidl @@ -48,4 +48,6 @@ oneway interface IInCallService { void setPostDial(String callId, String remaining); void setPostDialWait(String callId, String remaining); + + void setHandoffEnabled(String callId, boolean isHandoffEnabled); } -- cgit v1.1