From 9efdcd8a31e497e5de092b600be316edc4a7ddf1 Mon Sep 17 00:00:00 2001 From: Ihab Awad Date: Wed, 28 May 2014 16:46:42 -0700 Subject: [PATCH] Allow ConnectionService to ask Telecomm for ringback Cherry picked from branch lmp-preview-dev because checking the changes into master required an API update, whereas the relevant APIs are @hide-ed in the source branch. Provides a pass-through from the ConnectionService API to Telecomm allowing a ConnectionService to either play the ringbacks on its own, or ask Telecomm to play the ringbacks on its behalf. Bug: 15190301 Change-Id: Ib0f2ce9bf798ec0df0e6d33559174c82de059a94 (cherry picked from commit 20536bc3c4d40fa96306b0319d8313a7437fc702) --- api/current.txt | 6 +++ .../android/telecomm/CallServiceAdapter.java | 12 +++++ .../java/android/telecomm/Connection.java | 52 +++++++++++++++++-- .../android/telecomm/ConnectionService.java | 7 +++ .../telecomm/ICallServiceAdapter.aidl | 2 + 5 files changed, 74 insertions(+), 5 deletions(-) diff --git a/api/current.txt b/api/current.txt index fb1259ff8066f..0c3702e94d403 100644 --- a/api/current.txt +++ b/api/current.txt @@ -27542,6 +27542,7 @@ package android.telecomm { method public void setDisconnected(java.lang.String, int, java.lang.String); method public void setIsCompatibleWith(java.lang.String, boolean); method public void setOnHold(java.lang.String); + method public void setRequestingRingback(java.lang.String, boolean); method public void setRinging(java.lang.String); } @@ -27607,6 +27608,7 @@ package android.telecomm { ctor protected Connection(); method public final android.telecomm.CallAudioState getCallAudioState(); method public final android.net.Uri getHandle(); + method public boolean isRequestingRingback(); method protected void onAbort(); method protected void onAnswer(); method protected void onDisconnect(); @@ -27615,6 +27617,7 @@ package android.telecomm { method protected void onReject(); method protected void onSetAudioState(android.telecomm.CallAudioState); method protected void onSetSignal(android.os.Bundle); + method protected void onSetState(int); method protected void onStopDtmfTone(); method protected void onUnhold(); method protected void setActive(); @@ -27623,6 +27626,7 @@ package android.telecomm { method protected void setDisconnected(int, java.lang.String); method protected void setHandle(android.net.Uri); method protected void setOnHold(); + method protected void setRequestingRingback(boolean); method protected void setRinging(); method public static java.lang.String stateToString(int); } @@ -27632,6 +27636,7 @@ package android.telecomm { method public abstract void onDestroyed(android.telecomm.Connection); method public abstract void onDisconnected(android.telecomm.Connection, int, java.lang.String); method public abstract void onHandleChanged(android.telecomm.Connection, android.net.Uri); + method public abstract void onRequestingRingback(android.telecomm.Connection, boolean); method public abstract void onSignalChanged(android.telecomm.Connection, android.os.Bundle); method public abstract void onStateChanged(android.telecomm.Connection, int); } @@ -27642,6 +27647,7 @@ package android.telecomm { method public void onDestroyed(android.telecomm.Connection); method public void onDisconnected(android.telecomm.Connection, int, java.lang.String); method public void onHandleChanged(android.telecomm.Connection, android.net.Uri); + method public void onRequestingRingback(android.telecomm.Connection, boolean); method public void onSignalChanged(android.telecomm.Connection, android.os.Bundle); method public void onStateChanged(android.telecomm.Connection, int); } diff --git a/telecomm/java/android/telecomm/CallServiceAdapter.java b/telecomm/java/android/telecomm/CallServiceAdapter.java index d5bb9893dbef8..dafc3104edb30 100644 --- a/telecomm/java/android/telecomm/CallServiceAdapter.java +++ b/telecomm/java/android/telecomm/CallServiceAdapter.java @@ -156,5 +156,17 @@ public final class CallServiceAdapter { } } + /** + * Asks Telecomm to start or stop a ringback tone for a call. + * + * @param callId The unique ID of the call whose ringback is being changed. + * @param ringback Whether Telecomm should start playing a ringback tone. + */ + public void setRequestingRingback(String callId, boolean ringback) { + try { + mAdapter.setRequestingRingback(callId, ringback); + } catch (RemoteException e) { + } + } } diff --git a/telecomm/java/android/telecomm/Connection.java b/telecomm/java/android/telecomm/Connection.java index 88de17af787e1..8cce8e62c1aa7 100644 --- a/telecomm/java/android/telecomm/Connection.java +++ b/telecomm/java/android/telecomm/Connection.java @@ -33,6 +33,7 @@ public abstract class Connection { void onHandleChanged(Connection c, Uri newHandle); void onSignalChanged(Connection c, Bundle details); void onDisconnected(Connection c, int cause, String message); + void onRequestingRingback(Connection c, boolean ringback); void onDestroyed(Connection c); } @@ -60,6 +61,10 @@ public abstract class Connection { /** {@inheritDoc} */ @Override public void onDestroyed(Connection c) {} + + /** {@inheritDoc} */ + @Override + public void onRequestingRingback(Connection c, boolean ringback) {} } public final class State { @@ -77,6 +82,7 @@ public abstract class Connection { private int mState = State.NEW; private CallAudioState mCallAudioState; private Uri mHandle; + private boolean mRequestingRingback = false; /** * Create a new Connection. @@ -267,6 +273,14 @@ public abstract class Connection { } } + /** + * @return Whether this connection is requesting that the system play a ringback tone + * on its behalf. + */ + public boolean isRequestingRingback() { + return mRequestingRingback; + } + /** * Sets the value of the {@link #getHandle()} property and notifies listeners. * @@ -286,6 +300,7 @@ public abstract class Connection { * communicate). */ protected void setActive() { + setRequestingRingback(false); setState(State.ACTIVE); } @@ -328,6 +343,21 @@ public abstract class Connection { } } + /** + * Requests that the framework play a ringback tone. This is to be invoked by implementations + * that do not play a ringback tone themselves in the call's audio stream. + * + * @param ringback Whether the ringback tone is to be played. + */ + protected void setRequestingRingback(boolean ringback) { + if (mRequestingRingback != ringback) { + mRequestingRingback = ringback; + for (Listener l : mListeners) { + l.onRequestingRingback(this, ringback); + } + } + } + /** * Notifies this Connection and listeners that the {@link #getCallAudioState()} property * has a new value. @@ -336,7 +366,7 @@ public abstract class Connection { */ protected void onSetAudioState(CallAudioState state) { // TODO: Enforce super called - this.mCallAudioState = state; + mCallAudioState = state; for (Listener l : mListeners) { l.onAudioStateChanged(this, state); } @@ -355,6 +385,21 @@ public abstract class Connection { } } + /** + * Notifies this Connection of an internal state change. This method is called before the + * state is actually changed. Overriding implementations must call + * {@code super.onSetState(state)}. + * + * @param state The new state, a {@link Connection.State} member. + */ + protected void onSetState(int state) { + // TODO: Enforce super called + this.mState = state; + for (Listener l : mListeners) { + l.onStateChanged(this, state); + } + } + /** * Notifies this Connection of a request to play a DTMF tone. * @@ -401,9 +446,6 @@ public abstract class Connection { private void setState(int state) { Log.d(this, "setState: %s", stateToString(state)); - this.mState = state; - for (Listener l : mListeners) { - l.onStateChanged(this, state); - } + onSetState(state); } } diff --git a/telecomm/java/android/telecomm/ConnectionService.java b/telecomm/java/android/telecomm/ConnectionService.java index 492b08ec93d97..8d02842dc5a6d 100644 --- a/telecomm/java/android/telecomm/ConnectionService.java +++ b/telecomm/java/android/telecomm/ConnectionService.java @@ -89,6 +89,13 @@ public abstract class ConnectionService extends CallService { public void onDestroyed(Connection c) { removeConnection(c); } + + @Override + public void onRequestingRingback(Connection c, boolean ringback) { + String id = mIdByConnection.get(c); + Log.d(this, "Adapter onRingback %b", ringback); + getAdapter().setRequestingRingback(id, ringback); + } }; @Override diff --git a/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl b/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl index dfdaa75a3686f..6d36494e498dc 100644 --- a/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl +++ b/telecomm/java/com/android/internal/telecomm/ICallServiceAdapter.aidl @@ -43,4 +43,6 @@ oneway interface ICallServiceAdapter { void setDisconnected(String callId, int disconnectCause, String disconnectMessage); void setOnHold(String callId); + + void setRequestingRingback(String callId, boolean ringing); }