diff options
author | Evan Charlton <evanc@google.com> | 2014-04-03 08:36:38 -0700 |
---|---|---|
committer | Evan Charlton <evanc@google.com> | 2014-04-04 09:26:01 -0700 |
commit | 924748fa3fc663c780c3fb21ec1332bd9757fcd2 (patch) | |
tree | 30ece111c1b629a57e26365aa1db4b0f3197dd57 /telecomm | |
parent | 0e2b79e67f495110a8b0defc61299a49eb80045e (diff) | |
download | frameworks_base-924748fa3fc663c780c3fb21ec1332bd9757fcd2.zip frameworks_base-924748fa3fc663c780c3fb21ec1332bd9757fcd2.tar.gz frameworks_base-924748fa3fc663c780c3fb21ec1332bd9757fcd2.tar.bz2 |
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
Diffstat (limited to 'telecomm')
-rw-r--r-- | telecomm/java/android/telecomm/CallService.java | 21 | ||||
-rw-r--r-- | telecomm/java/android/telecomm/CallServiceSelector.java | 20 | ||||
-rw-r--r-- | telecomm/java/android/telecomm/InCallService.java | 22 |
3 files changed, 48 insertions, 15 deletions
diff --git a/telecomm/java/android/telecomm/CallService.java b/telecomm/java/android/telecomm/CallService.java index c34395b..142c37e 100644 --- a/telecomm/java/android/telecomm/CallService.java +++ b/telecomm/java/android/telecomm/CallService.java @@ -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. + * @return The attached {@link CallServiceAdapter} if the service is bound, null otherwise. + */ + 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 callServiceAdapter Adapter object for communicating call to CallsManager + * @param adapter The adapter now attached to this call service. */ - public abstract void setCallServiceAdapter(CallServiceAdapter callServiceAdapter); + protected void onAdapterAttached(CallServiceAdapter adapter) { + } /** * Determines if the CallService can place the specified call. Response is sent via diff --git a/telecomm/java/android/telecomm/CallServiceSelector.java b/telecomm/java/android/telecomm/CallServiceSelector.java index 9e714b4..a2ff617 100644 --- a/telecomm/java/android/telecomm/CallServiceSelector.java +++ b/telecomm/java/android/telecomm/CallServiceSelector.java @@ -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. + * @return The attached {@link CallServiceSelectorAdapter} if attached, or null otherwise. + */ + 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 Adapter object for communicating with Telecomm. + * @param adapter The adapter now attached to this call service selector. */ - protected abstract void setCallServiceSelectorAdapter(CallServiceSelectorAdapter adapter); + protected void onAdapterAttached(CallServiceSelectorAdapter adapter) { + } /** * Given a list of {@link CallServiceDescriptor}s, order them into a prioritized list and return diff --git a/telecomm/java/android/telecomm/InCallService.java b/telecomm/java/android/telecomm/InCallService.java index c70f56e..14c6f28 100644 --- a/telecomm/java/android/telecomm/InCallService.java +++ b/telecomm/java/android/telecomm/InCallService.java @@ -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). + * @return The attached {@link CallServiceSelectorAdapter} if attached, or null otherwise. + */ + 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 inCallAdapter Adapter through which an in-call app can send call-commands to Telecomm. + * @param adapter The adapter now attached to this in-call service. */ - protected abstract void setInCallAdapter(InCallAdapter inCallAdapter); + protected void onAdapterAttached(InCallAdapter adapter) { + } /** * Indicates to the in-call app that a new call has been created and an appropriate |