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