blob: 0f0e9d9f25a0a849a71e4651ef1b9680eace50ed [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;
twyen66adad02018-04-24 13:51:08 -070058import com.android.contacts.common.widget.SelectPhoneAccountDialogOptions;
59import com.android.contacts.common.widget.SelectPhoneAccountDialogOptionsUtil;
linyuhc3968e62017-11-20 17:40:50 -080060import com.android.dialer.animation.AnimUtils;
61import com.android.dialer.animation.AnimationListenerAdapter;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070062import com.android.dialer.common.Assert;
Eric Erfanianccca3152017-02-22 16:32:36 -080063import com.android.dialer.common.LogUtil;
twyen73a74c32018-03-07 12:12:24 -080064import com.android.dialer.common.concurrent.DialerExecutorComponent;
weijiaxu650e7cc2017-10-31 12:38:54 -070065import com.android.dialer.common.concurrent.ThreadUtil;
twyena1723252018-04-24 17:02:57 -070066import com.android.dialer.common.concurrent.UiListener;
Eric Erfanian2ca43182017-08-31 06:57:16 -070067import com.android.dialer.configprovider.ConfigProviderBindings;
twyen73a74c32018-03-07 12:12:24 -080068import com.android.dialer.logging.DialerImpression.Type;
Eric Erfanianccca3152017-02-22 16:32:36 -080069import com.android.dialer.logging.Logger;
Eric Erfanian8369df02017-05-03 10:27:13 -070070import com.android.dialer.logging.ScreenEvent;
zachh7a96dc72018-02-20 22:16:03 -080071import com.android.dialer.metrics.Metrics;
72import com.android.dialer.metrics.MetricsComponent;
twyen73a74c32018-03-07 12:12:24 -080073import com.android.dialer.preferredsim.PreferredAccountRecorder;
74import com.android.dialer.preferredsim.PreferredAccountWorker;
twyena1723252018-04-24 17:02:57 -070075import com.android.dialer.preferredsim.PreferredAccountWorker.Result;
twyen73a74c32018-03-07 12:12:24 -080076import com.android.dialer.preferredsim.suggestion.SuggestionProvider;
linyuhc3968e62017-11-20 17:40:50 -080077import com.android.dialer.util.ViewUtil;
Eric Erfanianccca3152017-02-22 16:32:36 -080078import com.android.incallui.answer.bindings.AnswerBindings;
79import com.android.incallui.answer.protocol.AnswerScreen;
80import com.android.incallui.answer.protocol.AnswerScreenDelegate;
81import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory;
82import com.android.incallui.answerproximitysensor.PseudoScreenState;
linyuh57b093b2017-11-17 14:32:32 -080083import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080084import com.android.incallui.call.CallList;
85import com.android.incallui.call.DialerCall;
linyuh57b093b2017-11-17 14:32:32 -080086import com.android.incallui.call.TelecomAdapter;
wangqibb94ca62018-04-27 14:34:04 -070087import com.android.incallui.call.state.DialerCallState;
Eric Erfanian2ca43182017-08-31 06:57:16 -070088import com.android.incallui.callpending.CallPendingActivity;
89import com.android.incallui.disconnectdialog.DisconnectMessage;
Eric Erfanianccca3152017-02-22 16:32:36 -080090import com.android.incallui.incall.bindings.InCallBindings;
91import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
92import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory;
93import com.android.incallui.incall.protocol.InCallScreen;
94import com.android.incallui.incall.protocol.InCallScreenDelegate;
95import com.android.incallui.incall.protocol.InCallScreenDelegateFactory;
linyuh7b86f562017-11-16 11:24:09 -080096import com.android.incallui.incalluilock.InCallUiLock;
wangqi219b8702018-02-13 09:34:41 -080097import com.android.incallui.rtt.bindings.RttBindings;
98import com.android.incallui.rtt.protocol.RttCallScreen;
99import com.android.incallui.rtt.protocol.RttCallScreenDelegate;
100import com.android.incallui.rtt.protocol.RttCallScreenDelegateFactory;
erfaniand05d8992018-03-20 19:42:26 -0700101import com.android.incallui.speakeasy.SpeakEasyCallManager;
linyuhf99f6302017-11-15 11:23:51 -0800102import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment;
Eric Erfanianccca3152017-02-22 16:32:36 -0800103import com.android.incallui.video.bindings.VideoBindings;
104import com.android.incallui.video.protocol.VideoCallScreen;
105import com.android.incallui.video.protocol.VideoCallScreenDelegate;
106import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory;
linyuhc3968e62017-11-20 17:40:50 -0800107import com.google.common.base.Optional;
twyena1723252018-04-24 17:02:57 -0700108import com.google.common.util.concurrent.ListenableFuture;
linyuhc3968e62017-11-20 17:40:50 -0800109import java.lang.annotation.Retention;
110import java.lang.annotation.RetentionPolicy;
111import java.util.ArrayList;
112import java.util.List;
Eric Erfanianccca3152017-02-22 16:32:36 -0800113
114/** Version of {@link InCallActivity} that shows the new UI */
115public class InCallActivity extends TransactionSafeFragmentActivity
116 implements AnswerScreenDelegateFactory,
117 InCallScreenDelegateFactory,
118 InCallButtonUiDelegateFactory,
119 VideoCallScreenDelegateFactory,
wangqi219b8702018-02-13 09:34:41 -0800120 RttCallScreenDelegateFactory,
Eric Erfanianccca3152017-02-22 16:32:36 -0800121 PseudoScreenState.StateChangedListener {
122
linyuhc3968e62017-11-20 17:40:50 -0800123 @Retention(RetentionPolicy.SOURCE)
124 @IntDef({
125 DIALPAD_REQUEST_NONE,
126 DIALPAD_REQUEST_SHOW,
127 DIALPAD_REQUEST_HIDE,
128 })
129 @interface DialpadRequestType {}
Eric Erfanian2ca43182017-08-31 06:57:16 -0700130
linyuhc3968e62017-11-20 17:40:50 -0800131 private static final int DIALPAD_REQUEST_NONE = 1;
132 private static final int DIALPAD_REQUEST_SHOW = 2;
133 private static final int DIALPAD_REQUEST_HIDE = 3;
linyuh57b093b2017-11-17 14:32:32 -0800134
linyuhc3968e62017-11-20 17:40:50 -0800135 private static Optional<Integer> audioRouteForTesting = Optional.absent();
linyuh57b093b2017-11-17 14:32:32 -0800136
twyen73a74c32018-03-07 12:12:24 -0800137 private SelectPhoneAccountListener selectPhoneAccountListener;
twyena1723252018-04-24 17:02:57 -0700138 private UiListener<Result> preferredAccountWorkerResultListener;
Eric Erfanianccca3152017-02-22 16:32:36 -0800139
linyuhc3968e62017-11-20 17:40:50 -0800140 private Animation dialpadSlideInAnimation;
141 private Animation dialpadSlideOutAnimation;
142 private Dialog errorDialog;
143 private GradientDrawable backgroundDrawable;
linyuh69a25062017-11-15 16:18:51 -0800144 private InCallOrientationEventListener inCallOrientationEventListener;
linyuhc3968e62017-11-20 17:40:50 -0800145 private View pseudoBlackScreenOverlay;
146 private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment;
147 private String dtmfTextToPrepopulate;
linyuhc3968e62017-11-20 17:40:50 -0800148 private boolean allowOrientationChange;
149 private boolean animateDialpadOnShow;
Eric Erfanianccca3152017-02-22 16:32:36 -0800150 private boolean didShowAnswerScreen;
151 private boolean didShowInCallScreen;
152 private boolean didShowVideoCallScreen;
wangqi219b8702018-02-13 09:34:41 -0800153 private boolean didShowRttCallScreen;
erfaniand05d8992018-03-20 19:42:26 -0700154 private boolean didShowSpeakEasyScreen;
erfanian612d13a2018-04-04 15:27:57 -0700155 private String lastShownSpeakEasyScreenUniqueCallid = "";
linyuh9c327da2017-11-14 12:33:48 -0800156 private boolean dismissKeyguard;
Eric Erfanianccca3152017-02-22 16:32:36 -0800157 private boolean isInShowMainInCallFragment;
linyuhc3968e62017-11-20 17:40:50 -0800158 private boolean isRecreating; // whether the activity is going to be recreated
159 private boolean isVisible;
Eric Erfanianccca3152017-02-22 16:32:36 -0800160 private boolean needDismissPendingDialogs;
linyuhc3968e62017-11-20 17:40:50 -0800161 private boolean touchDownWhenPseudoScreenOff;
162 private int[] backgroundDrawableColors;
163 @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE;
erfaniand05d8992018-03-20 19:42:26 -0700164 private SpeakEasyCallManager speakEasyCallManager;
Eric Erfanianccca3152017-02-22 16:32:36 -0800165
166 public static Intent getIntent(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700167 Context context, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800168 Intent intent = new Intent(Intent.ACTION_MAIN, null);
169 intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
170 intent.setClass(context, InCallActivity.class);
linyuhc3968e62017-11-20 17:40:50 -0800171 if (showDialpad) {
172 intent.putExtra(IntentExtraNames.SHOW_DIALPAD, true);
173 }
174 intent.putExtra(IntentExtraNames.NEW_OUTGOING_CALL, newOutgoingCall);
175 intent.putExtra(IntentExtraNames.FOR_FULL_SCREEN, isForFullScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -0800176 return intent;
177 }
178
179 @Override
180 protected void onResumeFragments() {
181 super.onResumeFragments();
182 if (needDismissPendingDialogs) {
183 dismissPendingDialogs();
184 }
185 }
186
187 @Override
linyuhc3968e62017-11-20 17:40:50 -0800188 protected void onCreate(Bundle bundle) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700189 Trace.beginSection("InCallActivity.onCreate");
linyuhc3968e62017-11-20 17:40:50 -0800190 super.onCreate(bundle);
Eric Erfanianccca3152017-02-22 16:32:36 -0800191
twyena1723252018-04-24 17:02:57 -0700192 preferredAccountWorkerResultListener =
193 DialerExecutorComponent.get(this)
194 .createUiListener(getFragmentManager(), "preferredAccountWorkerResultListener");
195
twyen73a74c32018-03-07 12:12:24 -0800196 selectPhoneAccountListener = new SelectPhoneAccountListener(getApplicationContext());
197
linyuhc3968e62017-11-20 17:40:50 -0800198 if (bundle != null) {
199 didShowAnswerScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN);
200 didShowInCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN);
201 didShowVideoCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN);
wangqi153af2f2018-02-15 16:21:49 -0800202 didShowRttCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -0800203 }
204
linyuhc3968e62017-11-20 17:40:50 -0800205 setWindowFlags();
206 setContentView(R.layout.incall_screen);
207 internalResolveIntent(getIntent());
208
209 boolean isLandscape =
210 getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
211 boolean isRtl = ViewUtil.isRtl();
212 if (isLandscape) {
213 dialpadSlideInAnimation =
214 AnimationUtils.loadAnimation(
215 this, isRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
216 dialpadSlideOutAnimation =
217 AnimationUtils.loadAnimation(
218 this, isRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
219 } else {
220 dialpadSlideInAnimation = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
221 dialpadSlideOutAnimation =
222 AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
223 }
224 dialpadSlideInAnimation.setInterpolator(AnimUtils.EASE_IN);
225 dialpadSlideOutAnimation.setInterpolator(AnimUtils.EASE_OUT);
226 dialpadSlideOutAnimation.setAnimationListener(
227 new AnimationListenerAdapter() {
228 @Override
229 public void onAnimationEnd(Animation animation) {
230 hideDialpadFragment();
231 }
232 });
233
234 if (bundle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) {
235 // If the dialpad was shown before, set related variables so that it can be shown and
236 // populated with the previous DTMF text during onResume().
237 if (bundle.containsKey(IntentExtraNames.SHOW_DIALPAD)) {
238 boolean showDialpad = bundle.getBoolean(IntentExtraNames.SHOW_DIALPAD);
239 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_HIDE;
240 animateDialpadOnShow = false;
241 }
242 dtmfTextToPrepopulate = bundle.getString(KeysForSavedInstance.DIALPAD_TEXT);
243
244 SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment =
245 (SelectPhoneAccountDialogFragment)
246 getFragmentManager().findFragmentByTag(Tags.SELECT_ACCOUNT_FRAGMENT);
247 if (selectPhoneAccountDialogFragment != null) {
248 selectPhoneAccountDialogFragment.setListener(selectPhoneAccountListener);
249 }
250 }
251
linyuh69a25062017-11-15 16:18:51 -0800252 inCallOrientationEventListener = new InCallOrientationEventListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -0800253
254 getWindow()
255 .getDecorView()
256 .setSystemUiVisibility(
257 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
258
259 pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700260 sendBroadcast(CallPendingActivity.getFinishBroadcast());
261 Trace.endSection();
zachh7a96dc72018-02-20 22:16:03 -0800262 MetricsComponent.get(this)
263 .metrics()
264 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_INCOMING);
265 MetricsComponent.get(this)
266 .metrics()
267 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_OUTGOING);
Eric Erfanianccca3152017-02-22 16:32:36 -0800268 }
269
linyuhc3968e62017-11-20 17:40:50 -0800270 private void setWindowFlags() {
271 // Allow the activity to be shown when the screen is locked and filter out touch events that are
272 // "too fat".
273 int flags =
274 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
275 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;
276
linyuhf79d1cb2017-12-15 17:49:56 -0800277 // When the audio stream is not via Bluetooth, turn on the screen once the activity is shown.
278 // When the audio stream is via Bluetooth, turn on the screen only for an incoming call.
linyuhc3968e62017-11-20 17:40:50 -0800279 final int audioRoute = getAudioRoute();
linyuhf79d1cb2017-12-15 17:49:56 -0800280 if (audioRoute != CallAudioState.ROUTE_BLUETOOTH
281 || CallList.getInstance().getIncomingCall() != null) {
linyuhc3968e62017-11-20 17:40:50 -0800282 flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
283 }
284
285 getWindow().addFlags(flags);
286 }
287
288 private static int getAudioRoute() {
289 if (audioRouteForTesting.isPresent()) {
290 return audioRouteForTesting.get();
291 }
292
293 return AudioModeProvider.getInstance().getAudioState().getRoute();
294 }
295
296 @VisibleForTesting(otherwise = VisibleForTesting.NONE)
297 public static void setAudioRouteForTesting(int audioRoute) {
298 audioRouteForTesting = Optional.of(audioRoute);
299 }
300
301 private void internalResolveIntent(Intent intent) {
302 if (!intent.getAction().equals(Intent.ACTION_MAIN)) {
303 return;
304 }
305
306 if (intent.hasExtra(IntentExtraNames.SHOW_DIALPAD)) {
307 // IntentExtraNames.SHOW_DIALPAD can be used to specify whether the DTMF dialpad should be
308 // initially visible. If the extra is absent, leave the dialpad in its previous state.
309 boolean showDialpad = intent.getBooleanExtra(IntentExtraNames.SHOW_DIALPAD, false);
310 relaunchedFromDialer(showDialpad);
311 }
312
313 DialerCall outgoingCall = CallList.getInstance().getOutgoingCall();
314 if (outgoingCall == null) {
315 outgoingCall = CallList.getInstance().getPendingOutgoingCall();
316 }
317 if (intent.getBooleanExtra(IntentExtraNames.NEW_OUTGOING_CALL, false)) {
318 intent.removeExtra(IntentExtraNames.NEW_OUTGOING_CALL);
319
320 // InCallActivity is responsible for disconnecting a new outgoing call if there is no way of
321 // making it (i.e. no valid call capable accounts).
linyuh122fb0b2018-03-26 13:35:32 -0700322 if (InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) {
linyuhc3968e62017-11-20 17:40:50 -0800323 LogUtil.i(
324 "InCallActivity.internalResolveIntent", "Call with no valid accounts, disconnecting");
325 outgoingCall.disconnect();
326 }
327
328 dismissKeyguard(true);
329 }
330
331 if (showPhoneAccountSelectionDialog()) {
332 hideMainInCallFragment();
333 }
334 }
335
336 /**
337 * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should
338 * be shown on launch.
339 *
340 * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code
341 * false} to indicate no change should be made to the dialpad visibility.
342 */
343 private void relaunchedFromDialer(boolean showDialpad) {
344 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE;
345 animateDialpadOnShow = true;
346
347 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
348 // If there's only one line in use, AND it's on hold, then we're sure the user
349 // wants to use the dialpad toward the exact line, so un-hold the holding line.
350 DialerCall call = CallList.getInstance().getActiveOrBackgroundCall();
wangqibb94ca62018-04-27 14:34:04 -0700351 if (call != null && call.getState() == DialerCallState.ONHOLD) {
linyuhc3968e62017-11-20 17:40:50 -0800352 call.unhold();
353 }
354 }
355 }
356
357 /**
358 * Show a phone account selection dialog if there is a call waiting for phone account selection.
359 *
360 * @return true if the dialog was shown.
361 */
362 private boolean showPhoneAccountSelectionDialog() {
363 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
364 if (waitingForAccountCall == null) {
365 return false;
366 }
367
twyena1723252018-04-24 17:02:57 -0700368 ListenableFuture<PreferredAccountWorker.Result> preferredAccountFuture =
369 DialerExecutorComponent.get(this)
370 .backgroundExecutor()
371 .submit(
372 () -> {
373 try {
374 return new PreferredAccountWorker(waitingForAccountCall.getNumber())
375 .doInBackground(getApplicationContext());
376 } catch (Throwable throwable) {
377 throw new Exception(throwable);
378 }
379 });
linyuhc3968e62017-11-20 17:40:50 -0800380
twyena1723252018-04-24 17:02:57 -0700381 preferredAccountWorkerResultListener.listen(
382 this,
383 preferredAccountFuture,
384 result -> {
385 if (result.getPhoneAccountHandle().isPresent()) {
386 Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_PREFERRED_USED);
387 selectPhoneAccountListener.onPhoneAccountSelected(
388 result.getPhoneAccountHandle().get(), false, waitingForAccountCall.getId());
389 return;
390 }
391 if (result.getSuggestion().isPresent()) {
392 LogUtil.i(
393 "CallingAccountSelector.processPreferredAccount",
394 "SIM suggested: " + result.getSuggestion().get().reason);
395 if (result.getSuggestion().get().shouldAutoSelect) {
396 Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_SUGGESTION_AUTO_SELECTED);
397 LogUtil.i(
398 "CallingAccountSelector.processPreferredAccount", "Auto selected suggestion");
399 selectPhoneAccountListener.onPhoneAccountSelected(
400 result.getSuggestion().get().phoneAccountHandle,
401 false,
402 waitingForAccountCall.getId());
403 return;
404 }
405 }
406 Bundle extras = waitingForAccountCall.getIntentExtras();
407 List<PhoneAccountHandle> phoneAccountHandles =
408 extras == null
409 ? new ArrayList<>()
410 : extras.getParcelableArrayList(Call.AVAILABLE_PHONE_ACCOUNTS);
twyen66adad02018-04-24 13:51:08 -0700411
twyena1723252018-04-24 17:02:57 -0700412 waitingForAccountCall.setPreferredAccountRecorder(
413 new PreferredAccountRecorder(
414 waitingForAccountCall.getNumber(),
415 result.getSuggestion().orNull(),
416 result.getDataId().orNull()));
417 SelectPhoneAccountDialogOptions.Builder optionsBuilder =
418 SelectPhoneAccountDialogOptions.newBuilder()
419 .setTitle(R.string.select_phone_account_for_calls)
420 .setCanSetDefault(result.getDataId().isPresent())
421 .setSetDefaultLabel(R.string.select_phone_account_for_calls_remember)
422 .setCallId(waitingForAccountCall.getId());
twyen66adad02018-04-24 13:51:08 -0700423
twyena1723252018-04-24 17:02:57 -0700424 for (PhoneAccountHandle phoneAccountHandle : phoneAccountHandles) {
425 SelectPhoneAccountDialogOptions.Entry.Builder entryBuilder =
426 SelectPhoneAccountDialogOptions.Entry.newBuilder();
427 SelectPhoneAccountDialogOptionsUtil.setPhoneAccountHandle(
428 entryBuilder, phoneAccountHandle);
429 Optional<String> hint =
430 SuggestionProvider.getHint(
431 this, phoneAccountHandle, result.getSuggestion().orNull());
432 if (hint.isPresent()) {
433 entryBuilder.setHint(hint.get());
434 }
435 optionsBuilder.addEntries(entryBuilder);
436 }
437
438 selectPhoneAccountDialogFragment =
439 SelectPhoneAccountDialogFragment.newInstance(
440 optionsBuilder.build(), selectPhoneAccountListener);
441 selectPhoneAccountDialogFragment.show(getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT);
442 },
443 throwable -> {
444 throw new RuntimeException(throwable);
445 });
twyen73a74c32018-03-07 12:12:24 -0800446
linyuhc3968e62017-11-20 17:40:50 -0800447 return true;
448 }
449
Eric Erfanianccca3152017-02-22 16:32:36 -0800450 @Override
451 protected void onSaveInstanceState(Bundle out) {
linyuh57b093b2017-11-17 14:32:32 -0800452 LogUtil.enterBlock("InCallActivity.onSaveInstanceState");
453
454 // TODO: DialpadFragment should handle this as part of its own state
linyuhc3968e62017-11-20 17:40:50 -0800455 out.putBoolean(IntentExtraNames.SHOW_DIALPAD, isDialpadVisible());
linyuh57b093b2017-11-17 14:32:32 -0800456 DialpadFragment dialpadFragment = getDialpadFragment();
457 if (dialpadFragment != null) {
linyuhc3968e62017-11-20 17:40:50 -0800458 out.putString(KeysForSavedInstance.DIALPAD_TEXT, dialpadFragment.getDtmfText());
linyuh57b093b2017-11-17 14:32:32 -0800459 }
460
linyuhc3968e62017-11-20 17:40:50 -0800461 out.putBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN, didShowAnswerScreen);
462 out.putBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN, didShowInCallScreen);
463 out.putBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN, didShowVideoCallScreen);
wangqi153af2f2018-02-15 16:21:49 -0800464 out.putBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN, didShowRttCallScreen);
erfaniand05d8992018-03-20 19:42:26 -0700465 out.putBoolean(KeysForSavedInstance.DID_SHOW_SPEAK_EASY_SCREEN, didShowSpeakEasyScreen);
linyuh57b093b2017-11-17 14:32:32 -0800466
Eric Erfanianccca3152017-02-22 16:32:36 -0800467 super.onSaveInstanceState(out);
468 isVisible = false;
469 }
470
471 @Override
472 protected void onStart() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700473 Trace.beginSection("InCallActivity.onStart");
Eric Erfanianccca3152017-02-22 16:32:36 -0800474 super.onStart();
linyuh57b093b2017-11-17 14:32:32 -0800475
Eric Erfanianccca3152017-02-22 16:32:36 -0800476 isVisible = true;
477 showMainInCallFragment();
linyuh57b093b2017-11-17 14:32:32 -0800478
479 InCallPresenter.getInstance().setActivity(this);
480 enableInCallOrientationEventListener(
481 getRequestedOrientation()
482 == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
483 InCallPresenter.getInstance().onActivityStarted();
484
yueg10f6e822018-01-17 15:32:18 -0800485 if (!isRecreating) {
486 InCallPresenter.getInstance().onUiShowing(true);
487 }
488
linyuh437ae952018-03-26 12:46:18 -0700489 if (isInMultiWindowMode() && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800490 // Hide the dialpad because there may not be enough room
491 showDialpadFragment(false, false);
492 }
linyuh57b093b2017-11-17 14:32:32 -0800493
Eric Erfanian2ca43182017-08-31 06:57:16 -0700494 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800495 }
496
497 @Override
498 protected void onResume() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700499 Trace.beginSection("InCallActivity.onResume");
Eric Erfanianccca3152017-02-22 16:32:36 -0800500 super.onResume();
linyuhc3968e62017-11-20 17:40:50 -0800501
502 if (!InCallPresenter.getInstance().isReadyForTearDown()) {
503 updateTaskDescription();
linyuhc3968e62017-11-20 17:40:50 -0800504 }
505
506 // If there is a pending request to show or hide the dialpad, handle that now.
507 if (showDialpadRequest != DIALPAD_REQUEST_NONE) {
508 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
509 // Exit fullscreen so that the user has access to the dialpad hide/show button.
510 // This is important when showing the dialpad from within dialer.
511 InCallPresenter.getInstance().setFullScreen(false /* isFullScreen */, true /* force */);
512
513 showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */);
514 animateDialpadOnShow = false;
515
516 DialpadFragment dialpadFragment = getDialpadFragment();
517 if (dialpadFragment != null) {
518 dialpadFragment.setDtmfText(dtmfTextToPrepopulate);
519 dtmfTextToPrepopulate = null;
520 }
521 } else {
522 LogUtil.i("InCallActivity.onResume", "Force-hide the dialpad");
523 if (getDialpadFragment() != null) {
524 showDialpadFragment(false /* show */, false /* animate */);
525 }
526 }
527 showDialpadRequest = DIALPAD_REQUEST_NONE;
528 }
529 updateNavigationBar(isDialpadVisible());
530
linyuhc3968e62017-11-20 17:40:50 -0800531 CallList.getInstance()
532 .onInCallUiShown(getIntent().getBooleanExtra(IntentExtraNames.FOR_FULL_SCREEN, false));
533
Eric Erfanianccca3152017-02-22 16:32:36 -0800534 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
535 pseudoScreenState.addListener(this);
536 onPseudoScreenStateChanged(pseudoScreenState.isOn());
Eric Erfanian2ca43182017-08-31 06:57:16 -0700537 Trace.endSection();
weijiaxu650e7cc2017-10-31 12:38:54 -0700538 // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume.
539 ThreadUtil.postDelayedOnUiThread(
weijiaxuc950a9b2017-11-06 16:39:04 -0800540 () ->
zachh7a96dc72018-02-20 22:16:03 -0800541 MetricsComponent.get(this)
542 .metrics()
543 .recordMemory(Metrics.INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME),
weijiaxu650e7cc2017-10-31 12:38:54 -0700544 1000);
Eric Erfanianccca3152017-02-22 16:32:36 -0800545 }
546
Eric Erfanianccca3152017-02-22 16:32:36 -0800547 @Override
548 protected void onPause() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700549 Trace.beginSection("InCallActivity.onPause");
Eric Erfanianccca3152017-02-22 16:32:36 -0800550 super.onPause();
linyuh57b093b2017-11-17 14:32:32 -0800551
552 DialpadFragment dialpadFragment = getDialpadFragment();
553 if (dialpadFragment != null) {
554 dialpadFragment.onDialerKeyUp(null);
555 }
556
Eric Erfanianccca3152017-02-22 16:32:36 -0800557 InCallPresenter.getInstance().getPseudoScreenState().removeListener(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700558 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800559 }
560
561 @Override
562 protected void onStop() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700563 Trace.beginSection("InCallActivity.onStop");
wangqi4d705e52017-09-28 12:23:35 -0700564 isVisible = false;
Eric Erfanianccca3152017-02-22 16:32:36 -0800565 super.onStop();
linyuh57b093b2017-11-17 14:32:32 -0800566
567 // Disconnects the call waiting for a phone account when the activity is hidden (e.g., after the
568 // user presses the home button).
569 // Without this the pending call will get stuck on phone account selection and new calls can't
570 // be created.
571 // Skip this when the screen is locked since the activity may complete its current life cycle
572 // and restart.
linyuhc3968e62017-11-20 17:40:50 -0800573 if (!isRecreating && !getSystemService(KeyguardManager.class).isKeyguardLocked()) {
linyuh57b093b2017-11-17 14:32:32 -0800574 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
575 if (waitingForAccountCall != null) {
576 waitingForAccountCall.disconnect();
577 }
578 }
579
580 enableInCallOrientationEventListener(false);
581 InCallPresenter.getInstance().updateIsChangingConfigurations();
582 InCallPresenter.getInstance().onActivityStopped();
linyuhc3968e62017-11-20 17:40:50 -0800583 if (!isRecreating) {
yueg10f6e822018-01-17 15:32:18 -0800584 InCallPresenter.getInstance().onUiShowing(false);
wangqie6060522018-04-05 11:47:15 -0700585 }
586 if (errorDialog != null) {
587 errorDialog.dismiss();
linyuh57b093b2017-11-17 14:32:32 -0800588 }
589
yueg10f6e822018-01-17 15:32:18 -0800590 if (isFinishing()) {
591 InCallPresenter.getInstance().unsetActivity(this);
592 }
593
Eric Erfanian2ca43182017-08-31 06:57:16 -0700594 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800595 }
596
597 @Override
598 protected void onDestroy() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700599 Trace.beginSection("InCallActivity.onDestroy");
Eric Erfanianccca3152017-02-22 16:32:36 -0800600 super.onDestroy();
linyuh57b093b2017-11-17 14:32:32 -0800601
602 InCallPresenter.getInstance().unsetActivity(this);
603 InCallPresenter.getInstance().updateIsChangingConfigurations();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700604 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800605 }
606
607 @Override
608 public void finish() {
609 if (shouldCloseActivityOnFinish()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700610 // When user select incall ui from recents after the call is disconnected, it tries to launch
611 // a new InCallActivity but InCallPresenter is already teared down at this point, which causes
612 // crash.
613 // By calling finishAndRemoveTask() instead of finish() the task associated with
614 // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in
615 // this case.
616 //
617 // Calling finish won't clear the task and normally when an activity finishes it shouldn't
618 // clear the task since there could be parent activity in the same task that's still alive.
619 // But InCallActivity is special since it's singleInstance which means it's root activity and
620 // only instance of activity in the task. So it should be safe to also remove task when
621 // finishing.
622 // It's also necessary in the sense of it's excluded from recents. So whenever the activity
623 // finishes, the task should also be removed since it doesn't make sense to go back to it in
624 // anyway anymore.
625 super.finishAndRemoveTask();
Eric Erfanianccca3152017-02-22 16:32:36 -0800626 }
627 }
628
629 private boolean shouldCloseActivityOnFinish() {
linyuhc3968e62017-11-20 17:40:50 -0800630 if (!isVisible) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800631 LogUtil.i(
632 "InCallActivity.shouldCloseActivityOnFinish",
633 "allowing activity to be closed because it's not visible");
634 return true;
635 }
636
twyen8efb4952017-10-06 16:35:54 -0700637 if (InCallPresenter.getInstance().isInCallUiLocked()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800638 LogUtil.i(
639 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700640 "in call ui is locked, not closing activity");
Eric Erfanianccca3152017-02-22 16:32:36 -0800641 return false;
642 }
643
644 LogUtil.i(
645 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700646 "activity is visible and has no locks, allowing activity to close");
Eric Erfanianccca3152017-02-22 16:32:36 -0800647 return true;
648 }
649
650 @Override
651 protected void onNewIntent(Intent intent) {
linyuhc3968e62017-11-20 17:40:50 -0800652 LogUtil.enterBlock("InCallActivity.onNewIntent");
Eric Erfanianccca3152017-02-22 16:32:36 -0800653
654 // If the screen is off, we need to make sure it gets turned on for incoming calls.
655 // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works
656 // when the activity is first created. Therefore, to ensure the screen is turned on
657 // for the call waiting case, we recreate() the current activity. There should be no jank from
658 // this since the screen is already off and will remain so until our new activity is up.
linyuhc3968e62017-11-20 17:40:50 -0800659 if (!isVisible) {
660 onNewIntent(intent, true /* isRecreating */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800661 LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on.");
662 recreate();
Eric Erfanian10b34a52017-05-04 08:23:17 -0700663 } else {
linyuhc3968e62017-11-20 17:40:50 -0800664 onNewIntent(intent, false /* isRecreating */);
665 }
666 }
667
yuega3305352018-01-09 11:02:47 -0800668 @VisibleForTesting
669 void onNewIntent(Intent intent, boolean isRecreating) {
linyuhc3968e62017-11-20 17:40:50 -0800670 this.isRecreating = isRecreating;
671
672 // We're being re-launched with a new Intent. Since it's possible for a single InCallActivity
673 // instance to persist indefinitely (even if we finish() ourselves), this sequence can
674 // happen any time the InCallActivity needs to be displayed.
675
676 // Stash away the new intent so that we can get it in the future by calling getIntent().
677 // Otherwise getIntent() will return the original Intent from when we first got created.
678 setIntent(intent);
679
680 // Activities are always paused before receiving a new intent, so we can count on our onResume()
681 // method being called next.
682
683 // Just like in onCreate(), handle the intent.
684 // Skip if InCallActivity is going to be recreated since this will be called in onCreate().
685 if (!isRecreating) {
686 internalResolveIntent(intent);
Eric Erfanianccca3152017-02-22 16:32:36 -0800687 }
688 }
689
690 @Override
691 public void onBackPressed() {
linyuh57b093b2017-11-17 14:32:32 -0800692 LogUtil.enterBlock("InCallActivity.onBackPressed");
693
linyuhc3968e62017-11-20 17:40:50 -0800694 if (!isVisible) {
linyuh57b093b2017-11-17 14:32:32 -0800695 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800696 }
linyuh57b093b2017-11-17 14:32:32 -0800697
698 if (!getCallCardFragmentVisible()) {
699 return;
700 }
701
702 DialpadFragment dialpadFragment = getDialpadFragment();
703 if (dialpadFragment != null && dialpadFragment.isVisible()) {
704 showDialpadFragment(false /* show */, true /* animate */);
705 return;
706 }
707
708 if (CallList.getInstance().getIncomingCall() != null) {
709 LogUtil.i(
710 "InCallActivity.onBackPressed",
711 "Ignore the press of the back key when an incoming call is ringing");
712 return;
713 }
714
715 // Nothing special to do. Fall back to the default behavior.
716 super.onBackPressed();
Eric Erfanianccca3152017-02-22 16:32:36 -0800717 }
718
719 @Override
720 public boolean onOptionsItemSelected(MenuItem item) {
721 LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item);
722 if (item.getItemId() == android.R.id.home) {
723 onBackPressed();
724 return true;
725 }
726 return super.onOptionsItemSelected(item);
727 }
728
729 @Override
730 public boolean onKeyUp(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800731 DialpadFragment dialpadFragment = getDialpadFragment();
732 if (dialpadFragment != null
733 && dialpadFragment.isVisible()
734 && dialpadFragment.onDialerKeyUp(event)) {
735 return true;
736 }
737
738 if (keyCode == KeyEvent.KEYCODE_CALL) {
739 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
740 return true;
741 }
742
743 return super.onKeyUp(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800744 }
745
746 @Override
747 public boolean onKeyDown(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800748 switch (keyCode) {
749 case KeyEvent.KEYCODE_CALL:
750 if (!InCallPresenter.getInstance().handleCallKey()) {
751 LogUtil.e(
752 "InCallActivity.onKeyDown",
753 "InCallPresenter should always handle KEYCODE_CALL in onKeyDown");
754 }
755 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
756 return true;
757
758 // Note that KEYCODE_ENDCALL isn't handled here as the standard system-wide handling of it
759 // is exactly what's needed, namely
760 // (1) "hang up" if there's an active call, or
761 // (2) "don't answer" if there's an incoming call.
762 // (See PhoneWindowManager for implementation details.)
763
764 case KeyEvent.KEYCODE_CAMERA:
765 // Consume KEYCODE_CAMERA since it's easy to accidentally press the camera button.
766 return true;
767
768 case KeyEvent.KEYCODE_VOLUME_UP:
769 case KeyEvent.KEYCODE_VOLUME_DOWN:
770 case KeyEvent.KEYCODE_VOLUME_MUTE:
771 // Ringer silencing handled by PhoneWindowManager.
772 break;
773
774 case KeyEvent.KEYCODE_MUTE:
775 TelecomAdapter.getInstance()
776 .mute(!AudioModeProvider.getInstance().getAudioState().isMuted());
777 return true;
778
779 case KeyEvent.KEYCODE_SLASH:
780 // When verbose logging is enabled, dump the view for debugging/testing purposes.
781 if (LogUtil.isVerboseEnabled()) {
782 View decorView = getWindow().getDecorView();
783 LogUtil.v("InCallActivity.onKeyDown", "View dump:\n%s", decorView);
784 return true;
785 }
786 break;
787
788 case KeyEvent.KEYCODE_EQUALS:
789 break;
790
791 default: // fall out
792 }
793
794 // Pass other key events to DialpadFragment's "onDialerKeyDown" method in case the user types
795 // in DTMF (Dual-tone multi-frequency signaling) code.
796 DialpadFragment dialpadFragment = getDialpadFragment();
797 if (dialpadFragment != null
798 && dialpadFragment.isVisible()
799 && dialpadFragment.onDialerKeyDown(event)) {
800 return true;
801 }
802
803 return super.onKeyDown(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800804 }
805
806 public boolean isInCallScreenAnimating() {
807 return false;
808 }
809
810 public void showConferenceFragment(boolean show) {
811 if (show) {
812 startActivity(new Intent(this, ManageConferenceActivity.class));
813 }
814 }
815
linyuhc3968e62017-11-20 17:40:50 -0800816 public void showDialpadFragment(boolean show, boolean animate) {
817 if (show == isDialpadVisible()) {
818 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800819 }
linyuhc3968e62017-11-20 17:40:50 -0800820
821 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
822 if (dialpadFragmentManager == null) {
823 LogUtil.i("InCallActivity.showDialpadFragment", "Unable to obtain a FragmentManager");
824 return;
825 }
826
827 if (!animate) {
828 if (show) {
829 showDialpadFragment();
830 } else {
831 hideDialpadFragment();
832 }
833 } else {
834 if (show) {
835 showDialpadFragment();
836 getDialpadFragment().animateShowDialpad();
837 }
838 getDialpadFragment()
839 .getView()
840 .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation);
841 }
842
843 ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor();
844 if (sensor != null) {
845 sensor.onDialpadVisible(show);
846 }
847 showDialpadRequest = DIALPAD_REQUEST_NONE;
848
849 // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB
850 // repositions itself.
wangqifd4c9f72018-03-08 18:21:50 -0800851 getInCallOrRttCallScreen().onInCallScreenDialpadVisibilityChange(show);
linyuhc3968e62017-11-20 17:40:50 -0800852 }
853
854 private void showDialpadFragment() {
855 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
856 if (dialpadFragmentManager == null) {
857 return;
858 }
859
860 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
861 DialpadFragment dialpadFragment = getDialpadFragment();
862 if (dialpadFragment == null) {
wangqifd4c9f72018-03-08 18:21:50 -0800863 dialpadFragment = new DialpadFragment();
864 transaction.add(getDialpadContainerId(), dialpadFragment, Tags.DIALPAD_FRAGMENT);
linyuhc3968e62017-11-20 17:40:50 -0800865 } else {
866 transaction.show(dialpadFragment);
calderwoodrad5883872017-12-12 15:29:12 -0800867 dialpadFragment.setUserVisibleHint(true);
linyuhc3968e62017-11-20 17:40:50 -0800868 }
wangqifd4c9f72018-03-08 18:21:50 -0800869 // RTT call screen doesn't show end call button inside dialpad, thus the space reserved for end
870 // call button should be removed.
871 dialpadFragment.setShouldShowEndCallSpace(didShowInCallScreen);
linyuhc3968e62017-11-20 17:40:50 -0800872 transaction.commitAllowingStateLoss();
873 dialpadFragmentManager.executePendingTransactions();
874
875 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, this);
876 updateNavigationBar(true /* isDialpadVisible */);
877 }
878
879 private void hideDialpadFragment() {
880 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
881 if (dialpadFragmentManager == null) {
882 return;
883 }
884
calderwoodrad5883872017-12-12 15:29:12 -0800885 DialpadFragment dialpadFragment = getDialpadFragment();
linyuhc3968e62017-11-20 17:40:50 -0800886 if (dialpadFragment != null) {
887 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
888 transaction.hide(dialpadFragment);
889 transaction.commitAllowingStateLoss();
890 dialpadFragmentManager.executePendingTransactions();
calderwoodrad5883872017-12-12 15:29:12 -0800891 dialpadFragment.setUserVisibleHint(false);
linyuhc3968e62017-11-20 17:40:50 -0800892 }
893 updateNavigationBar(false /* isDialpadVisible */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800894 }
895
896 public boolean isDialpadVisible() {
linyuh69a25062017-11-15 16:18:51 -0800897 DialpadFragment dialpadFragment = getDialpadFragment();
calderwoodraa584bcd2018-01-24 12:19:56 -0800898 return dialpadFragment != null
899 && dialpadFragment.isAdded()
900 && !dialpadFragment.isHidden()
901 && dialpadFragment.getView() != null
902 && dialpadFragment.getUserVisibleHint();
linyuh69a25062017-11-15 16:18:51 -0800903 }
904
linyuhc3968e62017-11-20 17:40:50 -0800905 /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */
linyuh69a25062017-11-15 16:18:51 -0800906 @Nullable
linyuhc3968e62017-11-20 17:40:50 -0800907 private DialpadFragment getDialpadFragment() {
linyuh69a25062017-11-15 16:18:51 -0800908 FragmentManager fragmentManager = getDialpadFragmentManager();
909 if (fragmentManager == null) {
910 return null;
911 }
linyuhc3968e62017-11-20 17:40:50 -0800912 return (DialpadFragment) fragmentManager.findFragmentByTag(Tags.DIALPAD_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -0800913 }
914
915 public void onForegroundCallChanged(DialerCall newForegroundCall) {
linyuh57b093b2017-11-17 14:32:32 -0800916 updateTaskDescription();
917
918 if (newForegroundCall == null || !didShowAnswerScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800919 LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color");
linyuh57b093b2017-11-17 14:32:32 -0800920 updateWindowBackgroundColor(0 /* progress */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800921 }
922 }
923
linyuhc3968e62017-11-20 17:40:50 -0800924 private void updateTaskDescription() {
linyuh57b093b2017-11-17 14:32:32 -0800925 int color =
926 getResources().getBoolean(R.bool.is_layout_landscape)
927 ? ResourcesCompat.getColor(
928 getResources(), R.color.statusbar_background_color, getTheme())
929 : InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor();
930 setTaskDescription(
931 new TaskDescription(
932 getResources().getString(R.string.notification_ongoing_call), null /* icon */, color));
933 }
934
Eric Erfanianccca3152017-02-22 16:32:36 -0800935 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
936 ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager();
937 @ColorInt int top;
938 @ColorInt int middle;
939 @ColorInt int bottom;
940 @ColorInt int gray = 0x66000000;
941
linyuh437ae952018-03-26 12:46:18 -0700942 if (isInMultiWindowMode()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800943 top = themeColorManager.getBackgroundColorSolid();
944 middle = themeColorManager.getBackgroundColorSolid();
945 bottom = themeColorManager.getBackgroundColorSolid();
946 } else {
947 top = themeColorManager.getBackgroundColorTop();
948 middle = themeColorManager.getBackgroundColorMiddle();
949 bottom = themeColorManager.getBackgroundColorBottom();
950 }
951
952 if (progress < 0) {
953 float correctedProgress = Math.abs(progress);
954 top = ColorUtils.blendARGB(top, gray, correctedProgress);
955 middle = ColorUtils.blendARGB(middle, gray, correctedProgress);
956 bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress);
957 }
958
959 boolean backgroundDirty = false;
960 if (backgroundDrawable == null) {
961 backgroundDrawableColors = new int[] {top, middle, bottom};
962 backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors);
963 backgroundDirty = true;
964 } else {
965 if (backgroundDrawableColors[0] != top) {
966 backgroundDrawableColors[0] = top;
967 backgroundDirty = true;
968 }
969 if (backgroundDrawableColors[1] != middle) {
970 backgroundDrawableColors[1] = middle;
971 backgroundDirty = true;
972 }
973 if (backgroundDrawableColors[2] != bottom) {
974 backgroundDrawableColors[2] = bottom;
975 backgroundDirty = true;
976 }
977 if (backgroundDirty) {
978 backgroundDrawable.setColors(backgroundDrawableColors);
979 }
980 }
981
982 if (backgroundDirty) {
983 getWindow().setBackgroundDrawable(backgroundDrawable);
984 }
985 }
986
987 public boolean isVisible() {
988 return isVisible;
989 }
990
991 public boolean getCallCardFragmentVisible() {
erfaniand05d8992018-03-20 19:42:26 -0700992 return didShowInCallScreen
993 || didShowVideoCallScreen
994 || didShowRttCallScreen
995 || didShowSpeakEasyScreen;
Eric Erfanianccca3152017-02-22 16:32:36 -0800996 }
997
998 public void dismissKeyguard(boolean dismiss) {
linyuh9c327da2017-11-14 12:33:48 -0800999 if (dismissKeyguard == dismiss) {
1000 return;
1001 }
1002
1003 dismissKeyguard = dismiss;
1004 if (dismiss) {
1005 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
1006 } else {
1007 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
1008 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001009 }
1010
linyuhc3968e62017-11-20 17:40:50 -08001011 public void showDialogForPostCharWait(String callId, String chars) {
yuega489f512018-04-25 12:01:09 -07001012 PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars);
1013 fragment.show(getSupportFragmentManager(), Tags.POST_CHAR_DIALOG_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -08001014 }
1015
linyuh7b86f562017-11-16 11:24:09 -08001016 public void showDialogOrToastForDisconnectedCall(DisconnectMessage disconnectMessage) {
1017 LogUtil.i(
1018 "InCallActivity.showDialogOrToastForDisconnectedCall",
1019 "disconnect cause: %s",
1020 disconnectMessage);
1021
1022 if (disconnectMessage.dialog == null || isFinishing()) {
1023 return;
1024 }
1025
1026 dismissPendingDialogs();
1027
1028 // Show a toast if the app is in background when a dialog can't be visible.
1029 if (!isVisible()) {
1030 Toast.makeText(getApplicationContext(), disconnectMessage.toastMessage, Toast.LENGTH_LONG)
1031 .show();
1032 return;
1033 }
1034
1035 // Show the dialog.
linyuhc3968e62017-11-20 17:40:50 -08001036 errorDialog = disconnectMessage.dialog;
linyuh7b86f562017-11-16 11:24:09 -08001037 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog");
1038 disconnectMessage.dialog.setOnDismissListener(
1039 dialogInterface -> {
1040 lock.release();
1041 onDialogDismissed();
1042 });
1043 disconnectMessage.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
1044 disconnectMessage.dialog.show();
1045 }
1046
1047 private void onDialogDismissed() {
linyuhc3968e62017-11-20 17:40:50 -08001048 errorDialog = null;
linyuh7b86f562017-11-16 11:24:09 -08001049 CallList.getInstance().onErrorDialogDismissed();
Eric Erfanianccca3152017-02-22 16:32:36 -08001050 }
1051
1052 public void dismissPendingDialogs() {
linyuhc3968e62017-11-20 17:40:50 -08001053 LogUtil.enterBlock("InCallActivity.dismissPendingDialogs");
linyuhf99f6302017-11-15 11:23:51 -08001054
1055 if (!isVisible) {
1056 // Defer the dismissing action as the activity is not visible and onSaveInstanceState may have
1057 // been called.
Eric Erfanianccca3152017-02-22 16:32:36 -08001058 LogUtil.i(
1059 "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible");
1060 needDismissPendingDialogs = true;
linyuhf99f6302017-11-15 11:23:51 -08001061 return;
Eric Erfanianccca3152017-02-22 16:32:36 -08001062 }
linyuhf99f6302017-11-15 11:23:51 -08001063
1064 // Dismiss the error dialog
linyuhf99f6302017-11-15 11:23:51 -08001065 if (errorDialog != null) {
1066 errorDialog.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001067 errorDialog = null;
linyuhf99f6302017-11-15 11:23:51 -08001068 }
1069
1070 // Dismiss the phone account selection dialog
linyuhf99f6302017-11-15 11:23:51 -08001071 if (selectPhoneAccountDialogFragment != null) {
1072 selectPhoneAccountDialogFragment.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001073 selectPhoneAccountDialogFragment = null;
linyuhf99f6302017-11-15 11:23:51 -08001074 }
1075
1076 // Dismiss the dialog for international call on WiFi
1077 InternationalCallOnWifiDialogFragment internationalCallOnWifiFragment =
1078 (InternationalCallOnWifiDialogFragment)
linyuhc3968e62017-11-20 17:40:50 -08001079 getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
linyuhf99f6302017-11-15 11:23:51 -08001080 if (internationalCallOnWifiFragment != null) {
1081 internationalCallOnWifiFragment.dismiss();
1082 }
1083
1084 // Dismiss the answer screen
1085 AnswerScreen answerScreen = getAnswerScreen();
1086 if (answerScreen != null) {
1087 answerScreen.dismissPendingDialogs();
1088 }
1089
1090 needDismissPendingDialogs = false;
Eric Erfanianccca3152017-02-22 16:32:36 -08001091 }
1092
linyuhc3968e62017-11-20 17:40:50 -08001093 private void enableInCallOrientationEventListener(boolean enable) {
linyuh69a25062017-11-15 16:18:51 -08001094 if (enable) {
1095 inCallOrientationEventListener.enable(true /* notifyDeviceOrientationChange */);
1096 } else {
1097 inCallOrientationEventListener.disable();
1098 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001099 }
1100
1101 public void setExcludeFromRecents(boolean exclude) {
linyuhc3968e62017-11-20 17:40:50 -08001102 int taskId = getTaskId();
1103
1104 List<AppTask> tasks = getSystemService(ActivityManager.class).getAppTasks();
1105 for (AppTask task : tasks) {
1106 try {
1107 if (task.getTaskInfo().id == taskId) {
1108 task.setExcludeFromRecents(exclude);
1109 }
1110 } catch (RuntimeException e) {
1111 LogUtil.e("InCallActivity.setExcludeFromRecents", "RuntimeException:\n%s", e);
1112 }
1113 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001114 }
1115
Eric Erfanianccca3152017-02-22 16:32:36 -08001116 @Nullable
1117 public FragmentManager getDialpadFragmentManager() {
wangqifd4c9f72018-03-08 18:21:50 -08001118 InCallScreen inCallScreen = getInCallOrRttCallScreen();
Eric Erfanianccca3152017-02-22 16:32:36 -08001119 if (inCallScreen != null) {
1120 return inCallScreen.getInCallScreenFragment().getChildFragmentManager();
1121 }
1122 return null;
1123 }
1124
1125 public int getDialpadContainerId() {
wangqifd4c9f72018-03-08 18:21:50 -08001126 return getInCallOrRttCallScreen().getAnswerAndDialpadContainerResourceId();
Eric Erfanianccca3152017-02-22 16:32:36 -08001127 }
1128
1129 @Override
1130 public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) {
1131 DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId());
1132 if (call == null) {
1133 // This is a work around for a bug where we attempt to create a new delegate after the call
1134 // has already been removed. An example of when this can happen is:
1135 // 1. incoming video call in landscape mode
1136 // 2. remote party hangs up
1137 // 3. activity switches from landscape to portrait
1138 // At step #3 the answer fragment will try to create a new answer delegate but the call won't
1139 // exist. In this case we'll simply return a stub delegate that does nothing. This is ok
1140 // because this new state is transient and the activity will be destroyed soon.
1141 LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub");
1142 return new AnswerScreenPresenterStub();
1143 } else {
1144 return new AnswerScreenPresenter(
1145 this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId()));
1146 }
1147 }
1148
1149 @Override
1150 public InCallScreenDelegate newInCallScreenDelegate() {
1151 return new CallCardPresenter(this);
1152 }
1153
1154 @Override
1155 public InCallButtonUiDelegate newInCallButtonUiDelegate() {
1156 return new CallButtonPresenter(this);
1157 }
1158
1159 @Override
Eric Erfanian90508232017-03-24 09:31:16 -07001160 public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) {
1161 DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId());
1162 if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) {
1163 return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen);
1164 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001165 return new VideoCallPresenter();
1166 }
1167
1168 public void onPrimaryCallStateChanged() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001169 Trace.beginSection("InCallActivity.onPrimaryCallStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -08001170 showMainInCallFragment();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001171 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001172 }
1173
linyuh7b86f562017-11-16 11:24:09 -08001174 public void showDialogOrToastForWifiHandoverFailure(DialerCall call) {
1175 if (call.showWifiHandoverAlertAsToast()) {
1176 Toast.makeText(this, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT)
1177 .show();
1178 return;
1179 }
1180
1181 dismissPendingDialogs();
1182
1183 AlertDialog.Builder builder =
1184 new AlertDialog.Builder(this).setTitle(R.string.video_call_lte_to_wifi_failed_title);
1185
1186 // This allows us to use the theme of the dialog instead of the activity
1187 View dialogCheckBoxView =
1188 View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null /* root */);
1189 CheckBox wifiHandoverFailureCheckbox =
1190 (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox);
1191 wifiHandoverFailureCheckbox.setChecked(false);
1192
1193 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog");
linyuhc3968e62017-11-20 17:40:50 -08001194 errorDialog =
linyuh7b86f562017-11-16 11:24:09 -08001195 builder
1196 .setView(dialogCheckBoxView)
1197 .setMessage(R.string.video_call_lte_to_wifi_failed_message)
1198 .setOnCancelListener(dialogInterface -> onDialogDismissed())
1199 .setPositiveButton(
1200 android.R.string.ok,
1201 (dialogInterface, id) -> {
1202 call.setDoNotShowDialogForHandoffToWifiFailure(
1203 wifiHandoverFailureCheckbox.isChecked());
1204 dialogInterface.cancel();
1205 onDialogDismissed();
1206 })
1207 .setOnDismissListener(dialogInterface -> lock.release())
1208 .create();
linyuh7b86f562017-11-16 11:24:09 -08001209 errorDialog.show();
Eric Erfanianccca3152017-02-22 16:32:36 -08001210 }
1211
linyuh7b86f562017-11-16 11:24:09 -08001212 public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) {
linyuh7b86f562017-11-16 11:24:09 -08001213 InternationalCallOnWifiDialogFragment fragment =
yuegb47528e2018-04-24 12:12:57 -07001214 InternationalCallOnWifiDialogFragment.newInstance(call.getId());
linyuhc3968e62017-11-20 17:40:50 -08001215 fragment.show(getSupportFragmentManager(), Tags.INTERNATIONAL_CALL_ON_WIFI);
Eric Erfanianc857f902017-05-15 14:05:33 -07001216 }
1217
wangqibc28ea72018-04-02 16:23:00 -07001218 public void showDialogForRttRequest(DialerCall call, int rttRequestId) {
1219 LogUtil.enterBlock("InCallActivity.showDialogForRttRequest");
1220 DialogFragment fragment = RttRequestDialogFragment.newInstance(call.getId(), rttRequestId);
1221 fragment.show(getSupportFragmentManager(), Tags.RTT_REQUEST_DIALOG);
1222 }
1223
Eric Erfanian938468d2017-10-24 14:05:52 -07001224 @Override
1225 public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
1226 super.onMultiWindowModeChanged(isInMultiWindowMode);
linyuh57b093b2017-11-17 14:32:32 -08001227 updateNavigationBar(isDialpadVisible());
1228 }
1229
linyuhc3968e62017-11-20 17:40:50 -08001230 private void updateNavigationBar(boolean isDialpadVisible) {
linyuh437ae952018-03-26 12:46:18 -07001231 if (isInMultiWindowMode()) {
linyuh57b093b2017-11-17 14:32:32 -08001232 return;
1233 }
1234
1235 View navigationBarBackground = getWindow().findViewById(R.id.navigation_bar_background);
1236 if (navigationBarBackground != null) {
1237 navigationBarBackground.setVisibility(isDialpadVisible ? View.VISIBLE : View.GONE);
Eric Erfanian938468d2017-10-24 14:05:52 -07001238 }
1239 }
1240
Eric Erfanianccca3152017-02-22 16:32:36 -08001241 public void setAllowOrientationChange(boolean allowOrientationChange) {
wangqi9982f0d2017-10-11 17:46:07 -07001242 if (this.allowOrientationChange == allowOrientationChange) {
1243 return;
1244 }
1245 this.allowOrientationChange = allowOrientationChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001246 if (!allowOrientationChange) {
1247 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_DISALLOW_ROTATION);
1248 } else {
1249 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
1250 }
1251 enableInCallOrientationEventListener(allowOrientationChange);
1252 }
1253
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001254 public void hideMainInCallFragment() {
linyuhc3968e62017-11-20 17:40:50 -08001255 LogUtil.enterBlock("InCallActivity.hideMainInCallFragment");
1256 if (getCallCardFragmentVisible()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001257 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1258 hideInCallScreenFragment(transaction);
1259 hideVideoCallScreenFragment(transaction);
1260 transaction.commitAllowingStateLoss();
1261 getSupportFragmentManager().executePendingTransactions();
1262 }
1263 }
1264
1265 private void showMainInCallFragment() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001266 Trace.beginSection("InCallActivity.showMainInCallFragment");
Eric Erfanianccca3152017-02-22 16:32:36 -08001267 // If the activity's onStart method hasn't been called yet then defer doing any work.
1268 if (!isVisible) {
1269 LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001270 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001271 return;
1272 }
1273
1274 // Don't let this be reentrant.
1275 if (isInShowMainInCallFragment) {
1276 LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001277 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001278 return;
1279 }
1280
1281 isInShowMainInCallFragment = true;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001282 ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi();
1283 ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi();
wangqi219b8702018-02-13 09:34:41 -08001284 ShouldShowUiResult shouldShowRttUi = getShouldShowRttUi();
erfaniand05d8992018-03-20 19:42:26 -07001285 ShouldShowUiResult shouldShowSpeakEasyUi = getShouldShowSpeakEasyUi();
Eric Erfanianccca3152017-02-22 16:32:36 -08001286 LogUtil.i(
1287 "InCallActivity.showMainInCallFragment",
wangqi219b8702018-02-13 09:34:41 -08001288 "shouldShowAnswerUi: %b, shouldShowRttUi: %b, shouldShowVideoUi: %b "
1289 + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowRttCallScreen: %b, "
erfaniand05d8992018-03-20 19:42:26 -07001290 + "didShowVideoCallScreen: %b"
1291 + "didShowSpeakEasyScreen: %b",
Eric Erfanianccca3152017-02-22 16:32:36 -08001292 shouldShowAnswerUi.shouldShow,
wangqi219b8702018-02-13 09:34:41 -08001293 shouldShowRttUi.shouldShow,
Eric Erfanian10b34a52017-05-04 08:23:17 -07001294 shouldShowVideoUi.shouldShow,
Eric Erfanianccca3152017-02-22 16:32:36 -08001295 didShowAnswerScreen,
1296 didShowInCallScreen,
wangqi219b8702018-02-13 09:34:41 -08001297 didShowRttCallScreen,
erfaniand05d8992018-03-20 19:42:26 -07001298 didShowVideoCallScreen,
1299 didShowSpeakEasyScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -08001300 // Only video call ui allows orientation change.
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001301 setAllowOrientationChange(shouldShowVideoUi.shouldShow);
Eric Erfanianccca3152017-02-22 16:32:36 -08001302
1303 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
wangqi219b8702018-02-13 09:34:41 -08001304 boolean didChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001305 if (shouldShowAnswerUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001306 didChange = hideInCallScreenFragment(transaction);
1307 didChange |= hideVideoCallScreenFragment(transaction);
1308 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001309 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001310 didChange |= showAnswerScreenFragment(transaction, shouldShowAnswerUi.call);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001311 } else if (shouldShowVideoUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001312 didChange = hideInCallScreenFragment(transaction);
1313 didChange |= showVideoCallScreenFragment(transaction, shouldShowVideoUi.call);
1314 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001315 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001316 didChange |= hideAnswerScreenFragment(transaction);
1317 } else if (shouldShowRttUi.shouldShow) {
1318 didChange = hideInCallScreenFragment(transaction);
1319 didChange |= hideVideoCallScreenFragment(transaction);
1320 didChange |= hideAnswerScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001321 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001322 didChange |= showRttCallScreenFragment(transaction, shouldShowRttUi.call);
erfaniand05d8992018-03-20 19:42:26 -07001323 } else if (shouldShowSpeakEasyUi.shouldShow) {
1324 didChange = hideInCallScreenFragment(transaction);
1325 didChange |= hideVideoCallScreenFragment(transaction);
1326 didChange |= hideAnswerScreenFragment(transaction);
1327 didChange |= hideRttCallScreenFragment(transaction);
1328 didChange |= showSpeakEasyFragment(transaction, shouldShowSpeakEasyUi.call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001329 } else {
wangqi219b8702018-02-13 09:34:41 -08001330 didChange = showInCallScreenFragment(transaction);
1331 didChange |= hideVideoCallScreenFragment(transaction);
1332 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001333 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001334 didChange |= hideAnswerScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001335 }
1336
wangqi219b8702018-02-13 09:34:41 -08001337 if (didChange) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001338 Trace.beginSection("InCallActivity.commitTransaction");
Eric Erfanianccca3152017-02-22 16:32:36 -08001339 transaction.commitNow();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001340 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001341 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1342 }
1343 isInShowMainInCallFragment = false;
Eric Erfanian2ca43182017-08-31 06:57:16 -07001344 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001345 }
1346
erfaniand05d8992018-03-20 19:42:26 -07001347 private boolean showSpeakEasyFragment(FragmentTransaction transaction, DialerCall call) {
1348
erfaniand05d8992018-03-20 19:42:26 -07001349 if (didShowSpeakEasyScreen) {
erfanian612d13a2018-04-04 15:27:57 -07001350 if (lastShownSpeakEasyScreenUniqueCallid.equals(call.getUniqueCallId())) {
erfanian12243de2018-04-17 12:17:08 -07001351 LogUtil.i("InCallActivity.showSpeakEasyFragment", "found existing fragment");
erfanian612d13a2018-04-04 15:27:57 -07001352 return false;
1353 }
1354 hideSpeakEasyFragment(transaction);
erfanian12243de2018-04-17 12:17:08 -07001355 LogUtil.i("InCallActivity.showSpeakEasyFragment", "hid existing fragment");
erfaniand05d8992018-03-20 19:42:26 -07001356 }
1357
1358 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1359 if (speakEasyFragment.isPresent()) {
1360 transaction.add(R.id.main, speakEasyFragment.get(), Tags.SPEAK_EASY_SCREEN);
1361 didShowSpeakEasyScreen = true;
erfanian612d13a2018-04-04 15:27:57 -07001362 lastShownSpeakEasyScreenUniqueCallid = call.getUniqueCallId();
erfanian12243de2018-04-17 12:17:08 -07001363 LogUtil.i(
1364 "InCallActivity.showSpeakEasyFragment",
1365 "set fragment for call %s",
1366 lastShownSpeakEasyScreenUniqueCallid);
erfaniand05d8992018-03-20 19:42:26 -07001367 return true;
1368 }
1369 return false;
1370 }
1371
1372 private Fragment getSpeakEasyScreen() {
1373 return getSupportFragmentManager().findFragmentByTag(Tags.SPEAK_EASY_SCREEN);
1374 }
1375
1376 private boolean hideSpeakEasyFragment(FragmentTransaction transaction) {
1377 if (!didShowSpeakEasyScreen) {
1378 return false;
1379 }
1380
1381 Fragment speakEasyFragment = getSpeakEasyScreen();
1382
1383 if (speakEasyFragment != null) {
1384 transaction.remove(speakEasyFragment);
1385 didShowSpeakEasyScreen = false;
1386 return true;
1387 }
1388 return false;
1389 }
1390
erfanian12243de2018-04-17 12:17:08 -07001391 @VisibleForTesting
erfaniand05d8992018-03-20 19:42:26 -07001392 public void setSpeakEasyCallManager(SpeakEasyCallManager speakEasyCallManager) {
erfanian87dbb622018-04-04 15:43:00 -07001393 this.speakEasyCallManager = speakEasyCallManager;
erfaniand05d8992018-03-20 19:42:26 -07001394 }
1395
erfanian12243de2018-04-17 12:17:08 -07001396 @Nullable
erfaniand05d8992018-03-20 19:42:26 -07001397 public SpeakEasyCallManager getSpeakEasyCallManager() {
erfanian12243de2018-04-17 12:17:08 -07001398 if (this.speakEasyCallManager == null) {
1399 this.speakEasyCallManager = InCallPresenter.getInstance().getSpeakEasyCallManager();
1400 }
erfaniand05d8992018-03-20 19:42:26 -07001401 return speakEasyCallManager;
1402 }
1403
1404 private ShouldShowUiResult getShouldShowSpeakEasyUi() {
1405 SpeakEasyCallManager speakEasyCallManager = getSpeakEasyCallManager();
1406
1407 if (speakEasyCallManager == null) {
1408 return new ShouldShowUiResult(false, null);
1409 }
1410
erfanian3bb7cb62018-04-11 09:01:15 -07001411 DialerCall call =
1412 CallList.getInstance().getIncomingCall() != null
1413 ? CallList.getInstance().getIncomingCall()
1414 : CallList.getInstance().getActiveCall();
erfaniand05d8992018-03-20 19:42:26 -07001415
1416 if (call == null) {
1417 return new ShouldShowUiResult(false, call);
1418 }
1419
1420 if (!call.isSpeakEasyCall() || !call.isSpeakEasyEligible()) {
1421 return new ShouldShowUiResult(false, call);
1422 }
1423
1424 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1425
1426 if (!speakEasyFragment.isPresent()) {
1427 return new ShouldShowUiResult(false, call);
1428 }
1429 return new ShouldShowUiResult(true, call);
1430 }
1431
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001432 private ShouldShowUiResult getShouldShowAnswerUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001433 DialerCall call = CallList.getInstance().getIncomingCall();
erfanian3bb7cb62018-04-11 09:01:15 -07001434 if (call != null && !call.isSpeakEasyCall()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001435 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001436 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001437 }
1438
1439 call = CallList.getInstance().getVideoUpgradeRequestCall();
1440 if (call != null) {
1441 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001442 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001443 }
1444
1445 // Check if we're showing the answer screen and the call is disconnected. If this condition is
1446 // true then we won't switch from the answer UI to the in call UI. This prevents flicker when
1447 // the user rejects an incoming call.
1448 call = CallList.getInstance().getFirstCall();
1449 if (call == null) {
1450 call = CallList.getInstance().getBackgroundCall();
1451 }
wangqibb94ca62018-04-27 14:34:04 -07001452 if (didShowAnswerScreen && (call == null || call.getState() == DialerCallState.DISCONNECTED)) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001453 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001454 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001455 }
1456
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001457 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001458 }
1459
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001460 private static ShouldShowUiResult getShouldShowVideoUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001461 DialerCall call = CallList.getInstance().getFirstCall();
1462 if (call == null) {
1463 LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001464 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001465 }
1466
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001467 if (call.isVideoCall()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001468 LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001469 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001470 }
1471
linyuh8fbecce2017-12-18 13:53:09 -08001472 if (call.hasSentVideoUpgradeRequest() || call.hasReceivedVideoUpgradeRequest()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001473 LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001474 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001475 }
1476
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001477 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001478 }
1479
wangqi219b8702018-02-13 09:34:41 -08001480 private static ShouldShowUiResult getShouldShowRttUi() {
1481 DialerCall call = CallList.getInstance().getFirstCall();
1482 if (call == null) {
1483 LogUtil.i("InCallActivity.getShouldShowRttUi", "null call");
1484 return new ShouldShowUiResult(false, null);
1485 }
1486
wangqif6be6172018-03-30 15:57:56 -07001487 if (call.isActiveRttCall()) {
wangqi219b8702018-02-13 09:34:41 -08001488 LogUtil.i("InCallActivity.getShouldShowRttUi", "found rtt call");
1489 return new ShouldShowUiResult(true, call);
1490 }
1491
1492 if (call.hasSentRttUpgradeRequest()) {
1493 LogUtil.i("InCallActivity.getShouldShowRttUi", "upgrading to rtt");
1494 return new ShouldShowUiResult(true, call);
1495 }
1496
1497 return new ShouldShowUiResult(false, null);
1498 }
1499
Eric Erfanianccca3152017-02-22 16:32:36 -08001500 private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) {
1501 // When rejecting a call the active call can become null in which case we should continue
1502 // showing the answer screen.
1503 if (didShowAnswerScreen && call == null) {
1504 return false;
1505 }
1506
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001507 Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null");
1508
1509 boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -08001510
1511 // Check if we're already showing an answer screen for this call.
1512 if (didShowAnswerScreen) {
1513 AnswerScreen answerScreen = getAnswerScreen();
1514 if (answerScreen.getCallId().equals(call.getId())
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001515 && answerScreen.isVideoCall() == call.isVideoCall()
Eric Erfanian2ca43182017-08-31 06:57:16 -07001516 && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest
1517 && !answerScreen.isActionTimeout()) {
1518 LogUtil.d(
1519 "InCallActivity.showAnswerScreenFragment",
1520 "answer fragment exists for same call and has NOT been accepted/rejected/timed out");
Eric Erfanianccca3152017-02-22 16:32:36 -08001521 return false;
1522 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001523 if (answerScreen.isActionTimeout()) {
1524 LogUtil.i(
1525 "InCallActivity.showAnswerScreenFragment",
1526 "answer fragment exists but has been accepted/rejected and timed out");
1527 } else {
1528 LogUtil.i(
1529 "InCallActivity.showAnswerScreenFragment",
1530 "answer fragment exists but arguments do not match");
1531 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001532 hideAnswerScreenFragment(transaction);
1533 }
1534
1535 // Show a new answer screen.
1536 AnswerScreen answerScreen =
Eric Erfanianfc37b022017-03-21 10:11:17 -07001537 AnswerBindings.createAnswerScreen(
1538 call.getId(),
wangqif6be6172018-03-30 15:57:56 -07001539 call.isActiveRttCall(),
Eric Erfanianfc37b022017-03-21 10:11:17 -07001540 call.isVideoCall(),
1541 isVideoUpgradeRequest,
Eric Erfanian90508232017-03-24 09:31:16 -07001542 call.getVideoTech().isSelfManagedCamera(),
1543 shouldAllowAnswerAndRelease(call),
erfaniand05d8992018-03-20 19:42:26 -07001544 CallList.getInstance().getBackgroundCall() != null,
1545 call.isSpeakEasyEligible());
linyuhc3968e62017-11-20 17:40:50 -08001546 transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001547
1548 Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this);
1549 didShowAnswerScreen = true;
1550 return true;
1551 }
1552
Eric Erfanian90508232017-03-24 09:31:16 -07001553 private boolean shouldAllowAnswerAndRelease(DialerCall call) {
1554 if (CallList.getInstance().getActiveCall() == null) {
1555 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call");
1556 return false;
1557 }
1558 if (getSystemService(TelephonyManager.class).getPhoneType()
1559 == TelephonyManager.PHONE_TYPE_CDMA) {
1560 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported");
1561 return false;
1562 }
1563 if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) {
1564 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call");
1565 return false;
1566 }
linyuhc3968e62017-11-20 17:40:50 -08001567 if (!ConfigProviderBindings.get(this)
1568 .getBoolean(ConfigNames.ANSWER_AND_RELEASE_ENABLED, true)) {
Eric Erfanian90508232017-03-24 09:31:16 -07001569 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config");
1570 return false;
1571 }
1572
1573 return true;
1574 }
1575
Eric Erfanianccca3152017-02-22 16:32:36 -08001576 private boolean hideAnswerScreenFragment(FragmentTransaction transaction) {
1577 if (!didShowAnswerScreen) {
1578 return false;
1579 }
1580 AnswerScreen answerScreen = getAnswerScreen();
1581 if (answerScreen != null) {
1582 transaction.remove(answerScreen.getAnswerScreenFragment());
1583 }
1584
1585 didShowAnswerScreen = false;
1586 return true;
1587 }
1588
1589 private boolean showInCallScreenFragment(FragmentTransaction transaction) {
1590 if (didShowInCallScreen) {
1591 return false;
1592 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001593 InCallScreen inCallScreen = InCallBindings.createInCallScreen();
linyuhc3968e62017-11-20 17:40:50 -08001594 transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001595 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1596 didShowInCallScreen = true;
1597 return true;
1598 }
1599
1600 private boolean hideInCallScreenFragment(FragmentTransaction transaction) {
1601 if (!didShowInCallScreen) {
1602 return false;
1603 }
1604 InCallScreen inCallScreen = getInCallScreen();
1605 if (inCallScreen != null) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001606 transaction.remove(inCallScreen.getInCallScreenFragment());
Eric Erfanianccca3152017-02-22 16:32:36 -08001607 }
1608 didShowInCallScreen = false;
1609 return true;
1610 }
1611
wangqi219b8702018-02-13 09:34:41 -08001612 private boolean showRttCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
1613 if (didShowRttCallScreen) {
1614 // This shouldn't happen since only one RTT call is allow at same time.
1615 if (!getRttCallScreen().getCallId().equals(call.getId())) {
1616 LogUtil.e("InCallActivity.showRttCallScreenFragment", "RTT call id doesn't match");
1617 }
1618 return false;
1619 }
1620 RttCallScreen rttCallScreen = RttBindings.createRttCallScreen(call.getId());
1621 transaction.add(R.id.main, rttCallScreen.getRttCallScreenFragment(), Tags.RTT_CALL_SCREEN);
1622 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1623 didShowRttCallScreen = true;
1624 return true;
1625 }
1626
1627 private boolean hideRttCallScreenFragment(FragmentTransaction transaction) {
1628 if (!didShowRttCallScreen) {
1629 return false;
1630 }
1631 RttCallScreen rttCallScreen = getRttCallScreen();
1632 if (rttCallScreen != null) {
1633 transaction.remove(rttCallScreen.getRttCallScreenFragment());
1634 }
1635 didShowRttCallScreen = false;
1636 return true;
1637 }
1638
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001639 private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001640 if (didShowVideoCallScreen) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001641 VideoCallScreen videoCallScreen = getVideoCallScreen();
1642 if (videoCallScreen.getCallId().equals(call.getId())) {
1643 return false;
1644 }
1645 LogUtil.i(
1646 "InCallActivity.showVideoCallScreenFragment",
1647 "video call fragment exists but arguments do not match");
1648 hideVideoCallScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001649 }
1650
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001651 LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call);
1652
Eric Erfanian90508232017-03-24 09:31:16 -07001653 VideoCallScreen videoCallScreen =
1654 VideoBindings.createVideoCallScreen(
1655 call.getId(), call.getVideoTech().shouldUseSurfaceView());
linyuhc3968e62017-11-20 17:40:50 -08001656 transaction.add(
1657 R.id.main, videoCallScreen.getVideoCallScreenFragment(), Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001658
1659 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1660 didShowVideoCallScreen = true;
1661 return true;
1662 }
1663
1664 private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) {
1665 if (!didShowVideoCallScreen) {
1666 return false;
1667 }
1668 VideoCallScreen videoCallScreen = getVideoCallScreen();
1669 if (videoCallScreen != null) {
1670 transaction.remove(videoCallScreen.getVideoCallScreenFragment());
1671 }
1672 didShowVideoCallScreen = false;
1673 return true;
1674 }
1675
linyuhc3968e62017-11-20 17:40:50 -08001676 private AnswerScreen getAnswerScreen() {
1677 return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001678 }
1679
linyuhc3968e62017-11-20 17:40:50 -08001680 private InCallScreen getInCallScreen() {
1681 return (InCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001682 }
1683
linyuhc3968e62017-11-20 17:40:50 -08001684 private VideoCallScreen getVideoCallScreen() {
1685 return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001686 }
1687
wangqi219b8702018-02-13 09:34:41 -08001688 private RttCallScreen getRttCallScreen() {
1689 return (RttCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.RTT_CALL_SCREEN);
1690 }
1691
wangqifd4c9f72018-03-08 18:21:50 -08001692 private InCallScreen getInCallOrRttCallScreen() {
1693 InCallScreen inCallScreen = null;
1694 if (didShowInCallScreen) {
1695 inCallScreen = getInCallScreen();
1696 }
1697 if (didShowRttCallScreen) {
1698 inCallScreen = getRttCallScreen();
1699 }
1700 return inCallScreen;
1701 }
1702
Eric Erfanianccca3152017-02-22 16:32:36 -08001703 @Override
1704 public void onPseudoScreenStateChanged(boolean isOn) {
1705 LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn);
1706 pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE);
1707 }
1708
1709 /**
1710 * For some touch related issue, turning off the screen can be faked by drawing a black view over
1711 * the activity. All touch events started when the screen is "off" is rejected.
1712 *
1713 * @see PseudoScreenState
1714 */
1715 @Override
1716 public boolean dispatchTouchEvent(MotionEvent event) {
1717 // Reject any gesture that started when the screen is in the fake off state.
1718 if (touchDownWhenPseudoScreenOff) {
1719 if (event.getAction() == MotionEvent.ACTION_UP) {
1720 touchDownWhenPseudoScreenOff = false;
1721 }
1722 return true;
1723 }
1724 // Reject all touch event when the screen is in the fake off state.
1725 if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) {
1726 if (event.getAction() == MotionEvent.ACTION_DOWN) {
1727 touchDownWhenPseudoScreenOff = true;
1728 LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff");
1729 }
1730 return true;
1731 }
1732 return super.dispatchTouchEvent(event);
1733 }
1734
wangqi219b8702018-02-13 09:34:41 -08001735 @Override
1736 public RttCallScreenDelegate newRttCallScreenDelegate(RttCallScreen videoCallScreen) {
1737 return new RttCallPresenter();
1738 }
1739
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001740 private static class ShouldShowUiResult {
Eric Erfanianccca3152017-02-22 16:32:36 -08001741 public final boolean shouldShow;
1742 public final DialerCall call;
1743
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001744 ShouldShowUiResult(boolean shouldShow, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001745 this.shouldShow = shouldShow;
1746 this.call = call;
1747 }
1748 }
linyuhc3968e62017-11-20 17:40:50 -08001749
1750 private static final class IntentExtraNames {
1751 static final String FOR_FULL_SCREEN = "InCallActivity.for_full_screen_intent";
1752 static final String NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call";
1753 static final String SHOW_DIALPAD = "InCallActivity.show_dialpad";
1754 }
1755
1756 private static final class KeysForSavedInstance {
1757 static final String DIALPAD_TEXT = "InCallActivity.dialpad_text";
1758 static final String DID_SHOW_ANSWER_SCREEN = "did_show_answer_screen";
1759 static final String DID_SHOW_IN_CALL_SCREEN = "did_show_in_call_screen";
1760 static final String DID_SHOW_VIDEO_CALL_SCREEN = "did_show_video_call_screen";
wangqi153af2f2018-02-15 16:21:49 -08001761 static final String DID_SHOW_RTT_CALL_SCREEN = "did_show_rtt_call_screen";
erfaniand05d8992018-03-20 19:42:26 -07001762 static final String DID_SHOW_SPEAK_EASY_SCREEN = "did_show_speak_easy_screen";
linyuhc3968e62017-11-20 17:40:50 -08001763 }
1764
1765 /** Request codes for pending intents. */
1766 public static final class PendingIntentRequestCodes {
1767 static final int NON_FULL_SCREEN = 0;
1768 static final int FULL_SCREEN = 1;
1769 static final int BUBBLE = 2;
1770 }
1771
1772 private static final class Tags {
1773 static final String ANSWER_SCREEN = "tag_answer_screen";
1774 static final String DIALPAD_FRAGMENT = "tag_dialpad_fragment";
1775 static final String IN_CALL_SCREEN = "tag_in_call_screen";
1776 static final String INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi";
1777 static final String SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment";
1778 static final String VIDEO_CALL_SCREEN = "tag_video_call_screen";
wangqi219b8702018-02-13 09:34:41 -08001779 static final String RTT_CALL_SCREEN = "tag_rtt_call_screen";
linyuhc3968e62017-11-20 17:40:50 -08001780 static final String POST_CHAR_DIALOG_FRAGMENT = "tag_post_char_dialog_fragment";
erfaniand05d8992018-03-20 19:42:26 -07001781 static final String SPEAK_EASY_SCREEN = "tag_speak_easy_screen";
wangqibc28ea72018-04-02 16:23:00 -07001782 static final String RTT_REQUEST_DIALOG = "tag_rtt_request_dialog";
linyuhc3968e62017-11-20 17:40:50 -08001783 }
1784
1785 private static final class ConfigNames {
1786 static final String ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled";
1787 }
1788
linyuhc3968e62017-11-20 17:40:50 -08001789 private static final class SelectPhoneAccountListener
1790 extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener {
1791 private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName();
1792
twyen73a74c32018-03-07 12:12:24 -08001793 private final Context appContext;
1794
1795 SelectPhoneAccountListener(Context appContext) {
1796 this.appContext = appContext;
1797 }
1798
linyuhc3968e62017-11-20 17:40:50 -08001799 @Override
1800 public void onPhoneAccountSelected(
1801 PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) {
1802 DialerCall call = CallList.getInstance().getCallById(callId);
1803 LogUtil.i(TAG, "Phone account select with call:\n%s", call);
1804
1805 if (call != null) {
twyen73a74c32018-03-07 12:12:24 -08001806 call.phoneAccountSelected(selectedAccountHandle, false);
1807 if (call.getPreferredAccountRecorder() != null) {
1808 call.getPreferredAccountRecorder().record(appContext, selectedAccountHandle, setDefault);
1809 }
linyuhc3968e62017-11-20 17:40:50 -08001810 }
1811 }
1812
1813 @Override
1814 public void onDialogDismissed(String callId) {
1815 DialerCall call = CallList.getInstance().getCallById(callId);
1816 LogUtil.i(TAG, "Disconnecting call:\n%s" + call);
1817
1818 if (call != null) {
1819 call.disconnect();
1820 }
1821 }
1822 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001823}