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.app.ActivityManager; |
| 20 | import android.app.ActivityManager.AppTask; |
| 21 | import android.app.ActivityManager.TaskDescription; |
| 22 | import android.app.AlertDialog; |
| 23 | import android.app.Dialog; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 24 | import android.app.KeyguardManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 25 | import android.content.DialogInterface; |
| 26 | import android.content.DialogInterface.OnCancelListener; |
| 27 | import android.content.DialogInterface.OnDismissListener; |
| 28 | import android.content.Intent; |
| 29 | import android.content.res.Configuration; |
| 30 | import android.content.res.Resources; |
| 31 | import android.os.Bundle; |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 32 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.support.annotation.IntDef; |
| 34 | import android.support.annotation.NonNull; |
| 35 | import android.support.annotation.Nullable; |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 36 | import android.support.annotation.VisibleForTesting; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 37 | import android.support.v4.app.Fragment; |
| 38 | import android.support.v4.app.FragmentManager; |
| 39 | import android.support.v4.app.FragmentTransaction; |
| 40 | import android.support.v4.content.res.ResourcesCompat; |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 41 | import android.telecom.CallAudioState; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 42 | import android.telecom.PhoneAccountHandle; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 43 | import android.view.KeyEvent; |
| 44 | import android.view.View; |
| 45 | import android.view.Window; |
| 46 | import android.view.WindowManager; |
| 47 | import android.view.animation.Animation; |
| 48 | import android.view.animation.AnimationUtils; |
| 49 | import android.widget.CheckBox; |
| 50 | import android.widget.Toast; |
| 51 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; |
| 52 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; |
| 53 | import com.android.dialer.animation.AnimUtils; |
| 54 | import com.android.dialer.animation.AnimationListenerAdapter; |
| 55 | import com.android.dialer.common.LogUtil; |
wangqi | fad3d87 | 2017-10-25 13:15:23 -0700 | [diff] [blame] | 56 | import com.android.dialer.compat.ActivityCompat; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 57 | import com.android.dialer.compat.CompatUtils; |
| 58 | import com.android.dialer.logging.Logger; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 59 | import com.android.dialer.logging.ScreenEvent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 60 | import com.android.dialer.util.ViewUtil; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 61 | import com.android.incallui.audiomode.AudioModeProvider; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 62 | import com.android.incallui.call.CallList; |
| 63 | import com.android.incallui.call.DialerCall; |
| 64 | import com.android.incallui.call.DialerCall.State; |
| 65 | import com.android.incallui.call.TelecomAdapter; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 66 | import com.android.incallui.disconnectdialog.DisconnectMessage; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 67 | import com.android.incallui.incalluilock.InCallUiLock; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 68 | import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment; |
| 69 | import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment.Callback; |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 70 | import com.google.common.base.Optional; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 71 | import java.lang.annotation.Retention; |
| 72 | import java.lang.annotation.RetentionPolicy; |
| 73 | import java.util.ArrayList; |
| 74 | import java.util.List; |
| 75 | |
| 76 | /** Shared functionality between the new and old in call activity. */ |
| 77 | public class InCallActivityCommon { |
| 78 | |
| 79 | private static final String INTENT_EXTRA_SHOW_DIALPAD = "InCallActivity.show_dialpad"; |
| 80 | private static final String INTENT_EXTRA_NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call"; |
| 81 | private static final String INTENT_EXTRA_FOR_FULL_SCREEN = |
| 82 | "InCallActivity.for_full_screen_intent"; |
| 83 | |
| 84 | private static final String DIALPAD_TEXT_KEY = "InCallActivity.dialpad_text"; |
| 85 | |
| 86 | private static final String TAG_SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment"; |
| 87 | private static final String TAG_DIALPAD_FRAGMENT = "tag_dialpad_fragment"; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 88 | private static final String TAG_INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi"; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 89 | |
| 90 | @Retention(RetentionPolicy.SOURCE) |
| 91 | @IntDef({ |
| 92 | DIALPAD_REQUEST_NONE, |
| 93 | DIALPAD_REQUEST_SHOW, |
| 94 | DIALPAD_REQUEST_HIDE, |
| 95 | }) |
| 96 | @interface DialpadRequestType {} |
| 97 | |
| 98 | private static final int DIALPAD_REQUEST_NONE = 1; |
| 99 | private static final int DIALPAD_REQUEST_SHOW = 2; |
| 100 | private static final int DIALPAD_REQUEST_HIDE = 3; |
| 101 | |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 102 | private static Optional<Integer> audioRouteForTesting = Optional.absent(); |
| 103 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 104 | private final InCallActivity inCallActivity; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 105 | private boolean showPostCharWaitDialogOnResume; |
| 106 | private String showPostCharWaitDialogCallId; |
| 107 | private String showPostCharWaitDialogChars; |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 108 | private Dialog errorDialog; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 109 | private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 110 | private InCallOrientationEventListener inCallOrientationEventListener; |
| 111 | private Animation dialpadSlideInAnimation; |
| 112 | private Animation dialpadSlideOutAnimation; |
| 113 | private boolean animateDialpadOnShow; |
| 114 | private String dtmfTextToPreopulate; |
| 115 | @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 116 | // If activity is going to be recreated. This is usually happening in {@link onNewIntent}. |
| 117 | private boolean isRecreating; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 118 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 119 | private final SelectPhoneAccountListener selectAccountListener = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 120 | new SelectPhoneAccountListener() { |
| 121 | @Override |
| 122 | public void onPhoneAccountSelected( |
| 123 | PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) { |
| 124 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 125 | LogUtil.i( |
| 126 | "InCallActivityCommon.SelectPhoneAccountListener.onPhoneAccountSelected", |
| 127 | "call: " + call); |
| 128 | if (call != null) { |
| 129 | call.phoneAccountSelected(selectedAccountHandle, setDefault); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void onDialogDismissed(String callId) { |
| 135 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 136 | LogUtil.i( |
| 137 | "InCallActivityCommon.SelectPhoneAccountListener.onDialogDismissed", |
| 138 | "disconnecting call: " + call); |
| 139 | if (call != null) { |
| 140 | call.disconnect(); |
| 141 | } |
| 142 | } |
| 143 | }; |
| 144 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 145 | private InternationalCallOnWifiDialogFragment.Callback internationalCallOnWifiCallback = |
| 146 | new Callback() { |
| 147 | @Override |
| 148 | public void continueCall(@NonNull String callId) { |
| 149 | LogUtil.i("InCallActivityCommon.continueCall", "continuing call with id: %s", callId); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void cancelCall(@NonNull String callId) { |
| 154 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 155 | if (call == null) { |
| 156 | LogUtil.i("InCallActivityCommon.cancelCall", "call destroyed before dialog closed"); |
| 157 | return; |
| 158 | } |
| 159 | LogUtil.i("InCallActivityCommon.cancelCall", "disconnecting international call on wifi"); |
| 160 | call.disconnect(); |
| 161 | } |
| 162 | }; |
| 163 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 164 | public static void setIntentExtras( |
| 165 | Intent intent, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) { |
| 166 | if (showDialpad) { |
| 167 | intent.putExtra(INTENT_EXTRA_SHOW_DIALPAD, true); |
| 168 | } |
| 169 | intent.putExtra(INTENT_EXTRA_NEW_OUTGOING_CALL, newOutgoingCall); |
| 170 | intent.putExtra(INTENT_EXTRA_FOR_FULL_SCREEN, isForFullScreen); |
| 171 | } |
| 172 | |
| 173 | public InCallActivityCommon(InCallActivity inCallActivity) { |
| 174 | this.inCallActivity = inCallActivity; |
| 175 | } |
| 176 | |
| 177 | public void onCreate(Bundle icicle) { |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 178 | setWindowFlags(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 179 | |
| 180 | inCallActivity.setContentView(R.layout.incall_screen); |
| 181 | |
| 182 | internalResolveIntent(inCallActivity.getIntent()); |
| 183 | |
| 184 | boolean isLandscape = |
| 185 | inCallActivity.getResources().getConfiguration().orientation |
| 186 | == Configuration.ORIENTATION_LANDSCAPE; |
| 187 | boolean isRtl = ViewUtil.isRtl(); |
| 188 | |
| 189 | if (isLandscape) { |
| 190 | dialpadSlideInAnimation = |
| 191 | AnimationUtils.loadAnimation( |
| 192 | inCallActivity, isRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right); |
| 193 | dialpadSlideOutAnimation = |
| 194 | AnimationUtils.loadAnimation( |
| 195 | inCallActivity, |
| 196 | isRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right); |
| 197 | } else { |
| 198 | dialpadSlideInAnimation = |
| 199 | AnimationUtils.loadAnimation(inCallActivity, R.anim.dialpad_slide_in_bottom); |
| 200 | dialpadSlideOutAnimation = |
| 201 | AnimationUtils.loadAnimation(inCallActivity, R.anim.dialpad_slide_out_bottom); |
| 202 | } |
| 203 | |
| 204 | dialpadSlideInAnimation.setInterpolator(AnimUtils.EASE_IN); |
| 205 | dialpadSlideOutAnimation.setInterpolator(AnimUtils.EASE_OUT); |
| 206 | |
| 207 | dialpadSlideOutAnimation.setAnimationListener( |
| 208 | new AnimationListenerAdapter() { |
| 209 | @Override |
| 210 | public void onAnimationEnd(Animation animation) { |
| 211 | performHideDialpadFragment(); |
| 212 | } |
| 213 | }); |
| 214 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 215 | // Don't override the value if show dialpad request is true in intent extras. |
| 216 | if (icicle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 217 | // If the dialpad was shown before, set variables indicating it should be shown and |
| 218 | // populated with the previous DTMF text. The dialpad is actually shown and populated |
| 219 | // in onResume() to ensure the hosting fragment has been inflated and is ready to receive it. |
| 220 | if (icicle.containsKey(INTENT_EXTRA_SHOW_DIALPAD)) { |
| 221 | boolean showDialpad = icicle.getBoolean(INTENT_EXTRA_SHOW_DIALPAD); |
| 222 | showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_HIDE; |
| 223 | animateDialpadOnShow = false; |
| 224 | } |
| 225 | dtmfTextToPreopulate = icicle.getString(DIALPAD_TEXT_KEY); |
| 226 | |
| 227 | SelectPhoneAccountDialogFragment dialogFragment = |
| 228 | (SelectPhoneAccountDialogFragment) |
| 229 | inCallActivity.getFragmentManager().findFragmentByTag(TAG_SELECT_ACCOUNT_FRAGMENT); |
| 230 | if (dialogFragment != null) { |
| 231 | dialogFragment.setListener(selectAccountListener); |
| 232 | } |
| 233 | } |
| 234 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 235 | InternationalCallOnWifiDialogFragment existingInternationalFragment = |
| 236 | (InternationalCallOnWifiDialogFragment) |
| 237 | inCallActivity |
| 238 | .getSupportFragmentManager() |
| 239 | .findFragmentByTag(TAG_INTERNATIONAL_CALL_ON_WIFI); |
| 240 | if (existingInternationalFragment != null) { |
| 241 | LogUtil.i( |
| 242 | "InCallActivityCommon.onCreate", "international fragment exists attaching callback"); |
| 243 | existingInternationalFragment.setCallback(internationalCallOnWifiCallback); |
| 244 | } |
| 245 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 246 | inCallOrientationEventListener = new InCallOrientationEventListener(inCallActivity); |
| 247 | } |
| 248 | |
| 249 | public void onSaveInstanceState(Bundle out) { |
| 250 | // TODO: The dialpad fragment should handle this as part of its own state |
| 251 | out.putBoolean(INTENT_EXTRA_SHOW_DIALPAD, isDialpadVisible()); |
| 252 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 253 | if (dialpadFragment != null) { |
| 254 | out.putString(DIALPAD_TEXT_KEY, dialpadFragment.getDtmfText()); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | public void onStart() { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 259 | Trace.beginSection("InCallActivityCommon.onStart"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 260 | // setting activity should be last thing in setup process |
| 261 | InCallPresenter.getInstance().setActivity(inCallActivity); |
| 262 | enableInCallOrientationEventListener( |
| 263 | inCallActivity.getRequestedOrientation() |
| 264 | == InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION); |
| 265 | |
| 266 | InCallPresenter.getInstance().onActivityStarted(); |
yueg | 7b28abc | 2017-09-21 16:08:30 -0700 | [diff] [blame] | 267 | if (!isRecreating) { |
| 268 | InCallPresenter.getInstance().onUiShowing(true); |
| 269 | } |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 270 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | public void onResume() { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 274 | Trace.beginSection("InCallActivityCommon.onResume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 275 | if (InCallPresenter.getInstance().isReadyForTearDown()) { |
| 276 | LogUtil.i( |
| 277 | "InCallActivityCommon.onResume", |
| 278 | "InCallPresenter is ready for tear down, not sending updates"); |
| 279 | } else { |
| 280 | updateTaskDescription(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | // If there is a pending request to show or hide the dialpad, handle that now. |
| 284 | if (showDialpadRequest != DIALPAD_REQUEST_NONE) { |
| 285 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 286 | // Exit fullscreen so that the user has access to the dialpad hide/show button and |
| 287 | // can hide the dialpad. Important when showing the dialpad from within dialer. |
| 288 | InCallPresenter.getInstance().setFullScreen(false, true /* force */); |
| 289 | |
| 290 | inCallActivity.showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */); |
| 291 | animateDialpadOnShow = false; |
| 292 | |
| 293 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 294 | if (dialpadFragment != null) { |
| 295 | dialpadFragment.setDtmfText(dtmfTextToPreopulate); |
| 296 | dtmfTextToPreopulate = null; |
| 297 | } |
| 298 | } else { |
| 299 | LogUtil.i("InCallActivityCommon.onResume", "force hide dialpad"); |
| 300 | if (getDialpadFragment() != null) { |
| 301 | inCallActivity.showDialpadFragment(false /* show */, false /* animate */); |
| 302 | } |
| 303 | } |
| 304 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 305 | } |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 306 | updateNavigationBar(isDialpadVisible()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 307 | |
| 308 | if (showPostCharWaitDialogOnResume) { |
| 309 | showPostCharWaitDialog(showPostCharWaitDialogCallId, showPostCharWaitDialogChars); |
| 310 | } |
| 311 | |
| 312 | CallList.getInstance() |
| 313 | .onInCallUiShown( |
| 314 | inCallActivity.getIntent().getBooleanExtra(INTENT_EXTRA_FOR_FULL_SCREEN, false)); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 315 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | // onPause is guaranteed to be called when the InCallActivity goes |
| 319 | // in the background. |
| 320 | public void onPause() { |
| 321 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 322 | if (dialpadFragment != null) { |
| 323 | dialpadFragment.onDialerKeyUp(null); |
| 324 | } |
roldenburg | 006ac37 | 2017-11-15 10:59:49 -0800 | [diff] [blame] | 325 | |
| 326 | if (inCallActivity.isFinishing()) { |
| 327 | InCallPresenter.getInstance().unsetActivity(inCallActivity); |
| 328 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | public void onStop() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 332 | // Disconnects call waiting for account when activity is hidden e.g. user press home button. |
| 333 | // This is necessary otherwise the pending call will stuck on account choose and no new call |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 334 | // will be able to create. See a bug for more details. |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 335 | // Skip this on locked screen since the activity may go over life cycle and start again. |
| 336 | if (!isRecreating |
| 337 | && !inCallActivity.getSystemService(KeyguardManager.class).isKeyguardLocked()) { |
| 338 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 339 | if (waitingForAccountCall != null) { |
| 340 | waitingForAccountCall.disconnect(); |
| 341 | } |
| 342 | } |
| 343 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 344 | enableInCallOrientationEventListener(false); |
| 345 | InCallPresenter.getInstance().updateIsChangingConfigurations(); |
| 346 | InCallPresenter.getInstance().onActivityStopped(); |
yueg | 7b28abc | 2017-09-21 16:08:30 -0700 | [diff] [blame] | 347 | if (!isRecreating) { |
| 348 | InCallPresenter.getInstance().onUiShowing(false); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 349 | if (errorDialog != null) { |
| 350 | errorDialog.dismiss(); |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 351 | } |
yueg | 7b28abc | 2017-09-21 16:08:30 -0700 | [diff] [blame] | 352 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | public void onDestroy() { |
| 356 | InCallPresenter.getInstance().unsetActivity(inCallActivity); |
| 357 | InCallPresenter.getInstance().updateIsChangingConfigurations(); |
| 358 | } |
| 359 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 360 | void onNewIntent(Intent intent, boolean isRecreating) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 361 | LogUtil.i("InCallActivityCommon.onNewIntent", ""); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 362 | this.isRecreating = isRecreating; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 363 | |
| 364 | // We're being re-launched with a new Intent. Since it's possible for a |
| 365 | // single InCallActivity instance to persist indefinitely (even if we |
| 366 | // finish() ourselves), this sequence can potentially happen any time |
| 367 | // the InCallActivity needs to be displayed. |
| 368 | |
| 369 | // Stash away the new intent so that we can get it in the future |
| 370 | // by calling getIntent(). (Otherwise getIntent() will return the |
| 371 | // original Intent from when we first got created!) |
| 372 | inCallActivity.setIntent(intent); |
| 373 | |
| 374 | // Activities are always paused before receiving a new intent, so |
| 375 | // we can count on our onResume() method being called next. |
| 376 | |
| 377 | // Just like in onCreate(), handle the intent. |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 378 | // Skip if InCallActivity is going to recreate since this will be called in onCreate(). |
| 379 | if (!isRecreating) { |
| 380 | internalResolveIntent(intent); |
| 381 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | public boolean onBackPressed(boolean isInCallScreenVisible) { |
| 385 | LogUtil.i("InCallActivityCommon.onBackPressed", ""); |
| 386 | |
| 387 | // BACK is also used to exit out of any "special modes" of the |
| 388 | // in-call UI: |
| 389 | if (!inCallActivity.isVisible()) { |
| 390 | return true; |
| 391 | } |
| 392 | |
| 393 | if (!isInCallScreenVisible) { |
| 394 | return true; |
| 395 | } |
| 396 | |
| 397 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 398 | if (dialpadFragment != null && dialpadFragment.isVisible()) { |
| 399 | inCallActivity.showDialpadFragment(false /* show */, true /* animate */); |
| 400 | return true; |
| 401 | } |
| 402 | |
| 403 | // Always disable the Back key while an incoming call is ringing |
| 404 | DialerCall call = CallList.getInstance().getIncomingCall(); |
| 405 | if (call != null) { |
| 406 | LogUtil.i("InCallActivityCommon.onBackPressed", "consume Back press for an incoming call"); |
| 407 | return true; |
| 408 | } |
| 409 | |
| 410 | // Nothing special to do. Fall back to the default behavior. |
| 411 | return false; |
| 412 | } |
| 413 | |
| 414 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 415 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 416 | // push input to the dialer. |
| 417 | if (dialpadFragment != null |
| 418 | && (dialpadFragment.isVisible()) |
| 419 | && (dialpadFragment.onDialerKeyUp(event))) { |
| 420 | return true; |
| 421 | } else if (keyCode == KeyEvent.KEYCODE_CALL) { |
| 422 | // Always consume CALL to be sure the PhoneWindow won't do anything with it |
| 423 | return true; |
| 424 | } |
| 425 | return false; |
| 426 | } |
| 427 | |
| 428 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 429 | switch (keyCode) { |
| 430 | case KeyEvent.KEYCODE_CALL: |
| 431 | boolean handled = InCallPresenter.getInstance().handleCallKey(); |
| 432 | if (!handled) { |
| 433 | LogUtil.e( |
| 434 | "InCallActivityCommon.onKeyDown", |
| 435 | "InCallPresenter should always handle KEYCODE_CALL in onKeyDown"); |
| 436 | } |
| 437 | // Always consume CALL to be sure the PhoneWindow won't do anything with it |
| 438 | return true; |
| 439 | |
| 440 | // Note there's no KeyEvent.KEYCODE_ENDCALL case here. |
| 441 | // The standard system-wide handling of the ENDCALL key |
| 442 | // (see PhoneWindowManager's handling of KEYCODE_ENDCALL) |
| 443 | // already implements exactly what the UI spec wants, |
| 444 | // namely (1) "hang up" if there's a current active call, |
| 445 | // or (2) "don't answer" if there's a current ringing call. |
| 446 | |
| 447 | case KeyEvent.KEYCODE_CAMERA: |
| 448 | // Disable the CAMERA button while in-call since it's too |
| 449 | // easy to press accidentally. |
| 450 | return true; |
| 451 | |
| 452 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 453 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 454 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 455 | // Ringer silencing handled by PhoneWindowManager. |
| 456 | break; |
| 457 | |
| 458 | case KeyEvent.KEYCODE_MUTE: |
| 459 | TelecomAdapter.getInstance() |
| 460 | .mute(!AudioModeProvider.getInstance().getAudioState().isMuted()); |
| 461 | return true; |
| 462 | |
| 463 | // Various testing/debugging features, enabled ONLY when VERBOSE == true. |
| 464 | case KeyEvent.KEYCODE_SLASH: |
| 465 | if (LogUtil.isVerboseEnabled()) { |
| 466 | LogUtil.v( |
| 467 | "InCallActivityCommon.onKeyDown", |
| 468 | "----------- InCallActivity View dump --------------"); |
| 469 | // Dump starting from the top-level view of the entire activity: |
| 470 | Window w = inCallActivity.getWindow(); |
| 471 | View decorView = w.getDecorView(); |
| 472 | LogUtil.v("InCallActivityCommon.onKeyDown", "View dump:" + decorView); |
| 473 | return true; |
| 474 | } |
| 475 | break; |
| 476 | case KeyEvent.KEYCODE_EQUALS: |
| 477 | break; |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 478 | default: // fall out |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | return event.getRepeatCount() == 0 && handleDialerKeyDown(keyCode, event); |
| 482 | } |
| 483 | |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 484 | private void setWindowFlags() { |
| 485 | // Allow the activity to be shown when the screen is locked and filter out touch events that are |
| 486 | // "too fat". |
| 487 | int flags = |
| 488 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 489 | | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES; |
| 490 | |
| 491 | // When the audio stream is not directed through Bluetooth, turn the screen on once the |
| 492 | // activity is shown. |
| 493 | final int audioRoute = getAudioRoute(); |
| 494 | if (audioRoute != CallAudioState.ROUTE_BLUETOOTH) { |
| 495 | flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 496 | } |
| 497 | |
| 498 | inCallActivity.getWindow().addFlags(flags); |
| 499 | } |
| 500 | |
| 501 | private static int getAudioRoute() { |
| 502 | if (audioRouteForTesting.isPresent()) { |
| 503 | return audioRouteForTesting.get(); |
| 504 | } |
| 505 | |
| 506 | return AudioModeProvider.getInstance().getAudioState().getRoute(); |
| 507 | } |
| 508 | |
| 509 | @VisibleForTesting(otherwise = VisibleForTesting.NONE) |
| 510 | public static void setAudioRouteForTesting(int audioRoute) { |
| 511 | audioRouteForTesting = Optional.of(audioRoute); |
| 512 | } |
| 513 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 514 | private boolean handleDialerKeyDown(int keyCode, KeyEvent event) { |
| 515 | LogUtil.v("InCallActivityCommon.handleDialerKeyDown", "keyCode %d, event: %s", keyCode, event); |
| 516 | |
| 517 | // As soon as the user starts typing valid dialable keys on the |
| 518 | // keyboard (presumably to type DTMF tones) we start passing the |
| 519 | // key events to the DTMFDialer's onDialerKeyDown. |
| 520 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 521 | if (dialpadFragment != null && dialpadFragment.isVisible()) { |
| 522 | return dialpadFragment.onDialerKeyDown(event); |
| 523 | } |
| 524 | |
| 525 | return false; |
| 526 | } |
| 527 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 528 | public void showPostCharWaitDialog(String callId, String chars) { |
| 529 | if (inCallActivity.isVisible()) { |
| 530 | PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars); |
| 531 | fragment.show(inCallActivity.getSupportFragmentManager(), "postCharWait"); |
| 532 | |
| 533 | showPostCharWaitDialogOnResume = false; |
| 534 | showPostCharWaitDialogCallId = null; |
| 535 | showPostCharWaitDialogChars = null; |
| 536 | } else { |
| 537 | showPostCharWaitDialogOnResume = true; |
| 538 | showPostCharWaitDialogCallId = callId; |
| 539 | showPostCharWaitDialogChars = chars; |
| 540 | } |
| 541 | } |
| 542 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 543 | public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 544 | LogUtil.i( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 545 | "InCallActivityCommon.maybeShowErrorDialogOnDisconnect", |
| 546 | "disconnect cause: %s", |
| 547 | disconnectMessage); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 548 | |
| 549 | if (!inCallActivity.isFinishing()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 550 | if (disconnectMessage.dialog != null) { |
| 551 | showErrorDialog(disconnectMessage.dialog, disconnectMessage.toastMessage); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should |
| 558 | * be shown on launch. |
| 559 | * |
| 560 | * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code |
| 561 | * false} to indicate no change should be made to the dialpad visibility. |
| 562 | */ |
| 563 | private void relaunchedFromDialer(boolean showDialpad) { |
| 564 | showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE; |
| 565 | animateDialpadOnShow = true; |
| 566 | |
| 567 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 568 | // If there's only one line in use, AND it's on hold, then we're sure the user |
| 569 | // wants to use the dialpad toward the exact line, so un-hold the holding line. |
| 570 | DialerCall call = CallList.getInstance().getActiveOrBackgroundCall(); |
| 571 | if (call != null && call.getState() == State.ONHOLD) { |
| 572 | call.unhold(); |
| 573 | } |
| 574 | } |
| 575 | } |
| 576 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 577 | private void showErrorDialog(Dialog dialog, CharSequence message) { |
| 578 | LogUtil.i("InCallActivityCommon.showErrorDialog", "message: %s", message); |
| 579 | inCallActivity.dismissPendingDialogs(); |
| 580 | |
| 581 | // Show toast if apps is in background when dialog won't be visible. |
| 582 | if (!inCallActivity.isVisible()) { |
| 583 | Toast.makeText(inCallActivity.getApplicationContext(), message, Toast.LENGTH_LONG).show(); |
| 584 | return; |
| 585 | } |
| 586 | |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 587 | this.errorDialog = dialog; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 588 | InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 589 | dialog.setOnDismissListener( |
| 590 | new OnDismissListener() { |
| 591 | @Override |
| 592 | public void onDismiss(DialogInterface dialog) { |
| 593 | LogUtil.i("InCallActivityCommon.showErrorDialog", "dialog dismissed"); |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 594 | lock.release(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 595 | onDialogDismissed(); |
| 596 | } |
| 597 | }); |
| 598 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 599 | dialog.show(); |
| 600 | } |
| 601 | |
| 602 | private void onDialogDismissed() { |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 603 | errorDialog = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 604 | CallList.getInstance().onErrorDialogDismissed(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | public void enableInCallOrientationEventListener(boolean enable) { |
| 608 | if (enable) { |
| 609 | inCallOrientationEventListener.enable(true); |
| 610 | } else { |
| 611 | inCallOrientationEventListener.disable(); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | public void setExcludeFromRecents(boolean exclude) { |
| 616 | List<AppTask> tasks = inCallActivity.getSystemService(ActivityManager.class).getAppTasks(); |
| 617 | int taskId = inCallActivity.getTaskId(); |
| 618 | for (int i = 0; i < tasks.size(); i++) { |
| 619 | ActivityManager.AppTask task = tasks.get(i); |
| 620 | try { |
| 621 | if (task.getTaskInfo().id == taskId) { |
| 622 | task.setExcludeFromRecents(exclude); |
| 623 | } |
| 624 | } catch (RuntimeException e) { |
| 625 | LogUtil.e( |
| 626 | "InCallActivityCommon.setExcludeFromRecents", |
| 627 | "RuntimeException when excluding task from recents.", |
| 628 | e); |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 633 | void showInternationalCallOnWifiDialog(@NonNull DialerCall call) { |
| 634 | LogUtil.enterBlock("InCallActivityCommon.showInternationalCallOnWifiDialog"); |
| 635 | if (!InternationalCallOnWifiDialogFragment.shouldShow(inCallActivity)) { |
| 636 | LogUtil.i( |
| 637 | "InCallActivityCommon.showInternationalCallOnWifiDialog", |
| 638 | "InternationalCallOnWifiDialogFragment.shouldShow returned false"); |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | InternationalCallOnWifiDialogFragment fragment = |
| 643 | InternationalCallOnWifiDialogFragment.newInstance( |
| 644 | call.getId(), internationalCallOnWifiCallback); |
| 645 | fragment.show(inCallActivity.getSupportFragmentManager(), TAG_INTERNATIONAL_CALL_ON_WIFI); |
| 646 | } |
| 647 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 648 | public void showWifiToLteHandoverToast(DialerCall call) { |
| 649 | if (call.hasShownWiFiToLteHandoverToast()) { |
| 650 | return; |
| 651 | } |
| 652 | Toast.makeText( |
| 653 | inCallActivity, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG) |
| 654 | .show(); |
| 655 | call.setHasShownWiFiToLteHandoverToast(); |
| 656 | } |
| 657 | |
| 658 | public void showWifiFailedDialog(final DialerCall call) { |
| 659 | if (call.showWifiHandoverAlertAsToast()) { |
| 660 | LogUtil.i("InCallActivityCommon.showWifiFailedDialog", "as toast"); |
| 661 | Toast.makeText( |
| 662 | inCallActivity, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT) |
| 663 | .show(); |
| 664 | return; |
| 665 | } |
| 666 | |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 667 | inCallActivity.dismissPendingDialogs(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 668 | |
| 669 | AlertDialog.Builder builder = |
| 670 | new AlertDialog.Builder(inCallActivity) |
| 671 | .setTitle(R.string.video_call_lte_to_wifi_failed_title); |
| 672 | |
| 673 | // This allows us to use the theme of the dialog instead of the activity |
| 674 | View dialogCheckBoxView = |
| 675 | View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null); |
| 676 | final CheckBox wifiHandoverFailureCheckbox = |
| 677 | (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox); |
| 678 | wifiHandoverFailureCheckbox.setChecked(false); |
| 679 | |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 680 | InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog"); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 681 | errorDialog = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 682 | builder |
| 683 | .setView(dialogCheckBoxView) |
| 684 | .setMessage(R.string.video_call_lte_to_wifi_failed_message) |
| 685 | .setOnCancelListener( |
| 686 | new OnCancelListener() { |
| 687 | @Override |
| 688 | public void onCancel(DialogInterface dialog) { |
| 689 | onDialogDismissed(); |
| 690 | } |
| 691 | }) |
| 692 | .setPositiveButton( |
| 693 | android.R.string.ok, |
| 694 | new DialogInterface.OnClickListener() { |
| 695 | @Override |
| 696 | public void onClick(DialogInterface dialog, int id) { |
| 697 | call.setDoNotShowDialogForHandoffToWifiFailure( |
| 698 | wifiHandoverFailureCheckbox.isChecked()); |
| 699 | dialog.cancel(); |
| 700 | onDialogDismissed(); |
| 701 | } |
| 702 | }) |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 703 | .setOnDismissListener((dialog) -> lock.release()) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 704 | .create(); |
| 705 | |
| 706 | LogUtil.i("InCallActivityCommon.showWifiFailedDialog", "as dialog"); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 707 | errorDialog.show(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 708 | } |
| 709 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 710 | void updateNavigationBar(boolean isDialpadVisible) { |
wangqi | fad3d87 | 2017-10-25 13:15:23 -0700 | [diff] [blame] | 711 | if (!ActivityCompat.isInMultiWindowMode(inCallActivity)) { |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 712 | View navigationBarBackground = |
| 713 | inCallActivity.getWindow().findViewById(R.id.navigation_bar_background); |
| 714 | if (navigationBarBackground != null) { |
| 715 | navigationBarBackground.setVisibility(isDialpadVisible ? View.VISIBLE : View.GONE); |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 720 | public boolean showDialpadFragment(boolean show, boolean animate) { |
| 721 | // If the dialpad is already visible, don't animate in. If it's gone, don't animate out. |
| 722 | boolean isDialpadVisible = isDialpadVisible(); |
| 723 | LogUtil.i( |
| 724 | "InCallActivityCommon.showDialpadFragment", |
| 725 | "show: %b, animate: %b, " + "isDialpadVisible: %b", |
| 726 | show, |
| 727 | animate, |
| 728 | isDialpadVisible); |
| 729 | if (show == isDialpadVisible) { |
| 730 | return false; |
| 731 | } |
| 732 | |
| 733 | FragmentManager dialpadFragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 734 | if (dialpadFragmentManager == null) { |
| 735 | LogUtil.i( |
| 736 | "InCallActivityCommon.showDialpadFragment", "unable to show or hide dialpad fragment"); |
| 737 | return false; |
| 738 | } |
| 739 | |
| 740 | // We don't do a FragmentTransaction on the hide case because it will be dealt with when |
| 741 | // the listener is fired after an animation finishes. |
| 742 | if (!animate) { |
| 743 | if (show) { |
| 744 | performShowDialpadFragment(dialpadFragmentManager); |
| 745 | } else { |
| 746 | performHideDialpadFragment(); |
| 747 | } |
| 748 | } else { |
| 749 | if (show) { |
| 750 | performShowDialpadFragment(dialpadFragmentManager); |
| 751 | getDialpadFragment().animateShowDialpad(); |
| 752 | } |
| 753 | getDialpadFragment() |
| 754 | .getView() |
| 755 | .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation); |
| 756 | } |
| 757 | |
| 758 | ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor(); |
| 759 | if (sensor != null) { |
| 760 | sensor.onDialpadVisible(show); |
| 761 | } |
| 762 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 763 | return true; |
| 764 | } |
| 765 | |
| 766 | private void performShowDialpadFragment(@NonNull FragmentManager dialpadFragmentManager) { |
| 767 | FragmentTransaction transaction = dialpadFragmentManager.beginTransaction(); |
| 768 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 769 | if (dialpadFragment == null) { |
| 770 | transaction.add( |
| 771 | inCallActivity.getDialpadContainerId(), new DialpadFragment(), TAG_DIALPAD_FRAGMENT); |
| 772 | } else { |
| 773 | transaction.show(dialpadFragment); |
| 774 | } |
| 775 | |
| 776 | transaction.commitAllowingStateLoss(); |
| 777 | dialpadFragmentManager.executePendingTransactions(); |
| 778 | |
| 779 | Logger.get(inCallActivity).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, inCallActivity); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 780 | updateNavigationBar(true /* isDialpadVisible */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | private void performHideDialpadFragment() { |
| 784 | FragmentManager fragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 785 | if (fragmentManager == null) { |
| 786 | LogUtil.e( |
| 787 | "InCallActivityCommon.performHideDialpadFragment", "child fragment manager is null"); |
| 788 | return; |
| 789 | } |
| 790 | |
| 791 | Fragment fragment = fragmentManager.findFragmentByTag(TAG_DIALPAD_FRAGMENT); |
| 792 | if (fragment != null) { |
| 793 | FragmentTransaction transaction = fragmentManager.beginTransaction(); |
| 794 | transaction.hide(fragment); |
| 795 | transaction.commitAllowingStateLoss(); |
| 796 | fragmentManager.executePendingTransactions(); |
| 797 | } |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 798 | updateNavigationBar(false /* isDialpadVisible */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | public boolean isDialpadVisible() { |
| 802 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 803 | return dialpadFragment != null && dialpadFragment.isVisible(); |
| 804 | } |
| 805 | |
| 806 | /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */ |
| 807 | @Nullable |
| 808 | private DialpadFragment getDialpadFragment() { |
| 809 | FragmentManager fragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 810 | if (fragmentManager == null) { |
| 811 | return null; |
| 812 | } |
| 813 | return (DialpadFragment) fragmentManager.findFragmentByTag(TAG_DIALPAD_FRAGMENT); |
| 814 | } |
| 815 | |
| 816 | public void updateTaskDescription() { |
| 817 | Resources resources = inCallActivity.getResources(); |
| 818 | int color; |
| 819 | if (resources.getBoolean(R.bool.is_layout_landscape)) { |
| 820 | color = |
| 821 | ResourcesCompat.getColor( |
| 822 | resources, R.color.statusbar_background_color, inCallActivity.getTheme()); |
| 823 | } else { |
| 824 | color = InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor(); |
| 825 | } |
| 826 | |
| 827 | TaskDescription td = |
| 828 | new TaskDescription(resources.getString(R.string.notification_ongoing_call), null, color); |
| 829 | inCallActivity.setTaskDescription(td); |
| 830 | } |
| 831 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 832 | private void internalResolveIntent(Intent intent) { |
| 833 | if (!intent.getAction().equals(Intent.ACTION_MAIN)) { |
| 834 | return; |
| 835 | } |
| 836 | |
| 837 | if (intent.hasExtra(INTENT_EXTRA_SHOW_DIALPAD)) { |
| 838 | // SHOW_DIALPAD_EXTRA can be used here to specify whether the DTMF |
| 839 | // dialpad should be initially visible. If the extra isn't |
| 840 | // present at all, we just leave the dialpad in its previous state. |
| 841 | boolean showDialpad = intent.getBooleanExtra(INTENT_EXTRA_SHOW_DIALPAD, false); |
| 842 | LogUtil.i("InCallActivityCommon.internalResolveIntent", "SHOW_DIALPAD_EXTRA: " + showDialpad); |
| 843 | |
| 844 | relaunchedFromDialer(showDialpad); |
| 845 | } |
| 846 | |
| 847 | DialerCall outgoingCall = CallList.getInstance().getOutgoingCall(); |
| 848 | if (outgoingCall == null) { |
| 849 | outgoingCall = CallList.getInstance().getPendingOutgoingCall(); |
| 850 | } |
| 851 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 852 | if (intent.getBooleanExtra(INTENT_EXTRA_NEW_OUTGOING_CALL, false)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 853 | intent.removeExtra(INTENT_EXTRA_NEW_OUTGOING_CALL); |
| 854 | |
| 855 | // InCallActivity is responsible for disconnecting a new outgoing call if there |
| 856 | // is no way of making it (i.e. no valid call capable accounts). |
| 857 | // If the version is not MSIM compatible, then ignore this code. |
| 858 | if (CompatUtils.isMSIMCompatible() |
| 859 | && InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) { |
| 860 | LogUtil.i( |
| 861 | "InCallActivityCommon.internalResolveIntent", |
| 862 | "call with no valid accounts, disconnecting"); |
| 863 | outgoingCall.disconnect(); |
| 864 | } |
| 865 | |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame] | 866 | inCallActivity.dismissKeyguard(true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | boolean didShowAccountSelectionDialog = maybeShowAccountSelectionDialog(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 870 | if (didShowAccountSelectionDialog) { |
| 871 | inCallActivity.hideMainInCallFragment(); |
| 872 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | private boolean maybeShowAccountSelectionDialog() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 876 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 877 | if (waitingForAccountCall == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 878 | return false; |
| 879 | } |
| 880 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 881 | Bundle extras = waitingForAccountCall.getIntentExtras(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 882 | List<PhoneAccountHandle> phoneAccountHandles; |
| 883 | if (extras != null) { |
| 884 | phoneAccountHandles = |
| 885 | extras.getParcelableArrayList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS); |
| 886 | } else { |
| 887 | phoneAccountHandles = new ArrayList<>(); |
| 888 | } |
| 889 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 890 | selectPhoneAccountDialogFragment = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 891 | SelectPhoneAccountDialogFragment.newInstance( |
| 892 | R.string.select_phone_account_for_calls, |
| 893 | true, |
| 894 | phoneAccountHandles, |
| 895 | selectAccountListener, |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 896 | waitingForAccountCall.getId()); |
| 897 | selectPhoneAccountDialogFragment.show( |
| 898 | inCallActivity.getFragmentManager(), TAG_SELECT_ACCOUNT_FRAGMENT); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 899 | return true; |
| 900 | } |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame^] | 901 | |
| 902 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 903 | @Deprecated |
| 904 | @Nullable |
| 905 | Dialog getErrorDialog() { |
| 906 | return errorDialog; |
| 907 | } |
| 908 | |
| 909 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 910 | @Deprecated |
| 911 | void setErrorDialog(@Nullable Dialog errorDialog) { |
| 912 | this.errorDialog = errorDialog; |
| 913 | } |
| 914 | |
| 915 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 916 | @Deprecated |
| 917 | @Nullable |
| 918 | SelectPhoneAccountDialogFragment getSelectPhoneAccountDialogFragment() { |
| 919 | return selectPhoneAccountDialogFragment; |
| 920 | } |
| 921 | |
| 922 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 923 | @Deprecated |
| 924 | void setSelectPhoneAccountDialogFragment( |
| 925 | @Nullable SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment) { |
| 926 | this.selectPhoneAccountDialogFragment = selectPhoneAccountDialogFragment; |
| 927 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 928 | } |