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