From df59884370e63788d1c82a8ba755485a25edfd82 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 31 Mar 2023 23:45:36 +0000 Subject: Add debug logs for why taskbar might not be destroyed Test: Manually read log output Flag: None Bug: 254119092 Change-Id: Ibaa7ffdc91030c5c999ddc5f2807a55763854331 --- .../android/launcher3/taskbar/TaskbarManager.java | 74 +++++++++++++++++++++- .../launcher3/uioverrides/QuickstepLauncher.java | 3 + .../android/launcher3/util/DisplayController.java | 22 ++++++- 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index c5371069a6..3d8bf9ea63 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -22,6 +22,7 @@ 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.TASKBAR_NOT_DESTROYED_TAG; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange; @@ -63,6 +64,7 @@ import com.android.systemui.unfold.UnfoldTransitionProgressProvider; import com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider; import java.io.PrintWriter; +import java.util.StringJoiner; /** * Class to manage taskbar lifecycle @@ -147,6 +149,8 @@ public class TaskbarManager { @Override public void onConfigurationChanged(Configuration newConfig) { + debugWhyTaskbarNotDestroyed( + "TaskbarManager#mComponentCallbacks.onConfigurationChanged: " + newConfig); DeviceProfile dp = mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null; @@ -179,6 +183,9 @@ public class TaskbarManager { } } + debugWhyTaskbarNotDestroyed("ComponentCallbacks#onConfigurationChanged() " + + "configDiffForRecreate=" + + Configuration.configurationDiffToString(configDiffForRecreate)); if ((configDiffForRecreate & configsRequiringRecreate) != 0) { recreateTaskbar(); } else { @@ -207,6 +214,8 @@ public class TaskbarManager { mNavMode = info.navigationMode; recreateTaskbar(); } + debugWhyTaskbarNotDestroyed("DisplayInfoChangeListener#" + + mDisplayController.getChangeFlagsString(flags)); }; mNavMode = mDisplayController.getInfo().navigationMode; mDisplayController.addChangeListener(mDispInfoChangeListener); @@ -227,10 +236,13 @@ public class TaskbarManager { new IntentFilter(ACTION_SHOW_TASKBAR), RECEIVER_NOT_EXPORTED); }); + + debugWhyTaskbarNotDestroyed("TaskbarManager created"); recreateTaskbar(); } private void destroyExistingTaskbar() { + debugWhyTaskbarNotDestroyed("destroyExistingTaskbar: " + mTaskbarActivityContext); if (mTaskbarActivityContext != null) { mTaskbarActivityContext.onDestroy(); if (!FLAG_HIDE_NAVBAR_WINDOW) { @@ -274,7 +286,12 @@ public class TaskbarManager { if (mActivity == activity) { return; } + if (mActivity != null) { + mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged); + } mActivity = activity; + debugWhyTaskbarNotDestroyed("Set mActivity=" + mActivity); + mActivity.addOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged); UnfoldTransitionProgressProvider unfoldTransitionProgressProvider = getUnfoldTransitionProgressProviderForActivity(activity); mUnfoldProgressProvider.setSourceProvider(unfoldTransitionProgressProvider); @@ -318,7 +335,9 @@ public class TaskbarManager { */ public void clearActivity(@NonNull StatefulActivity activity) { if (mActivity == activity) { + mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged); mActivity = null; + debugWhyTaskbarNotDestroyed("clearActivity"); if (mTaskbarActivityContext != null) { mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT); } @@ -338,8 +357,12 @@ public class TaskbarManager { destroyExistingTaskbar(); - boolean isTaskBarEnabled = dp != null && isTaskbarPresent(dp); - if (!isTaskBarEnabled) { + boolean isTaskbarEnabled = dp != null && isTaskbarPresent(dp); + debugWhyTaskbarNotDestroyed("recreateTaskbar: isTaskbarEnabled=" + isTaskbarEnabled + + " [dp != null (i.e. mUserUnlocked)]=" + (dp != null) + + " FLAG_HIDE_NAVBAR_WINDOW=" + FLAG_HIDE_NAVBAR_WINDOW + + " dp.isTaskbarPresent=" + (dp == null ? "null" : dp.isTaskbarPresent)); + if (!isTaskbarEnabled) { SystemUiProxy.INSTANCE.get(mContext) .notifyTaskbarStatus(/* visible */ false, /* stashed */ false); return; @@ -440,6 +463,11 @@ public class TaskbarManager { * Called when the manager is no longer needed */ public void destroy() { + debugWhyTaskbarNotDestroyed("TaskbarManager#destroy()"); + if (mActivity != null) { + mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged); + } + UI_HELPER_EXECUTOR.execute( () -> mTaskbarBroadcastReceiver.unregisterReceiverSafely(mContext)); destroyExistingTaskbar(); @@ -464,4 +492,46 @@ public class TaskbarManager { mTaskbarActivityContext.dumpLogs(prefix + "\t", pw); } } + + /** Temp logs for b/254119092. */ + public void debugWhyTaskbarNotDestroyed(String debugReason) { + StringJoiner log = new StringJoiner("\n"); + log.add(debugReason); + + boolean activityTaskbarPresent = mActivity != null + && mActivity.getDeviceProfile().isTaskbarPresent; + boolean contextTaskbarPresent = mUserUnlocked + && LauncherAppState.getIDP(mContext).getDeviceProfile(mContext).isTaskbarPresent; + if (activityTaskbarPresent == contextTaskbarPresent) { + log.add("mActivity and mContext agree taskbarIsPresent=" + contextTaskbarPresent); + Log.d(TASKBAR_NOT_DESTROYED_TAG, log.toString()); + return; + } + + log.add("mActivity and mContext device profiles have different values, add more logs."); + + log.add("\tmActivity logs:"); + log.add("\t\tmActivity=" + mActivity); + if (mActivity != null) { + log.add("\t\tmActivity.getResources().getConfiguration()=" + + mActivity.getResources().getConfiguration()); + log.add("\t\tmActivity.getDeviceProfile().isTaskbarPresent=" + + activityTaskbarPresent); + } + log.add("\tmContext logs:"); + log.add("\t\tmContext=" + mContext); + log.add("\t\tmContext.getResources().getConfiguration()=" + + mContext.getResources().getConfiguration()); + if (mUserUnlocked) { + log.add("\t\tLauncherAppState.getIDP().getDeviceProfile(mContext).isTaskbarPresent=" + + contextTaskbarPresent); + } else { + log.add("\t\tCouldn't get DeviceProfile because !mUserUnlocked"); + } + + Log.d(TASKBAR_NOT_DESTROYED_TAG, log.toString()); + } + + private final DeviceProfile.OnDeviceProfileChangeListener mDebugActivityDeviceProfileChanged = + dp -> debugWhyTaskbarNotDestroyed("mActivity onDeviceProfileChanged"); } diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 7318298bef..243ed5c2ee 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -1237,6 +1237,9 @@ public class QuickstepLauncher extends Launcher { Trace.instantForTrack(TRACE_TAG_APP, "QuickstepLauncher#DeviceProfileChanged", getDeviceProfile().toSmallString()); SystemUiProxy.INSTANCE.get(this).setLauncherAppIconSize(mDeviceProfile.iconSizePx); + if (mTaskbarManager != null) { + mTaskbarManager.debugWhyTaskbarNotDestroyed("QuickstepLauncher#onDeviceProfileChanged"); + } } /** diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 3d455d8509..a3261b2623 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -23,6 +23,7 @@ import static com.android.launcher3.Utilities.dpiFromPx; import static com.android.launcher3.config.FeatureFlags.ENABLE_TRANSIENT_TASKBAR; import static com.android.launcher3.config.FeatureFlags.FORCE_PERSISTENT_TASKBAR; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; +import static com.android.launcher3.util.FlagDebugUtils.appendFlag; import static com.android.launcher3.util.window.WindowManagerProxy.MIN_TABLET_WIDTH; import android.annotation.SuppressLint; @@ -55,6 +56,7 @@ import java.util.Collections; import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.StringJoiner; /** * Utility class to cache properties of default display to avoid a system RPC on every call. @@ -66,6 +68,9 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable { private static final boolean DEBUG = false; private static boolean sTransientTaskbarStatusForTests; + // TODO(b/254119092) remove all logs with this tag + public static final String TASKBAR_NOT_DESTROYED_TAG = "b/254119092"; + public static final MainThreadInitializedObject INSTANCE = new MainThreadInitializedObject<>(DisplayController::new); @@ -206,6 +211,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable { @Override @TargetApi(Build.VERSION_CODES.S) public final void onConfigurationChanged(Configuration config) { + Log.d(TASKBAR_NOT_DESTROYED_TAG, "DisplayController#onConfigurationChanged: " + config); Display display = mWindowContext.getDisplay(); if (config.densityDpi != mInfo.densityDpi || config.fontScale != mInfo.fontScale @@ -272,7 +278,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable { change |= CHANGE_SUPPORTED_BOUNDS; } if (DEBUG) { - Log.d(TAG, "handleInfoChange - change: 0b" + Integer.toBinaryString(change)); + Log.d(TAG, "handleInfoChange - change: " + getChangeFlagsString(change)); } if (change != 0) { @@ -391,6 +397,20 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable { } } + /** + * Returns the given binary flags as a human-readable string. + * @see #CHANGE_ALL + */ + public String getChangeFlagsString(int change) { + StringJoiner result = new StringJoiner("|"); + appendFlag(result, change, CHANGE_ACTIVE_SCREEN, "CHANGE_ACTIVE_SCREEN"); + appendFlag(result, change, CHANGE_ROTATION, "CHANGE_ROTATION"); + appendFlag(result, change, CHANGE_DENSITY, "CHANGE_DENSITY"); + appendFlag(result, change, CHANGE_SUPPORTED_BOUNDS, "CHANGE_SUPPORTED_BOUNDS"); + appendFlag(result, change, CHANGE_NAVIGATION_MODE, "CHANGE_NAVIGATION_MODE"); + return result.toString(); + } + /** * Dumps the current state information */ -- cgit v1.2.3