Update CallServiceSelector API
Move the consumer methods to the main thread and use response objects to return the results back to the caller. Change-Id: Ifc062cf49421079686d925406c823000232fa728
This commit is contained in:
@@ -24188,9 +24188,9 @@ package android.telecomm {
|
||||
method public abstract void call(android.telecomm.CallInfo);
|
||||
method public abstract void confirmIncomingCall(java.lang.String, java.lang.String);
|
||||
method public abstract void disconnect(java.lang.String);
|
||||
method public android.os.IBinder getBinder();
|
||||
method public final android.os.IBinder getBinder();
|
||||
method public abstract void isCompatibleWith(android.telecomm.CallInfo);
|
||||
method public android.os.IBinder onBind(android.content.Intent);
|
||||
method public final android.os.IBinder onBind(android.content.Intent);
|
||||
method public abstract void setCallServiceAdapter(android.telecomm.ICallServiceAdapter);
|
||||
}
|
||||
|
||||
@@ -24220,9 +24220,14 @@ package android.telecomm {
|
||||
|
||||
public abstract class CallServiceSelector extends android.app.Service {
|
||||
ctor protected CallServiceSelector();
|
||||
method protected abstract boolean isSwitchable(android.telecomm.CallInfo);
|
||||
method protected abstract void isSwitchable(android.telecomm.CallInfo, android.telecomm.CallServiceSelector.Response);
|
||||
method public final android.os.IBinder onBind(android.content.Intent);
|
||||
method protected abstract java.util.List<android.telecomm.CallServiceInfo> select(android.telecomm.CallInfo, java.util.List<android.telecomm.CallServiceInfo>);
|
||||
method protected abstract void select(android.telecomm.CallInfo, java.util.List<android.telecomm.CallServiceDescriptor>, android.telecomm.CallServiceSelector.Response);
|
||||
}
|
||||
|
||||
public static abstract interface CallServiceSelector.Response {
|
||||
method public abstract void setSelectedCallServices(java.util.List<android.telecomm.CallServiceDescriptor>);
|
||||
method public abstract void setSwitchable(boolean);
|
||||
}
|
||||
|
||||
public final class CallState extends java.lang.Enum {
|
||||
|
||||
@@ -21,8 +21,6 @@ import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.telecomm.ICallService;
|
||||
import android.telecomm.ICallServiceAdapter;
|
||||
|
||||
import com.android.internal.os.SomeArgs;
|
||||
|
||||
@@ -135,14 +133,14 @@ public abstract class CallService extends Service {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
public final IBinder onBind(Intent intent) {
|
||||
return getBinder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns binder object which can be used across IPC methods.
|
||||
*/
|
||||
public IBinder getBinder() {
|
||||
public final IBinder getBinder() {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,47 +18,146 @@ package android.telecomm;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.os.SomeArgs;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Allows for the organization of {@link CallService}s for outbound calls. Given a call and list of
|
||||
* {@link CallService} IDs, order the list in terms of priority and return it using
|
||||
* {@link #select(CallInfo, List)}. <br />
|
||||
* {@link #select(CallInfo, List, CallServiceSelectionResponse)}. <br />
|
||||
* <br />
|
||||
* Also determine whether a call is switchable (can be moved between {@link CallService}s) or not
|
||||
* using {@link #isSwitchable(CallInfo)}.
|
||||
* using {@link #isSwitchable(CallInfo, CallSwitchabilityResponse)}.
|
||||
*/
|
||||
public abstract class CallServiceSelector extends Service {
|
||||
private static final String TAG = CallServiceSelector.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Used to tell {@link #mHandler} to move the call to
|
||||
* {@link CallServiceSelector#isSwitchable(CallInfo, CallSwitchabilityResponse)} to the main
|
||||
* thread.
|
||||
*/
|
||||
private static final int MSG_IS_SWITCHABLE = 1;
|
||||
|
||||
/**
|
||||
* Used to tell {@link #mHandler} to move the call to
|
||||
* {@link #select(CallInfo, List, CallServiceSelectionResponse)} to the main thread.
|
||||
*/
|
||||
private static final int MSG_SELECT_CALL_SERVICES = 2;
|
||||
|
||||
/**
|
||||
* Listens for responses from the {@link CallServiceSelector} and passes them back through the
|
||||
* Binder interface. This must be called from
|
||||
* {@link CallServiceSelector#isSwitchable(CallInfo, CallSwitchabilityResponse)}.
|
||||
*/
|
||||
public interface CallSwitchabilityResponse {
|
||||
/**
|
||||
* Mark a call as switchable (or not). This must be called by
|
||||
* {@link CallServiceSelector#isSwitchable(CallInfo, CallSwitchabilityResponse)}.
|
||||
*
|
||||
* @param isSwitchable Whether the call was switchable or not.
|
||||
*/
|
||||
void setSwitchable(boolean isSwitchable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for responses from the {@link CallServiceSelector} and passes them back through the
|
||||
* Binder interface. This must be called from
|
||||
* {@link CallServiceSelector#select(CallInfo, List, CallServiceSelectionResponse)}.
|
||||
*/
|
||||
public interface CallServiceSelectionResponse {
|
||||
/**
|
||||
* Sets the prioritized {@link CallServiceDescriptor}s for the given {@link CallInfo}. This
|
||||
* must be called by
|
||||
* {@link CallServiceSelector#select(CallInfo, List, CallServiceSelectionResponse)}.
|
||||
*
|
||||
* @param callServices The prioritized {@link CallServiceDescriptor}s.
|
||||
*/
|
||||
void setSelectedCallServices(List<CallServiceDescriptor> callServices);
|
||||
}
|
||||
|
||||
/** Handler to move client-bound method calls to the main thread. */
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
final SomeArgs args = (SomeArgs) msg.obj;
|
||||
try {
|
||||
switch (msg.what) {
|
||||
case MSG_IS_SWITCHABLE:
|
||||
isSwitchable((CallInfo) args.arg1, (CallSwitchabilityResponse) args.arg2);
|
||||
break;
|
||||
case MSG_SELECT_CALL_SERVICES:
|
||||
select((CallInfo) args.arg1, (List<CallServiceDescriptor>) args.arg2,
|
||||
(CallServiceSelectionResponse) args.arg3);
|
||||
break;
|
||||
}
|
||||
} finally {
|
||||
if (args != null) {
|
||||
args.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** Manages the binder calls so that the implementor does not need to deal it. */
|
||||
private final class CallServiceSelectorBinder extends ICallServiceSelector.Stub {
|
||||
private final class CallServiceSelectorBinder extends ICallServiceSelector.Stub
|
||||
implements CallSwitchabilityResponse, CallServiceSelectionResponse {
|
||||
private ICallSwitchabilityResponse mSwitchabilityResponse;
|
||||
private ICallServiceSelectionResponse mSelectionResponse;
|
||||
|
||||
@Override
|
||||
public void isSwitchable(CallInfo callInfo, ICallSwitchabilityResponse response)
|
||||
throws RemoteException {
|
||||
// Ensure that we're running with the app's normal permission level
|
||||
long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
response.setIsSwitchable(CallServiceSelector.this.isSwitchable(callInfo));
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
}
|
||||
mSwitchabilityResponse = response;
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = callInfo;
|
||||
args.arg2 = this;
|
||||
mHandler.obtainMessage(MSG_IS_SWITCHABLE, args).sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void select(CallInfo callInfo, List<CallServiceDescriptor> descriptors,
|
||||
ICallServiceSelectionResponse response) throws RemoteException {
|
||||
mSelectionResponse = response;
|
||||
SomeArgs args = SomeArgs.obtain();
|
||||
args.arg1 = callInfo;
|
||||
args.arg2 = descriptors;
|
||||
args.arg3 = this;
|
||||
mHandler.obtainMessage(MSG_SELECT_CALL_SERVICES, args).sendToTarget();
|
||||
}
|
||||
|
||||
// Ensure that we're running with the app's normal permission level
|
||||
long ident = Binder.clearCallingIdentity();
|
||||
try {
|
||||
response.setSelectedCallServiceDescriptors(
|
||||
CallServiceSelector.this.select(callInfo, descriptors));
|
||||
} finally {
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
@Override
|
||||
public void setSwitchable(boolean isSwitchable) {
|
||||
if (mSwitchabilityResponse != null) {
|
||||
try {
|
||||
mSwitchabilityResponse.setIsSwitchable(isSwitchable);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Failed to set switchability", e);
|
||||
}
|
||||
} else {
|
||||
Log.wtf(TAG, "Switchability response object not set");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedCallServices(List<CallServiceDescriptor> callServices) {
|
||||
if (mSelectionResponse != null) {
|
||||
try {
|
||||
mSelectionResponse.setSelectedCallServiceDescriptors(callServices);
|
||||
} catch (RemoteException e) {
|
||||
Log.d(TAG, "Failed to set call services", e);
|
||||
}
|
||||
} else {
|
||||
Log.wtf(TAG, "Selector response object not set");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,27 +174,31 @@ public abstract class CallServiceSelector extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines (and returns) whether the given call is switchable. That is, whether the call can
|
||||
* be moved to another {@link CallService} seamlessly.<br />
|
||||
* Determines whether the given call is switchable. That is, whether the call can be moved to
|
||||
* another {@link CallService} seamlessly. Once this is determined, the result is passed to the
|
||||
* given {@link CallSwitchabilityResponse} listener.<br />
|
||||
* <br />
|
||||
* This method is not called on the UI thread and is safe to block.
|
||||
* This method is called on the main thread and is not safe to block.
|
||||
*
|
||||
* @param callInfo The call being potentially switched between {@link CallService}s.
|
||||
* @return Whether the given call is switchable or not.
|
||||
* @param response The {@link CallSwitchabilityResponse} listener to call back with the result.
|
||||
*/
|
||||
protected abstract boolean isSwitchable(CallInfo callInfo);
|
||||
protected abstract void isSwitchable(CallInfo callInfo, CallSwitchabilityResponse response);
|
||||
|
||||
/**
|
||||
* Return a list of prioritized {@link CallService}s which should be used to complete the given
|
||||
* call.<br />
|
||||
* Given a list of {@link CallServiceDescriptor}s, order them into a prioritized list and return
|
||||
* them through the given {@link CallServiceSelectionResponse} listener.<br />
|
||||
* <br />
|
||||
* This method is not called on the UI thread and is safe to block.
|
||||
* This method is called on the UI thread and is not safe to block.
|
||||
*
|
||||
* @param callInfo The call being placed using the {@link CallService}s.
|
||||
* @param descriptors The descriptors of the available {@link CallService}s with which to place
|
||||
* the call.
|
||||
* @return A list of prioritized call-service descriptors to use to complete the given call.
|
||||
* the call.
|
||||
* @param response The {@link CallServiceSelectionResponse} listener to call back with the
|
||||
* result.
|
||||
*/
|
||||
protected abstract List<CallServiceDescriptor> select(
|
||||
CallInfo callInfo, List<CallServiceDescriptor> descriptors);
|
||||
protected abstract void select(
|
||||
CallInfo callInfo,
|
||||
List<CallServiceDescriptor> descriptors,
|
||||
CallServiceSelectionResponse response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user