blob: 3236e160a557305840a6c6e57614cfcc66bdae41 [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;
erfaniand05d8992018-03-20 19:42:26 -070038import android.support.v4.app.Fragment;
Eric Erfanianccca3152017-02-22 16:32:36 -080039import android.support.v4.app.FragmentManager;
40import android.support.v4.app.FragmentTransaction;
linyuh57b093b2017-11-17 14:32:32 -080041import android.support.v4.content.res.ResourcesCompat;
Eric Erfanianccca3152017-02-22 16:32:36 -080042import android.support.v4.graphics.ColorUtils;
twyen73a74c32018-03-07 12:12:24 -080043import android.telecom.Call;
linyuhc3968e62017-11-20 17:40:50 -080044import android.telecom.CallAudioState;
45import android.telecom.PhoneAccountHandle;
Eric Erfanian90508232017-03-24 09:31:16 -070046import android.telephony.TelephonyManager;
Eric Erfanianccca3152017-02-22 16:32:36 -080047import android.view.KeyEvent;
48import android.view.MenuItem;
49import android.view.MotionEvent;
50import android.view.View;
linyuh9c327da2017-11-14 12:33:48 -080051import android.view.WindowManager;
linyuhc3968e62017-11-20 17:40:50 -080052import android.view.animation.Animation;
53import android.view.animation.AnimationUtils;
linyuh7b86f562017-11-16 11:24:09 -080054import android.widget.CheckBox;
55import android.widget.Toast;
linyuhf99f6302017-11-15 11:23:51 -080056import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
linyuhc3968e62017-11-20 17:40:50 -080057import com.android.dialer.animation.AnimUtils;
58import com.android.dialer.animation.AnimationListenerAdapter;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070059import com.android.dialer.common.Assert;
Eric Erfanianccca3152017-02-22 16:32:36 -080060import com.android.dialer.common.LogUtil;
twyen73a74c32018-03-07 12:12:24 -080061import com.android.dialer.common.concurrent.DialerExecutorComponent;
weijiaxu650e7cc2017-10-31 12:38:54 -070062import com.android.dialer.common.concurrent.ThreadUtil;
linyuhc3968e62017-11-20 17:40:50 -080063import com.android.dialer.compat.CompatUtils;
Eric Erfanian2ca43182017-08-31 06:57:16 -070064import com.android.dialer.configprovider.ConfigProviderBindings;
twyen73a74c32018-03-07 12:12:24 -080065import com.android.dialer.logging.DialerImpression.Type;
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;
72import com.android.dialer.preferredsim.suggestion.SuggestionProvider;
linyuhc3968e62017-11-20 17:40:50 -080073import com.android.dialer.util.ViewUtil;
Eric Erfanianccca3152017-02-22 16:32:36 -080074import com.android.incallui.answer.bindings.AnswerBindings;
75import com.android.incallui.answer.protocol.AnswerScreen;
76import com.android.incallui.answer.protocol.AnswerScreenDelegate;
77import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory;
78import com.android.incallui.answerproximitysensor.PseudoScreenState;
linyuh57b093b2017-11-17 14:32:32 -080079import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080080import com.android.incallui.call.CallList;
81import com.android.incallui.call.DialerCall;
82import com.android.incallui.call.DialerCall.State;
linyuh57b093b2017-11-17 14:32:32 -080083import com.android.incallui.call.TelecomAdapter;
Eric Erfanian2ca43182017-08-31 06:57:16 -070084import com.android.incallui.callpending.CallPendingActivity;
85import com.android.incallui.disconnectdialog.DisconnectMessage;
Eric Erfanianccca3152017-02-22 16:32:36 -080086import com.android.incallui.incall.bindings.InCallBindings;
87import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
88import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory;
89import com.android.incallui.incall.protocol.InCallScreen;
90import com.android.incallui.incall.protocol.InCallScreenDelegate;
91import com.android.incallui.incall.protocol.InCallScreenDelegateFactory;
linyuh7b86f562017-11-16 11:24:09 -080092import com.android.incallui.incalluilock.InCallUiLock;
wangqi219b8702018-02-13 09:34:41 -080093import com.android.incallui.rtt.bindings.RttBindings;
94import com.android.incallui.rtt.protocol.RttCallScreen;
95import com.android.incallui.rtt.protocol.RttCallScreenDelegate;
96import com.android.incallui.rtt.protocol.RttCallScreenDelegateFactory;
erfaniand05d8992018-03-20 19:42:26 -070097import com.android.incallui.speakeasy.SpeakEasyCallManager;
linyuhf99f6302017-11-15 11:23:51 -080098import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment;
Eric Erfanianccca3152017-02-22 16:32:36 -080099import com.android.incallui.video.bindings.VideoBindings;
100import com.android.incallui.video.protocol.VideoCallScreen;
101import com.android.incallui.video.protocol.VideoCallScreenDelegate;
102import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory;
linyuhc3968e62017-11-20 17:40:50 -0800103import com.google.common.base.Optional;
104import java.lang.annotation.Retention;
105import java.lang.annotation.RetentionPolicy;
106import java.util.ArrayList;
107import java.util.List;
Eric Erfanianccca3152017-02-22 16:32:36 -0800108
109/** Version of {@link InCallActivity} that shows the new UI */
110public class InCallActivity extends TransactionSafeFragmentActivity
111 implements AnswerScreenDelegateFactory,
112 InCallScreenDelegateFactory,
113 InCallButtonUiDelegateFactory,
114 VideoCallScreenDelegateFactory,
wangqi219b8702018-02-13 09:34:41 -0800115 RttCallScreenDelegateFactory,
Eric Erfanianccca3152017-02-22 16:32:36 -0800116 PseudoScreenState.StateChangedListener {
117
linyuhc3968e62017-11-20 17:40:50 -0800118 @Retention(RetentionPolicy.SOURCE)
119 @IntDef({
120 DIALPAD_REQUEST_NONE,
121 DIALPAD_REQUEST_SHOW,
122 DIALPAD_REQUEST_HIDE,
123 })
124 @interface DialpadRequestType {}
Eric Erfanian2ca43182017-08-31 06:57:16 -0700125
linyuhc3968e62017-11-20 17:40:50 -0800126 private static final int DIALPAD_REQUEST_NONE = 1;
127 private static final int DIALPAD_REQUEST_SHOW = 2;
128 private static final int DIALPAD_REQUEST_HIDE = 3;
linyuh57b093b2017-11-17 14:32:32 -0800129
linyuhc3968e62017-11-20 17:40:50 -0800130 private static Optional<Integer> audioRouteForTesting = Optional.absent();
linyuh57b093b2017-11-17 14:32:32 -0800131
linyuhc3968e62017-11-20 17:40:50 -0800132 private final InternationalCallOnWifiCallback internationalCallOnWifiCallback =
133 new InternationalCallOnWifiCallback();
twyen73a74c32018-03-07 12:12:24 -0800134
135 private SelectPhoneAccountListener selectPhoneAccountListener;
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;
145 private String showPostCharWaitDialogCallId;
146 private String showPostCharWaitDialogChars;
147 private boolean allowOrientationChange;
148 private boolean animateDialpadOnShow;
Eric Erfanianccca3152017-02-22 16:32:36 -0800149 private boolean didShowAnswerScreen;
150 private boolean didShowInCallScreen;
151 private boolean didShowVideoCallScreen;
wangqi219b8702018-02-13 09:34:41 -0800152 private boolean didShowRttCallScreen;
erfaniand05d8992018-03-20 19:42:26 -0700153 private boolean didShowSpeakEasyScreen;
linyuh9c327da2017-11-14 12:33:48 -0800154 private boolean dismissKeyguard;
Eric Erfanianccca3152017-02-22 16:32:36 -0800155 private boolean isInShowMainInCallFragment;
linyuhc3968e62017-11-20 17:40:50 -0800156 private boolean isRecreating; // whether the activity is going to be recreated
157 private boolean isVisible;
Eric Erfanianccca3152017-02-22 16:32:36 -0800158 private boolean needDismissPendingDialogs;
linyuhc3968e62017-11-20 17:40:50 -0800159 private boolean showPostCharWaitDialogOnResume;
160 private boolean touchDownWhenPseudoScreenOff;
161 private int[] backgroundDrawableColors;
162 @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE;
erfaniand05d8992018-03-20 19:42:26 -0700163 private SpeakEasyCallManager speakEasyCallManager;
Eric Erfanianccca3152017-02-22 16:32:36 -0800164
165 public static Intent getIntent(
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700166 Context context, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800167 Intent intent = new Intent(Intent.ACTION_MAIN, null);
168 intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK);
169 intent.setClass(context, InCallActivity.class);
linyuhc3968e62017-11-20 17:40:50 -0800170 if (showDialpad) {
171 intent.putExtra(IntentExtraNames.SHOW_DIALPAD, true);
172 }
173 intent.putExtra(IntentExtraNames.NEW_OUTGOING_CALL, newOutgoingCall);
174 intent.putExtra(IntentExtraNames.FOR_FULL_SCREEN, isForFullScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -0800175 return intent;
176 }
177
178 @Override
179 protected void onResumeFragments() {
180 super.onResumeFragments();
181 if (needDismissPendingDialogs) {
182 dismissPendingDialogs();
183 }
184 }
185
186 @Override
linyuhc3968e62017-11-20 17:40:50 -0800187 protected void onCreate(Bundle bundle) {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700188 Trace.beginSection("InCallActivity.onCreate");
linyuhc3968e62017-11-20 17:40:50 -0800189 super.onCreate(bundle);
Eric Erfanianccca3152017-02-22 16:32:36 -0800190
twyen73a74c32018-03-07 12:12:24 -0800191 selectPhoneAccountListener = new SelectPhoneAccountListener(getApplicationContext());
192
linyuhc3968e62017-11-20 17:40:50 -0800193 if (bundle != null) {
194 didShowAnswerScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN);
195 didShowInCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN);
196 didShowVideoCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN);
wangqi153af2f2018-02-15 16:21:49 -0800197 didShowRttCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -0800198 }
199
linyuhc3968e62017-11-20 17:40:50 -0800200 setWindowFlags();
201 setContentView(R.layout.incall_screen);
202 internalResolveIntent(getIntent());
203
204 boolean isLandscape =
205 getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
206 boolean isRtl = ViewUtil.isRtl();
207 if (isLandscape) {
208 dialpadSlideInAnimation =
209 AnimationUtils.loadAnimation(
210 this, isRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
211 dialpadSlideOutAnimation =
212 AnimationUtils.loadAnimation(
213 this, isRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
214 } else {
215 dialpadSlideInAnimation = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
216 dialpadSlideOutAnimation =
217 AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
218 }
219 dialpadSlideInAnimation.setInterpolator(AnimUtils.EASE_IN);
220 dialpadSlideOutAnimation.setInterpolator(AnimUtils.EASE_OUT);
221 dialpadSlideOutAnimation.setAnimationListener(
222 new AnimationListenerAdapter() {
223 @Override
224 public void onAnimationEnd(Animation animation) {
225 hideDialpadFragment();
226 }
227 });
228
229 if (bundle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) {
230 // If the dialpad was shown before, set related variables so that it can be shown and
231 // populated with the previous DTMF text during onResume().
232 if (bundle.containsKey(IntentExtraNames.SHOW_DIALPAD)) {
233 boolean showDialpad = bundle.getBoolean(IntentExtraNames.SHOW_DIALPAD);
234 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_HIDE;
235 animateDialpadOnShow = false;
236 }
237 dtmfTextToPrepopulate = bundle.getString(KeysForSavedInstance.DIALPAD_TEXT);
238
239 SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment =
240 (SelectPhoneAccountDialogFragment)
241 getFragmentManager().findFragmentByTag(Tags.SELECT_ACCOUNT_FRAGMENT);
242 if (selectPhoneAccountDialogFragment != null) {
243 selectPhoneAccountDialogFragment.setListener(selectPhoneAccountListener);
244 }
245 }
246
247 InternationalCallOnWifiDialogFragment existingInternationalCallOnWifiDialogFragment =
248 (InternationalCallOnWifiDialogFragment)
249 getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
250 if (existingInternationalCallOnWifiDialogFragment != null) {
251 existingInternationalCallOnWifiDialogFragment.setCallback(internationalCallOnWifiCallback);
252 }
253
linyuh69a25062017-11-15 16:18:51 -0800254 inCallOrientationEventListener = new InCallOrientationEventListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -0800255
256 getWindow()
257 .getDecorView()
258 .setSystemUiVisibility(
259 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
260
261 pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700262 sendBroadcast(CallPendingActivity.getFinishBroadcast());
263 Trace.endSection();
zachh7a96dc72018-02-20 22:16:03 -0800264 MetricsComponent.get(this)
265 .metrics()
266 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_INCOMING);
267 MetricsComponent.get(this)
268 .metrics()
269 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_OUTGOING);
Eric Erfanianccca3152017-02-22 16:32:36 -0800270 }
271
linyuhc3968e62017-11-20 17:40:50 -0800272 private void setWindowFlags() {
273 // Allow the activity to be shown when the screen is locked and filter out touch events that are
274 // "too fat".
275 int flags =
276 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
277 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;
278
linyuhf79d1cb2017-12-15 17:49:56 -0800279 // When the audio stream is not via Bluetooth, turn on the screen once the activity is shown.
280 // When the audio stream is via Bluetooth, turn on the screen only for an incoming call.
linyuhc3968e62017-11-20 17:40:50 -0800281 final int audioRoute = getAudioRoute();
linyuhf79d1cb2017-12-15 17:49:56 -0800282 if (audioRoute != CallAudioState.ROUTE_BLUETOOTH
283 || CallList.getInstance().getIncomingCall() != null) {
linyuhc3968e62017-11-20 17:40:50 -0800284 flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
285 }
286
287 getWindow().addFlags(flags);
288 }
289
290 private static int getAudioRoute() {
291 if (audioRouteForTesting.isPresent()) {
292 return audioRouteForTesting.get();
293 }
294
295 return AudioModeProvider.getInstance().getAudioState().getRoute();
296 }
297
298 @VisibleForTesting(otherwise = VisibleForTesting.NONE)
299 public static void setAudioRouteForTesting(int audioRoute) {
300 audioRouteForTesting = Optional.of(audioRoute);
301 }
302
303 private void internalResolveIntent(Intent intent) {
304 if (!intent.getAction().equals(Intent.ACTION_MAIN)) {
305 return;
306 }
307
308 if (intent.hasExtra(IntentExtraNames.SHOW_DIALPAD)) {
309 // IntentExtraNames.SHOW_DIALPAD can be used to specify whether the DTMF dialpad should be
310 // initially visible. If the extra is absent, leave the dialpad in its previous state.
311 boolean showDialpad = intent.getBooleanExtra(IntentExtraNames.SHOW_DIALPAD, false);
312 relaunchedFromDialer(showDialpad);
313 }
314
315 DialerCall outgoingCall = CallList.getInstance().getOutgoingCall();
316 if (outgoingCall == null) {
317 outgoingCall = CallList.getInstance().getPendingOutgoingCall();
318 }
319 if (intent.getBooleanExtra(IntentExtraNames.NEW_OUTGOING_CALL, false)) {
320 intent.removeExtra(IntentExtraNames.NEW_OUTGOING_CALL);
321
322 // InCallActivity is responsible for disconnecting a new outgoing call if there is no way of
323 // making it (i.e. no valid call capable accounts).
324 // If the version is not MSIM compatible, ignore this code.
325 if (CompatUtils.isMSIMCompatible()
326 && InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) {
327 LogUtil.i(
328 "InCallActivity.internalResolveIntent", "Call with no valid accounts, disconnecting");
329 outgoingCall.disconnect();
330 }
331
332 dismissKeyguard(true);
333 }
334
335 if (showPhoneAccountSelectionDialog()) {
336 hideMainInCallFragment();
337 }
338 }
339
340 /**
341 * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should
342 * be shown on launch.
343 *
344 * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code
345 * false} to indicate no change should be made to the dialpad visibility.
346 */
347 private void relaunchedFromDialer(boolean showDialpad) {
348 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE;
349 animateDialpadOnShow = true;
350
351 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
352 // If there's only one line in use, AND it's on hold, then we're sure the user
353 // wants to use the dialpad toward the exact line, so un-hold the holding line.
354 DialerCall call = CallList.getInstance().getActiveOrBackgroundCall();
355 if (call != null && call.getState() == State.ONHOLD) {
356 call.unhold();
357 }
358 }
359 }
360
361 /**
362 * Show a phone account selection dialog if there is a call waiting for phone account selection.
363 *
364 * @return true if the dialog was shown.
365 */
366 private boolean showPhoneAccountSelectionDialog() {
367 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
368 if (waitingForAccountCall == null) {
369 return false;
370 }
371
twyen73a74c32018-03-07 12:12:24 -0800372 DialerExecutorComponent.get(this)
373 .dialerExecutorFactory()
374 .createNonUiTaskBuilder(new PreferredAccountWorker(waitingForAccountCall.getNumber()))
375 .onSuccess(
376 (result -> {
377 if (result.getPhoneAccountHandle().isPresent()) {
378 Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_PREFERRED_USED);
379 selectPhoneAccountListener.onPhoneAccountSelected(
380 result.getPhoneAccountHandle().get(), false, waitingForAccountCall.getId());
381 return;
382 }
383 if (result.getSuggestion().isPresent()) {
384 LogUtil.i(
385 "CallingAccountSelector.processPreferredAccount",
386 "SIM suggested: " + result.getSuggestion().get().reason);
387 if (result.getSuggestion().get().shouldAutoSelect) {
388 Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_SUGGESTION_AUTO_SELECTED);
389 LogUtil.i(
390 "CallingAccountSelector.processPreferredAccount", "Auto selected suggestion");
391 selectPhoneAccountListener.onPhoneAccountSelected(
392 result.getSuggestion().get().phoneAccountHandle,
393 false,
394 waitingForAccountCall.getId());
395 return;
396 }
397 }
398 Bundle extras = waitingForAccountCall.getIntentExtras();
399 List<PhoneAccountHandle> phoneAccountHandles =
400 extras == null
401 ? new ArrayList<>()
402 : extras.getParcelableArrayList(Call.AVAILABLE_PHONE_ACCOUNTS);
linyuhc3968e62017-11-20 17:40:50 -0800403
twyen73a74c32018-03-07 12:12:24 -0800404 waitingForAccountCall.setPreferredAccountRecorder(
405 new PreferredAccountRecorder(
406 waitingForAccountCall.getNumber(),
407 result.getSuggestion().orNull(),
408 result.getDataId().orNull()));
409 selectPhoneAccountDialogFragment =
410 SelectPhoneAccountDialogFragment.newInstance(
411 R.string.select_phone_account_for_calls,
412 result.getDataId().isPresent() /* canSetDefault */,
413 R.string.select_phone_account_for_calls_remember /* setDefaultResId */,
414 phoneAccountHandles,
415 selectPhoneAccountListener,
416 waitingForAccountCall.getId(),
417 SuggestionProvider.buildHint(
418 this, phoneAccountHandles, result.getSuggestion().orNull() /* hints */));
419 selectPhoneAccountDialogFragment.show(
420 getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT);
421 }))
422 .build()
423 .executeParallel(this);
424
linyuhc3968e62017-11-20 17:40:50 -0800425 return true;
426 }
427
Eric Erfanianccca3152017-02-22 16:32:36 -0800428 @Override
429 protected void onSaveInstanceState(Bundle out) {
linyuh57b093b2017-11-17 14:32:32 -0800430 LogUtil.enterBlock("InCallActivity.onSaveInstanceState");
431
432 // TODO: DialpadFragment should handle this as part of its own state
linyuhc3968e62017-11-20 17:40:50 -0800433 out.putBoolean(IntentExtraNames.SHOW_DIALPAD, isDialpadVisible());
linyuh57b093b2017-11-17 14:32:32 -0800434 DialpadFragment dialpadFragment = getDialpadFragment();
435 if (dialpadFragment != null) {
linyuhc3968e62017-11-20 17:40:50 -0800436 out.putString(KeysForSavedInstance.DIALPAD_TEXT, dialpadFragment.getDtmfText());
linyuh57b093b2017-11-17 14:32:32 -0800437 }
438
linyuhc3968e62017-11-20 17:40:50 -0800439 out.putBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN, didShowAnswerScreen);
440 out.putBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN, didShowInCallScreen);
441 out.putBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN, didShowVideoCallScreen);
wangqi153af2f2018-02-15 16:21:49 -0800442 out.putBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN, didShowRttCallScreen);
erfaniand05d8992018-03-20 19:42:26 -0700443 out.putBoolean(KeysForSavedInstance.DID_SHOW_SPEAK_EASY_SCREEN, didShowSpeakEasyScreen);
linyuh57b093b2017-11-17 14:32:32 -0800444
Eric Erfanianccca3152017-02-22 16:32:36 -0800445 super.onSaveInstanceState(out);
446 isVisible = false;
447 }
448
449 @Override
450 protected void onStart() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700451 Trace.beginSection("InCallActivity.onStart");
Eric Erfanianccca3152017-02-22 16:32:36 -0800452 super.onStart();
linyuh57b093b2017-11-17 14:32:32 -0800453
Eric Erfanianccca3152017-02-22 16:32:36 -0800454 isVisible = true;
455 showMainInCallFragment();
linyuh57b093b2017-11-17 14:32:32 -0800456
457 InCallPresenter.getInstance().setActivity(this);
458 enableInCallOrientationEventListener(
459 getRequestedOrientation()
460 == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
461 InCallPresenter.getInstance().onActivityStarted();
462
yueg10f6e822018-01-17 15:32:18 -0800463 if (!isRecreating) {
464 InCallPresenter.getInstance().onUiShowing(true);
465 }
466
linyuh437ae952018-03-26 12:46:18 -0700467 if (isInMultiWindowMode() && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800468 // Hide the dialpad because there may not be enough room
469 showDialpadFragment(false, false);
470 }
linyuh57b093b2017-11-17 14:32:32 -0800471
Eric Erfanian2ca43182017-08-31 06:57:16 -0700472 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800473 }
474
475 @Override
476 protected void onResume() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700477 Trace.beginSection("InCallActivity.onResume");
Eric Erfanianccca3152017-02-22 16:32:36 -0800478 super.onResume();
linyuhc3968e62017-11-20 17:40:50 -0800479
480 if (!InCallPresenter.getInstance().isReadyForTearDown()) {
481 updateTaskDescription();
yueg10f6e822018-01-17 15:32:18 -0800482 InCallPresenter.getInstance().updateNotification();
linyuhc3968e62017-11-20 17:40:50 -0800483 }
484
485 // If there is a pending request to show or hide the dialpad, handle that now.
486 if (showDialpadRequest != DIALPAD_REQUEST_NONE) {
487 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
488 // Exit fullscreen so that the user has access to the dialpad hide/show button.
489 // This is important when showing the dialpad from within dialer.
490 InCallPresenter.getInstance().setFullScreen(false /* isFullScreen */, true /* force */);
491
492 showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */);
493 animateDialpadOnShow = false;
494
495 DialpadFragment dialpadFragment = getDialpadFragment();
496 if (dialpadFragment != null) {
497 dialpadFragment.setDtmfText(dtmfTextToPrepopulate);
498 dtmfTextToPrepopulate = null;
499 }
500 } else {
501 LogUtil.i("InCallActivity.onResume", "Force-hide the dialpad");
502 if (getDialpadFragment() != null) {
503 showDialpadFragment(false /* show */, false /* animate */);
504 }
505 }
506 showDialpadRequest = DIALPAD_REQUEST_NONE;
507 }
508 updateNavigationBar(isDialpadVisible());
509
510 if (showPostCharWaitDialogOnResume) {
511 showDialogForPostCharWait(showPostCharWaitDialogCallId, showPostCharWaitDialogChars);
512 }
513
514 CallList.getInstance()
515 .onInCallUiShown(getIntent().getBooleanExtra(IntentExtraNames.FOR_FULL_SCREEN, false));
516
Eric Erfanianccca3152017-02-22 16:32:36 -0800517 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
518 pseudoScreenState.addListener(this);
519 onPseudoScreenStateChanged(pseudoScreenState.isOn());
Eric Erfanian2ca43182017-08-31 06:57:16 -0700520 Trace.endSection();
weijiaxu650e7cc2017-10-31 12:38:54 -0700521 // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume.
522 ThreadUtil.postDelayedOnUiThread(
weijiaxuc950a9b2017-11-06 16:39:04 -0800523 () ->
zachh7a96dc72018-02-20 22:16:03 -0800524 MetricsComponent.get(this)
525 .metrics()
526 .recordMemory(Metrics.INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME),
weijiaxu650e7cc2017-10-31 12:38:54 -0700527 1000);
Eric Erfanianccca3152017-02-22 16:32:36 -0800528 }
529
Eric Erfanianccca3152017-02-22 16:32:36 -0800530 @Override
531 protected void onPause() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700532 Trace.beginSection("InCallActivity.onPause");
Eric Erfanianccca3152017-02-22 16:32:36 -0800533 super.onPause();
linyuh57b093b2017-11-17 14:32:32 -0800534
535 DialpadFragment dialpadFragment = getDialpadFragment();
536 if (dialpadFragment != null) {
537 dialpadFragment.onDialerKeyUp(null);
538 }
539
yueg10f6e822018-01-17 15:32:18 -0800540 InCallPresenter.getInstance().updateNotification();
linyuh57b093b2017-11-17 14:32:32 -0800541
Eric Erfanianccca3152017-02-22 16:32:36 -0800542 InCallPresenter.getInstance().getPseudoScreenState().removeListener(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700543 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800544 }
545
546 @Override
547 protected void onStop() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700548 Trace.beginSection("InCallActivity.onStop");
wangqi4d705e52017-09-28 12:23:35 -0700549 isVisible = false;
Eric Erfanianccca3152017-02-22 16:32:36 -0800550 super.onStop();
linyuh57b093b2017-11-17 14:32:32 -0800551
552 // Disconnects the call waiting for a phone account when the activity is hidden (e.g., after the
553 // user presses the home button).
554 // Without this the pending call will get stuck on phone account selection and new calls can't
555 // be created.
556 // Skip this when the screen is locked since the activity may complete its current life cycle
557 // and restart.
linyuhc3968e62017-11-20 17:40:50 -0800558 if (!isRecreating && !getSystemService(KeyguardManager.class).isKeyguardLocked()) {
linyuh57b093b2017-11-17 14:32:32 -0800559 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
560 if (waitingForAccountCall != null) {
561 waitingForAccountCall.disconnect();
562 }
563 }
564
565 enableInCallOrientationEventListener(false);
566 InCallPresenter.getInstance().updateIsChangingConfigurations();
567 InCallPresenter.getInstance().onActivityStopped();
linyuhc3968e62017-11-20 17:40:50 -0800568 if (!isRecreating) {
yueg10f6e822018-01-17 15:32:18 -0800569 InCallPresenter.getInstance().onUiShowing(false);
linyuh57b093b2017-11-17 14:32:32 -0800570 if (errorDialog != null) {
571 errorDialog.dismiss();
572 }
573 }
574
yueg10f6e822018-01-17 15:32:18 -0800575 if (isFinishing()) {
576 InCallPresenter.getInstance().unsetActivity(this);
577 }
578
Eric Erfanian2ca43182017-08-31 06:57:16 -0700579 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800580 }
581
582 @Override
583 protected void onDestroy() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700584 Trace.beginSection("InCallActivity.onDestroy");
Eric Erfanianccca3152017-02-22 16:32:36 -0800585 super.onDestroy();
linyuh57b093b2017-11-17 14:32:32 -0800586
587 InCallPresenter.getInstance().unsetActivity(this);
588 InCallPresenter.getInstance().updateIsChangingConfigurations();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700589 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800590 }
591
592 @Override
593 public void finish() {
594 if (shouldCloseActivityOnFinish()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700595 // When user select incall ui from recents after the call is disconnected, it tries to launch
596 // a new InCallActivity but InCallPresenter is already teared down at this point, which causes
597 // crash.
598 // By calling finishAndRemoveTask() instead of finish() the task associated with
599 // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in
600 // this case.
601 //
602 // Calling finish won't clear the task and normally when an activity finishes it shouldn't
603 // clear the task since there could be parent activity in the same task that's still alive.
604 // But InCallActivity is special since it's singleInstance which means it's root activity and
605 // only instance of activity in the task. So it should be safe to also remove task when
606 // finishing.
607 // It's also necessary in the sense of it's excluded from recents. So whenever the activity
608 // finishes, the task should also be removed since it doesn't make sense to go back to it in
609 // anyway anymore.
610 super.finishAndRemoveTask();
Eric Erfanianccca3152017-02-22 16:32:36 -0800611 }
612 }
613
614 private boolean shouldCloseActivityOnFinish() {
linyuhc3968e62017-11-20 17:40:50 -0800615 if (!isVisible) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800616 LogUtil.i(
617 "InCallActivity.shouldCloseActivityOnFinish",
618 "allowing activity to be closed because it's not visible");
619 return true;
620 }
621
twyen8efb4952017-10-06 16:35:54 -0700622 if (InCallPresenter.getInstance().isInCallUiLocked()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800623 LogUtil.i(
624 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700625 "in call ui is locked, not closing activity");
Eric Erfanianccca3152017-02-22 16:32:36 -0800626 return false;
627 }
628
629 LogUtil.i(
630 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700631 "activity is visible and has no locks, allowing activity to close");
Eric Erfanianccca3152017-02-22 16:32:36 -0800632 return true;
633 }
634
635 @Override
636 protected void onNewIntent(Intent intent) {
linyuhc3968e62017-11-20 17:40:50 -0800637 LogUtil.enterBlock("InCallActivity.onNewIntent");
Eric Erfanianccca3152017-02-22 16:32:36 -0800638
639 // If the screen is off, we need to make sure it gets turned on for incoming calls.
640 // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works
641 // when the activity is first created. Therefore, to ensure the screen is turned on
642 // for the call waiting case, we recreate() the current activity. There should be no jank from
643 // this since the screen is already off and will remain so until our new activity is up.
linyuhc3968e62017-11-20 17:40:50 -0800644 if (!isVisible) {
645 onNewIntent(intent, true /* isRecreating */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800646 LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on.");
647 recreate();
Eric Erfanian10b34a52017-05-04 08:23:17 -0700648 } else {
linyuhc3968e62017-11-20 17:40:50 -0800649 onNewIntent(intent, false /* isRecreating */);
650 }
651 }
652
yuega3305352018-01-09 11:02:47 -0800653 @VisibleForTesting
654 void onNewIntent(Intent intent, boolean isRecreating) {
linyuhc3968e62017-11-20 17:40:50 -0800655 this.isRecreating = isRecreating;
656
657 // We're being re-launched with a new Intent. Since it's possible for a single InCallActivity
658 // instance to persist indefinitely (even if we finish() ourselves), this sequence can
659 // happen any time the InCallActivity needs to be displayed.
660
661 // Stash away the new intent so that we can get it in the future by calling getIntent().
662 // Otherwise getIntent() will return the original Intent from when we first got created.
663 setIntent(intent);
664
665 // Activities are always paused before receiving a new intent, so we can count on our onResume()
666 // method being called next.
667
668 // Just like in onCreate(), handle the intent.
669 // Skip if InCallActivity is going to be recreated since this will be called in onCreate().
670 if (!isRecreating) {
671 internalResolveIntent(intent);
Eric Erfanianccca3152017-02-22 16:32:36 -0800672 }
673 }
674
675 @Override
676 public void onBackPressed() {
linyuh57b093b2017-11-17 14:32:32 -0800677 LogUtil.enterBlock("InCallActivity.onBackPressed");
678
linyuhc3968e62017-11-20 17:40:50 -0800679 if (!isVisible) {
linyuh57b093b2017-11-17 14:32:32 -0800680 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800681 }
linyuh57b093b2017-11-17 14:32:32 -0800682
683 if (!getCallCardFragmentVisible()) {
684 return;
685 }
686
687 DialpadFragment dialpadFragment = getDialpadFragment();
688 if (dialpadFragment != null && dialpadFragment.isVisible()) {
689 showDialpadFragment(false /* show */, true /* animate */);
690 return;
691 }
692
693 if (CallList.getInstance().getIncomingCall() != null) {
694 LogUtil.i(
695 "InCallActivity.onBackPressed",
696 "Ignore the press of the back key when an incoming call is ringing");
697 return;
698 }
699
700 // Nothing special to do. Fall back to the default behavior.
701 super.onBackPressed();
Eric Erfanianccca3152017-02-22 16:32:36 -0800702 }
703
704 @Override
705 public boolean onOptionsItemSelected(MenuItem item) {
706 LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item);
707 if (item.getItemId() == android.R.id.home) {
708 onBackPressed();
709 return true;
710 }
711 return super.onOptionsItemSelected(item);
712 }
713
714 @Override
715 public boolean onKeyUp(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800716 DialpadFragment dialpadFragment = getDialpadFragment();
717 if (dialpadFragment != null
718 && dialpadFragment.isVisible()
719 && dialpadFragment.onDialerKeyUp(event)) {
720 return true;
721 }
722
723 if (keyCode == KeyEvent.KEYCODE_CALL) {
724 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
725 return true;
726 }
727
728 return super.onKeyUp(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800729 }
730
731 @Override
732 public boolean onKeyDown(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800733 switch (keyCode) {
734 case KeyEvent.KEYCODE_CALL:
735 if (!InCallPresenter.getInstance().handleCallKey()) {
736 LogUtil.e(
737 "InCallActivity.onKeyDown",
738 "InCallPresenter should always handle KEYCODE_CALL in onKeyDown");
739 }
740 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
741 return true;
742
743 // Note that KEYCODE_ENDCALL isn't handled here as the standard system-wide handling of it
744 // is exactly what's needed, namely
745 // (1) "hang up" if there's an active call, or
746 // (2) "don't answer" if there's an incoming call.
747 // (See PhoneWindowManager for implementation details.)
748
749 case KeyEvent.KEYCODE_CAMERA:
750 // Consume KEYCODE_CAMERA since it's easy to accidentally press the camera button.
751 return true;
752
753 case KeyEvent.KEYCODE_VOLUME_UP:
754 case KeyEvent.KEYCODE_VOLUME_DOWN:
755 case KeyEvent.KEYCODE_VOLUME_MUTE:
756 // Ringer silencing handled by PhoneWindowManager.
757 break;
758
759 case KeyEvent.KEYCODE_MUTE:
760 TelecomAdapter.getInstance()
761 .mute(!AudioModeProvider.getInstance().getAudioState().isMuted());
762 return true;
763
764 case KeyEvent.KEYCODE_SLASH:
765 // When verbose logging is enabled, dump the view for debugging/testing purposes.
766 if (LogUtil.isVerboseEnabled()) {
767 View decorView = getWindow().getDecorView();
768 LogUtil.v("InCallActivity.onKeyDown", "View dump:\n%s", decorView);
769 return true;
770 }
771 break;
772
773 case KeyEvent.KEYCODE_EQUALS:
774 break;
775
776 default: // fall out
777 }
778
779 // Pass other key events to DialpadFragment's "onDialerKeyDown" method in case the user types
780 // in DTMF (Dual-tone multi-frequency signaling) code.
781 DialpadFragment dialpadFragment = getDialpadFragment();
782 if (dialpadFragment != null
783 && dialpadFragment.isVisible()
784 && dialpadFragment.onDialerKeyDown(event)) {
785 return true;
786 }
787
788 return super.onKeyDown(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800789 }
790
791 public boolean isInCallScreenAnimating() {
792 return false;
793 }
794
795 public void showConferenceFragment(boolean show) {
796 if (show) {
797 startActivity(new Intent(this, ManageConferenceActivity.class));
798 }
799 }
800
linyuhc3968e62017-11-20 17:40:50 -0800801 public void showDialpadFragment(boolean show, boolean animate) {
802 if (show == isDialpadVisible()) {
803 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800804 }
linyuhc3968e62017-11-20 17:40:50 -0800805
806 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
807 if (dialpadFragmentManager == null) {
808 LogUtil.i("InCallActivity.showDialpadFragment", "Unable to obtain a FragmentManager");
809 return;
810 }
811
812 if (!animate) {
813 if (show) {
814 showDialpadFragment();
815 } else {
816 hideDialpadFragment();
817 }
818 } else {
819 if (show) {
820 showDialpadFragment();
821 getDialpadFragment().animateShowDialpad();
822 }
823 getDialpadFragment()
824 .getView()
825 .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation);
826 }
827
828 ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor();
829 if (sensor != null) {
830 sensor.onDialpadVisible(show);
831 }
832 showDialpadRequest = DIALPAD_REQUEST_NONE;
833
834 // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB
835 // repositions itself.
wangqifd4c9f72018-03-08 18:21:50 -0800836 getInCallOrRttCallScreen().onInCallScreenDialpadVisibilityChange(show);
linyuhc3968e62017-11-20 17:40:50 -0800837 }
838
839 private void showDialpadFragment() {
840 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
841 if (dialpadFragmentManager == null) {
842 return;
843 }
844
845 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
846 DialpadFragment dialpadFragment = getDialpadFragment();
847 if (dialpadFragment == null) {
wangqifd4c9f72018-03-08 18:21:50 -0800848 dialpadFragment = new DialpadFragment();
849 transaction.add(getDialpadContainerId(), dialpadFragment, Tags.DIALPAD_FRAGMENT);
linyuhc3968e62017-11-20 17:40:50 -0800850 } else {
851 transaction.show(dialpadFragment);
calderwoodrad5883872017-12-12 15:29:12 -0800852 dialpadFragment.setUserVisibleHint(true);
linyuhc3968e62017-11-20 17:40:50 -0800853 }
wangqifd4c9f72018-03-08 18:21:50 -0800854 // RTT call screen doesn't show end call button inside dialpad, thus the space reserved for end
855 // call button should be removed.
856 dialpadFragment.setShouldShowEndCallSpace(didShowInCallScreen);
linyuhc3968e62017-11-20 17:40:50 -0800857 transaction.commitAllowingStateLoss();
858 dialpadFragmentManager.executePendingTransactions();
859
860 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, this);
861 updateNavigationBar(true /* isDialpadVisible */);
862 }
863
864 private void hideDialpadFragment() {
865 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
866 if (dialpadFragmentManager == null) {
867 return;
868 }
869
calderwoodrad5883872017-12-12 15:29:12 -0800870 DialpadFragment dialpadFragment = getDialpadFragment();
linyuhc3968e62017-11-20 17:40:50 -0800871 if (dialpadFragment != null) {
872 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
873 transaction.hide(dialpadFragment);
874 transaction.commitAllowingStateLoss();
875 dialpadFragmentManager.executePendingTransactions();
calderwoodrad5883872017-12-12 15:29:12 -0800876 dialpadFragment.setUserVisibleHint(false);
linyuhc3968e62017-11-20 17:40:50 -0800877 }
878 updateNavigationBar(false /* isDialpadVisible */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800879 }
880
881 public boolean isDialpadVisible() {
linyuh69a25062017-11-15 16:18:51 -0800882 DialpadFragment dialpadFragment = getDialpadFragment();
calderwoodraa584bcd2018-01-24 12:19:56 -0800883 return dialpadFragment != null
884 && dialpadFragment.isAdded()
885 && !dialpadFragment.isHidden()
886 && dialpadFragment.getView() != null
887 && dialpadFragment.getUserVisibleHint();
linyuh69a25062017-11-15 16:18:51 -0800888 }
889
linyuhc3968e62017-11-20 17:40:50 -0800890 /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */
linyuh69a25062017-11-15 16:18:51 -0800891 @Nullable
linyuhc3968e62017-11-20 17:40:50 -0800892 private DialpadFragment getDialpadFragment() {
linyuh69a25062017-11-15 16:18:51 -0800893 FragmentManager fragmentManager = getDialpadFragmentManager();
894 if (fragmentManager == null) {
895 return null;
896 }
linyuhc3968e62017-11-20 17:40:50 -0800897 return (DialpadFragment) fragmentManager.findFragmentByTag(Tags.DIALPAD_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -0800898 }
899
900 public void onForegroundCallChanged(DialerCall newForegroundCall) {
linyuh57b093b2017-11-17 14:32:32 -0800901 updateTaskDescription();
902
903 if (newForegroundCall == null || !didShowAnswerScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800904 LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color");
linyuh57b093b2017-11-17 14:32:32 -0800905 updateWindowBackgroundColor(0 /* progress */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800906 }
907 }
908
linyuhc3968e62017-11-20 17:40:50 -0800909 private void updateTaskDescription() {
linyuh57b093b2017-11-17 14:32:32 -0800910 int color =
911 getResources().getBoolean(R.bool.is_layout_landscape)
912 ? ResourcesCompat.getColor(
913 getResources(), R.color.statusbar_background_color, getTheme())
914 : InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor();
915 setTaskDescription(
916 new TaskDescription(
917 getResources().getString(R.string.notification_ongoing_call), null /* icon */, color));
918 }
919
Eric Erfanianccca3152017-02-22 16:32:36 -0800920 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
921 ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager();
922 @ColorInt int top;
923 @ColorInt int middle;
924 @ColorInt int bottom;
925 @ColorInt int gray = 0x66000000;
926
linyuh437ae952018-03-26 12:46:18 -0700927 if (isInMultiWindowMode()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800928 top = themeColorManager.getBackgroundColorSolid();
929 middle = themeColorManager.getBackgroundColorSolid();
930 bottom = themeColorManager.getBackgroundColorSolid();
931 } else {
932 top = themeColorManager.getBackgroundColorTop();
933 middle = themeColorManager.getBackgroundColorMiddle();
934 bottom = themeColorManager.getBackgroundColorBottom();
935 }
936
937 if (progress < 0) {
938 float correctedProgress = Math.abs(progress);
939 top = ColorUtils.blendARGB(top, gray, correctedProgress);
940 middle = ColorUtils.blendARGB(middle, gray, correctedProgress);
941 bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress);
942 }
943
944 boolean backgroundDirty = false;
945 if (backgroundDrawable == null) {
946 backgroundDrawableColors = new int[] {top, middle, bottom};
947 backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors);
948 backgroundDirty = true;
949 } else {
950 if (backgroundDrawableColors[0] != top) {
951 backgroundDrawableColors[0] = top;
952 backgroundDirty = true;
953 }
954 if (backgroundDrawableColors[1] != middle) {
955 backgroundDrawableColors[1] = middle;
956 backgroundDirty = true;
957 }
958 if (backgroundDrawableColors[2] != bottom) {
959 backgroundDrawableColors[2] = bottom;
960 backgroundDirty = true;
961 }
962 if (backgroundDirty) {
963 backgroundDrawable.setColors(backgroundDrawableColors);
964 }
965 }
966
967 if (backgroundDirty) {
968 getWindow().setBackgroundDrawable(backgroundDrawable);
969 }
970 }
971
972 public boolean isVisible() {
973 return isVisible;
974 }
975
976 public boolean getCallCardFragmentVisible() {
erfaniand05d8992018-03-20 19:42:26 -0700977 return didShowInCallScreen
978 || didShowVideoCallScreen
979 || didShowRttCallScreen
980 || didShowSpeakEasyScreen;
Eric Erfanianccca3152017-02-22 16:32:36 -0800981 }
982
983 public void dismissKeyguard(boolean dismiss) {
linyuh9c327da2017-11-14 12:33:48 -0800984 if (dismissKeyguard == dismiss) {
985 return;
986 }
987
988 dismissKeyguard = dismiss;
989 if (dismiss) {
990 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
991 } else {
992 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
993 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800994 }
995
linyuhc3968e62017-11-20 17:40:50 -0800996 public void showDialogForPostCharWait(String callId, String chars) {
997 if (isVisible) {
998 PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars);
999 fragment.show(getSupportFragmentManager(), Tags.POST_CHAR_DIALOG_FRAGMENT);
1000
1001 showPostCharWaitDialogOnResume = false;
1002 showPostCharWaitDialogCallId = null;
1003 showPostCharWaitDialogChars = null;
1004 } else {
1005 showPostCharWaitDialogOnResume = true;
1006 showPostCharWaitDialogCallId = callId;
1007 showPostCharWaitDialogChars = chars;
1008 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001009 }
1010
linyuh7b86f562017-11-16 11:24:09 -08001011 public void showDialogOrToastForDisconnectedCall(DisconnectMessage disconnectMessage) {
1012 LogUtil.i(
1013 "InCallActivity.showDialogOrToastForDisconnectedCall",
1014 "disconnect cause: %s",
1015 disconnectMessage);
1016
1017 if (disconnectMessage.dialog == null || isFinishing()) {
1018 return;
1019 }
1020
1021 dismissPendingDialogs();
1022
1023 // Show a toast if the app is in background when a dialog can't be visible.
1024 if (!isVisible()) {
1025 Toast.makeText(getApplicationContext(), disconnectMessage.toastMessage, Toast.LENGTH_LONG)
1026 .show();
1027 return;
1028 }
1029
1030 // Show the dialog.
linyuhc3968e62017-11-20 17:40:50 -08001031 errorDialog = disconnectMessage.dialog;
linyuh7b86f562017-11-16 11:24:09 -08001032 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog");
1033 disconnectMessage.dialog.setOnDismissListener(
1034 dialogInterface -> {
1035 lock.release();
1036 onDialogDismissed();
1037 });
1038 disconnectMessage.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
1039 disconnectMessage.dialog.show();
1040 }
1041
1042 private void onDialogDismissed() {
linyuhc3968e62017-11-20 17:40:50 -08001043 errorDialog = null;
linyuh7b86f562017-11-16 11:24:09 -08001044 CallList.getInstance().onErrorDialogDismissed();
Eric Erfanianccca3152017-02-22 16:32:36 -08001045 }
1046
1047 public void dismissPendingDialogs() {
linyuhc3968e62017-11-20 17:40:50 -08001048 LogUtil.enterBlock("InCallActivity.dismissPendingDialogs");
linyuhf99f6302017-11-15 11:23:51 -08001049
1050 if (!isVisible) {
1051 // Defer the dismissing action as the activity is not visible and onSaveInstanceState may have
1052 // been called.
Eric Erfanianccca3152017-02-22 16:32:36 -08001053 LogUtil.i(
1054 "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible");
1055 needDismissPendingDialogs = true;
linyuhf99f6302017-11-15 11:23:51 -08001056 return;
Eric Erfanianccca3152017-02-22 16:32:36 -08001057 }
linyuhf99f6302017-11-15 11:23:51 -08001058
1059 // Dismiss the error dialog
linyuhf99f6302017-11-15 11:23:51 -08001060 if (errorDialog != null) {
1061 errorDialog.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001062 errorDialog = null;
linyuhf99f6302017-11-15 11:23:51 -08001063 }
1064
1065 // Dismiss the phone account selection dialog
linyuhf99f6302017-11-15 11:23:51 -08001066 if (selectPhoneAccountDialogFragment != null) {
1067 selectPhoneAccountDialogFragment.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001068 selectPhoneAccountDialogFragment = null;
linyuhf99f6302017-11-15 11:23:51 -08001069 }
1070
1071 // Dismiss the dialog for international call on WiFi
1072 InternationalCallOnWifiDialogFragment internationalCallOnWifiFragment =
1073 (InternationalCallOnWifiDialogFragment)
linyuhc3968e62017-11-20 17:40:50 -08001074 getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
linyuhf99f6302017-11-15 11:23:51 -08001075 if (internationalCallOnWifiFragment != null) {
1076 internationalCallOnWifiFragment.dismiss();
1077 }
1078
1079 // Dismiss the answer screen
1080 AnswerScreen answerScreen = getAnswerScreen();
1081 if (answerScreen != null) {
1082 answerScreen.dismissPendingDialogs();
1083 }
1084
1085 needDismissPendingDialogs = false;
Eric Erfanianccca3152017-02-22 16:32:36 -08001086 }
1087
linyuhc3968e62017-11-20 17:40:50 -08001088 private void enableInCallOrientationEventListener(boolean enable) {
linyuh69a25062017-11-15 16:18:51 -08001089 if (enable) {
1090 inCallOrientationEventListener.enable(true /* notifyDeviceOrientationChange */);
1091 } else {
1092 inCallOrientationEventListener.disable();
1093 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001094 }
1095
1096 public void setExcludeFromRecents(boolean exclude) {
linyuhc3968e62017-11-20 17:40:50 -08001097 int taskId = getTaskId();
1098
1099 List<AppTask> tasks = getSystemService(ActivityManager.class).getAppTasks();
1100 for (AppTask task : tasks) {
1101 try {
1102 if (task.getTaskInfo().id == taskId) {
1103 task.setExcludeFromRecents(exclude);
1104 }
1105 } catch (RuntimeException e) {
1106 LogUtil.e("InCallActivity.setExcludeFromRecents", "RuntimeException:\n%s", e);
1107 }
1108 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001109 }
1110
Eric Erfanianccca3152017-02-22 16:32:36 -08001111 @Nullable
1112 public FragmentManager getDialpadFragmentManager() {
wangqifd4c9f72018-03-08 18:21:50 -08001113 InCallScreen inCallScreen = getInCallOrRttCallScreen();
Eric Erfanianccca3152017-02-22 16:32:36 -08001114 if (inCallScreen != null) {
1115 return inCallScreen.getInCallScreenFragment().getChildFragmentManager();
1116 }
1117 return null;
1118 }
1119
1120 public int getDialpadContainerId() {
wangqifd4c9f72018-03-08 18:21:50 -08001121 return getInCallOrRttCallScreen().getAnswerAndDialpadContainerResourceId();
Eric Erfanianccca3152017-02-22 16:32:36 -08001122 }
1123
1124 @Override
1125 public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) {
1126 DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId());
1127 if (call == null) {
1128 // This is a work around for a bug where we attempt to create a new delegate after the call
1129 // has already been removed. An example of when this can happen is:
1130 // 1. incoming video call in landscape mode
1131 // 2. remote party hangs up
1132 // 3. activity switches from landscape to portrait
1133 // At step #3 the answer fragment will try to create a new answer delegate but the call won't
1134 // exist. In this case we'll simply return a stub delegate that does nothing. This is ok
1135 // because this new state is transient and the activity will be destroyed soon.
1136 LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub");
1137 return new AnswerScreenPresenterStub();
1138 } else {
1139 return new AnswerScreenPresenter(
1140 this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId()));
1141 }
1142 }
1143
1144 @Override
1145 public InCallScreenDelegate newInCallScreenDelegate() {
1146 return new CallCardPresenter(this);
1147 }
1148
1149 @Override
1150 public InCallButtonUiDelegate newInCallButtonUiDelegate() {
1151 return new CallButtonPresenter(this);
1152 }
1153
1154 @Override
Eric Erfanian90508232017-03-24 09:31:16 -07001155 public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) {
1156 DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId());
1157 if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) {
1158 return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen);
1159 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001160 return new VideoCallPresenter();
1161 }
1162
1163 public void onPrimaryCallStateChanged() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001164 Trace.beginSection("InCallActivity.onPrimaryCallStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -08001165 showMainInCallFragment();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001166 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001167 }
1168
linyuh7b86f562017-11-16 11:24:09 -08001169 public void showToastForWiFiToLteHandover(DialerCall call) {
1170 if (call.hasShownWiFiToLteHandoverToast()) {
1171 return;
1172 }
1173
1174 Toast.makeText(this, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG).show();
1175 call.setHasShownWiFiToLteHandoverToast();
Eric Erfanianccca3152017-02-22 16:32:36 -08001176 }
1177
linyuh7b86f562017-11-16 11:24:09 -08001178 public void showDialogOrToastForWifiHandoverFailure(DialerCall call) {
1179 if (call.showWifiHandoverAlertAsToast()) {
1180 Toast.makeText(this, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT)
1181 .show();
1182 return;
1183 }
1184
1185 dismissPendingDialogs();
1186
1187 AlertDialog.Builder builder =
1188 new AlertDialog.Builder(this).setTitle(R.string.video_call_lte_to_wifi_failed_title);
1189
1190 // This allows us to use the theme of the dialog instead of the activity
1191 View dialogCheckBoxView =
1192 View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null /* root */);
1193 CheckBox wifiHandoverFailureCheckbox =
1194 (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox);
1195 wifiHandoverFailureCheckbox.setChecked(false);
1196
1197 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog");
linyuhc3968e62017-11-20 17:40:50 -08001198 errorDialog =
linyuh7b86f562017-11-16 11:24:09 -08001199 builder
1200 .setView(dialogCheckBoxView)
1201 .setMessage(R.string.video_call_lte_to_wifi_failed_message)
1202 .setOnCancelListener(dialogInterface -> onDialogDismissed())
1203 .setPositiveButton(
1204 android.R.string.ok,
1205 (dialogInterface, id) -> {
1206 call.setDoNotShowDialogForHandoffToWifiFailure(
1207 wifiHandoverFailureCheckbox.isChecked());
1208 dialogInterface.cancel();
1209 onDialogDismissed();
1210 })
1211 .setOnDismissListener(dialogInterface -> lock.release())
1212 .create();
linyuh7b86f562017-11-16 11:24:09 -08001213 errorDialog.show();
Eric Erfanianccca3152017-02-22 16:32:36 -08001214 }
1215
linyuh7b86f562017-11-16 11:24:09 -08001216 public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) {
1217 if (!InternationalCallOnWifiDialogFragment.shouldShow(this)) {
1218 LogUtil.i(
1219 "InCallActivity.showDialogForInternationalCallOnWifi",
1220 "InternationalCallOnWifiDialogFragment.shouldShow returned false");
1221 return;
1222 }
1223
1224 InternationalCallOnWifiDialogFragment fragment =
1225 InternationalCallOnWifiDialogFragment.newInstance(
linyuhc3968e62017-11-20 17:40:50 -08001226 call.getId(), internationalCallOnWifiCallback);
1227 fragment.show(getSupportFragmentManager(), Tags.INTERNATIONAL_CALL_ON_WIFI);
Eric Erfanianc857f902017-05-15 14:05:33 -07001228 }
1229
Eric Erfanian938468d2017-10-24 14:05:52 -07001230 @Override
1231 public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
1232 super.onMultiWindowModeChanged(isInMultiWindowMode);
linyuh57b093b2017-11-17 14:32:32 -08001233 updateNavigationBar(isDialpadVisible());
1234 }
1235
linyuhc3968e62017-11-20 17:40:50 -08001236 private void updateNavigationBar(boolean isDialpadVisible) {
linyuh437ae952018-03-26 12:46:18 -07001237 if (isInMultiWindowMode()) {
linyuh57b093b2017-11-17 14:32:32 -08001238 return;
1239 }
1240
1241 View navigationBarBackground = getWindow().findViewById(R.id.navigation_bar_background);
1242 if (navigationBarBackground != null) {
1243 navigationBarBackground.setVisibility(isDialpadVisible ? View.VISIBLE : View.GONE);
Eric Erfanian938468d2017-10-24 14:05:52 -07001244 }
1245 }
1246
Eric Erfanianccca3152017-02-22 16:32:36 -08001247 public void setAllowOrientationChange(boolean allowOrientationChange) {
wangqi9982f0d2017-10-11 17:46:07 -07001248 if (this.allowOrientationChange == allowOrientationChange) {
1249 return;
1250 }
1251 this.allowOrientationChange = allowOrientationChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001252 if (!allowOrientationChange) {
1253 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_DISALLOW_ROTATION);
1254 } else {
1255 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
1256 }
1257 enableInCallOrientationEventListener(allowOrientationChange);
1258 }
1259
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001260 public void hideMainInCallFragment() {
linyuhc3968e62017-11-20 17:40:50 -08001261 LogUtil.enterBlock("InCallActivity.hideMainInCallFragment");
1262 if (getCallCardFragmentVisible()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001263 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1264 hideInCallScreenFragment(transaction);
1265 hideVideoCallScreenFragment(transaction);
1266 transaction.commitAllowingStateLoss();
1267 getSupportFragmentManager().executePendingTransactions();
1268 }
1269 }
1270
1271 private void showMainInCallFragment() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001272 Trace.beginSection("InCallActivity.showMainInCallFragment");
Eric Erfanianccca3152017-02-22 16:32:36 -08001273 // If the activity's onStart method hasn't been called yet then defer doing any work.
1274 if (!isVisible) {
1275 LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001276 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001277 return;
1278 }
1279
1280 // Don't let this be reentrant.
1281 if (isInShowMainInCallFragment) {
1282 LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001283 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001284 return;
1285 }
1286
1287 isInShowMainInCallFragment = true;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001288 ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi();
1289 ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi();
wangqi219b8702018-02-13 09:34:41 -08001290 ShouldShowUiResult shouldShowRttUi = getShouldShowRttUi();
erfaniand05d8992018-03-20 19:42:26 -07001291 ShouldShowUiResult shouldShowSpeakEasyUi = getShouldShowSpeakEasyUi();
Eric Erfanianccca3152017-02-22 16:32:36 -08001292 LogUtil.i(
1293 "InCallActivity.showMainInCallFragment",
wangqi219b8702018-02-13 09:34:41 -08001294 "shouldShowAnswerUi: %b, shouldShowRttUi: %b, shouldShowVideoUi: %b "
1295 + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowRttCallScreen: %b, "
erfaniand05d8992018-03-20 19:42:26 -07001296 + "didShowVideoCallScreen: %b"
1297 + "didShowSpeakEasyScreen: %b",
Eric Erfanianccca3152017-02-22 16:32:36 -08001298 shouldShowAnswerUi.shouldShow,
wangqi219b8702018-02-13 09:34:41 -08001299 shouldShowRttUi.shouldShow,
Eric Erfanian10b34a52017-05-04 08:23:17 -07001300 shouldShowVideoUi.shouldShow,
Eric Erfanianccca3152017-02-22 16:32:36 -08001301 didShowAnswerScreen,
1302 didShowInCallScreen,
wangqi219b8702018-02-13 09:34:41 -08001303 didShowRttCallScreen,
erfaniand05d8992018-03-20 19:42:26 -07001304 didShowVideoCallScreen,
1305 didShowSpeakEasyScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -08001306 // Only video call ui allows orientation change.
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001307 setAllowOrientationChange(shouldShowVideoUi.shouldShow);
Eric Erfanianccca3152017-02-22 16:32:36 -08001308
1309 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
wangqi219b8702018-02-13 09:34:41 -08001310 boolean didChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001311 if (shouldShowAnswerUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001312 didChange = hideInCallScreenFragment(transaction);
1313 didChange |= hideVideoCallScreenFragment(transaction);
1314 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001315 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001316 didChange |= showAnswerScreenFragment(transaction, shouldShowAnswerUi.call);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001317 } else if (shouldShowVideoUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001318 didChange = hideInCallScreenFragment(transaction);
1319 didChange |= showVideoCallScreenFragment(transaction, shouldShowVideoUi.call);
1320 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001321 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001322 didChange |= hideAnswerScreenFragment(transaction);
1323 } else if (shouldShowRttUi.shouldShow) {
1324 didChange = hideInCallScreenFragment(transaction);
1325 didChange |= hideVideoCallScreenFragment(transaction);
1326 didChange |= hideAnswerScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001327 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001328 didChange |= showRttCallScreenFragment(transaction, shouldShowRttUi.call);
erfaniand05d8992018-03-20 19:42:26 -07001329 } else if (shouldShowSpeakEasyUi.shouldShow) {
1330 didChange = hideInCallScreenFragment(transaction);
1331 didChange |= hideVideoCallScreenFragment(transaction);
1332 didChange |= hideAnswerScreenFragment(transaction);
1333 didChange |= hideRttCallScreenFragment(transaction);
1334 didChange |= showSpeakEasyFragment(transaction, shouldShowSpeakEasyUi.call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001335 } else {
wangqi219b8702018-02-13 09:34:41 -08001336 didChange = showInCallScreenFragment(transaction);
1337 didChange |= hideVideoCallScreenFragment(transaction);
1338 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001339 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001340 didChange |= hideAnswerScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001341 }
1342
wangqi219b8702018-02-13 09:34:41 -08001343 if (didChange) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001344 Trace.beginSection("InCallActivity.commitTransaction");
Eric Erfanianccca3152017-02-22 16:32:36 -08001345 transaction.commitNow();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001346 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001347 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1348 }
1349 isInShowMainInCallFragment = false;
Eric Erfanian2ca43182017-08-31 06:57:16 -07001350 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001351 }
1352
erfaniand05d8992018-03-20 19:42:26 -07001353 private boolean showSpeakEasyFragment(FragmentTransaction transaction, DialerCall call) {
1354
1355 // TODO(erfanian): Support multiple speakeasy screens.
1356 if (didShowSpeakEasyScreen) {
1357 return false;
1358 }
1359
1360 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1361 if (speakEasyFragment.isPresent()) {
1362 transaction.add(R.id.main, speakEasyFragment.get(), Tags.SPEAK_EASY_SCREEN);
1363 didShowSpeakEasyScreen = true;
1364 return true;
1365 }
1366 return false;
1367 }
1368
1369 private Fragment getSpeakEasyScreen() {
1370 return getSupportFragmentManager().findFragmentByTag(Tags.SPEAK_EASY_SCREEN);
1371 }
1372
1373 private boolean hideSpeakEasyFragment(FragmentTransaction transaction) {
1374 if (!didShowSpeakEasyScreen) {
1375 return false;
1376 }
1377
1378 Fragment speakEasyFragment = getSpeakEasyScreen();
1379
1380 if (speakEasyFragment != null) {
1381 transaction.remove(speakEasyFragment);
1382 didShowSpeakEasyScreen = false;
1383 return true;
1384 }
1385 return false;
1386 }
1387
1388 public void setSpeakEasyCallManager(SpeakEasyCallManager speakEasyCallManager) {
1389 this.speakEasyCallManager = Assert.isNotNull(speakEasyCallManager);
1390 }
1391
1392 public SpeakEasyCallManager getSpeakEasyCallManager() {
1393 return speakEasyCallManager;
1394 }
1395
1396 private ShouldShowUiResult getShouldShowSpeakEasyUi() {
1397 SpeakEasyCallManager speakEasyCallManager = getSpeakEasyCallManager();
1398
1399 if (speakEasyCallManager == null) {
1400 return new ShouldShowUiResult(false, null);
1401 }
1402
1403 // TODO(erfanian): Get a better call?
1404 DialerCall call = CallList.getInstance().getActiveCall();
1405
1406 if (call == null) {
1407 return new ShouldShowUiResult(false, call);
1408 }
1409
1410 if (!call.isSpeakEasyCall() || !call.isSpeakEasyEligible()) {
1411 return new ShouldShowUiResult(false, call);
1412 }
1413
1414 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1415
1416 if (!speakEasyFragment.isPresent()) {
1417 return new ShouldShowUiResult(false, call);
1418 }
1419 return new ShouldShowUiResult(true, call);
1420 }
1421
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001422 private ShouldShowUiResult getShouldShowAnswerUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001423 DialerCall call = CallList.getInstance().getIncomingCall();
1424 if (call != null) {
1425 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001426 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001427 }
1428
1429 call = CallList.getInstance().getVideoUpgradeRequestCall();
1430 if (call != null) {
1431 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001432 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001433 }
1434
1435 // Check if we're showing the answer screen and the call is disconnected. If this condition is
1436 // true then we won't switch from the answer UI to the in call UI. This prevents flicker when
1437 // the user rejects an incoming call.
1438 call = CallList.getInstance().getFirstCall();
1439 if (call == null) {
1440 call = CallList.getInstance().getBackgroundCall();
1441 }
1442 if (didShowAnswerScreen && (call == null || call.getState() == State.DISCONNECTED)) {
1443 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001444 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001445 }
1446
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001447 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001448 }
1449
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001450 private static ShouldShowUiResult getShouldShowVideoUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001451 DialerCall call = CallList.getInstance().getFirstCall();
1452 if (call == null) {
1453 LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001454 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001455 }
1456
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001457 if (call.isVideoCall()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001458 LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001459 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001460 }
1461
linyuh8fbecce2017-12-18 13:53:09 -08001462 if (call.hasSentVideoUpgradeRequest() || call.hasReceivedVideoUpgradeRequest()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001463 LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001464 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001465 }
1466
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001467 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001468 }
1469
wangqi219b8702018-02-13 09:34:41 -08001470 private static ShouldShowUiResult getShouldShowRttUi() {
1471 DialerCall call = CallList.getInstance().getFirstCall();
1472 if (call == null) {
1473 LogUtil.i("InCallActivity.getShouldShowRttUi", "null call");
1474 return new ShouldShowUiResult(false, null);
1475 }
1476
1477 if (call.isRttCall()) {
1478 LogUtil.i("InCallActivity.getShouldShowRttUi", "found rtt call");
1479 return new ShouldShowUiResult(true, call);
1480 }
1481
1482 if (call.hasSentRttUpgradeRequest()) {
1483 LogUtil.i("InCallActivity.getShouldShowRttUi", "upgrading to rtt");
1484 return new ShouldShowUiResult(true, call);
1485 }
1486
1487 return new ShouldShowUiResult(false, null);
1488 }
1489
Eric Erfanianccca3152017-02-22 16:32:36 -08001490 private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) {
1491 // When rejecting a call the active call can become null in which case we should continue
1492 // showing the answer screen.
1493 if (didShowAnswerScreen && call == null) {
1494 return false;
1495 }
1496
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001497 Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null");
1498
1499 boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -08001500
1501 // Check if we're already showing an answer screen for this call.
1502 if (didShowAnswerScreen) {
1503 AnswerScreen answerScreen = getAnswerScreen();
1504 if (answerScreen.getCallId().equals(call.getId())
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001505 && answerScreen.isVideoCall() == call.isVideoCall()
Eric Erfanian2ca43182017-08-31 06:57:16 -07001506 && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest
1507 && !answerScreen.isActionTimeout()) {
1508 LogUtil.d(
1509 "InCallActivity.showAnswerScreenFragment",
1510 "answer fragment exists for same call and has NOT been accepted/rejected/timed out");
Eric Erfanianccca3152017-02-22 16:32:36 -08001511 return false;
1512 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001513 if (answerScreen.isActionTimeout()) {
1514 LogUtil.i(
1515 "InCallActivity.showAnswerScreenFragment",
1516 "answer fragment exists but has been accepted/rejected and timed out");
1517 } else {
1518 LogUtil.i(
1519 "InCallActivity.showAnswerScreenFragment",
1520 "answer fragment exists but arguments do not match");
1521 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001522 hideAnswerScreenFragment(transaction);
1523 }
1524
1525 // Show a new answer screen.
1526 AnswerScreen answerScreen =
Eric Erfanianfc37b022017-03-21 10:11:17 -07001527 AnswerBindings.createAnswerScreen(
1528 call.getId(),
wangqi219b8702018-02-13 09:34:41 -08001529 call.isRttCall(),
Eric Erfanianfc37b022017-03-21 10:11:17 -07001530 call.isVideoCall(),
1531 isVideoUpgradeRequest,
Eric Erfanian90508232017-03-24 09:31:16 -07001532 call.getVideoTech().isSelfManagedCamera(),
1533 shouldAllowAnswerAndRelease(call),
erfaniand05d8992018-03-20 19:42:26 -07001534 CallList.getInstance().getBackgroundCall() != null,
1535 call.isSpeakEasyEligible());
linyuhc3968e62017-11-20 17:40:50 -08001536 transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001537
1538 Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this);
1539 didShowAnswerScreen = true;
1540 return true;
1541 }
1542
Eric Erfanian90508232017-03-24 09:31:16 -07001543 private boolean shouldAllowAnswerAndRelease(DialerCall call) {
1544 if (CallList.getInstance().getActiveCall() == null) {
1545 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call");
1546 return false;
1547 }
1548 if (getSystemService(TelephonyManager.class).getPhoneType()
1549 == TelephonyManager.PHONE_TYPE_CDMA) {
1550 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported");
1551 return false;
1552 }
1553 if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) {
1554 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call");
1555 return false;
1556 }
linyuhc3968e62017-11-20 17:40:50 -08001557 if (!ConfigProviderBindings.get(this)
1558 .getBoolean(ConfigNames.ANSWER_AND_RELEASE_ENABLED, true)) {
Eric Erfanian90508232017-03-24 09:31:16 -07001559 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config");
1560 return false;
1561 }
1562
1563 return true;
1564 }
1565
Eric Erfanianccca3152017-02-22 16:32:36 -08001566 private boolean hideAnswerScreenFragment(FragmentTransaction transaction) {
1567 if (!didShowAnswerScreen) {
1568 return false;
1569 }
1570 AnswerScreen answerScreen = getAnswerScreen();
1571 if (answerScreen != null) {
1572 transaction.remove(answerScreen.getAnswerScreenFragment());
1573 }
1574
1575 didShowAnswerScreen = false;
1576 return true;
1577 }
1578
1579 private boolean showInCallScreenFragment(FragmentTransaction transaction) {
1580 if (didShowInCallScreen) {
1581 return false;
1582 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001583 InCallScreen inCallScreen = InCallBindings.createInCallScreen();
linyuhc3968e62017-11-20 17:40:50 -08001584 transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001585 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1586 didShowInCallScreen = true;
1587 return true;
1588 }
1589
1590 private boolean hideInCallScreenFragment(FragmentTransaction transaction) {
1591 if (!didShowInCallScreen) {
1592 return false;
1593 }
1594 InCallScreen inCallScreen = getInCallScreen();
1595 if (inCallScreen != null) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001596 transaction.remove(inCallScreen.getInCallScreenFragment());
Eric Erfanianccca3152017-02-22 16:32:36 -08001597 }
1598 didShowInCallScreen = false;
1599 return true;
1600 }
1601
wangqi219b8702018-02-13 09:34:41 -08001602 private boolean showRttCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
1603 if (didShowRttCallScreen) {
1604 // This shouldn't happen since only one RTT call is allow at same time.
1605 if (!getRttCallScreen().getCallId().equals(call.getId())) {
1606 LogUtil.e("InCallActivity.showRttCallScreenFragment", "RTT call id doesn't match");
1607 }
1608 return false;
1609 }
1610 RttCallScreen rttCallScreen = RttBindings.createRttCallScreen(call.getId());
1611 transaction.add(R.id.main, rttCallScreen.getRttCallScreenFragment(), Tags.RTT_CALL_SCREEN);
1612 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1613 didShowRttCallScreen = true;
1614 return true;
1615 }
1616
1617 private boolean hideRttCallScreenFragment(FragmentTransaction transaction) {
1618 if (!didShowRttCallScreen) {
1619 return false;
1620 }
1621 RttCallScreen rttCallScreen = getRttCallScreen();
1622 if (rttCallScreen != null) {
1623 transaction.remove(rttCallScreen.getRttCallScreenFragment());
1624 }
1625 didShowRttCallScreen = false;
1626 return true;
1627 }
1628
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001629 private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001630 if (didShowVideoCallScreen) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001631 VideoCallScreen videoCallScreen = getVideoCallScreen();
1632 if (videoCallScreen.getCallId().equals(call.getId())) {
1633 return false;
1634 }
1635 LogUtil.i(
1636 "InCallActivity.showVideoCallScreenFragment",
1637 "video call fragment exists but arguments do not match");
1638 hideVideoCallScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001639 }
1640
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001641 LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call);
1642
Eric Erfanian90508232017-03-24 09:31:16 -07001643 VideoCallScreen videoCallScreen =
1644 VideoBindings.createVideoCallScreen(
1645 call.getId(), call.getVideoTech().shouldUseSurfaceView());
linyuhc3968e62017-11-20 17:40:50 -08001646 transaction.add(
1647 R.id.main, videoCallScreen.getVideoCallScreenFragment(), Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001648
1649 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1650 didShowVideoCallScreen = true;
1651 return true;
1652 }
1653
1654 private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) {
1655 if (!didShowVideoCallScreen) {
1656 return false;
1657 }
1658 VideoCallScreen videoCallScreen = getVideoCallScreen();
1659 if (videoCallScreen != null) {
1660 transaction.remove(videoCallScreen.getVideoCallScreenFragment());
1661 }
1662 didShowVideoCallScreen = false;
1663 return true;
1664 }
1665
linyuhc3968e62017-11-20 17:40:50 -08001666 private AnswerScreen getAnswerScreen() {
1667 return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001668 }
1669
linyuhc3968e62017-11-20 17:40:50 -08001670 private InCallScreen getInCallScreen() {
1671 return (InCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001672 }
1673
linyuhc3968e62017-11-20 17:40:50 -08001674 private VideoCallScreen getVideoCallScreen() {
1675 return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001676 }
1677
wangqi219b8702018-02-13 09:34:41 -08001678 private RttCallScreen getRttCallScreen() {
1679 return (RttCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.RTT_CALL_SCREEN);
1680 }
1681
wangqifd4c9f72018-03-08 18:21:50 -08001682 private InCallScreen getInCallOrRttCallScreen() {
1683 InCallScreen inCallScreen = null;
1684 if (didShowInCallScreen) {
1685 inCallScreen = getInCallScreen();
1686 }
1687 if (didShowRttCallScreen) {
1688 inCallScreen = getRttCallScreen();
1689 }
1690 return inCallScreen;
1691 }
1692
Eric Erfanianccca3152017-02-22 16:32:36 -08001693 @Override
1694 public void onPseudoScreenStateChanged(boolean isOn) {
1695 LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn);
1696 pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE);
1697 }
1698
1699 /**
1700 * For some touch related issue, turning off the screen can be faked by drawing a black view over
1701 * the activity. All touch events started when the screen is "off" is rejected.
1702 *
1703 * @see PseudoScreenState
1704 */
1705 @Override
1706 public boolean dispatchTouchEvent(MotionEvent event) {
1707 // Reject any gesture that started when the screen is in the fake off state.
1708 if (touchDownWhenPseudoScreenOff) {
1709 if (event.getAction() == MotionEvent.ACTION_UP) {
1710 touchDownWhenPseudoScreenOff = false;
1711 }
1712 return true;
1713 }
1714 // Reject all touch event when the screen is in the fake off state.
1715 if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) {
1716 if (event.getAction() == MotionEvent.ACTION_DOWN) {
1717 touchDownWhenPseudoScreenOff = true;
1718 LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff");
1719 }
1720 return true;
1721 }
1722 return super.dispatchTouchEvent(event);
1723 }
1724
wangqi219b8702018-02-13 09:34:41 -08001725 @Override
1726 public RttCallScreenDelegate newRttCallScreenDelegate(RttCallScreen videoCallScreen) {
1727 return new RttCallPresenter();
1728 }
1729
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001730 private static class ShouldShowUiResult {
Eric Erfanianccca3152017-02-22 16:32:36 -08001731 public final boolean shouldShow;
1732 public final DialerCall call;
1733
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001734 ShouldShowUiResult(boolean shouldShow, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001735 this.shouldShow = shouldShow;
1736 this.call = call;
1737 }
1738 }
linyuhc3968e62017-11-20 17:40:50 -08001739
1740 private static final class IntentExtraNames {
1741 static final String FOR_FULL_SCREEN = "InCallActivity.for_full_screen_intent";
1742 static final String NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call";
1743 static final String SHOW_DIALPAD = "InCallActivity.show_dialpad";
1744 }
1745
1746 private static final class KeysForSavedInstance {
1747 static final String DIALPAD_TEXT = "InCallActivity.dialpad_text";
1748 static final String DID_SHOW_ANSWER_SCREEN = "did_show_answer_screen";
1749 static final String DID_SHOW_IN_CALL_SCREEN = "did_show_in_call_screen";
1750 static final String DID_SHOW_VIDEO_CALL_SCREEN = "did_show_video_call_screen";
wangqi153af2f2018-02-15 16:21:49 -08001751 static final String DID_SHOW_RTT_CALL_SCREEN = "did_show_rtt_call_screen";
erfaniand05d8992018-03-20 19:42:26 -07001752 static final String DID_SHOW_SPEAK_EASY_SCREEN = "did_show_speak_easy_screen";
linyuhc3968e62017-11-20 17:40:50 -08001753 }
1754
1755 /** Request codes for pending intents. */
1756 public static final class PendingIntentRequestCodes {
1757 static final int NON_FULL_SCREEN = 0;
1758 static final int FULL_SCREEN = 1;
1759 static final int BUBBLE = 2;
1760 }
1761
1762 private static final class Tags {
1763 static final String ANSWER_SCREEN = "tag_answer_screen";
1764 static final String DIALPAD_FRAGMENT = "tag_dialpad_fragment";
1765 static final String IN_CALL_SCREEN = "tag_in_call_screen";
1766 static final String INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi";
1767 static final String SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment";
1768 static final String VIDEO_CALL_SCREEN = "tag_video_call_screen";
wangqi219b8702018-02-13 09:34:41 -08001769 static final String RTT_CALL_SCREEN = "tag_rtt_call_screen";
linyuhc3968e62017-11-20 17:40:50 -08001770 static final String POST_CHAR_DIALOG_FRAGMENT = "tag_post_char_dialog_fragment";
erfaniand05d8992018-03-20 19:42:26 -07001771 static final String SPEAK_EASY_SCREEN = "tag_speak_easy_screen";
linyuhc3968e62017-11-20 17:40:50 -08001772 }
1773
1774 private static final class ConfigNames {
1775 static final String ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled";
1776 }
1777
1778 private static final class InternationalCallOnWifiCallback
1779 implements InternationalCallOnWifiDialogFragment.Callback {
1780 private static final String TAG = InternationalCallOnWifiCallback.class.getCanonicalName();
1781
1782 @Override
1783 public void continueCall(@NonNull String callId) {
1784 LogUtil.i(TAG, "Continuing call with ID: %s", callId);
1785 }
1786
1787 @Override
1788 public void cancelCall(@NonNull String callId) {
1789 DialerCall call = CallList.getInstance().getCallById(callId);
1790 if (call == null) {
1791 LogUtil.i(TAG, "Call destroyed before the dialog is closed");
1792 return;
1793 }
1794
1795 LogUtil.i(TAG, "Disconnecting international call on WiFi");
1796 call.disconnect();
1797 }
1798 }
1799
1800 private static final class SelectPhoneAccountListener
1801 extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener {
1802 private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName();
1803
twyen73a74c32018-03-07 12:12:24 -08001804 private final Context appContext;
1805
1806 SelectPhoneAccountListener(Context appContext) {
1807 this.appContext = appContext;
1808 }
1809
linyuhc3968e62017-11-20 17:40:50 -08001810 @Override
1811 public void onPhoneAccountSelected(
1812 PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) {
1813 DialerCall call = CallList.getInstance().getCallById(callId);
1814 LogUtil.i(TAG, "Phone account select with call:\n%s", call);
1815
1816 if (call != null) {
twyen73a74c32018-03-07 12:12:24 -08001817 call.phoneAccountSelected(selectedAccountHandle, false);
1818 if (call.getPreferredAccountRecorder() != null) {
1819 call.getPreferredAccountRecorder().record(appContext, selectedAccountHandle, setDefault);
1820 }
linyuhc3968e62017-11-20 17:40:50 -08001821 }
1822 }
1823
1824 @Override
1825 public void onDialogDismissed(String callId) {
1826 DialerCall call = CallList.getInstance().getCallById(callId);
1827 LogUtil.i(TAG, "Disconnecting call:\n%s" + call);
1828
1829 if (call != null) {
1830 call.disconnect();
1831 }
1832 }
1833 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001834}