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