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