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