blob: 5ac6b50290f4047b738cd1c2484ae972431a71fe [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
2 * Copyright (C) 2016 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
17package com.android.incallui;
18
linyuhc3968e62017-11-20 17:40:50 -080019import android.app.ActivityManager;
20import android.app.ActivityManager.AppTask;
linyuh57b093b2017-11-17 14:32:32 -080021import android.app.ActivityManager.TaskDescription;
linyuh7b86f562017-11-16 11:24:09 -080022import android.app.AlertDialog;
linyuhf99f6302017-11-15 11:23:51 -080023import android.app.Dialog;
linyuh57b093b2017-11-17 14:32:32 -080024import android.app.KeyguardManager;
Eric Erfanianccca3152017-02-22 16:32:36 -080025import android.content.Context;
26import android.content.Intent;
linyuhc3968e62017-11-20 17:40:50 -080027import android.content.res.Configuration;
Eric Erfanianccca3152017-02-22 16:32:36 -080028import android.graphics.drawable.GradientDrawable;
29import android.graphics.drawable.GradientDrawable.Orientation;
30import android.os.Bundle;
Eric Erfanian2ca43182017-08-31 06:57:16 -070031import android.os.Trace;
Eric Erfanianccca3152017-02-22 16:32:36 -080032import android.support.annotation.ColorInt;
33import android.support.annotation.FloatRange;
linyuhc3968e62017-11-20 17:40:50 -080034import android.support.annotation.IntDef;
Eric Erfanianc857f902017-05-15 14:05:33 -070035import android.support.annotation.NonNull;
Eric Erfanianccca3152017-02-22 16:32:36 -080036import android.support.annotation.Nullable;
linyuhc3968e62017-11-20 17:40:50 -080037import android.support.annotation.VisibleForTesting;
wangqibc28ea72018-04-02 16:23:00 -070038import android.support.v4.app.DialogFragment;
erfaniand05d8992018-03-20 19:42:26 -070039import android.support.v4.app.Fragment;
Eric Erfanianccca3152017-02-22 16:32:36 -080040import android.support.v4.app.FragmentManager;
41import android.support.v4.app.FragmentTransaction;
linyuh57b093b2017-11-17 14:32:32 -080042import android.support.v4.content.res.ResourcesCompat;
Eric Erfanianccca3152017-02-22 16:32:36 -080043import android.support.v4.graphics.ColorUtils;
twyen73a74c32018-03-07 12:12:24 -080044import android.telecom.Call;
linyuhc3968e62017-11-20 17:40:50 -080045import android.telecom.CallAudioState;
46import android.telecom.PhoneAccountHandle;
Eric Erfanian90508232017-03-24 09:31:16 -070047import android.telephony.TelephonyManager;
Eric Erfanianccca3152017-02-22 16:32:36 -080048import android.view.KeyEvent;
49import android.view.MenuItem;
50import android.view.MotionEvent;
51import android.view.View;
linyuh9c327da2017-11-14 12:33:48 -080052import android.view.WindowManager;
linyuhc3968e62017-11-20 17:40:50 -080053import android.view.animation.Animation;
54import android.view.animation.AnimationUtils;
linyuh7b86f562017-11-16 11:24:09 -080055import android.widget.CheckBox;
56import android.widget.Toast;
linyuhf99f6302017-11-15 11:23:51 -080057import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
linyuhc3968e62017-11-20 17:40:50 -080058import com.android.dialer.animation.AnimUtils;
59import com.android.dialer.animation.AnimationListenerAdapter;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070060import com.android.dialer.common.Assert;
Eric Erfanianccca3152017-02-22 16:32:36 -080061import com.android.dialer.common.LogUtil;
twyen73a74c32018-03-07 12:12:24 -080062import com.android.dialer.common.concurrent.DialerExecutorComponent;
weijiaxu650e7cc2017-10-31 12:38:54 -070063import com.android.dialer.common.concurrent.ThreadUtil;
twyena1723252018-04-24 17:02:57 -070064import com.android.dialer.common.concurrent.UiListener;
Eric Erfanian2ca43182017-08-31 06:57:16 -070065import com.android.dialer.configprovider.ConfigProviderBindings;
Eric Erfanianccca3152017-02-22 16:32:36 -080066import com.android.dialer.logging.Logger;
Eric Erfanian8369df02017-05-03 10:27:13 -070067import com.android.dialer.logging.ScreenEvent;
zachh7a96dc72018-02-20 22:16:03 -080068import com.android.dialer.metrics.Metrics;
69import com.android.dialer.metrics.MetricsComponent;
twyen73a74c32018-03-07 12:12:24 -080070import com.android.dialer.preferredsim.PreferredAccountRecorder;
71import com.android.dialer.preferredsim.PreferredAccountWorker;
twyena1723252018-04-24 17:02:57 -070072import com.android.dialer.preferredsim.PreferredAccountWorker.Result;
twyen56f79ba2018-04-30 14:25:46 -070073import com.android.dialer.preferredsim.PreferredSimComponent;
linyuhc3968e62017-11-20 17:40:50 -080074import com.android.dialer.util.ViewUtil;
Eric Erfanianccca3152017-02-22 16:32:36 -080075import com.android.incallui.answer.bindings.AnswerBindings;
76import com.android.incallui.answer.protocol.AnswerScreen;
77import com.android.incallui.answer.protocol.AnswerScreenDelegate;
78import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory;
79import com.android.incallui.answerproximitysensor.PseudoScreenState;
linyuh57b093b2017-11-17 14:32:32 -080080import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080081import com.android.incallui.call.CallList;
82import com.android.incallui.call.DialerCall;
linyuh57b093b2017-11-17 14:32:32 -080083import com.android.incallui.call.TelecomAdapter;
wangqibb94ca62018-04-27 14:34:04 -070084import com.android.incallui.call.state.DialerCallState;
Eric Erfanian2ca43182017-08-31 06:57:16 -070085import com.android.incallui.callpending.CallPendingActivity;
86import com.android.incallui.disconnectdialog.DisconnectMessage;
Eric Erfanianccca3152017-02-22 16:32:36 -080087import com.android.incallui.incall.bindings.InCallBindings;
88import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
89import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory;
90import com.android.incallui.incall.protocol.InCallScreen;
91import com.android.incallui.incall.protocol.InCallScreenDelegate;
92import com.android.incallui.incall.protocol.InCallScreenDelegateFactory;
linyuh7b86f562017-11-16 11:24:09 -080093import com.android.incallui.incalluilock.InCallUiLock;
wangqi219b8702018-02-13 09:34:41 -080094import com.android.incallui.rtt.bindings.RttBindings;
95import com.android.incallui.rtt.protocol.RttCallScreen;
96import com.android.incallui.rtt.protocol.RttCallScreenDelegate;
97import com.android.incallui.rtt.protocol.RttCallScreenDelegateFactory;
erfaniand05d8992018-03-20 19:42:26 -070098import com.android.incallui.speakeasy.SpeakEasyCallManager;
linyuhf99f6302017-11-15 11:23:51 -080099import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment;
Eric Erfanianccca3152017-02-22 16:32:36 -0800100import com.android.incallui.video.bindings.VideoBindings;
101import com.android.incallui.video.protocol.VideoCallScreen;
102import com.android.incallui.video.protocol.VideoCallScreenDelegate;
103import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory;
linyuhc3968e62017-11-20 17:40:50 -0800104import com.google.common.base.Optional;
twyena1723252018-04-24 17:02:57 -0700105import com.google.common.util.concurrent.ListenableFuture;
linyuhc3968e62017-11-20 17:40:50 -0800106import java.lang.annotation.Retention;
107import java.lang.annotation.RetentionPolicy;
108import java.util.ArrayList;
109import java.util.List;
Eric Erfanianccca3152017-02-22 16:32:36 -0800110
111/** Version of {@link InCallActivity} that shows the new UI */
112public class InCallActivity extends TransactionSafeFragmentActivity
113 implements AnswerScreenDelegateFactory,
114 InCallScreenDelegateFactory,
115 InCallButtonUiDelegateFactory,
116 VideoCallScreenDelegateFactory,
wangqi219b8702018-02-13 09:34:41 -0800117 RttCallScreenDelegateFactory,
Eric Erfanianccca3152017-02-22 16:32:36 -0800118 PseudoScreenState.StateChangedListener {
119
linyuhc3968e62017-11-20 17:40:50 -0800120 @Retention(RetentionPolicy.SOURCE)
121 @IntDef({
122 DIALPAD_REQUEST_NONE,
123 DIALPAD_REQUEST_SHOW,
124 DIALPAD_REQUEST_HIDE,
125 })
126 @interface DialpadRequestType {}
Eric Erfanian2ca43182017-08-31 06:57:16 -0700127
linyuhc3968e62017-11-20 17:40:50 -0800128 private static final int DIALPAD_REQUEST_NONE = 1;
129 private static final int DIALPAD_REQUEST_SHOW = 2;
130 private static final int DIALPAD_REQUEST_HIDE = 3;
linyuh57b093b2017-11-17 14:32:32 -0800131
linyuhc3968e62017-11-20 17:40:50 -0800132 private static Optional<Integer> audioRouteForTesting = Optional.absent();
linyuh57b093b2017-11-17 14:32:32 -0800133
twyen73a74c32018-03-07 12:12:24 -0800134 private SelectPhoneAccountListener selectPhoneAccountListener;
twyena1723252018-04-24 17:02:57 -0700135 private UiListener<Result> preferredAccountWorkerResultListener;
Eric Erfanianccca3152017-02-22 16:32:36 -0800136
linyuhc3968e62017-11-20 17:40:50 -0800137 private Animation dialpadSlideInAnimation;
138 private Animation dialpadSlideOutAnimation;
139 private Dialog errorDialog;
140 private GradientDrawable backgroundDrawable;
linyuh69a25062017-11-15 16:18:51 -0800141 private InCallOrientationEventListener inCallOrientationEventListener;
linyuhc3968e62017-11-20 17:40:50 -0800142 private View pseudoBlackScreenOverlay;
143 private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment;
144 private String dtmfTextToPrepopulate;
linyuhc3968e62017-11-20 17:40:50 -0800145 private boolean allowOrientationChange;
146 private boolean animateDialpadOnShow;
Eric Erfanianccca3152017-02-22 16:32:36 -0800147 private boolean didShowAnswerScreen;
148 private boolean didShowInCallScreen;
149 private boolean didShowVideoCallScreen;
wangqi219b8702018-02-13 09:34:41 -0800150 private boolean didShowRttCallScreen;
erfaniand05d8992018-03-20 19:42:26 -0700151 private boolean didShowSpeakEasyScreen;
erfanian612d13a2018-04-04 15:27:57 -0700152 private String lastShownSpeakEasyScreenUniqueCallid = "";
linyuh9c327da2017-11-14 12:33:48 -0800153 private boolean dismissKeyguard;
Eric Erfanianccca3152017-02-22 16:32:36 -0800154 private boolean isInShowMainInCallFragment;
linyuhc3968e62017-11-20 17:40:50 -0800155 private boolean isRecreating; // whether the activity is going to be recreated
156 private boolean isVisible;
Eric Erfanianccca3152017-02-22 16:32:36 -0800157 private boolean needDismissPendingDialogs;
linyuhc3968e62017-11-20 17:40:50 -0800158 private boolean touchDownWhenPseudoScreenOff;
159 private int[] backgroundDrawableColors;
160 @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE;
erfaniand05d8992018-03-20 19:42:26 -0700161 private SpeakEasyCallManager speakEasyCallManager;
Eric Erfanianccca3152017-02-22 16:32:36 -0800162
163 public static Intent getIntent(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700164 Context context, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800165 Intent intent = new Intent(Intent.ACTION_MAIN, null);
166 intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
167 intent.setClass(context, InCallActivity.class);
linyuhc3968e62017-11-20 17:40:50 -0800168 if (showDialpad) {
169 intent.putExtra(IntentExtraNames.SHOW_DIALPAD, true);
170 }
171 intent.putExtra(IntentExtraNames.NEW_OUTGOING_CALL, newOutgoingCall);
172 intent.putExtra(IntentExtraNames.FOR_FULL_SCREEN, isForFullScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -0800173 return intent;
174 }
175
176 @Override
177 protected void onResumeFragments() {
178 super.onResumeFragments();
179 if (needDismissPendingDialogs) {
180 dismissPendingDialogs();
181 }
182 }
183
184 @Override
linyuhc3968e62017-11-20 17:40:50 -0800185 protected void onCreate(Bundle bundle) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700186 Trace.beginSection("InCallActivity.onCreate");
linyuhc3968e62017-11-20 17:40:50 -0800187 super.onCreate(bundle);
Eric Erfanianccca3152017-02-22 16:32:36 -0800188
twyena1723252018-04-24 17:02:57 -0700189 preferredAccountWorkerResultListener =
190 DialerExecutorComponent.get(this)
191 .createUiListener(getFragmentManager(), "preferredAccountWorkerResultListener");
192
twyen73a74c32018-03-07 12:12:24 -0800193 selectPhoneAccountListener = new SelectPhoneAccountListener(getApplicationContext());
194
linyuhc3968e62017-11-20 17:40:50 -0800195 if (bundle != null) {
196 didShowAnswerScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN);
197 didShowInCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN);
198 didShowVideoCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN);
wangqi153af2f2018-02-15 16:21:49 -0800199 didShowRttCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -0800200 }
201
linyuhc3968e62017-11-20 17:40:50 -0800202 setWindowFlags();
203 setContentView(R.layout.incall_screen);
204 internalResolveIntent(getIntent());
205
206 boolean isLandscape =
207 getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
208 boolean isRtl = ViewUtil.isRtl();
209 if (isLandscape) {
210 dialpadSlideInAnimation =
211 AnimationUtils.loadAnimation(
212 this, isRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
213 dialpadSlideOutAnimation =
214 AnimationUtils.loadAnimation(
215 this, isRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
216 } else {
217 dialpadSlideInAnimation = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
218 dialpadSlideOutAnimation =
219 AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
220 }
221 dialpadSlideInAnimation.setInterpolator(AnimUtils.EASE_IN);
222 dialpadSlideOutAnimation.setInterpolator(AnimUtils.EASE_OUT);
223 dialpadSlideOutAnimation.setAnimationListener(
224 new AnimationListenerAdapter() {
225 @Override
226 public void onAnimationEnd(Animation animation) {
227 hideDialpadFragment();
228 }
229 });
230
231 if (bundle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) {
232 // If the dialpad was shown before, set related variables so that it can be shown and
233 // populated with the previous DTMF text during onResume().
234 if (bundle.containsKey(IntentExtraNames.SHOW_DIALPAD)) {
235 boolean showDialpad = bundle.getBoolean(IntentExtraNames.SHOW_DIALPAD);
236 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_HIDE;
237 animateDialpadOnShow = false;
238 }
239 dtmfTextToPrepopulate = bundle.getString(KeysForSavedInstance.DIALPAD_TEXT);
240
241 SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment =
242 (SelectPhoneAccountDialogFragment)
243 getFragmentManager().findFragmentByTag(Tags.SELECT_ACCOUNT_FRAGMENT);
244 if (selectPhoneAccountDialogFragment != null) {
245 selectPhoneAccountDialogFragment.setListener(selectPhoneAccountListener);
246 }
247 }
248
linyuh69a25062017-11-15 16:18:51 -0800249 inCallOrientationEventListener = new InCallOrientationEventListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -0800250
251 getWindow()
252 .getDecorView()
253 .setSystemUiVisibility(
254 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
255
256 pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700257 sendBroadcast(CallPendingActivity.getFinishBroadcast());
258 Trace.endSection();
zachh7a96dc72018-02-20 22:16:03 -0800259 MetricsComponent.get(this)
260 .metrics()
261 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_INCOMING);
262 MetricsComponent.get(this)
263 .metrics()
264 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_OUTGOING);
Eric Erfanianccca3152017-02-22 16:32:36 -0800265 }
266
linyuhc3968e62017-11-20 17:40:50 -0800267 private void setWindowFlags() {
268 // Allow the activity to be shown when the screen is locked and filter out touch events that are
269 // "too fat".
270 int flags =
271 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
272 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;
273
linyuhf79d1cb2017-12-15 17:49:56 -0800274 // When the audio stream is not via Bluetooth, turn on the screen once the activity is shown.
275 // When the audio stream is via Bluetooth, turn on the screen only for an incoming call.
linyuhc3968e62017-11-20 17:40:50 -0800276 final int audioRoute = getAudioRoute();
linyuhf79d1cb2017-12-15 17:49:56 -0800277 if (audioRoute != CallAudioState.ROUTE_BLUETOOTH
278 || CallList.getInstance().getIncomingCall() != null) {
linyuhc3968e62017-11-20 17:40:50 -0800279 flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
280 }
281
282 getWindow().addFlags(flags);
283 }
284
285 private static int getAudioRoute() {
286 if (audioRouteForTesting.isPresent()) {
287 return audioRouteForTesting.get();
288 }
289
290 return AudioModeProvider.getInstance().getAudioState().getRoute();
291 }
292
293 @VisibleForTesting(otherwise = VisibleForTesting.NONE)
294 public static void setAudioRouteForTesting(int audioRoute) {
295 audioRouteForTesting = Optional.of(audioRoute);
296 }
297
298 private void internalResolveIntent(Intent intent) {
299 if (!intent.getAction().equals(Intent.ACTION_MAIN)) {
300 return;
301 }
302
303 if (intent.hasExtra(IntentExtraNames.SHOW_DIALPAD)) {
304 // IntentExtraNames.SHOW_DIALPAD can be used to specify whether the DTMF dialpad should be
305 // initially visible. If the extra is absent, leave the dialpad in its previous state.
306 boolean showDialpad = intent.getBooleanExtra(IntentExtraNames.SHOW_DIALPAD, false);
307 relaunchedFromDialer(showDialpad);
308 }
309
310 DialerCall outgoingCall = CallList.getInstance().getOutgoingCall();
311 if (outgoingCall == null) {
312 outgoingCall = CallList.getInstance().getPendingOutgoingCall();
313 }
314 if (intent.getBooleanExtra(IntentExtraNames.NEW_OUTGOING_CALL, false)) {
315 intent.removeExtra(IntentExtraNames.NEW_OUTGOING_CALL);
316
317 // InCallActivity is responsible for disconnecting a new outgoing call if there is no way of
318 // making it (i.e. no valid call capable accounts).
linyuh122fb0b2018-03-26 13:35:32 -0700319 if (InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) {
linyuhc3968e62017-11-20 17:40:50 -0800320 LogUtil.i(
321 "InCallActivity.internalResolveIntent", "Call with no valid accounts, disconnecting");
322 outgoingCall.disconnect();
323 }
324
325 dismissKeyguard(true);
326 }
327
328 if (showPhoneAccountSelectionDialog()) {
329 hideMainInCallFragment();
330 }
331 }
332
333 /**
334 * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should
335 * be shown on launch.
336 *
337 * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code
338 * false} to indicate no change should be made to the dialpad visibility.
339 */
340 private void relaunchedFromDialer(boolean showDialpad) {
341 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE;
342 animateDialpadOnShow = true;
343
344 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
345 // If there's only one line in use, AND it's on hold, then we're sure the user
346 // wants to use the dialpad toward the exact line, so un-hold the holding line.
347 DialerCall call = CallList.getInstance().getActiveOrBackgroundCall();
wangqibb94ca62018-04-27 14:34:04 -0700348 if (call != null && call.getState() == DialerCallState.ONHOLD) {
linyuhc3968e62017-11-20 17:40:50 -0800349 call.unhold();
350 }
351 }
352 }
353
354 /**
355 * Show a phone account selection dialog if there is a call waiting for phone account selection.
356 *
357 * @return true if the dialog was shown.
358 */
359 private boolean showPhoneAccountSelectionDialog() {
360 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
361 if (waitingForAccountCall == null) {
362 return false;
363 }
364
twyen56f79ba2018-04-30 14:25:46 -0700365 PreferredAccountWorker preferredAccountWorker =
366 PreferredSimComponent.get(this).preferredAccountWorker();
linyuhc3968e62017-11-20 17:40:50 -0800367
twyen56f79ba2018-04-30 14:25:46 -0700368 Bundle extras = waitingForAccountCall.getIntentExtras();
369 List<PhoneAccountHandle> phoneAccountHandles =
370 extras == null
371 ? new ArrayList<>()
372 : extras.getParcelableArrayList(Call.AVAILABLE_PHONE_ACCOUNTS);
373
374 ListenableFuture<PreferredAccountWorker.Result> preferredAccountFuture =
375 preferredAccountWorker.selectAccount(
376 waitingForAccountCall.getNumber(), phoneAccountHandles);
twyena1723252018-04-24 17:02:57 -0700377 preferredAccountWorkerResultListener.listen(
378 this,
379 preferredAccountFuture,
380 result -> {
twyen3b2c7812018-04-30 12:13:06 -0700381 if (!isVisible()) {
382 LogUtil.i(
383 "CallingAccountSelector.showPhoneAccountSelectionDialog",
384 "activity ended before result returned");
385 return;
386 }
twyen56f79ba2018-04-30 14:25:46 -0700387 String callId = waitingForAccountCall.getId();
388 if (result.getSelectedPhoneAccountHandle().isPresent()) {
twyena1723252018-04-24 17:02:57 -0700389 selectPhoneAccountListener.onPhoneAccountSelected(
twyen56f79ba2018-04-30 14:25:46 -0700390 result.getSelectedPhoneAccountHandle().get(), false, callId);
twyena1723252018-04-24 17:02:57 -0700391 return;
392 }
twyen66adad02018-04-24 13:51:08 -0700393
twyena1723252018-04-24 17:02:57 -0700394 waitingForAccountCall.setPreferredAccountRecorder(
395 new PreferredAccountRecorder(
396 waitingForAccountCall.getNumber(),
397 result.getSuggestion().orNull(),
398 result.getDataId().orNull()));
twyena1723252018-04-24 17:02:57 -0700399 selectPhoneAccountDialogFragment =
400 SelectPhoneAccountDialogFragment.newInstance(
twyen56f79ba2018-04-30 14:25:46 -0700401 result.getDialogOptionsBuilder().get().setCallId(callId).build(),
402 selectPhoneAccountListener);
twyena1723252018-04-24 17:02:57 -0700403 selectPhoneAccountDialogFragment.show(getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT);
404 },
405 throwable -> {
406 throw new RuntimeException(throwable);
407 });
twyen73a74c32018-03-07 12:12:24 -0800408
linyuhc3968e62017-11-20 17:40:50 -0800409 return true;
410 }
411
Eric Erfanianccca3152017-02-22 16:32:36 -0800412 @Override
413 protected void onSaveInstanceState(Bundle out) {
linyuh57b093b2017-11-17 14:32:32 -0800414 LogUtil.enterBlock("InCallActivity.onSaveInstanceState");
415
416 // TODO: DialpadFragment should handle this as part of its own state
linyuhc3968e62017-11-20 17:40:50 -0800417 out.putBoolean(IntentExtraNames.SHOW_DIALPAD, isDialpadVisible());
linyuh57b093b2017-11-17 14:32:32 -0800418 DialpadFragment dialpadFragment = getDialpadFragment();
419 if (dialpadFragment != null) {
linyuhc3968e62017-11-20 17:40:50 -0800420 out.putString(KeysForSavedInstance.DIALPAD_TEXT, dialpadFragment.getDtmfText());
linyuh57b093b2017-11-17 14:32:32 -0800421 }
422
linyuhc3968e62017-11-20 17:40:50 -0800423 out.putBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN, didShowAnswerScreen);
424 out.putBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN, didShowInCallScreen);
425 out.putBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN, didShowVideoCallScreen);
wangqi153af2f2018-02-15 16:21:49 -0800426 out.putBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN, didShowRttCallScreen);
erfaniand05d8992018-03-20 19:42:26 -0700427 out.putBoolean(KeysForSavedInstance.DID_SHOW_SPEAK_EASY_SCREEN, didShowSpeakEasyScreen);
linyuh57b093b2017-11-17 14:32:32 -0800428
Eric Erfanianccca3152017-02-22 16:32:36 -0800429 super.onSaveInstanceState(out);
430 isVisible = false;
431 }
432
433 @Override
434 protected void onStart() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700435 Trace.beginSection("InCallActivity.onStart");
Eric Erfanianccca3152017-02-22 16:32:36 -0800436 super.onStart();
linyuh57b093b2017-11-17 14:32:32 -0800437
Eric Erfanianccca3152017-02-22 16:32:36 -0800438 isVisible = true;
439 showMainInCallFragment();
linyuh57b093b2017-11-17 14:32:32 -0800440
441 InCallPresenter.getInstance().setActivity(this);
442 enableInCallOrientationEventListener(
443 getRequestedOrientation()
444 == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
445 InCallPresenter.getInstance().onActivityStarted();
446
yueg10f6e822018-01-17 15:32:18 -0800447 if (!isRecreating) {
448 InCallPresenter.getInstance().onUiShowing(true);
449 }
450
linyuh437ae952018-03-26 12:46:18 -0700451 if (isInMultiWindowMode() && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800452 // Hide the dialpad because there may not be enough room
453 showDialpadFragment(false, false);
454 }
linyuh57b093b2017-11-17 14:32:32 -0800455
Eric Erfanian2ca43182017-08-31 06:57:16 -0700456 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800457 }
458
459 @Override
460 protected void onResume() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700461 Trace.beginSection("InCallActivity.onResume");
Eric Erfanianccca3152017-02-22 16:32:36 -0800462 super.onResume();
linyuhc3968e62017-11-20 17:40:50 -0800463
464 if (!InCallPresenter.getInstance().isReadyForTearDown()) {
465 updateTaskDescription();
linyuhc3968e62017-11-20 17:40:50 -0800466 }
467
468 // If there is a pending request to show or hide the dialpad, handle that now.
469 if (showDialpadRequest != DIALPAD_REQUEST_NONE) {
470 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
471 // Exit fullscreen so that the user has access to the dialpad hide/show button.
472 // This is important when showing the dialpad from within dialer.
473 InCallPresenter.getInstance().setFullScreen(false /* isFullScreen */, true /* force */);
474
475 showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */);
476 animateDialpadOnShow = false;
477
478 DialpadFragment dialpadFragment = getDialpadFragment();
479 if (dialpadFragment != null) {
480 dialpadFragment.setDtmfText(dtmfTextToPrepopulate);
481 dtmfTextToPrepopulate = null;
482 }
483 } else {
484 LogUtil.i("InCallActivity.onResume", "Force-hide the dialpad");
485 if (getDialpadFragment() != null) {
486 showDialpadFragment(false /* show */, false /* animate */);
487 }
488 }
489 showDialpadRequest = DIALPAD_REQUEST_NONE;
490 }
491 updateNavigationBar(isDialpadVisible());
492
linyuhc3968e62017-11-20 17:40:50 -0800493 CallList.getInstance()
494 .onInCallUiShown(getIntent().getBooleanExtra(IntentExtraNames.FOR_FULL_SCREEN, false));
495
Eric Erfanianccca3152017-02-22 16:32:36 -0800496 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
497 pseudoScreenState.addListener(this);
498 onPseudoScreenStateChanged(pseudoScreenState.isOn());
Eric Erfanian2ca43182017-08-31 06:57:16 -0700499 Trace.endSection();
weijiaxu650e7cc2017-10-31 12:38:54 -0700500 // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume.
501 ThreadUtil.postDelayedOnUiThread(
weijiaxuc950a9b2017-11-06 16:39:04 -0800502 () ->
zachh7a96dc72018-02-20 22:16:03 -0800503 MetricsComponent.get(this)
504 .metrics()
505 .recordMemory(Metrics.INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME),
weijiaxu650e7cc2017-10-31 12:38:54 -0700506 1000);
Eric Erfanianccca3152017-02-22 16:32:36 -0800507 }
508
Eric Erfanianccca3152017-02-22 16:32:36 -0800509 @Override
510 protected void onPause() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700511 Trace.beginSection("InCallActivity.onPause");
Eric Erfanianccca3152017-02-22 16:32:36 -0800512 super.onPause();
linyuh57b093b2017-11-17 14:32:32 -0800513
514 DialpadFragment dialpadFragment = getDialpadFragment();
515 if (dialpadFragment != null) {
516 dialpadFragment.onDialerKeyUp(null);
517 }
518
Eric Erfanianccca3152017-02-22 16:32:36 -0800519 InCallPresenter.getInstance().getPseudoScreenState().removeListener(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700520 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800521 }
522
523 @Override
524 protected void onStop() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700525 Trace.beginSection("InCallActivity.onStop");
wangqi4d705e52017-09-28 12:23:35 -0700526 isVisible = false;
Eric Erfanianccca3152017-02-22 16:32:36 -0800527 super.onStop();
linyuh57b093b2017-11-17 14:32:32 -0800528
529 // Disconnects the call waiting for a phone account when the activity is hidden (e.g., after the
530 // user presses the home button).
531 // Without this the pending call will get stuck on phone account selection and new calls can't
532 // be created.
533 // Skip this when the screen is locked since the activity may complete its current life cycle
534 // and restart.
linyuhc3968e62017-11-20 17:40:50 -0800535 if (!isRecreating && !getSystemService(KeyguardManager.class).isKeyguardLocked()) {
linyuh57b093b2017-11-17 14:32:32 -0800536 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
537 if (waitingForAccountCall != null) {
538 waitingForAccountCall.disconnect();
539 }
540 }
541
542 enableInCallOrientationEventListener(false);
543 InCallPresenter.getInstance().updateIsChangingConfigurations();
544 InCallPresenter.getInstance().onActivityStopped();
linyuhc3968e62017-11-20 17:40:50 -0800545 if (!isRecreating) {
yueg10f6e822018-01-17 15:32:18 -0800546 InCallPresenter.getInstance().onUiShowing(false);
wangqie6060522018-04-05 11:47:15 -0700547 }
548 if (errorDialog != null) {
549 errorDialog.dismiss();
linyuh57b093b2017-11-17 14:32:32 -0800550 }
551
yueg10f6e822018-01-17 15:32:18 -0800552 if (isFinishing()) {
553 InCallPresenter.getInstance().unsetActivity(this);
554 }
555
Eric Erfanian2ca43182017-08-31 06:57:16 -0700556 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800557 }
558
559 @Override
560 protected void onDestroy() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700561 Trace.beginSection("InCallActivity.onDestroy");
Eric Erfanianccca3152017-02-22 16:32:36 -0800562 super.onDestroy();
linyuh57b093b2017-11-17 14:32:32 -0800563
564 InCallPresenter.getInstance().unsetActivity(this);
565 InCallPresenter.getInstance().updateIsChangingConfigurations();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700566 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800567 }
568
569 @Override
570 public void finish() {
571 if (shouldCloseActivityOnFinish()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700572 // When user select incall ui from recents after the call is disconnected, it tries to launch
573 // a new InCallActivity but InCallPresenter is already teared down at this point, which causes
574 // crash.
575 // By calling finishAndRemoveTask() instead of finish() the task associated with
576 // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in
577 // this case.
578 //
579 // Calling finish won't clear the task and normally when an activity finishes it shouldn't
580 // clear the task since there could be parent activity in the same task that's still alive.
581 // But InCallActivity is special since it's singleInstance which means it's root activity and
582 // only instance of activity in the task. So it should be safe to also remove task when
583 // finishing.
584 // It's also necessary in the sense of it's excluded from recents. So whenever the activity
585 // finishes, the task should also be removed since it doesn't make sense to go back to it in
586 // anyway anymore.
587 super.finishAndRemoveTask();
Eric Erfanianccca3152017-02-22 16:32:36 -0800588 }
589 }
590
591 private boolean shouldCloseActivityOnFinish() {
linyuhc3968e62017-11-20 17:40:50 -0800592 if (!isVisible) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800593 LogUtil.i(
594 "InCallActivity.shouldCloseActivityOnFinish",
595 "allowing activity to be closed because it's not visible");
596 return true;
597 }
598
twyen8efb4952017-10-06 16:35:54 -0700599 if (InCallPresenter.getInstance().isInCallUiLocked()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800600 LogUtil.i(
601 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700602 "in call ui is locked, not closing activity");
Eric Erfanianccca3152017-02-22 16:32:36 -0800603 return false;
604 }
605
606 LogUtil.i(
607 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700608 "activity is visible and has no locks, allowing activity to close");
Eric Erfanianccca3152017-02-22 16:32:36 -0800609 return true;
610 }
611
612 @Override
613 protected void onNewIntent(Intent intent) {
linyuhc3968e62017-11-20 17:40:50 -0800614 LogUtil.enterBlock("InCallActivity.onNewIntent");
Eric Erfanianccca3152017-02-22 16:32:36 -0800615
616 // If the screen is off, we need to make sure it gets turned on for incoming calls.
617 // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works
618 // when the activity is first created. Therefore, to ensure the screen is turned on
619 // for the call waiting case, we recreate() the current activity. There should be no jank from
620 // this since the screen is already off and will remain so until our new activity is up.
linyuhc3968e62017-11-20 17:40:50 -0800621 if (!isVisible) {
622 onNewIntent(intent, true /* isRecreating */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800623 LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on.");
624 recreate();
Eric Erfanian10b34a52017-05-04 08:23:17 -0700625 } else {
linyuhc3968e62017-11-20 17:40:50 -0800626 onNewIntent(intent, false /* isRecreating */);
627 }
628 }
629
yuega3305352018-01-09 11:02:47 -0800630 @VisibleForTesting
631 void onNewIntent(Intent intent, boolean isRecreating) {
linyuhc3968e62017-11-20 17:40:50 -0800632 this.isRecreating = isRecreating;
633
634 // We're being re-launched with a new Intent. Since it's possible for a single InCallActivity
635 // instance to persist indefinitely (even if we finish() ourselves), this sequence can
636 // happen any time the InCallActivity needs to be displayed.
637
638 // Stash away the new intent so that we can get it in the future by calling getIntent().
639 // Otherwise getIntent() will return the original Intent from when we first got created.
640 setIntent(intent);
641
642 // Activities are always paused before receiving a new intent, so we can count on our onResume()
643 // method being called next.
644
645 // Just like in onCreate(), handle the intent.
646 // Skip if InCallActivity is going to be recreated since this will be called in onCreate().
647 if (!isRecreating) {
648 internalResolveIntent(intent);
Eric Erfanianccca3152017-02-22 16:32:36 -0800649 }
650 }
651
652 @Override
653 public void onBackPressed() {
linyuh57b093b2017-11-17 14:32:32 -0800654 LogUtil.enterBlock("InCallActivity.onBackPressed");
655
linyuhc3968e62017-11-20 17:40:50 -0800656 if (!isVisible) {
linyuh57b093b2017-11-17 14:32:32 -0800657 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800658 }
linyuh57b093b2017-11-17 14:32:32 -0800659
660 if (!getCallCardFragmentVisible()) {
661 return;
662 }
663
664 DialpadFragment dialpadFragment = getDialpadFragment();
665 if (dialpadFragment != null && dialpadFragment.isVisible()) {
666 showDialpadFragment(false /* show */, true /* animate */);
667 return;
668 }
669
670 if (CallList.getInstance().getIncomingCall() != null) {
671 LogUtil.i(
672 "InCallActivity.onBackPressed",
673 "Ignore the press of the back key when an incoming call is ringing");
674 return;
675 }
676
677 // Nothing special to do. Fall back to the default behavior.
678 super.onBackPressed();
Eric Erfanianccca3152017-02-22 16:32:36 -0800679 }
680
681 @Override
682 public boolean onOptionsItemSelected(MenuItem item) {
683 LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item);
684 if (item.getItemId() == android.R.id.home) {
685 onBackPressed();
686 return true;
687 }
688 return super.onOptionsItemSelected(item);
689 }
690
691 @Override
692 public boolean onKeyUp(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800693 DialpadFragment dialpadFragment = getDialpadFragment();
694 if (dialpadFragment != null
695 && dialpadFragment.isVisible()
696 && dialpadFragment.onDialerKeyUp(event)) {
697 return true;
698 }
699
700 if (keyCode == KeyEvent.KEYCODE_CALL) {
701 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
702 return true;
703 }
704
705 return super.onKeyUp(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800706 }
707
708 @Override
709 public boolean onKeyDown(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800710 switch (keyCode) {
711 case KeyEvent.KEYCODE_CALL:
712 if (!InCallPresenter.getInstance().handleCallKey()) {
713 LogUtil.e(
714 "InCallActivity.onKeyDown",
715 "InCallPresenter should always handle KEYCODE_CALL in onKeyDown");
716 }
717 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
718 return true;
719
720 // Note that KEYCODE_ENDCALL isn't handled here as the standard system-wide handling of it
721 // is exactly what's needed, namely
722 // (1) "hang up" if there's an active call, or
723 // (2) "don't answer" if there's an incoming call.
724 // (See PhoneWindowManager for implementation details.)
725
726 case KeyEvent.KEYCODE_CAMERA:
727 // Consume KEYCODE_CAMERA since it's easy to accidentally press the camera button.
728 return true;
729
730 case KeyEvent.KEYCODE_VOLUME_UP:
731 case KeyEvent.KEYCODE_VOLUME_DOWN:
732 case KeyEvent.KEYCODE_VOLUME_MUTE:
733 // Ringer silencing handled by PhoneWindowManager.
734 break;
735
736 case KeyEvent.KEYCODE_MUTE:
737 TelecomAdapter.getInstance()
738 .mute(!AudioModeProvider.getInstance().getAudioState().isMuted());
739 return true;
740
741 case KeyEvent.KEYCODE_SLASH:
742 // When verbose logging is enabled, dump the view for debugging/testing purposes.
743 if (LogUtil.isVerboseEnabled()) {
744 View decorView = getWindow().getDecorView();
745 LogUtil.v("InCallActivity.onKeyDown", "View dump:\n%s", decorView);
746 return true;
747 }
748 break;
749
750 case KeyEvent.KEYCODE_EQUALS:
751 break;
752
753 default: // fall out
754 }
755
756 // Pass other key events to DialpadFragment's "onDialerKeyDown" method in case the user types
757 // in DTMF (Dual-tone multi-frequency signaling) code.
758 DialpadFragment dialpadFragment = getDialpadFragment();
759 if (dialpadFragment != null
760 && dialpadFragment.isVisible()
761 && dialpadFragment.onDialerKeyDown(event)) {
762 return true;
763 }
764
765 return super.onKeyDown(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800766 }
767
768 public boolean isInCallScreenAnimating() {
769 return false;
770 }
771
772 public void showConferenceFragment(boolean show) {
773 if (show) {
774 startActivity(new Intent(this, ManageConferenceActivity.class));
775 }
776 }
777
linyuhc3968e62017-11-20 17:40:50 -0800778 public void showDialpadFragment(boolean show, boolean animate) {
779 if (show == isDialpadVisible()) {
780 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800781 }
linyuhc3968e62017-11-20 17:40:50 -0800782
783 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
784 if (dialpadFragmentManager == null) {
785 LogUtil.i("InCallActivity.showDialpadFragment", "Unable to obtain a FragmentManager");
786 return;
787 }
788
789 if (!animate) {
790 if (show) {
791 showDialpadFragment();
792 } else {
793 hideDialpadFragment();
794 }
795 } else {
796 if (show) {
797 showDialpadFragment();
798 getDialpadFragment().animateShowDialpad();
799 }
800 getDialpadFragment()
801 .getView()
802 .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation);
803 }
804
805 ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor();
806 if (sensor != null) {
807 sensor.onDialpadVisible(show);
808 }
809 showDialpadRequest = DIALPAD_REQUEST_NONE;
810
811 // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB
812 // repositions itself.
wangqifd4c9f72018-03-08 18:21:50 -0800813 getInCallOrRttCallScreen().onInCallScreenDialpadVisibilityChange(show);
linyuhc3968e62017-11-20 17:40:50 -0800814 }
815
816 private void showDialpadFragment() {
817 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
818 if (dialpadFragmentManager == null) {
819 return;
820 }
821
822 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
823 DialpadFragment dialpadFragment = getDialpadFragment();
824 if (dialpadFragment == null) {
wangqifd4c9f72018-03-08 18:21:50 -0800825 dialpadFragment = new DialpadFragment();
826 transaction.add(getDialpadContainerId(), dialpadFragment, Tags.DIALPAD_FRAGMENT);
linyuhc3968e62017-11-20 17:40:50 -0800827 } else {
828 transaction.show(dialpadFragment);
calderwoodrad5883872017-12-12 15:29:12 -0800829 dialpadFragment.setUserVisibleHint(true);
linyuhc3968e62017-11-20 17:40:50 -0800830 }
wangqifd4c9f72018-03-08 18:21:50 -0800831 // RTT call screen doesn't show end call button inside dialpad, thus the space reserved for end
832 // call button should be removed.
833 dialpadFragment.setShouldShowEndCallSpace(didShowInCallScreen);
linyuhc3968e62017-11-20 17:40:50 -0800834 transaction.commitAllowingStateLoss();
835 dialpadFragmentManager.executePendingTransactions();
836
837 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, this);
838 updateNavigationBar(true /* isDialpadVisible */);
839 }
840
841 private void hideDialpadFragment() {
842 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
843 if (dialpadFragmentManager == null) {
844 return;
845 }
846
calderwoodrad5883872017-12-12 15:29:12 -0800847 DialpadFragment dialpadFragment = getDialpadFragment();
linyuhc3968e62017-11-20 17:40:50 -0800848 if (dialpadFragment != null) {
849 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
850 transaction.hide(dialpadFragment);
851 transaction.commitAllowingStateLoss();
852 dialpadFragmentManager.executePendingTransactions();
calderwoodrad5883872017-12-12 15:29:12 -0800853 dialpadFragment.setUserVisibleHint(false);
linyuhc3968e62017-11-20 17:40:50 -0800854 }
855 updateNavigationBar(false /* isDialpadVisible */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800856 }
857
858 public boolean isDialpadVisible() {
linyuh69a25062017-11-15 16:18:51 -0800859 DialpadFragment dialpadFragment = getDialpadFragment();
calderwoodraa584bcd2018-01-24 12:19:56 -0800860 return dialpadFragment != null
861 && dialpadFragment.isAdded()
862 && !dialpadFragment.isHidden()
863 && dialpadFragment.getView() != null
864 && dialpadFragment.getUserVisibleHint();
linyuh69a25062017-11-15 16:18:51 -0800865 }
866
linyuhc3968e62017-11-20 17:40:50 -0800867 /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */
linyuh69a25062017-11-15 16:18:51 -0800868 @Nullable
linyuhc3968e62017-11-20 17:40:50 -0800869 private DialpadFragment getDialpadFragment() {
linyuh69a25062017-11-15 16:18:51 -0800870 FragmentManager fragmentManager = getDialpadFragmentManager();
871 if (fragmentManager == null) {
872 return null;
873 }
linyuhc3968e62017-11-20 17:40:50 -0800874 return (DialpadFragment) fragmentManager.findFragmentByTag(Tags.DIALPAD_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -0800875 }
876
877 public void onForegroundCallChanged(DialerCall newForegroundCall) {
linyuh57b093b2017-11-17 14:32:32 -0800878 updateTaskDescription();
879
880 if (newForegroundCall == null || !didShowAnswerScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800881 LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color");
linyuh57b093b2017-11-17 14:32:32 -0800882 updateWindowBackgroundColor(0 /* progress */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800883 }
884 }
885
linyuhc3968e62017-11-20 17:40:50 -0800886 private void updateTaskDescription() {
linyuh57b093b2017-11-17 14:32:32 -0800887 int color =
888 getResources().getBoolean(R.bool.is_layout_landscape)
889 ? ResourcesCompat.getColor(
890 getResources(), R.color.statusbar_background_color, getTheme())
891 : InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor();
892 setTaskDescription(
893 new TaskDescription(
894 getResources().getString(R.string.notification_ongoing_call), null /* icon */, color));
895 }
896
Eric Erfanianccca3152017-02-22 16:32:36 -0800897 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
898 ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager();
899 @ColorInt int top;
900 @ColorInt int middle;
901 @ColorInt int bottom;
902 @ColorInt int gray = 0x66000000;
903
linyuh437ae952018-03-26 12:46:18 -0700904 if (isInMultiWindowMode()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800905 top = themeColorManager.getBackgroundColorSolid();
906 middle = themeColorManager.getBackgroundColorSolid();
907 bottom = themeColorManager.getBackgroundColorSolid();
908 } else {
909 top = themeColorManager.getBackgroundColorTop();
910 middle = themeColorManager.getBackgroundColorMiddle();
911 bottom = themeColorManager.getBackgroundColorBottom();
912 }
913
914 if (progress < 0) {
915 float correctedProgress = Math.abs(progress);
916 top = ColorUtils.blendARGB(top, gray, correctedProgress);
917 middle = ColorUtils.blendARGB(middle, gray, correctedProgress);
918 bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress);
919 }
920
921 boolean backgroundDirty = false;
922 if (backgroundDrawable == null) {
923 backgroundDrawableColors = new int[] {top, middle, bottom};
924 backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors);
925 backgroundDirty = true;
926 } else {
927 if (backgroundDrawableColors[0] != top) {
928 backgroundDrawableColors[0] = top;
929 backgroundDirty = true;
930 }
931 if (backgroundDrawableColors[1] != middle) {
932 backgroundDrawableColors[1] = middle;
933 backgroundDirty = true;
934 }
935 if (backgroundDrawableColors[2] != bottom) {
936 backgroundDrawableColors[2] = bottom;
937 backgroundDirty = true;
938 }
939 if (backgroundDirty) {
940 backgroundDrawable.setColors(backgroundDrawableColors);
941 }
942 }
943
944 if (backgroundDirty) {
945 getWindow().setBackgroundDrawable(backgroundDrawable);
946 }
947 }
948
949 public boolean isVisible() {
950 return isVisible;
951 }
952
953 public boolean getCallCardFragmentVisible() {
erfaniand05d8992018-03-20 19:42:26 -0700954 return didShowInCallScreen
955 || didShowVideoCallScreen
956 || didShowRttCallScreen
957 || didShowSpeakEasyScreen;
Eric Erfanianccca3152017-02-22 16:32:36 -0800958 }
959
960 public void dismissKeyguard(boolean dismiss) {
linyuh9c327da2017-11-14 12:33:48 -0800961 if (dismissKeyguard == dismiss) {
962 return;
963 }
964
965 dismissKeyguard = dismiss;
966 if (dismiss) {
967 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
968 } else {
969 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
970 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800971 }
972
linyuhc3968e62017-11-20 17:40:50 -0800973 public void showDialogForPostCharWait(String callId, String chars) {
yuega489f512018-04-25 12:01:09 -0700974 PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars);
975 fragment.show(getSupportFragmentManager(), Tags.POST_CHAR_DIALOG_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -0800976 }
977
linyuh7b86f562017-11-16 11:24:09 -0800978 public void showDialogOrToastForDisconnectedCall(DisconnectMessage disconnectMessage) {
979 LogUtil.i(
980 "InCallActivity.showDialogOrToastForDisconnectedCall",
981 "disconnect cause: %s",
982 disconnectMessage);
983
984 if (disconnectMessage.dialog == null || isFinishing()) {
985 return;
986 }
987
988 dismissPendingDialogs();
989
990 // Show a toast if the app is in background when a dialog can't be visible.
991 if (!isVisible()) {
992 Toast.makeText(getApplicationContext(), disconnectMessage.toastMessage, Toast.LENGTH_LONG)
993 .show();
994 return;
995 }
996
997 // Show the dialog.
linyuhc3968e62017-11-20 17:40:50 -0800998 errorDialog = disconnectMessage.dialog;
linyuh7b86f562017-11-16 11:24:09 -0800999 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog");
1000 disconnectMessage.dialog.setOnDismissListener(
1001 dialogInterface -> {
1002 lock.release();
1003 onDialogDismissed();
1004 });
1005 disconnectMessage.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
1006 disconnectMessage.dialog.show();
1007 }
1008
1009 private void onDialogDismissed() {
linyuhc3968e62017-11-20 17:40:50 -08001010 errorDialog = null;
linyuh7b86f562017-11-16 11:24:09 -08001011 CallList.getInstance().onErrorDialogDismissed();
Eric Erfanianccca3152017-02-22 16:32:36 -08001012 }
1013
1014 public void dismissPendingDialogs() {
linyuhc3968e62017-11-20 17:40:50 -08001015 LogUtil.enterBlock("InCallActivity.dismissPendingDialogs");
linyuhf99f6302017-11-15 11:23:51 -08001016
1017 if (!isVisible) {
1018 // Defer the dismissing action as the activity is not visible and onSaveInstanceState may have
1019 // been called.
Eric Erfanianccca3152017-02-22 16:32:36 -08001020 LogUtil.i(
1021 "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible");
1022 needDismissPendingDialogs = true;
linyuhf99f6302017-11-15 11:23:51 -08001023 return;
Eric Erfanianccca3152017-02-22 16:32:36 -08001024 }
linyuhf99f6302017-11-15 11:23:51 -08001025
1026 // Dismiss the error dialog
linyuhf99f6302017-11-15 11:23:51 -08001027 if (errorDialog != null) {
1028 errorDialog.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001029 errorDialog = null;
linyuhf99f6302017-11-15 11:23:51 -08001030 }
1031
1032 // Dismiss the phone account selection dialog
linyuhf99f6302017-11-15 11:23:51 -08001033 if (selectPhoneAccountDialogFragment != null) {
1034 selectPhoneAccountDialogFragment.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001035 selectPhoneAccountDialogFragment = null;
linyuhf99f6302017-11-15 11:23:51 -08001036 }
1037
1038 // Dismiss the dialog for international call on WiFi
1039 InternationalCallOnWifiDialogFragment internationalCallOnWifiFragment =
1040 (InternationalCallOnWifiDialogFragment)
linyuhc3968e62017-11-20 17:40:50 -08001041 getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
linyuhf99f6302017-11-15 11:23:51 -08001042 if (internationalCallOnWifiFragment != null) {
1043 internationalCallOnWifiFragment.dismiss();
1044 }
1045
1046 // Dismiss the answer screen
1047 AnswerScreen answerScreen = getAnswerScreen();
1048 if (answerScreen != null) {
1049 answerScreen.dismissPendingDialogs();
1050 }
1051
1052 needDismissPendingDialogs = false;
Eric Erfanianccca3152017-02-22 16:32:36 -08001053 }
1054
linyuhc3968e62017-11-20 17:40:50 -08001055 private void enableInCallOrientationEventListener(boolean enable) {
linyuh69a25062017-11-15 16:18:51 -08001056 if (enable) {
1057 inCallOrientationEventListener.enable(true /* notifyDeviceOrientationChange */);
1058 } else {
1059 inCallOrientationEventListener.disable();
1060 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001061 }
1062
1063 public void setExcludeFromRecents(boolean exclude) {
linyuhc3968e62017-11-20 17:40:50 -08001064 int taskId = getTaskId();
1065
1066 List<AppTask> tasks = getSystemService(ActivityManager.class).getAppTasks();
1067 for (AppTask task : tasks) {
1068 try {
1069 if (task.getTaskInfo().id == taskId) {
1070 task.setExcludeFromRecents(exclude);
1071 }
1072 } catch (RuntimeException e) {
1073 LogUtil.e("InCallActivity.setExcludeFromRecents", "RuntimeException:\n%s", e);
1074 }
1075 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001076 }
1077
Eric Erfanianccca3152017-02-22 16:32:36 -08001078 @Nullable
1079 public FragmentManager getDialpadFragmentManager() {
wangqifd4c9f72018-03-08 18:21:50 -08001080 InCallScreen inCallScreen = getInCallOrRttCallScreen();
Eric Erfanianccca3152017-02-22 16:32:36 -08001081 if (inCallScreen != null) {
1082 return inCallScreen.getInCallScreenFragment().getChildFragmentManager();
1083 }
1084 return null;
1085 }
1086
1087 public int getDialpadContainerId() {
wangqifd4c9f72018-03-08 18:21:50 -08001088 return getInCallOrRttCallScreen().getAnswerAndDialpadContainerResourceId();
Eric Erfanianccca3152017-02-22 16:32:36 -08001089 }
1090
1091 @Override
1092 public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) {
1093 DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId());
1094 if (call == null) {
1095 // This is a work around for a bug where we attempt to create a new delegate after the call
1096 // has already been removed. An example of when this can happen is:
1097 // 1. incoming video call in landscape mode
1098 // 2. remote party hangs up
1099 // 3. activity switches from landscape to portrait
1100 // At step #3 the answer fragment will try to create a new answer delegate but the call won't
1101 // exist. In this case we'll simply return a stub delegate that does nothing. This is ok
1102 // because this new state is transient and the activity will be destroyed soon.
1103 LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub");
1104 return new AnswerScreenPresenterStub();
1105 } else {
1106 return new AnswerScreenPresenter(
1107 this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId()));
1108 }
1109 }
1110
1111 @Override
1112 public InCallScreenDelegate newInCallScreenDelegate() {
1113 return new CallCardPresenter(this);
1114 }
1115
1116 @Override
1117 public InCallButtonUiDelegate newInCallButtonUiDelegate() {
1118 return new CallButtonPresenter(this);
1119 }
1120
1121 @Override
Eric Erfanian90508232017-03-24 09:31:16 -07001122 public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) {
1123 DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId());
1124 if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) {
1125 return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen);
1126 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001127 return new VideoCallPresenter();
1128 }
1129
1130 public void onPrimaryCallStateChanged() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001131 Trace.beginSection("InCallActivity.onPrimaryCallStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -08001132 showMainInCallFragment();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001133 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001134 }
1135
linyuh7b86f562017-11-16 11:24:09 -08001136 public void showDialogOrToastForWifiHandoverFailure(DialerCall call) {
1137 if (call.showWifiHandoverAlertAsToast()) {
1138 Toast.makeText(this, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT)
1139 .show();
1140 return;
1141 }
1142
1143 dismissPendingDialogs();
1144
1145 AlertDialog.Builder builder =
1146 new AlertDialog.Builder(this).setTitle(R.string.video_call_lte_to_wifi_failed_title);
1147
1148 // This allows us to use the theme of the dialog instead of the activity
1149 View dialogCheckBoxView =
1150 View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null /* root */);
1151 CheckBox wifiHandoverFailureCheckbox =
1152 (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox);
1153 wifiHandoverFailureCheckbox.setChecked(false);
1154
1155 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog");
linyuhc3968e62017-11-20 17:40:50 -08001156 errorDialog =
linyuh7b86f562017-11-16 11:24:09 -08001157 builder
1158 .setView(dialogCheckBoxView)
1159 .setMessage(R.string.video_call_lte_to_wifi_failed_message)
1160 .setOnCancelListener(dialogInterface -> onDialogDismissed())
1161 .setPositiveButton(
1162 android.R.string.ok,
1163 (dialogInterface, id) -> {
1164 call.setDoNotShowDialogForHandoffToWifiFailure(
1165 wifiHandoverFailureCheckbox.isChecked());
1166 dialogInterface.cancel();
1167 onDialogDismissed();
1168 })
1169 .setOnDismissListener(dialogInterface -> lock.release())
1170 .create();
linyuh7b86f562017-11-16 11:24:09 -08001171 errorDialog.show();
Eric Erfanianccca3152017-02-22 16:32:36 -08001172 }
1173
linyuh7b86f562017-11-16 11:24:09 -08001174 public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) {
linyuh7b86f562017-11-16 11:24:09 -08001175 InternationalCallOnWifiDialogFragment fragment =
yuegb47528e2018-04-24 12:12:57 -07001176 InternationalCallOnWifiDialogFragment.newInstance(call.getId());
linyuhc3968e62017-11-20 17:40:50 -08001177 fragment.show(getSupportFragmentManager(), Tags.INTERNATIONAL_CALL_ON_WIFI);
Eric Erfanianc857f902017-05-15 14:05:33 -07001178 }
1179
wangqibc28ea72018-04-02 16:23:00 -07001180 public void showDialogForRttRequest(DialerCall call, int rttRequestId) {
1181 LogUtil.enterBlock("InCallActivity.showDialogForRttRequest");
1182 DialogFragment fragment = RttRequestDialogFragment.newInstance(call.getId(), rttRequestId);
1183 fragment.show(getSupportFragmentManager(), Tags.RTT_REQUEST_DIALOG);
1184 }
1185
Eric Erfanian938468d2017-10-24 14:05:52 -07001186 @Override
1187 public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
1188 super.onMultiWindowModeChanged(isInMultiWindowMode);
linyuh57b093b2017-11-17 14:32:32 -08001189 updateNavigationBar(isDialpadVisible());
1190 }
1191
linyuhc3968e62017-11-20 17:40:50 -08001192 private void updateNavigationBar(boolean isDialpadVisible) {
linyuh437ae952018-03-26 12:46:18 -07001193 if (isInMultiWindowMode()) {
linyuh57b093b2017-11-17 14:32:32 -08001194 return;
1195 }
1196
1197 View navigationBarBackground = getWindow().findViewById(R.id.navigation_bar_background);
1198 if (navigationBarBackground != null) {
1199 navigationBarBackground.setVisibility(isDialpadVisible ? View.VISIBLE : View.GONE);
Eric Erfanian938468d2017-10-24 14:05:52 -07001200 }
1201 }
1202
Eric Erfanianccca3152017-02-22 16:32:36 -08001203 public void setAllowOrientationChange(boolean allowOrientationChange) {
wangqi9982f0d2017-10-11 17:46:07 -07001204 if (this.allowOrientationChange == allowOrientationChange) {
1205 return;
1206 }
1207 this.allowOrientationChange = allowOrientationChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001208 if (!allowOrientationChange) {
1209 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_DISALLOW_ROTATION);
1210 } else {
1211 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
1212 }
1213 enableInCallOrientationEventListener(allowOrientationChange);
1214 }
1215
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001216 public void hideMainInCallFragment() {
linyuhc3968e62017-11-20 17:40:50 -08001217 LogUtil.enterBlock("InCallActivity.hideMainInCallFragment");
1218 if (getCallCardFragmentVisible()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001219 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1220 hideInCallScreenFragment(transaction);
1221 hideVideoCallScreenFragment(transaction);
1222 transaction.commitAllowingStateLoss();
1223 getSupportFragmentManager().executePendingTransactions();
1224 }
1225 }
1226
1227 private void showMainInCallFragment() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001228 Trace.beginSection("InCallActivity.showMainInCallFragment");
Eric Erfanianccca3152017-02-22 16:32:36 -08001229 // If the activity's onStart method hasn't been called yet then defer doing any work.
1230 if (!isVisible) {
1231 LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001232 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001233 return;
1234 }
1235
1236 // Don't let this be reentrant.
1237 if (isInShowMainInCallFragment) {
1238 LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001239 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001240 return;
1241 }
1242
1243 isInShowMainInCallFragment = true;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001244 ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi();
1245 ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi();
wangqi219b8702018-02-13 09:34:41 -08001246 ShouldShowUiResult shouldShowRttUi = getShouldShowRttUi();
erfaniand05d8992018-03-20 19:42:26 -07001247 ShouldShowUiResult shouldShowSpeakEasyUi = getShouldShowSpeakEasyUi();
Eric Erfanianccca3152017-02-22 16:32:36 -08001248 LogUtil.i(
1249 "InCallActivity.showMainInCallFragment",
wangqi219b8702018-02-13 09:34:41 -08001250 "shouldShowAnswerUi: %b, shouldShowRttUi: %b, shouldShowVideoUi: %b "
1251 + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowRttCallScreen: %b, "
erfaniand05d8992018-03-20 19:42:26 -07001252 + "didShowVideoCallScreen: %b"
1253 + "didShowSpeakEasyScreen: %b",
Eric Erfanianccca3152017-02-22 16:32:36 -08001254 shouldShowAnswerUi.shouldShow,
wangqi219b8702018-02-13 09:34:41 -08001255 shouldShowRttUi.shouldShow,
Eric Erfanian10b34a52017-05-04 08:23:17 -07001256 shouldShowVideoUi.shouldShow,
Eric Erfanianccca3152017-02-22 16:32:36 -08001257 didShowAnswerScreen,
1258 didShowInCallScreen,
wangqi219b8702018-02-13 09:34:41 -08001259 didShowRttCallScreen,
erfaniand05d8992018-03-20 19:42:26 -07001260 didShowVideoCallScreen,
1261 didShowSpeakEasyScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -08001262 // Only video call ui allows orientation change.
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001263 setAllowOrientationChange(shouldShowVideoUi.shouldShow);
Eric Erfanianccca3152017-02-22 16:32:36 -08001264
1265 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
wangqi219b8702018-02-13 09:34:41 -08001266 boolean didChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001267 if (shouldShowAnswerUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001268 didChange = hideInCallScreenFragment(transaction);
1269 didChange |= hideVideoCallScreenFragment(transaction);
1270 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001271 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001272 didChange |= showAnswerScreenFragment(transaction, shouldShowAnswerUi.call);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001273 } else if (shouldShowVideoUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001274 didChange = hideInCallScreenFragment(transaction);
1275 didChange |= showVideoCallScreenFragment(transaction, shouldShowVideoUi.call);
1276 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001277 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001278 didChange |= hideAnswerScreenFragment(transaction);
1279 } else if (shouldShowRttUi.shouldShow) {
1280 didChange = hideInCallScreenFragment(transaction);
1281 didChange |= hideVideoCallScreenFragment(transaction);
1282 didChange |= hideAnswerScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001283 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001284 didChange |= showRttCallScreenFragment(transaction, shouldShowRttUi.call);
erfaniand05d8992018-03-20 19:42:26 -07001285 } else if (shouldShowSpeakEasyUi.shouldShow) {
1286 didChange = hideInCallScreenFragment(transaction);
1287 didChange |= hideVideoCallScreenFragment(transaction);
1288 didChange |= hideAnswerScreenFragment(transaction);
1289 didChange |= hideRttCallScreenFragment(transaction);
1290 didChange |= showSpeakEasyFragment(transaction, shouldShowSpeakEasyUi.call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001291 } else {
wangqi219b8702018-02-13 09:34:41 -08001292 didChange = showInCallScreenFragment(transaction);
1293 didChange |= hideVideoCallScreenFragment(transaction);
1294 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001295 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001296 didChange |= hideAnswerScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001297 }
1298
wangqi219b8702018-02-13 09:34:41 -08001299 if (didChange) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001300 Trace.beginSection("InCallActivity.commitTransaction");
Eric Erfanianccca3152017-02-22 16:32:36 -08001301 transaction.commitNow();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001302 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001303 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1304 }
1305 isInShowMainInCallFragment = false;
Eric Erfanian2ca43182017-08-31 06:57:16 -07001306 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001307 }
1308
erfaniand05d8992018-03-20 19:42:26 -07001309 private boolean showSpeakEasyFragment(FragmentTransaction transaction, DialerCall call) {
1310
erfaniand05d8992018-03-20 19:42:26 -07001311 if (didShowSpeakEasyScreen) {
erfanian612d13a2018-04-04 15:27:57 -07001312 if (lastShownSpeakEasyScreenUniqueCallid.equals(call.getUniqueCallId())) {
erfanian12243de2018-04-17 12:17:08 -07001313 LogUtil.i("InCallActivity.showSpeakEasyFragment", "found existing fragment");
erfanian612d13a2018-04-04 15:27:57 -07001314 return false;
1315 }
1316 hideSpeakEasyFragment(transaction);
erfanian12243de2018-04-17 12:17:08 -07001317 LogUtil.i("InCallActivity.showSpeakEasyFragment", "hid existing fragment");
erfaniand05d8992018-03-20 19:42:26 -07001318 }
1319
1320 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1321 if (speakEasyFragment.isPresent()) {
1322 transaction.add(R.id.main, speakEasyFragment.get(), Tags.SPEAK_EASY_SCREEN);
1323 didShowSpeakEasyScreen = true;
erfanian612d13a2018-04-04 15:27:57 -07001324 lastShownSpeakEasyScreenUniqueCallid = call.getUniqueCallId();
erfanian12243de2018-04-17 12:17:08 -07001325 LogUtil.i(
1326 "InCallActivity.showSpeakEasyFragment",
1327 "set fragment for call %s",
1328 lastShownSpeakEasyScreenUniqueCallid);
erfaniand05d8992018-03-20 19:42:26 -07001329 return true;
1330 }
1331 return false;
1332 }
1333
1334 private Fragment getSpeakEasyScreen() {
1335 return getSupportFragmentManager().findFragmentByTag(Tags.SPEAK_EASY_SCREEN);
1336 }
1337
1338 private boolean hideSpeakEasyFragment(FragmentTransaction transaction) {
1339 if (!didShowSpeakEasyScreen) {
1340 return false;
1341 }
1342
1343 Fragment speakEasyFragment = getSpeakEasyScreen();
1344
1345 if (speakEasyFragment != null) {
1346 transaction.remove(speakEasyFragment);
1347 didShowSpeakEasyScreen = false;
1348 return true;
1349 }
1350 return false;
1351 }
1352
erfanian12243de2018-04-17 12:17:08 -07001353 @VisibleForTesting
erfaniand05d8992018-03-20 19:42:26 -07001354 public void setSpeakEasyCallManager(SpeakEasyCallManager speakEasyCallManager) {
erfanian87dbb622018-04-04 15:43:00 -07001355 this.speakEasyCallManager = speakEasyCallManager;
erfaniand05d8992018-03-20 19:42:26 -07001356 }
1357
erfanian12243de2018-04-17 12:17:08 -07001358 @Nullable
erfaniand05d8992018-03-20 19:42:26 -07001359 public SpeakEasyCallManager getSpeakEasyCallManager() {
erfanian12243de2018-04-17 12:17:08 -07001360 if (this.speakEasyCallManager == null) {
1361 this.speakEasyCallManager = InCallPresenter.getInstance().getSpeakEasyCallManager();
1362 }
erfaniand05d8992018-03-20 19:42:26 -07001363 return speakEasyCallManager;
1364 }
1365
1366 private ShouldShowUiResult getShouldShowSpeakEasyUi() {
1367 SpeakEasyCallManager speakEasyCallManager = getSpeakEasyCallManager();
1368
1369 if (speakEasyCallManager == null) {
1370 return new ShouldShowUiResult(false, null);
1371 }
1372
erfanian3bb7cb62018-04-11 09:01:15 -07001373 DialerCall call =
1374 CallList.getInstance().getIncomingCall() != null
1375 ? CallList.getInstance().getIncomingCall()
1376 : CallList.getInstance().getActiveCall();
erfaniand05d8992018-03-20 19:42:26 -07001377
1378 if (call == null) {
1379 return new ShouldShowUiResult(false, call);
1380 }
1381
1382 if (!call.isSpeakEasyCall() || !call.isSpeakEasyEligible()) {
1383 return new ShouldShowUiResult(false, call);
1384 }
1385
1386 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1387
1388 if (!speakEasyFragment.isPresent()) {
1389 return new ShouldShowUiResult(false, call);
1390 }
1391 return new ShouldShowUiResult(true, call);
1392 }
1393
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001394 private ShouldShowUiResult getShouldShowAnswerUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001395 DialerCall call = CallList.getInstance().getIncomingCall();
erfanian3bb7cb62018-04-11 09:01:15 -07001396 if (call != null && !call.isSpeakEasyCall()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001397 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001398 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001399 }
1400
1401 call = CallList.getInstance().getVideoUpgradeRequestCall();
1402 if (call != null) {
1403 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001404 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001405 }
1406
1407 // Check if we're showing the answer screen and the call is disconnected. If this condition is
1408 // true then we won't switch from the answer UI to the in call UI. This prevents flicker when
1409 // the user rejects an incoming call.
1410 call = CallList.getInstance().getFirstCall();
1411 if (call == null) {
1412 call = CallList.getInstance().getBackgroundCall();
1413 }
wangqibb94ca62018-04-27 14:34:04 -07001414 if (didShowAnswerScreen && (call == null || call.getState() == DialerCallState.DISCONNECTED)) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001415 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001416 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001417 }
1418
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001419 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001420 }
1421
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001422 private static ShouldShowUiResult getShouldShowVideoUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001423 DialerCall call = CallList.getInstance().getFirstCall();
1424 if (call == null) {
1425 LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001426 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001427 }
1428
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001429 if (call.isVideoCall()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001430 LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001431 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001432 }
1433
linyuh8fbecce2017-12-18 13:53:09 -08001434 if (call.hasSentVideoUpgradeRequest() || call.hasReceivedVideoUpgradeRequest()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001435 LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001436 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001437 }
1438
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001439 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001440 }
1441
wangqi219b8702018-02-13 09:34:41 -08001442 private static ShouldShowUiResult getShouldShowRttUi() {
1443 DialerCall call = CallList.getInstance().getFirstCall();
1444 if (call == null) {
1445 LogUtil.i("InCallActivity.getShouldShowRttUi", "null call");
1446 return new ShouldShowUiResult(false, null);
1447 }
1448
wangqif6be6172018-03-30 15:57:56 -07001449 if (call.isActiveRttCall()) {
wangqi219b8702018-02-13 09:34:41 -08001450 LogUtil.i("InCallActivity.getShouldShowRttUi", "found rtt call");
1451 return new ShouldShowUiResult(true, call);
1452 }
1453
1454 if (call.hasSentRttUpgradeRequest()) {
1455 LogUtil.i("InCallActivity.getShouldShowRttUi", "upgrading to rtt");
1456 return new ShouldShowUiResult(true, call);
1457 }
1458
1459 return new ShouldShowUiResult(false, null);
1460 }
1461
Eric Erfanianccca3152017-02-22 16:32:36 -08001462 private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) {
1463 // When rejecting a call the active call can become null in which case we should continue
1464 // showing the answer screen.
1465 if (didShowAnswerScreen && call == null) {
1466 return false;
1467 }
1468
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001469 Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null");
1470
1471 boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -08001472
1473 // Check if we're already showing an answer screen for this call.
1474 if (didShowAnswerScreen) {
1475 AnswerScreen answerScreen = getAnswerScreen();
1476 if (answerScreen.getCallId().equals(call.getId())
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001477 && answerScreen.isVideoCall() == call.isVideoCall()
Eric Erfanian2ca43182017-08-31 06:57:16 -07001478 && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest
1479 && !answerScreen.isActionTimeout()) {
1480 LogUtil.d(
1481 "InCallActivity.showAnswerScreenFragment",
1482 "answer fragment exists for same call and has NOT been accepted/rejected/timed out");
Eric Erfanianccca3152017-02-22 16:32:36 -08001483 return false;
1484 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001485 if (answerScreen.isActionTimeout()) {
1486 LogUtil.i(
1487 "InCallActivity.showAnswerScreenFragment",
1488 "answer fragment exists but has been accepted/rejected and timed out");
1489 } else {
1490 LogUtil.i(
1491 "InCallActivity.showAnswerScreenFragment",
1492 "answer fragment exists but arguments do not match");
1493 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001494 hideAnswerScreenFragment(transaction);
1495 }
1496
1497 // Show a new answer screen.
1498 AnswerScreen answerScreen =
Eric Erfanianfc37b022017-03-21 10:11:17 -07001499 AnswerBindings.createAnswerScreen(
1500 call.getId(),
wangqif6be6172018-03-30 15:57:56 -07001501 call.isActiveRttCall(),
Eric Erfanianfc37b022017-03-21 10:11:17 -07001502 call.isVideoCall(),
1503 isVideoUpgradeRequest,
Eric Erfanian90508232017-03-24 09:31:16 -07001504 call.getVideoTech().isSelfManagedCamera(),
1505 shouldAllowAnswerAndRelease(call),
erfaniand05d8992018-03-20 19:42:26 -07001506 CallList.getInstance().getBackgroundCall() != null,
1507 call.isSpeakEasyEligible());
linyuhc3968e62017-11-20 17:40:50 -08001508 transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001509
1510 Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this);
1511 didShowAnswerScreen = true;
1512 return true;
1513 }
1514
Eric Erfanian90508232017-03-24 09:31:16 -07001515 private boolean shouldAllowAnswerAndRelease(DialerCall call) {
1516 if (CallList.getInstance().getActiveCall() == null) {
1517 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call");
1518 return false;
1519 }
1520 if (getSystemService(TelephonyManager.class).getPhoneType()
1521 == TelephonyManager.PHONE_TYPE_CDMA) {
1522 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported");
1523 return false;
1524 }
1525 if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) {
1526 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call");
1527 return false;
1528 }
linyuhc3968e62017-11-20 17:40:50 -08001529 if (!ConfigProviderBindings.get(this)
1530 .getBoolean(ConfigNames.ANSWER_AND_RELEASE_ENABLED, true)) {
Eric Erfanian90508232017-03-24 09:31:16 -07001531 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config");
1532 return false;
1533 }
1534
1535 return true;
1536 }
1537
Eric Erfanianccca3152017-02-22 16:32:36 -08001538 private boolean hideAnswerScreenFragment(FragmentTransaction transaction) {
1539 if (!didShowAnswerScreen) {
1540 return false;
1541 }
1542 AnswerScreen answerScreen = getAnswerScreen();
1543 if (answerScreen != null) {
1544 transaction.remove(answerScreen.getAnswerScreenFragment());
1545 }
1546
1547 didShowAnswerScreen = false;
1548 return true;
1549 }
1550
1551 private boolean showInCallScreenFragment(FragmentTransaction transaction) {
1552 if (didShowInCallScreen) {
1553 return false;
1554 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001555 InCallScreen inCallScreen = InCallBindings.createInCallScreen();
linyuhc3968e62017-11-20 17:40:50 -08001556 transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001557 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1558 didShowInCallScreen = true;
1559 return true;
1560 }
1561
1562 private boolean hideInCallScreenFragment(FragmentTransaction transaction) {
1563 if (!didShowInCallScreen) {
1564 return false;
1565 }
1566 InCallScreen inCallScreen = getInCallScreen();
1567 if (inCallScreen != null) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001568 transaction.remove(inCallScreen.getInCallScreenFragment());
Eric Erfanianccca3152017-02-22 16:32:36 -08001569 }
1570 didShowInCallScreen = false;
1571 return true;
1572 }
1573
wangqi219b8702018-02-13 09:34:41 -08001574 private boolean showRttCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
1575 if (didShowRttCallScreen) {
1576 // This shouldn't happen since only one RTT call is allow at same time.
1577 if (!getRttCallScreen().getCallId().equals(call.getId())) {
1578 LogUtil.e("InCallActivity.showRttCallScreenFragment", "RTT call id doesn't match");
1579 }
1580 return false;
1581 }
1582 RttCallScreen rttCallScreen = RttBindings.createRttCallScreen(call.getId());
1583 transaction.add(R.id.main, rttCallScreen.getRttCallScreenFragment(), Tags.RTT_CALL_SCREEN);
1584 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1585 didShowRttCallScreen = true;
1586 return true;
1587 }
1588
1589 private boolean hideRttCallScreenFragment(FragmentTransaction transaction) {
1590 if (!didShowRttCallScreen) {
1591 return false;
1592 }
1593 RttCallScreen rttCallScreen = getRttCallScreen();
1594 if (rttCallScreen != null) {
1595 transaction.remove(rttCallScreen.getRttCallScreenFragment());
1596 }
1597 didShowRttCallScreen = false;
1598 return true;
1599 }
1600
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001601 private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001602 if (didShowVideoCallScreen) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001603 VideoCallScreen videoCallScreen = getVideoCallScreen();
1604 if (videoCallScreen.getCallId().equals(call.getId())) {
1605 return false;
1606 }
1607 LogUtil.i(
1608 "InCallActivity.showVideoCallScreenFragment",
1609 "video call fragment exists but arguments do not match");
1610 hideVideoCallScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001611 }
1612
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001613 LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call);
1614
Eric Erfanian90508232017-03-24 09:31:16 -07001615 VideoCallScreen videoCallScreen =
1616 VideoBindings.createVideoCallScreen(
1617 call.getId(), call.getVideoTech().shouldUseSurfaceView());
linyuhc3968e62017-11-20 17:40:50 -08001618 transaction.add(
1619 R.id.main, videoCallScreen.getVideoCallScreenFragment(), Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001620
1621 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1622 didShowVideoCallScreen = true;
1623 return true;
1624 }
1625
1626 private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) {
1627 if (!didShowVideoCallScreen) {
1628 return false;
1629 }
1630 VideoCallScreen videoCallScreen = getVideoCallScreen();
1631 if (videoCallScreen != null) {
1632 transaction.remove(videoCallScreen.getVideoCallScreenFragment());
1633 }
1634 didShowVideoCallScreen = false;
1635 return true;
1636 }
1637
linyuhc3968e62017-11-20 17:40:50 -08001638 private AnswerScreen getAnswerScreen() {
1639 return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001640 }
1641
linyuhc3968e62017-11-20 17:40:50 -08001642 private InCallScreen getInCallScreen() {
1643 return (InCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001644 }
1645
linyuhc3968e62017-11-20 17:40:50 -08001646 private VideoCallScreen getVideoCallScreen() {
1647 return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001648 }
1649
wangqi219b8702018-02-13 09:34:41 -08001650 private RttCallScreen getRttCallScreen() {
1651 return (RttCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.RTT_CALL_SCREEN);
1652 }
1653
wangqifd4c9f72018-03-08 18:21:50 -08001654 private InCallScreen getInCallOrRttCallScreen() {
1655 InCallScreen inCallScreen = null;
1656 if (didShowInCallScreen) {
1657 inCallScreen = getInCallScreen();
1658 }
1659 if (didShowRttCallScreen) {
1660 inCallScreen = getRttCallScreen();
1661 }
1662 return inCallScreen;
1663 }
1664
Eric Erfanianccca3152017-02-22 16:32:36 -08001665 @Override
1666 public void onPseudoScreenStateChanged(boolean isOn) {
1667 LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn);
1668 pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE);
1669 }
1670
1671 /**
1672 * For some touch related issue, turning off the screen can be faked by drawing a black view over
1673 * the activity. All touch events started when the screen is "off" is rejected.
1674 *
1675 * @see PseudoScreenState
1676 */
1677 @Override
1678 public boolean dispatchTouchEvent(MotionEvent event) {
1679 // Reject any gesture that started when the screen is in the fake off state.
1680 if (touchDownWhenPseudoScreenOff) {
1681 if (event.getAction() == MotionEvent.ACTION_UP) {
1682 touchDownWhenPseudoScreenOff = false;
1683 }
1684 return true;
1685 }
1686 // Reject all touch event when the screen is in the fake off state.
1687 if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) {
1688 if (event.getAction() == MotionEvent.ACTION_DOWN) {
1689 touchDownWhenPseudoScreenOff = true;
1690 LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff");
1691 }
1692 return true;
1693 }
1694 return super.dispatchTouchEvent(event);
1695 }
1696
wangqi219b8702018-02-13 09:34:41 -08001697 @Override
1698 public RttCallScreenDelegate newRttCallScreenDelegate(RttCallScreen videoCallScreen) {
1699 return new RttCallPresenter();
1700 }
1701
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001702 private static class ShouldShowUiResult {
Eric Erfanianccca3152017-02-22 16:32:36 -08001703 public final boolean shouldShow;
1704 public final DialerCall call;
1705
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001706 ShouldShowUiResult(boolean shouldShow, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001707 this.shouldShow = shouldShow;
1708 this.call = call;
1709 }
1710 }
linyuhc3968e62017-11-20 17:40:50 -08001711
1712 private static final class IntentExtraNames {
1713 static final String FOR_FULL_SCREEN = "InCallActivity.for_full_screen_intent";
1714 static final String NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call";
1715 static final String SHOW_DIALPAD = "InCallActivity.show_dialpad";
1716 }
1717
1718 private static final class KeysForSavedInstance {
1719 static final String DIALPAD_TEXT = "InCallActivity.dialpad_text";
1720 static final String DID_SHOW_ANSWER_SCREEN = "did_show_answer_screen";
1721 static final String DID_SHOW_IN_CALL_SCREEN = "did_show_in_call_screen";
1722 static final String DID_SHOW_VIDEO_CALL_SCREEN = "did_show_video_call_screen";
wangqi153af2f2018-02-15 16:21:49 -08001723 static final String DID_SHOW_RTT_CALL_SCREEN = "did_show_rtt_call_screen";
erfaniand05d8992018-03-20 19:42:26 -07001724 static final String DID_SHOW_SPEAK_EASY_SCREEN = "did_show_speak_easy_screen";
linyuhc3968e62017-11-20 17:40:50 -08001725 }
1726
1727 /** Request codes for pending intents. */
1728 public static final class PendingIntentRequestCodes {
1729 static final int NON_FULL_SCREEN = 0;
1730 static final int FULL_SCREEN = 1;
1731 static final int BUBBLE = 2;
1732 }
1733
1734 private static final class Tags {
1735 static final String ANSWER_SCREEN = "tag_answer_screen";
1736 static final String DIALPAD_FRAGMENT = "tag_dialpad_fragment";
1737 static final String IN_CALL_SCREEN = "tag_in_call_screen";
1738 static final String INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi";
1739 static final String SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment";
1740 static final String VIDEO_CALL_SCREEN = "tag_video_call_screen";
wangqi219b8702018-02-13 09:34:41 -08001741 static final String RTT_CALL_SCREEN = "tag_rtt_call_screen";
linyuhc3968e62017-11-20 17:40:50 -08001742 static final String POST_CHAR_DIALOG_FRAGMENT = "tag_post_char_dialog_fragment";
erfaniand05d8992018-03-20 19:42:26 -07001743 static final String SPEAK_EASY_SCREEN = "tag_speak_easy_screen";
wangqibc28ea72018-04-02 16:23:00 -07001744 static final String RTT_REQUEST_DIALOG = "tag_rtt_request_dialog";
linyuhc3968e62017-11-20 17:40:50 -08001745 }
1746
1747 private static final class ConfigNames {
1748 static final String ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled";
1749 }
1750
linyuhc3968e62017-11-20 17:40:50 -08001751 private static final class SelectPhoneAccountListener
1752 extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener {
1753 private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName();
1754
twyen73a74c32018-03-07 12:12:24 -08001755 private final Context appContext;
1756
1757 SelectPhoneAccountListener(Context appContext) {
1758 this.appContext = appContext;
1759 }
1760
linyuhc3968e62017-11-20 17:40:50 -08001761 @Override
1762 public void onPhoneAccountSelected(
1763 PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) {
1764 DialerCall call = CallList.getInstance().getCallById(callId);
1765 LogUtil.i(TAG, "Phone account select with call:\n%s", call);
1766
1767 if (call != null) {
twyen73a74c32018-03-07 12:12:24 -08001768 call.phoneAccountSelected(selectedAccountHandle, false);
1769 if (call.getPreferredAccountRecorder() != null) {
1770 call.getPreferredAccountRecorder().record(appContext, selectedAccountHandle, setDefault);
1771 }
linyuhc3968e62017-11-20 17:40:50 -08001772 }
1773 }
1774
1775 @Override
1776 public void onDialogDismissed(String callId) {
1777 DialerCall call = CallList.getInstance().getCallById(callId);
1778 LogUtil.i(TAG, "Disconnecting call:\n%s" + call);
1779
1780 if (call != null) {
1781 call.disconnect();
1782 }
1783 }
1784 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001785}