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(); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 267 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | public void onResume() { |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 271 | Trace.beginSection("InCallActivityCommon.onResume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 272 | if (InCallPresenter.getInstance().isReadyForTearDown()) { |
| 273 | LogUtil.i( |
| 274 | "InCallActivityCommon.onResume", |
| 275 | "InCallPresenter is ready for tear down, not sending updates"); |
| 276 | } else { |
| 277 | updateTaskDescription(); |
roldenburg | 4307347 | 2017-11-15 12:31:06 -0800 | [diff] [blame^] | 278 | InCallPresenter.getInstance().onUiShowing(true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | // If there is a pending request to show or hide the dialpad, handle that now. |
| 282 | if (showDialpadRequest != DIALPAD_REQUEST_NONE) { |
| 283 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 284 | // Exit fullscreen so that the user has access to the dialpad hide/show button and |
| 285 | // can hide the dialpad. Important when showing the dialpad from within dialer. |
| 286 | InCallPresenter.getInstance().setFullScreen(false, true /* force */); |
| 287 | |
| 288 | inCallActivity.showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */); |
| 289 | animateDialpadOnShow = false; |
| 290 | |
| 291 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 292 | if (dialpadFragment != null) { |
| 293 | dialpadFragment.setDtmfText(dtmfTextToPreopulate); |
| 294 | dtmfTextToPreopulate = null; |
| 295 | } |
| 296 | } else { |
| 297 | LogUtil.i("InCallActivityCommon.onResume", "force hide dialpad"); |
| 298 | if (getDialpadFragment() != null) { |
| 299 | inCallActivity.showDialpadFragment(false /* show */, false /* animate */); |
| 300 | } |
| 301 | } |
| 302 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 303 | } |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 304 | updateNavigationBar(isDialpadVisible()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 305 | |
| 306 | if (showPostCharWaitDialogOnResume) { |
| 307 | showPostCharWaitDialog(showPostCharWaitDialogCallId, showPostCharWaitDialogChars); |
| 308 | } |
| 309 | |
| 310 | CallList.getInstance() |
| 311 | .onInCallUiShown( |
| 312 | inCallActivity.getIntent().getBooleanExtra(INTENT_EXTRA_FOR_FULL_SCREEN, false)); |
wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 313 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | // onPause is guaranteed to be called when the InCallActivity goes |
| 317 | // in the background. |
| 318 | public void onPause() { |
| 319 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 320 | if (dialpadFragment != null) { |
| 321 | dialpadFragment.onDialerKeyUp(null); |
| 322 | } |
roldenburg | 006ac37 | 2017-11-15 10:59:49 -0800 | [diff] [blame] | 323 | |
roldenburg | 4307347 | 2017-11-15 12:31:06 -0800 | [diff] [blame^] | 324 | InCallPresenter.getInstance().onUiShowing(false); |
roldenburg | 006ac37 | 2017-11-15 10:59:49 -0800 | [diff] [blame] | 325 | if (inCallActivity.isFinishing()) { |
| 326 | InCallPresenter.getInstance().unsetActivity(inCallActivity); |
| 327 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | public void onStop() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 331 | // Disconnects call waiting for account when activity is hidden e.g. user press home button. |
| 332 | // 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] | 333 | // will be able to create. See a bug for more details. |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 334 | // Skip this on locked screen since the activity may go over life cycle and start again. |
| 335 | if (!isRecreating |
| 336 | && !inCallActivity.getSystemService(KeyguardManager.class).isKeyguardLocked()) { |
| 337 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 338 | if (waitingForAccountCall != null) { |
| 339 | waitingForAccountCall.disconnect(); |
| 340 | } |
| 341 | } |
| 342 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 343 | enableInCallOrientationEventListener(false); |
| 344 | InCallPresenter.getInstance().updateIsChangingConfigurations(); |
| 345 | InCallPresenter.getInstance().onActivityStopped(); |
yueg | 7b28abc | 2017-09-21 16:08:30 -0700 | [diff] [blame] | 346 | if (!isRecreating) { |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 347 | if (errorDialog != null) { |
| 348 | errorDialog.dismiss(); |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 349 | } |
yueg | 7b28abc | 2017-09-21 16:08:30 -0700 | [diff] [blame] | 350 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | public void onDestroy() { |
| 354 | InCallPresenter.getInstance().unsetActivity(inCallActivity); |
| 355 | InCallPresenter.getInstance().updateIsChangingConfigurations(); |
| 356 | } |
| 357 | |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 358 | void onNewIntent(Intent intent, boolean isRecreating) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 359 | LogUtil.i("InCallActivityCommon.onNewIntent", ""); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 360 | this.isRecreating = isRecreating; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 361 | |
| 362 | // We're being re-launched with a new Intent. Since it's possible for a |
| 363 | // single InCallActivity instance to persist indefinitely (even if we |
| 364 | // finish() ourselves), this sequence can potentially happen any time |
| 365 | // the InCallActivity needs to be displayed. |
| 366 | |
| 367 | // Stash away the new intent so that we can get it in the future |
| 368 | // by calling getIntent(). (Otherwise getIntent() will return the |
| 369 | // original Intent from when we first got created!) |
| 370 | inCallActivity.setIntent(intent); |
| 371 | |
| 372 | // Activities are always paused before receiving a new intent, so |
| 373 | // we can count on our onResume() method being called next. |
| 374 | |
| 375 | // Just like in onCreate(), handle the intent. |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 376 | // Skip if InCallActivity is going to recreate since this will be called in onCreate(). |
| 377 | if (!isRecreating) { |
| 378 | internalResolveIntent(intent); |
| 379 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | public boolean onBackPressed(boolean isInCallScreenVisible) { |
| 383 | LogUtil.i("InCallActivityCommon.onBackPressed", ""); |
| 384 | |
| 385 | // BACK is also used to exit out of any "special modes" of the |
| 386 | // in-call UI: |
| 387 | if (!inCallActivity.isVisible()) { |
| 388 | return true; |
| 389 | } |
| 390 | |
| 391 | if (!isInCallScreenVisible) { |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 396 | if (dialpadFragment != null && dialpadFragment.isVisible()) { |
| 397 | inCallActivity.showDialpadFragment(false /* show */, true /* animate */); |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | // Always disable the Back key while an incoming call is ringing |
| 402 | DialerCall call = CallList.getInstance().getIncomingCall(); |
| 403 | if (call != null) { |
| 404 | LogUtil.i("InCallActivityCommon.onBackPressed", "consume Back press for an incoming call"); |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | // Nothing special to do. Fall back to the default behavior. |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 413 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 414 | // push input to the dialer. |
| 415 | if (dialpadFragment != null |
| 416 | && (dialpadFragment.isVisible()) |
| 417 | && (dialpadFragment.onDialerKeyUp(event))) { |
| 418 | return true; |
| 419 | } else if (keyCode == KeyEvent.KEYCODE_CALL) { |
| 420 | // Always consume CALL to be sure the PhoneWindow won't do anything with it |
| 421 | return true; |
| 422 | } |
| 423 | return false; |
| 424 | } |
| 425 | |
| 426 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 427 | switch (keyCode) { |
| 428 | case KeyEvent.KEYCODE_CALL: |
| 429 | boolean handled = InCallPresenter.getInstance().handleCallKey(); |
| 430 | if (!handled) { |
| 431 | LogUtil.e( |
| 432 | "InCallActivityCommon.onKeyDown", |
| 433 | "InCallPresenter should always handle KEYCODE_CALL in onKeyDown"); |
| 434 | } |
| 435 | // Always consume CALL to be sure the PhoneWindow won't do anything with it |
| 436 | return true; |
| 437 | |
| 438 | // Note there's no KeyEvent.KEYCODE_ENDCALL case here. |
| 439 | // The standard system-wide handling of the ENDCALL key |
| 440 | // (see PhoneWindowManager's handling of KEYCODE_ENDCALL) |
| 441 | // already implements exactly what the UI spec wants, |
| 442 | // namely (1) "hang up" if there's a current active call, |
| 443 | // or (2) "don't answer" if there's a current ringing call. |
| 444 | |
| 445 | case KeyEvent.KEYCODE_CAMERA: |
| 446 | // Disable the CAMERA button while in-call since it's too |
| 447 | // easy to press accidentally. |
| 448 | return true; |
| 449 | |
| 450 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 451 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 452 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 453 | // Ringer silencing handled by PhoneWindowManager. |
| 454 | break; |
| 455 | |
| 456 | case KeyEvent.KEYCODE_MUTE: |
| 457 | TelecomAdapter.getInstance() |
| 458 | .mute(!AudioModeProvider.getInstance().getAudioState().isMuted()); |
| 459 | return true; |
| 460 | |
| 461 | // Various testing/debugging features, enabled ONLY when VERBOSE == true. |
| 462 | case KeyEvent.KEYCODE_SLASH: |
| 463 | if (LogUtil.isVerboseEnabled()) { |
| 464 | LogUtil.v( |
| 465 | "InCallActivityCommon.onKeyDown", |
| 466 | "----------- InCallActivity View dump --------------"); |
| 467 | // Dump starting from the top-level view of the entire activity: |
| 468 | Window w = inCallActivity.getWindow(); |
| 469 | View decorView = w.getDecorView(); |
| 470 | LogUtil.v("InCallActivityCommon.onKeyDown", "View dump:" + decorView); |
| 471 | return true; |
| 472 | } |
| 473 | break; |
| 474 | case KeyEvent.KEYCODE_EQUALS: |
| 475 | break; |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 476 | default: // fall out |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | return event.getRepeatCount() == 0 && handleDialerKeyDown(keyCode, event); |
| 480 | } |
| 481 | |
linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 482 | private void setWindowFlags() { |
| 483 | // Allow the activity to be shown when the screen is locked and filter out touch events that are |
| 484 | // "too fat". |
| 485 | int flags = |
| 486 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 487 | | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES; |
| 488 | |
| 489 | // When the audio stream is not directed through Bluetooth, turn the screen on once the |
| 490 | // activity is shown. |
| 491 | final int audioRoute = getAudioRoute(); |
| 492 | if (audioRoute != CallAudioState.ROUTE_BLUETOOTH) { |
| 493 | flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 494 | } |
| 495 | |
| 496 | inCallActivity.getWindow().addFlags(flags); |
| 497 | } |
| 498 | |
| 499 | private static int getAudioRoute() { |
| 500 | if (audioRouteForTesting.isPresent()) { |
| 501 | return audioRouteForTesting.get(); |
| 502 | } |
| 503 | |
| 504 | return AudioModeProvider.getInstance().getAudioState().getRoute(); |
| 505 | } |
| 506 | |
| 507 | @VisibleForTesting(otherwise = VisibleForTesting.NONE) |
| 508 | public static void setAudioRouteForTesting(int audioRoute) { |
| 509 | audioRouteForTesting = Optional.of(audioRoute); |
| 510 | } |
| 511 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 512 | private boolean handleDialerKeyDown(int keyCode, KeyEvent event) { |
| 513 | LogUtil.v("InCallActivityCommon.handleDialerKeyDown", "keyCode %d, event: %s", keyCode, event); |
| 514 | |
| 515 | // As soon as the user starts typing valid dialable keys on the |
| 516 | // keyboard (presumably to type DTMF tones) we start passing the |
| 517 | // key events to the DTMFDialer's onDialerKeyDown. |
| 518 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 519 | if (dialpadFragment != null && dialpadFragment.isVisible()) { |
| 520 | return dialpadFragment.onDialerKeyDown(event); |
| 521 | } |
| 522 | |
| 523 | return false; |
| 524 | } |
| 525 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 526 | public void showPostCharWaitDialog(String callId, String chars) { |
| 527 | if (inCallActivity.isVisible()) { |
| 528 | PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars); |
| 529 | fragment.show(inCallActivity.getSupportFragmentManager(), "postCharWait"); |
| 530 | |
| 531 | showPostCharWaitDialogOnResume = false; |
| 532 | showPostCharWaitDialogCallId = null; |
| 533 | showPostCharWaitDialogChars = null; |
| 534 | } else { |
| 535 | showPostCharWaitDialogOnResume = true; |
| 536 | showPostCharWaitDialogCallId = callId; |
| 537 | showPostCharWaitDialogChars = chars; |
| 538 | } |
| 539 | } |
| 540 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 541 | public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 542 | LogUtil.i( |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 543 | "InCallActivityCommon.maybeShowErrorDialogOnDisconnect", |
| 544 | "disconnect cause: %s", |
| 545 | disconnectMessage); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 546 | |
| 547 | if (!inCallActivity.isFinishing()) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 548 | if (disconnectMessage.dialog != null) { |
| 549 | showErrorDialog(disconnectMessage.dialog, disconnectMessage.toastMessage); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should |
| 556 | * be shown on launch. |
| 557 | * |
| 558 | * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code |
| 559 | * false} to indicate no change should be made to the dialpad visibility. |
| 560 | */ |
| 561 | private void relaunchedFromDialer(boolean showDialpad) { |
| 562 | showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE; |
| 563 | animateDialpadOnShow = true; |
| 564 | |
| 565 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 566 | // If there's only one line in use, AND it's on hold, then we're sure the user |
| 567 | // wants to use the dialpad toward the exact line, so un-hold the holding line. |
| 568 | DialerCall call = CallList.getInstance().getActiveOrBackgroundCall(); |
| 569 | if (call != null && call.getState() == State.ONHOLD) { |
| 570 | call.unhold(); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 575 | private void showErrorDialog(Dialog dialog, CharSequence message) { |
| 576 | LogUtil.i("InCallActivityCommon.showErrorDialog", "message: %s", message); |
| 577 | inCallActivity.dismissPendingDialogs(); |
| 578 | |
| 579 | // Show toast if apps is in background when dialog won't be visible. |
| 580 | if (!inCallActivity.isVisible()) { |
| 581 | Toast.makeText(inCallActivity.getApplicationContext(), message, Toast.LENGTH_LONG).show(); |
| 582 | return; |
| 583 | } |
| 584 | |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 585 | this.errorDialog = dialog; |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 586 | InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("showErrorDialog"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 587 | dialog.setOnDismissListener( |
| 588 | new OnDismissListener() { |
| 589 | @Override |
| 590 | public void onDismiss(DialogInterface dialog) { |
| 591 | LogUtil.i("InCallActivityCommon.showErrorDialog", "dialog dismissed"); |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 592 | lock.release(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 593 | onDialogDismissed(); |
| 594 | } |
| 595 | }); |
| 596 | dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 597 | dialog.show(); |
| 598 | } |
| 599 | |
| 600 | private void onDialogDismissed() { |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 601 | errorDialog = null; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 602 | CallList.getInstance().onErrorDialogDismissed(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | public void enableInCallOrientationEventListener(boolean enable) { |
| 606 | if (enable) { |
| 607 | inCallOrientationEventListener.enable(true); |
| 608 | } else { |
| 609 | inCallOrientationEventListener.disable(); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | public void setExcludeFromRecents(boolean exclude) { |
| 614 | List<AppTask> tasks = inCallActivity.getSystemService(ActivityManager.class).getAppTasks(); |
| 615 | int taskId = inCallActivity.getTaskId(); |
| 616 | for (int i = 0; i < tasks.size(); i++) { |
| 617 | ActivityManager.AppTask task = tasks.get(i); |
| 618 | try { |
| 619 | if (task.getTaskInfo().id == taskId) { |
| 620 | task.setExcludeFromRecents(exclude); |
| 621 | } |
| 622 | } catch (RuntimeException e) { |
| 623 | LogUtil.e( |
| 624 | "InCallActivityCommon.setExcludeFromRecents", |
| 625 | "RuntimeException when excluding task from recents.", |
| 626 | e); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 631 | void showInternationalCallOnWifiDialog(@NonNull DialerCall call) { |
| 632 | LogUtil.enterBlock("InCallActivityCommon.showInternationalCallOnWifiDialog"); |
| 633 | if (!InternationalCallOnWifiDialogFragment.shouldShow(inCallActivity)) { |
| 634 | LogUtil.i( |
| 635 | "InCallActivityCommon.showInternationalCallOnWifiDialog", |
| 636 | "InternationalCallOnWifiDialogFragment.shouldShow returned false"); |
| 637 | return; |
| 638 | } |
| 639 | |
| 640 | InternationalCallOnWifiDialogFragment fragment = |
| 641 | InternationalCallOnWifiDialogFragment.newInstance( |
| 642 | call.getId(), internationalCallOnWifiCallback); |
| 643 | fragment.show(inCallActivity.getSupportFragmentManager(), TAG_INTERNATIONAL_CALL_ON_WIFI); |
| 644 | } |
| 645 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 646 | public void showWifiToLteHandoverToast(DialerCall call) { |
| 647 | if (call.hasShownWiFiToLteHandoverToast()) { |
| 648 | return; |
| 649 | } |
| 650 | Toast.makeText( |
| 651 | inCallActivity, R.string.video_call_wifi_to_lte_handover_toast, Toast.LENGTH_LONG) |
| 652 | .show(); |
| 653 | call.setHasShownWiFiToLteHandoverToast(); |
| 654 | } |
| 655 | |
| 656 | public void showWifiFailedDialog(final DialerCall call) { |
| 657 | if (call.showWifiHandoverAlertAsToast()) { |
| 658 | LogUtil.i("InCallActivityCommon.showWifiFailedDialog", "as toast"); |
| 659 | Toast.makeText( |
| 660 | inCallActivity, R.string.video_call_lte_to_wifi_failed_message, Toast.LENGTH_SHORT) |
| 661 | .show(); |
| 662 | return; |
| 663 | } |
| 664 | |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 665 | inCallActivity.dismissPendingDialogs(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 666 | |
| 667 | AlertDialog.Builder builder = |
| 668 | new AlertDialog.Builder(inCallActivity) |
| 669 | .setTitle(R.string.video_call_lte_to_wifi_failed_title); |
| 670 | |
| 671 | // This allows us to use the theme of the dialog instead of the activity |
| 672 | View dialogCheckBoxView = |
| 673 | View.inflate(builder.getContext(), R.layout.video_call_lte_to_wifi_failed, null); |
| 674 | final CheckBox wifiHandoverFailureCheckbox = |
| 675 | (CheckBox) dialogCheckBoxView.findViewById(R.id.video_call_lte_to_wifi_failed_checkbox); |
| 676 | wifiHandoverFailureCheckbox.setChecked(false); |
| 677 | |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 678 | InCallUiLock lock = InCallPresenter.getInstance().acquireInCallUiLock("WifiFailedDialog"); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 679 | errorDialog = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 680 | builder |
| 681 | .setView(dialogCheckBoxView) |
| 682 | .setMessage(R.string.video_call_lte_to_wifi_failed_message) |
| 683 | .setOnCancelListener( |
| 684 | new OnCancelListener() { |
| 685 | @Override |
| 686 | public void onCancel(DialogInterface dialog) { |
| 687 | onDialogDismissed(); |
| 688 | } |
| 689 | }) |
| 690 | .setPositiveButton( |
| 691 | android.R.string.ok, |
| 692 | new DialogInterface.OnClickListener() { |
| 693 | @Override |
| 694 | public void onClick(DialogInterface dialog, int id) { |
| 695 | call.setDoNotShowDialogForHandoffToWifiFailure( |
| 696 | wifiHandoverFailureCheckbox.isChecked()); |
| 697 | dialog.cancel(); |
| 698 | onDialogDismissed(); |
| 699 | } |
| 700 | }) |
twyen | 8efb495 | 2017-10-06 16:35:54 -0700 | [diff] [blame] | 701 | .setOnDismissListener((dialog) -> lock.release()) |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 702 | .create(); |
| 703 | |
| 704 | LogUtil.i("InCallActivityCommon.showWifiFailedDialog", "as dialog"); |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 705 | errorDialog.show(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 706 | } |
| 707 | |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 708 | void updateNavigationBar(boolean isDialpadVisible) { |
wangqi | fad3d87 | 2017-10-25 13:15:23 -0700 | [diff] [blame] | 709 | if (!ActivityCompat.isInMultiWindowMode(inCallActivity)) { |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 710 | View navigationBarBackground = |
| 711 | inCallActivity.getWindow().findViewById(R.id.navigation_bar_background); |
| 712 | if (navigationBarBackground != null) { |
| 713 | navigationBarBackground.setVisibility(isDialpadVisible ? View.VISIBLE : View.GONE); |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 718 | public boolean showDialpadFragment(boolean show, boolean animate) { |
| 719 | // If the dialpad is already visible, don't animate in. If it's gone, don't animate out. |
| 720 | boolean isDialpadVisible = isDialpadVisible(); |
| 721 | LogUtil.i( |
| 722 | "InCallActivityCommon.showDialpadFragment", |
| 723 | "show: %b, animate: %b, " + "isDialpadVisible: %b", |
| 724 | show, |
| 725 | animate, |
| 726 | isDialpadVisible); |
| 727 | if (show == isDialpadVisible) { |
| 728 | return false; |
| 729 | } |
| 730 | |
| 731 | FragmentManager dialpadFragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 732 | if (dialpadFragmentManager == null) { |
| 733 | LogUtil.i( |
| 734 | "InCallActivityCommon.showDialpadFragment", "unable to show or hide dialpad fragment"); |
| 735 | return false; |
| 736 | } |
| 737 | |
| 738 | // We don't do a FragmentTransaction on the hide case because it will be dealt with when |
| 739 | // the listener is fired after an animation finishes. |
| 740 | if (!animate) { |
| 741 | if (show) { |
| 742 | performShowDialpadFragment(dialpadFragmentManager); |
| 743 | } else { |
| 744 | performHideDialpadFragment(); |
| 745 | } |
| 746 | } else { |
| 747 | if (show) { |
| 748 | performShowDialpadFragment(dialpadFragmentManager); |
| 749 | getDialpadFragment().animateShowDialpad(); |
| 750 | } |
| 751 | getDialpadFragment() |
| 752 | .getView() |
| 753 | .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation); |
| 754 | } |
| 755 | |
| 756 | ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor(); |
| 757 | if (sensor != null) { |
| 758 | sensor.onDialpadVisible(show); |
| 759 | } |
| 760 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 761 | return true; |
| 762 | } |
| 763 | |
| 764 | private void performShowDialpadFragment(@NonNull FragmentManager dialpadFragmentManager) { |
| 765 | FragmentTransaction transaction = dialpadFragmentManager.beginTransaction(); |
| 766 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 767 | if (dialpadFragment == null) { |
| 768 | transaction.add( |
| 769 | inCallActivity.getDialpadContainerId(), new DialpadFragment(), TAG_DIALPAD_FRAGMENT); |
| 770 | } else { |
| 771 | transaction.show(dialpadFragment); |
| 772 | } |
| 773 | |
| 774 | transaction.commitAllowingStateLoss(); |
| 775 | dialpadFragmentManager.executePendingTransactions(); |
| 776 | |
| 777 | Logger.get(inCallActivity).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, inCallActivity); |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 778 | updateNavigationBar(true /* isDialpadVisible */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | private void performHideDialpadFragment() { |
| 782 | FragmentManager fragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 783 | if (fragmentManager == null) { |
| 784 | LogUtil.e( |
| 785 | "InCallActivityCommon.performHideDialpadFragment", "child fragment manager is null"); |
| 786 | return; |
| 787 | } |
| 788 | |
| 789 | Fragment fragment = fragmentManager.findFragmentByTag(TAG_DIALPAD_FRAGMENT); |
| 790 | if (fragment != null) { |
| 791 | FragmentTransaction transaction = fragmentManager.beginTransaction(); |
| 792 | transaction.hide(fragment); |
| 793 | transaction.commitAllowingStateLoss(); |
| 794 | fragmentManager.executePendingTransactions(); |
| 795 | } |
Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame] | 796 | updateNavigationBar(false /* isDialpadVisible */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | public boolean isDialpadVisible() { |
| 800 | DialpadFragment dialpadFragment = getDialpadFragment(); |
| 801 | return dialpadFragment != null && dialpadFragment.isVisible(); |
| 802 | } |
| 803 | |
| 804 | /** Returns the {@link DialpadFragment} that's shown by this activity, or {@code null} */ |
| 805 | @Nullable |
| 806 | private DialpadFragment getDialpadFragment() { |
| 807 | FragmentManager fragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 808 | if (fragmentManager == null) { |
| 809 | return null; |
| 810 | } |
| 811 | return (DialpadFragment) fragmentManager.findFragmentByTag(TAG_DIALPAD_FRAGMENT); |
| 812 | } |
| 813 | |
| 814 | public void updateTaskDescription() { |
| 815 | Resources resources = inCallActivity.getResources(); |
| 816 | int color; |
| 817 | if (resources.getBoolean(R.bool.is_layout_landscape)) { |
| 818 | color = |
| 819 | ResourcesCompat.getColor( |
| 820 | resources, R.color.statusbar_background_color, inCallActivity.getTheme()); |
| 821 | } else { |
| 822 | color = InCallPresenter.getInstance().getThemeColorManager().getSecondaryColor(); |
| 823 | } |
| 824 | |
| 825 | TaskDescription td = |
| 826 | new TaskDescription(resources.getString(R.string.notification_ongoing_call), null, color); |
| 827 | inCallActivity.setTaskDescription(td); |
| 828 | } |
| 829 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 830 | private void internalResolveIntent(Intent intent) { |
| 831 | if (!intent.getAction().equals(Intent.ACTION_MAIN)) { |
| 832 | return; |
| 833 | } |
| 834 | |
| 835 | if (intent.hasExtra(INTENT_EXTRA_SHOW_DIALPAD)) { |
| 836 | // SHOW_DIALPAD_EXTRA can be used here to specify whether the DTMF |
| 837 | // dialpad should be initially visible. If the extra isn't |
| 838 | // present at all, we just leave the dialpad in its previous state. |
| 839 | boolean showDialpad = intent.getBooleanExtra(INTENT_EXTRA_SHOW_DIALPAD, false); |
| 840 | LogUtil.i("InCallActivityCommon.internalResolveIntent", "SHOW_DIALPAD_EXTRA: " + showDialpad); |
| 841 | |
| 842 | relaunchedFromDialer(showDialpad); |
| 843 | } |
| 844 | |
| 845 | DialerCall outgoingCall = CallList.getInstance().getOutgoingCall(); |
| 846 | if (outgoingCall == null) { |
| 847 | outgoingCall = CallList.getInstance().getPendingOutgoingCall(); |
| 848 | } |
| 849 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 850 | if (intent.getBooleanExtra(INTENT_EXTRA_NEW_OUTGOING_CALL, false)) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 851 | intent.removeExtra(INTENT_EXTRA_NEW_OUTGOING_CALL); |
| 852 | |
| 853 | // InCallActivity is responsible for disconnecting a new outgoing call if there |
| 854 | // is no way of making it (i.e. no valid call capable accounts). |
| 855 | // If the version is not MSIM compatible, then ignore this code. |
| 856 | if (CompatUtils.isMSIMCompatible() |
| 857 | && InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) { |
| 858 | LogUtil.i( |
| 859 | "InCallActivityCommon.internalResolveIntent", |
| 860 | "call with no valid accounts, disconnecting"); |
| 861 | outgoingCall.disconnect(); |
| 862 | } |
| 863 | |
linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame] | 864 | inCallActivity.dismissKeyguard(true); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | boolean didShowAccountSelectionDialog = maybeShowAccountSelectionDialog(); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 868 | if (didShowAccountSelectionDialog) { |
| 869 | inCallActivity.hideMainInCallFragment(); |
| 870 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | private boolean maybeShowAccountSelectionDialog() { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 874 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 875 | if (waitingForAccountCall == null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 876 | return false; |
| 877 | } |
| 878 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 879 | Bundle extras = waitingForAccountCall.getIntentExtras(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 880 | List<PhoneAccountHandle> phoneAccountHandles; |
| 881 | if (extras != null) { |
| 882 | phoneAccountHandles = |
| 883 | extras.getParcelableArrayList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS); |
| 884 | } else { |
| 885 | phoneAccountHandles = new ArrayList<>(); |
| 886 | } |
| 887 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 888 | selectPhoneAccountDialogFragment = |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 889 | SelectPhoneAccountDialogFragment.newInstance( |
| 890 | R.string.select_phone_account_for_calls, |
| 891 | true, |
| 892 | phoneAccountHandles, |
| 893 | selectAccountListener, |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 894 | waitingForAccountCall.getId()); |
| 895 | selectPhoneAccountDialogFragment.show( |
| 896 | inCallActivity.getFragmentManager(), TAG_SELECT_ACCOUNT_FRAGMENT); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 897 | return true; |
| 898 | } |
linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 899 | |
| 900 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 901 | @Deprecated |
| 902 | @Nullable |
| 903 | Dialog getErrorDialog() { |
| 904 | return errorDialog; |
| 905 | } |
| 906 | |
| 907 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 908 | @Deprecated |
| 909 | void setErrorDialog(@Nullable Dialog errorDialog) { |
| 910 | this.errorDialog = errorDialog; |
| 911 | } |
| 912 | |
| 913 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 914 | @Deprecated |
| 915 | @Nullable |
| 916 | SelectPhoneAccountDialogFragment getSelectPhoneAccountDialogFragment() { |
| 917 | return selectPhoneAccountDialogFragment; |
| 918 | } |
| 919 | |
| 920 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 921 | @Deprecated |
| 922 | void setSelectPhoneAccountDialogFragment( |
| 923 | @Nullable SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment) { |
| 924 | this.selectPhoneAccountDialogFragment = selectPhoneAccountDialogFragment; |
| 925 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 926 | } |