| 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; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 21 | import android.app.Dialog; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.res.Configuration; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 24 | import android.os.Bundle; |
| wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 25 | import android.os.Trace; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 26 | import android.support.annotation.IntDef; |
| 27 | import android.support.annotation.NonNull; |
| 28 | import android.support.annotation.Nullable; |
| linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 29 | import android.support.annotation.VisibleForTesting; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 30 | import android.support.v4.app.Fragment; |
| 31 | import android.support.v4.app.FragmentManager; |
| 32 | import android.support.v4.app.FragmentTransaction; |
| linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 33 | import android.telecom.CallAudioState; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 34 | import android.telecom.PhoneAccountHandle; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 35 | import android.view.WindowManager; |
| 36 | import android.view.animation.Animation; |
| 37 | import android.view.animation.AnimationUtils; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 38 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment; |
| 39 | import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener; |
| 40 | import com.android.dialer.animation.AnimUtils; |
| 41 | import com.android.dialer.animation.AnimationListenerAdapter; |
| 42 | import com.android.dialer.common.LogUtil; |
| 43 | import com.android.dialer.compat.CompatUtils; |
| 44 | import com.android.dialer.logging.Logger; |
| Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 45 | import com.android.dialer.logging.ScreenEvent; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 46 | import com.android.dialer.util.ViewUtil; |
| Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 47 | import com.android.incallui.audiomode.AudioModeProvider; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 48 | import com.android.incallui.call.CallList; |
| 49 | import com.android.incallui.call.DialerCall; |
| 50 | import com.android.incallui.call.DialerCall.State; |
| Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 51 | import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment; |
| 52 | import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment.Callback; |
| linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 53 | import com.google.common.base.Optional; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 54 | import java.lang.annotation.Retention; |
| 55 | import java.lang.annotation.RetentionPolicy; |
| 56 | import java.util.ArrayList; |
| 57 | import java.util.List; |
| 58 | |
| 59 | /** Shared functionality between the new and old in call activity. */ |
| 60 | public class InCallActivityCommon { |
| 61 | |
| 62 | private static final String INTENT_EXTRA_SHOW_DIALPAD = "InCallActivity.show_dialpad"; |
| 63 | private static final String INTENT_EXTRA_NEW_OUTGOING_CALL = "InCallActivity.new_outgoing_call"; |
| 64 | private static final String INTENT_EXTRA_FOR_FULL_SCREEN = |
| 65 | "InCallActivity.for_full_screen_intent"; |
| 66 | |
| 67 | private static final String DIALPAD_TEXT_KEY = "InCallActivity.dialpad_text"; |
| 68 | |
| 69 | private static final String TAG_SELECT_ACCOUNT_FRAGMENT = "tag_select_account_fragment"; |
| 70 | private static final String TAG_DIALPAD_FRAGMENT = "tag_dialpad_fragment"; |
| Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 71 | 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] | 72 | |
| 73 | @Retention(RetentionPolicy.SOURCE) |
| 74 | @IntDef({ |
| 75 | DIALPAD_REQUEST_NONE, |
| 76 | DIALPAD_REQUEST_SHOW, |
| 77 | DIALPAD_REQUEST_HIDE, |
| 78 | }) |
| 79 | @interface DialpadRequestType {} |
| 80 | |
| 81 | private static final int DIALPAD_REQUEST_NONE = 1; |
| 82 | private static final int DIALPAD_REQUEST_SHOW = 2; |
| 83 | private static final int DIALPAD_REQUEST_HIDE = 3; |
| 84 | |
| linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 85 | private static Optional<Integer> audioRouteForTesting = Optional.absent(); |
| 86 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 87 | private final InCallActivity inCallActivity; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 88 | private boolean showPostCharWaitDialogOnResume; |
| 89 | private String showPostCharWaitDialogCallId; |
| 90 | private String showPostCharWaitDialogChars; |
| linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 91 | private Dialog errorDialog; |
| Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 92 | private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 93 | private Animation dialpadSlideInAnimation; |
| 94 | private Animation dialpadSlideOutAnimation; |
| 95 | private boolean animateDialpadOnShow; |
| 96 | private String dtmfTextToPreopulate; |
| 97 | @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE; |
| Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 98 | // If activity is going to be recreated. This is usually happening in {@link onNewIntent}. |
| 99 | private boolean isRecreating; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 100 | |
| Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 101 | private final SelectPhoneAccountListener selectAccountListener = |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 102 | new SelectPhoneAccountListener() { |
| 103 | @Override |
| 104 | public void onPhoneAccountSelected( |
| 105 | PhoneAccountHandle selectedAccountHandle, boolean setDefault, String callId) { |
| 106 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 107 | LogUtil.i( |
| 108 | "InCallActivityCommon.SelectPhoneAccountListener.onPhoneAccountSelected", |
| 109 | "call: " + call); |
| 110 | if (call != null) { |
| 111 | call.phoneAccountSelected(selectedAccountHandle, setDefault); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public void onDialogDismissed(String callId) { |
| 117 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 118 | LogUtil.i( |
| 119 | "InCallActivityCommon.SelectPhoneAccountListener.onDialogDismissed", |
| 120 | "disconnecting call: " + call); |
| 121 | if (call != null) { |
| 122 | call.disconnect(); |
| 123 | } |
| 124 | } |
| 125 | }; |
| 126 | |
| Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 127 | private InternationalCallOnWifiDialogFragment.Callback internationalCallOnWifiCallback = |
| 128 | new Callback() { |
| 129 | @Override |
| 130 | public void continueCall(@NonNull String callId) { |
| 131 | LogUtil.i("InCallActivityCommon.continueCall", "continuing call with id: %s", callId); |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public void cancelCall(@NonNull String callId) { |
| 136 | DialerCall call = CallList.getInstance().getCallById(callId); |
| 137 | if (call == null) { |
| 138 | LogUtil.i("InCallActivityCommon.cancelCall", "call destroyed before dialog closed"); |
| 139 | return; |
| 140 | } |
| 141 | LogUtil.i("InCallActivityCommon.cancelCall", "disconnecting international call on wifi"); |
| 142 | call.disconnect(); |
| 143 | } |
| 144 | }; |
| 145 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 146 | public static void setIntentExtras( |
| 147 | Intent intent, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) { |
| 148 | if (showDialpad) { |
| 149 | intent.putExtra(INTENT_EXTRA_SHOW_DIALPAD, true); |
| 150 | } |
| 151 | intent.putExtra(INTENT_EXTRA_NEW_OUTGOING_CALL, newOutgoingCall); |
| 152 | intent.putExtra(INTENT_EXTRA_FOR_FULL_SCREEN, isForFullScreen); |
| 153 | } |
| 154 | |
| 155 | public InCallActivityCommon(InCallActivity inCallActivity) { |
| 156 | this.inCallActivity = inCallActivity; |
| 157 | } |
| 158 | |
| 159 | public void onCreate(Bundle icicle) { |
| linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 160 | setWindowFlags(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 161 | |
| 162 | inCallActivity.setContentView(R.layout.incall_screen); |
| 163 | |
| 164 | internalResolveIntent(inCallActivity.getIntent()); |
| 165 | |
| 166 | boolean isLandscape = |
| 167 | inCallActivity.getResources().getConfiguration().orientation |
| 168 | == Configuration.ORIENTATION_LANDSCAPE; |
| 169 | boolean isRtl = ViewUtil.isRtl(); |
| 170 | |
| 171 | if (isLandscape) { |
| 172 | dialpadSlideInAnimation = |
| 173 | AnimationUtils.loadAnimation( |
| 174 | inCallActivity, isRtl ? R.anim.dialpad_slide_in_left : R.anim.dialpad_slide_in_right); |
| 175 | dialpadSlideOutAnimation = |
| 176 | AnimationUtils.loadAnimation( |
| 177 | inCallActivity, |
| 178 | isRtl ? R.anim.dialpad_slide_out_left : R.anim.dialpad_slide_out_right); |
| 179 | } else { |
| 180 | dialpadSlideInAnimation = |
| 181 | AnimationUtils.loadAnimation(inCallActivity, R.anim.dialpad_slide_in_bottom); |
| 182 | dialpadSlideOutAnimation = |
| 183 | AnimationUtils.loadAnimation(inCallActivity, R.anim.dialpad_slide_out_bottom); |
| 184 | } |
| 185 | |
| 186 | dialpadSlideInAnimation.setInterpolator(AnimUtils.EASE_IN); |
| 187 | dialpadSlideOutAnimation.setInterpolator(AnimUtils.EASE_OUT); |
| 188 | |
| 189 | dialpadSlideOutAnimation.setAnimationListener( |
| 190 | new AnimationListenerAdapter() { |
| 191 | @Override |
| 192 | public void onAnimationEnd(Animation animation) { |
| 193 | performHideDialpadFragment(); |
| 194 | } |
| 195 | }); |
| 196 | |
| Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 197 | // Don't override the value if show dialpad request is true in intent extras. |
| 198 | if (icicle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) { |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 199 | // If the dialpad was shown before, set variables indicating it should be shown and |
| 200 | // populated with the previous DTMF text. The dialpad is actually shown and populated |
| 201 | // in onResume() to ensure the hosting fragment has been inflated and is ready to receive it. |
| 202 | if (icicle.containsKey(INTENT_EXTRA_SHOW_DIALPAD)) { |
| 203 | boolean showDialpad = icicle.getBoolean(INTENT_EXTRA_SHOW_DIALPAD); |
| 204 | showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_HIDE; |
| 205 | animateDialpadOnShow = false; |
| 206 | } |
| 207 | dtmfTextToPreopulate = icicle.getString(DIALPAD_TEXT_KEY); |
| 208 | |
| 209 | SelectPhoneAccountDialogFragment dialogFragment = |
| 210 | (SelectPhoneAccountDialogFragment) |
| 211 | inCallActivity.getFragmentManager().findFragmentByTag(TAG_SELECT_ACCOUNT_FRAGMENT); |
| 212 | if (dialogFragment != null) { |
| 213 | dialogFragment.setListener(selectAccountListener); |
| 214 | } |
| 215 | } |
| 216 | |
| Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 217 | InternationalCallOnWifiDialogFragment existingInternationalFragment = |
| 218 | (InternationalCallOnWifiDialogFragment) |
| 219 | inCallActivity |
| 220 | .getSupportFragmentManager() |
| 221 | .findFragmentByTag(TAG_INTERNATIONAL_CALL_ON_WIFI); |
| 222 | if (existingInternationalFragment != null) { |
| 223 | LogUtil.i( |
| 224 | "InCallActivityCommon.onCreate", "international fragment exists attaching callback"); |
| 225 | existingInternationalFragment.setCallback(internationalCallOnWifiCallback); |
| 226 | } |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 229 | public void onResume() { |
| wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 230 | Trace.beginSection("InCallActivityCommon.onResume"); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 231 | if (InCallPresenter.getInstance().isReadyForTearDown()) { |
| 232 | LogUtil.i( |
| 233 | "InCallActivityCommon.onResume", |
| 234 | "InCallPresenter is ready for tear down, not sending updates"); |
| 235 | } else { |
| linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 236 | inCallActivity.updateTaskDescription(); |
| roldenburg | 4307347 | 2017-11-15 12:31:06 -0800 | [diff] [blame] | 237 | InCallPresenter.getInstance().onUiShowing(true); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // If there is a pending request to show or hide the dialpad, handle that now. |
| 241 | if (showDialpadRequest != DIALPAD_REQUEST_NONE) { |
| 242 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 243 | // Exit fullscreen so that the user has access to the dialpad hide/show button and |
| 244 | // can hide the dialpad. Important when showing the dialpad from within dialer. |
| 245 | InCallPresenter.getInstance().setFullScreen(false, true /* force */); |
| 246 | |
| 247 | inCallActivity.showDialpadFragment(true /* show */, animateDialpadOnShow /* animate */); |
| 248 | animateDialpadOnShow = false; |
| 249 | |
| linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 250 | DialpadFragment dialpadFragment = inCallActivity.getDialpadFragment(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 251 | if (dialpadFragment != null) { |
| 252 | dialpadFragment.setDtmfText(dtmfTextToPreopulate); |
| 253 | dtmfTextToPreopulate = null; |
| 254 | } |
| 255 | } else { |
| 256 | LogUtil.i("InCallActivityCommon.onResume", "force hide dialpad"); |
| linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 257 | if (inCallActivity.getDialpadFragment() != null) { |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 258 | inCallActivity.showDialpadFragment(false /* show */, false /* animate */); |
| 259 | } |
| 260 | } |
| 261 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 262 | } |
| linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 263 | inCallActivity.updateNavigationBar(inCallActivity.isDialpadVisible()); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 264 | |
| 265 | if (showPostCharWaitDialogOnResume) { |
| 266 | showPostCharWaitDialog(showPostCharWaitDialogCallId, showPostCharWaitDialogChars); |
| 267 | } |
| 268 | |
| 269 | CallList.getInstance() |
| 270 | .onInCallUiShown( |
| 271 | inCallActivity.getIntent().getBooleanExtra(INTENT_EXTRA_FOR_FULL_SCREEN, false)); |
| wangqi | 9982f0d | 2017-10-11 17:46:07 -0700 | [diff] [blame] | 272 | Trace.endSection(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 275 | void onNewIntent(Intent intent, boolean isRecreating) { |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 276 | LogUtil.i("InCallActivityCommon.onNewIntent", ""); |
| Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame] | 277 | this.isRecreating = isRecreating; |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 278 | |
| 279 | // We're being re-launched with a new Intent. Since it's possible for a |
| 280 | // single InCallActivity instance to persist indefinitely (even if we |
| 281 | // finish() ourselves), this sequence can potentially happen any time |
| 282 | // the InCallActivity needs to be displayed. |
| 283 | |
| 284 | // Stash away the new intent so that we can get it in the future |
| 285 | // by calling getIntent(). (Otherwise getIntent() will return the |
| 286 | // original Intent from when we first got created!) |
| 287 | inCallActivity.setIntent(intent); |
| 288 | |
| 289 | // Activities are always paused before receiving a new intent, so |
| 290 | // we can count on our onResume() method being called next. |
| 291 | |
| 292 | // Just like in onCreate(), handle the intent. |
| Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 293 | // Skip if InCallActivity is going to recreate since this will be called in onCreate(). |
| 294 | if (!isRecreating) { |
| 295 | internalResolveIntent(intent); |
| 296 | } |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| linyuh | 9a915fc | 2017-11-09 16:27:13 -0800 | [diff] [blame] | 299 | private void setWindowFlags() { |
| 300 | // Allow the activity to be shown when the screen is locked and filter out touch events that are |
| 301 | // "too fat". |
| 302 | int flags = |
| 303 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 304 | | WindowManager.LayoutParams.FLAG_IGNORE_CHEEK_PRESSES; |
| 305 | |
| 306 | // When the audio stream is not directed through Bluetooth, turn the screen on once the |
| 307 | // activity is shown. |
| 308 | final int audioRoute = getAudioRoute(); |
| 309 | if (audioRoute != CallAudioState.ROUTE_BLUETOOTH) { |
| 310 | flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON; |
| 311 | } |
| 312 | |
| 313 | inCallActivity.getWindow().addFlags(flags); |
| 314 | } |
| 315 | |
| 316 | private static int getAudioRoute() { |
| 317 | if (audioRouteForTesting.isPresent()) { |
| 318 | return audioRouteForTesting.get(); |
| 319 | } |
| 320 | |
| 321 | return AudioModeProvider.getInstance().getAudioState().getRoute(); |
| 322 | } |
| 323 | |
| 324 | @VisibleForTesting(otherwise = VisibleForTesting.NONE) |
| 325 | public static void setAudioRouteForTesting(int audioRoute) { |
| 326 | audioRouteForTesting = Optional.of(audioRoute); |
| 327 | } |
| 328 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 329 | public void showPostCharWaitDialog(String callId, String chars) { |
| 330 | if (inCallActivity.isVisible()) { |
| 331 | PostCharDialogFragment fragment = new PostCharDialogFragment(callId, chars); |
| 332 | fragment.show(inCallActivity.getSupportFragmentManager(), "postCharWait"); |
| 333 | |
| 334 | showPostCharWaitDialogOnResume = false; |
| 335 | showPostCharWaitDialogCallId = null; |
| 336 | showPostCharWaitDialogChars = null; |
| 337 | } else { |
| 338 | showPostCharWaitDialogOnResume = true; |
| 339 | showPostCharWaitDialogCallId = callId; |
| 340 | showPostCharWaitDialogChars = chars; |
| 341 | } |
| 342 | } |
| 343 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 344 | /** |
| 345 | * When relaunching from the dialer app, {@code showDialpad} indicates whether the dialpad should |
| 346 | * be shown on launch. |
| 347 | * |
| 348 | * @param showDialpad {@code true} to indicate the dialpad should be shown on launch, and {@code |
| 349 | * false} to indicate no change should be made to the dialpad visibility. |
| 350 | */ |
| 351 | private void relaunchedFromDialer(boolean showDialpad) { |
| 352 | showDialpadRequest = showDialpad ? DIALPAD_REQUEST_SHOW : DIALPAD_REQUEST_NONE; |
| 353 | animateDialpadOnShow = true; |
| 354 | |
| 355 | if (showDialpadRequest == DIALPAD_REQUEST_SHOW) { |
| 356 | // If there's only one line in use, AND it's on hold, then we're sure the user |
| 357 | // wants to use the dialpad toward the exact line, so un-hold the holding line. |
| 358 | DialerCall call = CallList.getInstance().getActiveOrBackgroundCall(); |
| 359 | if (call != null && call.getState() == State.ONHOLD) { |
| 360 | call.unhold(); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 365 | public void setExcludeFromRecents(boolean exclude) { |
| 366 | List<AppTask> tasks = inCallActivity.getSystemService(ActivityManager.class).getAppTasks(); |
| 367 | int taskId = inCallActivity.getTaskId(); |
| 368 | for (int i = 0; i < tasks.size(); i++) { |
| 369 | ActivityManager.AppTask task = tasks.get(i); |
| 370 | try { |
| 371 | if (task.getTaskInfo().id == taskId) { |
| 372 | task.setExcludeFromRecents(exclude); |
| 373 | } |
| 374 | } catch (RuntimeException e) { |
| 375 | LogUtil.e( |
| 376 | "InCallActivityCommon.setExcludeFromRecents", |
| 377 | "RuntimeException when excluding task from recents.", |
| 378 | e); |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 383 | public boolean showDialpadFragment(boolean show, boolean animate) { |
| 384 | // If the dialpad is already visible, don't animate in. If it's gone, don't animate out. |
| linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 385 | boolean isDialpadVisible = inCallActivity.isDialpadVisible(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 386 | LogUtil.i( |
| 387 | "InCallActivityCommon.showDialpadFragment", |
| 388 | "show: %b, animate: %b, " + "isDialpadVisible: %b", |
| 389 | show, |
| 390 | animate, |
| 391 | isDialpadVisible); |
| 392 | if (show == isDialpadVisible) { |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | FragmentManager dialpadFragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 397 | if (dialpadFragmentManager == null) { |
| 398 | LogUtil.i( |
| 399 | "InCallActivityCommon.showDialpadFragment", "unable to show or hide dialpad fragment"); |
| 400 | return false; |
| 401 | } |
| 402 | |
| 403 | // We don't do a FragmentTransaction on the hide case because it will be dealt with when |
| 404 | // the listener is fired after an animation finishes. |
| 405 | if (!animate) { |
| 406 | if (show) { |
| 407 | performShowDialpadFragment(dialpadFragmentManager); |
| 408 | } else { |
| 409 | performHideDialpadFragment(); |
| 410 | } |
| 411 | } else { |
| 412 | if (show) { |
| 413 | performShowDialpadFragment(dialpadFragmentManager); |
| linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 414 | inCallActivity.getDialpadFragment().animateShowDialpad(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 415 | } |
| linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 416 | inCallActivity |
| 417 | .getDialpadFragment() |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 418 | .getView() |
| 419 | .startAnimation(show ? dialpadSlideInAnimation : dialpadSlideOutAnimation); |
| 420 | } |
| 421 | |
| 422 | ProximitySensor sensor = InCallPresenter.getInstance().getProximitySensor(); |
| 423 | if (sensor != null) { |
| 424 | sensor.onDialpadVisible(show); |
| 425 | } |
| 426 | showDialpadRequest = DIALPAD_REQUEST_NONE; |
| 427 | return true; |
| 428 | } |
| 429 | |
| 430 | private void performShowDialpadFragment(@NonNull FragmentManager dialpadFragmentManager) { |
| 431 | FragmentTransaction transaction = dialpadFragmentManager.beginTransaction(); |
| linyuh | 69a2506 | 2017-11-15 16:18:51 -0800 | [diff] [blame] | 432 | DialpadFragment dialpadFragment = inCallActivity.getDialpadFragment(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 433 | if (dialpadFragment == null) { |
| 434 | transaction.add( |
| 435 | inCallActivity.getDialpadContainerId(), new DialpadFragment(), TAG_DIALPAD_FRAGMENT); |
| 436 | } else { |
| 437 | transaction.show(dialpadFragment); |
| 438 | } |
| 439 | |
| 440 | transaction.commitAllowingStateLoss(); |
| 441 | dialpadFragmentManager.executePendingTransactions(); |
| 442 | |
| 443 | Logger.get(inCallActivity).logScreenView(ScreenEvent.Type.INCALL_DIALPAD, inCallActivity); |
| linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 444 | inCallActivity.updateNavigationBar(true /* isDialpadVisible */); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | private void performHideDialpadFragment() { |
| 448 | FragmentManager fragmentManager = inCallActivity.getDialpadFragmentManager(); |
| 449 | if (fragmentManager == null) { |
| 450 | LogUtil.e( |
| 451 | "InCallActivityCommon.performHideDialpadFragment", "child fragment manager is null"); |
| 452 | return; |
| 453 | } |
| 454 | |
| 455 | Fragment fragment = fragmentManager.findFragmentByTag(TAG_DIALPAD_FRAGMENT); |
| 456 | if (fragment != null) { |
| 457 | FragmentTransaction transaction = fragmentManager.beginTransaction(); |
| 458 | transaction.hide(fragment); |
| 459 | transaction.commitAllowingStateLoss(); |
| 460 | fragmentManager.executePendingTransactions(); |
| 461 | } |
| linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 462 | inCallActivity.updateNavigationBar(false /* isDialpadVisible */); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 465 | private void internalResolveIntent(Intent intent) { |
| 466 | if (!intent.getAction().equals(Intent.ACTION_MAIN)) { |
| 467 | return; |
| 468 | } |
| 469 | |
| 470 | if (intent.hasExtra(INTENT_EXTRA_SHOW_DIALPAD)) { |
| 471 | // SHOW_DIALPAD_EXTRA can be used here to specify whether the DTMF |
| 472 | // dialpad should be initially visible. If the extra isn't |
| 473 | // present at all, we just leave the dialpad in its previous state. |
| 474 | boolean showDialpad = intent.getBooleanExtra(INTENT_EXTRA_SHOW_DIALPAD, false); |
| 475 | LogUtil.i("InCallActivityCommon.internalResolveIntent", "SHOW_DIALPAD_EXTRA: " + showDialpad); |
| 476 | |
| 477 | relaunchedFromDialer(showDialpad); |
| 478 | } |
| 479 | |
| 480 | DialerCall outgoingCall = CallList.getInstance().getOutgoingCall(); |
| 481 | if (outgoingCall == null) { |
| 482 | outgoingCall = CallList.getInstance().getPendingOutgoingCall(); |
| 483 | } |
| 484 | |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 485 | if (intent.getBooleanExtra(INTENT_EXTRA_NEW_OUTGOING_CALL, false)) { |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 486 | intent.removeExtra(INTENT_EXTRA_NEW_OUTGOING_CALL); |
| 487 | |
| 488 | // InCallActivity is responsible for disconnecting a new outgoing call if there |
| 489 | // is no way of making it (i.e. no valid call capable accounts). |
| 490 | // If the version is not MSIM compatible, then ignore this code. |
| 491 | if (CompatUtils.isMSIMCompatible() |
| 492 | && InCallPresenter.isCallWithNoValidAccounts(outgoingCall)) { |
| 493 | LogUtil.i( |
| 494 | "InCallActivityCommon.internalResolveIntent", |
| 495 | "call with no valid accounts, disconnecting"); |
| 496 | outgoingCall.disconnect(); |
| 497 | } |
| 498 | |
| linyuh | 9c327da | 2017-11-14 12:33:48 -0800 | [diff] [blame] | 499 | inCallActivity.dismissKeyguard(true); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | boolean didShowAccountSelectionDialog = maybeShowAccountSelectionDialog(); |
| Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 503 | if (didShowAccountSelectionDialog) { |
| 504 | inCallActivity.hideMainInCallFragment(); |
| 505 | } |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | private boolean maybeShowAccountSelectionDialog() { |
| Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 509 | DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall(); |
| 510 | if (waitingForAccountCall == null) { |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | |
| Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 514 | Bundle extras = waitingForAccountCall.getIntentExtras(); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 515 | List<PhoneAccountHandle> phoneAccountHandles; |
| 516 | if (extras != null) { |
| 517 | phoneAccountHandles = |
| 518 | extras.getParcelableArrayList(android.telecom.Call.AVAILABLE_PHONE_ACCOUNTS); |
| 519 | } else { |
| 520 | phoneAccountHandles = new ArrayList<>(); |
| 521 | } |
| 522 | |
| Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 523 | selectPhoneAccountDialogFragment = |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 524 | SelectPhoneAccountDialogFragment.newInstance( |
| 525 | R.string.select_phone_account_for_calls, |
| 526 | true, |
| twyen | ba99bef | 2017-11-20 15:13:07 -0800 | [diff] [blame] | 527 | 0, |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 528 | phoneAccountHandles, |
| 529 | selectAccountListener, |
| twyen | ba99bef | 2017-11-20 15:13:07 -0800 | [diff] [blame] | 530 | waitingForAccountCall.getId(), |
| 531 | null); |
| Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 532 | selectPhoneAccountDialogFragment.show( |
| 533 | inCallActivity.getFragmentManager(), TAG_SELECT_ACCOUNT_FRAGMENT); |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 534 | return true; |
| 535 | } |
| linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 536 | |
| 537 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 538 | @Deprecated |
| 539 | @Nullable |
| 540 | Dialog getErrorDialog() { |
| 541 | return errorDialog; |
| 542 | } |
| 543 | |
| 544 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 545 | @Deprecated |
| 546 | void setErrorDialog(@Nullable Dialog errorDialog) { |
| 547 | this.errorDialog = errorDialog; |
| 548 | } |
| 549 | |
| 550 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 551 | @Deprecated |
| linyuh | 57b093b | 2017-11-17 14:32:32 -0800 | [diff] [blame] | 552 | boolean getIsRecreating() { |
| 553 | return isRecreating; |
| 554 | } |
| 555 | |
| 556 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 557 | @Deprecated |
| linyuh | f99f630 | 2017-11-15 11:23:51 -0800 | [diff] [blame] | 558 | @Nullable |
| 559 | SelectPhoneAccountDialogFragment getSelectPhoneAccountDialogFragment() { |
| 560 | return selectPhoneAccountDialogFragment; |
| 561 | } |
| 562 | |
| 563 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 564 | @Deprecated |
| 565 | void setSelectPhoneAccountDialogFragment( |
| 566 | @Nullable SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment) { |
| 567 | this.selectPhoneAccountDialogFragment = selectPhoneAccountDialogFragment; |
| 568 | } |
| linyuh | 7b86f56 | 2017-11-16 11:24:09 -0800 | [diff] [blame] | 569 | |
| 570 | /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */ |
| 571 | @Deprecated |
| 572 | InternationalCallOnWifiDialogFragment.Callback getCallbackForInternationalCallOnWifiDialog() { |
| 573 | return internationalCallOnWifiCallback; |
| 574 | } |
| Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 575 | } |