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