diff options
Diffstat (limited to 'InCallUI')
4 files changed, 73 insertions, 20 deletions
diff --git a/InCallUI/src/com/android/incallui/CallButtonPresenter.java b/InCallUI/src/com/android/incallui/CallButtonPresenter.java index dc5eda1c3..0b5b0f4ca 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. @@ -189,6 +191,28 @@ public class CallButtonPresenter extends Presenter<CallButtonPresenter.CallButto setAudioMode(newMode); } + public void endCallClicked() { + if (mCall == null) { + return; + } + + CallCommandClient.getInstance().disconnectCall(mCall.getCallId()); + + // Notify Telecomm that the user hit end-call. + IInCallAdapter telecommAdapter = InCallPresenter.getInstance().getTelecommAdapter(); + if (telecommAdapter != null) { + String callId = CallInfoTranslator.getTelecommCallId(mCall); + if (callId != null) { + try { + Log.i(this, "Disconnecting the call: " + callId); + telecommAdapter.disconnectCall(callId); + } catch (RemoteException e) { + Log.e(this, "Failed to send disconnect command.", e); + } + } + } + } + public void manageConferenceButtonClicked() { getUi().displayManageConferencePanel(true); } diff --git a/InCallUI/src/com/android/incallui/CallInfoTranslator.java b/InCallUI/src/com/android/incallui/CallInfoTranslator.java index be68c0237..ba44c450b 100644 --- a/InCallUI/src/com/android/incallui/CallInfoTranslator.java +++ b/InCallUI/src/com/android/incallui/CallInfoTranslator.java @@ -21,7 +21,8 @@ import android.telecomm.CallInfo; import com.android.services.telephony.common.Call; import com.google.common.base.Preconditions; import com.google.common.base.Strings; -import com.google.common.collect.Maps; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; import java.util.Map; @@ -29,17 +30,17 @@ import java.util.Map; * Translates {@link CallInfo} objects into {@link Call} objects so that call-infos received from * Telecomm can be used easily with {@link CallList}. Manages Telecomm call ID to {@link Call} * mappings. This class uses IDs for both {@link Call} objects and {@link CallInfo} objects which - * are both normally referred to as "call id". To distinguish the two, the code and comments refer + * are both normally referred to as "call ID". To distinguish the two, the code and comments refer * to them as "call ID" and "Telecomm call ID" respectively. * TODO(santoscordon): This class is a temporary solution until all calls are coming in through * Telecomm at which point we can rewrite the standard Call object format. */ final class CallInfoTranslator { /** - * Maps String-based Telecomm call IDs to call objects. Entries are added with calls to + * Maps String-based Telecomm call IDs to call objects and back. Entries are added with calls to * {@link #getCall} and removed with explicit calls to {@link #removeCall}. */ - private static final Map<String, Call> sCallsById = Maps.newHashMap(); + private static final BiMap<String, Call> 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 5e20cea2c..bc7c41a2c 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -57,7 +57,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 @@ -560,10 +560,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(); + } } |