From 188ae142209f2d8157afe789d3ca8e11a58f10c9 Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Thu, 31 Mar 2022 16:20:23 -0700 Subject: [PATCH] Listen for density changes through DisplayController callbacks * Make display controller callbacks member variable for clarity. * Created follow-up refactor (b/227669780) Fix: 227329641 Test: Repro steps in bug no longer make taskbar appear when it shouldn't Change-Id: I83702c0b817749943d2a9c4c5f0e44342a475e75 --- .../launcher3/taskbar/TaskbarManager.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index 8e31a74927..e02a9d77c1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -19,6 +19,7 @@ import static android.content.pm.PackageManager.FEATURE_PC; import static android.view.Display.DEFAULT_DISPLAY; import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; +import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY; import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; import android.content.ComponentCallbacks; @@ -41,7 +42,6 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider; import com.android.launcher3.util.DisplayController; -import com.android.launcher3.util.DisplayController.Info; import com.android.launcher3.util.SettingsCache; import com.android.launcher3.util.SimpleBroadcastReceiver; import com.android.quickstep.RecentsActivity; @@ -55,7 +55,7 @@ import java.io.PrintWriter; /** * Class to manage taskbar lifecycle */ -public class TaskbarManager implements DisplayController.DisplayInfoChangeListener { +public class TaskbarManager { private static final Uri USER_SETUP_COMPLETE_URI = Settings.Secure.getUriFor( Settings.Secure.USER_SETUP_COMPLETE); @@ -91,8 +91,15 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen * navigation mode, that callback gets called too soon, before it's internal navigation mode * reflects the current one. * DisplayController's callback is delayed enough to get the correct nav mode value + * + * We also use density change here because DeviceProfile has had a chance to update it's state + * whereas density for component callbacks registered in this class don't update DeviceProfile. + * Confused? Me too. Make it less confusing (TODO: b/227669780) + * + * Flags used with {@link #mDispInfoChangeListener} */ - private static final int CHANGE_FLAGS = CHANGE_NAVIGATION_MODE; + private static final int CHANGE_FLAGS = CHANGE_NAVIGATION_MODE | CHANGE_DENSITY; + private final DisplayController.DisplayInfoChangeListener mDispInfoChangeListener; private boolean mUserUnlocked = false; @@ -105,6 +112,7 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen SystemUiProxy.INSTANCE.get(mContext), new Handler()); mUserSetupCompleteListener = isUserSetupComplete -> recreateTaskbar(); mNavBarKidsModeListener = isNavBarKidsMode -> recreateTaskbar(); + // TODO(b/227669780): Consolidate this w/ DisplayController callbacks mComponentCallbacks = new ComponentCallbacks() { private Configuration mOldConfig = mContext.getResources().getConfiguration(); @@ -116,7 +124,7 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen int configDiff = mOldConfig.diff(newConfig); int configsRequiringRecreate = ActivityInfo.CONFIG_ASSETS_PATHS | ActivityInfo.CONFIG_LAYOUT_DIRECTION | ActivityInfo.CONFIG_UI_MODE - | ActivityInfo.CONFIG_DENSITY | ActivityInfo.CONFIG_SCREEN_SIZE; + | ActivityInfo.CONFIG_SCREEN_SIZE; boolean requiresRecreate = (configDiff & configsRequiringRecreate) != 0; if ((configDiff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0 && mTaskbarActivityContext != null && dp != null) { @@ -151,8 +159,12 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen public void onLowMemory() { } }; mShutdownReceiver = new SimpleBroadcastReceiver(i -> destroyExistingTaskbar()); - - mDisplayController.addChangeListener(this); + mDispInfoChangeListener = (context, info, flags) -> { + if ((flags & CHANGE_FLAGS) != 0) { + recreateTaskbar(); + } + }; + mDisplayController.addChangeListener(mDispInfoChangeListener); SettingsCache.INSTANCE.get(mContext).register(USER_SETUP_COMPLETE_URI, mUserSetupCompleteListener); SettingsCache.INSTANCE.get(mContext).register(NAV_BAR_KIDS_MODE, @@ -163,13 +175,6 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen recreateTaskbar(); } - @Override - public void onDisplayInfoChanged(Context context, Info info, int flags) { - if ((flags & CHANGE_FLAGS) != 0) { - recreateTaskbar(); - } - } - private void destroyExistingTaskbar() { if (mTaskbarActivityContext != null) { mTaskbarActivityContext.onDestroy(); @@ -310,7 +315,7 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen */ public void destroy() { destroyExistingTaskbar(); - mDisplayController.removeChangeListener(this); + mDisplayController.removeChangeListener(mDispInfoChangeListener); SettingsCache.INSTANCE.get(mContext).unregister(USER_SETUP_COMPLETE_URI, mUserSetupCompleteListener); SettingsCache.INSTANCE.get(mContext).unregister(NAV_BAR_KIDS_MODE,