Merge "Listen for density changes through DisplayController callbacks" into tm-dev am: 37ce441089 am: a299f92e33

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/17529040

Change-Id: Ib565537e4bd1dc0c268794da2a59fe7f23b127b4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Vinit Nayak
2022-04-14 00:50:39 +00:00
committed by Automerger Merge Worker
@@ -19,6 +19,7 @@ import static android.content.pm.PackageManager.FEATURE_PC;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL; 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 static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
import android.content.ComponentCallbacks; import android.content.ComponentCallbacks;
@@ -41,7 +42,6 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.statemanager.StatefulActivity; import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider; import com.android.launcher3.taskbar.unfold.NonDestroyableScopedUnfoldTransitionProgressProvider;
import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.SettingsCache; import com.android.launcher3.util.SettingsCache;
import com.android.launcher3.util.SimpleBroadcastReceiver; import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.quickstep.RecentsActivity; import com.android.quickstep.RecentsActivity;
@@ -55,7 +55,7 @@ import java.io.PrintWriter;
/** /**
* Class to manage taskbar lifecycle * 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( private static final Uri USER_SETUP_COMPLETE_URI = Settings.Secure.getUriFor(
Settings.Secure.USER_SETUP_COMPLETE); 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 * navigation mode, that callback gets called too soon, before it's internal navigation mode
* reflects the current one. * reflects the current one.
* DisplayController's callback is delayed enough to get the correct nav mode value * 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; private boolean mUserUnlocked = false;
@@ -105,6 +112,7 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
SystemUiProxy.INSTANCE.get(mContext), new Handler()); SystemUiProxy.INSTANCE.get(mContext), new Handler());
mUserSetupCompleteListener = isUserSetupComplete -> recreateTaskbar(); mUserSetupCompleteListener = isUserSetupComplete -> recreateTaskbar();
mNavBarKidsModeListener = isNavBarKidsMode -> recreateTaskbar(); mNavBarKidsModeListener = isNavBarKidsMode -> recreateTaskbar();
// TODO(b/227669780): Consolidate this w/ DisplayController callbacks
mComponentCallbacks = new ComponentCallbacks() { mComponentCallbacks = new ComponentCallbacks() {
private Configuration mOldConfig = mContext.getResources().getConfiguration(); private Configuration mOldConfig = mContext.getResources().getConfiguration();
@@ -116,7 +124,7 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
int configDiff = mOldConfig.diff(newConfig); int configDiff = mOldConfig.diff(newConfig);
int configsRequiringRecreate = ActivityInfo.CONFIG_ASSETS_PATHS int configsRequiringRecreate = ActivityInfo.CONFIG_ASSETS_PATHS
| ActivityInfo.CONFIG_LAYOUT_DIRECTION | ActivityInfo.CONFIG_UI_MODE | ActivityInfo.CONFIG_LAYOUT_DIRECTION | ActivityInfo.CONFIG_UI_MODE
| ActivityInfo.CONFIG_DENSITY | ActivityInfo.CONFIG_SCREEN_SIZE; | ActivityInfo.CONFIG_SCREEN_SIZE;
boolean requiresRecreate = (configDiff & configsRequiringRecreate) != 0; boolean requiresRecreate = (configDiff & configsRequiringRecreate) != 0;
if ((configDiff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0 if ((configDiff & ActivityInfo.CONFIG_SCREEN_SIZE) != 0
&& mTaskbarActivityContext != null && dp != null) { && mTaskbarActivityContext != null && dp != null) {
@@ -151,8 +159,12 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
public void onLowMemory() { } public void onLowMemory() { }
}; };
mShutdownReceiver = new SimpleBroadcastReceiver(i -> destroyExistingTaskbar()); mShutdownReceiver = new SimpleBroadcastReceiver(i -> destroyExistingTaskbar());
mDispInfoChangeListener = (context, info, flags) -> {
mDisplayController.addChangeListener(this); if ((flags & CHANGE_FLAGS) != 0) {
recreateTaskbar();
}
};
mDisplayController.addChangeListener(mDispInfoChangeListener);
SettingsCache.INSTANCE.get(mContext).register(USER_SETUP_COMPLETE_URI, SettingsCache.INSTANCE.get(mContext).register(USER_SETUP_COMPLETE_URI,
mUserSetupCompleteListener); mUserSetupCompleteListener);
SettingsCache.INSTANCE.get(mContext).register(NAV_BAR_KIDS_MODE, SettingsCache.INSTANCE.get(mContext).register(NAV_BAR_KIDS_MODE,
@@ -163,13 +175,6 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
recreateTaskbar(); recreateTaskbar();
} }
@Override
public void onDisplayInfoChanged(Context context, Info info, int flags) {
if ((flags & CHANGE_FLAGS) != 0) {
recreateTaskbar();
}
}
private void destroyExistingTaskbar() { private void destroyExistingTaskbar() {
if (mTaskbarActivityContext != null) { if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.onDestroy(); mTaskbarActivityContext.onDestroy();
@@ -310,7 +315,7 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
*/ */
public void destroy() { public void destroy() {
destroyExistingTaskbar(); destroyExistingTaskbar();
mDisplayController.removeChangeListener(this); mDisplayController.removeChangeListener(mDispInfoChangeListener);
SettingsCache.INSTANCE.get(mContext).unregister(USER_SETUP_COMPLETE_URI, SettingsCache.INSTANCE.get(mContext).unregister(USER_SETUP_COMPLETE_URI,
mUserSetupCompleteListener); mUserSetupCompleteListener);
SettingsCache.INSTANCE.get(mContext).unregister(NAV_BAR_KIDS_MODE, SettingsCache.INSTANCE.get(mContext).unregister(NAV_BAR_KIDS_MODE,