From 711c98ed1a282b5d93f3252ab67abde24c7a7f47 Mon Sep 17 00:00:00 2001 From: twyen Date: Wed, 22 Nov 2017 16:24:48 -0800 Subject: Fix showing CallingAccountSelector in lock screen FLAG_SHOW_WHEN_LOCKED is added to PreCallActivity so it can be launched in lockscreen. PreCallCoordinator now grabs new instances of PreCallActions onResume so the state can be flushed. If it is reused states like PendingAction might be used after it is discarded. Added null check before discarding fragment because it might not be created yet due to background query. Bug: 69570769 Test: CallingAccountSelectorTest PiperOrigin-RevId: 176714225 Change-Id: I8b09441bd1cdb8df835978a1d82b53a3d3d056e0 --- .../precall/impl/CallingAccountSelector.java | 24 +++++++++++++--------- .../dialer/precall/impl/PreCallActivity.java | 6 ++++++ .../precall/impl/PreCallCoordinatorImpl.java | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) (limited to 'java/com/android/dialer/precall') diff --git a/java/com/android/dialer/precall/impl/CallingAccountSelector.java b/java/com/android/dialer/precall/impl/CallingAccountSelector.java index 4308df73a..8d3df2360 100644 --- a/java/com/android/dialer/precall/impl/CallingAccountSelector.java +++ b/java/com/android/dialer/precall/impl/CallingAccountSelector.java @@ -127,12 +127,12 @@ public class CallingAccountSelector implements PreCallAction { PendingAction pendingAction = coordinator.startPendingAction(); DialerExecutorComponent.get(coordinator.getActivity()) .dialerExecutorFactory() - .createUiTaskBuilder( - activity.getFragmentManager(), - "PreferredAccountWorker", - new PreferredAccountWorker(phoneNumber)) + .createNonUiTaskBuilder(new PreferredAccountWorker(phoneNumber)) .onSuccess( (result -> { + if (isDiscarding) { + return; + } if (result.phoneAccountHandle.isPresent()) { coordinator.getBuilder().setPhoneAccountHandle(result.phoneAccountHandle.get()); pendingAction.finish(); @@ -221,7 +221,9 @@ public class CallingAccountSelector implements PreCallAction { @Override public void onDiscard() { isDiscarding = true; - selectPhoneAccountDialogFragment.dismiss(); + if (selectPhoneAccountDialogFragment != null) { + selectPhoneAccountDialogFragment.dismiss(); + } } private static class PreferredAccountWorkerResult { @@ -364,11 +366,13 @@ public class CallingAccountSelector implements PreCallAction { new WritePreferredAccountWorkerInput( coordinator.getActivity(), dataId, selectedAccountHandle)); } - DialerExecutorComponent.get(coordinator.getActivity()) - .dialerExecutorFactory() - .createNonUiTaskBuilder(new UserSelectionReporter(selectedAccountHandle, number)) - .build() - .executeParallel(coordinator.getActivity()); + if (number != null) { + DialerExecutorComponent.get(coordinator.getActivity()) + .dialerExecutorFactory() + .createNonUiTaskBuilder(new UserSelectionReporter(selectedAccountHandle, number)) + .build() + .executeParallel(coordinator.getActivity()); + } listener.finish(); } diff --git a/java/com/android/dialer/precall/impl/PreCallActivity.java b/java/com/android/dialer/precall/impl/PreCallActivity.java index 938d31d5f..48c2fbfc3 100644 --- a/java/com/android/dialer/precall/impl/PreCallActivity.java +++ b/java/com/android/dialer/precall/impl/PreCallActivity.java @@ -16,9 +16,13 @@ package com.android.dialer.precall.impl; +import android.annotation.TargetApi; import android.app.Activity; +import android.os.Build.VERSION; +import android.os.Build.VERSION_CODES; import android.os.Bundle; import android.support.annotation.Nullable; +import android.view.WindowManager.LayoutParams; /** A transparent activity to host dialogs for {@link PreCallCoordinatorImpl} */ public class PreCallActivity extends Activity { @@ -30,6 +34,8 @@ public class PreCallActivity extends Activity { super.onCreate(savedInstanceState); preCallCoordinator = new PreCallCoordinatorImpl(this); preCallCoordinator.onCreate(getIntent(), savedInstanceState); + getWindow().addFlags(LayoutParams.FLAG_SHOW_WHEN_LOCKED); + } @Override diff --git a/java/com/android/dialer/precall/impl/PreCallCoordinatorImpl.java b/java/com/android/dialer/precall/impl/PreCallCoordinatorImpl.java index de32cc2ae..94ba90d75 100644 --- a/java/com/android/dialer/precall/impl/PreCallCoordinatorImpl.java +++ b/java/com/android/dialer/precall/impl/PreCallCoordinatorImpl.java @@ -59,7 +59,6 @@ public class PreCallCoordinatorImpl implements PreCallCoordinator { } else { builder = Assert.isNotNull(intent.getParcelableExtra(EXTRA_CALL_INTENT_BUILDER)); } - actions = PreCallComponent.get(activity).getPreCall().getActions(); } void onRestoreInstanceState(Bundle savedInstanceState) { @@ -68,6 +67,7 @@ public class PreCallCoordinatorImpl implements PreCallCoordinator { } void onResume() { + actions = PreCallComponent.get(activity).getPreCall().getActions(); runNextAction(); } -- cgit v1.2.3