Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [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 | |
| 17 | package com.android.incallui; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.graphics.Point; |
| 22 | import android.os.Bundle; |
| 23 | import android.os.Handler; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 24 | import android.os.Trace; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 25 | import android.support.annotation.MainThread; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 26 | import android.support.annotation.NonNull; |
| 27 | import android.support.annotation.Nullable; |
| 28 | import android.support.annotation.VisibleForTesting; |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 29 | import android.support.v4.os.UserManagerCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 30 | import android.telecom.Call.Details; |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 31 | import android.telecom.CallAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 32 | import android.telecom.DisconnectCause; |
| 33 | import android.telecom.PhoneAccount; |
| 34 | import android.telecom.PhoneAccountHandle; |
| 35 | import android.telecom.TelecomManager; |
| 36 | import android.telecom.VideoProfile; |
| 37 | import android.telephony.PhoneStateListener; |
| 38 | import android.telephony.TelephonyManager; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 39 | import android.util.ArraySet; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 40 | import android.view.Window; |
| 41 | import android.view.WindowManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 42 | import com.android.contacts.common.compat.CallCompat; |
| 43 | import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler; |
| 44 | import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 45 | import com.android.dialer.blocking.FilteredNumberCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 46 | import com.android.dialer.blocking.FilteredNumbersUtil; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 47 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 48 | import com.android.dialer.common.LogUtil; |
zachh | 6a4cebd | 2017-10-24 17:10:06 -0700 | [diff] [blame] | 49 | import com.android.dialer.common.concurrent.DialerExecutorComponent; |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 50 | import com.android.dialer.enrichedcall.EnrichedCallComponent; |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 51 | import com.android.dialer.location.GeoUtil; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 52 | import com.android.dialer.logging.InteractionEvent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 53 | import com.android.dialer.logging.Logger; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 54 | import com.android.dialer.postcall.PostCall; |
twyen | a4745bd | 2017-12-12 18:40:11 -0800 | [diff] [blame] | 55 | import com.android.dialer.telecom.TelecomCallUtil; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 56 | import com.android.dialer.telecom.TelecomUtil; |
| 57 | import com.android.dialer.util.TouchPointManager; |
| 58 | import com.android.incallui.InCallOrientationEventListener.ScreenOrientation; |
| 59 | import com.android.incallui.answerproximitysensor.PseudoScreenState; |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 60 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 61 | import com.android.incallui.call.CallList; |
| 62 | import com.android.incallui.call.DialerCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 63 | import com.android.incallui.call.ExternalCallList; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 64 | import com.android.incallui.call.TelecomAdapter; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 65 | import com.android.incallui.disconnectdialog.DisconnectMessage; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 66 | import com.android.incallui.incalluilock.InCallUiLock; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 67 | import com.android.incallui.latencyreport.LatencyReport; |
| 68 | import com.android.incallui.legacyblocking.BlockedNumberContentObserver; |
| 69 | import com.android.incallui.spam.SpamCallListListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 70 | import com.android.incallui.videosurface.bindings.VideoSurfaceBindings; |
| 71 | import com.android.incallui.videosurface.protocol.VideoSurfaceTexture; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 72 | import com.android.incallui.videotech.utils.VideoUtils; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 73 | import java.util.Collections; |
| 74 | import java.util.List; |
| 75 | import java.util.Objects; |
| 76 | import java.util.Set; |
| 77 | import java.util.concurrent.ConcurrentHashMap; |
| 78 | import java.util.concurrent.CopyOnWriteArrayList; |
| 79 | import java.util.concurrent.atomic.AtomicBoolean; |
| 80 | |
| 81 | /** |
| 82 | * Takes updates from the CallList and notifies the InCallActivity (UI) of the changes. Responsible |
| 83 | * for starting the activity for a new call and finishing the activity when all calls are |
| 84 | * disconnected. Creates and manages the in-call state and provides a listener pattern for the |
| 85 | * presenters that want to listen in on the in-call state changes. TODO: This class has become more |
| 86 | * of a state machine at this point. Consider renaming. |
| 87 | */ |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 88 | public class InCallPresenter implements CallList.Listener, AudioModeProvider.AudioModeListener { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 89 | private static final String PIXEL2017_SYSTEM_FEATURE = |
| 90 | "com.google.android.feature.PIXEL_2017_EXPERIENCE"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 91 | |
| 92 | private static final long BLOCK_QUERY_TIMEOUT_MS = 1000; |
| 93 | |
| 94 | private static final Bundle EMPTY_EXTRAS = new Bundle(); |
| 95 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 96 | private static InCallPresenter inCallPresenter; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is load factor before |
| 100 | * resizing, 1 means we only expect a single thread to access the map so make only a single shard |
| 101 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 102 | private final Set<InCallStateListener> listeners = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 103 | Collections.newSetFromMap(new ConcurrentHashMap<InCallStateListener, Boolean>(8, 0.9f, 1)); |
| 104 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 105 | private final List<IncomingCallListener> incomingCallListeners = new CopyOnWriteArrayList<>(); |
| 106 | private final Set<InCallDetailsListener> detailsListeners = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 107 | Collections.newSetFromMap(new ConcurrentHashMap<InCallDetailsListener, Boolean>(8, 0.9f, 1)); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 108 | private final Set<CanAddCallListener> canAddCallListeners = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 109 | Collections.newSetFromMap(new ConcurrentHashMap<CanAddCallListener, Boolean>(8, 0.9f, 1)); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 110 | private final Set<InCallUiListener> inCallUiListeners = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 111 | Collections.newSetFromMap(new ConcurrentHashMap<InCallUiListener, Boolean>(8, 0.9f, 1)); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 112 | private final Set<InCallOrientationListener> orientationListeners = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 113 | Collections.newSetFromMap( |
| 114 | new ConcurrentHashMap<InCallOrientationListener, Boolean>(8, 0.9f, 1)); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 115 | private final Set<InCallEventListener> inCallEventListeners = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 116 | Collections.newSetFromMap(new ConcurrentHashMap<InCallEventListener, Boolean>(8, 0.9f, 1)); |
| 117 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 118 | private StatusBarNotifier statusBarNotifier; |
| 119 | private ExternalCallNotifier externalCallNotifier; |
| 120 | private ContactInfoCache contactInfoCache; |
| 121 | private Context context; |
| 122 | private final OnCheckBlockedListener onCheckBlockedListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 123 | new OnCheckBlockedListener() { |
| 124 | @Override |
| 125 | public void onCheckComplete(final Integer id) { |
| 126 | if (id != null && id != FilteredNumberAsyncQueryHandler.INVALID_ID) { |
| 127 | // Silence the ringer now to prevent ringing and vibration before the call is |
| 128 | // terminated when Telecom attempts to add it. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 129 | TelecomUtil.silenceRinger(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | }; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 133 | private CallList callList; |
| 134 | private ExternalCallList externalCallList; |
| 135 | private InCallActivity inCallActivity; |
| 136 | private ManageConferenceActivity manageConferenceActivity; |
| 137 | private final android.telecom.Call.Callback callCallback = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 138 | new android.telecom.Call.Callback() { |
| 139 | @Override |
| 140 | public void onPostDialWait( |
| 141 | android.telecom.Call telecomCall, String remainingPostDialSequence) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 142 | final DialerCall call = callList.getDialerCallFromTelecomCall(telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 143 | if (call == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 144 | LogUtil.w( |
| 145 | "InCallPresenter.onPostDialWait", |
| 146 | "DialerCall not found in call list: " + telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 147 | return; |
| 148 | } |
| 149 | onPostDialCharWait(call.getId(), remainingPostDialSequence); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void onDetailsChanged( |
| 154 | android.telecom.Call telecomCall, android.telecom.Call.Details details) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 155 | final DialerCall call = callList.getDialerCallFromTelecomCall(telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 156 | if (call == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 157 | LogUtil.w( |
| 158 | "InCallPresenter.onDetailsChanged", |
| 159 | "DialerCall not found in call list: " + telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 160 | return; |
| 161 | } |
| 162 | |
| 163 | if (details.hasProperty(Details.PROPERTY_IS_EXTERNAL_CALL) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 164 | && !externalCallList.isCallTracked(telecomCall)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 165 | |
| 166 | // A regular call became an external call so swap call lists. |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 167 | LogUtil.i("InCallPresenter.onDetailsChanged", "Call became external: " + telecomCall); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 168 | callList.onInternalCallMadeExternal(context, telecomCall); |
| 169 | externalCallList.onCallAdded(telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 170 | return; |
| 171 | } |
| 172 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 173 | for (InCallDetailsListener listener : detailsListeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 174 | listener.onDetailsChanged(call, details); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public void onConferenceableCallsChanged( |
| 180 | android.telecom.Call telecomCall, List<android.telecom.Call> conferenceableCalls) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 181 | LogUtil.i( |
| 182 | "InCallPresenter.onConferenceableCallsChanged", |
| 183 | "onConferenceableCallsChanged: " + telecomCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 184 | onDetailsChanged(telecomCall, telecomCall.getDetails()); |
| 185 | } |
| 186 | }; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 187 | private InCallState inCallState = InCallState.NO_CALLS; |
| 188 | private ProximitySensor proximitySensor; |
| 189 | private final PseudoScreenState pseudoScreenState = new PseudoScreenState(); |
| 190 | private boolean serviceConnected; |
| 191 | private InCallCameraManager inCallCameraManager; |
| 192 | private FilteredNumberAsyncQueryHandler filteredQueryHandler; |
| 193 | private CallList.Listener spamCallListListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 194 | /** Whether or not we are currently bound and waiting for Telecom to send us a new call. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 195 | private boolean boundAndWaitingForOutgoingCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 196 | /** Determines if the InCall UI is in fullscreen mode or not. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 197 | private boolean isFullScreen = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 198 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 199 | private boolean screenTimeoutEnabled = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 200 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 201 | private PhoneStateListener phoneStateListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 202 | new PhoneStateListener() { |
| 203 | @Override |
| 204 | public void onCallStateChanged(int state, String incomingNumber) { |
| 205 | if (state == TelephonyManager.CALL_STATE_RINGING) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 206 | if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 207 | return; |
| 208 | } |
| 209 | // Check if the number is blocked, to silence the ringer. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 210 | String countryIso = GeoUtil.getCurrentCountryIso(context); |
| 211 | filteredQueryHandler.isBlockedNumber( |
| 212 | onCheckBlockedListener, incomingNumber, countryIso); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | }; |
twyen | a4745bd | 2017-12-12 18:40:11 -0800 | [diff] [blame] | 216 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 217 | /** Whether or not InCallService is bound to Telecom. */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 218 | private boolean serviceBound = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * When configuration changes Android kills the current activity and starts a new one. The flag is |
| 222 | * used to check if full clean up is necessary (activity is stopped and new activity won't be |
| 223 | * started), or if a new activity will be started right after the current one is destroyed, and |
| 224 | * therefore no need in release all resources. |
| 225 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 226 | private boolean isChangingConfigurations = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 227 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 228 | private boolean awaitingCallListUpdate = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 229 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 230 | private ExternalCallList.ExternalCallListener externalCallListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 231 | new ExternalCallList.ExternalCallListener() { |
| 232 | |
| 233 | @Override |
| 234 | public void onExternalCallPulled(android.telecom.Call call) { |
| 235 | // Note: keep this code in sync with InCallPresenter#onCallAdded |
| 236 | LatencyReport latencyReport = new LatencyReport(call); |
| 237 | latencyReport.onCallBlockingDone(); |
| 238 | // Note: External calls do not require spam checking. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 239 | callList.onCallAdded(context, call, latencyReport); |
| 240 | call.registerCallback(callCallback); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public void onExternalCallAdded(android.telecom.Call call) { |
| 245 | // No-op |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void onExternalCallRemoved(android.telecom.Call call) { |
| 250 | // No-op |
| 251 | } |
| 252 | |
| 253 | @Override |
| 254 | public void onExternalCallUpdated(android.telecom.Call call) { |
| 255 | // No-op |
| 256 | } |
| 257 | }; |
| 258 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 259 | private ThemeColorManager themeColorManager; |
| 260 | private VideoSurfaceTexture localVideoSurfaceTexture; |
| 261 | private VideoSurfaceTexture remoteVideoSurfaceTexture; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 262 | |
yueg | 7f5acbe | 2018-01-10 13:50:29 -0800 | [diff] [blame] | 263 | private MotorolaInCallUiNotifier motorolaInCallUiNotifier; |
| 264 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 265 | /** Inaccessible constructor. Must use getRunningInstance() to get this singleton. */ |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 266 | @VisibleForTesting |
| 267 | InCallPresenter() {} |
| 268 | |
| 269 | public static synchronized InCallPresenter getInstance() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 270 | if (inCallPresenter == null) { |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 271 | Trace.beginSection("InCallPresenter.Constructor"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 272 | inCallPresenter = new InCallPresenter(); |
wangqi | c8cf79e | 2017-10-17 09:21:00 -0700 | [diff] [blame] | 273 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 274 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 275 | return inCallPresenter; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 278 | @VisibleForTesting |
| 279 | public static synchronized void setInstanceForTesting(InCallPresenter inCallPresenter) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 280 | InCallPresenter.inCallPresenter = inCallPresenter; |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 281 | } |
| 282 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 283 | /** |
| 284 | * Determines whether or not a call has no valid phone accounts that can be used to make the call |
| 285 | * with. Emergency calls do not require a phone account. |
| 286 | * |
| 287 | * @param call to check accounts for. |
| 288 | * @return {@code true} if the call has no call capable phone accounts set, {@code false} if the |
| 289 | * call contains a phone account that could be used to initiate it with, or is an emergency |
| 290 | * call. |
| 291 | */ |
| 292 | public static boolean isCallWithNoValidAccounts(DialerCall call) { |
| 293 | if (call != null && !call.isEmergencyCall()) { |
| 294 | Bundle extras = call.getIntentExtras(); |
| 295 | |
| 296 | if (extras == null) { |
| 297 | extras = EMPTY_EXTRAS; |
| 298 | } |
| 299 | |
| 300 | final List<PhoneAccountHandle> phoneAccountHandles = |
| 301 | extras.getParcelableArrayList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS); |
| 302 | |
| 303 | if ((call.getAccountHandle() == null |
| 304 | && (phoneAccountHandles == null || phoneAccountHandles.isEmpty()))) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 305 | LogUtil.i( |
| 306 | "InCallPresenter.isCallWithNoValidAccounts", "No valid accounts for call " + call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 307 | return true; |
| 308 | } |
| 309 | } |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | public InCallState getInCallState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 314 | return inCallState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | public CallList getCallList() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 318 | return callList; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | public void setUp( |
| 322 | @NonNull Context context, |
| 323 | CallList callList, |
| 324 | ExternalCallList externalCallList, |
| 325 | StatusBarNotifier statusBarNotifier, |
| 326 | ExternalCallNotifier externalCallNotifier, |
| 327 | ContactInfoCache contactInfoCache, |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 328 | ProximitySensor proximitySensor, |
| 329 | FilteredNumberAsyncQueryHandler filteredNumberQueryHandler) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 330 | Trace.beginSection("InCallPresenter.setUp"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 331 | if (serviceConnected) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 332 | LogUtil.i("InCallPresenter.setUp", "New service connection replacing existing one."); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 333 | if (context != this.context || callList != this.callList) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 334 | throw new IllegalStateException(); |
| 335 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 336 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 337 | return; |
| 338 | } |
| 339 | |
| 340 | Objects.requireNonNull(context); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 341 | this.context = context; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 342 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 343 | this.contactInfoCache = contactInfoCache; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 344 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 345 | this.statusBarNotifier = statusBarNotifier; |
| 346 | this.externalCallNotifier = externalCallNotifier; |
| 347 | addListener(this.statusBarNotifier); |
| 348 | EnrichedCallComponent.get(this.context) |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 349 | .getEnrichedCallManager() |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 350 | .registerStateChangedListener(this.statusBarNotifier); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 351 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 352 | this.proximitySensor = proximitySensor; |
| 353 | addListener(this.proximitySensor); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 354 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 355 | if (themeColorManager == null) { |
| 356 | themeColorManager = |
| 357 | new ThemeColorManager(new InCallUIMaterialColorMapUtils(this.context.getResources())); |
wangqi | 8d662ca | 2017-10-26 11:27:19 -0700 | [diff] [blame] | 358 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 359 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 360 | this.callList = callList; |
| 361 | this.externalCallList = externalCallList; |
| 362 | externalCallList.addExternalCallListener(this.externalCallNotifier); |
| 363 | externalCallList.addExternalCallListener(externalCallListener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 364 | |
| 365 | // This only gets called by the service so this is okay. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 366 | serviceConnected = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 367 | |
| 368 | // The final thing we do in this set up is add ourselves as a listener to CallList. This |
| 369 | // will kick off an update and the whole process can start. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 370 | this.callList.addListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 371 | |
| 372 | // Create spam call list listener and add it to the list of listeners |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 373 | spamCallListListener = |
zachh | 6a4cebd | 2017-10-24 17:10:06 -0700 | [diff] [blame] | 374 | new SpamCallListListener( |
| 375 | context, DialerExecutorComponent.get(context).dialerExecutorFactory()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 376 | this.callList.addListener(spamCallListListener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 377 | |
| 378 | VideoPauseController.getInstance().setUp(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 379 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 380 | filteredQueryHandler = filteredNumberQueryHandler; |
| 381 | this.context |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 382 | .getSystemService(TelephonyManager.class) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 383 | .listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 384 | |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 385 | AudioModeProvider.getInstance().addListener(this); |
| 386 | |
yueg | 7f5acbe | 2018-01-10 13:50:29 -0800 | [diff] [blame] | 387 | if (motorolaInCallUiNotifier == null) { |
| 388 | // Add listener to notify Telephony process when the incoming call screen is started or |
| 389 | // finished. This is for hiding USSD dialog because the incoming call screen should have |
| 390 | // higher precedence over this dialog. |
| 391 | motorolaInCallUiNotifier = new MotorolaInCallUiNotifier(context); |
| 392 | addInCallUiListener(motorolaInCallUiNotifier); |
| 393 | addListener(motorolaInCallUiNotifier); |
| 394 | } |
| 395 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 396 | LogUtil.d("InCallPresenter.setUp", "Finished InCallPresenter.setUp"); |
| 397 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Called when the telephony service has disconnected from us. This will happen when there are no |
| 402 | * more active calls. However, we may still want to continue showing the UI for certain cases like |
| 403 | * showing "Call Ended". What we really want is to wait for the activity and the service to both |
| 404 | * disconnect before we tear things down. This method sets a serviceConnected boolean and calls a |
| 405 | * secondary method that performs the aforementioned logic. |
| 406 | */ |
| 407 | public void tearDown() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 408 | LogUtil.d("InCallPresenter.tearDown", "tearDown"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 409 | callList.clearOnDisconnect(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 410 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 411 | serviceConnected = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 412 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 413 | context |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 414 | .getSystemService(TelephonyManager.class) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 415 | .listen(phoneStateListener, PhoneStateListener.LISTEN_NONE); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 416 | |
| 417 | attemptCleanup(); |
| 418 | VideoPauseController.getInstance().tearDown(); |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 419 | AudioModeProvider.getInstance().removeListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | private void attemptFinishActivity() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 423 | screenTimeoutEnabled = true; |
| 424 | final boolean doFinish = (inCallActivity != null && isActivityStarted()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 425 | LogUtil.i("InCallPresenter.attemptFinishActivity", "Hide in call UI: " + doFinish); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 426 | if (doFinish) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 427 | inCallActivity.setExcludeFromRecents(true); |
| 428 | inCallActivity.finish(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 429 | } |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Called when the UI ends. Attempts to tear down everything if necessary. See {@link #tearDown()} |
| 434 | * for more insight on the tear-down process. |
| 435 | */ |
| 436 | public void unsetActivity(InCallActivity inCallActivity) { |
| 437 | if (inCallActivity == null) { |
| 438 | throw new IllegalArgumentException("unregisterActivity cannot be called with null"); |
| 439 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 440 | if (this.inCallActivity == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 441 | LogUtil.i( |
| 442 | "InCallPresenter.unsetActivity", "No InCallActivity currently set, no need to unset."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 443 | return; |
| 444 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 445 | if (this.inCallActivity != inCallActivity) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 446 | LogUtil.w( |
| 447 | "InCallPresenter.unsetActivity", |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 448 | "Second instance of InCallActivity is trying to unregister when another" |
| 449 | + " instance is active. Ignoring."); |
| 450 | return; |
| 451 | } |
| 452 | updateActivity(null); |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Updates the current instance of {@link InCallActivity} with the provided one. If a {@code null} |
| 457 | * activity is provided, it means that the activity was finished and we should attempt to cleanup. |
| 458 | */ |
| 459 | private void updateActivity(InCallActivity inCallActivity) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 460 | Trace.beginSection("InCallPresenter.updateActivity"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 461 | boolean updateListeners = false; |
| 462 | boolean doAttemptCleanup = false; |
| 463 | |
| 464 | if (inCallActivity != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 465 | if (this.inCallActivity == null) { |
| 466 | context = inCallActivity.getApplicationContext(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 467 | updateListeners = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 468 | LogUtil.i("InCallPresenter.updateActivity", "UI Initialized"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 469 | } else { |
| 470 | // since setActivity is called onStart(), it can be called multiple times. |
| 471 | // This is fine and ignorable, but we do not want to update the world every time |
| 472 | // this happens (like going to/from background) so we do not set updateListeners. |
| 473 | } |
| 474 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 475 | this.inCallActivity = inCallActivity; |
| 476 | this.inCallActivity.setExcludeFromRecents(false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 477 | |
| 478 | // By the time the UI finally comes up, the call may already be disconnected. |
| 479 | // If that's the case, we may need to show an error dialog. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 480 | if (callList != null && callList.getDisconnectedCall() != null) { |
| 481 | showDialogOrToastForDisconnectedCall(callList.getDisconnectedCall()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | // When the UI comes up, we need to first check the in-call state. |
| 485 | // If we are showing NO_CALLS, that means that a call probably connected and |
| 486 | // then immediately disconnected before the UI was able to come up. |
| 487 | // If we dont have any calls, start tearing down the UI instead. |
| 488 | // NOTE: This code relies on {@link #mInCallActivity} being set so we run it after |
| 489 | // it has been set. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 490 | if (inCallState == InCallState.NO_CALLS) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 491 | LogUtil.i("InCallPresenter.updateActivity", "UI Initialized, but no calls left. Shut down"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 492 | attemptFinishActivity(); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 493 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 494 | return; |
| 495 | } |
| 496 | } else { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 497 | LogUtil.i("InCallPresenter.updateActivity", "UI Destroyed"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 498 | updateListeners = true; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 499 | this.inCallActivity = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 500 | |
| 501 | // We attempt cleanup for the destroy case but only after we recalculate the state |
| 502 | // to see if we need to come back up or stay shut down. This is why we do the |
| 503 | // cleanup after the call to onCallListChange() instead of directly here. |
| 504 | doAttemptCleanup = true; |
| 505 | } |
| 506 | |
| 507 | // Messages can come from the telephony layer while the activity is coming up |
| 508 | // and while the activity is going down. So in both cases we need to recalculate what |
| 509 | // state we should be in after they complete. |
| 510 | // Examples: (1) A new incoming call could come in and then get disconnected before |
| 511 | // the activity is created. |
| 512 | // (2) All calls could disconnect and then get a new incoming call before the |
| 513 | // activity is destroyed. |
| 514 | // |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 515 | // a bug - We previously had a check for mServiceConnected here as well, but there are |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 516 | // cases where we need to recalculate the current state even if the service in not |
| 517 | // connected. In particular the case where startOrFinish() is called while the app is |
| 518 | // already finish()ing. In that case, we skip updating the state with the knowledge that |
| 519 | // we will check again once the activity has finished. That means we have to recalculate the |
| 520 | // state here even if the service is disconnected since we may not have finished a state |
| 521 | // transition while finish()ing. |
| 522 | if (updateListeners) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 523 | onCallListChange(callList); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | if (doAttemptCleanup) { |
| 527 | attemptCleanup(); |
| 528 | } |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 529 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | public void setManageConferenceActivity( |
| 533 | @Nullable ManageConferenceActivity manageConferenceActivity) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 534 | this.manageConferenceActivity = manageConferenceActivity; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | public void onBringToForeground(boolean showDialpad) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 538 | LogUtil.i("InCallPresenter.onBringToForeground", "Bringing UI to foreground."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 539 | bringToForeground(showDialpad); |
| 540 | } |
| 541 | |
| 542 | public void onCallAdded(final android.telecom.Call call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 543 | Trace.beginSection("InCallPresenter.onCallAdded"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 544 | LatencyReport latencyReport = new LatencyReport(call); |
| 545 | if (shouldAttemptBlocking(call)) { |
| 546 | maybeBlockCall(call, latencyReport); |
| 547 | } else { |
| 548 | if (call.getDetails().hasProperty(CallCompat.Details.PROPERTY_IS_EXTERNAL_CALL)) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 549 | externalCallList.onCallAdded(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 550 | } else { |
| 551 | latencyReport.onCallBlockingDone(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 552 | callList.onCallAdded(context, call, latencyReport); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
| 556 | // Since a call has been added we are no longer waiting for Telecom to send us a call. |
| 557 | setBoundAndWaitingForOutgoingCall(false, null); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 558 | call.registerCallback(callCallback); |
zachh | 78e54ac | 2017-12-05 16:38:35 -0800 | [diff] [blame] | 559 | // TODO(maxwelb): Return the future in recordPhoneLookupInfo and propagate. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 560 | PhoneLookupHistoryRecorder.recordPhoneLookupInfo(context.getApplicationContext(), call); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 561 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | private boolean shouldAttemptBlocking(android.telecom.Call call) { |
| 565 | if (call.getState() != android.telecom.Call.STATE_RINGING) { |
| 566 | return false; |
| 567 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 568 | if (!UserManagerCompat.isUserUnlocked(context)) { |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 569 | LogUtil.i( |
| 570 | "InCallPresenter.shouldAttemptBlocking", |
| 571 | "not attempting to block incoming call because user is locked"); |
| 572 | return false; |
| 573 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 574 | if (TelecomCallUtil.isEmergencyCall(call)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 575 | LogUtil.i( |
| 576 | "InCallPresenter.shouldAttemptBlocking", |
| 577 | "Not attempting to block incoming emergency call"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 578 | return false; |
| 579 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 580 | if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 581 | LogUtil.i( |
| 582 | "InCallPresenter.shouldAttemptBlocking", |
| 583 | "Not attempting to block incoming call due to recent emergency call"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 584 | return false; |
| 585 | } |
| 586 | if (call.getDetails().hasProperty(CallCompat.Details.PROPERTY_IS_EXTERNAL_CALL)) { |
| 587 | return false; |
| 588 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 589 | if (FilteredNumberCompat.useNewFiltering(context)) { |
Eric Erfanian | 83b2021 | 2017-05-31 08:53:10 -0700 | [diff] [blame] | 590 | LogUtil.i( |
| 591 | "InCallPresenter.shouldAttemptBlocking", |
| 592 | "not attempting to block incoming call because framework blocking is in use"); |
| 593 | return false; |
| 594 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 595 | return true; |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * Checks whether a call should be blocked, and blocks it if so. Otherwise, it adds the call to |
| 600 | * the CallList so it can proceed as normal. There is a timeout, so if the function for checking |
| 601 | * whether a function is blocked does not return in a reasonable time, we proceed with adding the |
| 602 | * call anyways. |
| 603 | */ |
| 604 | private void maybeBlockCall(final android.telecom.Call call, final LatencyReport latencyReport) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 605 | final String countryIso = GeoUtil.getCurrentCountryIso(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 606 | final String number = TelecomCallUtil.getNumber(call); |
| 607 | final long timeAdded = System.currentTimeMillis(); |
| 608 | |
| 609 | // Though AtomicBoolean's can be scary, don't fear, as in this case it is only used on the |
| 610 | // main UI thread. It is needed so we can change its value within different scopes, since |
| 611 | // that cannot be done with a final boolean. |
| 612 | final AtomicBoolean hasTimedOut = new AtomicBoolean(false); |
| 613 | |
| 614 | final Handler handler = new Handler(); |
| 615 | |
| 616 | // Proceed if the query is slow; the call may still be blocked after the query returns. |
| 617 | final Runnable runnable = |
| 618 | new Runnable() { |
| 619 | @Override |
| 620 | public void run() { |
| 621 | hasTimedOut.set(true); |
| 622 | latencyReport.onCallBlockingDone(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 623 | callList.onCallAdded(context, call, latencyReport); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 624 | } |
| 625 | }; |
| 626 | handler.postDelayed(runnable, BLOCK_QUERY_TIMEOUT_MS); |
| 627 | |
| 628 | OnCheckBlockedListener onCheckBlockedListener = |
| 629 | new OnCheckBlockedListener() { |
| 630 | @Override |
| 631 | public void onCheckComplete(final Integer id) { |
| 632 | if (isReadyForTearDown()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 633 | LogUtil.i("InCallPresenter.onCheckComplete", "torn down, not adding call"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 634 | return; |
| 635 | } |
| 636 | if (!hasTimedOut.get()) { |
| 637 | handler.removeCallbacks(runnable); |
| 638 | } |
| 639 | if (id == null) { |
| 640 | if (!hasTimedOut.get()) { |
| 641 | latencyReport.onCallBlockingDone(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 642 | callList.onCallAdded(context, call, latencyReport); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 643 | } |
| 644 | } else if (id == FilteredNumberAsyncQueryHandler.INVALID_ID) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 645 | LogUtil.d( |
| 646 | "InCallPresenter.onCheckComplete", "invalid number, skipping block checking"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 647 | if (!hasTimedOut.get()) { |
| 648 | handler.removeCallbacks(runnable); |
| 649 | |
| 650 | latencyReport.onCallBlockingDone(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 651 | callList.onCallAdded(context, call, latencyReport); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 652 | } |
| 653 | } else { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 654 | LogUtil.i( |
| 655 | "InCallPresenter.onCheckComplete", "Rejecting incoming call from blocked number"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 656 | call.reject(false, null); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 657 | Logger.get(context).logInteraction(InteractionEvent.Type.CALL_BLOCKED); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 658 | |
| 659 | /* |
| 660 | * If mContext is null, then the InCallPresenter was torn down before the |
| 661 | * block check had a chance to complete. The context is no longer valid, so |
| 662 | * don't attempt to remove the call log entry. |
| 663 | */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 664 | if (context == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 665 | return; |
| 666 | } |
| 667 | // Register observer to update the call log. |
| 668 | // BlockedNumberContentObserver will unregister after successful log or timeout. |
| 669 | BlockedNumberContentObserver contentObserver = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 670 | new BlockedNumberContentObserver(context, new Handler(), number, timeAdded); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 671 | contentObserver.register(); |
| 672 | } |
| 673 | } |
| 674 | }; |
| 675 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 676 | filteredQueryHandler.isBlockedNumber(onCheckBlockedListener, number, countryIso); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | public void onCallRemoved(android.telecom.Call call) { |
| 680 | if (call.getDetails().hasProperty(CallCompat.Details.PROPERTY_IS_EXTERNAL_CALL)) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 681 | externalCallList.onCallRemoved(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 682 | } else { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 683 | callList.onCallRemoved(context, call); |
| 684 | call.unregisterCallback(callCallback); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
| 688 | public void onCanAddCallChanged(boolean canAddCall) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 689 | for (CanAddCallListener listener : canAddCallListeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 690 | listener.onCanAddCallChanged(canAddCall); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | @Override |
| 695 | public void onWiFiToLteHandover(DialerCall call) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 696 | if (inCallActivity != null) { |
| 697 | inCallActivity.showToastForWiFiToLteHandover(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | |
| 701 | @Override |
| 702 | public void onHandoverToWifiFailed(DialerCall call) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 703 | if (inCallActivity != null) { |
| 704 | inCallActivity.showDialogOrToastForWifiHandoverFailure(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 708 | @Override |
| 709 | public void onInternationalCallOnWifi(@NonNull DialerCall call) { |
| 710 | LogUtil.enterBlock("InCallPresenter.onInternationalCallOnWifi"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 711 | if (inCallActivity != null) { |
| 712 | inCallActivity.showDialogForInternationalCallOnWifi(call); |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 716 | /** |
| 717 | * Called when there is a change to the call list. Sets the In-Call state for the entire in-call |
| 718 | * app based on the information it gets from CallList. Dispatches the in-call state to all |
| 719 | * listeners. Can trigger the creation or destruction of the UI based on the states that is |
| 720 | * calculates. |
| 721 | */ |
| 722 | @Override |
| 723 | public void onCallListChange(CallList callList) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 724 | Trace.beginSection("InCallPresenter.onCallListChange"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 725 | if (inCallActivity != null && inCallActivity.isInCallScreenAnimating()) { |
| 726 | awaitingCallListUpdate = true; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 727 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 728 | return; |
| 729 | } |
| 730 | if (callList == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 731 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 732 | return; |
| 733 | } |
| 734 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 735 | awaitingCallListUpdate = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 736 | |
| 737 | InCallState newState = getPotentialStateFromCallList(callList); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 738 | InCallState oldState = inCallState; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 739 | LogUtil.d( |
| 740 | "InCallPresenter.onCallListChange", |
| 741 | "onCallListChange oldState= " + oldState + " newState=" + newState); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 742 | |
| 743 | // If the user placed a call and was asked to choose the account, but then pressed "Home", the |
| 744 | // incall activity for that call will still exist (even if it's not visible). In the case of |
| 745 | // an incoming call in that situation, just disconnect that "waiting for account" call and |
| 746 | // dismiss the dialog. The same activity will be reused to handle the new incoming call. See |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 747 | // a bug for more details. |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 748 | DialerCall waitingForAccountCall; |
| 749 | if (newState == InCallState.INCOMING |
| 750 | && (waitingForAccountCall = callList.getWaitingForAccountCall()) != null) { |
| 751 | waitingForAccountCall.disconnect(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 752 | // The InCallActivity might be destroyed or not started yet at this point. |
| 753 | if (isActivityStarted()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 754 | inCallActivity.dismissPendingDialogs(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 755 | } |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 758 | newState = startOrFinishUi(newState); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 759 | LogUtil.d( |
| 760 | "InCallPresenter.onCallListChange", "onCallListChange newState changed to " + newState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 761 | |
| 762 | // Set the new state before announcing it to the world |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 763 | LogUtil.i( |
| 764 | "InCallPresenter.onCallListChange", |
| 765 | "Phone switching state: " + oldState + " -> " + newState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 766 | inCallState = newState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 767 | |
| 768 | // notify listeners of new state |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 769 | for (InCallStateListener listener : listeners) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 770 | LogUtil.d( |
| 771 | "InCallPresenter.onCallListChange", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 772 | "Notify " + listener + " of state " + inCallState.toString()); |
| 773 | listener.onStateChange(oldState, inCallState, callList); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | if (isActivityStarted()) { |
| 777 | final boolean hasCall = |
| 778 | callList.getActiveOrBackgroundCall() != null || callList.getOutgoingCall() != null; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 779 | inCallActivity.dismissKeyguard(hasCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 780 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 781 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | /** Called when there is a new incoming call. */ |
| 785 | @Override |
| 786 | public void onIncomingCall(DialerCall call) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 787 | Trace.beginSection("InCallPresenter.onIncomingCall"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 788 | InCallState newState = startOrFinishUi(InCallState.INCOMING); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 789 | InCallState oldState = inCallState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 790 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 791 | LogUtil.i( |
| 792 | "InCallPresenter.onIncomingCall", "Phone switching state: " + oldState + " -> " + newState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 793 | inCallState = newState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 794 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 795 | Trace.beginSection("listener.onIncomingCall"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 796 | for (IncomingCallListener listener : incomingCallListeners) { |
| 797 | listener.onIncomingCall(oldState, inCallState, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 798 | } |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 799 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 800 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 801 | Trace.beginSection("onPrimaryCallStateChanged"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 802 | if (inCallActivity != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 803 | // Re-evaluate which fragment is being shown. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 804 | inCallActivity.onPrimaryCallStateChanged(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 805 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 806 | Trace.endSection(); |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 807 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | @Override |
| 811 | public void onUpgradeToVideo(DialerCall call) { |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 812 | if (VideoUtils.hasReceivedVideoUpgradeRequest(call.getVideoTech().getSessionModificationState()) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 813 | && inCallState == InCallPresenter.InCallState.INCOMING) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 814 | LogUtil.i( |
| 815 | "InCallPresenter.onUpgradeToVideo", |
| 816 | "rejecting upgrade request due to existing incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 817 | call.getVideoTech().declineVideoRequest(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 818 | } |
| 819 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 820 | if (inCallActivity != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 821 | // Re-evaluate which fragment is being shown. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 822 | inCallActivity.onPrimaryCallStateChanged(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
| 826 | @Override |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 827 | public void onSessionModificationStateChange(DialerCall call) { |
| 828 | int newState = call.getVideoTech().getSessionModificationState(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 829 | LogUtil.i("InCallPresenter.onSessionModificationStateChange", "state: %d", newState); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 830 | if (proximitySensor == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 831 | LogUtil.i("InCallPresenter.onSessionModificationStateChange", "proximitySensor is null"); |
| 832 | return; |
| 833 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 834 | proximitySensor.setIsAttemptingVideoCall( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 835 | call.hasSentVideoUpgradeRequest() || call.hasReceivedVideoUpgradeRequest()); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 836 | if (inCallActivity != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 837 | // Re-evaluate which fragment is being shown. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 838 | inCallActivity.onPrimaryCallStateChanged(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 839 | } |
| 840 | } |
| 841 | |
| 842 | /** |
| 843 | * Called when a call becomes disconnected. Called everytime an existing call changes from being |
| 844 | * connected (incoming/outgoing/active) to disconnected. |
| 845 | */ |
| 846 | @Override |
| 847 | public void onDisconnect(DialerCall call) { |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 848 | showDialogOrToastForDisconnectedCall(call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 849 | |
| 850 | // We need to do the run the same code as onCallListChange. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 851 | onCallListChange(callList); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 852 | |
| 853 | if (isActivityStarted()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 854 | inCallActivity.dismissKeyguard(false); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | if (call.isEmergencyCall()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 858 | FilteredNumbersUtil.recordLastEmergencyCallTime(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 859 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 860 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 861 | if (!callList.hasLiveCall() |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 862 | && !call.getLogState().isIncoming |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 863 | && !isSecretCode(call.getNumber()) |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 864 | && !call.isVoiceMailNumber()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 865 | PostCall.onCallDisconnected(context, call.getNumber(), call.getConnectTimeMillis()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 866 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 867 | } |
| 868 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 869 | private boolean isSecretCode(@Nullable String number) { |
| 870 | return number != null |
| 871 | && (number.length() <= 8 || number.startsWith("*#*#") || number.endsWith("#*#*")); |
| 872 | } |
| 873 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 874 | /** Given the call list, return the state in which the in-call screen should be. */ |
| 875 | public InCallState getPotentialStateFromCallList(CallList callList) { |
| 876 | |
| 877 | InCallState newState = InCallState.NO_CALLS; |
| 878 | |
| 879 | if (callList == null) { |
| 880 | return newState; |
| 881 | } |
| 882 | if (callList.getIncomingCall() != null) { |
| 883 | newState = InCallState.INCOMING; |
| 884 | } else if (callList.getWaitingForAccountCall() != null) { |
| 885 | newState = InCallState.WAITING_FOR_ACCOUNT; |
| 886 | } else if (callList.getPendingOutgoingCall() != null) { |
| 887 | newState = InCallState.PENDING_OUTGOING; |
| 888 | } else if (callList.getOutgoingCall() != null) { |
| 889 | newState = InCallState.OUTGOING; |
| 890 | } else if (callList.getActiveCall() != null |
| 891 | || callList.getBackgroundCall() != null |
| 892 | || callList.getDisconnectedCall() != null |
| 893 | || callList.getDisconnectingCall() != null) { |
| 894 | newState = InCallState.INCALL; |
| 895 | } |
| 896 | |
| 897 | if (newState == InCallState.NO_CALLS) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 898 | if (boundAndWaitingForOutgoingCall) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 899 | return InCallState.PENDING_OUTGOING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 900 | } |
| 901 | } |
| 902 | |
| 903 | return newState; |
| 904 | } |
| 905 | |
| 906 | public boolean isBoundAndWaitingForOutgoingCall() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 907 | return boundAndWaitingForOutgoingCall; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | public void setBoundAndWaitingForOutgoingCall(boolean isBound, PhoneAccountHandle handle) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 911 | LogUtil.i( |
| 912 | "InCallPresenter.setBoundAndWaitingForOutgoingCall", |
| 913 | "setBoundAndWaitingForOutgoingCall: " + isBound); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 914 | boundAndWaitingForOutgoingCall = isBound; |
| 915 | themeColorManager.setPendingPhoneAccountHandle(handle); |
| 916 | if (isBound && inCallState == InCallState.NO_CALLS) { |
| 917 | inCallState = InCallState.PENDING_OUTGOING; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 918 | } |
| 919 | } |
| 920 | |
| 921 | public void onShrinkAnimationComplete() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 922 | if (awaitingCallListUpdate) { |
| 923 | onCallListChange(callList); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 924 | } |
| 925 | } |
| 926 | |
| 927 | public void addIncomingCallListener(IncomingCallListener listener) { |
| 928 | Objects.requireNonNull(listener); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 929 | incomingCallListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | public void removeIncomingCallListener(IncomingCallListener listener) { |
| 933 | if (listener != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 934 | incomingCallListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
| 938 | public void addListener(InCallStateListener listener) { |
| 939 | Objects.requireNonNull(listener); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 940 | listeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | public void removeListener(InCallStateListener listener) { |
| 944 | if (listener != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 945 | listeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | public void addDetailsListener(InCallDetailsListener listener) { |
| 950 | Objects.requireNonNull(listener); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 951 | detailsListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | public void removeDetailsListener(InCallDetailsListener listener) { |
| 955 | if (listener != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 956 | detailsListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
| 960 | public void addCanAddCallListener(CanAddCallListener listener) { |
| 961 | Objects.requireNonNull(listener); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 962 | canAddCallListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | public void removeCanAddCallListener(CanAddCallListener listener) { |
| 966 | if (listener != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 967 | canAddCallListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 968 | } |
| 969 | } |
| 970 | |
| 971 | public void addOrientationListener(InCallOrientationListener listener) { |
| 972 | Objects.requireNonNull(listener); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 973 | orientationListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | public void removeOrientationListener(InCallOrientationListener listener) { |
| 977 | if (listener != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 978 | orientationListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | public void addInCallEventListener(InCallEventListener listener) { |
| 983 | Objects.requireNonNull(listener); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 984 | inCallEventListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | public void removeInCallEventListener(InCallEventListener listener) { |
| 988 | if (listener != null) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 989 | inCallEventListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
| 993 | public ProximitySensor getProximitySensor() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 994 | return proximitySensor; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | public PseudoScreenState getPseudoScreenState() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 998 | return pseudoScreenState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | /** Returns true if the incall app is the foreground application. */ |
| 1002 | public boolean isShowingInCallUi() { |
| 1003 | if (!isActivityStarted()) { |
| 1004 | return false; |
| 1005 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1006 | if (manageConferenceActivity != null && manageConferenceActivity.isVisible()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1007 | return true; |
| 1008 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1009 | return inCallActivity.isVisible(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * Returns true if the activity has been created and is running. Returns true as long as activity |
| 1014 | * is not destroyed or finishing. This ensures that we return true even if the activity is paused |
| 1015 | * (not in foreground). |
| 1016 | */ |
| 1017 | public boolean isActivityStarted() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1018 | return (inCallActivity != null |
| 1019 | && !inCallActivity.isDestroyed() |
| 1020 | && !inCallActivity.isFinishing()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * Determines if the In-Call app is currently changing configuration. |
| 1025 | * |
| 1026 | * @return {@code true} if the In-Call app is changing configuration. |
| 1027 | */ |
| 1028 | public boolean isChangingConfigurations() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1029 | return isChangingConfigurations; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * Tracks whether the In-Call app is currently in the process of changing configuration (i.e. |
| 1034 | * screen orientation). |
| 1035 | */ |
| 1036 | /*package*/ |
| 1037 | void updateIsChangingConfigurations() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1038 | isChangingConfigurations = false; |
| 1039 | if (inCallActivity != null) { |
| 1040 | isChangingConfigurations = inCallActivity.isChangingConfigurations(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1041 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1042 | LogUtil.v( |
| 1043 | "InCallPresenter.updateIsChangingConfigurations", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1044 | "updateIsChangingConfigurations = " + isChangingConfigurations); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1045 | } |
| 1046 | |
yueg | 10f6e82 | 2018-01-17 15:32:18 -0800 | [diff] [blame^] | 1047 | void updateNotification() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1048 | // We need to update the notification bar when we leave the UI because that |
| 1049 | // could trigger it to show again. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1050 | if (statusBarNotifier != null) { |
| 1051 | statusBarNotifier.updateNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1052 | } |
yueg | 10f6e82 | 2018-01-17 15:32:18 -0800 | [diff] [blame^] | 1053 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1054 | |
yueg | 10f6e82 | 2018-01-17 15:32:18 -0800 | [diff] [blame^] | 1055 | /** Called when the activity goes in/out of the foreground. */ |
| 1056 | public void onUiShowing(boolean showing) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1057 | if (proximitySensor != null) { |
| 1058 | proximitySensor.onInCallShowing(showing); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
yueg | 092b21c | 2017-11-15 16:20:07 -0800 | [diff] [blame] | 1061 | if (!showing) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1062 | updateIsChangingConfigurations(); |
| 1063 | } |
| 1064 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1065 | for (InCallUiListener listener : inCallUiListeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1066 | listener.onUiShowing(showing); |
| 1067 | } |
| 1068 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1069 | if (inCallActivity != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1070 | // Re-evaluate which fragment is being shown. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1071 | inCallActivity.onPrimaryCallStateChanged(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1072 | } |
| 1073 | } |
| 1074 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1075 | public void refreshUi() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1076 | if (inCallActivity != null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1077 | // Re-evaluate which fragment is being shown. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1078 | inCallActivity.onPrimaryCallStateChanged(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1082 | public void addInCallUiListener(InCallUiListener listener) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1083 | inCallUiListeners.add(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | public boolean removeInCallUiListener(InCallUiListener listener) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1087 | return inCallUiListeners.remove(listener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | /*package*/ |
| 1091 | void onActivityStarted() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1092 | LogUtil.d("InCallPresenter.onActivityStarted", "onActivityStarted"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1093 | notifyVideoPauseController(true); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1094 | applyScreenTimeout(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /*package*/ |
| 1098 | void onActivityStopped() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1099 | LogUtil.d("InCallPresenter.onActivityStopped", "onActivityStopped"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1100 | notifyVideoPauseController(false); |
| 1101 | } |
| 1102 | |
| 1103 | private void notifyVideoPauseController(boolean showing) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1104 | LogUtil.d( |
| 1105 | "InCallPresenter.notifyVideoPauseController", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1106 | "mIsChangingConfigurations=" + isChangingConfigurations); |
| 1107 | if (!isChangingConfigurations) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1108 | VideoPauseController.getInstance().onUiShowing(showing); |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | /** Brings the app into the foreground if possible. */ |
| 1113 | public void bringToForeground(boolean showDialpad) { |
| 1114 | // Before we bring the incall UI to the foreground, we check to see if: |
| 1115 | // 1. It is not currently in the foreground |
| 1116 | // 2. We are in a state where we want to show the incall ui (i.e. there are calls to |
| 1117 | // be displayed) |
| 1118 | // If the activity hadn't actually been started previously, yet there are still calls |
| 1119 | // present (e.g. a call was accepted by a bluetooth or wired headset), we want to |
| 1120 | // bring it up the UI regardless. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1121 | if (!isShowingInCallUi() && inCallState != InCallState.NO_CALLS) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1122 | showInCall(showDialpad, false /* newOutgoingCall */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | public void onPostDialCharWait(String callId, String chars) { |
| 1127 | if (isActivityStarted()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1128 | inCallActivity.showDialogForPostCharWait(callId, chars); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | /** |
| 1133 | * Handles the green CALL key while in-call. |
| 1134 | * |
| 1135 | * @return true if we consumed the event. |
| 1136 | */ |
| 1137 | public boolean handleCallKey() { |
| 1138 | LogUtil.v("InCallPresenter.handleCallKey", null); |
| 1139 | |
| 1140 | // The green CALL button means either "Answer", "Unhold", or |
| 1141 | // "Swap calls", or can be a no-op, depending on the current state |
| 1142 | // of the Phone. |
| 1143 | |
| 1144 | /** INCOMING CALL */ |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1145 | final CallList calls = callList; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1146 | final DialerCall incomingCall = calls.getIncomingCall(); |
| 1147 | LogUtil.v("InCallPresenter.handleCallKey", "incomingCall: " + incomingCall); |
| 1148 | |
| 1149 | // (1) Attempt to answer a call |
| 1150 | if (incomingCall != null) { |
| 1151 | incomingCall.answer(VideoProfile.STATE_AUDIO_ONLY); |
| 1152 | return true; |
| 1153 | } |
| 1154 | |
| 1155 | /** STATE_ACTIVE CALL */ |
| 1156 | final DialerCall activeCall = calls.getActiveCall(); |
| 1157 | if (activeCall != null) { |
| 1158 | // TODO: This logic is repeated from CallButtonPresenter.java. We should |
| 1159 | // consolidate this logic. |
| 1160 | final boolean canMerge = |
| 1161 | activeCall.can(android.telecom.Call.Details.CAPABILITY_MERGE_CONFERENCE); |
| 1162 | final boolean canSwap = |
| 1163 | activeCall.can(android.telecom.Call.Details.CAPABILITY_SWAP_CONFERENCE); |
| 1164 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1165 | LogUtil.v( |
| 1166 | "InCallPresenter.handleCallKey", |
| 1167 | "activeCall: " + activeCall + ", canMerge: " + canMerge + ", canSwap: " + canSwap); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1168 | |
| 1169 | // (2) Attempt actions on conference calls |
| 1170 | if (canMerge) { |
| 1171 | TelecomAdapter.getInstance().merge(activeCall.getId()); |
| 1172 | return true; |
| 1173 | } else if (canSwap) { |
| 1174 | TelecomAdapter.getInstance().swap(activeCall.getId()); |
| 1175 | return true; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | /** BACKGROUND CALL */ |
| 1180 | final DialerCall heldCall = calls.getBackgroundCall(); |
| 1181 | if (heldCall != null) { |
| 1182 | // We have a hold call so presumeable it will always support HOLD...but |
| 1183 | // there is no harm in double checking. |
| 1184 | final boolean canHold = heldCall.can(android.telecom.Call.Details.CAPABILITY_HOLD); |
| 1185 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1186 | LogUtil.v("InCallPresenter.handleCallKey", "heldCall: " + heldCall + ", canHold: " + canHold); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1187 | |
| 1188 | // (4) unhold call |
| 1189 | if (heldCall.getState() == DialerCall.State.ONHOLD && canHold) { |
| 1190 | heldCall.unhold(); |
| 1191 | return true; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | // Always consume hard keys |
| 1196 | return true; |
| 1197 | } |
| 1198 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1199 | /** Clears the previous fullscreen state. */ |
| 1200 | public void clearFullscreen() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1201 | isFullScreen = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * Changes the fullscreen mode of the in-call UI. |
| 1206 | * |
| 1207 | * @param isFullScreen {@code true} if in-call should be in fullscreen mode, {@code false} |
| 1208 | * otherwise. |
| 1209 | */ |
| 1210 | public void setFullScreen(boolean isFullScreen) { |
| 1211 | setFullScreen(isFullScreen, false /* force */); |
| 1212 | } |
| 1213 | |
| 1214 | /** |
| 1215 | * Changes the fullscreen mode of the in-call UI. |
| 1216 | * |
| 1217 | * @param isFullScreen {@code true} if in-call should be in fullscreen mode, {@code false} |
| 1218 | * otherwise. |
| 1219 | * @param force {@code true} if fullscreen mode should be set regardless of its current state. |
| 1220 | */ |
| 1221 | public void setFullScreen(boolean isFullScreen, boolean force) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1222 | LogUtil.i("InCallPresenter.setFullScreen", "setFullScreen = " + isFullScreen); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1223 | |
| 1224 | // As a safeguard, ensure we cannot enter fullscreen if the dialpad is shown. |
| 1225 | if (isDialpadVisible()) { |
| 1226 | isFullScreen = false; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1227 | LogUtil.v( |
| 1228 | "InCallPresenter.setFullScreen", |
| 1229 | "setFullScreen overridden as dialpad is shown = " + isFullScreen); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1232 | if (this.isFullScreen == isFullScreen && !force) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1233 | LogUtil.v("InCallPresenter.setFullScreen", "setFullScreen ignored as already in that state."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1234 | return; |
| 1235 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1236 | this.isFullScreen = isFullScreen; |
| 1237 | notifyFullscreenModeChange(this.isFullScreen); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | /** |
| 1241 | * @return {@code true} if the in-call ui is currently in fullscreen mode, {@code false} |
| 1242 | * otherwise. |
| 1243 | */ |
| 1244 | public boolean isFullscreen() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1245 | return isFullScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /** |
| 1249 | * Called by the {@link VideoCallPresenter} to inform of a change in full screen video status. |
| 1250 | * |
| 1251 | * @param isFullscreenMode {@code True} if entering full screen mode. |
| 1252 | */ |
| 1253 | public void notifyFullscreenModeChange(boolean isFullscreenMode) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1254 | for (InCallEventListener listener : inCallEventListeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1255 | listener.onFullscreenModeChanged(isFullscreenMode); |
| 1256 | } |
| 1257 | } |
| 1258 | |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1259 | /** Instruct the in-call activity to show an error dialog or toast for a disconnected call. */ |
| 1260 | private void showDialogOrToastForDisconnectedCall(DialerCall call) { |
| 1261 | if (!isActivityStarted() || call.getState() != DialerCall.State.DISCONNECTED) { |
| 1262 | return; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1263 | } |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1264 | |
| 1265 | // For newly disconnected calls, we may want to show a dialog on specific error conditions |
| 1266 | if (call.getAccountHandle() == null && !call.isConferenceCall()) { |
| 1267 | setDisconnectCauseForMissingAccounts(call); |
| 1268 | } |
| 1269 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1270 | inCallActivity.showDialogOrToastForDisconnectedCall( |
| 1271 | new DisconnectMessage(inCallActivity, call)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | /** |
| 1275 | * When the state of in-call changes, this is the first method to get called. It determines if the |
| 1276 | * UI needs to be started or finished depending on the new state and does it. |
| 1277 | */ |
| 1278 | private InCallState startOrFinishUi(InCallState newState) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 1279 | Trace.beginSection("InCallPresenter.startOrFinishUi"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1280 | LogUtil.d( |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1281 | "InCallPresenter.startOrFinishUi", "startOrFinishUi: " + inCallState + " -> " + newState); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1282 | |
| 1283 | // TODO: Consider a proper state machine implementation |
| 1284 | |
| 1285 | // If the state isn't changing we have already done any starting/stopping of activities in |
| 1286 | // a previous pass...so lets cut out early |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1287 | if (newState == inCallState) { |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 1288 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1289 | return newState; |
| 1290 | } |
| 1291 | |
| 1292 | // A new Incoming call means that the user needs to be notified of the the call (since |
| 1293 | // it wasn't them who initiated it). We do this through full screen notifications and |
| 1294 | // happens indirectly through {@link StatusBarNotifier}. |
| 1295 | // |
| 1296 | // The process for incoming calls is as follows: |
| 1297 | // |
| 1298 | // 1) CallList - Announces existence of new INCOMING call |
| 1299 | // 2) InCallPresenter - Gets announcement and calculates that the new InCallState |
| 1300 | // - should be set to INCOMING. |
| 1301 | // 3) InCallPresenter - This method is called to see if we need to start or finish |
| 1302 | // the app given the new state. |
| 1303 | // 4) StatusBarNotifier - Listens to InCallState changes. InCallPresenter calls |
| 1304 | // StatusBarNotifier explicitly to issue a FullScreen Notification |
| 1305 | // that will either start the InCallActivity or show the user a |
| 1306 | // top-level notification dialog if the user is in an immersive app. |
| 1307 | // That notification can also start the InCallActivity. |
| 1308 | // 5) InCallActivity - Main activity starts up and at the end of its onCreate will |
| 1309 | // call InCallPresenter::setActivity() to let the presenter |
| 1310 | // know that start-up is complete. |
| 1311 | // |
| 1312 | // [ AND NOW YOU'RE IN THE CALL. voila! ] |
| 1313 | // |
| 1314 | // Our app is started using a fullScreen notification. We need to do this whenever |
| 1315 | // we get an incoming call. Depending on the current context of the device, either a |
| 1316 | // incoming call HUN or the actual InCallActivity will be shown. |
| 1317 | final boolean startIncomingCallSequence = (InCallState.INCOMING == newState); |
| 1318 | |
| 1319 | // A dialog to show on top of the InCallUI to select a PhoneAccount |
| 1320 | final boolean showAccountPicker = (InCallState.WAITING_FOR_ACCOUNT == newState); |
| 1321 | |
| 1322 | // A new outgoing call indicates that the user just now dialed a number and when that |
| 1323 | // happens we need to display the screen immediately or show an account picker dialog if |
| 1324 | // no default is set. However, if the main InCallUI is already visible, we do not want to |
| 1325 | // re-initiate the start-up animation, so we do not need to do anything here. |
| 1326 | // |
| 1327 | // It is also possible to go into an intermediate state where the call has been initiated |
| 1328 | // but Telecom has not yet returned with the details of the call (handle, gateway, etc.). |
| 1329 | // This pending outgoing state can also launch the call screen. |
| 1330 | // |
| 1331 | // This is different from the incoming call sequence because we do not need to shock the |
| 1332 | // user with a top-level notification. Just show the call UI normally. |
| 1333 | boolean callCardFragmentVisible = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1334 | inCallActivity != null && inCallActivity.getCallCardFragmentVisible(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1335 | final boolean mainUiNotVisible = !isShowingInCallUi() || !callCardFragmentVisible; |
| 1336 | boolean showCallUi = InCallState.OUTGOING == newState && mainUiNotVisible; |
| 1337 | |
| 1338 | // Direct transition from PENDING_OUTGOING -> INCALL means that there was an error in the |
| 1339 | // outgoing call process, so the UI should be brought up to show an error dialog. |
| 1340 | showCallUi |= |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1341 | (InCallState.PENDING_OUTGOING == inCallState |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1342 | && InCallState.INCALL == newState |
| 1343 | && !isShowingInCallUi()); |
| 1344 | |
| 1345 | // Another exception - InCallActivity is in charge of disconnecting a call with no |
| 1346 | // valid accounts set. Bring the UI up if this is true for the current pending outgoing |
| 1347 | // call so that: |
| 1348 | // 1) The call can be disconnected correctly |
| 1349 | // 2) The UI comes up and correctly displays the error dialog. |
| 1350 | // TODO: Remove these special case conditions by making InCallPresenter a true state |
| 1351 | // machine. Telecom should also be the component responsible for disconnecting a call |
| 1352 | // with no valid accounts. |
| 1353 | showCallUi |= |
| 1354 | InCallState.PENDING_OUTGOING == newState |
| 1355 | && mainUiNotVisible |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1356 | && isCallWithNoValidAccounts(callList.getPendingOutgoingCall()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1357 | |
| 1358 | // The only time that we have an instance of mInCallActivity and it isn't started is |
| 1359 | // when it is being destroyed. In that case, lets avoid bringing up another instance of |
| 1360 | // the activity. When it is finally destroyed, we double check if we should bring it back |
| 1361 | // up so we aren't going to lose anything by avoiding a second startup here. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1362 | boolean activityIsFinishing = inCallActivity != null && !isActivityStarted(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1363 | if (activityIsFinishing) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1364 | LogUtil.i( |
| 1365 | "InCallPresenter.startOrFinishUi", |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1366 | "Undo the state change: " + newState + " -> " + inCallState); |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 1367 | Trace.endSection(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1368 | return inCallState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | // We're about the bring up the in-call UI for outgoing and incoming call. If we still have |
| 1372 | // dialogs up, we need to clear them out before showing in-call screen. This is necessary |
| 1373 | // to fix the bug that dialog will show up when data reaches limit even after makeing new |
| 1374 | // outgoing call after user ignore it by pressing home button. |
| 1375 | if ((newState == InCallState.INCOMING || newState == InCallState.PENDING_OUTGOING) |
| 1376 | && !showCallUi |
| 1377 | && isActivityStarted()) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1378 | inCallActivity.dismissPendingDialogs(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | if (showCallUi || showAccountPicker) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1382 | LogUtil.i("InCallPresenter.startOrFinishUi", "Start in call UI"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1383 | showInCall(false /* showDialpad */, !showAccountPicker /* newOutgoingCall */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1384 | } else if (startIncomingCallSequence) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1385 | LogUtil.i("InCallPresenter.startOrFinishUi", "Start Full Screen in call UI"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1386 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1387 | statusBarNotifier.updateNotification(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1388 | } else if (newState == InCallState.NO_CALLS) { |
| 1389 | // The new state is the no calls state. Tear everything down. |
| 1390 | attemptFinishActivity(); |
| 1391 | attemptCleanup(); |
| 1392 | } |
| 1393 | |
wangqi | cf61ca0 | 2017-08-31 15:32:55 -0700 | [diff] [blame] | 1394 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1395 | return newState; |
| 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * Sets the DisconnectCause for a call that was disconnected because it was missing a PhoneAccount |
| 1400 | * or PhoneAccounts to select from. |
| 1401 | */ |
| 1402 | private void setDisconnectCauseForMissingAccounts(DialerCall call) { |
| 1403 | |
| 1404 | Bundle extras = call.getIntentExtras(); |
| 1405 | // Initialize the extras bundle to avoid NPE |
| 1406 | if (extras == null) { |
| 1407 | extras = new Bundle(); |
| 1408 | } |
| 1409 | |
| 1410 | final List<PhoneAccountHandle> phoneAccountHandles = |
| 1411 | extras.getParcelableArrayList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS); |
| 1412 | |
| 1413 | if (phoneAccountHandles == null || phoneAccountHandles.isEmpty()) { |
| 1414 | String scheme = call.getHandle().getScheme(); |
| 1415 | final String errorMsg = |
| 1416 | PhoneAccount.SCHEME_TEL.equals(scheme) |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1417 | ? context.getString(R.string.callFailed_simError) |
| 1418 | : context.getString(R.string.incall_error_supp_service_unknown); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1419 | DisconnectCause disconnectCause = |
| 1420 | new DisconnectCause(DisconnectCause.ERROR, null, errorMsg, errorMsg); |
| 1421 | call.setDisconnectCause(disconnectCause); |
| 1422 | } |
| 1423 | } |
| 1424 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1425 | /** |
| 1426 | * @return {@code true} if the InCallPresenter is ready to be torn down, {@code false} otherwise. |
| 1427 | * Calling classes should use this as an indication whether to interact with the |
| 1428 | * InCallPresenter or not. |
| 1429 | */ |
| 1430 | public boolean isReadyForTearDown() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1431 | return inCallActivity == null && !serviceConnected && inCallState == InCallState.NO_CALLS; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | /** |
| 1435 | * Checks to see if both the UI is gone and the service is disconnected. If so, tear it all down. |
| 1436 | */ |
| 1437 | private void attemptCleanup() { |
| 1438 | if (isReadyForTearDown()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1439 | LogUtil.i("InCallPresenter.attemptCleanup", "Cleaning up"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1440 | |
| 1441 | cleanupSurfaces(); |
| 1442 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1443 | isChangingConfigurations = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1444 | |
| 1445 | // blow away stale contact info so that we get fresh data on |
| 1446 | // the next set of calls |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1447 | if (contactInfoCache != null) { |
| 1448 | contactInfoCache.clearCache(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1449 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1450 | contactInfoCache = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1451 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1452 | if (proximitySensor != null) { |
| 1453 | removeListener(proximitySensor); |
| 1454 | proximitySensor.tearDown(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1455 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1456 | proximitySensor = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1457 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1458 | if (statusBarNotifier != null) { |
| 1459 | removeListener(statusBarNotifier); |
| 1460 | EnrichedCallComponent.get(context) |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1461 | .getEnrichedCallManager() |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1462 | .unregisterStateChangedListener(statusBarNotifier); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1463 | } |
Eric Erfanian | d8046e5 | 2017-04-06 09:41:50 -0700 | [diff] [blame] | 1464 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1465 | if (externalCallNotifier != null && externalCallList != null) { |
| 1466 | externalCallList.removeExternalCallListener(externalCallNotifier); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1467 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1468 | statusBarNotifier = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1469 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1470 | if (callList != null) { |
| 1471 | callList.removeListener(this); |
| 1472 | callList.removeListener(spamCallListListener); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1473 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1474 | callList = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1475 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1476 | context = null; |
| 1477 | inCallActivity = null; |
| 1478 | manageConferenceActivity = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1479 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1480 | listeners.clear(); |
| 1481 | incomingCallListeners.clear(); |
| 1482 | detailsListeners.clear(); |
| 1483 | canAddCallListeners.clear(); |
| 1484 | orientationListeners.clear(); |
| 1485 | inCallEventListeners.clear(); |
| 1486 | inCallUiListeners.clear(); |
| 1487 | if (!inCallUiLocks.isEmpty()) { |
| 1488 | LogUtil.e("InCallPresenter.attemptCleanup", "held in call locks: " + inCallUiLocks); |
| 1489 | inCallUiLocks.clear(); |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1490 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1491 | LogUtil.d("InCallPresenter.attemptCleanup", "finished"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1492 | } |
| 1493 | } |
| 1494 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1495 | public void showInCall(boolean showDialpad, boolean newOutgoingCall) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1496 | LogUtil.i("InCallPresenter.showInCall", "Showing InCallActivity"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1497 | context.startActivity( |
| 1498 | InCallActivity.getIntent(context, showDialpad, newOutgoingCall, false /* forFullScreen */)); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | public void onServiceBind() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1502 | serviceBound = true; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | public void onServiceUnbind() { |
| 1506 | InCallPresenter.getInstance().setBoundAndWaitingForOutgoingCall(false, null); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1507 | serviceBound = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1508 | } |
| 1509 | |
| 1510 | public boolean isServiceBound() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1511 | return serviceBound; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | public void maybeStartRevealAnimation(Intent intent) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1515 | if (intent == null || inCallActivity != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1516 | return; |
| 1517 | } |
| 1518 | final Bundle extras = intent.getBundleExtra(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS); |
| 1519 | if (extras == null) { |
| 1520 | // Incoming call, just show the in-call UI directly. |
| 1521 | return; |
| 1522 | } |
| 1523 | |
| 1524 | if (extras.containsKey(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS)) { |
| 1525 | // Account selection dialog will show up so don't show the animation. |
| 1526 | return; |
| 1527 | } |
| 1528 | |
| 1529 | final PhoneAccountHandle accountHandle = |
| 1530 | intent.getParcelableExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE); |
| 1531 | final Point touchPoint = extras.getParcelable(TouchPointManager.TOUCH_POINT); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1532 | |
| 1533 | InCallPresenter.getInstance().setBoundAndWaitingForOutgoingCall(true, accountHandle); |
| 1534 | |
| 1535 | final Intent activityIntent = |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1536 | InCallActivity.getIntent(context, false, true, false /* forFullScreen */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1537 | activityIntent.putExtra(TouchPointManager.TOUCH_POINT, touchPoint); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1538 | context.startActivity(activityIntent); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | /** |
| 1542 | * Retrieves the current in-call camera manager instance, creating if necessary. |
| 1543 | * |
| 1544 | * @return The {@link InCallCameraManager}. |
| 1545 | */ |
| 1546 | public InCallCameraManager getInCallCameraManager() { |
| 1547 | synchronized (this) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1548 | if (inCallCameraManager == null) { |
| 1549 | inCallCameraManager = new InCallCameraManager(context); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1550 | } |
| 1551 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1552 | return inCallCameraManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | /** |
| 1557 | * Notifies listeners of changes in orientation and notify calls of rotation angle change. |
| 1558 | * |
| 1559 | * @param orientation The screen orientation of the device (one of: {@link |
| 1560 | * InCallOrientationEventListener#SCREEN_ORIENTATION_0}, {@link |
| 1561 | * InCallOrientationEventListener#SCREEN_ORIENTATION_90}, {@link |
| 1562 | * InCallOrientationEventListener#SCREEN_ORIENTATION_180}, {@link |
| 1563 | * InCallOrientationEventListener#SCREEN_ORIENTATION_270}). |
| 1564 | */ |
| 1565 | public void onDeviceOrientationChange(@ScreenOrientation int orientation) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1566 | LogUtil.d( |
| 1567 | "InCallPresenter.onDeviceOrientationChange", |
| 1568 | "onDeviceOrientationChange: orientation= " + orientation); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1569 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1570 | if (callList != null) { |
| 1571 | callList.notifyCallsOfDeviceRotation(orientation); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1572 | } else { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1573 | LogUtil.w("InCallPresenter.onDeviceOrientationChange", "CallList is null."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | // Notify listeners of device orientation changed. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1577 | for (InCallOrientationListener listener : orientationListeners) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1578 | listener.onDeviceOrientationChanged(orientation); |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * Configures the in-call UI activity so it can change orientations or not. Enables the |
| 1584 | * orientation event listener if allowOrientationChange is true, disables it if false. |
| 1585 | * |
| 1586 | * @param allowOrientationChange {@code true} if the in-call UI can change between portrait and |
| 1587 | * landscape. {@code false} if the in-call UI should be locked in portrait. |
| 1588 | */ |
| 1589 | public void setInCallAllowsOrientationChange(boolean allowOrientationChange) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1590 | if (inCallActivity == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1591 | LogUtil.e( |
| 1592 | "InCallPresenter.setInCallAllowsOrientationChange", |
| 1593 | "InCallActivity is null. Can't set requested orientation."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1594 | return; |
| 1595 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1596 | inCallActivity.setAllowOrientationChange(allowOrientationChange); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | public void enableScreenTimeout(boolean enable) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1600 | LogUtil.v("InCallPresenter.enableScreenTimeout", "enableScreenTimeout: value=" + enable); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1601 | screenTimeoutEnabled = enable; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1602 | applyScreenTimeout(); |
| 1603 | } |
| 1604 | |
| 1605 | private void applyScreenTimeout() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1606 | if (inCallActivity == null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1607 | LogUtil.e("InCallPresenter.applyScreenTimeout", "InCallActivity is null."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1608 | return; |
| 1609 | } |
| 1610 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1611 | final Window window = inCallActivity.getWindow(); |
| 1612 | if (screenTimeoutEnabled) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1613 | window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1614 | } else { |
| 1615 | window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 1616 | } |
| 1617 | } |
| 1618 | |
| 1619 | /** |
| 1620 | * Hides or shows the conference manager fragment. |
| 1621 | * |
| 1622 | * @param show {@code true} if the conference manager should be shown, {@code false} if it should |
| 1623 | * be hidden. |
| 1624 | */ |
| 1625 | public void showConferenceCallManager(boolean show) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1626 | if (inCallActivity != null) { |
| 1627 | inCallActivity.showConferenceFragment(show); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1628 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1629 | if (!show && manageConferenceActivity != null) { |
| 1630 | manageConferenceActivity.finish(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | |
| 1634 | /** |
| 1635 | * Determines if the dialpad is visible. |
| 1636 | * |
| 1637 | * @return {@code true} if the dialpad is visible, {@code false} otherwise. |
| 1638 | */ |
| 1639 | public boolean isDialpadVisible() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1640 | if (inCallActivity == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1641 | return false; |
| 1642 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1643 | return inCallActivity.isDialpadVisible(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | public ThemeColorManager getThemeColorManager() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1647 | return themeColorManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1648 | } |
| 1649 | |
wangqi | 8d662ca | 2017-10-26 11:27:19 -0700 | [diff] [blame] | 1650 | @VisibleForTesting |
| 1651 | public void setThemeColorManager(ThemeColorManager themeColorManager) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1652 | this.themeColorManager = themeColorManager; |
wangqi | 8d662ca | 2017-10-26 11:27:19 -0700 | [diff] [blame] | 1653 | } |
| 1654 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1655 | /** Called when the foreground call changes. */ |
| 1656 | public void onForegroundCallChanged(DialerCall newForegroundCall) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1657 | themeColorManager.onForegroundCallChanged(context, newForegroundCall); |
| 1658 | if (inCallActivity != null) { |
| 1659 | inCallActivity.onForegroundCallChanged(newForegroundCall); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | public InCallActivity getActivity() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1664 | return inCallActivity; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | /** Called when the UI begins, and starts the callstate callbacks if necessary. */ |
| 1668 | public void setActivity(InCallActivity inCallActivity) { |
| 1669 | if (inCallActivity == null) { |
| 1670 | throw new IllegalArgumentException("registerActivity cannot be called with null"); |
| 1671 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1672 | if (this.inCallActivity != null && this.inCallActivity != inCallActivity) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1673 | LogUtil.w( |
| 1674 | "InCallPresenter.setActivity", "Setting a second activity before destroying the first."); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1675 | } |
| 1676 | updateActivity(inCallActivity); |
| 1677 | } |
| 1678 | |
| 1679 | ExternalCallNotifier getExternalCallNotifier() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1680 | return externalCallNotifier; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | VideoSurfaceTexture getLocalVideoSurfaceTexture() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1684 | if (localVideoSurfaceTexture == null) { |
roldenburg | 12b50c6 | 2017-09-01 14:41:19 -0700 | [diff] [blame] | 1685 | boolean isPixel2017 = false; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1686 | if (context != null) { |
| 1687 | isPixel2017 = context.getPackageManager().hasSystemFeature(PIXEL2017_SYSTEM_FEATURE); |
roldenburg | 12b50c6 | 2017-09-01 14:41:19 -0700 | [diff] [blame] | 1688 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1689 | localVideoSurfaceTexture = VideoSurfaceBindings.createLocalVideoSurfaceTexture(isPixel2017); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1690 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1691 | return localVideoSurfaceTexture; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | VideoSurfaceTexture getRemoteVideoSurfaceTexture() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1695 | if (remoteVideoSurfaceTexture == null) { |
roldenburg | 12b50c6 | 2017-09-01 14:41:19 -0700 | [diff] [blame] | 1696 | boolean isPixel2017 = false; |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1697 | if (context != null) { |
| 1698 | isPixel2017 = context.getPackageManager().hasSystemFeature(PIXEL2017_SYSTEM_FEATURE); |
roldenburg | 12b50c6 | 2017-09-01 14:41:19 -0700 | [diff] [blame] | 1699 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1700 | remoteVideoSurfaceTexture = VideoSurfaceBindings.createRemoteVideoSurfaceTexture(isPixel2017); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1701 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1702 | return remoteVideoSurfaceTexture; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | void cleanupSurfaces() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1706 | if (remoteVideoSurfaceTexture != null) { |
| 1707 | remoteVideoSurfaceTexture.setDoneWithSurface(); |
| 1708 | remoteVideoSurfaceTexture = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1709 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1710 | if (localVideoSurfaceTexture != null) { |
| 1711 | localVideoSurfaceTexture.setDoneWithSurface(); |
| 1712 | localVideoSurfaceTexture = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 1716 | @Override |
| 1717 | public void onAudioStateChanged(CallAudioState audioState) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1718 | if (statusBarNotifier != null) { |
| 1719 | statusBarNotifier.updateNotification(); |
yueg | 77cb8e5 | 2017-10-27 16:42:51 -0700 | [diff] [blame] | 1720 | } |
| 1721 | } |
| 1722 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1723 | /** All the main states of InCallActivity. */ |
| 1724 | public enum InCallState { |
| 1725 | // InCall Screen is off and there are no calls |
| 1726 | NO_CALLS, |
| 1727 | |
| 1728 | // Incoming-call screen is up |
| 1729 | INCOMING, |
| 1730 | |
| 1731 | // In-call experience is showing |
| 1732 | INCALL, |
| 1733 | |
| 1734 | // Waiting for user input before placing outgoing call |
| 1735 | WAITING_FOR_ACCOUNT, |
| 1736 | |
| 1737 | // UI is starting up but no call has been initiated yet. |
| 1738 | // The UI is waiting for Telecom to respond. |
| 1739 | PENDING_OUTGOING, |
| 1740 | |
| 1741 | // User is dialing out |
| 1742 | OUTGOING; |
| 1743 | |
| 1744 | public boolean isIncoming() { |
| 1745 | return (this == INCOMING); |
| 1746 | } |
| 1747 | |
| 1748 | public boolean isConnectingOrConnected() { |
| 1749 | return (this == INCOMING || this == OUTGOING || this == INCALL); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | /** Interface implemented by classes that need to know about the InCall State. */ |
| 1754 | public interface InCallStateListener { |
| 1755 | |
| 1756 | // TODO: Enhance state to contain the call objects instead of passing CallList |
| 1757 | void onStateChange(InCallState oldState, InCallState newState, CallList callList); |
| 1758 | } |
| 1759 | |
| 1760 | public interface IncomingCallListener { |
| 1761 | |
| 1762 | void onIncomingCall(InCallState oldState, InCallState newState, DialerCall call); |
| 1763 | } |
| 1764 | |
| 1765 | public interface CanAddCallListener { |
| 1766 | |
| 1767 | void onCanAddCallChanged(boolean canAddCall); |
| 1768 | } |
| 1769 | |
| 1770 | public interface InCallDetailsListener { |
| 1771 | |
| 1772 | void onDetailsChanged(DialerCall call, android.telecom.Call.Details details); |
| 1773 | } |
| 1774 | |
| 1775 | public interface InCallOrientationListener { |
| 1776 | |
| 1777 | void onDeviceOrientationChanged(@ScreenOrientation int orientation); |
| 1778 | } |
| 1779 | |
| 1780 | /** |
| 1781 | * Interface implemented by classes that need to know about events which occur within the In-Call |
| 1782 | * UI. Used as a means of communicating between fragments that make up the UI. |
| 1783 | */ |
| 1784 | public interface InCallEventListener { |
| 1785 | |
| 1786 | void onFullscreenModeChanged(boolean isFullscreenMode); |
| 1787 | } |
| 1788 | |
| 1789 | public interface InCallUiListener { |
| 1790 | |
| 1791 | void onUiShowing(boolean showing); |
| 1792 | } |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1793 | |
| 1794 | private class InCallUiLockImpl implements InCallUiLock { |
| 1795 | private final String tag; |
| 1796 | |
| 1797 | private InCallUiLockImpl(String tag) { |
| 1798 | this.tag = tag; |
| 1799 | } |
| 1800 | |
| 1801 | @MainThread |
| 1802 | @Override |
| 1803 | public void release() { |
| 1804 | Assert.isMainThread(); |
| 1805 | releaseInCallUiLock(InCallUiLockImpl.this); |
| 1806 | } |
| 1807 | |
| 1808 | @Override |
| 1809 | public String toString() { |
| 1810 | return "InCallUiLock[" + tag + "]"; |
| 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | @MainThread |
| 1815 | public InCallUiLock acquireInCallUiLock(String tag) { |
| 1816 | Assert.isMainThread(); |
| 1817 | InCallUiLock lock = new InCallUiLockImpl(tag); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1818 | inCallUiLocks.add(lock); |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1819 | return lock; |
| 1820 | } |
| 1821 | |
| 1822 | @MainThread |
| 1823 | private void releaseInCallUiLock(InCallUiLock lock) { |
| 1824 | Assert.isMainThread(); |
| 1825 | LogUtil.i("InCallPresenter.releaseInCallUiLock", "releasing %s", lock); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1826 | inCallUiLocks.remove(lock); |
| 1827 | if (inCallUiLocks.isEmpty()) { |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1828 | LogUtil.i("InCallPresenter.releaseInCallUiLock", "all locks released"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1829 | if (inCallState == InCallState.NO_CALLS) { |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1830 | LogUtil.i("InCallPresenter.releaseInCallUiLock", "no more calls, finishing UI"); |
| 1831 | attemptFinishActivity(); |
| 1832 | attemptCleanup(); |
| 1833 | } |
| 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | @MainThread |
| 1838 | public boolean isInCallUiLocked() { |
| 1839 | Assert.isMainThread(); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1840 | if (inCallUiLocks.isEmpty()) { |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1841 | return false; |
| 1842 | } |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1843 | for (InCallUiLock lock : inCallUiLocks) { |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 1844 | LogUtil.i("InCallPresenter.isInCallUiLocked", "still locked by %s", lock); |
| 1845 | } |
| 1846 | return true; |
| 1847 | } |
| 1848 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 1849 | private final Set<InCallUiLock> inCallUiLocks = new ArraySet<>(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1850 | } |