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