From 4a35dd4f0d552531e612c64b5d08e9379a11be26 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 18 May 2022 13:26:03 -0700 Subject: [PATCH] Do not launch home disambiguation screen when home is not known Bug: 233071361 Test: Verified on device Change-Id: I54e71e19363920b0778c328dc391575d0921f304 --- .../quickstep/FallbackSwipeHandler.java | 9 ++--- .../quickstep/OverviewComponentObserver.java | 36 ++++++++++++++++++- .../android/quickstep/RecentsActivity.java | 4 +-- .../DeviceLockedInputConsumer.java | 7 ++-- .../OverviewWithoutFocusInputConsumer.java | 9 ++--- .../quickstep/interaction/AllSetActivity.java | 3 +- src/com/android/launcher3/Utilities.java | 9 ----- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java index ee5bb44040..99f7bdd2e7 100644 --- a/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java +++ b/quickstep/src/com/android/quickstep/FallbackSwipeHandler.java @@ -23,16 +23,15 @@ import static com.android.launcher3.GestureNavContract.EXTRA_ICON_POSITION; import static com.android.launcher3.GestureNavContract.EXTRA_ICON_SURFACE; import static com.android.launcher3.GestureNavContract.EXTRA_ON_FINISH_CALLBACK; import static com.android.launcher3.GestureNavContract.EXTRA_REMOTE_CALLBACK; -import static com.android.launcher3.Utilities.createHomeIntent; import static com.android.launcher3.anim.AnimatorListeners.forEndCallback; import static com.android.launcher3.anim.Interpolators.ACCEL; +import static com.android.quickstep.OverviewComponentObserver.startHomeIntentSafely; import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.ACTIVITY_TYPE_HOME; import android.animation.ObjectAnimator; import android.annotation.TargetApi; import android.app.ActivityManager.RunningTaskInfo; import android.app.ActivityOptions; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.graphics.Matrix; @@ -161,11 +160,7 @@ public class FallbackSwipeHandler extends if (gestureContractAnimationFactory != null && runningTaskTarget != null) { gestureContractAnimationFactory.addGestureContract(intent, runningTaskTarget.taskInfo); } - try { - mContext.startActivity(intent, options.toBundle()); - } catch (NullPointerException | ActivityNotFoundException | SecurityException e) { - mContext.startActivity(createHomeIntent()); - } + startHomeIntentSafely(mContext, intent, options.toBundle()); } @Override diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java index 0efe6666a8..9e3173c1f0 100644 --- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java +++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java @@ -20,11 +20,11 @@ import static android.content.Intent.ACTION_PACKAGE_ADDED; import static android.content.Intent.ACTION_PACKAGE_CHANGED; import static android.content.Intent.ACTION_PACKAGE_REMOVED; -import static com.android.launcher3.Utilities.createHomeIntent; import static com.android.launcher3.config.FeatureFlags.SEPARATE_RECENTS_ACTIVITY; import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter; import static com.android.systemui.shared.system.PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED; +import android.content.ActivityNotFoundException; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -33,8 +33,12 @@ import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.os.Bundle; import android.util.SparseIntArray; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import com.android.launcher3.tracing.OverviewComponentObserverProto; import com.android.launcher3.tracing.TouchInteractionServiceProto; import com.android.launcher3.util.SimpleBroadcastReceiver; @@ -276,4 +280,34 @@ public final class OverviewComponentObserver { overviewComponentObserver.setOverviewActivityResumed(mActivityInterface.isResumed()); serviceProto.setOverviewComponentObvserver(overviewComponentObserver); } + + /** + * Starts the intent for the current home activity. + */ + public static void startHomeIntentSafely(@NonNull Context context, @Nullable Bundle options) { + RecentsAnimationDeviceState deviceState = new RecentsAnimationDeviceState(context); + OverviewComponentObserver observer = new OverviewComponentObserver(context, deviceState); + Intent intent = observer.getHomeIntent(); + observer.onDestroy(); + deviceState.destroy(); + startHomeIntentSafely(context, intent, options); + } + + /** + * Starts the intent for the current home activity. + */ + public static void startHomeIntentSafely( + @NonNull Context context, @NonNull Intent homeIntent, @Nullable Bundle options) { + try { + context.startActivity(homeIntent, options); + } catch (NullPointerException | ActivityNotFoundException | SecurityException e) { + context.startActivity(createHomeIntent(), options); + } + } + + private static Intent createHomeIntent() { + return new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_HOME) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } } diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java index 4f0b9767f9..67ce606da9 100644 --- a/quickstep/src/com/android/quickstep/RecentsActivity.java +++ b/quickstep/src/com/android/quickstep/RecentsActivity.java @@ -21,11 +21,11 @@ import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE; import static com.android.launcher3.QuickstepTransitionManager.RECENTS_LAUNCH_DURATION; import static com.android.launcher3.QuickstepTransitionManager.STATUS_BAR_TRANSITION_DURATION; import static com.android.launcher3.QuickstepTransitionManager.STATUS_BAR_TRANSITION_PRE_DELAY; -import static com.android.launcher3.Utilities.createHomeIntent; import static com.android.launcher3.config.FeatureFlags.ENABLE_QUICKSTEP_LIVE_TILE; import static com.android.launcher3.graphics.SysUiScrim.SYSUI_PROGRESS; import static com.android.launcher3.testing.TestProtocol.BAD_STATE; import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; +import static com.android.quickstep.OverviewComponentObserver.startHomeIntentSafely; import static com.android.quickstep.TaskUtils.taskIsATargetWithMode; import static com.android.quickstep.TaskViewUtils.createRecentsWindowAnimator; import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING; @@ -428,7 +428,7 @@ public final class RecentsActivity extends StatefulActivity { RemoteAnimationAdapterCompat adapterCompat = new RemoteAnimationAdapterCompat(runner, HOME_APPEAR_DURATION, 0, getIApplicationThread()); - startActivity(createHomeIntent(), + startHomeIntentSafely(this, ActivityOptionsCompat.makeRemoteAnimation(adapterCompat).toBundle()); } diff --git a/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java index 3d737ca0e4..3c0da01db6 100644 --- a/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java +++ b/quickstep/src/com/android/quickstep/inputconsumers/DeviceLockedInputConsumer.java @@ -19,12 +19,12 @@ import static android.view.MotionEvent.ACTION_CANCEL; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_UP; -import static com.android.launcher3.Utilities.createHomeIntent; import static com.android.launcher3.Utilities.squaredHypot; import static com.android.launcher3.Utilities.squaredTouchSlop; import static com.android.launcher3.util.VelocityUtils.PX_PER_MS; import static com.android.quickstep.AbsSwipeUpHandler.MIN_PROGRESS_FOR_OVERVIEW; import static com.android.quickstep.MultiStateCallback.DEBUG_STATES; +import static com.android.quickstep.OverviewComponentObserver.startHomeIntentSafely; import static com.android.quickstep.util.ActiveGestureLog.INTENT_EXTRA_LOG_TRACE_ID; import android.animation.Animator; @@ -205,8 +205,9 @@ public class DeviceLockedInputConsumer implements InputConsumer, @Override public void onAnimationEnd(Animator animation) { if (dismissTask) { - // For now, just start the home intent so user is prompted to unlock the device. - mContext.startActivity(createHomeIntent()); + // For now, just start the home intent so user is prompted to + // unlock the device. + startHomeIntentSafely(mContext, mGestureState.getHomeIntent(), null); mHomeLaunched = true; } mStateCallback.setState(STATE_HANDLER_INVALIDATED); diff --git a/quickstep/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java index 864e08da46..a7301833a2 100644 --- a/quickstep/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java +++ b/quickstep/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java @@ -15,12 +15,11 @@ */ package com.android.quickstep.inputconsumers; -import static com.android.launcher3.Utilities.createHomeIntent; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_BACKGROUND; import static com.android.launcher3.logging.StatsLogManager.LAUNCHER_STATE_HOME; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_GESTURE; +import static com.android.quickstep.OverviewComponentObserver.startHomeIntentSafely; -import android.content.ActivityNotFoundException; import android.content.Context; import android.graphics.PointF; import android.view.MotionEvent; @@ -79,11 +78,7 @@ public class OverviewWithoutFocusInputConsumer implements InputConsumer, @Override public void onSwipeUp(boolean wasFling, PointF finalVelocity) { - try { - mContext.startActivity(mGestureState.getHomeIntent()); - } catch (NullPointerException | ActivityNotFoundException | SecurityException e) { - mContext.startActivity(createHomeIntent()); - } + startHomeIntentSafely(mContext, mGestureState.getHomeIntent(), null); ActiveGestureLog.INSTANCE.addLog("startQuickstep"); BaseActivity activity = BaseDraggingActivity.fromContext(mContext); int state = (mGestureState != null && mGestureState.getEndTarget() != null) diff --git a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java index a379aada4a..3dab6162b3 100644 --- a/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java +++ b/quickstep/src/com/android/quickstep/interaction/AllSetActivity.java @@ -19,6 +19,7 @@ import static com.android.launcher3.Utilities.mapBoundToRange; import static com.android.launcher3.Utilities.mapRange; import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN; import static com.android.launcher3.anim.Interpolators.LINEAR; +import static com.android.quickstep.OverviewComponentObserver.startHomeIntentSafely; import android.animation.Animator; import android.app.Activity; @@ -281,7 +282,7 @@ public class AllSetActivity extends Activity { @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (action == AccessibilityAction.ACTION_CLICK.getId()) { - startActivity(Utilities.createHomeIntent()); + startHomeIntentSafely(AllSetActivity.this, null); finish(); return true; } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 7b96838dbb..dc8c739311 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -586,15 +586,6 @@ public final class Utilities { return Math.max(lowerBound, Math.min(value, upperBound)); } - /** - * Returns an intent for starting the default home activity - */ - public static Intent createHomeIntent() { - return new Intent(Intent.ACTION_MAIN) - .addCategory(Intent.CATEGORY_HOME) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - } - /** * Wraps a message with a TTS span, so that a different message is spoken than * what is getting displayed.