diff options
author | Santos Cordon <santoscordon@google.com> | 2014-01-29 11:07:46 -0800 |
---|---|---|
committer | Baligh Uddin <baligh@google.com> | 2014-02-20 15:06:46 -0800 |
commit | c07366f82b7a38f48f1f17c3f7b9b274e4d36b34 (patch) | |
tree | 793e3fd8722094309596592c7a8bd46f573e9b9d | |
parent | 69af6b351d0231968b885494fd8e1e8b814bbb43 (diff) |
Add implementation of InCallService.
Adds a rudimentary implementation of IInCallService which supports
updating the UI with new outgoing calls and changing a call to active or
disconnected. The new service takes updates from Telecomm in the form of
CallInfo object or callInfo IDs and turns them into Call objects which
work with the existing CallList.
This CL does not have the changes to send commands back to Telecomm.
Change-Id: I985de1d7e0c7fbcbf242ce3f7a831335790d05b5
-rw-r--r-- | InCallUI/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/CallInfoTranslator.java | 99 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallPresenter.java | 13 | ||||
-rw-r--r-- | InCallUI/src/com/android/incallui/InCallService.java | 103 |
4 files changed, 221 insertions, 0 deletions
diff --git a/InCallUI/AndroidManifest.xml b/InCallUI/AndroidManifest.xml index 56cd5e868..efab0331a 100644 --- a/InCallUI/AndroidManifest.xml +++ b/InCallUI/AndroidManifest.xml @@ -50,6 +50,12 @@ </intent-filter> </service> + <service android:name="InCallService"> + <intent-filter> + <action android:name="android.telecomm.IInCallService" /> + </intent-filter> + </service> + <!-- BroadcastReceiver for receiving Intents from Notification mechanism. --> <receiver android:name="InCallApp$NotificationBroadcastReceiver" android:exported="false"> <intent-filter> diff --git a/InCallUI/src/com/android/incallui/CallInfoTranslator.java b/InCallUI/src/com/android/incallui/CallInfoTranslator.java new file mode 100644 index 000000000..be68c0237 --- /dev/null +++ b/InCallUI/src/com/android/incallui/CallInfoTranslator.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui; + +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 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 + * 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 + * {@link #getCall} and removed with explicit calls to {@link #removeCall}. + */ + private static final Map<String, Call> sCallsById = Maps.newHashMap(); + + /** + * Stores the next available ID usable by Call objects. IDs start at 100000 and increase by one + * with each use. 100000 is used so as not to conflict with traditional call IDs which start + * at 1. Non-conflict theory based on the notion that a user is highly unlikely to receive + * 100000 more traditional phone calls than those of type CallInfo (from Telecom). + * TODO(santoscordon): Remove this once Telecomm is the only source of phone calls. + */ + private static int sNextAvailableCallId = 100000; + + /** + * Performs the translation from a {@link CallInfo} into a {@link Call}. Looks up the Telecomm + * call ID to see if an integer call ID has been assigned. If it has not, then a new call ID + * will be created for the call. + * + * @param callInfo The call-info object from which to create a Call. + */ + static Call getCall(CallInfo callInfo) { + Call call = getCall(callInfo.getId()); + if (call == null) { + call = new Call(sNextAvailableCallId++); + } + + // TODO(santoscordon): Remove assumption that all calls are dialing by default once + // CallInfo supports Call States + call.setState(Call.State.DIALING); + call.setNumber(callInfo.getHandle()); + + return call; + } + + /** + * Returns the call which maps from the specified Telecomm call ID. If no call was previously + * associated with the specified ID then return null. + * + * @param telecommCallId The Telecomm call ID to map. + * @return The call associated with the specified Telecomm call ID. + */ + static Call getCall(String telecommCallId) { + Preconditions.checkState(!Strings.isNullOrEmpty(telecommCallId)); + + if (sCallsById.containsKey(telecommCallId)) { + return sCallsById.get(telecommCallId); + } + + return null; + } + + /** + * Removes the specified Telecomm call ID from the map. + * + * @param telecommCallId The Telecomm call ID to remove. + */ + static void removeCall(String telecommCallId) { + sCallsById.remove(telecommCallId); + } +} diff --git a/InCallUI/src/com/android/incallui/InCallPresenter.java b/InCallUI/src/com/android/incallui/InCallPresenter.java index 274be6e2d..98393cf90 100644 --- a/InCallUI/src/com/android/incallui/InCallPresenter.java +++ b/InCallUI/src/com/android/incallui/InCallPresenter.java @@ -22,6 +22,7 @@ import com.google.common.base.Preconditions; import android.content.Context; import android.content.Intent; +import android.telecomm.IInCallAdapter; import com.android.services.telephony.common.Call; import com.android.services.telephony.common.Call.Capabilities; @@ -56,6 +57,9 @@ public class InCallPresenter implements CallList.Listener { private ProximitySensor mProximitySensor; private boolean mServiceConnected = false; + /** Used to send call-related commands and updates back to Telecomm. */ + private IInCallAdapter mInCallAdapter; + /** * Is true when the activity has been previously started. Some code needs to know not just if * the activity is currently up, but if it had been previously shown in foreground for this @@ -522,6 +526,15 @@ 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. + */ + void setInCallAdapter(IInCallAdapter inCallAdapter) { + mInCallAdapter = inCallAdapter; + } + + /** * For some disconnected causes, we show a dialog. This calls into the activity to show * the dialog if appropriate for the call. */ diff --git a/InCallUI/src/com/android/incallui/InCallService.java b/InCallUI/src/com/android/incallui/InCallService.java new file mode 100644 index 000000000..5a975b075 --- /dev/null +++ b/InCallUI/src/com/android/incallui/InCallService.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.incallui; + +import android.app.Service; +import android.content.Intent; +import android.os.Handler; +import android.os.IBinder; +import android.os.Looper; +import android.telecomm.CallInfo; +import android.telecomm.IInCallAdapter; +import android.telecomm.IInCallService; + +import com.android.services.telephony.common.Call; + +/** + * Used to receive updates about calls from the Telecomm component. This service is bound to + * Telecomm while there exist calls which potentially require UI. This includes ringing (incoming), + * dialing (outgoing), and active calls. When the last call is disconnected, Telecomm will unbind to + * the service triggering InCallActivity (via CallList) to finish soon after. + */ +public class InCallService extends Service { + + /** + * The actual service implementation that is passed to Telecomm as a binder. Implements all the + * methods of {@link IInCallService}. Most methods ultimately update one or more calls in + * {@link CallList} which in turn will trigger UI activity. + */ + private class InCallServiceBinder extends IInCallService.Stub { + /** {@inheritDoc} */ + @Override public void setInCallAdapter(final IInCallAdapter inCallAdapter) { + mHandler.post(new Runnable() { + @Override public void run() { + InCallPresenter.getInstance().setInCallAdapter(inCallAdapter); + } + }); + } + + /** {@inheritDoc} */ + @Override public void addCall(final CallInfo callInfo) { + mHandler.post(new Runnable() { + @Override public void run() { + Call call = CallInfoTranslator.getCall(callInfo); + CallList.getInstance().onUpdate(call); + } + }); + } + + /** {@inheritDoc} */ + @Override public void setActive(final String callId) { + mHandler.post(new Runnable() { + @Override public void run() { + Call call = CallInfoTranslator.getCall(callId); + if (null != call) { + call.setState(Call.State.ACTIVE); + CallList.getInstance().onUpdate(call); + } + } + }); + } + + /** {@inheritDoc} */ + @Override public void setDisconnected(final String callId) { + mHandler.post(new Runnable() { + @Override public void run() { + Call call = CallInfoTranslator.getCall(callId); + if (null != call) { + call.setState(Call.State.DISCONNECTED); + CallList.getInstance().onDisconnect(call); + + // Remove it from the mapping since we no longer need to interact + // with the Call. + CallInfoTranslator.removeCall(callId); + } + } + }); + } + } + + private final Handler mHandler = new Handler(Looper.getMainLooper()); + + /** Instance of IInCallService which is sent to Telecomm. */ + private final InCallServiceBinder mBinder = new InCallServiceBinder(); + + /** {@inheritDoc} */ + @Override public IBinder onBind(Intent intent) { + return mBinder; + } +} |