Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.incallui; |
| 18 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
| 20 | import android.app.ActivityManager.AppTask; |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 21 | import android.app.ActivityManager.TaskDescription; |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 22 | import android.app.AlertDialog; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 23 | import android.app.Dialog; |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 24 | import android.app.KeyguardManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 27 | import android.content.res.Configuration; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 28 | import android.graphics.drawable.GradientDrawable; |
| 29 | import android.graphics.drawable.GradientDrawable.Orientation; |
| 30 | import android.os.Bundle; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 31 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 32 | import android.support.annotation.ColorInt; |
| 33 | import android.support.annotation.FloatRange; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 34 | import android.support.annotation.IntDef; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 35 | import android.support.annotation.NonNull; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 36 | import android.support.annotation.Nullable; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 37 | import android.support.annotation.VisibleForTesting; |
wangqi | bc28ea7 | 2018-04-02 16:23:00 -0700 | [diff] [blame] | 38 | import android.support.v4.app.DialogFragment; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 39 | import android.support.v4.app.Fragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 40 | import android.support.v4.app.FragmentManager; |
| 41 | import android.support.v4.app.FragmentTransaction; |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 42 | import android.support.v4.content.res.ResourcesCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 43 | import android.support.v4.graphics.ColorUtils; |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 44 | import android.telecom.Call; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 45 | import android.telecom.CallAudioState; |
| 46 | import android.telecom.PhoneAccountHandle; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 47 | import android.telephony.TelephonyManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 48 | import android.view.KeyEvent; |
| 49 | import android.view.MenuItem; |
| 50 | import android.view.MotionEvent; |
| 51 | import android.view.View; |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame] | 52 | import android.view.WindowManager; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 53 | import android.view.animation.Animation; |
| 54 | import android.view.animation.AnimationUtils; |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 55 | import android.widget.CheckBox; |
| 56 | import android.widget.Toast; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 57 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 58 | import com.android.dialer.animation.AnimUtils; |
| 59 | import com.android.dialer.animation.AnimationListenerAdapter; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 60 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 61 | import com.android.dialer.common.LogUtil; |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 62 | import com.android.dialer.common.concurrent.DialerExecutorComponent; |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 63 | import com.android.dialer.common.concurrent.ThreadUtil; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 64 | import com.android.dialer.configprovider.ConfigProviderBindings; |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 65 | import com.android.dialer.logging.DialerImpression.Type; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 66 | import com.android.dialer.logging.Logger; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 67 | import com.android.dialer.logging.ScreenEvent; |
zachh | 7a96dc7 | 2018-02-20 22:16:03 -0800 | [diff] [blame] | 68 | import com.android.dialer.metrics.Metrics; |
| 69 | import com.android.dialer.metrics.MetricsComponent; |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 70 | import com.android.dialer.preferredsim.PreferredAccountRecorder; |
| 71 | import com.android.dialer.preferredsim.PreferredAccountWorker; |
| 72 | import com.android.dialer.preferredsim.suggestion.SuggestionProvider; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 73 | import com.android.dialer.util.ViewUtil; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 74 | import com.android.incallui.answer.bindings.AnswerBindings; |
| 75 | import com.android.incallui.answer.protocol.AnswerScreen; |
| 76 | import com.android.incallui.answer.protocol.AnswerScreenDelegate; |
| 77 | import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory; |
| 78 | import com.android.incallui.answerproximitysensor.PseudoScreenState; |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 79 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 80 | import com.android.incallui.call.CallList; |
| 81 | import com.android.incallui.call.DialerCall; |
| 82 | import com.android.incallui.call.DialerCall.State; |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 83 | import com.android.incallui.call.TelecomAdapter; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 84 | import com.android.incallui.callpending.CallPendingActivity; |
| 85 | import com.android.incallui.disconnectdialog.DisconnectMessage; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 86 | import com.android.incallui.incall.bindings.InCallBindings; |
| 87 | import com.android.incallui.incall.protocol.InCallButtonUiDelegate; |
| 88 | import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory; |
| 89 | import com.android.incallui.incall.protocol.InCallScreen; |
| 90 | import com.android.incallui.incall.protocol.InCallScreenDelegate; |
| 91 | import com.android.incallui.incall.protocol.InCallScreenDelegateFactory; |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 92 | import com.android.incallui.incalluilock.InCallUiLock; |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 93 | import com.android.incallui.rtt.bindings.RttBindings; |
| 94 | import com.android.incallui.rtt.protocol.RttCallScreen; |
| 95 | import com.android.incallui.rtt.protocol.RttCallScreenDelegate; |
| 96 | import com.android.incallui.rtt.protocol.RttCallScreenDelegateFactory; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 97 | import com.android.incallui.speakeasy.SpeakEasyCallManager; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 98 | import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 99 | import com.android.incallui.video.bindings.VideoBindings; |
| 100 | import com.android.incallui.video.protocol.VideoCallScreen; |
| 101 | import com.android.incallui.video.protocol.VideoCallScreenDelegate; |
| 102 | import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 103 | import com.google.common.base.Optional; |
| 104 | import java.lang.annotation.Retention; |
| 105 | import java.lang.annotation.RetentionPolicy; |
| 106 | import java.util.ArrayList; |
| 107 | import java.util.List; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 108 | |
| 109 | /** Version of {@link InCallActivity} that shows the new UI */ |
| 110 | public class InCallActivity extends TransactionSafeFragmentActivity |
| 111 | implements AnswerScreenDelegateFactory, |
| 112 | InCallScreenDelegateFactory, |
| 113 | InCallButtonUiDelegateFactory, |
| 114 | VideoCallScreenDelegateFactory, |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 115 | RttCallScreenDelegateFactory, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 116 | PseudoScreenState.StateChangedListener { |
| 117 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 118 | @Retention(RetentionPolicy.SOURCE) |
| 119 | @IntDef({ |
| 120 | DIALPAD_REQUEST_NONE, |
| 121 | DIALPAD_REQUEST_SHOW, |
| 122 | DIALPAD_REQUEST_HIDE, |
| 123 | }) |
| 124 | @interface DialpadRequestType {} |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 125 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 126 | 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; |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 129 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 130 | private static Optional<Integer> audioRouteForTesting = Optional.absent(); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 131 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 132 | private final InternationalCallOnWifiCallback internationalCallOnWifiCallback = |
| 133 | new InternationalCallOnWifiCallback(); |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 134 | |
| 135 | private SelectPhoneAccountListener selectPhoneAccountListener; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 136 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 137 | private Animation dialpadSlideInAnimation; |
| 138 | private Animation dialpadSlideOutAnimation; |
| 139 | private Dialog errorDialog; |
| 140 | private GradientDrawable backgroundDrawable; |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 141 | private InCallOrientationEventListener inCallOrientationEventListener; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 142 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 149 | private boolean didShowAnswerScreen; |
| 150 | private boolean didShowInCallScreen; |
| 151 | private boolean didShowVideoCallScreen; |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 152 | private boolean didShowRttCallScreen; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 153 | private boolean didShowSpeakEasyScreen; |
erfanian | 612d13a | 2018-04-04 15:27:57 -0700 | [diff] [blame] | 154 | private String lastShownSpeakEasyScreenUniqueCallid = ""; |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame] | 155 | private boolean dismissKeyguard; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 156 | private boolean isInShowMainInCallFragment; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 157 | private boolean isRecreating; // whether the activity is going to be recreated |
| 158 | private boolean isVisible; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 159 | private boolean needDismissPendingDialogs; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 160 | private boolean showPostCharWaitDialogOnResume; |
| 161 | private boolean touchDownWhenPseudoScreenOff; |
| 162 | private int[] backgroundDrawableColors; |
| 163 | @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 164 | private SpeakEasyCallManager speakEasyCallManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 165 | |
| 166 | public static Intent getIntent( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 167 | Context context, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 168 | 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); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 171 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 176 | return intent; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | protected void onResumeFragments() { |
| 181 | super.onResumeFragments(); |
| 182 | if (needDismissPendingDialogs) { |
| 183 | dismissPendingDialogs(); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | @Override |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 188 | protected void onCreate(Bundle bundle) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 189 | Trace.beginSection("InCallActivity.onCreate"); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 190 | super.onCreate(bundle); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 191 | |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 192 | selectPhoneAccountListener = new SelectPhoneAccountListener(getApplicationContext()); |
| 193 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 194 | 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); |
wangqi | 153af2f | 2018-02-15 16:21:49 -0800 | [diff] [blame] | 198 | didShowRttCallScreen = bundle.getBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 199 | } |
| 200 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 201 | 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 | |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 255 | inCallOrientationEventListener = new InCallOrientationEventListener(this); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 256 | |
| 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 Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 263 | sendBroadcast(CallPendingActivity.getFinishBroadcast()); |
| 264 | Trace.endSection(); |
zachh | 7a96dc7 | 2018-02-20 22:16:03 -0800 | [diff] [blame] | 265 | 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 271 | } |
| 272 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 273 | 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 | |
linyuh | f79d1cb | 2017-12-15 17:49:56 -0800 | [diff] [blame] | 280 | // 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. |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 282 | final int audioRoute = getAudioRoute(); |
linyuh | f79d1cb | 2017-12-15 17:49:56 -0800 | [diff] [blame] | 283 | if (audioRoute != CallAudioState.ROUTE_BLUETOOTH |
| 284 | || CallList.getInstance().getIncomingCall() != null) { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 285 | 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). |
linyuh | 122fb0b | 2018-03-26 13:35:32 -0700 | [diff] [blame] | 325 | if (InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 326 | LogUtil.i( |
| 327 | "InCallActivity.internalResolveIntent", "Call with no valid accounts, disconnecting"); |
| 328 | outgoingCall.disconnect(); |
| 329 | } |
| 330 | |
| 331 | dismissKeyguard(true); |
| 332 | } |
| 333 | |
| 334 | if (showPhoneAccountSelectionDialog()) { |
| 335 | hideMainInCallFragment(); |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should |
| 341 | * be shown on launch. |
| 342 | * |
| 343 | * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code |
| 344 | * false} to indicate no change should be made to the dialpad visibility. |
| 345 | */ |
| 346 | private void relaunchedFromDialer(boolean showDialpad) { |
| 347 | showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE; |
| 348 | animateDialpadOnShow = true; |
| 349 | |
| 350 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 351 | // If there's only one line in use, AND it's on hold, then we're sure the user |
| 352 | // wants to use the dialpad toward the exact line, so un-hold the holding line. |
| 353 | DialerCall call = CallList.getInstance().getActiveOrBackgroundCall(); |
| 354 | if (call != null && call.getState() == State.ONHOLD) { |
| 355 | call.unhold(); |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Show a phone account selection dialog if there is a call waiting for phone account selection. |
| 362 | * |
| 363 | * @return true if the dialog was shown. |
| 364 | */ |
| 365 | private boolean showPhoneAccountSelectionDialog() { |
| 366 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 367 | if (waitingForAccountCall == null) { |
| 368 | return false; |
| 369 | } |
| 370 | |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 371 | DialerExecutorComponent.get(this) |
| 372 | .dialerExecutorFactory() |
| 373 | .createNonUiTaskBuilder(new PreferredAccountWorker(waitingForAccountCall.getNumber())) |
| 374 | .onSuccess( |
| 375 | (result -> { |
| 376 | if (result.getPhoneAccountHandle().isPresent()) { |
| 377 | Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_PREFERRED_USED); |
| 378 | selectPhoneAccountListener.onPhoneAccountSelected( |
| 379 | result.getPhoneAccountHandle().get(), false, waitingForAccountCall.getId()); |
| 380 | return; |
| 381 | } |
| 382 | if (result.getSuggestion().isPresent()) { |
| 383 | LogUtil.i( |
| 384 | "CallingAccountSelector.processPreferredAccount", |
| 385 | "SIM suggested: " + result.getSuggestion().get().reason); |
| 386 | if (result.getSuggestion().get().shouldAutoSelect) { |
| 387 | Logger.get(this).logImpression(Type.DUAL_SIM_SELECTION_SUGGESTION_AUTO_SELECTED); |
| 388 | LogUtil.i( |
| 389 | "CallingAccountSelector.processPreferredAccount", "Auto selected suggestion"); |
| 390 | selectPhoneAccountListener.onPhoneAccountSelected( |
| 391 | result.getSuggestion().get().phoneAccountHandle, |
| 392 | false, |
| 393 | waitingForAccountCall.getId()); |
| 394 | return; |
| 395 | } |
| 396 | } |
| 397 | Bundle extras = waitingForAccountCall.getIntentExtras(); |
| 398 | List<PhoneAccountHandle> phoneAccountHandles = |
| 399 | extras == null |
| 400 | ? new ArrayList<>() |
| 401 | : extras.getParcelableArrayList(Call.AVAILABLE_PHONE_ACCOUNTS); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 402 | |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 403 | waitingForAccountCall.setPreferredAccountRecorder( |
| 404 | new PreferredAccountRecorder( |
| 405 | waitingForAccountCall.getNumber(), |
| 406 | result.getSuggestion().orNull(), |
| 407 | result.getDataId().orNull())); |
| 408 | selectPhoneAccountDialogFragment = |
| 409 | SelectPhoneAccountDialogFragment.newInstance( |
| 410 | R.string.select_phone_account_for_calls, |
| 411 | result.getDataId().isPresent() /* canSetDefault */, |
| 412 | R.string.select_phone_account_for_calls_remember /* setDefaultResId */, |
| 413 | phoneAccountHandles, |
| 414 | selectPhoneAccountListener, |
| 415 | waitingForAccountCall.getId(), |
| 416 | SuggestionProvider.buildHint( |
| 417 | this, phoneAccountHandles, result.getSuggestion().orNull() /* hints */)); |
| 418 | selectPhoneAccountDialogFragment.show( |
| 419 | getFragmentManager(), Tags.SELECT_ACCOUNT_FRAGMENT); |
| 420 | })) |
| 421 | .build() |
| 422 | .executeParallel(this); |
| 423 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 424 | return true; |
| 425 | } |
| 426 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 427 | @Override |
| 428 | protected void onSaveInstanceState(Bundle out) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 429 | LogUtil.enterBlock("InCallActivity.onSaveInstanceState"); |
| 430 | |
| 431 | // TODO: DialpadFragment should handle this as part of its own state |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 432 | out.putBoolean(IntentExtraNames.SHOW_DIALPAD, isDialpadVisible()); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 433 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 434 | if (dialpadFragment != null) { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 435 | out.putString(KeysForSavedInstance.DIALPAD_TEXT, dialpadFragment.getDtmfText()); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 436 | } |
| 437 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 438 | out.putBoolean(KeysForSavedInstance.DID_SHOW_ANSWER_SCREEN, didShowAnswerScreen); |
| 439 | out.putBoolean(KeysForSavedInstance.DID_SHOW_IN_CALL_SCREEN, didShowInCallScreen); |
| 440 | out.putBoolean(KeysForSavedInstance.DID_SHOW_VIDEO_CALL_SCREEN, didShowVideoCallScreen); |
wangqi | 153af2f | 2018-02-15 16:21:49 -0800 | [diff] [blame] | 441 | out.putBoolean(KeysForSavedInstance.DID_SHOW_RTT_CALL_SCREEN, didShowRttCallScreen); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 442 | out.putBoolean(KeysForSavedInstance.DID_SHOW_SPEAK_EASY_SCREEN, didShowSpeakEasyScreen); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 443 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 444 | super.onSaveInstanceState(out); |
| 445 | isVisible = false; |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | protected void onStart() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 450 | Trace.beginSection("InCallActivity.onStart"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 451 | super.onStart(); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 452 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 453 | isVisible = true; |
| 454 | showMainInCallFragment(); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 455 | |
| 456 | InCallPresenter.getInstance().setActivity(this); |
| 457 | enableInCallOrientationEventListener( |
| 458 | getRequestedOrientation() |
| 459 | == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION); |
| 460 | InCallPresenter.getInstance().onActivityStarted(); |
| 461 | |
yueg | 10f6e82 | 2018-01-17 15:32:18 -0800 | [diff] [blame] | 462 | if (!isRecreating) { |
| 463 | InCallPresenter.getInstance().onUiShowing(true); |
| 464 | } |
| 465 | |
linyuh | 437ae95 | 2018-03-26 12:46:18 -0700 | [diff] [blame] | 466 | if (isInMultiWindowMode() && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 467 | // Hide the dialpad because there may not be enough room |
| 468 | showDialpadFragment(false, false); |
| 469 | } |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 470 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 471 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | @Override |
| 475 | protected void onResume() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 476 | Trace.beginSection("InCallActivity.onResume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 477 | super.onResume(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 478 | |
| 479 | if (!InCallPresenter.getInstance().isReadyForTearDown()) { |
| 480 | updateTaskDescription(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | // If there is a pending request to show or hide the dialpad, handle that now. |
| 484 | if (showDialpadRequest != DIALPAD_REQUEST_NONE) { |
| 485 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 486 | // Exit fullscreen so that the user has access to the dialpad hide/show button. |
| 487 | // This is important when showing the dialpad from within dialer. |
| 488 | InCallPresenter.getInstance().setFullScreen(false /* isFullScreen */, true /* force */); |
| 489 | |
| 490 | showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */); |
| 491 | animateDialpadOnShow = false; |
| 492 | |
| 493 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 494 | if (dialpadFragment != null) { |
| 495 | dialpadFragment.setDtmfText(dtmfTextToPrepopulate); |
| 496 | dtmfTextToPrepopulate = null; |
| 497 | } |
| 498 | } else { |
| 499 | LogUtil.i("InCallActivity.onResume", "Force-hide the dialpad"); |
| 500 | if (getDialpadFragment() != null) { |
| 501 | showDialpadFragment(false /* show */, false /* animate */); |
| 502 | } |
| 503 | } |
| 504 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 505 | } |
| 506 | updateNavigationBar(isDialpadVisible()); |
| 507 | |
| 508 | if (showPostCharWaitDialogOnResume) { |
| 509 | showDialogForPostCharWait(showPostCharWaitDialogCallId, showPostCharWaitDialogChars); |
| 510 | } |
| 511 | |
| 512 | CallList.getInstance() |
| 513 | .onInCallUiShown(getIntent().getBooleanExtra(IntentExtraNames.FOR_FULL_SCREEN, false)); |
| 514 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 515 | PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState(); |
| 516 | pseudoScreenState.addListener(this); |
| 517 | onPseudoScreenStateChanged(pseudoScreenState.isOn()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 518 | Trace.endSection(); |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 519 | // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume. |
| 520 | ThreadUtil.postDelayedOnUiThread( |
weijiaxu | c950a9b | 2017-11-06 16:39:04 -0800 | [diff] [blame] | 521 | () -> |
zachh | 7a96dc7 | 2018-02-20 22:16:03 -0800 | [diff] [blame] | 522 | MetricsComponent.get(this) |
| 523 | .metrics() |
| 524 | .recordMemory(Metrics.INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME), |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 525 | 1000); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 528 | @Override |
| 529 | protected void onPause() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 530 | Trace.beginSection("InCallActivity.onPause"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 531 | super.onPause(); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 532 | |
| 533 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 534 | if (dialpadFragment != null) { |
| 535 | dialpadFragment.onDialerKeyUp(null); |
| 536 | } |
| 537 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 538 | InCallPresenter.getInstance().getPseudoScreenState().removeListener(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 539 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | @Override |
| 543 | protected void onStop() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 544 | Trace.beginSection("InCallActivity.onStop"); |
wangqi | 4d705e5 | 2017-09-28 12:23:35 -0700 | [diff] [blame] | 545 | isVisible = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 546 | super.onStop(); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 547 | |
| 548 | // Disconnects the call waiting for a phone account when the activity is hidden (e.g., after the |
| 549 | // user presses the home button). |
| 550 | // Without this the pending call will get stuck on phone account selection and new calls can't |
| 551 | // be created. |
| 552 | // Skip this when the screen is locked since the activity may complete its current life cycle |
| 553 | // and restart. |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 554 | if (!isRecreating && !getSystemService(KeyguardManager.class).isKeyguardLocked()) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 555 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 556 | if (waitingForAccountCall != null) { |
| 557 | waitingForAccountCall.disconnect(); |
| 558 | } |
| 559 | } |
| 560 | |
| 561 | enableInCallOrientationEventListener(false); |
| 562 | InCallPresenter.getInstance().updateIsChangingConfigurations(); |
| 563 | InCallPresenter.getInstance().onActivityStopped(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 564 | if (!isRecreating) { |
yueg | 10f6e82 | 2018-01-17 15:32:18 -0800 | [diff] [blame] | 565 | InCallPresenter.getInstance().onUiShowing(false); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 566 | if (errorDialog != null) { |
| 567 | errorDialog.dismiss(); |
| 568 | } |
| 569 | } |
| 570 | |
yueg | 10f6e82 | 2018-01-17 15:32:18 -0800 | [diff] [blame] | 571 | if (isFinishing()) { |
| 572 | InCallPresenter.getInstance().unsetActivity(this); |
| 573 | } |
| 574 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 575 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | @Override |
| 579 | protected void onDestroy() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 580 | Trace.beginSection("InCallActivity.onDestroy"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 581 | super.onDestroy(); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 582 | |
| 583 | InCallPresenter.getInstance().unsetActivity(this); |
| 584 | InCallPresenter.getInstance().updateIsChangingConfigurations(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 585 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | @Override |
| 589 | public void finish() { |
| 590 | if (shouldCloseActivityOnFinish()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 591 | // When user select incall ui from recents after the call is disconnected, it tries to launch |
| 592 | // a new InCallActivity but InCallPresenter is already teared down at this point, which causes |
| 593 | // crash. |
| 594 | // By calling finishAndRemoveTask() instead of finish() the task associated with |
| 595 | // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in |
| 596 | // this case. |
| 597 | // |
| 598 | // Calling finish won't clear the task and normally when an activity finishes it shouldn't |
| 599 | // clear the task since there could be parent activity in the same task that's still alive. |
| 600 | // But InCallActivity is special since it's singleInstance which means it's root activity and |
| 601 | // only instance of activity in the task. So it should be safe to also remove task when |
| 602 | // finishing. |
| 603 | // It's also necessary in the sense of it's excluded from recents. So whenever the activity |
| 604 | // finishes, the task should also be removed since it doesn't make sense to go back to it in |
| 605 | // anyway anymore. |
| 606 | super.finishAndRemoveTask(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
| 610 | private boolean shouldCloseActivityOnFinish() { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 611 | if (!isVisible) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 612 | LogUtil.i( |
| 613 | "InCallActivity.shouldCloseActivityOnFinish", |
| 614 | "allowing activity to be closed because it's not visible"); |
| 615 | return true; |
| 616 | } |
| 617 | |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 618 | if (InCallPresenter.getInstance().isInCallUiLocked()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 619 | LogUtil.i( |
| 620 | "InCallActivity.shouldCloseActivityOnFinish", |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 621 | "in call ui is locked, not closing activity"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 622 | return false; |
| 623 | } |
| 624 | |
| 625 | LogUtil.i( |
| 626 | "InCallActivity.shouldCloseActivityOnFinish", |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 627 | "activity is visible and has no locks, allowing activity to close"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 628 | return true; |
| 629 | } |
| 630 | |
| 631 | @Override |
| 632 | protected void onNewIntent(Intent intent) { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 633 | LogUtil.enterBlock("InCallActivity.onNewIntent"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 634 | |
| 635 | // If the screen is off, we need to make sure it gets turned on for incoming calls. |
| 636 | // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works |
| 637 | // when the activity is first created. Therefore, to ensure the screen is turned on |
| 638 | // for the call waiting case, we recreate() the current activity. There should be no jank from |
| 639 | // this since the screen is already off and will remain so until our new activity is up. |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 640 | if (!isVisible) { |
| 641 | onNewIntent(intent, true /* isRecreating */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 642 | LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on."); |
| 643 | recreate(); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 644 | } else { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 645 | onNewIntent(intent, false /* isRecreating */); |
| 646 | } |
| 647 | } |
| 648 | |
yueg | a330535 | 2018-01-09 11:02:47 -0800 | [diff] [blame] | 649 | @VisibleForTesting |
| 650 | void onNewIntent(Intent intent, boolean isRecreating) { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 651 | this.isRecreating = isRecreating; |
| 652 | |
| 653 | // We're being re-launched with a new Intent. Since it's possible for a single InCallActivity |
| 654 | // instance to persist indefinitely (even if we finish() ourselves), this sequence can |
| 655 | // happen any time the InCallActivity needs to be displayed. |
| 656 | |
| 657 | // Stash away the new intent so that we can get it in the future by calling getIntent(). |
| 658 | // Otherwise getIntent() will return the original Intent from when we first got created. |
| 659 | setIntent(intent); |
| 660 | |
| 661 | // Activities are always paused before receiving a new intent, so we can count on our onResume() |
| 662 | // method being called next. |
| 663 | |
| 664 | // Just like in onCreate(), handle the intent. |
| 665 | // Skip if InCallActivity is going to be recreated since this will be called in onCreate(). |
| 666 | if (!isRecreating) { |
| 667 | internalResolveIntent(intent); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
| 671 | @Override |
| 672 | public void onBackPressed() { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 673 | LogUtil.enterBlock("InCallActivity.onBackPressed"); |
| 674 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 675 | if (!isVisible) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 676 | return; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 677 | } |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 678 | |
| 679 | if (!getCallCardFragmentVisible()) { |
| 680 | return; |
| 681 | } |
| 682 | |
| 683 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 684 | if (dialpadFragment != null && dialpadFragment.isVisible()) { |
| 685 | showDialpadFragment(false /* show */, true /* animate */); |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | if (CallList.getInstance().getIncomingCall() != null) { |
| 690 | LogUtil.i( |
| 691 | "InCallActivity.onBackPressed", |
| 692 | "Ignore the press of the back key when an incoming call is ringing"); |
| 693 | return; |
| 694 | } |
| 695 | |
| 696 | // Nothing special to do. Fall back to the default behavior. |
| 697 | super.onBackPressed(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | @Override |
| 701 | public boolean onOptionsItemSelected(MenuItem item) { |
| 702 | LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item); |
| 703 | if (item.getItemId() == android.R.id.home) { |
| 704 | onBackPressed(); |
| 705 | return true; |
| 706 | } |
| 707 | return super.onOptionsItemSelected(item); |
| 708 | } |
| 709 | |
| 710 | @Override |
| 711 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 712 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 713 | if (dialpadFragment != null |
| 714 | && dialpadFragment.isVisible() |
| 715 | && dialpadFragment.onDialerKeyUp(event)) { |
| 716 | return true; |
| 717 | } |
| 718 | |
| 719 | if (keyCode == KeyEvent.KEYCODE_CALL) { |
| 720 | // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it. |
| 721 | return true; |
| 722 | } |
| 723 | |
| 724 | return super.onKeyUp(keyCode, event); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 725 | } |
| 726 | |
| 727 | @Override |
| 728 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 729 | switch (keyCode) { |
| 730 | case KeyEvent.KEYCODE_CALL: |
| 731 | if (!InCallPresenter.getInstance().handleCallKey()) { |
| 732 | LogUtil.e( |
| 733 | "InCallActivity.onKeyDown", |
| 734 | "InCallPresenter should always handle KEYCODE_CALL in onKeyDown"); |
| 735 | } |
| 736 | // Always consume KEYCODE_CALL to ensure the PhoneWindow won't do anything with it. |
| 737 | return true; |
| 738 | |
| 739 | // Note that KEYCODE_ENDCALL isn't handled here as the standard system-wide handling of it |
| 740 | // is exactly what's needed, namely |
| 741 | // (1) "hang up" if there's an active call, or |
| 742 | // (2) "don't answer" if there's an incoming call. |
| 743 | // (See PhoneWindowManager for implementation details.) |
| 744 | |
| 745 | case KeyEvent.KEYCODE_CAMERA: |
| 746 | // Consume KEYCODE_CAMERA since it's easy to accidentally press the camera button. |
| 747 | return true; |
| 748 | |
| 749 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 750 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 751 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 752 | // Ringer silencing handled by PhoneWindowManager. |
| 753 | break; |
| 754 | |
| 755 | case KeyEvent.KEYCODE_MUTE: |
| 756 | TelecomAdapter.getInstance() |
| 757 | .mute(!AudioModeProvider.getInstance().getAudioState().isMuted()); |
| 758 | return true; |
| 759 | |
| 760 | case KeyEvent.KEYCODE_SLASH: |
| 761 | // When verbose logging is enabled, dump the view for debugging/testing purposes. |
| 762 | if (LogUtil.isVerboseEnabled()) { |
| 763 | View decorView = getWindow().getDecorView(); |
| 764 | LogUtil.v("InCallActivity.onKeyDown", "View dump:\n%s", decorView); |
| 765 | return true; |
| 766 | } |
| 767 | break; |
| 768 | |
| 769 | case KeyEvent.KEYCODE_EQUALS: |
| 770 | break; |
| 771 | |
| 772 | default: // fall out |
| 773 | } |
| 774 | |
| 775 | // Pass other key events to DialpadFragment's "onDialerKeyDown" method in case the user types |
| 776 | // in DTMF (Dual-tone multi-frequency signaling) code. |
| 777 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 778 | if (dialpadFragment != null |
| 779 | && dialpadFragment.isVisible() |
| 780 | && dialpadFragment.onDialerKeyDown(event)) { |
| 781 | return true; |
| 782 | } |
| 783 | |
| 784 | return super.onKeyDown(keyCode, event); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | public boolean isInCallScreenAnimating() { |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | public void showConferenceFragment(boolean show) { |
| 792 | if (show) { |
| 793 | startActivity(new Intent(this, ManageConferenceActivity.class)); |
| 794 | } |
| 795 | } |
| 796 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 797 | public void showDialpadFragment(boolean show, boolean animate) { |
| 798 | if (show == isDialpadVisible()) { |
| 799 | return; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 800 | } |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 801 | |
| 802 | FragmentManager dialpadFragmentManager = getDialpadFragmentManager(); |
| 803 | if (dialpadFragmentManager == null) { |
| 804 | LogUtil.i("InCallActivity.showDialpadFragment", "Unable to obtain a FragmentManager"); |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | if (!animate) { |
| 809 | if (show) { |
| 810 | showDialpadFragment(); |
| 811 | } else { |
| 812 | hideDialpadFragment(); |
| 813 | } |
| 814 | } else { |
| 815 | if (show) { |
| 816 | showDialpadFragment(); |
| 817 | getDialpadFragment().animateShowDialpad(); |
| 818 | } |
| 819 | getDialpadFragment() |
| 820 | .getView() |
| 821 | .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation); |
| 822 | } |
| 823 | |
| 824 | ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor(); |
| 825 | if (sensor != null) { |
| 826 | sensor.onDialpadVisible(show); |
| 827 | } |
| 828 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 829 | |
| 830 | // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB |
| 831 | // repositions itself. |
wangqi | fd4c9f7 | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 832 | getInCallOrRttCallScreen().onInCallScreenDialpadVisibilityChange(show); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | private void showDialpadFragment() { |
| 836 | FragmentManager dialpadFragmentManager = getDialpadFragmentManager(); |
| 837 | if (dialpadFragmentManager == null) { |
| 838 | return; |
| 839 | } |
| 840 | |
| 841 | FragmentTransaction transaction = dialpadFragmentManager.beginTransaction(); |
| 842 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 843 | if (dialpadFragment == null) { |
wangqi | fd4c9f7 | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 844 | dialpadFragment = new DialpadFragment(); |
| 845 | transaction.add(getDialpadContainerId(), dialpadFragment, Tags.DIALPAD_FRAGMENT); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 846 | } else { |
| 847 | transaction.show(dialpadFragment); |
calderwoodra | d588387 | 2017-12-12 15:29:12 -0800 | [diff] [blame] | 848 | dialpadFragment.setUserVisibleHint(true); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 849 | } |
wangqi | fd4c9f7 | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 850 | // RTT call screen doesn't show end call button inside dialpad, thus the space reserved for end |
| 851 | // call button should be removed. |
| 852 | dialpadFragment.setShouldShowEndCallSpace(didShowInCallScreen); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 853 | transaction.commitAllowingStateLoss(); |
| 854 | dialpadFragmentManager.executePendingTransactions(); |
| 855 | |
| 856 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, this); |
| 857 | updateNavigationBar(true /* isDialpadVisible */); |
| 858 | } |
| 859 | |
| 860 | private void hideDialpadFragment() { |
| 861 | FragmentManager dialpadFragmentManager = getDialpadFragmentManager(); |
| 862 | if (dialpadFragmentManager == null) { |
| 863 | return; |
| 864 | } |
| 865 | |
calderwoodra | d588387 | 2017-12-12 15:29:12 -0800 | [diff] [blame] | 866 | DialpadFragment dialpadFragment = getDialpadFragment(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 867 | if (dialpadFragment != null) { |
| 868 | FragmentTransaction transaction = dialpadFragmentManager.beginTransaction(); |
| 869 | transaction.hide(dialpadFragment); |
| 870 | transaction.commitAllowingStateLoss(); |
| 871 | dialpadFragmentManager.executePendingTransactions(); |
calderwoodra | d588387 | 2017-12-12 15:29:12 -0800 | [diff] [blame] | 872 | dialpadFragment.setUserVisibleHint(false); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 873 | } |
| 874 | updateNavigationBar(false /* isDialpadVisible */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 875 | } |
| 876 | |
| 877 | public boolean isDialpadVisible() { |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 878 | DialpadFragment dialpadFragment = getDialpadFragment(); |
calderwoodra | a584bcd | 2018-01-24 12:19:56 -0800 | [diff] [blame] | 879 | return dialpadFragment != null |
| 880 | && dialpadFragment.isAdded() |
| 881 | && !dialpadFragment.isHidden() |
| 882 | && dialpadFragment.getView() != null |
| 883 | && dialpadFragment.getUserVisibleHint(); |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 884 | } |
| 885 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 886 | /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */ |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 887 | @Nullable |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 888 | private DialpadFragment getDialpadFragment() { |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 889 | FragmentManager fragmentManager = getDialpadFragmentManager(); |
| 890 | if (fragmentManager == null) { |
| 891 | return null; |
| 892 | } |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 893 | return (DialpadFragment) fragmentManager.findFragmentByTag(Tags.DIALPAD_FRAGMENT); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | public void onForegroundCallChanged(DialerCall newForegroundCall) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 897 | updateTaskDescription(); |
| 898 | |
| 899 | if (newForegroundCall == null || !didShowAnswerScreen) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 900 | LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color"); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 901 | updateWindowBackgroundColor(0 /* progress */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 905 | private void updateTaskDescription() { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 906 | int color = |
| 907 | getResources().getBoolean(R.bool.is_layout_landscape) |
| 908 | ? ResourcesCompat.getColor( |
| 909 | getResources(), R.color.statusbar_background_color, getTheme()) |
| 910 | : InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor(); |
| 911 | setTaskDescription( |
| 912 | new TaskDescription( |
| 913 | getResources().getString(R.string.notification_ongoing_call), null /* icon */, color)); |
| 914 | } |
| 915 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 916 | public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) { |
| 917 | ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager(); |
| 918 | @ColorInt int top; |
| 919 | @ColorInt int middle; |
| 920 | @ColorInt int bottom; |
| 921 | @ColorInt int gray = 0x66000000; |
| 922 | |
linyuh | 437ae95 | 2018-03-26 12:46:18 -0700 | [diff] [blame] | 923 | if (isInMultiWindowMode()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 924 | top = themeColorManager.getBackgroundColorSolid(); |
| 925 | middle = themeColorManager.getBackgroundColorSolid(); |
| 926 | bottom = themeColorManager.getBackgroundColorSolid(); |
| 927 | } else { |
| 928 | top = themeColorManager.getBackgroundColorTop(); |
| 929 | middle = themeColorManager.getBackgroundColorMiddle(); |
| 930 | bottom = themeColorManager.getBackgroundColorBottom(); |
| 931 | } |
| 932 | |
| 933 | if (progress < 0) { |
| 934 | float correctedProgress = Math.abs(progress); |
| 935 | top = ColorUtils.blendARGB(top, gray, correctedProgress); |
| 936 | middle = ColorUtils.blendARGB(middle, gray, correctedProgress); |
| 937 | bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress); |
| 938 | } |
| 939 | |
| 940 | boolean backgroundDirty = false; |
| 941 | if (backgroundDrawable == null) { |
| 942 | backgroundDrawableColors = new int[] {top, middle, bottom}; |
| 943 | backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors); |
| 944 | backgroundDirty = true; |
| 945 | } else { |
| 946 | if (backgroundDrawableColors[0] != top) { |
| 947 | backgroundDrawableColors[0] = top; |
| 948 | backgroundDirty = true; |
| 949 | } |
| 950 | if (backgroundDrawableColors[1] != middle) { |
| 951 | backgroundDrawableColors[1] = middle; |
| 952 | backgroundDirty = true; |
| 953 | } |
| 954 | if (backgroundDrawableColors[2] != bottom) { |
| 955 | backgroundDrawableColors[2] = bottom; |
| 956 | backgroundDirty = true; |
| 957 | } |
| 958 | if (backgroundDirty) { |
| 959 | backgroundDrawable.setColors(backgroundDrawableColors); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | if (backgroundDirty) { |
| 964 | getWindow().setBackgroundDrawable(backgroundDrawable); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | public boolean isVisible() { |
| 969 | return isVisible; |
| 970 | } |
| 971 | |
| 972 | public boolean getCallCardFragmentVisible() { |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 973 | return didShowInCallScreen |
| 974 | || didShowVideoCallScreen |
| 975 | || didShowRttCallScreen |
| 976 | || didShowSpeakEasyScreen; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | public void dismissKeyguard(boolean dismiss) { |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame] | 980 | if (dismissKeyguard == dismiss) { |
| 981 | return; |
| 982 | } |
| 983 | |
| 984 | dismissKeyguard = dismiss; |
| 985 | if (dismiss) { |
| 986 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
| 987 | } else { |
| 988 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
| 989 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 990 | } |
| 991 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 992 | public void showDialogForPostCharWait(String callId, String chars) { |
| 993 | if (isVisible) { |
| 994 | PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars); |
| 995 | fragment.show(getSupportFragmentManager(), Tags.POST_CHAR_DIALOG_FRAGMENT); |
| 996 | |
| 997 | showPostCharWaitDialogOnResume = false; |
| 998 | showPostCharWaitDialogCallId = null; |
| 999 | showPostCharWaitDialogChars = null; |
| 1000 | } else { |
| 1001 | showPostCharWaitDialogOnResume = true; |
| 1002 | showPostCharWaitDialogCallId = callId; |
| 1003 | showPostCharWaitDialogChars = chars; |
| 1004 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1005 | } |
| 1006 | |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1007 | public void showDialogOrToastForDisconnectedCall(DisconnectMessage disconnectMessage) { |
| 1008 | LogUtil.i( |
| 1009 | "InCallActivity.showDialogOrToastForDisconnectedCall", |
| 1010 | "disconnect cause: %s", |
| 1011 | disconnectMessage); |
| 1012 | |
| 1013 | if (disconnectMessage.dialog == null || isFinishing()) { |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | dismissPendingDialogs(); |
| 1018 | |
| 1019 | // Show a toast if the app is in background when a dialog can't be visible. |
| 1020 | if (!isVisible()) { |
| 1021 | Toast.makeText(getApplicationContext(), disconnectMessage.toastMessage, Toast.LENGTH_LONG) |
| 1022 | .show(); |
| 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | // Show the dialog. |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1027 | errorDialog = disconnectMessage.dialog; |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1028 | InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog"); |
| 1029 | disconnectMessage.dialog.setOnDismissListener( |
| 1030 | dialogInterface -> { |
| 1031 | lock.release(); |
| 1032 | onDialogDismissed(); |
| 1033 | }); |
| 1034 | disconnectMessage.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 1035 | disconnectMessage.dialog.show(); |
| 1036 | } |
| 1037 | |
| 1038 | private void onDialogDismissed() { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1039 | errorDialog = null; |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1040 | CallList.getInstance().onErrorDialogDismissed(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | public void dismissPendingDialogs() { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1044 | LogUtil.enterBlock("InCallActivity.dismissPendingDialogs"); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1045 | |
| 1046 | if (!isVisible) { |
| 1047 | // Defer the dismissing action as the activity is not visible and onSaveInstanceState may have |
| 1048 | // been called. |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1049 | LogUtil.i( |
| 1050 | "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible"); |
| 1051 | needDismissPendingDialogs = true; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1052 | return; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1053 | } |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1054 | |
| 1055 | // Dismiss the error dialog |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1056 | if (errorDialog != null) { |
| 1057 | errorDialog.dismiss(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1058 | errorDialog = null; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | // Dismiss the phone account selection dialog |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1062 | if (selectPhoneAccountDialogFragment != null) { |
| 1063 | selectPhoneAccountDialogFragment.dismiss(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1064 | selectPhoneAccountDialogFragment = null; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | // Dismiss the dialog for international call on WiFi |
| 1068 | InternationalCallOnWifiDialogFragment internationalCallOnWifiFragment = |
| 1069 | (InternationalCallOnWifiDialogFragment) |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1070 | getSupportFragmentManager().findFragmentByTag(Tags.INTERNATIONAL_CALL_ON_WIFI); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 1071 | if (internationalCallOnWifiFragment != null) { |
| 1072 | internationalCallOnWifiFragment.dismiss(); |
| 1073 | } |
| 1074 | |
| 1075 | // Dismiss the answer screen |
| 1076 | AnswerScreen answerScreen = getAnswerScreen(); |
| 1077 | if (answerScreen != null) { |
| 1078 | answerScreen.dismissPendingDialogs(); |
| 1079 | } |
| 1080 | |
| 1081 | needDismissPendingDialogs = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1084 | private void enableInCallOrientationEventListener(boolean enable) { |
linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 1085 | if (enable) { |
| 1086 | inCallOrientationEventListener.enable(true /* notifyDeviceOrientationChange */); |
| 1087 | } else { |
| 1088 | inCallOrientationEventListener.disable(); |
| 1089 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | public void setExcludeFromRecents(boolean exclude) { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1093 | int taskId = getTaskId(); |
| 1094 | |
| 1095 | List<AppTask> tasks = getSystemService(ActivityManager.class).getAppTasks(); |
| 1096 | for (AppTask task : tasks) { |
| 1097 | try { |
| 1098 | if (task.getTaskInfo().id == taskId) { |
| 1099 | task.setExcludeFromRecents(exclude); |
| 1100 | } |
| 1101 | } catch (RuntimeException e) { |
| 1102 | LogUtil.e("InCallActivity.setExcludeFromRecents", "RuntimeException:\n%s", e); |
| 1103 | } |
| 1104 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1105 | } |
| 1106 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1107 | @Nullable |
| 1108 | public FragmentManager getDialpadFragmentManager() { |
wangqi | fd4c9f7 | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1109 | InCallScreen inCallScreen = getInCallOrRttCallScreen(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1110 | if (inCallScreen != null) { |
| 1111 | return inCallScreen.getInCallScreenFragment().getChildFragmentManager(); |
| 1112 | } |
| 1113 | return null; |
| 1114 | } |
| 1115 | |
| 1116 | public int getDialpadContainerId() { |
wangqi | fd4c9f7 | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1117 | return getInCallOrRttCallScreen().getAnswerAndDialpadContainerResourceId(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | @Override |
| 1121 | public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) { |
| 1122 | DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId()); |
| 1123 | if (call == null) { |
| 1124 | // This is a work around for a bug where we attempt to create a new delegate after the call |
| 1125 | // has already been removed. An example of when this can happen is: |
| 1126 | // 1. incoming video call in landscape mode |
| 1127 | // 2. remote party hangs up |
| 1128 | // 3. activity switches from landscape to portrait |
| 1129 | // At step #3 the answer fragment will try to create a new answer delegate but the call won't |
| 1130 | // exist. In this case we'll simply return a stub delegate that does nothing. This is ok |
| 1131 | // because this new state is transient and the activity will be destroyed soon. |
| 1132 | LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub"); |
| 1133 | return new AnswerScreenPresenterStub(); |
| 1134 | } else { |
| 1135 | return new AnswerScreenPresenter( |
| 1136 | this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId())); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | @Override |
| 1141 | public InCallScreenDelegate newInCallScreenDelegate() { |
| 1142 | return new CallCardPresenter(this); |
| 1143 | } |
| 1144 | |
| 1145 | @Override |
| 1146 | public InCallButtonUiDelegate newInCallButtonUiDelegate() { |
| 1147 | return new CallButtonPresenter(this); |
| 1148 | } |
| 1149 | |
| 1150 | @Override |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1151 | public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) { |
| 1152 | DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId()); |
| 1153 | if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) { |
| 1154 | return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen); |
| 1155 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1156 | return new VideoCallPresenter(); |
| 1157 | } |
| 1158 | |
| 1159 | public void onPrimaryCallStateChanged() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1160 | Trace.beginSection("InCallActivity.onPrimaryCallStateChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1161 | showMainInCallFragment(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1162 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1163 | } |
| 1164 | |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1165 | public void showToastForWiFiToLteHandover(DialerCall call) { |
| 1166 | if (call.hasShownWiFiToLteHandoverToast()) { |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | Toast.makeText(this, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG).show(); |
| 1171 | call.setHasShownWiFiToLteHandoverToast(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1172 | } |
| 1173 | |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1174 | public void showDialogOrToastForWifiHandoverFailure(DialerCall call) { |
| 1175 | if (call.showWifiHandoverAlertAsToast()) { |
| 1176 | Toast.makeText(this, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT) |
| 1177 | .show(); |
| 1178 | return; |
| 1179 | } |
| 1180 | |
| 1181 | dismissPendingDialogs(); |
| 1182 | |
| 1183 | AlertDialog.Builder builder = |
| 1184 | new AlertDialog.Builder(this).setTitle(R.string.video_call_lte_to_wifi_failed_title); |
| 1185 | |
| 1186 | // This allows us to use the theme of the dialog instead of the activity |
| 1187 | View dialogCheckBoxView = |
| 1188 | View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null /* root */); |
| 1189 | CheckBox wifiHandoverFailureCheckbox = |
| 1190 | (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox); |
| 1191 | wifiHandoverFailureCheckbox.setChecked(false); |
| 1192 | |
| 1193 | InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog"); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1194 | errorDialog = |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1195 | builder |
| 1196 | .setView(dialogCheckBoxView) |
| 1197 | .setMessage(R.string.video_call_lte_to_wifi_failed_message) |
| 1198 | .setOnCancelListener(dialogInterface -> onDialogDismissed()) |
| 1199 | .setPositiveButton( |
| 1200 | android.R.string.ok, |
| 1201 | (dialogInterface, id) -> { |
| 1202 | call.setDoNotShowDialogForHandoffToWifiFailure( |
| 1203 | wifiHandoverFailureCheckbox.isChecked()); |
| 1204 | dialogInterface.cancel(); |
| 1205 | onDialogDismissed(); |
| 1206 | }) |
| 1207 | .setOnDismissListener(dialogInterface -> lock.release()) |
| 1208 | .create(); |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1209 | errorDialog.show(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 1212 | public void showDialogForInternationalCallOnWifi(@NonNull DialerCall call) { |
| 1213 | if (!InternationalCallOnWifiDialogFragment.shouldShow(this)) { |
| 1214 | LogUtil.i( |
| 1215 | "InCallActivity.showDialogForInternationalCallOnWifi", |
| 1216 | "InternationalCallOnWifiDialogFragment.shouldShow returned false"); |
| 1217 | return; |
| 1218 | } |
| 1219 | |
| 1220 | InternationalCallOnWifiDialogFragment fragment = |
| 1221 | InternationalCallOnWifiDialogFragment.newInstance( |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1222 | call.getId(), internationalCallOnWifiCallback); |
| 1223 | fragment.show(getSupportFragmentManager(), Tags.INTERNATIONAL_CALL_ON_WIFI); |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
wangqi | bc28ea7 | 2018-04-02 16:23:00 -0700 | [diff] [blame] | 1226 | public void showDialogForRttRequest(DialerCall call, int rttRequestId) { |
| 1227 | LogUtil.enterBlock("InCallActivity.showDialogForRttRequest"); |
| 1228 | DialogFragment fragment = RttRequestDialogFragment.newInstance(call.getId(), rttRequestId); |
| 1229 | fragment.show(getSupportFragmentManager(), Tags.RTT_REQUEST_DIALOG); |
| 1230 | } |
| 1231 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 1232 | @Override |
| 1233 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
| 1234 | super.onMultiWindowModeChanged(isInMultiWindowMode); |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 1235 | updateNavigationBar(isDialpadVisible()); |
| 1236 | } |
| 1237 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1238 | private void updateNavigationBar(boolean isDialpadVisible) { |
linyuh | 437ae95 | 2018-03-26 12:46:18 -0700 | [diff] [blame] | 1239 | if (isInMultiWindowMode()) { |
linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 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 Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 1246 | } |
| 1247 | } |
| 1248 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1249 | public void setAllowOrientationChange(boolean allowOrientationChange) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 1250 | if (this.allowOrientationChange == allowOrientationChange) { |
| 1251 | return; |
| 1252 | } |
| 1253 | this.allowOrientationChange = allowOrientationChange; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1254 | 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 Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1262 | public void hideMainInCallFragment() { |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1263 | LogUtil.enterBlock("InCallActivity.hideMainInCallFragment"); |
| 1264 | if (getCallCardFragmentVisible()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1265 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 1266 | hideInCallScreenFragment(transaction); |
| 1267 | hideVideoCallScreenFragment(transaction); |
| 1268 | transaction.commitAllowingStateLoss(); |
| 1269 | getSupportFragmentManager().executePendingTransactions(); |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | private void showMainInCallFragment() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1274 | Trace.beginSection("InCallActivity.showMainInCallFragment"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1275 | // 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 Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1278 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1279 | return; |
| 1280 | } |
| 1281 | |
| 1282 | // Don't let this be reentrant. |
| 1283 | if (isInShowMainInCallFragment) { |
| 1284 | LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1285 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1286 | return; |
| 1287 | } |
| 1288 | |
| 1289 | isInShowMainInCallFragment = true; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1290 | ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi(); |
| 1291 | ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi(); |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1292 | ShouldShowUiResult shouldShowRttUi = getShouldShowRttUi(); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1293 | ShouldShowUiResult shouldShowSpeakEasyUi = getShouldShowSpeakEasyUi(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1294 | LogUtil.i( |
| 1295 | "InCallActivity.showMainInCallFragment", |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1296 | "shouldShowAnswerUi: %b, shouldShowRttUi: %b, shouldShowVideoUi: %b " |
| 1297 | + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowRttCallScreen: %b, " |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1298 | + "didShowVideoCallScreen: %b" |
| 1299 | + "didShowSpeakEasyScreen: %b", |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1300 | shouldShowAnswerUi.shouldShow, |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1301 | shouldShowRttUi.shouldShow, |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 1302 | shouldShowVideoUi.shouldShow, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1303 | didShowAnswerScreen, |
| 1304 | didShowInCallScreen, |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1305 | didShowRttCallScreen, |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1306 | didShowVideoCallScreen, |
| 1307 | didShowSpeakEasyScreen); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1308 | // Only video call ui allows orientation change. |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1309 | setAllowOrientationChange(shouldShowVideoUi.shouldShow); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1310 | |
| 1311 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1312 | boolean didChange; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1313 | if (shouldShowAnswerUi.shouldShow) { |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1314 | didChange = hideInCallScreenFragment(transaction); |
| 1315 | didChange |= hideVideoCallScreenFragment(transaction); |
| 1316 | didChange |= hideRttCallScreenFragment(transaction); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1317 | didChange |= hideSpeakEasyFragment(transaction); |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1318 | didChange |= showAnswerScreenFragment(transaction, shouldShowAnswerUi.call); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1319 | } else if (shouldShowVideoUi.shouldShow) { |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1320 | didChange = hideInCallScreenFragment(transaction); |
| 1321 | didChange |= showVideoCallScreenFragment(transaction, shouldShowVideoUi.call); |
| 1322 | didChange |= hideRttCallScreenFragment(transaction); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1323 | didChange |= hideSpeakEasyFragment(transaction); |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1324 | didChange |= hideAnswerScreenFragment(transaction); |
| 1325 | } else if (shouldShowRttUi.shouldShow) { |
| 1326 | didChange = hideInCallScreenFragment(transaction); |
| 1327 | didChange |= hideVideoCallScreenFragment(transaction); |
| 1328 | didChange |= hideAnswerScreenFragment(transaction); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1329 | didChange |= hideSpeakEasyFragment(transaction); |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1330 | didChange |= showRttCallScreenFragment(transaction, shouldShowRttUi.call); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1331 | } 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 Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1337 | } else { |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1338 | didChange = showInCallScreenFragment(transaction); |
| 1339 | didChange |= hideVideoCallScreenFragment(transaction); |
| 1340 | didChange |= hideRttCallScreenFragment(transaction); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1341 | didChange |= hideSpeakEasyFragment(transaction); |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1342 | didChange |= hideAnswerScreenFragment(transaction); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1343 | } |
| 1344 | |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1345 | if (didChange) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1346 | Trace.beginSection("InCallActivity.commitTransaction"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1347 | transaction.commitNow(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1348 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1349 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 1350 | } |
| 1351 | isInShowMainInCallFragment = false; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1352 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1355 | private boolean showSpeakEasyFragment(FragmentTransaction transaction, DialerCall call) { |
| 1356 | |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1357 | if (didShowSpeakEasyScreen) { |
erfanian | 612d13a | 2018-04-04 15:27:57 -0700 | [diff] [blame] | 1358 | if (lastShownSpeakEasyScreenUniqueCallid.equals(call.getUniqueCallId())) { |
| 1359 | return false; |
| 1360 | } |
| 1361 | hideSpeakEasyFragment(transaction); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call); |
| 1365 | if (speakEasyFragment.isPresent()) { |
| 1366 | transaction.add(R.id.main, speakEasyFragment.get(), Tags.SPEAK_EASY_SCREEN); |
| 1367 | didShowSpeakEasyScreen = true; |
erfanian | 612d13a | 2018-04-04 15:27:57 -0700 | [diff] [blame] | 1368 | lastShownSpeakEasyScreenUniqueCallid = call.getUniqueCallId(); |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1369 | return true; |
| 1370 | } |
| 1371 | return false; |
| 1372 | } |
| 1373 | |
| 1374 | private Fragment getSpeakEasyScreen() { |
| 1375 | return getSupportFragmentManager().findFragmentByTag(Tags.SPEAK_EASY_SCREEN); |
| 1376 | } |
| 1377 | |
| 1378 | private boolean hideSpeakEasyFragment(FragmentTransaction transaction) { |
| 1379 | if (!didShowSpeakEasyScreen) { |
| 1380 | return false; |
| 1381 | } |
| 1382 | |
| 1383 | Fragment speakEasyFragment = getSpeakEasyScreen(); |
| 1384 | |
| 1385 | if (speakEasyFragment != null) { |
| 1386 | transaction.remove(speakEasyFragment); |
| 1387 | didShowSpeakEasyScreen = false; |
| 1388 | return true; |
| 1389 | } |
| 1390 | return false; |
| 1391 | } |
| 1392 | |
| 1393 | public void setSpeakEasyCallManager(SpeakEasyCallManager speakEasyCallManager) { |
erfanian | 87dbb62 | 2018-04-04 15:43:00 -0700 | [diff] [blame^] | 1394 | this.speakEasyCallManager = speakEasyCallManager; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | public SpeakEasyCallManager getSpeakEasyCallManager() { |
| 1398 | return speakEasyCallManager; |
| 1399 | } |
| 1400 | |
| 1401 | private ShouldShowUiResult getShouldShowSpeakEasyUi() { |
| 1402 | SpeakEasyCallManager speakEasyCallManager = getSpeakEasyCallManager(); |
| 1403 | |
| 1404 | if (speakEasyCallManager == null) { |
| 1405 | return new ShouldShowUiResult(false, null); |
| 1406 | } |
| 1407 | |
| 1408 | // TODO(erfanian): Get a better call? |
| 1409 | DialerCall call = CallList.getInstance().getActiveCall(); |
| 1410 | |
| 1411 | if (call == null) { |
| 1412 | return new ShouldShowUiResult(false, call); |
| 1413 | } |
| 1414 | |
| 1415 | if (!call.isSpeakEasyCall() || !call.isSpeakEasyEligible()) { |
| 1416 | return new ShouldShowUiResult(false, call); |
| 1417 | } |
| 1418 | |
| 1419 | Optional<Fragment> speakEasyFragment = speakEasyCallManager.getSpeakEasyFragment(call); |
| 1420 | |
| 1421 | if (!speakEasyFragment.isPresent()) { |
| 1422 | return new ShouldShowUiResult(false, call); |
| 1423 | } |
| 1424 | return new ShouldShowUiResult(true, call); |
| 1425 | } |
| 1426 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1427 | private ShouldShowUiResult getShouldShowAnswerUi() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1428 | DialerCall call = CallList.getInstance().getIncomingCall(); |
| 1429 | if (call != null) { |
| 1430 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1431 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | call = CallList.getInstance().getVideoUpgradeRequestCall(); |
| 1435 | if (call != null) { |
| 1436 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1437 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | // Check if we're showing the answer screen and the call is disconnected. If this condition is |
| 1441 | // true then we won't switch from the answer UI to the in call UI. This prevents flicker when |
| 1442 | // the user rejects an incoming call. |
| 1443 | call = CallList.getInstance().getFirstCall(); |
| 1444 | if (call == null) { |
| 1445 | call = CallList.getInstance().getBackgroundCall(); |
| 1446 | } |
| 1447 | if (didShowAnswerScreen && (call == null || call.getState() == State.DISCONNECTED)) { |
| 1448 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1449 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1452 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1453 | } |
| 1454 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1455 | private static ShouldShowUiResult getShouldShowVideoUi() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1456 | DialerCall call = CallList.getInstance().getFirstCall(); |
| 1457 | if (call == null) { |
| 1458 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1459 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1460 | } |
| 1461 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1462 | if (call.isVideoCall()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1463 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1464 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1465 | } |
| 1466 | |
linyuh | 8fbecce | 2017-12-18 13:53:09 -0800 | [diff] [blame] | 1467 | if (call.hasSentVideoUpgradeRequest() || call.hasReceivedVideoUpgradeRequest()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1468 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1469 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1472 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1473 | } |
| 1474 | |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1475 | private static ShouldShowUiResult getShouldShowRttUi() { |
| 1476 | DialerCall call = CallList.getInstance().getFirstCall(); |
| 1477 | if (call == null) { |
| 1478 | LogUtil.i("InCallActivity.getShouldShowRttUi", "null call"); |
| 1479 | return new ShouldShowUiResult(false, null); |
| 1480 | } |
| 1481 | |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 1482 | if (call.isActiveRttCall()) { |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1483 | LogUtil.i("InCallActivity.getShouldShowRttUi", "found rtt call"); |
| 1484 | return new ShouldShowUiResult(true, call); |
| 1485 | } |
| 1486 | |
| 1487 | if (call.hasSentRttUpgradeRequest()) { |
| 1488 | LogUtil.i("InCallActivity.getShouldShowRttUi", "upgrading to rtt"); |
| 1489 | return new ShouldShowUiResult(true, call); |
| 1490 | } |
| 1491 | |
| 1492 | return new ShouldShowUiResult(false, null); |
| 1493 | } |
| 1494 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1495 | private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) { |
| 1496 | // When rejecting a call the active call can become null in which case we should continue |
| 1497 | // showing the answer screen. |
| 1498 | if (didShowAnswerScreen && call == null) { |
| 1499 | return false; |
| 1500 | } |
| 1501 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1502 | Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null"); |
| 1503 | |
| 1504 | boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1505 | |
| 1506 | // Check if we're already showing an answer screen for this call. |
| 1507 | if (didShowAnswerScreen) { |
| 1508 | AnswerScreen answerScreen = getAnswerScreen(); |
| 1509 | if (answerScreen.getCallId().equals(call.getId()) |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1510 | && answerScreen.isVideoCall() == call.isVideoCall() |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1511 | && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest |
| 1512 | && !answerScreen.isActionTimeout()) { |
| 1513 | LogUtil.d( |
| 1514 | "InCallActivity.showAnswerScreenFragment", |
| 1515 | "answer fragment exists for same call and has NOT been accepted/rejected/timed out"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1516 | return false; |
| 1517 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1518 | if (answerScreen.isActionTimeout()) { |
| 1519 | LogUtil.i( |
| 1520 | "InCallActivity.showAnswerScreenFragment", |
| 1521 | "answer fragment exists but has been accepted/rejected and timed out"); |
| 1522 | } else { |
| 1523 | LogUtil.i( |
| 1524 | "InCallActivity.showAnswerScreenFragment", |
| 1525 | "answer fragment exists but arguments do not match"); |
| 1526 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1527 | hideAnswerScreenFragment(transaction); |
| 1528 | } |
| 1529 | |
| 1530 | // Show a new answer screen. |
| 1531 | AnswerScreen answerScreen = |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 1532 | AnswerBindings.createAnswerScreen( |
| 1533 | call.getId(), |
wangqi | f6be617 | 2018-03-30 15:57:56 -0700 | [diff] [blame] | 1534 | call.isActiveRttCall(), |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 1535 | call.isVideoCall(), |
| 1536 | isVideoUpgradeRequest, |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1537 | call.getVideoTech().isSelfManagedCamera(), |
| 1538 | shouldAllowAnswerAndRelease(call), |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1539 | CallList.getInstance().getBackgroundCall() != null, |
| 1540 | call.isSpeakEasyEligible()); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1541 | transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), Tags.ANSWER_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1542 | |
| 1543 | Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this); |
| 1544 | didShowAnswerScreen = true; |
| 1545 | return true; |
| 1546 | } |
| 1547 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1548 | private boolean shouldAllowAnswerAndRelease(DialerCall call) { |
| 1549 | if (CallList.getInstance().getActiveCall() == null) { |
| 1550 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call"); |
| 1551 | return false; |
| 1552 | } |
| 1553 | if (getSystemService(TelephonyManager.class).getPhoneType() |
| 1554 | == TelephonyManager.PHONE_TYPE_CDMA) { |
| 1555 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported"); |
| 1556 | return false; |
| 1557 | } |
| 1558 | if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) { |
| 1559 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call"); |
| 1560 | return false; |
| 1561 | } |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1562 | if (!ConfigProviderBindings.get(this) |
| 1563 | .getBoolean(ConfigNames.ANSWER_AND_RELEASE_ENABLED, true)) { |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1564 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config"); |
| 1565 | return false; |
| 1566 | } |
| 1567 | |
| 1568 | return true; |
| 1569 | } |
| 1570 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1571 | private boolean hideAnswerScreenFragment(FragmentTransaction transaction) { |
| 1572 | if (!didShowAnswerScreen) { |
| 1573 | return false; |
| 1574 | } |
| 1575 | AnswerScreen answerScreen = getAnswerScreen(); |
| 1576 | if (answerScreen != null) { |
| 1577 | transaction.remove(answerScreen.getAnswerScreenFragment()); |
| 1578 | } |
| 1579 | |
| 1580 | didShowAnswerScreen = false; |
| 1581 | return true; |
| 1582 | } |
| 1583 | |
| 1584 | private boolean showInCallScreenFragment(FragmentTransaction transaction) { |
| 1585 | if (didShowInCallScreen) { |
| 1586 | return false; |
| 1587 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1588 | InCallScreen inCallScreen = InCallBindings.createInCallScreen(); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1589 | transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), Tags.IN_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1590 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 1591 | didShowInCallScreen = true; |
| 1592 | return true; |
| 1593 | } |
| 1594 | |
| 1595 | private boolean hideInCallScreenFragment(FragmentTransaction transaction) { |
| 1596 | if (!didShowInCallScreen) { |
| 1597 | return false; |
| 1598 | } |
| 1599 | InCallScreen inCallScreen = getInCallScreen(); |
| 1600 | if (inCallScreen != null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 1601 | transaction.remove(inCallScreen.getInCallScreenFragment()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1602 | } |
| 1603 | didShowInCallScreen = false; |
| 1604 | return true; |
| 1605 | } |
| 1606 | |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1607 | private boolean showRttCallScreenFragment(FragmentTransaction transaction, DialerCall call) { |
| 1608 | if (didShowRttCallScreen) { |
| 1609 | // This shouldn't happen since only one RTT call is allow at same time. |
| 1610 | if (!getRttCallScreen().getCallId().equals(call.getId())) { |
| 1611 | LogUtil.e("InCallActivity.showRttCallScreenFragment", "RTT call id doesn't match"); |
| 1612 | } |
| 1613 | return false; |
| 1614 | } |
| 1615 | RttCallScreen rttCallScreen = RttBindings.createRttCallScreen(call.getId()); |
| 1616 | transaction.add(R.id.main, rttCallScreen.getRttCallScreenFragment(), Tags.RTT_CALL_SCREEN); |
| 1617 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 1618 | didShowRttCallScreen = true; |
| 1619 | return true; |
| 1620 | } |
| 1621 | |
| 1622 | private boolean hideRttCallScreenFragment(FragmentTransaction transaction) { |
| 1623 | if (!didShowRttCallScreen) { |
| 1624 | return false; |
| 1625 | } |
| 1626 | RttCallScreen rttCallScreen = getRttCallScreen(); |
| 1627 | if (rttCallScreen != null) { |
| 1628 | transaction.remove(rttCallScreen.getRttCallScreenFragment()); |
| 1629 | } |
| 1630 | didShowRttCallScreen = false; |
| 1631 | return true; |
| 1632 | } |
| 1633 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1634 | private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1635 | if (didShowVideoCallScreen) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1636 | VideoCallScreen videoCallScreen = getVideoCallScreen(); |
| 1637 | if (videoCallScreen.getCallId().equals(call.getId())) { |
| 1638 | return false; |
| 1639 | } |
| 1640 | LogUtil.i( |
| 1641 | "InCallActivity.showVideoCallScreenFragment", |
| 1642 | "video call fragment exists but arguments do not match"); |
| 1643 | hideVideoCallScreenFragment(transaction); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1644 | } |
| 1645 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1646 | LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call); |
| 1647 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 1648 | VideoCallScreen videoCallScreen = |
| 1649 | VideoBindings.createVideoCallScreen( |
| 1650 | call.getId(), call.getVideoTech().shouldUseSurfaceView()); |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1651 | transaction.add( |
| 1652 | R.id.main, videoCallScreen.getVideoCallScreenFragment(), Tags.VIDEO_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1653 | |
| 1654 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 1655 | didShowVideoCallScreen = true; |
| 1656 | return true; |
| 1657 | } |
| 1658 | |
| 1659 | private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) { |
| 1660 | if (!didShowVideoCallScreen) { |
| 1661 | return false; |
| 1662 | } |
| 1663 | VideoCallScreen videoCallScreen = getVideoCallScreen(); |
| 1664 | if (videoCallScreen != null) { |
| 1665 | transaction.remove(videoCallScreen.getVideoCallScreenFragment()); |
| 1666 | } |
| 1667 | didShowVideoCallScreen = false; |
| 1668 | return true; |
| 1669 | } |
| 1670 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1671 | private AnswerScreen getAnswerScreen() { |
| 1672 | return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(Tags.ANSWER_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1675 | private InCallScreen getInCallScreen() { |
| 1676 | return (InCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.IN_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1679 | private VideoCallScreen getVideoCallScreen() { |
| 1680 | return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.VIDEO_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1681 | } |
| 1682 | |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1683 | private RttCallScreen getRttCallScreen() { |
| 1684 | return (RttCallScreen) getSupportFragmentManager().findFragmentByTag(Tags.RTT_CALL_SCREEN); |
| 1685 | } |
| 1686 | |
wangqi | fd4c9f7 | 2018-03-08 18:21:50 -0800 | [diff] [blame] | 1687 | private InCallScreen getInCallOrRttCallScreen() { |
| 1688 | InCallScreen inCallScreen = null; |
| 1689 | if (didShowInCallScreen) { |
| 1690 | inCallScreen = getInCallScreen(); |
| 1691 | } |
| 1692 | if (didShowRttCallScreen) { |
| 1693 | inCallScreen = getRttCallScreen(); |
| 1694 | } |
| 1695 | return inCallScreen; |
| 1696 | } |
| 1697 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1698 | @Override |
| 1699 | public void onPseudoScreenStateChanged(boolean isOn) { |
| 1700 | LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn); |
| 1701 | pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE); |
| 1702 | } |
| 1703 | |
| 1704 | /** |
| 1705 | * For some touch related issue, turning off the screen can be faked by drawing a black view over |
| 1706 | * the activity. All touch events started when the screen is "off" is rejected. |
| 1707 | * |
| 1708 | * @see PseudoScreenState |
| 1709 | */ |
| 1710 | @Override |
| 1711 | public boolean dispatchTouchEvent(MotionEvent event) { |
| 1712 | // Reject any gesture that started when the screen is in the fake off state. |
| 1713 | if (touchDownWhenPseudoScreenOff) { |
| 1714 | if (event.getAction() == MotionEvent.ACTION_UP) { |
| 1715 | touchDownWhenPseudoScreenOff = false; |
| 1716 | } |
| 1717 | return true; |
| 1718 | } |
| 1719 | // Reject all touch event when the screen is in the fake off state. |
| 1720 | if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) { |
| 1721 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 1722 | touchDownWhenPseudoScreenOff = true; |
| 1723 | LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff"); |
| 1724 | } |
| 1725 | return true; |
| 1726 | } |
| 1727 | return super.dispatchTouchEvent(event); |
| 1728 | } |
| 1729 | |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1730 | @Override |
| 1731 | public RttCallScreenDelegate newRttCallScreenDelegate(RttCallScreen videoCallScreen) { |
| 1732 | return new RttCallPresenter(); |
| 1733 | } |
| 1734 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1735 | private static class ShouldShowUiResult { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1736 | public final boolean shouldShow; |
| 1737 | public final DialerCall call; |
| 1738 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 1739 | ShouldShowUiResult(boolean shouldShow, DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1740 | this.shouldShow = shouldShow; |
| 1741 | this.call = call; |
| 1742 | } |
| 1743 | } |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1744 | |
| 1745 | private static final class IntentExtraNames { |
| 1746 | static final String FOR_FULL_SCREEN = "InCallActivity.for_full_screen_intent"; |
| 1747 | static final String NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call"; |
| 1748 | static final String SHOW_DIALPAD = "InCallActivity.show_dialpad"; |
| 1749 | } |
| 1750 | |
| 1751 | private static final class KeysForSavedInstance { |
| 1752 | static final String DIALPAD_TEXT = "InCallActivity.dialpad_text"; |
| 1753 | static final String DID_SHOW_ANSWER_SCREEN = "did_show_answer_screen"; |
| 1754 | static final String DID_SHOW_IN_CALL_SCREEN = "did_show_in_call_screen"; |
| 1755 | static final String DID_SHOW_VIDEO_CALL_SCREEN = "did_show_video_call_screen"; |
wangqi | 153af2f | 2018-02-15 16:21:49 -0800 | [diff] [blame] | 1756 | static final String DID_SHOW_RTT_CALL_SCREEN = "did_show_rtt_call_screen"; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1757 | static final String DID_SHOW_SPEAK_EASY_SCREEN = "did_show_speak_easy_screen"; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | /** Request codes for pending intents. */ |
| 1761 | public static final class PendingIntentRequestCodes { |
| 1762 | static final int NON_FULL_SCREEN = 0; |
| 1763 | static final int FULL_SCREEN = 1; |
| 1764 | static final int BUBBLE = 2; |
| 1765 | } |
| 1766 | |
| 1767 | private static final class Tags { |
| 1768 | static final String ANSWER_SCREEN = "tag_answer_screen"; |
| 1769 | static final String DIALPAD_FRAGMENT = "tag_dialpad_fragment"; |
| 1770 | static final String IN_CALL_SCREEN = "tag_in_call_screen"; |
| 1771 | static final String INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi"; |
| 1772 | static final String SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment"; |
| 1773 | static final String VIDEO_CALL_SCREEN = "tag_video_call_screen"; |
wangqi | 219b870 | 2018-02-13 09:34:41 -0800 | [diff] [blame] | 1774 | static final String RTT_CALL_SCREEN = "tag_rtt_call_screen"; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1775 | static final String POST_CHAR_DIALOG_FRAGMENT = "tag_post_char_dialog_fragment"; |
erfanian | d05d899 | 2018-03-20 19:42:26 -0700 | [diff] [blame] | 1776 | static final String SPEAK_EASY_SCREEN = "tag_speak_easy_screen"; |
wangqi | bc28ea7 | 2018-04-02 16:23:00 -0700 | [diff] [blame] | 1777 | static final String RTT_REQUEST_DIALOG = "tag_rtt_request_dialog"; |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | private static final class ConfigNames { |
| 1781 | static final String ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled"; |
| 1782 | } |
| 1783 | |
| 1784 | private static final class InternationalCallOnWifiCallback |
| 1785 | implements InternationalCallOnWifiDialogFragment.Callback { |
| 1786 | private static final String TAG = InternationalCallOnWifiCallback.class.getCanonicalName(); |
| 1787 | |
| 1788 | @Override |
| 1789 | public void continueCall(@NonNull String callId) { |
| 1790 | LogUtil.i(TAG, "Continuing call with ID: %s", callId); |
| 1791 | } |
| 1792 | |
| 1793 | @Override |
| 1794 | public void cancelCall(@NonNull String callId) { |
| 1795 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 1796 | if (call == null) { |
| 1797 | LogUtil.i(TAG, "Call destroyed before the dialog is closed"); |
| 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | LogUtil.i(TAG, "Disconnecting international call on WiFi"); |
| 1802 | call.disconnect(); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | private static final class SelectPhoneAccountListener |
| 1807 | extends SelectPhoneAccountDialogFragment.SelectPhoneAccountListener { |
| 1808 | private static final String TAG = SelectPhoneAccountListener.class.getCanonicalName(); |
| 1809 | |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 1810 | private final Context appContext; |
| 1811 | |
| 1812 | SelectPhoneAccountListener(Context appContext) { |
| 1813 | this.appContext = appContext; |
| 1814 | } |
| 1815 | |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1816 | @Override |
| 1817 | public void onPhoneAccountSelected( |
| 1818 | PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) { |
| 1819 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 1820 | LogUtil.i(TAG, "Phone account select with call:\n%s", call); |
| 1821 | |
| 1822 | if (call != null) { |
twyen | 73a74c3 | 2018-03-07 12:12:24 -0800 | [diff] [blame] | 1823 | call.phoneAccountSelected(selectedAccountHandle, false); |
| 1824 | if (call.getPreferredAccountRecorder() != null) { |
| 1825 | call.getPreferredAccountRecorder().record(appContext, selectedAccountHandle, setDefault); |
| 1826 | } |
linyuh | c3968e6 | 2017-11-20 17:40:50 -0800 | [diff] [blame] | 1827 | } |
| 1828 | } |
| 1829 | |
| 1830 | @Override |
| 1831 | public void onDialogDismissed(String callId) { |
| 1832 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 1833 | LogUtil.i(TAG, "Disconnecting call:\n%s" + call); |
| 1834 | |
| 1835 | if (call != null) { |
| 1836 | call.disconnect(); |
| 1837 | } |
| 1838 | } |
| 1839 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1840 | } |