From dd81d5dcff06d1ea940051fd535adeecae63a746 Mon Sep 17 00:00:00 2001 From: Santos Cordon Date: Thu, 30 Jan 2014 05:51:06 -0800 Subject: OutgoingCalls(4/6) - Connecting the in-call disconnect button with Telecomm. In-call app now sends appropriate disconnect command when user clicks the end-call button. Change-Id: I3da99827ce068566ca9e72d69c0375f0409a8014 --- .../com/android/incallui/CallButtonPresenter.java | 16 ++++++++++ .../com/android/incallui/CallInfoTranslator.java | 36 +++++++++++++--------- .../src/com/android/incallui/InCallPresenter.java | 12 +++++--- .../src/com/android/incallui/InCallService.java | 21 +++++++++++-- 4 files changed, 65 insertions(+), 20 deletions(-) (limited to 'InCallUI') diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java index 104da6d94..3f3e0fad3 100644 --- a/InCallUI/src/com/android/incallui/CallButtonPresenter.java +++ b/InCallUI/src/com/android/incallui/CallButtonPresenter.java @@ -32,6 +32,8 @@ import com.android.services.telephony.common.Call; import com.android.services.telephony.common.Call.Capabilities; import android.app.Fragment; +import android.os.RemoteException; +import android.telecomm.IInCallAdapter; /** * Logic for call buttons. @@ -195,6 +197,20 @@ public class CallButtonPresenter extends Presenter sCallsById = Maps.newHashMap(); + private static final BiMap sCallsByTelecommId = HashBiMap.create(); /** * Stores the next available ID usable by Call objects. IDs start at 100000 and increase by one @@ -58,9 +59,11 @@ final class CallInfoTranslator { * @param callInfo The call-info object from which to create a Call. */ static Call getCall(CallInfo callInfo) { - Call call = getCall(callInfo.getId()); + String telecommCallId = callInfo.getId(); + Call call = getCall(telecommCallId); if (call == null) { call = new Call(sNextAvailableCallId++); + sCallsByTelecommId.put(telecommCallId, call); } // TODO(santoscordon): Remove assumption that all calls are dialing by default once @@ -72,20 +75,25 @@ final class CallInfoTranslator { } /** - * Returns the call which maps from the specified Telecomm call ID. If no call was previously - * associated with the specified ID then return null. + * Returns the call which maps from the specified Telecomm call ID. * * @param telecommCallId The Telecomm call ID to map. - * @return The call associated with the specified Telecomm call ID. + * @return The call associated with the specified Telecomm call ID, or null if no association + * exists. */ static Call getCall(String telecommCallId) { Preconditions.checkState(!Strings.isNullOrEmpty(telecommCallId)); + return sCallsByTelecommId.get(telecommCallId); + } - if (sCallsById.containsKey(telecommCallId)) { - return sCallsById.get(telecommCallId); - } - - return null; + /** + * Returns the Telecomm call ID for the given call object. + * + * @param call The call object associated with the Telecomm call ID. + * @return The telecomm call ID or null if it cannot be found. + */ + static String getTelecommCallId(Call call) { + return sCallsByTelecommId.inverse().get(call); } /** @@ -94,6 +102,6 @@ final class CallInfoTranslator { * @param telecommCallId The Telecomm call ID to remove. */ static void removeCall(String telecommCallId) { - sCallsById.remove(telecommCallId); + sCallsByTelecommId.remove(telecommCallId); } } diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 98393cf90..16d22ed14 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -58,7 +58,7 @@ public class InCallPresenter implements CallList.Listener { private boolean mServiceConnected = false; /** Used to send call-related commands and updates back to Telecomm. */ - private IInCallAdapter mInCallAdapter; + private IInCallAdapter mTelecommAdapter; /** * Is true when the activity has been previously started. Some code needs to know not just if @@ -528,10 +528,14 @@ public class InCallPresenter implements CallList.Listener { /** * Persists the current instance of IInCallAdapter. * - * @param inCallAdapter The adapter to Telecomm system used to send call-related commands. + * @param telecommAdapter The adapter to the Telecomm system used to send call-related commands. */ - void setInCallAdapter(IInCallAdapter inCallAdapter) { - mInCallAdapter = inCallAdapter; + void setTelecommAdapter(IInCallAdapter telecommAdapter) { + mTelecommAdapter = telecommAdapter; + } + + IInCallAdapter getTelecommAdapter() { + return mTelecommAdapter; } /** diff --git a/InCallUI/src/com/android/incallui/InCallService.java b/InCallUI/src/com/android/incallui/InCallService.java index 5a975b075..113072d61 100644 --- a/InCallUI/src/com/android/incallui/InCallService.java +++ b/InCallUI/src/com/android/incallui/InCallService.java @@ -41,11 +41,14 @@ public class InCallService extends Service { * {@link CallList} which in turn will trigger UI activity. */ private class InCallServiceBinder extends IInCallService.Stub { - /** {@inheritDoc} */ + /** + * TODO(santoscordon): Rename this to setTelecommAdapter. + * {@inheritDoc} + */ @Override public void setInCallAdapter(final IInCallAdapter inCallAdapter) { mHandler.post(new Runnable() { @Override public void run() { - InCallPresenter.getInstance().setInCallAdapter(inCallAdapter); + InCallPresenter.getInstance().setTelecommAdapter(inCallAdapter); } }); } @@ -100,4 +103,18 @@ public class InCallService extends Service { @Override public IBinder onBind(Intent intent) { return mBinder; } + + /** {@inheritDoc} */ + @Override public void onCreate() { + InCallPresenter inCallPresenter = InCallPresenter.getInstance(); + inCallPresenter.setUp( + getApplicationContext(), CallList.getInstance(), AudioModeProvider.getInstance()); + } + + /** {@inheritDoc} */ + @Override public void onDestroy() { + // Tear down the InCall system + CallList.getInstance().clearOnDisconnect(); + InCallPresenter.getInstance().tearDown(); + } } -- cgit v1.2.3