Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 18 | |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 20 | import android.bluetooth.BluetoothDevice; |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 21 | import android.os.Bundle; |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 22 | import android.os.RemoteException; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 23 | import android.util.ArrayMap; |
| 24 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 25 | import java.util.Collections; |
| 26 | import java.util.List; |
| 27 | import java.util.Map; |
| 28 | import java.util.Objects; |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 29 | import java.util.concurrent.CopyOnWriteArrayList; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * A unified virtual device providing a means of voice (and other) communication on a device. |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 33 | * |
| 34 | * @hide |
| 35 | * @deprecated Use {@link InCallService} directly instead of using this class. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 36 | */ |
Santos Cordon | 29886d8 | 2015-04-16 15:34:07 -0700 | [diff] [blame] | 37 | @SystemApi |
| 38 | @Deprecated |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 39 | public final class Phone { |
| 40 | |
| 41 | public abstract static class Listener { |
| 42 | /** |
| 43 | * Called when the audio state changes. |
| 44 | * |
| 45 | * @param phone The {@code Phone} calling this method. |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 46 | * @param audioState The new {@link AudioState}. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 47 | * |
| 48 | * @deprecated Use {@link #onCallAudioStateChanged(Phone, CallAudioState)} instead. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 49 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 50 | @Deprecated |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 51 | public void onAudioStateChanged(Phone phone, AudioState audioState) { } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 54 | * Called when the audio state changes. |
| 55 | * |
| 56 | * @param phone The {@code Phone} calling this method. |
| 57 | * @param callAudioState The new {@link CallAudioState}. |
| 58 | */ |
| 59 | public void onCallAudioStateChanged(Phone phone, CallAudioState callAudioState) { } |
| 60 | |
| 61 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 62 | * Called to bring the in-call screen to the foreground. The in-call experience should |
| 63 | * respond immediately by coming to the foreground to inform the user of the state of |
| 64 | * ongoing {@code Call}s. |
| 65 | * |
| 66 | * @param phone The {@code Phone} calling this method. |
| 67 | * @param showDialpad If true, put up the dialpad when the screen is shown. |
| 68 | */ |
| 69 | public void onBringToForeground(Phone phone, boolean showDialpad) { } |
| 70 | |
| 71 | /** |
| 72 | * Called when a {@code Call} has been added to this in-call session. The in-call user |
| 73 | * experience should add necessary state listeners to the specified {@code Call} and |
| 74 | * immediately start to show the user information about the existence |
| 75 | * and nature of this {@code Call}. Subsequent invocations of {@link #getCalls()} will |
| 76 | * include this {@code Call}. |
| 77 | * |
| 78 | * @param phone The {@code Phone} calling this method. |
| 79 | * @param call A newly added {@code Call}. |
| 80 | */ |
| 81 | public void onCallAdded(Phone phone, Call call) { } |
| 82 | |
| 83 | /** |
| 84 | * Called when a {@code Call} has been removed from this in-call session. The in-call user |
| 85 | * experience should remove any state listeners from the specified {@code Call} and |
| 86 | * immediately stop displaying any information about this {@code Call}. |
| 87 | * Subsequent invocations of {@link #getCalls()} will no longer include this {@code Call}. |
| 88 | * |
| 89 | * @param phone The {@code Phone} calling this method. |
| 90 | * @param call A newly removed {@code Call}. |
| 91 | */ |
| 92 | public void onCallRemoved(Phone phone, Call call) { } |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Called when the {@code Phone} ability to add more calls changes. If the phone cannot |
| 96 | * support more calls then {@code canAddCall} is set to {@code false}. If it can, then it |
| 97 | * is set to {@code true}. |
| 98 | * |
| 99 | * @param phone The {@code Phone} calling this method. |
| 100 | * @param canAddCall Indicates whether an additional call can be added. |
| 101 | */ |
| 102 | public void onCanAddCallChanged(Phone phone, boolean canAddCall) { } |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Called to silence the ringer if a ringing call exists. |
| 106 | * |
| 107 | * @param phone The {@code Phone} calling this method. |
| 108 | */ |
| 109 | public void onSilenceRinger(Phone phone) { } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 112 | // A Map allows us to track each Call by its Telecom-specified call ID |
| 113 | private final Map<String, Call> mCallByTelecomCallId = new ArrayMap<>(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 114 | |
| 115 | // A List allows us to keep the Calls in a stable iteration order so that casually developed |
| 116 | // user interface components do not incur any spurious jank |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 117 | private final List<Call> mCalls = new CopyOnWriteArrayList<>(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 118 | |
| 119 | // An unmodifiable view of the above List can be safely shared with subclass implementations |
| 120 | private final List<Call> mUnmodifiableCalls = Collections.unmodifiableList(mCalls); |
| 121 | |
| 122 | private final InCallAdapter mInCallAdapter; |
| 123 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 124 | private CallAudioState mCallAudioState; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 125 | |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 126 | private final List<Listener> mListeners = new CopyOnWriteArrayList<>(); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 127 | |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 128 | private boolean mCanAddCall = true; |
| 129 | |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 130 | private final String mCallingPackage; |
| 131 | |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 132 | /** |
| 133 | * The Target SDK version of the InCallService implementation. |
| 134 | */ |
| 135 | private final int mTargetSdkVersion; |
| 136 | |
| 137 | Phone(InCallAdapter adapter, String callingPackage, int targetSdkVersion) { |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 138 | mInCallAdapter = adapter; |
Tyler Gunn | bf9c6fd | 2016-11-09 10:19:23 -0800 | [diff] [blame] | 139 | mCallingPackage = callingPackage; |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 140 | mTargetSdkVersion = targetSdkVersion; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 143 | final void internalAddCall(ParcelableCall parcelableCall) { |
Shriram Ganesh | ddf570e | 2015-05-31 09:18:48 -0700 | [diff] [blame] | 144 | Call call = new Call(this, parcelableCall.getId(), mInCallAdapter, |
Tyler Gunn | 159f35c | 2017-03-02 09:28:37 -0800 | [diff] [blame] | 145 | parcelableCall.getState(), mCallingPackage, mTargetSdkVersion); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 146 | mCallByTelecomCallId.put(parcelableCall.getId(), call); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 147 | mCalls.add(call); |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 148 | checkCallTree(parcelableCall); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 149 | call.internalUpdate(parcelableCall, mCallByTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 150 | fireCallAdded(call); |
| 151 | } |
| 152 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 153 | final void internalRemoveCall(Call call) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 154 | mCallByTelecomCallId.remove(call.internalGetCallId()); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 155 | mCalls.remove(call); |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 156 | |
| 157 | InCallService.VideoCall videoCall = call.getVideoCall(); |
| 158 | if (videoCall != null) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 159 | videoCall.destroy(); |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 160 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 161 | fireCallRemoved(call); |
| 162 | } |
| 163 | |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 164 | final void internalUpdateCall(ParcelableCall parcelableCall) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 165 | Call call = mCallByTelecomCallId.get(parcelableCall.getId()); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 166 | if (call != null) { |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 167 | checkCallTree(parcelableCall); |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 168 | call.internalUpdate(parcelableCall, mCallByTelecomCallId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 172 | final void internalSetPostDialWait(String telecomId, String remaining) { |
| 173 | Call call = mCallByTelecomCallId.get(telecomId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 174 | if (call != null) { |
| 175 | call.internalSetPostDialWait(remaining); |
| 176 | } |
| 177 | } |
| 178 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 179 | final void internalCallAudioStateChanged(CallAudioState callAudioState) { |
| 180 | if (!Objects.equals(mCallAudioState, callAudioState)) { |
| 181 | mCallAudioState = callAudioState; |
| 182 | fireCallAudioStateChanged(callAudioState); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 186 | final Call internalGetCallByTelecomId(String telecomId) { |
| 187 | return mCallByTelecomCallId.get(telecomId); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 190 | final void internalBringToForeground(boolean showDialpad) { |
| 191 | fireBringToForeground(showDialpad); |
| 192 | } |
| 193 | |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 194 | final void internalSetCanAddCall(boolean canAddCall) { |
| 195 | if (mCanAddCall != canAddCall) { |
| 196 | mCanAddCall = canAddCall; |
| 197 | fireCanAddCallChanged(canAddCall); |
| 198 | } |
| 199 | } |
| 200 | |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 201 | final void internalSilenceRinger() { |
| 202 | fireSilenceRinger(); |
| 203 | } |
| 204 | |
Tyler Gunn | 876dbfb | 2016-03-14 15:18:07 -0700 | [diff] [blame] | 205 | final void internalOnConnectionEvent(String telecomId, String event, Bundle extras) { |
| 206 | Call call = mCallByTelecomCallId.get(telecomId); |
| 207 | if (call != null) { |
| 208 | call.internalOnConnectionEvent(event, extras); |
| 209 | } |
| 210 | } |
| 211 | |
Hall Liu | 95d5587 | 2017-01-25 17:12:49 -0800 | [diff] [blame] | 212 | final void internalOnRttUpgradeRequest(String callId, int requestId) { |
| 213 | Call call = mCallByTelecomCallId.get(callId); |
| 214 | if (call != null) { |
| 215 | call.internalOnRttUpgradeRequest(requestId); |
| 216 | } |
| 217 | } |
| 218 | |
Hall Liu | 57006aa | 2017-02-06 10:49:48 -0800 | [diff] [blame] | 219 | final void internalOnRttInitiationFailure(String callId, int reason) { |
| 220 | Call call = mCallByTelecomCallId.get(callId); |
| 221 | if (call != null) { |
| 222 | call.internalOnRttInitiationFailure(reason); |
| 223 | } |
| 224 | } |
| 225 | |
Sanket Padawe | e29a266 | 2017-12-01 13:59:27 -0800 | [diff] [blame] | 226 | final void internalOnHandoverFailed(String callId, int error) { |
| 227 | Call call = mCallByTelecomCallId.get(callId); |
| 228 | if (call != null) { |
| 229 | call.internalOnHandoverFailed(error); |
| 230 | } |
| 231 | } |
| 232 | |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 233 | /** |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 234 | * Called to destroy the phone and cleanup any lingering calls. |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 235 | */ |
| 236 | final void destroy() { |
| 237 | for (Call call : mCalls) { |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 238 | InCallService.VideoCall videoCall = call.getVideoCall(); |
| 239 | if (videoCall != null) { |
Andrew Lee | 011728f | 2015-04-23 15:47:06 -0700 | [diff] [blame] | 240 | videoCall.destroy(); |
Tyler Gunn | 7595842 | 2015-04-15 14:23:42 -0700 | [diff] [blame] | 241 | } |
Santos Cordon | f30d7e9 | 2014-08-26 09:54:33 -0700 | [diff] [blame] | 242 | if (call.getState() != Call.STATE_DISCONNECTED) { |
| 243 | call.internalSetDisconnected(); |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 249 | * Adds a listener to this {@code Phone}. |
| 250 | * |
| 251 | * @param listener A {@code Listener} object. |
| 252 | */ |
| 253 | public final void addListener(Listener listener) { |
| 254 | mListeners.add(listener); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Removes a listener from this {@code Phone}. |
| 259 | * |
| 260 | * @param listener A {@code Listener} object. |
| 261 | */ |
| 262 | public final void removeListener(Listener listener) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 263 | if (listener != null) { |
| 264 | mListeners.remove(listener); |
| 265 | } |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Obtains the current list of {@code Call}s to be displayed by this in-call experience. |
| 270 | * |
| 271 | * @return A list of the relevant {@code Call}s. |
| 272 | */ |
| 273 | public final List<Call> getCalls() { |
| 274 | return mUnmodifiableCalls; |
| 275 | } |
| 276 | |
| 277 | /** |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 278 | * Returns if the {@code Phone} can support additional calls. |
| 279 | * |
| 280 | * @return Whether the phone supports adding more calls. |
| 281 | */ |
| 282 | public final boolean canAddCall() { |
| 283 | return mCanAddCall; |
| 284 | } |
| 285 | |
| 286 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 287 | * Sets the microphone mute state. When this request is honored, there will be change to |
| 288 | * the {@link #getAudioState()}. |
| 289 | * |
| 290 | * @param state {@code true} if the microphone should be muted; {@code false} otherwise. |
| 291 | */ |
| 292 | public final void setMuted(boolean state) { |
| 293 | mInCallAdapter.mute(state); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Sets the audio route (speaker, bluetooth, etc...). When this request is honored, there will |
| 298 | * be change to the {@link #getAudioState()}. |
| 299 | * |
| 300 | * @param route The audio route to use. |
| 301 | */ |
| 302 | public final void setAudioRoute(int route) { |
| 303 | mInCallAdapter.setAudioRoute(route); |
| 304 | } |
| 305 | |
| 306 | /** |
Hall Liu | a98f58b | 2017-11-07 17:59:28 -0800 | [diff] [blame] | 307 | * Request audio routing to a specific bluetooth device. Calling this method may result in |
| 308 | * the device routing audio to a different bluetooth device than the one specified. A list of |
| 309 | * available devices can be obtained via {@link CallAudioState#getSupportedBluetoothDevices()} |
| 310 | * |
| 311 | * @param bluetoothAddress The address of the bluetooth device to connect to, as returned by |
| 312 | * {@link BluetoothDevice#getAddress()}, or {@code null} if no device is preferred. |
| 313 | */ |
| 314 | public void requestBluetoothAudio(String bluetoothAddress) { |
| 315 | mInCallAdapter.requestBluetoothAudio(bluetoothAddress); |
| 316 | } |
| 317 | |
| 318 | /** |
Yorke Lee | 0d6ea71 | 2014-07-28 14:39:23 -0700 | [diff] [blame] | 319 | * Turns the proximity sensor on. When this request is made, the proximity sensor will |
| 320 | * become active, and the touch screen and display will be turned off when the user's face |
| 321 | * is detected to be in close proximity to the screen. This operation is a no-op on devices |
| 322 | * that do not have a proximity sensor. |
Yorke Lee | 22244d0 | 2015-04-14 12:34:28 -0700 | [diff] [blame] | 323 | * |
| 324 | * @hide |
Yorke Lee | 0d6ea71 | 2014-07-28 14:39:23 -0700 | [diff] [blame] | 325 | */ |
| 326 | public final void setProximitySensorOn() { |
| 327 | mInCallAdapter.turnProximitySensorOn(); |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Turns the proximity sensor off. When this request is made, the proximity sensor will |
| 332 | * become inactive, and no longer affect the touch screen and display. This operation is a |
| 333 | * no-op on devices that do not have a proximity sensor. |
| 334 | * |
| 335 | * @param screenOnImmediately If true, the screen will be turned on immediately if it was |
| 336 | * previously off. Otherwise, the screen will only be turned on after the proximity sensor |
| 337 | * is no longer triggered. |
Yorke Lee | 22244d0 | 2015-04-14 12:34:28 -0700 | [diff] [blame] | 338 | * |
| 339 | * @hide |
Yorke Lee | 0d6ea71 | 2014-07-28 14:39:23 -0700 | [diff] [blame] | 340 | */ |
| 341 | public final void setProximitySensorOff(boolean screenOnImmediately) { |
| 342 | mInCallAdapter.turnProximitySensorOff(screenOnImmediately); |
| 343 | } |
| 344 | |
| 345 | /** |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 346 | * Obtains the current phone call audio state of the {@code Phone}. |
| 347 | * |
| 348 | * @return An object encapsulating the audio state. |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 349 | * @deprecated Use {@link #getCallAudioState()} instead. |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 350 | */ |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 351 | @Deprecated |
Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 352 | public final AudioState getAudioState() { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 353 | return new AudioState(mCallAudioState); |
| 354 | } |
| 355 | |
| 356 | /** |
| 357 | * Obtains the current phone call audio state of the {@code Phone}. |
| 358 | * |
| 359 | * @return An object encapsulating the audio state. |
| 360 | */ |
| 361 | public final CallAudioState getCallAudioState() { |
| 362 | return mCallAudioState; |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | private void fireCallAdded(Call call) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 366 | for (Listener listener : mListeners) { |
| 367 | listener.onCallAdded(this, call); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
| 371 | private void fireCallRemoved(Call call) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 372 | for (Listener listener : mListeners) { |
| 373 | listener.onCallRemoved(this, call); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 377 | private void fireCallAudioStateChanged(CallAudioState audioState) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 378 | for (Listener listener : mListeners) { |
Yorke Lee | 4af5935 | 2015-05-13 14:14:54 -0700 | [diff] [blame] | 379 | listener.onCallAudioStateChanged(this, audioState); |
| 380 | listener.onAudioStateChanged(this, new AudioState(audioState)); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
| 384 | private void fireBringToForeground(boolean showDialpad) { |
Jay Shrauner | 229e382 | 2014-08-15 09:23:07 -0700 | [diff] [blame] | 385 | for (Listener listener : mListeners) { |
| 386 | listener.onBringToForeground(this, showDialpad); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Santos Cordon | 6c912b7 | 2014-11-07 16:05:09 -0800 | [diff] [blame] | 390 | private void fireCanAddCallChanged(boolean canAddCall) { |
| 391 | for (Listener listener : mListeners) { |
| 392 | listener.onCanAddCallChanged(this, canAddCall); |
| 393 | } |
| 394 | } |
| 395 | |
Sailesh Nepal | 9c2618b | 2016-01-23 16:28:22 -0800 | [diff] [blame] | 396 | private void fireSilenceRinger() { |
| 397 | for (Listener listener : mListeners) { |
| 398 | listener.onSilenceRinger(this); |
| 399 | } |
| 400 | } |
| 401 | |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 402 | private void checkCallTree(ParcelableCall parcelableCall) { |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 403 | if (parcelableCall.getChildCallIds() != null) { |
| 404 | for (int i = 0; i < parcelableCall.getChildCallIds().size(); i++) { |
Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 405 | if (!mCallByTelecomCallId.containsKey(parcelableCall.getChildCallIds().get(i))) { |
Santos Cordon | 88b771d | 2014-07-19 13:10:40 -0700 | [diff] [blame] | 406 | Log.wtf(this, "ParcelableCall %s has nonexistent child %s", |
| 407 | parcelableCall.getId(), parcelableCall.getChildCallIds().get(i)); |
Ihab Awad | e63fadb | 2014-07-09 21:52:04 -0700 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | } |