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