blob: d2aae485d8aa1b04c474629a69fa010654dffdc2 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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
17package com.android.incallui;
18
19import android.app.ActivityManager;
20import android.app.ActivityManager.AppTask;
Eric Erfanianccca3152017-02-22 16:32:36 -080021import android.app.Dialog;
Eric Erfanianccca3152017-02-22 16:32:36 -080022import android.content.Intent;
23import android.content.res.Configuration;
Eric Erfanianccca3152017-02-22 16:32:36 -080024import android.os.Bundle;
wangqi9982f0d2017-10-11 17:46:07 -070025import android.os.Trace;
Eric Erfanianccca3152017-02-22 16:32:36 -080026import android.support.annotation.IntDef;
27import android.support.annotation.NonNull;
28import android.support.annotation.Nullable;
linyuh9a915fc2017-11-09 16:27:13 -080029import android.support.annotation.VisibleForTesting;
Eric Erfanianccca3152017-02-22 16:32:36 -080030import android.support.v4.app.Fragment;
31import android.support.v4.app.FragmentManager;
32import android.support.v4.app.FragmentTransaction;
linyuh9a915fc2017-11-09 16:27:13 -080033import android.telecom.CallAudioState;
Eric Erfanianccca3152017-02-22 16:32:36 -080034import android.telecom.PhoneAccountHandle;
Eric Erfanianccca3152017-02-22 16:32:36 -080035import android.view.WindowManager;
36import android.view.animation.Animation;
37import android.view.animation.AnimationUtils;
Eric Erfanianccca3152017-02-22 16:32:36 -080038import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment;
39import com.android.contacts.common.widget.SelectPhoneAccountDialogFragment.SelectPhoneAccountListener;
40import com.android.dialer.animation.AnimUtils;
41import com.android.dialer.animation.AnimationListenerAdapter;
42import com.android.dialer.common.LogUtil;
43import com.android.dialer.compat.CompatUtils;
44import com.android.dialer.logging.Logger;
Eric Erfanian8369df02017-05-03 10:27:13 -070045import com.android.dialer.logging.ScreenEvent;
Eric Erfanianccca3152017-02-22 16:32:36 -080046import com.android.dialer.util.ViewUtil;
Eric Erfanian8369df02017-05-03 10:27:13 -070047import com.android.incallui.audiomode.AudioModeProvider;
Eric Erfanianccca3152017-02-22 16:32:36 -080048import com.android.incallui.call.CallList;
49import com.android.incallui.call.DialerCall;
50import com.android.incallui.call.DialerCall.State;
Eric Erfanianc857f902017-05-15 14:05:33 -070051import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment;
52import com.android.incallui.telecomeventui.InternationalCallOnWifiDialogFragment.Callback;
linyuh9a915fc2017-11-09 16:27:13 -080053import com.google.common.base.Optional;
Eric Erfanianccca3152017-02-22 16:32:36 -080054import java.lang.annotation.Retention;
55import java.lang.annotation.RetentionPolicy;
56import java.util.ArrayList;
57import java.util.List;
58
59/** Shared functionality between the new and old in call activity. */
60public 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 Erfanianc857f902017-05-15 14:05:33 -070071 private static final String TAG_INTERNATIONAL_CALL_ON_WIFI = "tag_international_call_on_wifi";
Eric Erfanianccca3152017-02-22 16:32:36 -080072
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
linyuh9a915fc2017-11-09 16:27:13 -080085 private static Optional<Integer> audioRouteForTesting = Optional.absent();
86
Eric Erfanianccca3152017-02-22 16:32:36 -080087 private final InCallActivity inCallActivity;
Eric Erfanianccca3152017-02-22 16:32:36 -080088 private boolean showPostCharWaitDialogOnResume;
89 private String showPostCharWaitDialogCallId;
90 private String showPostCharWaitDialogChars;
linyuhf99f6302017-11-15 11:23:51 -080091 private Dialog errorDialog;
Eric Erfaniand5e47f62017-03-15 14:41:07 -070092 private SelectPhoneAccountDialogFragment selectPhoneAccountDialogFragment;
Eric Erfanianccca3152017-02-22 16:32:36 -080093 private Animation dialpadSlideInAnimation;
94 private Animation dialpadSlideOutAnimation;
95 private boolean animateDialpadOnShow;
96 private String dtmfTextToPreopulate;
97 @DialpadRequestType private int showDialpadRequest = DIALPAD_REQUEST_NONE;
Eric Erfanian2ca43182017-08-31 06:57:16 -070098 // If activity is going to be recreated. This is usually happening in {@link onNewIntent}.
99 private boolean isRecreating;
Eric Erfanianccca3152017-02-22 16:32:36 -0800100
Eric Erfanianc857f902017-05-15 14:05:33 -0700101 private final SelectPhoneAccountListener selectAccountListener =
Eric Erfanianccca3152017-02-22 16:32:36 -0800102 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 Erfanianc857f902017-05-15 14:05:33 -0700127 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 Erfanianccca3152017-02-22 16:32:36 -0800146 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) {
linyuh9a915fc2017-11-09 16:27:13 -0800160 setWindowFlags();
Eric Erfanianccca3152017-02-22 16:32:36 -0800161
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 Erfanian2ca43182017-08-31 06:57:16 -0700197 // Don't override the value if show dialpad request is true in intent extras.
198 if (icicle != null && showDialpadRequest == DIALPAD_REQUEST_NONE) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800199 // 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 Erfanianc857f902017-05-15 14:05:33 -0700217 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 Erfanianccca3152017-02-22 16:32:36 -0800227 }
228
Eric Erfanianccca3152017-02-22 16:32:36 -0800229 public void onResume() {
wangqi9982f0d2017-10-11 17:46:07 -0700230 Trace.beginSection("InCallActivityCommon.onResume");
Eric Erfanianccca3152017-02-22 16:32:36 -0800231 if (InCallPresenter.getInstance().isReadyForTearDown()) {
232 LogUtil.i(
233 "InCallActivityCommon.onResume",
234 "InCallPresenter is ready for tear down, not sending updates");
235 } else {
linyuh57b093b2017-11-17 14:32:32 -0800236 inCallActivity.updateTaskDescription();
roldenburg43073472017-11-15 12:31:06 -0800237 InCallPresenter.getInstance().onUiShowing(true);
Eric Erfanianccca3152017-02-22 16:32:36 -0800238 }
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
linyuh69a25062017-11-15 16:18:51 -0800250 DialpadFragment dialpadFragment = inCallActivity.getDialpadFragment();
Eric Erfanianccca3152017-02-22 16:32:36 -0800251 if (dialpadFragment != null) {
252 dialpadFragment.setDtmfText(dtmfTextToPreopulate);
253 dtmfTextToPreopulate = null;
254 }
255 } else {
256 LogUtil.i("InCallActivityCommon.onResume", "force hide dialpad");
linyuh69a25062017-11-15 16:18:51 -0800257 if (inCallActivity.getDialpadFragment() != null) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800258 inCallActivity.showDialpadFragment(false /* show */, false /* animate */);
259 }
260 }
261 showDialpadRequest = DIALPAD_REQUEST_NONE;
262 }
linyuh57b093b2017-11-17 14:32:32 -0800263 inCallActivity.updateNavigationBar(inCallActivity.isDialpadVisible());
Eric Erfanianccca3152017-02-22 16:32:36 -0800264
265 if (showPostCharWaitDialogOnResume) {
266 showPostCharWaitDialog(showPostCharWaitDialogCallId, showPostCharWaitDialogChars);
267 }
268
269 CallList.getInstance()
270 .onInCallUiShown(
271 inCallActivity.getIntent().getBooleanExtra(INTENT_EXTRA_FOR_FULL_SCREEN, false));
wangqi9982f0d2017-10-11 17:46:07 -0700272 Trace.endSection();
Eric Erfanianccca3152017-02-22 16:32:36 -0800273 }
274
Eric Erfanian10b34a52017-05-04 08:23:17 -0700275 void onNewIntent(Intent intent, boolean isRecreating) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800276 LogUtil.i("InCallActivityCommon.onNewIntent", "");
Eric Erfanian2ca43182017-08-31 06:57:16 -0700277 this.isRecreating = isRecreating;
Eric Erfanianccca3152017-02-22 16:32:36 -0800278
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 Erfanian10b34a52017-05-04 08:23:17 -0700293 // Skip if InCallActivity is going to recreate since this will be called in onCreate().
294 if (!isRecreating) {
295 internalResolveIntent(intent);
296 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800297 }
298
linyuh9a915fc2017-11-09 16:27:13 -0800299 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 Erfanianccca3152017-02-22 16:32:36 -0800329 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 Erfanianccca3152017-02-22 16:32:36 -0800344 /**
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 Erfanianccca3152017-02-22 16:32:36 -0800365 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 Erfanianccca3152017-02-22 16:32:36 -0800383 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.
linyuh69a25062017-11-15 16:18:51 -0800385 boolean isDialpadVisible = inCallActivity.isDialpadVisible();
Eric Erfanianccca3152017-02-22 16:32:36 -0800386 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);
linyuh69a25062017-11-15 16:18:51 -0800414 inCallActivity.getDialpadFragment().animateShowDialpad();
Eric Erfanianccca3152017-02-22 16:32:36 -0800415 }
linyuh69a25062017-11-15 16:18:51 -0800416 inCallActivity
417 .getDialpadFragment()
Eric Erfanianccca3152017-02-22 16:32:36 -0800418 .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();
linyuh69a25062017-11-15 16:18:51 -0800432 DialpadFragment dialpadFragment = inCallActivity.getDialpadFragment();
Eric Erfanianccca3152017-02-22 16:32:36 -0800433 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);
linyuh57b093b2017-11-17 14:32:32 -0800444 inCallActivity.updateNavigationBar(true /* isDialpadVisible */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800445 }
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 }
linyuh57b093b2017-11-17 14:32:32 -0800462 inCallActivity.updateNavigationBar(false /* isDialpadVisible */);
Eric Erfanianccca3152017-02-22 16:32:36 -0800463 }
464
Eric Erfanianccca3152017-02-22 16:32:36 -0800465 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 Erfanianccca3152017-02-22 16:32:36 -0800485 if (intent.getBooleanExtra(INTENT_EXTRA_NEW_OUTGOING_CALL, false)) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800486 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
linyuh9c327da2017-11-14 12:33:48 -0800499 inCallActivity.dismissKeyguard(true);
Eric Erfanianccca3152017-02-22 16:32:36 -0800500 }
501
502 boolean didShowAccountSelectionDialog = maybeShowAccountSelectionDialog();
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700503 if (didShowAccountSelectionDialog) {
504 inCallActivity.hideMainInCallFragment();
505 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800506 }
507
508 private boolean maybeShowAccountSelectionDialog() {
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700509 DialerCall waitingForAccountCall = CallList.getInstance().getWaitingForAccountCall();
510 if (waitingForAccountCall == null) {
Eric Erfanianccca3152017-02-22 16:32:36 -0800511 return false;
512 }
513
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700514 Bundle extras = waitingForAccountCall.getIntentExtras();
Eric Erfanianccca3152017-02-22 16:32:36 -0800515 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 Erfaniand5e47f62017-03-15 14:41:07 -0700523 selectPhoneAccountDialogFragment =
Eric Erfanianccca3152017-02-22 16:32:36 -0800524 SelectPhoneAccountDialogFragment.newInstance(
525 R.string.select_phone_account_for_calls,
526 true,
twyenba99bef2017-11-20 15:13:07 -0800527 0,
Eric Erfanianccca3152017-02-22 16:32:36 -0800528 phoneAccountHandles,
529 selectAccountListener,
twyenba99bef2017-11-20 15:13:07 -0800530 waitingForAccountCall.getId(),
531 null);
Eric Erfaniand5e47f62017-03-15 14:41:07 -0700532 selectPhoneAccountDialogFragment.show(
533 inCallActivity.getFragmentManager(), TAG_SELECT_ACCOUNT_FRAGMENT);
Eric Erfanianccca3152017-02-22 16:32:36 -0800534 return true;
535 }
linyuhf99f6302017-11-15 11:23:51 -0800536
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
linyuh57b093b2017-11-17 14:32:32 -0800552 boolean getIsRecreating() {
553 return isRecreating;
554 }
555
556 /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */
557 @Deprecated
linyuhf99f6302017-11-15 11:23:51 -0800558 @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 }
linyuh7b86f562017-11-16 11:24:09 -0800569
570 /** @deprecated Only for temporary use during the deprecation of {@link InCallActivityCommon} */
571 @Deprecated
572 InternationalCallOnWifiDialogFragment.Callback getCallbackForInternationalCallOnWifiDialog() {
573 return internationalCallOnWifiCallback;
574 }
Eric Erfanianccca3152017-02-22 16:32:36 -0800575}