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 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.graphics.drawable.GradientDrawable; |
| 22 | import android.graphics.drawable.GradientDrawable.Orientation; |
| 23 | import android.os.Bundle; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 24 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 25 | import android.support.annotation.ColorInt; |
| 26 | import android.support.annotation.FloatRange; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 27 | import android.support.annotation.NonNull; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 28 | import android.support.annotation.Nullable; |
| 29 | import android.support.v4.app.FragmentManager; |
| 30 | import android.support.v4.app.FragmentTransaction; |
| 31 | import android.support.v4.graphics.ColorUtils; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 32 | import android.telephony.TelephonyManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
| 34 | import android.view.MenuItem; |
| 35 | import android.view.MotionEvent; |
| 36 | import android.view.View; |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame^] | 37 | import android.view.WindowManager; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 38 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 39 | import com.android.dialer.common.LogUtil; |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 40 | import com.android.dialer.common.concurrent.ThreadUtil; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 41 | import com.android.dialer.compat.ActivityCompat; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 42 | import com.android.dialer.configprovider.ConfigProviderBindings; |
| 43 | import com.android.dialer.logging.DialerImpression; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 44 | import com.android.dialer.logging.Logger; |
weijiaxu | 94df720 | 2017-10-25 18:21:41 -0700 | [diff] [blame] | 45 | import com.android.dialer.logging.LoggingBindings; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 46 | import com.android.dialer.logging.ScreenEvent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 47 | import com.android.incallui.answer.bindings.AnswerBindings; |
| 48 | import com.android.incallui.answer.protocol.AnswerScreen; |
| 49 | import com.android.incallui.answer.protocol.AnswerScreenDelegate; |
| 50 | import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory; |
| 51 | import com.android.incallui.answerproximitysensor.PseudoScreenState; |
| 52 | import com.android.incallui.call.CallList; |
| 53 | import com.android.incallui.call.DialerCall; |
| 54 | import com.android.incallui.call.DialerCall.State; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 55 | import com.android.incallui.callpending.CallPendingActivity; |
| 56 | import com.android.incallui.disconnectdialog.DisconnectMessage; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 57 | import com.android.incallui.incall.bindings.InCallBindings; |
| 58 | import com.android.incallui.incall.protocol.InCallButtonUiDelegate; |
| 59 | import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory; |
| 60 | import com.android.incallui.incall.protocol.InCallScreen; |
| 61 | import com.android.incallui.incall.protocol.InCallScreenDelegate; |
| 62 | import com.android.incallui.incall.protocol.InCallScreenDelegateFactory; |
| 63 | import com.android.incallui.video.bindings.VideoBindings; |
| 64 | import com.android.incallui.video.protocol.VideoCallScreen; |
| 65 | import com.android.incallui.video.protocol.VideoCallScreenDelegate; |
| 66 | import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory; |
| 67 | |
| 68 | /** Version of {@link InCallActivity} that shows the new UI */ |
| 69 | public class InCallActivity extends TransactionSafeFragmentActivity |
| 70 | implements AnswerScreenDelegateFactory, |
| 71 | InCallScreenDelegateFactory, |
| 72 | InCallButtonUiDelegateFactory, |
| 73 | VideoCallScreenDelegateFactory, |
| 74 | PseudoScreenState.StateChangedListener { |
| 75 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 76 | public static final int PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN = 0; |
| 77 | public static final int PENDING_INTENT_REQUEST_CODE_FULL_SCREEN = 1; |
| 78 | public static final int PENDING_INTENT_REQUEST_CODE_BUBBLE = 2; |
| 79 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 80 | private static final String TAG_IN_CALL_SCREEN = "tag_in_call_screen"; |
| 81 | private static final String TAG_ANSWER_SCREEN = "tag_answer_screen"; |
| 82 | private static final String TAG_VIDEO_CALL_SCREEN = "tag_video_call_screen"; |
| 83 | |
| 84 | private static final String DID_SHOW_ANSWER_SCREEN_KEY = "did_show_answer_screen"; |
| 85 | private static final String DID_SHOW_IN_CALL_SCREEN_KEY = "did_show_in_call_screen"; |
| 86 | private static final String DID_SHOW_VIDEO_CALL_SCREEN_KEY = "did_show_video_call_screen"; |
| 87 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 88 | private static final String CONFIG_ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled"; |
| 89 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 90 | private final InCallActivityCommon common; |
| 91 | private boolean didShowAnswerScreen; |
| 92 | private boolean didShowInCallScreen; |
| 93 | private boolean didShowVideoCallScreen; |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame^] | 94 | private boolean dismissKeyguard; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 95 | private int[] backgroundDrawableColors; |
| 96 | private GradientDrawable backgroundDrawable; |
| 97 | private boolean isVisible; |
| 98 | private View pseudoBlackScreenOverlay; |
| 99 | private boolean touchDownWhenPseudoScreenOff; |
| 100 | private boolean isInShowMainInCallFragment; |
| 101 | private boolean needDismissPendingDialogs; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 102 | private boolean allowOrientationChange; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 103 | |
| 104 | public InCallActivity() { |
| 105 | common = new InCallActivityCommon(this); |
| 106 | } |
| 107 | |
| 108 | public static Intent getIntent( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 109 | Context context, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 110 | Intent intent = new Intent(Intent.ACTION_MAIN, null); |
| 111 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 112 | intent.setClass(context, InCallActivity.class); |
| 113 | InCallActivityCommon.setIntentExtras(intent, showDialpad, newOutgoingCall, isForFullScreen); |
| 114 | return intent; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | protected void onResumeFragments() { |
| 119 | super.onResumeFragments(); |
| 120 | if (needDismissPendingDialogs) { |
| 121 | dismissPendingDialogs(); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | protected void onCreate(Bundle icicle) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 127 | Trace.beginSection("InCallActivity.onCreate"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 128 | LogUtil.i("InCallActivity.onCreate", ""); |
| 129 | super.onCreate(icicle); |
| 130 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 131 | if (getIntent().getBooleanExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY, false)) { |
| 132 | Logger.get(this).logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_RETURN_TO_CALL); |
| 133 | getIntent().removeExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY); |
| 134 | } |
| 135 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 136 | if (icicle != null) { |
| 137 | didShowAnswerScreen = icicle.getBoolean(DID_SHOW_ANSWER_SCREEN_KEY); |
| 138 | didShowInCallScreen = icicle.getBoolean(DID_SHOW_IN_CALL_SCREEN_KEY); |
| 139 | didShowVideoCallScreen = icicle.getBoolean(DID_SHOW_VIDEO_CALL_SCREEN_KEY); |
| 140 | } |
| 141 | |
| 142 | common.onCreate(icicle); |
| 143 | |
| 144 | getWindow() |
| 145 | .getDecorView() |
| 146 | .setSystemUiVisibility( |
| 147 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 148 | |
| 149 | pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 150 | sendBroadcast(CallPendingActivity.getFinishBroadcast()); |
| 151 | Trace.endSection(); |
weijiaxu | c950a9b | 2017-11-06 16:39:04 -0800 | [diff] [blame] | 152 | Logger.get(this) |
| 153 | .logStopLatencyTimer(LoggingBindings.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_INCOMING); |
| 154 | Logger.get(this) |
| 155 | .logStopLatencyTimer(LoggingBindings.ON_CALL_ADDED_TO_ON_INCALL_UI_SHOWN_OUTGOING); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | @Override |
| 159 | protected void onSaveInstanceState(Bundle out) { |
| 160 | LogUtil.i("InCallActivity.onSaveInstanceState", ""); |
| 161 | common.onSaveInstanceState(out); |
| 162 | out.putBoolean(DID_SHOW_ANSWER_SCREEN_KEY, didShowAnswerScreen); |
| 163 | out.putBoolean(DID_SHOW_IN_CALL_SCREEN_KEY, didShowInCallScreen); |
| 164 | out.putBoolean(DID_SHOW_VIDEO_CALL_SCREEN_KEY, didShowVideoCallScreen); |
| 165 | super.onSaveInstanceState(out); |
| 166 | isVisible = false; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | protected void onStart() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 171 | Trace.beginSection("InCallActivity.onStart"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 172 | LogUtil.i("InCallActivity.onStart", ""); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 173 | Trace.beginSection("call super"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 174 | super.onStart(); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 175 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 176 | isVisible = true; |
| 177 | showMainInCallFragment(); |
| 178 | common.onStart(); |
| 179 | if (ActivityCompat.isInMultiWindowMode(this) |
| 180 | && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) { |
| 181 | // Hide the dialpad because there may not be enough room |
| 182 | showDialpadFragment(false, false); |
| 183 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 184 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | @Override |
| 188 | protected void onResume() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 189 | Trace.beginSection("InCallActivity.onResume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 190 | LogUtil.i("InCallActivity.onResume", ""); |
| 191 | super.onResume(); |
| 192 | common.onResume(); |
| 193 | PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState(); |
| 194 | pseudoScreenState.addListener(this); |
| 195 | onPseudoScreenStateChanged(pseudoScreenState.isOn()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 196 | Trace.endSection(); |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 197 | // add 1 sec delay to get memory snapshot so that dialer wont react slowly on resume. |
| 198 | ThreadUtil.postDelayedOnUiThread( |
weijiaxu | c950a9b | 2017-11-06 16:39:04 -0800 | [diff] [blame] | 199 | () -> |
| 200 | Logger.get(this) |
| 201 | .logRecordMemory(LoggingBindings.INCALL_ACTIVITY_ON_RESUME_MEMORY_EVENT_NAME), |
weijiaxu | 650e7cc | 2017-10-31 12:38:54 -0700 | [diff] [blame] | 202 | 1000); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** onPause is guaranteed to be called when the InCallActivity goes in the background. */ |
| 206 | @Override |
| 207 | protected void onPause() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 208 | Trace.beginSection("InCallActivity.onPause"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 209 | LogUtil.i("InCallActivity.onPause", ""); |
| 210 | super.onPause(); |
| 211 | common.onPause(); |
| 212 | InCallPresenter.getInstance().getPseudoScreenState().removeListener(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 213 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Override |
| 217 | protected void onStop() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 218 | Trace.beginSection("InCallActivity.onStop"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 219 | LogUtil.i("InCallActivity.onStop", ""); |
wangqi | 4d705e5 | 2017-09-28 12:23:35 -0700 | [diff] [blame] | 220 | isVisible = false; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 221 | super.onStop(); |
| 222 | common.onStop(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 223 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
| 227 | protected void onDestroy() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 228 | Trace.beginSection("InCallActivity.onDestroy"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 229 | LogUtil.i("InCallActivity.onDestroy", ""); |
| 230 | super.onDestroy(); |
| 231 | common.onDestroy(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 232 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Override |
| 236 | public void finish() { |
| 237 | if (shouldCloseActivityOnFinish()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 238 | // When user select incall ui from recents after the call is disconnected, it tries to launch |
| 239 | // a new InCallActivity but InCallPresenter is already teared down at this point, which causes |
| 240 | // crash. |
| 241 | // By calling finishAndRemoveTask() instead of finish() the task associated with |
| 242 | // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in |
| 243 | // this case. |
| 244 | // |
| 245 | // Calling finish won't clear the task and normally when an activity finishes it shouldn't |
| 246 | // clear the task since there could be parent activity in the same task that's still alive. |
| 247 | // But InCallActivity is special since it's singleInstance which means it's root activity and |
| 248 | // only instance of activity in the task. So it should be safe to also remove task when |
| 249 | // finishing. |
| 250 | // It's also necessary in the sense of it's excluded from recents. So whenever the activity |
| 251 | // finishes, the task should also be removed since it doesn't make sense to go back to it in |
| 252 | // anyway anymore. |
| 253 | super.finishAndRemoveTask(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 254 | } |
| 255 | } |
| 256 | |
| 257 | private boolean shouldCloseActivityOnFinish() { |
| 258 | if (!isVisible()) { |
| 259 | LogUtil.i( |
| 260 | "InCallActivity.shouldCloseActivityOnFinish", |
| 261 | "allowing activity to be closed because it's not visible"); |
| 262 | return true; |
| 263 | } |
| 264 | |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 265 | if (InCallPresenter.getInstance().isInCallUiLocked()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 266 | LogUtil.i( |
| 267 | "InCallActivity.shouldCloseActivityOnFinish", |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 268 | "in call ui is locked, not closing activity"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 269 | return false; |
| 270 | } |
| 271 | |
| 272 | LogUtil.i( |
| 273 | "InCallActivity.shouldCloseActivityOnFinish", |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 274 | "activity is visible and has no locks, allowing activity to close"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 275 | return true; |
| 276 | } |
| 277 | |
| 278 | @Override |
| 279 | protected void onNewIntent(Intent intent) { |
| 280 | LogUtil.i("InCallActivity.onNewIntent", ""); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 281 | |
| 282 | // If the screen is off, we need to make sure it gets turned on for incoming calls. |
| 283 | // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works |
| 284 | // when the activity is first created. Therefore, to ensure the screen is turned on |
| 285 | // for the call waiting case, we recreate() the current activity. There should be no jank from |
| 286 | // this since the screen is already off and will remain so until our new activity is up. |
| 287 | if (!isVisible()) { |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 288 | common.onNewIntent(intent, true /* isRecreating */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 289 | LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on."); |
| 290 | recreate(); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 291 | } else { |
| 292 | common.onNewIntent(intent, false /* isRecreating */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | @Override |
| 297 | public void onBackPressed() { |
| 298 | LogUtil.i("InCallActivity.onBackPressed", ""); |
| 299 | if (!common.onBackPressed(didShowInCallScreen || didShowVideoCallScreen)) { |
| 300 | super.onBackPressed(); |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public boolean onOptionsItemSelected(MenuItem item) { |
| 306 | LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item); |
| 307 | if (item.getItemId() == android.R.id.home) { |
| 308 | onBackPressed(); |
| 309 | return true; |
| 310 | } |
| 311 | return super.onOptionsItemSelected(item); |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 316 | return common.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | @Override |
| 320 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 321 | return common.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | public boolean isInCallScreenAnimating() { |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | public void showConferenceFragment(boolean show) { |
| 329 | if (show) { |
| 330 | startActivity(new Intent(this, ManageConferenceActivity.class)); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | public boolean showDialpadFragment(boolean show, boolean animate) { |
| 335 | boolean didChange = common.showDialpadFragment(show, animate); |
| 336 | if (didChange) { |
| 337 | // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB |
| 338 | // repositions itself. |
| 339 | getInCallScreen().onInCallScreenDialpadVisibilityChange(show); |
| 340 | } |
| 341 | return didChange; |
| 342 | } |
| 343 | |
| 344 | public boolean isDialpadVisible() { |
| 345 | return common.isDialpadVisible(); |
| 346 | } |
| 347 | |
| 348 | public void onForegroundCallChanged(DialerCall newForegroundCall) { |
| 349 | common.updateTaskDescription(); |
| 350 | if (didShowAnswerScreen && newForegroundCall != null) { |
| 351 | if (newForegroundCall.getState() == State.DISCONNECTED |
| 352 | || newForegroundCall.getState() == State.IDLE) { |
| 353 | LogUtil.i( |
| 354 | "InCallActivity.onForegroundCallChanged", |
| 355 | "rejecting incoming call, not updating " + "window background color"); |
| 356 | } |
| 357 | } else { |
| 358 | LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color"); |
| 359 | updateWindowBackgroundColor(0); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) { |
| 364 | ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager(); |
| 365 | @ColorInt int top; |
| 366 | @ColorInt int middle; |
| 367 | @ColorInt int bottom; |
| 368 | @ColorInt int gray = 0x66000000; |
| 369 | |
| 370 | if (ActivityCompat.isInMultiWindowMode(this)) { |
| 371 | top = themeColorManager.getBackgroundColorSolid(); |
| 372 | middle = themeColorManager.getBackgroundColorSolid(); |
| 373 | bottom = themeColorManager.getBackgroundColorSolid(); |
| 374 | } else { |
| 375 | top = themeColorManager.getBackgroundColorTop(); |
| 376 | middle = themeColorManager.getBackgroundColorMiddle(); |
| 377 | bottom = themeColorManager.getBackgroundColorBottom(); |
| 378 | } |
| 379 | |
| 380 | if (progress < 0) { |
| 381 | float correctedProgress = Math.abs(progress); |
| 382 | top = ColorUtils.blendARGB(top, gray, correctedProgress); |
| 383 | middle = ColorUtils.blendARGB(middle, gray, correctedProgress); |
| 384 | bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress); |
| 385 | } |
| 386 | |
| 387 | boolean backgroundDirty = false; |
| 388 | if (backgroundDrawable == null) { |
| 389 | backgroundDrawableColors = new int[] {top, middle, bottom}; |
| 390 | backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors); |
| 391 | backgroundDirty = true; |
| 392 | } else { |
| 393 | if (backgroundDrawableColors[0] != top) { |
| 394 | backgroundDrawableColors[0] = top; |
| 395 | backgroundDirty = true; |
| 396 | } |
| 397 | if (backgroundDrawableColors[1] != middle) { |
| 398 | backgroundDrawableColors[1] = middle; |
| 399 | backgroundDirty = true; |
| 400 | } |
| 401 | if (backgroundDrawableColors[2] != bottom) { |
| 402 | backgroundDrawableColors[2] = bottom; |
| 403 | backgroundDirty = true; |
| 404 | } |
| 405 | if (backgroundDirty) { |
| 406 | backgroundDrawable.setColors(backgroundDrawableColors); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | if (backgroundDirty) { |
| 411 | getWindow().setBackgroundDrawable(backgroundDrawable); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | public boolean isVisible() { |
| 416 | return isVisible; |
| 417 | } |
| 418 | |
| 419 | public boolean getCallCardFragmentVisible() { |
| 420 | return didShowInCallScreen || didShowVideoCallScreen; |
| 421 | } |
| 422 | |
| 423 | public void dismissKeyguard(boolean dismiss) { |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame^] | 424 | if (dismissKeyguard == dismiss) { |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | dismissKeyguard = dismiss; |
| 429 | if (dismiss) { |
| 430 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
| 431 | } else { |
| 432 | getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); |
| 433 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | public void showPostCharWaitDialog(String callId, String chars) { |
| 437 | common.showPostCharWaitDialog(callId, chars); |
| 438 | } |
| 439 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 440 | public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) { |
| 441 | common.maybeShowErrorDialogOnDisconnect(disconnectMessage); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | public void dismissPendingDialogs() { |
| 445 | if (isVisible) { |
| 446 | LogUtil.i("InCallActivity.dismissPendingDialogs", ""); |
| 447 | common.dismissPendingDialogs(); |
| 448 | AnswerScreen answerScreen = getAnswerScreen(); |
| 449 | if (answerScreen != null) { |
| 450 | answerScreen.dismissPendingDialogs(); |
| 451 | } |
| 452 | needDismissPendingDialogs = false; |
| 453 | } else { |
| 454 | // The activity is not visible and onSaveInstanceState may have been called so defer the |
| 455 | // dismissing action. |
| 456 | LogUtil.i( |
| 457 | "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible"); |
| 458 | needDismissPendingDialogs = true; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | private void enableInCallOrientationEventListener(boolean enable) { |
| 463 | common.enableInCallOrientationEventListener(enable); |
| 464 | } |
| 465 | |
| 466 | public void setExcludeFromRecents(boolean exclude) { |
| 467 | common.setExcludeFromRecents(exclude); |
| 468 | } |
| 469 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 470 | @Nullable |
| 471 | public FragmentManager getDialpadFragmentManager() { |
| 472 | InCallScreen inCallScreen = getInCallScreen(); |
| 473 | if (inCallScreen != null) { |
| 474 | return inCallScreen.getInCallScreenFragment().getChildFragmentManager(); |
| 475 | } |
| 476 | return null; |
| 477 | } |
| 478 | |
| 479 | public int getDialpadContainerId() { |
| 480 | return getInCallScreen().getAnswerAndDialpadContainerResourceId(); |
| 481 | } |
| 482 | |
| 483 | @Override |
| 484 | public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) { |
| 485 | DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId()); |
| 486 | if (call == null) { |
| 487 | // This is a work around for a bug where we attempt to create a new delegate after the call |
| 488 | // has already been removed. An example of when this can happen is: |
| 489 | // 1. incoming video call in landscape mode |
| 490 | // 2. remote party hangs up |
| 491 | // 3. activity switches from landscape to portrait |
| 492 | // At step #3 the answer fragment will try to create a new answer delegate but the call won't |
| 493 | // exist. In this case we'll simply return a stub delegate that does nothing. This is ok |
| 494 | // because this new state is transient and the activity will be destroyed soon. |
| 495 | LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub"); |
| 496 | return new AnswerScreenPresenterStub(); |
| 497 | } else { |
| 498 | return new AnswerScreenPresenter( |
| 499 | this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId())); |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | @Override |
| 504 | public InCallScreenDelegate newInCallScreenDelegate() { |
| 505 | return new CallCardPresenter(this); |
| 506 | } |
| 507 | |
| 508 | @Override |
| 509 | public InCallButtonUiDelegate newInCallButtonUiDelegate() { |
| 510 | return new CallButtonPresenter(this); |
| 511 | } |
| 512 | |
| 513 | @Override |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 514 | public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) { |
| 515 | DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId()); |
| 516 | if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) { |
| 517 | return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen); |
| 518 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 519 | return new VideoCallPresenter(); |
| 520 | } |
| 521 | |
| 522 | public void onPrimaryCallStateChanged() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 523 | Trace.beginSection("InCallActivity.onPrimaryCallStateChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 524 | LogUtil.i("InCallActivity.onPrimaryCallStateChanged", ""); |
| 525 | showMainInCallFragment(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 526 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | public void onWiFiToLteHandover(DialerCall call) { |
| 530 | common.showWifiToLteHandoverToast(call); |
| 531 | } |
| 532 | |
| 533 | public void onHandoverToWifiFailed(DialerCall call) { |
| 534 | common.showWifiFailedDialog(call); |
| 535 | } |
| 536 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 537 | public void onInternationalCallOnWifi(@NonNull DialerCall call) { |
| 538 | LogUtil.enterBlock("InCallActivity.onInternationalCallOnWifi"); |
| 539 | common.showInternationalCallOnWifiDialog(call); |
| 540 | } |
| 541 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 542 | @Override |
| 543 | public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { |
| 544 | super.onMultiWindowModeChanged(isInMultiWindowMode); |
| 545 | if (!isInMultiWindowMode) { |
| 546 | common.updateNavigationBar(isDialpadVisible()); |
| 547 | } |
| 548 | } |
| 549 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 550 | public void setAllowOrientationChange(boolean allowOrientationChange) { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 551 | if (this.allowOrientationChange == allowOrientationChange) { |
| 552 | return; |
| 553 | } |
| 554 | this.allowOrientationChange = allowOrientationChange; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 555 | if (!allowOrientationChange) { |
| 556 | setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_DISALLOW_ROTATION); |
| 557 | } else { |
| 558 | setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION); |
| 559 | } |
| 560 | enableInCallOrientationEventListener(allowOrientationChange); |
| 561 | } |
| 562 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 563 | public void hideMainInCallFragment() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 564 | LogUtil.i("InCallActivity.hideMainInCallFragment", ""); |
| 565 | if (didShowInCallScreen || didShowVideoCallScreen) { |
| 566 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 567 | hideInCallScreenFragment(transaction); |
| 568 | hideVideoCallScreenFragment(transaction); |
| 569 | transaction.commitAllowingStateLoss(); |
| 570 | getSupportFragmentManager().executePendingTransactions(); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | private void showMainInCallFragment() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 575 | Trace.beginSection("InCallActivity.showMainInCallFragment"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 576 | // If the activity's onStart method hasn't been called yet then defer doing any work. |
| 577 | if (!isVisible) { |
| 578 | LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 579 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 580 | return; |
| 581 | } |
| 582 | |
| 583 | // Don't let this be reentrant. |
| 584 | if (isInShowMainInCallFragment) { |
| 585 | LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 586 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 587 | return; |
| 588 | } |
| 589 | |
| 590 | isInShowMainInCallFragment = true; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 591 | ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi(); |
| 592 | ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 593 | LogUtil.i( |
| 594 | "InCallActivity.showMainInCallFragment", |
| 595 | "shouldShowAnswerUi: %b, shouldShowVideoUi: %b, " |
| 596 | + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowVideoCallScreen: %b", |
| 597 | shouldShowAnswerUi.shouldShow, |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 598 | shouldShowVideoUi.shouldShow, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 599 | didShowAnswerScreen, |
| 600 | didShowInCallScreen, |
| 601 | didShowVideoCallScreen); |
| 602 | // Only video call ui allows orientation change. |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 603 | setAllowOrientationChange(shouldShowVideoUi.shouldShow); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 604 | |
| 605 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 606 | boolean didChangeInCall; |
| 607 | boolean didChangeVideo; |
| 608 | boolean didChangeAnswer; |
| 609 | if (shouldShowAnswerUi.shouldShow) { |
| 610 | didChangeInCall = hideInCallScreenFragment(transaction); |
| 611 | didChangeVideo = hideVideoCallScreenFragment(transaction); |
| 612 | didChangeAnswer = showAnswerScreenFragment(transaction, shouldShowAnswerUi.call); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 613 | } else if (shouldShowVideoUi.shouldShow) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 614 | didChangeInCall = hideInCallScreenFragment(transaction); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 615 | didChangeVideo = showVideoCallScreenFragment(transaction, shouldShowVideoUi.call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 616 | didChangeAnswer = hideAnswerScreenFragment(transaction); |
| 617 | } else { |
| 618 | didChangeInCall = showInCallScreenFragment(transaction); |
| 619 | didChangeVideo = hideVideoCallScreenFragment(transaction); |
| 620 | didChangeAnswer = hideAnswerScreenFragment(transaction); |
| 621 | } |
| 622 | |
| 623 | if (didChangeInCall || didChangeVideo || didChangeAnswer) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 624 | Trace.beginSection("InCallActivity.commitTransaction"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 625 | transaction.commitNow(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 626 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 627 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 628 | } |
| 629 | isInShowMainInCallFragment = false; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 630 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 633 | private ShouldShowUiResult getShouldShowAnswerUi() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 634 | DialerCall call = CallList.getInstance().getIncomingCall(); |
| 635 | if (call != null) { |
| 636 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 637 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | call = CallList.getInstance().getVideoUpgradeRequestCall(); |
| 641 | if (call != null) { |
| 642 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 643 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | // Check if we're showing the answer screen and the call is disconnected. If this condition is |
| 647 | // true then we won't switch from the answer UI to the in call UI. This prevents flicker when |
| 648 | // the user rejects an incoming call. |
| 649 | call = CallList.getInstance().getFirstCall(); |
| 650 | if (call == null) { |
| 651 | call = CallList.getInstance().getBackgroundCall(); |
| 652 | } |
| 653 | if (didShowAnswerScreen && (call == null || call.getState() == State.DISCONNECTED)) { |
| 654 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 655 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 656 | } |
| 657 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 658 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 659 | } |
| 660 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 661 | private static ShouldShowUiResult getShouldShowVideoUi() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 662 | DialerCall call = CallList.getInstance().getFirstCall(); |
| 663 | if (call == null) { |
| 664 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 665 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 666 | } |
| 667 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 668 | if (call.isVideoCall()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 669 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 670 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 673 | if (call.hasSentVideoUpgradeRequest()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 674 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 675 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 678 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) { |
| 682 | // When rejecting a call the active call can become null in which case we should continue |
| 683 | // showing the answer screen. |
| 684 | if (didShowAnswerScreen && call == null) { |
| 685 | return false; |
| 686 | } |
| 687 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 688 | Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null"); |
| 689 | |
| 690 | boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 691 | |
| 692 | // Check if we're already showing an answer screen for this call. |
| 693 | if (didShowAnswerScreen) { |
| 694 | AnswerScreen answerScreen = getAnswerScreen(); |
| 695 | if (answerScreen.getCallId().equals(call.getId()) |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 696 | && answerScreen.isVideoCall() == call.isVideoCall() |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 697 | && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest |
| 698 | && !answerScreen.isActionTimeout()) { |
| 699 | LogUtil.d( |
| 700 | "InCallActivity.showAnswerScreenFragment", |
| 701 | "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] | 702 | return false; |
| 703 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 704 | if (answerScreen.isActionTimeout()) { |
| 705 | LogUtil.i( |
| 706 | "InCallActivity.showAnswerScreenFragment", |
| 707 | "answer fragment exists but has been accepted/rejected and timed out"); |
| 708 | } else { |
| 709 | LogUtil.i( |
| 710 | "InCallActivity.showAnswerScreenFragment", |
| 711 | "answer fragment exists but arguments do not match"); |
| 712 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 713 | hideAnswerScreenFragment(transaction); |
| 714 | } |
| 715 | |
| 716 | // Show a new answer screen. |
| 717 | AnswerScreen answerScreen = |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 718 | AnswerBindings.createAnswerScreen( |
| 719 | call.getId(), |
| 720 | call.isVideoCall(), |
| 721 | isVideoUpgradeRequest, |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 722 | call.getVideoTech().isSelfManagedCamera(), |
| 723 | shouldAllowAnswerAndRelease(call), |
| 724 | CallList.getInstance().getBackgroundCall() != null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 725 | transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), TAG_ANSWER_SCREEN); |
| 726 | |
| 727 | Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this); |
| 728 | didShowAnswerScreen = true; |
| 729 | return true; |
| 730 | } |
| 731 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 732 | private boolean shouldAllowAnswerAndRelease(DialerCall call) { |
| 733 | if (CallList.getInstance().getActiveCall() == null) { |
| 734 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call"); |
| 735 | return false; |
| 736 | } |
| 737 | if (getSystemService(TelephonyManager.class).getPhoneType() |
| 738 | == TelephonyManager.PHONE_TYPE_CDMA) { |
| 739 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported"); |
| 740 | return false; |
| 741 | } |
| 742 | if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) { |
| 743 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call"); |
| 744 | return false; |
| 745 | } |
| 746 | if (!ConfigProviderBindings.get(this).getBoolean(CONFIG_ANSWER_AND_RELEASE_ENABLED, true)) { |
| 747 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config"); |
| 748 | return false; |
| 749 | } |
| 750 | |
| 751 | return true; |
| 752 | } |
| 753 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 754 | private boolean hideAnswerScreenFragment(FragmentTransaction transaction) { |
| 755 | if (!didShowAnswerScreen) { |
| 756 | return false; |
| 757 | } |
| 758 | AnswerScreen answerScreen = getAnswerScreen(); |
| 759 | if (answerScreen != null) { |
| 760 | transaction.remove(answerScreen.getAnswerScreenFragment()); |
| 761 | } |
| 762 | |
| 763 | didShowAnswerScreen = false; |
| 764 | return true; |
| 765 | } |
| 766 | |
| 767 | private boolean showInCallScreenFragment(FragmentTransaction transaction) { |
| 768 | if (didShowInCallScreen) { |
| 769 | return false; |
| 770 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 771 | InCallScreen inCallScreen = InCallBindings.createInCallScreen(); |
| 772 | transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), TAG_IN_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 773 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 774 | didShowInCallScreen = true; |
| 775 | return true; |
| 776 | } |
| 777 | |
| 778 | private boolean hideInCallScreenFragment(FragmentTransaction transaction) { |
| 779 | if (!didShowInCallScreen) { |
| 780 | return false; |
| 781 | } |
| 782 | InCallScreen inCallScreen = getInCallScreen(); |
| 783 | if (inCallScreen != null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 784 | transaction.remove(inCallScreen.getInCallScreenFragment()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 785 | } |
| 786 | didShowInCallScreen = false; |
| 787 | return true; |
| 788 | } |
| 789 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 790 | private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 791 | if (didShowVideoCallScreen) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 792 | VideoCallScreen videoCallScreen = getVideoCallScreen(); |
| 793 | if (videoCallScreen.getCallId().equals(call.getId())) { |
| 794 | return false; |
| 795 | } |
| 796 | LogUtil.i( |
| 797 | "InCallActivity.showVideoCallScreenFragment", |
| 798 | "video call fragment exists but arguments do not match"); |
| 799 | hideVideoCallScreenFragment(transaction); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 800 | } |
| 801 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 802 | LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call); |
| 803 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 804 | VideoCallScreen videoCallScreen = |
| 805 | VideoBindings.createVideoCallScreen( |
| 806 | call.getId(), call.getVideoTech().shouldUseSurfaceView()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 807 | transaction.add(R.id.main, videoCallScreen.getVideoCallScreenFragment(), TAG_VIDEO_CALL_SCREEN); |
| 808 | |
| 809 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 810 | didShowVideoCallScreen = true; |
| 811 | return true; |
| 812 | } |
| 813 | |
| 814 | private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) { |
| 815 | if (!didShowVideoCallScreen) { |
| 816 | return false; |
| 817 | } |
| 818 | VideoCallScreen videoCallScreen = getVideoCallScreen(); |
| 819 | if (videoCallScreen != null) { |
| 820 | transaction.remove(videoCallScreen.getVideoCallScreenFragment()); |
| 821 | } |
| 822 | didShowVideoCallScreen = false; |
| 823 | return true; |
| 824 | } |
| 825 | |
| 826 | AnswerScreen getAnswerScreen() { |
| 827 | return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(TAG_ANSWER_SCREEN); |
| 828 | } |
| 829 | |
| 830 | InCallScreen getInCallScreen() { |
| 831 | return (InCallScreen) getSupportFragmentManager().findFragmentByTag(TAG_IN_CALL_SCREEN); |
| 832 | } |
| 833 | |
| 834 | VideoCallScreen getVideoCallScreen() { |
| 835 | return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(TAG_VIDEO_CALL_SCREEN); |
| 836 | } |
| 837 | |
| 838 | @Override |
| 839 | public void onPseudoScreenStateChanged(boolean isOn) { |
| 840 | LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn); |
| 841 | pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE); |
| 842 | } |
| 843 | |
| 844 | /** |
| 845 | * For some touch related issue, turning off the screen can be faked by drawing a black view over |
| 846 | * the activity. All touch events started when the screen is "off" is rejected. |
| 847 | * |
| 848 | * @see PseudoScreenState |
| 849 | */ |
| 850 | @Override |
| 851 | public boolean dispatchTouchEvent(MotionEvent event) { |
| 852 | // Reject any gesture that started when the screen is in the fake off state. |
| 853 | if (touchDownWhenPseudoScreenOff) { |
| 854 | if (event.getAction() == MotionEvent.ACTION_UP) { |
| 855 | touchDownWhenPseudoScreenOff = false; |
| 856 | } |
| 857 | return true; |
| 858 | } |
| 859 | // Reject all touch event when the screen is in the fake off state. |
| 860 | if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) { |
| 861 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 862 | touchDownWhenPseudoScreenOff = true; |
| 863 | LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff"); |
| 864 | } |
| 865 | return true; |
| 866 | } |
| 867 | return super.dispatchTouchEvent(event); |
| 868 | } |
| 869 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 870 | private static class ShouldShowUiResult { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 871 | public final boolean shouldShow; |
| 872 | public final DialerCall call; |
| 873 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 874 | ShouldShowUiResult(boolean shouldShow, DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 875 | this.shouldShow = shouldShow; |
| 876 | this.call = call; |
| 877 | } |
| 878 | } |
| 879 | } |