Add lifecycle methods to telecomm services
Have the base classes track the adapters and provide an override-able hook (onAdapterAttached()) to notify when the adapter is set. Change-Id: I58ca5c6970328861327699ec497fa21288bce7df
This commit is contained in:
@@ -70,7 +70,8 @@ public abstract class CallService extends Service {
|
||||
case MSG_SET_CALL_SERVICE_ADAPTER:
|
||||
CallServiceAdapter adapter =
|
||||
new CallServiceAdapter((ICallServiceAdapter) msg.obj);
|
||||
setCallServiceAdapter(adapter);
|
||||
mAdapter = adapter;
|
||||
onAdapterAttached(adapter);
|
||||
break;
|
||||
case MSG_IS_COMPATIBLE_WITH:
|
||||
isCompatibleWith((CallInfo) msg.obj);
|
||||
@@ -218,6 +219,8 @@ public abstract class CallService extends Service {
|
||||
*/
|
||||
private final CallServiceBinder mBinder = new CallServiceBinder();
|
||||
|
||||
private CallServiceAdapter mAdapter = null;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final IBinder onBind(Intent intent) {
|
||||
@@ -232,12 +235,20 @@ public abstract class CallService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an implementation of CallServiceAdapter for adding new calls and communicating state
|
||||
* changes of existing calls.
|
||||
*
|
||||
* @param callServiceAdapter Adapter object for communicating call to CallsManager
|
||||
* @return The attached {@link CallServiceAdapter} if the service is bound, null otherwise.
|
||||
*/
|
||||
public abstract void setCallServiceAdapter(CallServiceAdapter callServiceAdapter);
|
||||
protected final CallServiceAdapter getAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lifecycle callback which is called when this {@link CallService} has been attached to a
|
||||
* {@link CallServiceAdapter}, indicating {@link #getAdapter()} is now safe to use.
|
||||
*
|
||||
* @param adapter The adapter now attached to this call service.
|
||||
*/
|
||||
protected void onAdapterAttached(CallServiceAdapter adapter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the CallService can place the specified call. Response is sent via
|
||||
|
||||
@@ -52,7 +52,8 @@ public abstract class CallServiceSelector extends Service {
|
||||
case MSG_SET_CALL_SERVICE_SELECTOR_ADAPTER:
|
||||
CallServiceSelectorAdapter adapter = new CallServiceSelectorAdapter(
|
||||
(ICallServiceSelectorAdapter) msg.obj);
|
||||
setCallServiceSelectorAdapter(adapter);
|
||||
mAdapter = adapter;
|
||||
onAdapterAttached(adapter);
|
||||
break;
|
||||
case MSG_SELECT:
|
||||
SomeArgs args = (SomeArgs) msg.obj;
|
||||
@@ -95,6 +96,8 @@ public abstract class CallServiceSelector extends Service {
|
||||
|
||||
private final CallServiceSelectorBinder mBinder;
|
||||
|
||||
private CallServiceSelectorAdapter mAdapter = null;
|
||||
|
||||
protected CallServiceSelector() {
|
||||
mBinder = new CallServiceSelectorBinder();
|
||||
}
|
||||
@@ -112,11 +115,20 @@ public abstract class CallServiceSelector extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an adapter that allows the selector to communicate with Telecomm.
|
||||
*
|
||||
* @param adapter Adapter object for communicating with Telecomm.
|
||||
* @return The attached {@link CallServiceSelectorAdapter} if attached, or null otherwise.
|
||||
*/
|
||||
protected abstract void setCallServiceSelectorAdapter(CallServiceSelectorAdapter adapter);
|
||||
protected final CallServiceSelectorAdapter getAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lifecycle callback which is called when this {@link CallServiceSelector} has been attached
|
||||
* to a {@link CallServiceSelectorAdapter}, indicating {@link #getAdapter()} is now safe to use.
|
||||
*
|
||||
* @param adapter The adapter now attached to this call service selector.
|
||||
*/
|
||||
protected void onAdapterAttached(CallServiceSelectorAdapter adapter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a list of {@link CallServiceDescriptor}s, order them into a prioritized list and return
|
||||
|
||||
@@ -55,7 +55,8 @@ public abstract class InCallService extends Service {
|
||||
switch (msg.what) {
|
||||
case MSG_SET_IN_CALL_ADAPTER:
|
||||
InCallAdapter adapter = new InCallAdapter((IInCallAdapter) msg.obj);
|
||||
setInCallAdapter(adapter);
|
||||
mAdapter = adapter;
|
||||
onAdapterAttached(adapter);
|
||||
break;
|
||||
case MSG_ADD_CALL:
|
||||
addCall((CallInfo) msg.obj);
|
||||
@@ -182,6 +183,8 @@ public abstract class InCallService extends Service {
|
||||
|
||||
private final InCallServiceBinder mBinder;
|
||||
|
||||
private InCallAdapter mAdapter;
|
||||
|
||||
protected InCallService() {
|
||||
mBinder = new InCallServiceBinder();
|
||||
}
|
||||
@@ -192,13 +195,20 @@ public abstract class InCallService extends Service {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the in-call app an adapter object through which to send call-commands such as
|
||||
* answering and rejecting incoming calls, disconnecting active calls, and putting calls in
|
||||
* special states (mute, hold, etc).
|
||||
*
|
||||
* @param inCallAdapter Adapter through which an in-call app can send call-commands to Telecomm.
|
||||
* @return The attached {@link CallServiceSelectorAdapter} if attached, or null otherwise.
|
||||
*/
|
||||
protected abstract void setInCallAdapter(InCallAdapter inCallAdapter);
|
||||
protected final InCallAdapter getAdapter() {
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lifecycle callback which is called when this {@link InCallService} has been attached
|
||||
* to a {@link InCallAdapter}, indicating {@link #getAdapter()} is now safe to use.
|
||||
*
|
||||
* @param adapter The adapter now attached to this in-call service.
|
||||
*/
|
||||
protected void onAdapterAttached(InCallAdapter adapter) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates to the in-call app that a new call has been created and an appropriate
|
||||
|
||||
Reference in New Issue
Block a user