blob: be365096a2258353642fac15c94e24766ecf35e8 [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;
Eric Erfanianccca3152017-02-22 16:32:36 -080063import com.android.dialer.compat.ActivityCompat;
linyuhc3968e62017-11-20 17:40:50 -080064import com.android.dialer.compat.CompatUtils;
Eric Erfanian2ca43182017-08-31 06:57:16 -070065import com.android.dialer.configprovider.ConfigProviderBindings;
twyen73a74c32018-03-07 12:12:24 -080066import com.android.dialer.logging.DialerImpression.Type;
Eric Erfanianccca3152017-02-22 16:32:36 -080067import com.android.dialer.logging.Logger;
Eric Erfanian8369df02017-05-03 10:27:13 -070068import com.android.dialer.logging.ScreenEvent;
zachh7a96dc72018-02-20 22:16:03 -080069import com.android.dialer.metrics.Metrics;
70import com.android.dialer.metrics.MetricsComponent;
twyen73a74c32018-03-07 12:12:24 -080071import com.android.dialer.preferredsim.PreferredAccountRecorder;
72import com.android.dialer.preferredsim.PreferredAccountWorker;
73import com.android.dialer.preferredsim.suggestion.SuggestionProvider;
linyuhc3968e62017-11-20 17:40:50 -080074import com.android.dialer.util.ViewUtil;
Eric Erfanianccca3152017-02-22 16:32:36 -080075import com.android.incallui.answer.bindings.AnswerBindings;
76import com.android.incallui.answer.protocol.AnswerScreen;
77import com.android.incallui.answer.protocol.AnswerScreenDelegate;
78import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory;
79import com.android.incallui.answerproximitysensor.PseudoScreenState;
linyuh57b093b2017-11-17 14:32:32 -080080import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080081import com.android.incallui.call.CallList;
82import com.android.incallui.call.DialerCall;
83import com.android.incallui.call.DialerCall.State;
linyuh57b093b2017-11-17 14:32:32 -080084import com.android.incallui.call.TelecomAdapter;
Eric Erfanian2ca43182017-08-31 06:57:16 -070085import com.android.incallui.callpending.CallPendingActivity;
86import com.android.incallui.disconnectdialog.DisconnectMessage;
Eric Erfanianccca3152017-02-22 16:32:36 -080087import com.android.incallui.incall.bindings.InCallBindings;
88import com.android.incallui.incall.protocol.InCallButtonUiDelegate;
89import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory;
90import com.android.incallui.incall.protocol.InCallScreen;
91import com.android.incallui.incall.protocol.InCallScreenDelegate;
92import com.android.incallui.incall.protocol.InCallScreenDelegateFactory;
linyuh7b86f562017-11-16 11:24:09 -080093import com.android.incallui.incalluilock.InCallUiLock;
wangqi219b8702018-02-13 09:34:41 -080094import com.android.incallui.rtt.bindings.RttBindings;
95import com.android.incallui.rtt.protocol.RttCallScreen;
96import com.android.incallui.rtt.protocol.RttCallScreenDelegate;
97import com.android.incallui.rtt.protocol.RttCallScreenDelegateFactory;
erfaniand05d8992018-03-20 19:42:26 -070098import com.android.incallui.speakeasy.SpeakEasyCallManager;
linyuhf99f6302017-11-15 11:23:51 -080099import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment;
Eric Erfanianccca3152017-02-22 16:32:36 -0800100import com.android.incallui.video.bindings.VideoBindings;
101import com.android.incallui.video.protocol.VideoCallScreen;
102import com.android.incallui.video.protocol.VideoCallScreenDelegate;
103import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory;
linyuhc3968e62017-11-20 17:40:50 -0800104import com.google.common.base.Optional;
105import java.lang.annotation.Retention;
106import java.lang.annotation.RetentionPolicy;
107import java.util.ArrayList;
108import java.util.List;
Eric Erfanianccca3152017-02-22 16:32:36 -0800109
110/** Version of {@link InCallActivity} that shows the new UI */
111public class InCallActivity extends TransactionSafeFragmentActivity
112 implements AnswerScreenDelegateFactory,
113 InCallScreenDelegateFactory,
114 InCallButtonUiDelegateFactory,
115 VideoCallScreenDelegateFactory,
wangqi219b8702018-02-13 09:34:41 -0800116 RttCallScreenDelegateFactory,
Eric Erfanianccca3152017-02-22 16:32:36 -0800117 PseudoScreenState.StateChangedListener {
118
linyuhc3968e62017-11-20 17:40:50 -0800119 @Retention(RetentionPolicy.SOURCE)
120 @IntDef({
121 DIALPAD_REQUEST_NONE,
122 DIALPAD_REQUEST_SHOW,
123 DIALPAD_REQUEST_HIDE,
124 })
125 @interface DialpadRequestType {}
Eric Erfanian2ca43182017-08-31 06:57:16 -0700126
linyuhc3968e62017-11-20 17:40:50 -0800127 private static final int DIALPAD_REQUEST_NONE = 1;
128 private static final int DIALPAD_REQUEST_SHOW = 2;
129 private static final int DIALPAD_REQUEST_HIDE = 3;
linyuh57b093b2017-11-17 14:32:32 -0800130
linyuhc3968e62017-11-20 17:40:50 -0800131 private static Optional<Integer> audioRouteForTesting = Optional.absent();
linyuh57b093b2017-11-17 14:32:32 -0800132
linyuhc3968e62017-11-20 17:40:50 -0800133 private final InternationalCallOnWifiCallback internationalCallOnWifiCallback =
134 new InternationalCallOnWifiCallback();
twyen73a74c32018-03-07 12:12:24 -0800135
136 private SelectPhoneAccountListener selectPhoneAccountListener;
Eric Erfanianccca3152017-02-22 16:32:36 -0800137
linyuhc3968e62017-11-20 17:40:50 -0800138 private Animation dialpadSlideInAnimation;
139 private Animation dialpadSlideOutAnimation;
140 private Dialog errorDialog;
141 private GradientDrawable backgroundDrawable;
linyuh69a25062017-11-15 16:18:51 -0800142 private InCallOrientationEventListener inCallOrientationEventListener;
linyuhc3968e62017-11-20 17:40:50 -0800143 private View pseudoBlackScreenOverlay;
144 private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment;
145 private String dtmfTextToPrepopulate;
146 private String showPostCharWaitDialogCallId;
147 private String showPostCharWaitDialogChars;
148 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;
linyuh9c327da2017-11-14 12:33:48 -0800155 private boolean dismissKeyguard;
Eric Erfanianccca3152017-02-22 16:32:36 -0800156 private boolean isInShowMainInCallFragment;
linyuhc3968e62017-11-20 17:40:50 -0800157 private boolean isRecreating; // whether the activity is going to be recreated
158 private boolean isVisible;
Eric Erfanianccca3152017-02-22 16:32:36 -0800159 private boolean needDismissPendingDialogs;
linyuhc3968e62017-11-20 17:40:50 -0800160 private boolean showPostCharWaitDialogOnResume;
161 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
twyen73a74c32018-03-07 12:12:24 -0800192 selectPhoneAccountListener = new SelectPhoneAccountListener(getApplicationContext());
193
linyuhc3968e62017-11-20 17:40:50 -0800194 if (bundle != null) {
195 didShowAnswerScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN);
196 didShowInCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN);
197 didShowVideoCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN);
wangqi153af2f2018-02-15 16:21:49 -0800198 didShowRttCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -0800199 }
200
linyuhc3968e62017-11-20 17:40:50 -0800201 setWindowFlags();
202 setContentView(R.layout.incall_screen);
203 internalResolveIntent(getIntent());
204
205 boolean isLandscape =
206 getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
207 boolean isRtl = ViewUtil.isRtl();
208 if (isLandscape) {
209 dialpadSlideInAnimation =
210 AnimationUtils.loadAnimation(
211 this, isRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right);
212 dialpadSlideOutAnimation =
213 AnimationUtils.loadAnimation(
214 this, isRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right);
215 } else {
216 dialpadSlideInAnimation = AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_in_bottom);
217 dialpadSlideOutAnimation =
218 AnimationUtils.loadAnimation(this, R.anim.dialpad_slide_out_bottom);
219 }
220 dialpadSlideInAnimation.setInterpolator(AnimUtils.EASE_IN);
221 dialpadSlideOutAnimation.setInterpolator(AnimUtils.EASE_OUT);
222 dialpadSlideOutAnimation.setAnimationListener(
223 new AnimationListenerAdapter() {
224 @Override
225 public void onAnimationEnd(Animation animation) {
226 hideDialpadFragment();
227 }
228 });
229
230 if (bundle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) {
231 // If the dialpad was shown before, set related variables so that it can be shown and
232 // populated with the previous DTMF text during onResume().
233 if (bundle.containsKey(IntentExtraNames.SHOW_DIALPAD)) {
234 boolean showDialpad = bundle.getBoolean(IntentExtraNames.SHOW_DIALPAD);
235 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_HIDE;
236 animateDialpadOnShow = false;
237 }
238 dtmfTextToPrepopulate = bundle.getString(KeysForSavedInstance.DIALPAD_TEXT);
239
240 SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment =
241 (SelectPhoneAccountDialogFragment)
242 getFragmentManager().findFragmentByTag(Tags.SELECT_ACCOUNT_FRAGMENT);
243 if (selectPhoneAccountDialogFragment != null) {
244 selectPhoneAccountDialogFragment.setListener(selectPhoneAccountListener);
245 }
246 }
247
248 InternationalCallOnWifiDialogFragment existingInternationalCallOnWifiDialogFragment =
249 (InternationalCallOnWifiDialogFragment)
250 getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
251 if (existingInternationalCallOnWifiDialogFragment != null) {
252 existingInternationalCallOnWifiDialogFragment.setCallback(internationalCallOnWifiCallback);
253 }
254
linyuh69a25062017-11-15 16:18:51 -0800255 inCallOrientationEventListener = new InCallOrientationEventListener(this);
Eric Erfanianccca3152017-02-22 16:32:36 -0800256
257 getWindow()
258 .getDecorView()
259 .setSystemUiVisibility(
260 View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
261
262 pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700263 sendBroadcast(CallPendingActivity.getFinishBroadcast());
264 Trace.endSection();
zachh7a96dc72018-02-20 22:16:03 -0800265 MetricsComponent.get(this)
266 .metrics()
267 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_INCOMING);
268 MetricsComponent.get(this)
269 .metrics()
270 .stopTimer(Metrics.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_OUTGOING);
Eric Erfanianccca3152017-02-22 16:32:36 -0800271 }
272
linyuhc3968e62017-11-20 17:40:50 -0800273 private void setWindowFlags() {
274 // Allow the activity to be shown when the screen is locked and filter out touch events that are
275 // "too fat".
276 int flags =
277 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
278 | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES;
279
linyuhf79d1cb2017-12-15 17:49:56 -0800280 // When the audio stream is not via Bluetooth, turn on the screen once the activity is shown.
281 // When the audio stream is via Bluetooth, turn on the screen only for an incoming call.
linyuhc3968e62017-11-20 17:40:50 -0800282 final int audioRoute = getAudioRoute();
linyuhf79d1cb2017-12-15 17:49:56 -0800283 if (audioRoute != CallAudioState.ROUTE_BLUETOOTH
284 || CallList.getInstance().getIncomingCall() != null) {
linyuhc3968e62017-11-20 17:40:50 -0800285 flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
286 }
287
288 getWindow().addFlags(flags);
289 }
290
291 private static int getAudioRoute() {
292 if (audioRouteForTesting.isPresent()) {
293 return audioRouteForTesting.get();
294 }
295
296 return AudioModeProvider.getInstance().getAudioState().getRoute();
297 }
298
299 @VisibleForTesting(otherwise = VisibleForTesting.NONE)
300 public static void setAudioRouteForTesting(int audioRoute) {
301 audioRouteForTesting = Optional.of(audioRoute);
302 }
303
304 private void internalResolveIntent(Intent intent) {
305 if (!intent.getAction().equals(Intent.ACTION_MAIN)) {
306 return;
307 }
308
309 if (intent.hasExtra(IntentExtraNames.SHOW_DIALPAD)) {
310 // IntentExtraNames.SHOW_DIALPAD can be used to specify whether the DTMF dialpad should be
311 // initially visible. If the extra is absent, leave the dialpad in its previous state.
312 boolean showDialpad = intent.getBooleanExtra(IntentExtraNames.SHOW_DIALPAD, false);
313 relaunchedFromDialer(showDialpad);
314 }
315
316 DialerCall outgoingCall = CallList.getInstance().getOutgoingCall();
317 if (outgoingCall == null) {
318 outgoingCall = CallList.getInstance().getPendingOutgoingCall();
319 }
320 if (intent.getBooleanExtra(IntentExtraNames.NEW_OUTGOING_CALL, false)) {
321 intent.removeExtra(IntentExtraNames.NEW_OUTGOING_CALL);
322
323 // InCallActivity is responsible for disconnecting a new outgoing call if there is no way of
324 // making it (i.e. no valid call capable accounts).
325 // If the version is not MSIM compatible, ignore this code.
326 if (CompatUtils.isMSIMCompatible()
327 && InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) {
328 LogUtil.i(
329 "InCallActivity.internalResolveIntent", "Call with no valid accounts, disconnecting");
330 outgoingCall.disconnect();
331 }
332
333 dismissKeyguard(true);
334 }
335
336 if (showPhoneAccountSelectionDialog()) {
337 hideMainInCallFragment();
338 }
339 }
340
341 /**
342 * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should
343 * be shown on launch.
344 *
345 * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code
346 * false} to indicate no change should be made to the dialpad visibility.
347 */
348 private void relaunchedFromDialer(boolean showDialpad) {
349 showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE;
350 animateDialpadOnShow = true;
351
352 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
353 // If there's only one line in use, AND it's on hold, then we're sure the user
354 // wants to use the dialpad toward the exact line, so un-hold the holding line.
355 DialerCall call = CallList.getInstance().getActiveOrBackgroundCall();
356 if (call != null && call.getState() == State.ONHOLD) {
357 call.unhold();
358 }
359 }
360 }
361
362 /**
363 * Show a phone account selection dialog if there is a call waiting for phone account selection.
364 *
365 * @return true if the dialog was shown.
366 */
367 private boolean showPhoneAccountSelectionDialog() {
368 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
369 if (waitingForAccountCall == null) {
370 return false;
371 }
372
twyen73a74c32018-03-07 12:12:24 -0800373 DialerExecutorComponent.get(this)
374 .dialerExecutorFactory()
375 .createNonUiTaskBuilder(new PreferredAccountWorker(waitingForAccountCall.getNumber()))
376 .onSuccess(
377 (result -> {
378 if (result.getPhoneAccountHandle().isPresent()) {
379 Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_PREFERRED_USED);
380 selectPhoneAccountListener.onPhoneAccountSelected(
381 result.getPhoneAccountHandle().get(), false, waitingForAccountCall.getId());
382 return;
383 }
384 if (result.getSuggestion().isPresent()) {
385 LogUtil.i(
386 "CallingAccountSelector.processPreferredAccount",
387 "SIM suggested: " + result.getSuggestion().get().reason);
388 if (result.getSuggestion().get().shouldAutoSelect) {
389 Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_SUGGESTION_AUTO_SELECTED);
390 LogUtil.i(
391 "CallingAccountSelector.processPreferredAccount", "Auto selected suggestion");
392 selectPhoneAccountListener.onPhoneAccountSelected(
393 result.getSuggestion().get().phoneAccountHandle,
394 false,
395 waitingForAccountCall.getId());
396 return;
397 }
398 }
399 Bundle extras = waitingForAccountCall.getIntentExtras();
400 List<PhoneAccountHandle> phoneAccountHandles =
401 extras == null
402 ? new ArrayList<>()
403 : extras.getParcelableArrayList(Call.AVAILABLE_PHONE_ACCOUNTS);
linyuhc3968e62017-11-20 17:40:50 -0800404
twyen73a74c32018-03-07 12:12:24 -0800405 waitingForAccountCall.setPreferredAccountRecorder(
406 new PreferredAccountRecorder(
407 waitingForAccountCall.getNumber(),
408 result.getSuggestion().orNull(),
409 result.getDataId().orNull()));
410 selectPhoneAccountDialogFragment =
411 SelectPhoneAccountDialogFragment.newInstance(
412 R.string.select_phone_account_for_calls,
413 result.getDataId().isPresent() /* canSetDefault */,
414 R.string.select_phone_account_for_calls_remember /* setDefaultResId */,
415 phoneAccountHandles,
416 selectPhoneAccountListener,
417 waitingForAccountCall.getId(),
418 SuggestionProvider.buildHint(
419 this, phoneAccountHandles, result.getSuggestion().orNull() /* hints */));
420 selectPhoneAccountDialogFragment.show(
421 getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT);
422 }))
423 .build()
424 .executeParallel(this);
425
linyuhc3968e62017-11-20 17:40:50 -0800426 return true;
427 }
428
Eric Erfanianccca3152017-02-22 16:32:36 -0800429 @Override
430 protected void onSaveInstanceState(Bundle out) {
linyuh57b093b2017-11-17 14:32:32 -0800431 LogUtil.enterBlock("InCallActivity.onSaveInstanceState");
432
433 // TODO: DialpadFragment should handle this as part of its own state
linyuhc3968e62017-11-20 17:40:50 -0800434 out.putBoolean(IntentExtraNames.SHOW_DIALPAD, isDialpadVisible());
linyuh57b093b2017-11-17 14:32:32 -0800435 DialpadFragment dialpadFragment = getDialpadFragment();
436 if (dialpadFragment != null) {
linyuhc3968e62017-11-20 17:40:50 -0800437 out.putString(KeysForSavedInstance.DIALPAD_TEXT, dialpadFragment.getDtmfText());
linyuh57b093b2017-11-17 14:32:32 -0800438 }
439
linyuhc3968e62017-11-20 17:40:50 -0800440 out.putBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN, didShowAnswerScreen);
441 out.putBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN, didShowInCallScreen);
442 out.putBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN, didShowVideoCallScreen);
wangqi153af2f2018-02-15 16:21:49 -0800443 out.putBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN, didShowRttCallScreen);
erfaniand05d8992018-03-20 19:42:26 -0700444 out.putBoolean(KeysForSavedInstance.DID_SHOW_SPEAK_EASY_SCREEN, didShowSpeakEasyScreen);
linyuh57b093b2017-11-17 14:32:32 -0800445
Eric Erfanianccca3152017-02-22 16:32:36 -0800446 super.onSaveInstanceState(out);
447 isVisible = false;
448 }
449
450 @Override
451 protected void onStart() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700452 Trace.beginSection("InCallActivity.onStart");
Eric Erfanianccca3152017-02-22 16:32:36 -0800453 super.onStart();
linyuh57b093b2017-11-17 14:32:32 -0800454
Eric Erfanianccca3152017-02-22 16:32:36 -0800455 isVisible = true;
456 showMainInCallFragment();
linyuh57b093b2017-11-17 14:32:32 -0800457
458 InCallPresenter.getInstance().setActivity(this);
459 enableInCallOrientationEventListener(
460 getRequestedOrientation()
461 == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
462 InCallPresenter.getInstance().onActivityStarted();
463
yueg10f6e822018-01-17 15:32:18 -0800464 if (!isRecreating) {
465 InCallPresenter.getInstance().onUiShowing(true);
466 }
467
Eric Erfanianccca3152017-02-22 16:32:36 -0800468 if (ActivityCompat.isInMultiWindowMode(this)
469 && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) {
470 // Hide the dialpad because there may not be enough room
471 showDialpadFragment(false, false);
472 }
linyuh57b093b2017-11-17 14:32:32 -0800473
Eric Erfanian2ca43182017-08-31 06:57:16 -0700474 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800475 }
476
477 @Override
478 protected void onResume() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700479 Trace.beginSection("InCallActivity.onResume");
Eric Erfanianccca3152017-02-22 16:32:36 -0800480 super.onResume();
linyuhc3968e62017-11-20 17:40:50 -0800481
482 if (!InCallPresenter.getInstance().isReadyForTearDown()) {
483 updateTaskDescription();
yueg10f6e822018-01-17 15:32:18 -0800484 InCallPresenter.getInstance().updateNotification();
linyuhc3968e62017-11-20 17:40:50 -0800485 }
486
487 // If there is a pending request to show or hide the dialpad, handle that now.
488 if (showDialpadRequest != DIALPAD_REQUEST_NONE) {
489 if (showDialpadRequest == DIALPAD_REQUEST_SHOW) {
490 // Exit fullscreen so that the user has access to the dialpad hide/show button.
491 // This is important when showing the dialpad from within dialer.
492 InCallPresenter.getInstance().setFullScreen(false /* isFullScreen */, true /* force */);
493
494 showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */);
495 animateDialpadOnShow = false;
496
497 DialpadFragment dialpadFragment = getDialpadFragment();
498 if (dialpadFragment != null) {
499 dialpadFragment.setDtmfText(dtmfTextToPrepopulate);
500 dtmfTextToPrepopulate = null;
501 }
502 } else {
503 LogUtil.i("InCallActivity.onResume", "Force-hide the dialpad");
504 if (getDialpadFragment() != null) {
505 showDialpadFragment(false /* show */, false /* animate */);
506 }
507 }
508 showDialpadRequest = DIALPAD_REQUEST_NONE;
509 }
510 updateNavigationBar(isDialpadVisible());
511
512 if (showPostCharWaitDialogOnResume) {
513 showDialogForPostCharWait(showPostCharWaitDialogCallId, showPostCharWaitDialogChars);
514 }
515
516 CallList.getInstance()
517 .onInCallUiShown(getIntent().getBooleanExtra(IntentExtraNames.FOR_FULL_SCREEN, false));
518
Eric Erfanianccca3152017-02-22 16:32:36 -0800519 PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState();
520 pseudoScreenState.addListener(this);
521 onPseudoScreenStateChanged(pseudoScreenState.isOn());
Eric Erfanian2ca43182017-08-31 06:57:16 -0700522 Trace.endSection();
weijiaxu650e7cc2017-10-31 12:38:54 -0700523 // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume.
524 ThreadUtil.postDelayedOnUiThread(
weijiaxuc950a9b2017-11-06 16:39:04 -0800525 () ->
zachh7a96dc72018-02-20 22:16:03 -0800526 MetricsComponent.get(this)
527 .metrics()
528 .recordMemory(Metrics.INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME),
weijiaxu650e7cc2017-10-31 12:38:54 -0700529 1000);
Eric Erfanianccca3152017-02-22 16:32:36 -0800530 }
531
Eric Erfanianccca3152017-02-22 16:32:36 -0800532 @Override
533 protected void onPause() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700534 Trace.beginSection("InCallActivity.onPause");
Eric Erfanianccca3152017-02-22 16:32:36 -0800535 super.onPause();
linyuh57b093b2017-11-17 14:32:32 -0800536
537 DialpadFragment dialpadFragment = getDialpadFragment();
538 if (dialpadFragment != null) {
539 dialpadFragment.onDialerKeyUp(null);
540 }
541
yueg10f6e822018-01-17 15:32:18 -0800542 InCallPresenter.getInstance().updateNotification();
linyuh57b093b2017-11-17 14:32:32 -0800543
Eric Erfanianccca3152017-02-22 16:32:36 -0800544 InCallPresenter.getInstance().getPseudoScreenState().removeListener(this);
Eric Erfanian2ca43182017-08-31 06:57:16 -0700545 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800546 }
547
548 @Override
549 protected void onStop() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700550 Trace.beginSection("InCallActivity.onStop");
wangqi4d705e52017-09-28 12:23:35 -0700551 isVisible = false;
Eric Erfanianccca3152017-02-22 16:32:36 -0800552 super.onStop();
linyuh57b093b2017-11-17 14:32:32 -0800553
554 // Disconnects the call waiting for a phone account when the activity is hidden (e.g., after the
555 // user presses the home button).
556 // Without this the pending call will get stuck on phone account selection and new calls can't
557 // be created.
558 // Skip this when the screen is locked since the activity may complete its current life cycle
559 // and restart.
linyuhc3968e62017-11-20 17:40:50 -0800560 if (!isRecreating && !getSystemService(KeyguardManager.class).isKeyguardLocked()) {
linyuh57b093b2017-11-17 14:32:32 -0800561 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
562 if (waitingForAccountCall != null) {
563 waitingForAccountCall.disconnect();
564 }
565 }
566
567 enableInCallOrientationEventListener(false);
568 InCallPresenter.getInstance().updateIsChangingConfigurations();
569 InCallPresenter.getInstance().onActivityStopped();
linyuhc3968e62017-11-20 17:40:50 -0800570 if (!isRecreating) {
yueg10f6e822018-01-17 15:32:18 -0800571 InCallPresenter.getInstance().onUiShowing(false);
linyuh57b093b2017-11-17 14:32:32 -0800572 if (errorDialog != null) {
573 errorDialog.dismiss();
574 }
575 }
576
yueg10f6e822018-01-17 15:32:18 -0800577 if (isFinishing()) {
578 InCallPresenter.getInstance().unsetActivity(this);
579 }
580
Eric Erfanian2ca43182017-08-31 06:57:16 -0700581 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800582 }
583
584 @Override
585 protected void onDestroy() {
Eric Erfanian2ca43182017-08-31 06:57:16 -0700586 Trace.beginSection("InCallActivity.onDestroy");
Eric Erfanianccca3152017-02-22 16:32:36 -0800587 super.onDestroy();
linyuh57b093b2017-11-17 14:32:32 -0800588
589 InCallPresenter.getInstance().unsetActivity(this);
590 InCallPresenter.getInstance().updateIsChangingConfigurations();
Eric Erfanian2ca43182017-08-31 06:57:16 -0700591 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800592 }
593
594 @Override
595 public void finish() {
596 if (shouldCloseActivityOnFinish()) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700597 // When user select incall ui from recents after the call is disconnected, it tries to launch
598 // a new InCallActivity but InCallPresenter is already teared down at this point, which causes
599 // crash.
600 // By calling finishAndRemoveTask() instead of finish() the task associated with
601 // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in
602 // this case.
603 //
604 // Calling finish won't clear the task and normally when an activity finishes it shouldn't
605 // clear the task since there could be parent activity in the same task that's still alive.
606 // But InCallActivity is special since it's singleInstance which means it's root activity and
607 // only instance of activity in the task. So it should be safe to also remove task when
608 // finishing.
609 // It's also necessary in the sense of it's excluded from recents. So whenever the activity
610 // finishes, the task should also be removed since it doesn't make sense to go back to it in
611 // anyway anymore.
612 super.finishAndRemoveTask();
Eric Erfanianccca3152017-02-22 16:32:36 -0800613 }
614 }
615
616 private boolean shouldCloseActivityOnFinish() {
linyuhc3968e62017-11-20 17:40:50 -0800617 if (!isVisible) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800618 LogUtil.i(
619 "InCallActivity.shouldCloseActivityOnFinish",
620 "allowing activity to be closed because it's not visible");
621 return true;
622 }
623
twyen8efb4952017-10-06 16:35:54 -0700624 if (InCallPresenter.getInstance().isInCallUiLocked()) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800625 LogUtil.i(
626 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700627 "in call ui is locked, not closing activity");
Eric Erfanianccca3152017-02-22 16:32:36 -0800628 return false;
629 }
630
631 LogUtil.i(
632 "InCallActivity.shouldCloseActivityOnFinish",
twyen8efb4952017-10-06 16:35:54 -0700633 "activity is visible and has no locks, allowing activity to close");
Eric Erfanianccca3152017-02-22 16:32:36 -0800634 return true;
635 }
636
637 @Override
638 protected void onNewIntent(Intent intent) {
linyuhc3968e62017-11-20 17:40:50 -0800639 LogUtil.enterBlock("InCallActivity.onNewIntent");
Eric Erfanianccca3152017-02-22 16:32:36 -0800640
641 // If the screen is off, we need to make sure it gets turned on for incoming calls.
642 // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works
643 // when the activity is first created. Therefore, to ensure the screen is turned on
644 // for the call waiting case, we recreate() the current activity. There should be no jank from
645 // this since the screen is already off and will remain so until our new activity is up.
linyuhc3968e62017-11-20 17:40:50 -0800646 if (!isVisible) {
647 onNewIntent(intent, true /* isRecreating */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800648 LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on.");
649 recreate();
Eric Erfanian10b34a52017-05-04 08:23:17 -0700650 } else {
linyuhc3968e62017-11-20 17:40:50 -0800651 onNewIntent(intent, false /* isRecreating */);
652 }
653 }
654
yuega3305352018-01-09 11:02:47 -0800655 @VisibleForTesting
656 void onNewIntent(Intent intent, boolean isRecreating) {
linyuhc3968e62017-11-20 17:40:50 -0800657 this.isRecreating = isRecreating;
658
659 // We're being re-launched with a new Intent. Since it's possible for a single InCallActivity
660 // instance to persist indefinitely (even if we finish() ourselves), this sequence can
661 // happen any time the InCallActivity needs to be displayed.
662
663 // Stash away the new intent so that we can get it in the future by calling getIntent().
664 // Otherwise getIntent() will return the original Intent from when we first got created.
665 setIntent(intent);
666
667 // Activities are always paused before receiving a new intent, so we can count on our onResume()
668 // method being called next.
669
670 // Just like in onCreate(), handle the intent.
671 // Skip if InCallActivity is going to be recreated since this will be called in onCreate().
672 if (!isRecreating) {
673 internalResolveIntent(intent);
Eric Erfanianccca3152017-02-22 16:32:36 -0800674 }
675 }
676
677 @Override
678 public void onBackPressed() {
linyuh57b093b2017-11-17 14:32:32 -0800679 LogUtil.enterBlock("InCallActivity.onBackPressed");
680
linyuhc3968e62017-11-20 17:40:50 -0800681 if (!isVisible) {
linyuh57b093b2017-11-17 14:32:32 -0800682 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800683 }
linyuh57b093b2017-11-17 14:32:32 -0800684
685 if (!getCallCardFragmentVisible()) {
686 return;
687 }
688
689 DialpadFragment dialpadFragment = getDialpadFragment();
690 if (dialpadFragment != null && dialpadFragment.isVisible()) {
691 showDialpadFragment(false /* show */, true /* animate */);
692 return;
693 }
694
695 if (CallList.getInstance().getIncomingCall() != null) {
696 LogUtil.i(
697 "InCallActivity.onBackPressed",
698 "Ignore the press of the back key when an incoming call is ringing");
699 return;
700 }
701
702 // Nothing special to do. Fall back to the default behavior.
703 super.onBackPressed();
Eric Erfanianccca3152017-02-22 16:32:36 -0800704 }
705
706 @Override
707 public boolean onOptionsItemSelected(MenuItem item) {
708 LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item);
709 if (item.getItemId() == android.R.id.home) {
710 onBackPressed();
711 return true;
712 }
713 return super.onOptionsItemSelected(item);
714 }
715
716 @Override
717 public boolean onKeyUp(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800718 DialpadFragment dialpadFragment = getDialpadFragment();
719 if (dialpadFragment != null
720 && dialpadFragment.isVisible()
721 && dialpadFragment.onDialerKeyUp(event)) {
722 return true;
723 }
724
725 if (keyCode == KeyEvent.KEYCODE_CALL) {
726 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
727 return true;
728 }
729
730 return super.onKeyUp(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800731 }
732
733 @Override
734 public boolean onKeyDown(int keyCode, KeyEvent event) {
linyuh57b093b2017-11-17 14:32:32 -0800735 switch (keyCode) {
736 case KeyEvent.KEYCODE_CALL:
737 if (!InCallPresenter.getInstance().handleCallKey()) {
738 LogUtil.e(
739 "InCallActivity.onKeyDown",
740 "InCallPresenter should always handle KEYCODE_CALL in onKeyDown");
741 }
742 // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it.
743 return true;
744
745 // Note that KEYCODE_ENDCALL isn't handled here as the standard system-wide handling of it
746 // is exactly what's needed, namely
747 // (1) "hang up" if there's an active call, or
748 // (2) "don't answer" if there's an incoming call.
749 // (See PhoneWindowManager for implementation details.)
750
751 case KeyEvent.KEYCODE_CAMERA:
752 // Consume KEYCODE_CAMERA since it's easy to accidentally press the camera button.
753 return true;
754
755 case KeyEvent.KEYCODE_VOLUME_UP:
756 case KeyEvent.KEYCODE_VOLUME_DOWN:
757 case KeyEvent.KEYCODE_VOLUME_MUTE:
758 // Ringer silencing handled by PhoneWindowManager.
759 break;
760
761 case KeyEvent.KEYCODE_MUTE:
762 TelecomAdapter.getInstance()
763 .mute(!AudioModeProvider.getInstance().getAudioState().isMuted());
764 return true;
765
766 case KeyEvent.KEYCODE_SLASH:
767 // When verbose logging is enabled, dump the view for debugging/testing purposes.
768 if (LogUtil.isVerboseEnabled()) {
769 View decorView = getWindow().getDecorView();
770 LogUtil.v("InCallActivity.onKeyDown", "View dump:\n%s", decorView);
771 return true;
772 }
773 break;
774
775 case KeyEvent.KEYCODE_EQUALS:
776 break;
777
778 default: // fall out
779 }
780
781 // Pass other key events to DialpadFragment's "onDialerKeyDown" method in case the user types
782 // in DTMF (Dual-tone multi-frequency signaling) code.
783 DialpadFragment dialpadFragment = getDialpadFragment();
784 if (dialpadFragment != null
785 && dialpadFragment.isVisible()
786 && dialpadFragment.onDialerKeyDown(event)) {
787 return true;
788 }
789
790 return super.onKeyDown(keyCode, event);
Eric Erfanianccca3152017-02-22 16:32:36 -0800791 }
792
793 public boolean isInCallScreenAnimating() {
794 return false;
795 }
796
797 public void showConferenceFragment(boolean show) {
798 if (show) {
799 startActivity(new Intent(this, ManageConferenceActivity.class));
800 }
801 }
802
linyuhc3968e62017-11-20 17:40:50 -0800803 public void showDialpadFragment(boolean show, boolean animate) {
804 if (show == isDialpadVisible()) {
805 return;
Eric Erfanianccca3152017-02-22 16:32:36 -0800806 }
linyuhc3968e62017-11-20 17:40:50 -0800807
808 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
809 if (dialpadFragmentManager == null) {
810 LogUtil.i("InCallActivity.showDialpadFragment", "Unable to obtain a FragmentManager");
811 return;
812 }
813
814 if (!animate) {
815 if (show) {
816 showDialpadFragment();
817 } else {
818 hideDialpadFragment();
819 }
820 } else {
821 if (show) {
822 showDialpadFragment();
823 getDialpadFragment().animateShowDialpad();
824 }
825 getDialpadFragment()
826 .getView()
827 .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation);
828 }
829
830 ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor();
831 if (sensor != null) {
832 sensor.onDialpadVisible(show);
833 }
834 showDialpadRequest = DIALPAD_REQUEST_NONE;
835
836 // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB
837 // repositions itself.
wangqifd4c9f72018-03-08 18:21:50 -0800838 getInCallOrRttCallScreen().onInCallScreenDialpadVisibilityChange(show);
linyuhc3968e62017-11-20 17:40:50 -0800839 }
840
841 private void showDialpadFragment() {
842 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
843 if (dialpadFragmentManager == null) {
844 return;
845 }
846
847 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
848 DialpadFragment dialpadFragment = getDialpadFragment();
849 if (dialpadFragment == null) {
wangqifd4c9f72018-03-08 18:21:50 -0800850 dialpadFragment = new DialpadFragment();
851 transaction.add(getDialpadContainerId(), dialpadFragment, Tags.DIALPAD_FRAGMENT);
linyuhc3968e62017-11-20 17:40:50 -0800852 } else {
853 transaction.show(dialpadFragment);
calderwoodrad5883872017-12-12 15:29:12 -0800854 dialpadFragment.setUserVisibleHint(true);
linyuhc3968e62017-11-20 17:40:50 -0800855 }
wangqifd4c9f72018-03-08 18:21:50 -0800856 // RTT call screen doesn't show end call button inside dialpad, thus the space reserved for end
857 // call button should be removed.
858 dialpadFragment.setShouldShowEndCallSpace(didShowInCallScreen);
linyuhc3968e62017-11-20 17:40:50 -0800859 transaction.commitAllowingStateLoss();
860 dialpadFragmentManager.executePendingTransactions();
861
862 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, this);
863 updateNavigationBar(true /* isDialpadVisible */);
864 }
865
866 private void hideDialpadFragment() {
867 FragmentManager dialpadFragmentManager = getDialpadFragmentManager();
868 if (dialpadFragmentManager == null) {
869 return;
870 }
871
calderwoodrad5883872017-12-12 15:29:12 -0800872 DialpadFragment dialpadFragment = getDialpadFragment();
linyuhc3968e62017-11-20 17:40:50 -0800873 if (dialpadFragment != null) {
874 FragmentTransaction transaction = dialpadFragmentManager.beginTransaction();
875 transaction.hide(dialpadFragment);
876 transaction.commitAllowingStateLoss();
877 dialpadFragmentManager.executePendingTransactions();
calderwoodrad5883872017-12-12 15:29:12 -0800878 dialpadFragment.setUserVisibleHint(false);
linyuhc3968e62017-11-20 17:40:50 -0800879 }
880 updateNavigationBar(false /* isDialpadVisible */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800881 }
882
883 public boolean isDialpadVisible() {
linyuh69a25062017-11-15 16:18:51 -0800884 DialpadFragment dialpadFragment = getDialpadFragment();
calderwoodraa584bcd2018-01-24 12:19:56 -0800885 return dialpadFragment != null
886 && dialpadFragment.isAdded()
887 && !dialpadFragment.isHidden()
888 && dialpadFragment.getView() != null
889 && dialpadFragment.getUserVisibleHint();
linyuh69a25062017-11-15 16:18:51 -0800890 }
891
linyuhc3968e62017-11-20 17:40:50 -0800892 /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */
linyuh69a25062017-11-15 16:18:51 -0800893 @Nullable
linyuhc3968e62017-11-20 17:40:50 -0800894 private DialpadFragment getDialpadFragment() {
linyuh69a25062017-11-15 16:18:51 -0800895 FragmentManager fragmentManager = getDialpadFragmentManager();
896 if (fragmentManager == null) {
897 return null;
898 }
linyuhc3968e62017-11-20 17:40:50 -0800899 return (DialpadFragment) fragmentManager.findFragmentByTag(Tags.DIALPAD_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -0800900 }
901
902 public void onForegroundCallChanged(DialerCall newForegroundCall) {
linyuh57b093b2017-11-17 14:32:32 -0800903 updateTaskDescription();
904
905 if (newForegroundCall == null || !didShowAnswerScreen) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800906 LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color");
linyuh57b093b2017-11-17 14:32:32 -0800907 updateWindowBackgroundColor(0 /* progress */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800908 }
909 }
910
linyuhc3968e62017-11-20 17:40:50 -0800911 private void updateTaskDescription() {
linyuh57b093b2017-11-17 14:32:32 -0800912 int color =
913 getResources().getBoolean(R.bool.is_layout_landscape)
914 ? ResourcesCompat.getColor(
915 getResources(), R.color.statusbar_background_color, getTheme())
916 : InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor();
917 setTaskDescription(
918 new TaskDescription(
919 getResources().getString(R.string.notification_ongoing_call), null /* icon */, color));
920 }
921
Eric Erfanianccca3152017-02-22 16:32:36 -0800922 public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) {
923 ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager();
924 @ColorInt int top;
925 @ColorInt int middle;
926 @ColorInt int bottom;
927 @ColorInt int gray = 0x66000000;
928
929 if (ActivityCompat.isInMultiWindowMode(this)) {
930 top = themeColorManager.getBackgroundColorSolid();
931 middle = themeColorManager.getBackgroundColorSolid();
932 bottom = themeColorManager.getBackgroundColorSolid();
933 } else {
934 top = themeColorManager.getBackgroundColorTop();
935 middle = themeColorManager.getBackgroundColorMiddle();
936 bottom = themeColorManager.getBackgroundColorBottom();
937 }
938
939 if (progress < 0) {
940 float correctedProgress = Math.abs(progress);
941 top = ColorUtils.blendARGB(top, gray, correctedProgress);
942 middle = ColorUtils.blendARGB(middle, gray, correctedProgress);
943 bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress);
944 }
945
946 boolean backgroundDirty = false;
947 if (backgroundDrawable == null) {
948 backgroundDrawableColors = new int[] {top, middle, bottom};
949 backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors);
950 backgroundDirty = true;
951 } else {
952 if (backgroundDrawableColors[0] != top) {
953 backgroundDrawableColors[0] = top;
954 backgroundDirty = true;
955 }
956 if (backgroundDrawableColors[1] != middle) {
957 backgroundDrawableColors[1] = middle;
958 backgroundDirty = true;
959 }
960 if (backgroundDrawableColors[2] != bottom) {
961 backgroundDrawableColors[2] = bottom;
962 backgroundDirty = true;
963 }
964 if (backgroundDirty) {
965 backgroundDrawable.setColors(backgroundDrawableColors);
966 }
967 }
968
969 if (backgroundDirty) {
970 getWindow().setBackgroundDrawable(backgroundDrawable);
971 }
972 }
973
974 public boolean isVisible() {
975 return isVisible;
976 }
977
978 public boolean getCallCardFragmentVisible() {
erfaniand05d8992018-03-20 19:42:26 -0700979 return didShowInCallScreen
980 || didShowVideoCallScreen
981 || didShowRttCallScreen
982 || didShowSpeakEasyScreen;
Eric Erfanianccca3152017-02-22 16:32:36 -0800983 }
984
985 public void dismissKeyguard(boolean dismiss) {
linyuh9c327da2017-11-14 12:33:48 -0800986 if (dismissKeyguard == dismiss) {
987 return;
988 }
989
990 dismissKeyguard = dismiss;
991 if (dismiss) {
992 getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
993 } else {
994 getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
995 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800996 }
997
linyuhc3968e62017-11-20 17:40:50 -0800998 public void showDialogForPostCharWait(String callId, String chars) {
999 if (isVisible) {
1000 PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars);
1001 fragment.show(getSupportFragmentManager(), Tags.POST_CHAR_DIALOG_FRAGMENT);
1002
1003 showPostCharWaitDialogOnResume = false;
1004 showPostCharWaitDialogCallId = null;
1005 showPostCharWaitDialogChars = null;
1006 } else {
1007 showPostCharWaitDialogOnResume = true;
1008 showPostCharWaitDialogCallId = callId;
1009 showPostCharWaitDialogChars = chars;
1010 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001011 }
1012
linyuh7b86f562017-11-16 11:24:09 -08001013 public void showDialogOrToastForDisconnectedCall(DisconnectMessage disconnectMessage) {
1014 LogUtil.i(
1015 "InCallActivity.showDialogOrToastForDisconnectedCall",
1016 "disconnect cause: %s",
1017 disconnectMessage);
1018
1019 if (disconnectMessage.dialog == null || isFinishing()) {
1020 return;
1021 }
1022
1023 dismissPendingDialogs();
1024
1025 // Show a toast if the app is in background when a dialog can't be visible.
1026 if (!isVisible()) {
1027 Toast.makeText(getApplicationContext(), disconnectMessage.toastMessage, Toast.LENGTH_LONG)
1028 .show();
1029 return;
1030 }
1031
1032 // Show the dialog.
linyuhc3968e62017-11-20 17:40:50 -08001033 errorDialog = disconnectMessage.dialog;
linyuh7b86f562017-11-16 11:24:09 -08001034 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog");
1035 disconnectMessage.dialog.setOnDismissListener(
1036 dialogInterface -> {
1037 lock.release();
1038 onDialogDismissed();
1039 });
1040 disconnectMessage.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
1041 disconnectMessage.dialog.show();
1042 }
1043
1044 private void onDialogDismissed() {
linyuhc3968e62017-11-20 17:40:50 -08001045 errorDialog = null;
linyuh7b86f562017-11-16 11:24:09 -08001046 CallList.getInstance().onErrorDialogDismissed();
Eric Erfanianccca3152017-02-22 16:32:36 -08001047 }
1048
1049 public void dismissPendingDialogs() {
linyuhc3968e62017-11-20 17:40:50 -08001050 LogUtil.enterBlock("InCallActivity.dismissPendingDialogs");
linyuhf99f6302017-11-15 11:23:51 -08001051
1052 if (!isVisible) {
1053 // Defer the dismissing action as the activity is not visible and onSaveInstanceState may have
1054 // been called.
Eric Erfanianccca3152017-02-22 16:32:36 -08001055 LogUtil.i(
1056 "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible");
1057 needDismissPendingDialogs = true;
linyuhf99f6302017-11-15 11:23:51 -08001058 return;
Eric Erfanianccca3152017-02-22 16:32:36 -08001059 }
linyuhf99f6302017-11-15 11:23:51 -08001060
1061 // Dismiss the error dialog
linyuhf99f6302017-11-15 11:23:51 -08001062 if (errorDialog != null) {
1063 errorDialog.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001064 errorDialog = null;
linyuhf99f6302017-11-15 11:23:51 -08001065 }
1066
1067 // Dismiss the phone account selection dialog
linyuhf99f6302017-11-15 11:23:51 -08001068 if (selectPhoneAccountDialogFragment != null) {
1069 selectPhoneAccountDialogFragment.dismiss();
linyuhc3968e62017-11-20 17:40:50 -08001070 selectPhoneAccountDialogFragment = null;
linyuhf99f6302017-11-15 11:23:51 -08001071 }
1072
1073 // Dismiss the dialog for international call on WiFi
1074 InternationalCallOnWifiDialogFragment internationalCallOnWifiFragment =
1075 (InternationalCallOnWifiDialogFragment)
linyuhc3968e62017-11-20 17:40:50 -08001076 getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI);
linyuhf99f6302017-11-15 11:23:51 -08001077 if (internationalCallOnWifiFragment != null) {
1078 internationalCallOnWifiFragment.dismiss();
1079 }
1080
1081 // Dismiss the answer screen
1082 AnswerScreen answerScreen = getAnswerScreen();
1083 if (answerScreen != null) {
1084 answerScreen.dismissPendingDialogs();
1085 }
1086
1087 needDismissPendingDialogs = false;
Eric Erfanianccca3152017-02-22 16:32:36 -08001088 }
1089
linyuhc3968e62017-11-20 17:40:50 -08001090 private void enableInCallOrientationEventListener(boolean enable) {
linyuh69a25062017-11-15 16:18:51 -08001091 if (enable) {
1092 inCallOrientationEventListener.enable(true /* notifyDeviceOrientationChange */);
1093 } else {
1094 inCallOrientationEventListener.disable();
1095 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001096 }
1097
1098 public void setExcludeFromRecents(boolean exclude) {
linyuhc3968e62017-11-20 17:40:50 -08001099 int taskId = getTaskId();
1100
1101 List<AppTask> tasks = getSystemService(ActivityManager.class).getAppTasks();
1102 for (AppTask task : tasks) {
1103 try {
1104 if (task.getTaskInfo().id == taskId) {
1105 task.setExcludeFromRecents(exclude);
1106 }
1107 } catch (RuntimeException e) {
1108 LogUtil.e("InCallActivity.setExcludeFromRecents", "RuntimeException:\n%s", e);
1109 }
1110 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001111 }
1112
Eric Erfanianccca3152017-02-22 16:32:36 -08001113 @Nullable
1114 public FragmentManager getDialpadFragmentManager() {
wangqifd4c9f72018-03-08 18:21:50 -08001115 InCallScreen inCallScreen = getInCallOrRttCallScreen();
Eric Erfanianccca3152017-02-22 16:32:36 -08001116 if (inCallScreen != null) {
1117 return inCallScreen.getInCallScreenFragment().getChildFragmentManager();
1118 }
1119 return null;
1120 }
1121
1122 public int getDialpadContainerId() {
wangqifd4c9f72018-03-08 18:21:50 -08001123 return getInCallOrRttCallScreen().getAnswerAndDialpadContainerResourceId();
Eric Erfanianccca3152017-02-22 16:32:36 -08001124 }
1125
1126 @Override
1127 public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) {
1128 DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId());
1129 if (call == null) {
1130 // This is a work around for a bug where we attempt to create a new delegate after the call
1131 // has already been removed. An example of when this can happen is:
1132 // 1. incoming video call in landscape mode
1133 // 2. remote party hangs up
1134 // 3. activity switches from landscape to portrait
1135 // At step #3 the answer fragment will try to create a new answer delegate but the call won't
1136 // exist. In this case we'll simply return a stub delegate that does nothing. This is ok
1137 // because this new state is transient and the activity will be destroyed soon.
1138 LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub");
1139 return new AnswerScreenPresenterStub();
1140 } else {
1141 return new AnswerScreenPresenter(
1142 this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId()));
1143 }
1144 }
1145
1146 @Override
1147 public InCallScreenDelegate newInCallScreenDelegate() {
1148 return new CallCardPresenter(this);
1149 }
1150
1151 @Override
1152 public InCallButtonUiDelegate newInCallButtonUiDelegate() {
1153 return new CallButtonPresenter(this);
1154 }
1155
1156 @Override
Eric Erfanian90508232017-03-24 09:31:16 -07001157 public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) {
1158 DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId());
1159 if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) {
1160 return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen);
1161 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001162 return new VideoCallPresenter();
1163 }
1164
1165 public void onPrimaryCallStateChanged() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001166 Trace.beginSection("InCallActivity.onPrimaryCallStateChanged");
Eric Erfanianccca3152017-02-22 16:32:36 -08001167 showMainInCallFragment();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001168 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001169 }
1170
linyuh7b86f562017-11-16 11:24:09 -08001171 public void showToastForWiFiToLteHandover(DialerCall call) {
1172 if (call.hasShownWiFiToLteHandoverToast()) {
1173 return;
1174 }
1175
1176 Toast.makeText(this, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG).show();
1177 call.setHasShownWiFiToLteHandoverToast();
Eric Erfanianccca3152017-02-22 16:32:36 -08001178 }
1179
linyuh7b86f562017-11-16 11:24:09 -08001180 public void showDialogOrToastForWifiHandoverFailure(DialerCall call) {
1181 if (call.showWifiHandoverAlertAsToast()) {
1182 Toast.makeText(this, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT)
1183 .show();
1184 return;
1185 }
1186
1187 dismissPendingDialogs();
1188
1189 AlertDialog.Builder builder =
1190 new AlertDialog.Builder(this).setTitle(R.string.video_call_lte_to_wifi_failed_title);
1191
1192 // This allows us to use the theme of the dialog instead of the activity
1193 View dialogCheckBoxView =
1194 View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null /* root */);
1195 CheckBox wifiHandoverFailureCheckbox =
1196 (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox);
1197 wifiHandoverFailureCheckbox.setChecked(false);
1198
1199 InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog");
linyuhc3968e62017-11-20 17:40:50 -08001200 errorDialog =
linyuh7b86f562017-11-16 11:24:09 -08001201 builder
1202 .setView(dialogCheckBoxView)
1203 .setMessage(R.string.video_call_lte_to_wifi_failed_message)
1204 .setOnCancelListener(dialogInterface -> onDialogDismissed())
1205 .setPositiveButton(
1206 android.R.string.ok,
1207 (dialogInterface, id) -> {
1208 call.setDoNotShowDialogForHandoffToWifiFailure(
1209 wifiHandoverFailureCheckbox.isChecked());
1210 dialogInterface.cancel();
1211 onDialogDismissed();
1212 })
1213 .setOnDismissListener(dialogInterface -> lock.release())
1214 .create();
linyuh7b86f562017-11-16 11:24:09 -08001215 errorDialog.show();
Eric Erfanianccca3152017-02-22 16:32:36 -08001216 }
1217
linyuh7b86f562017-11-16 11:24:09 -08001218 public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) {
1219 if (!InternationalCallOnWifiDialogFragment.shouldShow(this)) {
1220 LogUtil.i(
1221 "InCallActivity.showDialogForInternationalCallOnWifi",
1222 "InternationalCallOnWifiDialogFragment.shouldShow returned false");
1223 return;
1224 }
1225
1226 InternationalCallOnWifiDialogFragment fragment =
1227 InternationalCallOnWifiDialogFragment.newInstance(
linyuhc3968e62017-11-20 17:40:50 -08001228 call.getId(), internationalCallOnWifiCallback);
1229 fragment.show(getSupportFragmentManager(), Tags.INTERNATIONAL_CALL_ON_WIFI);
Eric Erfanianc857f902017-05-15 14:05:33 -07001230 }
1231
Eric Erfanian938468d2017-10-24 14:05:52 -07001232 @Override
1233 public void onMultiWindowModeChanged(boolean isInMultiWindowMode) {
1234 super.onMultiWindowModeChanged(isInMultiWindowMode);
linyuh57b093b2017-11-17 14:32:32 -08001235 updateNavigationBar(isDialpadVisible());
1236 }
1237
linyuhc3968e62017-11-20 17:40:50 -08001238 private void updateNavigationBar(boolean isDialpadVisible) {
linyuh57b093b2017-11-17 14:32:32 -08001239 if (ActivityCompat.isInMultiWindowMode(this)) {
1240 return;
1241 }
1242
1243 View navigationBarBackground = getWindow().findViewById(R.id.navigation_bar_background);
1244 if (navigationBarBackground != null) {
1245 navigationBarBackground.setVisibility(isDialpadVisible ? View.VISIBLE : View.GONE);
Eric Erfanian938468d2017-10-24 14:05:52 -07001246 }
1247 }
1248
Eric Erfanianccca3152017-02-22 16:32:36 -08001249 public void setAllowOrientationChange(boolean allowOrientationChange) {
wangqi9982f0d2017-10-11 17:46:07 -07001250 if (this.allowOrientationChange == allowOrientationChange) {
1251 return;
1252 }
1253 this.allowOrientationChange = allowOrientationChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001254 if (!allowOrientationChange) {
1255 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_DISALLOW_ROTATION);
1256 } else {
1257 setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION);
1258 }
1259 enableInCallOrientationEventListener(allowOrientationChange);
1260 }
1261
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001262 public void hideMainInCallFragment() {
linyuhc3968e62017-11-20 17:40:50 -08001263 LogUtil.enterBlock("InCallActivity.hideMainInCallFragment");
1264 if (getCallCardFragmentVisible()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001265 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
1266 hideInCallScreenFragment(transaction);
1267 hideVideoCallScreenFragment(transaction);
1268 transaction.commitAllowingStateLoss();
1269 getSupportFragmentManager().executePendingTransactions();
1270 }
1271 }
1272
1273 private void showMainInCallFragment() {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001274 Trace.beginSection("InCallActivity.showMainInCallFragment");
Eric Erfanianccca3152017-02-22 16:32:36 -08001275 // If the activity's onStart method hasn't been called yet then defer doing any work.
1276 if (!isVisible) {
1277 LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001278 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001279 return;
1280 }
1281
1282 // Don't let this be reentrant.
1283 if (isInShowMainInCallFragment) {
1284 LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing");
Eric Erfanian2ca43182017-08-31 06:57:16 -07001285 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001286 return;
1287 }
1288
1289 isInShowMainInCallFragment = true;
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001290 ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi();
1291 ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi();
wangqi219b8702018-02-13 09:34:41 -08001292 ShouldShowUiResult shouldShowRttUi = getShouldShowRttUi();
erfaniand05d8992018-03-20 19:42:26 -07001293 ShouldShowUiResult shouldShowSpeakEasyUi = getShouldShowSpeakEasyUi();
Eric Erfanianccca3152017-02-22 16:32:36 -08001294 LogUtil.i(
1295 "InCallActivity.showMainInCallFragment",
wangqi219b8702018-02-13 09:34:41 -08001296 "shouldShowAnswerUi: %b, shouldShowRttUi: %b, shouldShowVideoUi: %b "
1297 + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowRttCallScreen: %b, "
erfaniand05d8992018-03-20 19:42:26 -07001298 + "didShowVideoCallScreen: %b"
1299 + "didShowSpeakEasyScreen: %b",
Eric Erfanianccca3152017-02-22 16:32:36 -08001300 shouldShowAnswerUi.shouldShow,
wangqi219b8702018-02-13 09:34:41 -08001301 shouldShowRttUi.shouldShow,
Eric Erfanian10b34a52017-05-04 08:23:17 -07001302 shouldShowVideoUi.shouldShow,
Eric Erfanianccca3152017-02-22 16:32:36 -08001303 didShowAnswerScreen,
1304 didShowInCallScreen,
wangqi219b8702018-02-13 09:34:41 -08001305 didShowRttCallScreen,
erfaniand05d8992018-03-20 19:42:26 -07001306 didShowVideoCallScreen,
1307 didShowSpeakEasyScreen);
Eric Erfanianccca3152017-02-22 16:32:36 -08001308 // Only video call ui allows orientation change.
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001309 setAllowOrientationChange(shouldShowVideoUi.shouldShow);
Eric Erfanianccca3152017-02-22 16:32:36 -08001310
1311 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
wangqi219b8702018-02-13 09:34:41 -08001312 boolean didChange;
Eric Erfanianccca3152017-02-22 16:32:36 -08001313 if (shouldShowAnswerUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001314 didChange = hideInCallScreenFragment(transaction);
1315 didChange |= hideVideoCallScreenFragment(transaction);
1316 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001317 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001318 didChange |= showAnswerScreenFragment(transaction, shouldShowAnswerUi.call);
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001319 } else if (shouldShowVideoUi.shouldShow) {
wangqi219b8702018-02-13 09:34:41 -08001320 didChange = hideInCallScreenFragment(transaction);
1321 didChange |= showVideoCallScreenFragment(transaction, shouldShowVideoUi.call);
1322 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001323 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001324 didChange |= hideAnswerScreenFragment(transaction);
1325 } else if (shouldShowRttUi.shouldShow) {
1326 didChange = hideInCallScreenFragment(transaction);
1327 didChange |= hideVideoCallScreenFragment(transaction);
1328 didChange |= hideAnswerScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001329 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001330 didChange |= showRttCallScreenFragment(transaction, shouldShowRttUi.call);
erfaniand05d8992018-03-20 19:42:26 -07001331 } else if (shouldShowSpeakEasyUi.shouldShow) {
1332 didChange = hideInCallScreenFragment(transaction);
1333 didChange |= hideVideoCallScreenFragment(transaction);
1334 didChange |= hideAnswerScreenFragment(transaction);
1335 didChange |= hideRttCallScreenFragment(transaction);
1336 didChange |= showSpeakEasyFragment(transaction, shouldShowSpeakEasyUi.call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001337 } else {
wangqi219b8702018-02-13 09:34:41 -08001338 didChange = showInCallScreenFragment(transaction);
1339 didChange |= hideVideoCallScreenFragment(transaction);
1340 didChange |= hideRttCallScreenFragment(transaction);
erfaniand05d8992018-03-20 19:42:26 -07001341 didChange |= hideSpeakEasyFragment(transaction);
wangqi219b8702018-02-13 09:34:41 -08001342 didChange |= hideAnswerScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001343 }
1344
wangqi219b8702018-02-13 09:34:41 -08001345 if (didChange) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001346 Trace.beginSection("InCallActivity.commitTransaction");
Eric Erfanianccca3152017-02-22 16:32:36 -08001347 transaction.commitNow();
Eric Erfanian2ca43182017-08-31 06:57:16 -07001348 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001349 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1350 }
1351 isInShowMainInCallFragment = false;
Eric Erfanian2ca43182017-08-31 06:57:16 -07001352 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -08001353 }
1354
erfaniand05d8992018-03-20 19:42:26 -07001355 private boolean showSpeakEasyFragment(FragmentTransaction transaction, DialerCall call) {
1356
1357 // TODO(erfanian): Support multiple speakeasy screens.
1358 if (didShowSpeakEasyScreen) {
1359 return false;
1360 }
1361
1362 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1363 if (speakEasyFragment.isPresent()) {
1364 transaction.add(R.id.main, speakEasyFragment.get(), Tags.SPEAK_EASY_SCREEN);
1365 didShowSpeakEasyScreen = true;
1366 return true;
1367 }
1368 return false;
1369 }
1370
1371 private Fragment getSpeakEasyScreen() {
1372 return getSupportFragmentManager().findFragmentByTag(Tags.SPEAK_EASY_SCREEN);
1373 }
1374
1375 private boolean hideSpeakEasyFragment(FragmentTransaction transaction) {
1376 if (!didShowSpeakEasyScreen) {
1377 return false;
1378 }
1379
1380 Fragment speakEasyFragment = getSpeakEasyScreen();
1381
1382 if (speakEasyFragment != null) {
1383 transaction.remove(speakEasyFragment);
1384 didShowSpeakEasyScreen = false;
1385 return true;
1386 }
1387 return false;
1388 }
1389
1390 public void setSpeakEasyCallManager(SpeakEasyCallManager speakEasyCallManager) {
1391 this.speakEasyCallManager = Assert.isNotNull(speakEasyCallManager);
1392 }
1393
1394 public SpeakEasyCallManager getSpeakEasyCallManager() {
1395 return speakEasyCallManager;
1396 }
1397
1398 private ShouldShowUiResult getShouldShowSpeakEasyUi() {
1399 SpeakEasyCallManager speakEasyCallManager = getSpeakEasyCallManager();
1400
1401 if (speakEasyCallManager == null) {
1402 return new ShouldShowUiResult(false, null);
1403 }
1404
1405 // TODO(erfanian): Get a better call?
1406 DialerCall call = CallList.getInstance().getActiveCall();
1407
1408 if (call == null) {
1409 return new ShouldShowUiResult(false, call);
1410 }
1411
1412 if (!call.isSpeakEasyCall() || !call.isSpeakEasyEligible()) {
1413 return new ShouldShowUiResult(false, call);
1414 }
1415
1416 Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call);
1417
1418 if (!speakEasyFragment.isPresent()) {
1419 return new ShouldShowUiResult(false, call);
1420 }
1421 return new ShouldShowUiResult(true, call);
1422 }
1423
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001424 private ShouldShowUiResult getShouldShowAnswerUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001425 DialerCall call = CallList.getInstance().getIncomingCall();
1426 if (call != null) {
1427 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001428 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001429 }
1430
1431 call = CallList.getInstance().getVideoUpgradeRequestCall();
1432 if (call != null) {
1433 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001434 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001435 }
1436
1437 // Check if we're showing the answer screen and the call is disconnected. If this condition is
1438 // true then we won't switch from the answer UI to the in call UI. This prevents flicker when
1439 // the user rejects an incoming call.
1440 call = CallList.getInstance().getFirstCall();
1441 if (call == null) {
1442 call = CallList.getInstance().getBackgroundCall();
1443 }
1444 if (didShowAnswerScreen && (call == null || call.getState() == State.DISCONNECTED)) {
1445 LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001446 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001447 }
1448
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001449 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001450 }
1451
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001452 private static ShouldShowUiResult getShouldShowVideoUi() {
Eric Erfanianccca3152017-02-22 16:32:36 -08001453 DialerCall call = CallList.getInstance().getFirstCall();
1454 if (call == null) {
1455 LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001456 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001457 }
1458
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001459 if (call.isVideoCall()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001460 LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001461 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001462 }
1463
linyuh8fbecce2017-12-18 13:53:09 -08001464 if (call.hasSentVideoUpgradeRequest() || call.hasReceivedVideoUpgradeRequest()) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001465 LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video");
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001466 return new ShouldShowUiResult(true, call);
Eric Erfanianccca3152017-02-22 16:32:36 -08001467 }
1468
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001469 return new ShouldShowUiResult(false, null);
Eric Erfanianccca3152017-02-22 16:32:36 -08001470 }
1471
wangqi219b8702018-02-13 09:34:41 -08001472 private static ShouldShowUiResult getShouldShowRttUi() {
1473 DialerCall call = CallList.getInstance().getFirstCall();
1474 if (call == null) {
1475 LogUtil.i("InCallActivity.getShouldShowRttUi", "null call");
1476 return new ShouldShowUiResult(false, null);
1477 }
1478
1479 if (call.isRttCall()) {
1480 LogUtil.i("InCallActivity.getShouldShowRttUi", "found rtt call");
1481 return new ShouldShowUiResult(true, call);
1482 }
1483
1484 if (call.hasSentRttUpgradeRequest()) {
1485 LogUtil.i("InCallActivity.getShouldShowRttUi", "upgrading to rtt");
1486 return new ShouldShowUiResult(true, call);
1487 }
1488
1489 return new ShouldShowUiResult(false, null);
1490 }
1491
Eric Erfanianccca3152017-02-22 16:32:36 -08001492 private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) {
1493 // When rejecting a call the active call can become null in which case we should continue
1494 // showing the answer screen.
1495 if (didShowAnswerScreen && call == null) {
1496 return false;
1497 }
1498
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001499 Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null");
1500
1501 boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest();
Eric Erfanianccca3152017-02-22 16:32:36 -08001502
1503 // Check if we're already showing an answer screen for this call.
1504 if (didShowAnswerScreen) {
1505 AnswerScreen answerScreen = getAnswerScreen();
1506 if (answerScreen.getCallId().equals(call.getId())
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001507 && answerScreen.isVideoCall() == call.isVideoCall()
Eric Erfanian2ca43182017-08-31 06:57:16 -07001508 && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest
1509 && !answerScreen.isActionTimeout()) {
1510 LogUtil.d(
1511 "InCallActivity.showAnswerScreenFragment",
1512 "answer fragment exists for same call and has NOT been accepted/rejected/timed out");
Eric Erfanianccca3152017-02-22 16:32:36 -08001513 return false;
1514 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001515 if (answerScreen.isActionTimeout()) {
1516 LogUtil.i(
1517 "InCallActivity.showAnswerScreenFragment",
1518 "answer fragment exists but has been accepted/rejected and timed out");
1519 } else {
1520 LogUtil.i(
1521 "InCallActivity.showAnswerScreenFragment",
1522 "answer fragment exists but arguments do not match");
1523 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001524 hideAnswerScreenFragment(transaction);
1525 }
1526
1527 // Show a new answer screen.
1528 AnswerScreen answerScreen =
Eric Erfanianfc37b022017-03-21 10:11:17 -07001529 AnswerBindings.createAnswerScreen(
1530 call.getId(),
wangqi219b8702018-02-13 09:34:41 -08001531 call.isRttCall(),
Eric Erfanianfc37b022017-03-21 10:11:17 -07001532 call.isVideoCall(),
1533 isVideoUpgradeRequest,
Eric Erfanian90508232017-03-24 09:31:16 -07001534 call.getVideoTech().isSelfManagedCamera(),
1535 shouldAllowAnswerAndRelease(call),
erfaniand05d8992018-03-20 19:42:26 -07001536 CallList.getInstance().getBackgroundCall() != null,
1537 call.isSpeakEasyEligible());
linyuhc3968e62017-11-20 17:40:50 -08001538 transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001539
1540 Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this);
1541 didShowAnswerScreen = true;
1542 return true;
1543 }
1544
Eric Erfanian90508232017-03-24 09:31:16 -07001545 private boolean shouldAllowAnswerAndRelease(DialerCall call) {
1546 if (CallList.getInstance().getActiveCall() == null) {
1547 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call");
1548 return false;
1549 }
1550 if (getSystemService(TelephonyManager.class).getPhoneType()
1551 == TelephonyManager.PHONE_TYPE_CDMA) {
1552 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported");
1553 return false;
1554 }
1555 if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) {
1556 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call");
1557 return false;
1558 }
linyuhc3968e62017-11-20 17:40:50 -08001559 if (!ConfigProviderBindings.get(this)
1560 .getBoolean(ConfigNames.ANSWER_AND_RELEASE_ENABLED, true)) {
Eric Erfanian90508232017-03-24 09:31:16 -07001561 LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config");
1562 return false;
1563 }
1564
1565 return true;
1566 }
1567
Eric Erfanianccca3152017-02-22 16:32:36 -08001568 private boolean hideAnswerScreenFragment(FragmentTransaction transaction) {
1569 if (!didShowAnswerScreen) {
1570 return false;
1571 }
1572 AnswerScreen answerScreen = getAnswerScreen();
1573 if (answerScreen != null) {
1574 transaction.remove(answerScreen.getAnswerScreenFragment());
1575 }
1576
1577 didShowAnswerScreen = false;
1578 return true;
1579 }
1580
1581 private boolean showInCallScreenFragment(FragmentTransaction transaction) {
1582 if (didShowInCallScreen) {
1583 return false;
1584 }
Eric Erfanian2ca43182017-08-31 06:57:16 -07001585 InCallScreen inCallScreen = InCallBindings.createInCallScreen();
linyuhc3968e62017-11-20 17:40:50 -08001586 transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001587 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1588 didShowInCallScreen = true;
1589 return true;
1590 }
1591
1592 private boolean hideInCallScreenFragment(FragmentTransaction transaction) {
1593 if (!didShowInCallScreen) {
1594 return false;
1595 }
1596 InCallScreen inCallScreen = getInCallScreen();
1597 if (inCallScreen != null) {
Eric Erfanian2ca43182017-08-31 06:57:16 -07001598 transaction.remove(inCallScreen.getInCallScreenFragment());
Eric Erfanianccca3152017-02-22 16:32:36 -08001599 }
1600 didShowInCallScreen = false;
1601 return true;
1602 }
1603
wangqi219b8702018-02-13 09:34:41 -08001604 private boolean showRttCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
1605 if (didShowRttCallScreen) {
1606 // This shouldn't happen since only one RTT call is allow at same time.
1607 if (!getRttCallScreen().getCallId().equals(call.getId())) {
1608 LogUtil.e("InCallActivity.showRttCallScreenFragment", "RTT call id doesn't match");
1609 }
1610 return false;
1611 }
1612 RttCallScreen rttCallScreen = RttBindings.createRttCallScreen(call.getId());
1613 transaction.add(R.id.main, rttCallScreen.getRttCallScreenFragment(), Tags.RTT_CALL_SCREEN);
1614 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1615 didShowRttCallScreen = true;
1616 return true;
1617 }
1618
1619 private boolean hideRttCallScreenFragment(FragmentTransaction transaction) {
1620 if (!didShowRttCallScreen) {
1621 return false;
1622 }
1623 RttCallScreen rttCallScreen = getRttCallScreen();
1624 if (rttCallScreen != null) {
1625 transaction.remove(rttCallScreen.getRttCallScreenFragment());
1626 }
1627 didShowRttCallScreen = false;
1628 return true;
1629 }
1630
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001631 private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001632 if (didShowVideoCallScreen) {
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001633 VideoCallScreen videoCallScreen = getVideoCallScreen();
1634 if (videoCallScreen.getCallId().equals(call.getId())) {
1635 return false;
1636 }
1637 LogUtil.i(
1638 "InCallActivity.showVideoCallScreenFragment",
1639 "video call fragment exists but arguments do not match");
1640 hideVideoCallScreenFragment(transaction);
Eric Erfanianccca3152017-02-22 16:32:36 -08001641 }
1642
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001643 LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call);
1644
Eric Erfanian90508232017-03-24 09:31:16 -07001645 VideoCallScreen videoCallScreen =
1646 VideoBindings.createVideoCallScreen(
1647 call.getId(), call.getVideoTech().shouldUseSurfaceView());
linyuhc3968e62017-11-20 17:40:50 -08001648 transaction.add(
1649 R.id.main, videoCallScreen.getVideoCallScreenFragment(), Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001650
1651 Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this);
1652 didShowVideoCallScreen = true;
1653 return true;
1654 }
1655
1656 private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) {
1657 if (!didShowVideoCallScreen) {
1658 return false;
1659 }
1660 VideoCallScreen videoCallScreen = getVideoCallScreen();
1661 if (videoCallScreen != null) {
1662 transaction.remove(videoCallScreen.getVideoCallScreenFragment());
1663 }
1664 didShowVideoCallScreen = false;
1665 return true;
1666 }
1667
linyuhc3968e62017-11-20 17:40:50 -08001668 private AnswerScreen getAnswerScreen() {
1669 return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(Tags.ANSWER_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001670 }
1671
linyuhc3968e62017-11-20 17:40:50 -08001672 private InCallScreen getInCallScreen() {
1673 return (InCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.IN_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001674 }
1675
linyuhc3968e62017-11-20 17:40:50 -08001676 private VideoCallScreen getVideoCallScreen() {
1677 return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.VIDEO_CALL_SCREEN);
Eric Erfanianccca3152017-02-22 16:32:36 -08001678 }
1679
wangqi219b8702018-02-13 09:34:41 -08001680 private RttCallScreen getRttCallScreen() {
1681 return (RttCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.RTT_CALL_SCREEN);
1682 }
1683
wangqifd4c9f72018-03-08 18:21:50 -08001684 private InCallScreen getInCallOrRttCallScreen() {
1685 InCallScreen inCallScreen = null;
1686 if (didShowInCallScreen) {
1687 inCallScreen = getInCallScreen();
1688 }
1689 if (didShowRttCallScreen) {
1690 inCallScreen = getRttCallScreen();
1691 }
1692 return inCallScreen;
1693 }
1694
Eric Erfanianccca3152017-02-22 16:32:36 -08001695 @Override
1696 public void onPseudoScreenStateChanged(boolean isOn) {
1697 LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn);
1698 pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE);
1699 }
1700
1701 /**
1702 * For some touch related issue, turning off the screen can be faked by drawing a black view over
1703 * the activity. All touch events started when the screen is "off" is rejected.
1704 *
1705 * @see PseudoScreenState
1706 */
1707 @Override
1708 public boolean dispatchTouchEvent(MotionEvent event) {
1709 // Reject any gesture that started when the screen is in the fake off state.
1710 if (touchDownWhenPseudoScreenOff) {
1711 if (event.getAction() == MotionEvent.ACTION_UP) {
1712 touchDownWhenPseudoScreenOff = false;
1713 }
1714 return true;
1715 }
1716 // Reject all touch event when the screen is in the fake off state.
1717 if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) {
1718 if (event.getAction() == MotionEvent.ACTION_DOWN) {
1719 touchDownWhenPseudoScreenOff = true;
1720 LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff");
1721 }
1722 return true;
1723 }
1724 return super.dispatchTouchEvent(event);
1725 }
1726
wangqi219b8702018-02-13 09:34:41 -08001727 @Override
1728 public RttCallScreenDelegate newRttCallScreenDelegate(RttCallScreen videoCallScreen) {
1729 return new RttCallPresenter();
1730 }
1731
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001732 private static class ShouldShowUiResult {
Eric Erfanianccca3152017-02-22 16:32:36 -08001733 public final boolean shouldShow;
1734 public final DialerCall call;
1735
Eric Erfaniand5e47f62017-03-15 14:41:07 -07001736 ShouldShowUiResult(boolean shouldShow, DialerCall call) {
Eric Erfanianccca3152017-02-22 16:32:36 -08001737 this.shouldShow = shouldShow;
1738 this.call = call;
1739 }
1740 }
linyuhc3968e62017-11-20 17:40:50 -08001741
1742 private static final class IntentExtraNames {
1743 static final String FOR_FULL_SCREEN = "InCallActivity.for_full_screen_intent";
1744 static final String NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call";
1745 static final String SHOW_DIALPAD = "InCallActivity.show_dialpad";
1746 }
1747
1748 private static final class KeysForSavedInstance {
1749 static final String DIALPAD_TEXT = "InCallActivity.dialpad_text";
1750 static final String DID_SHOW_ANSWER_SCREEN = "did_show_answer_screen";
1751 static final String DID_SHOW_IN_CALL_SCREEN = "did_show_in_call_screen";
1752 static final String DID_SHOW_VIDEO_CALL_SCREEN = "did_show_video_call_screen";
wangqi153af2f2018-02-15 16:21:49 -08001753 static final String DID_SHOW_RTT_CALL_SCREEN = "did_show_rtt_call_screen";
erfaniand05d8992018-03-20 19:42:26 -07001754 static final String DID_SHOW_SPEAK_EASY_SCREEN = "did_show_speak_easy_screen";
linyuhc3968e62017-11-20 17:40:50 -08001755 }
1756
1757 /** Request codes for pending intents. */
1758 public static final class PendingIntentRequestCodes {
1759 static final int NON_FULL_SCREEN = 0;
1760 static final int FULL_SCREEN = 1;
1761 static final int BUBBLE = 2;
1762 }
1763
1764 private static final class Tags {
1765 static final String ANSWER_SCREEN = "tag_answer_screen";
1766 static final String DIALPAD_FRAGMENT = "tag_dialpad_fragment";
1767 static final String IN_CALL_SCREEN = "tag_in_call_screen";
1768 static final String INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi";
1769 static final String SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment";
1770 static final String VIDEO_CALL_SCREEN = "tag_video_call_screen";
wangqi219b8702018-02-13 09:34:41 -08001771 static final String RTT_CALL_SCREEN = "tag_rtt_call_screen";
linyuhc3968e62017-11-20 17:40:50 -08001772 static final String POST_CHAR_DIALOG_FRAGMENT = "tag_post_char_dialog_fragment";
erfaniand05d8992018-03-20 19:42:26 -07001773 static final String SPEAK_EASY_SCREEN = "tag_speak_easy_screen";
linyuhc3968e62017-11-20 17:40:50 -08001774 }
1775
1776 private static final class ConfigNames {
1777 static final String ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled";
1778 }
1779
1780 private static final class InternationalCallOnWifiCallback
1781 implements InternationalCallOnWifiDialogFragment.Callback {
1782 private static final String TAG = InternationalCallOnWifiCallback.class.getCanonicalName();
1783
1784 @Override
1785 public void continueCall(@NonNull String callId) {
1786 LogUtil.i(TAG, "Continuing call with ID: %s", callId);
1787 }
1788
1789 @Override
1790 public void cancelCall(@NonNull String callId) {
1791 DialerCall call = CallList.getInstance().getCallById(callId);
1792 if (call == null) {
1793 LogUtil.i(TAG, "Call destroyed before the dialog is closed");
1794 return;
1795 }
1796
1797 LogUtil.i(TAG, "Disconnecting international call on WiFi");
1798 call.disconnect();
1799 }
1800 }
1801
1802 private static final class SelectPhoneAccountListener
1803 extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener {
1804 private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName();
1805
twyen73a74c32018-03-07 12:12:24 -08001806 private final Context appContext;
1807
1808 SelectPhoneAccountListener(Context appContext) {
1809 this.appContext = appContext;
1810 }
1811
linyuhc3968e62017-11-20 17:40:50 -08001812 @Override
1813 public void onPhoneAccountSelected(
1814 PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) {
1815 DialerCall call = CallList.getInstance().getCallById(callId);
1816 LogUtil.i(TAG, "Phone account select with call:\n%s", call);
1817
1818 if (call != null) {
twyen73a74c32018-03-07 12:12:24 -08001819 call.phoneAccountSelected(selectedAccountHandle, false);
1820 if (call.getPreferredAccountRecorder() != null) {
1821 call.getPreferredAccountRecorder().record(appContext, selectedAccountHandle, setDefault);
1822 }
linyuhc3968e62017-11-20 17:40:50 -08001823 }
1824 }
1825
1826 @Override
1827 public void onDialogDismissed(String callId) {
1828 DialerCall call = CallList.getInstance().getCallById(callId);
1829 LogUtil.i(TAG, "Disconnecting call:\n%s" + call);
1830
1831 if (call != null) {
1832 call.disconnect();
1833 }
1834 }
1835 }
Eric Erfanianccca3152017-02-22 16:32:36 -08001836}