From 25137534a1e7194cc317c368d02b615caca07a20 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 18 Apr 2022 15:29:45 -0700 Subject: [PATCH] Fixing potential NullPointer exceptions when Launcher is created before TouchInteractionService is initialized SystemUiProxy is a wrapper opject which holds the state information until the actual proxy is initialized. It is safe to be initialized lazily. Bug: 221961069 Test: Verified on device Change-Id: I1a621cad52e5b8384439ef02de6b95c6452bcb06 --- .../launcher3/QuickstepTransitionManager.java | 6 +++--- .../android/quickstep/AbsSwipeUpHandler.java | 2 +- .../LauncherBackAnimationController.java | 21 ++++--------------- .../quickstep/RecentsAnimationController.java | 13 +++++------- .../quickstep/TaskAnimationManager.java | 5 ++--- .../android/quickstep/views/RecentsView.java | 5 +---- .../com/android/quickstep/views/TaskView.java | 6 +----- 7 files changed, 17 insertions(+), 41 deletions(-) diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java index 5b912ade65..097609f2d9 100644 --- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java +++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java @@ -1161,7 +1161,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener new LauncherAnimationRunner(mHandler, mWallpaperOpenTransitionRunner, false /* startAtFrontOfQueue */), mLauncher.getIApplicationThread()); mLauncherOpenTransition.addHomeOpenCheck(mLauncher.getComponentName()); - SystemUiProxy.INSTANCE.getNoCreate().registerRemoteTransition(mLauncherOpenTransition); + SystemUiProxy.INSTANCE.get(mLauncher).registerRemoteTransition(mLauncherOpenTransition); } if (mBackAnimationController != null) { mBackAnimationController.registerBackCallbacks(mHandler); @@ -1172,7 +1172,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener unregisterRemoteAnimations(); unregisterRemoteTransitions(); mStartingWindowListener.setTransitionManager(null); - SystemUiProxy.INSTANCE.getNoCreate().setStartingWindowListener(null); + SystemUiProxy.INSTANCE.get(mLauncher).setStartingWindowListener(null); } private void unregisterRemoteAnimations() { @@ -1196,7 +1196,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener } if (hasControlRemoteAppTransitionPermission()) { if (mLauncherOpenTransition == null) return; - SystemUiProxy.INSTANCE.getNoCreate().unregisterRemoteTransition( + SystemUiProxy.INSTANCE.get(mLauncher).unregisterRemoteTransition( mLauncherOpenTransition); mLauncherOpenTransition = null; mWallpaperOpenTransitionRunner = null; diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index 2ae0646ed0..2e581feded 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -770,7 +770,7 @@ public abstract class AbsSwipeUpHandler, // We will handle the sysui flags based on the centermost task view. mRecentsAnimationController.setUseLauncherSystemBarFlags(swipeUpThresholdPassed || (quickswitchThresholdPassed && centermostTaskFlags != 0)); - mRecentsAnimationController.setSplitScreenMinimized(swipeUpThresholdPassed); + mRecentsAnimationController.setSplitScreenMinimized(mContext, swipeUpThresholdPassed); // Provide a hint to WM the direction that we will be settling in case the animation // needs to be canceled mRecentsAnimationController.setWillFinishToHome(swipeUpThresholdPassed); diff --git a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java index cc79f4a1d8..921674a2d4 100644 --- a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java +++ b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java @@ -29,7 +29,6 @@ import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.os.Handler; -import android.util.Log; import android.util.MathUtils; import android.util.Pair; import android.view.RemoteAnimationTarget; @@ -55,7 +54,7 @@ import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat; * the app window and plays the rest of app close transitions in one go. * * This animation is used only for apps that enable back dispatching via - * {@link android.view.OnBackInvokedDispatcher}. The controller registers + * {@link android.window.OnBackInvokedDispatcher}. The controller registers * an {@link IOnBackInvokedCallback} with WM Shell and receives back dispatches when a back * navigation to launcher starts. * @@ -66,7 +65,6 @@ import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat; public class LauncherBackAnimationController { private static final int CANCEL_TRANSITION_DURATION = 233; private static final float MIN_WINDOW_SCALE = 0.7f; - private static final String TAG = "LauncherBackAnimationController"; private final QuickstepTransitionManager mQuickstepTransitionManager; private final Matrix mTransformMatrix = new Matrix(); /** The window position at the beginning of the back animation. */ @@ -115,12 +113,7 @@ public class LauncherBackAnimationController { * @param handler Handler to the thread to run the animations on. */ public void registerBackCallbacks(Handler handler) { - SystemUiProxy systemUiProxy = SystemUiProxy.INSTANCE.getNoCreate(); - if (systemUiProxy == null) { - Log.e(TAG, "SystemUiProxy is null. Skip registering back invocation callbacks"); - return; - } - systemUiProxy.setBackToLauncherCallback( + SystemUiProxy.INSTANCE.get(mLauncher).setBackToLauncherCallback( new IOnBackInvokedCallback.Stub() { @Override public void onBackCancelled() { @@ -170,10 +163,7 @@ public class LauncherBackAnimationController { /** Unregisters the back to launcher callback in shell. */ public void unregisterBackCallbacks() { - SystemUiProxy systemUiProxy = SystemUiProxy.INSTANCE.getNoCreate(); - if (systemUiProxy != null) { - systemUiProxy.clearBackToLauncherCallback(); - } + SystemUiProxy.INSTANCE.get(mLauncher).clearBackToLauncherCallback(); } private void startBack(BackEvent backEvent) { @@ -298,10 +288,7 @@ public class LauncherBackAnimationController { mInitialTouchPos.set(0, 0); mAnimatorSetInProgress = false; mSpringAnimationInProgress = false; - SystemUiProxy systemUiProxy = SystemUiProxy.INSTANCE.getNoCreate(); - if (systemUiProxy != null) { - SystemUiProxy.INSTANCE.getNoCreate().onBackToLauncherAnimationFinished(); - } + SystemUiProxy.INSTANCE.get(mLauncher).onBackToLauncherAnimationFinished(); } private void startTransitionAnimations(RectFSpringAnim springAnim, AnimatorSet anim) { diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationController.java b/quickstep/src/com/android/quickstep/RecentsAnimationController.java index c120b32543..2007ee1ebd 100644 --- a/quickstep/src/com/android/quickstep/RecentsAnimationController.java +++ b/quickstep/src/com/android/quickstep/RecentsAnimationController.java @@ -19,6 +19,7 @@ import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.quickstep.TaskAnimationManager.ENABLE_SHELL_TRANSITIONS; +import android.content.Context; import android.os.RemoteException; import android.util.Log; import android.view.IRecentsAnimationController; @@ -97,24 +98,20 @@ public class RecentsAnimationController { * Indicates that the gesture has crossed the window boundary threshold and we should minimize * if we are in splitscreen. */ - public void setSplitScreenMinimized(boolean splitScreenMinimized) { + public void setSplitScreenMinimized(Context context, boolean splitScreenMinimized) { if (!mAllowMinimizeSplitScreen) { return; } if (mSplitScreenMinimized != splitScreenMinimized) { mSplitScreenMinimized = splitScreenMinimized; - UI_HELPER_EXECUTOR.execute(() -> { - SystemUiProxy p = SystemUiProxy.INSTANCE.getNoCreate(); - if (p != null) { - p.setSplitScreenMinimized(splitScreenMinimized); - } - }); + UI_HELPER_EXECUTOR.execute(() -> SystemUiProxy.INSTANCE.get(context) + .setSplitScreenMinimized(splitScreenMinimized)); } } /** * Remove task remote animation target from - * {@link RecentsAnimationCallbacks#onTaskAppeared(RemoteAnimationTargetCompat)}}. + * {@link RecentsAnimationCallbacks#onTasksAppeared}}. */ @UiThread public void removeTaskTarget(@NonNull RemoteAnimationTargetCompat target) { diff --git a/quickstep/src/com/android/quickstep/TaskAnimationManager.java b/quickstep/src/com/android/quickstep/TaskAnimationManager.java index b8334a9ae8..f094d712a1 100644 --- a/quickstep/src/com/android/quickstep/TaskAnimationManager.java +++ b/quickstep/src/com/android/quickstep/TaskAnimationManager.java @@ -177,9 +177,8 @@ public class TaskAnimationManager implements RecentsAnimationCallbacks.RecentsAn ((RecentsActivity) activityInterface.getCreatedActivity()).startHome(); return; } - RemoteAnimationTarget[] nonAppTargets = - SystemUiProxy.INSTANCE.getNoCreate() - .onGoingToRecentsLegacy(false, nonHomeApps); + RemoteAnimationTarget[] nonAppTargets = SystemUiProxy.INSTANCE.get(mCtx) + .onGoingToRecentsLegacy(false, nonHomeApps); if (ENABLE_QUICKSTEP_LIVE_TILE.get() && activityInterface.isInLiveTileMode() && activityInterface.getCreatedActivity() != null) { diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index aff9df6f35..50fb9df773 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -4486,10 +4486,7 @@ public abstract class RecentsView