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