Merge "Add debug logs for why taskbar might not be destroyed" into tm-qpr-dev am: c8d8c58f5b am: 3979706e06 am: af02f865ee

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

Change-Id: Ic7a7854e0873f67e0ded12124eb6bf020d5c9a0f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Tony Wickham
2023-04-04 16:40:46 +00:00
committed by Automerger Merge Worker
3 changed files with 96 additions and 3 deletions
@@ -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_DENSITY;
import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE; 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.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.FlagDebugUtils.formatFlagChange; 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 com.android.systemui.unfold.util.ScopedUnfoldTransitionProgressProvider;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.StringJoiner;
/** /**
* Class to manage taskbar lifecycle * Class to manage taskbar lifecycle
@@ -147,6 +149,8 @@ public class TaskbarManager {
@Override @Override
public void onConfigurationChanged(Configuration newConfig) { public void onConfigurationChanged(Configuration newConfig) {
debugWhyTaskbarNotDestroyed(
"TaskbarManager#mComponentCallbacks.onConfigurationChanged: " + newConfig);
DeviceProfile dp = mUserUnlocked DeviceProfile dp = mUserUnlocked
? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext)
: null; : null;
@@ -179,6 +183,9 @@ public class TaskbarManager {
} }
} }
debugWhyTaskbarNotDestroyed("ComponentCallbacks#onConfigurationChanged() "
+ "configDiffForRecreate="
+ Configuration.configurationDiffToString(configDiffForRecreate));
if ((configDiffForRecreate & configsRequiringRecreate) != 0) { if ((configDiffForRecreate & configsRequiringRecreate) != 0) {
recreateTaskbar(); recreateTaskbar();
} else { } else {
@@ -207,6 +214,8 @@ public class TaskbarManager {
mNavMode = info.navigationMode; mNavMode = info.navigationMode;
recreateTaskbar(); recreateTaskbar();
} }
debugWhyTaskbarNotDestroyed("DisplayInfoChangeListener#"
+ mDisplayController.getChangeFlagsString(flags));
}; };
mNavMode = mDisplayController.getInfo().navigationMode; mNavMode = mDisplayController.getInfo().navigationMode;
mDisplayController.addChangeListener(mDispInfoChangeListener); mDisplayController.addChangeListener(mDispInfoChangeListener);
@@ -227,10 +236,13 @@ public class TaskbarManager {
new IntentFilter(ACTION_SHOW_TASKBAR), new IntentFilter(ACTION_SHOW_TASKBAR),
RECEIVER_NOT_EXPORTED); RECEIVER_NOT_EXPORTED);
}); });
debugWhyTaskbarNotDestroyed("TaskbarManager created");
recreateTaskbar(); recreateTaskbar();
} }
private void destroyExistingTaskbar() { private void destroyExistingTaskbar() {
debugWhyTaskbarNotDestroyed("destroyExistingTaskbar: " + mTaskbarActivityContext);
if (mTaskbarActivityContext != null) { if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.onDestroy(); mTaskbarActivityContext.onDestroy();
if (!FLAG_HIDE_NAVBAR_WINDOW) { if (!FLAG_HIDE_NAVBAR_WINDOW) {
@@ -274,7 +286,12 @@ public class TaskbarManager {
if (mActivity == activity) { if (mActivity == activity) {
return; return;
} }
if (mActivity != null) {
mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
}
mActivity = activity; mActivity = activity;
debugWhyTaskbarNotDestroyed("Set mActivity=" + mActivity);
mActivity.addOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
UnfoldTransitionProgressProvider unfoldTransitionProgressProvider = UnfoldTransitionProgressProvider unfoldTransitionProgressProvider =
getUnfoldTransitionProgressProviderForActivity(activity); getUnfoldTransitionProgressProviderForActivity(activity);
mUnfoldProgressProvider.setSourceProvider(unfoldTransitionProgressProvider); mUnfoldProgressProvider.setSourceProvider(unfoldTransitionProgressProvider);
@@ -318,7 +335,9 @@ public class TaskbarManager {
*/ */
public void clearActivity(@NonNull StatefulActivity activity) { public void clearActivity(@NonNull StatefulActivity activity) {
if (mActivity == activity) { if (mActivity == activity) {
mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
mActivity = null; mActivity = null;
debugWhyTaskbarNotDestroyed("clearActivity");
if (mTaskbarActivityContext != null) { if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT); mTaskbarActivityContext.setUIController(TaskbarUIController.DEFAULT);
} }
@@ -338,8 +357,12 @@ public class TaskbarManager {
destroyExistingTaskbar(); destroyExistingTaskbar();
boolean isTaskBarEnabled = dp != null && isTaskbarPresent(dp); boolean isTaskbarEnabled = dp != null && isTaskbarPresent(dp);
if (!isTaskBarEnabled) { 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) SystemUiProxy.INSTANCE.get(mContext)
.notifyTaskbarStatus(/* visible */ false, /* stashed */ false); .notifyTaskbarStatus(/* visible */ false, /* stashed */ false);
return; return;
@@ -440,6 +463,11 @@ public class TaskbarManager {
* Called when the manager is no longer needed * Called when the manager is no longer needed
*/ */
public void destroy() { public void destroy() {
debugWhyTaskbarNotDestroyed("TaskbarManager#destroy()");
if (mActivity != null) {
mActivity.removeOnDeviceProfileChangeListener(mDebugActivityDeviceProfileChanged);
}
UI_HELPER_EXECUTOR.execute( UI_HELPER_EXECUTOR.execute(
() -> mTaskbarBroadcastReceiver.unregisterReceiverSafely(mContext)); () -> mTaskbarBroadcastReceiver.unregisterReceiverSafely(mContext));
destroyExistingTaskbar(); destroyExistingTaskbar();
@@ -464,4 +492,46 @@ public class TaskbarManager {
mTaskbarActivityContext.dumpLogs(prefix + "\t", pw); 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");
} }
@@ -1245,6 +1245,9 @@ public class QuickstepLauncher extends Launcher {
Trace.instantForTrack(TRACE_TAG_APP, "QuickstepLauncher#DeviceProfileChanged", Trace.instantForTrack(TRACE_TAG_APP, "QuickstepLauncher#DeviceProfileChanged",
getDeviceProfile().toSmallString()); getDeviceProfile().toSmallString());
SystemUiProxy.INSTANCE.get(this).setLauncherAppIconSize(mDeviceProfile.iconSizePx); SystemUiProxy.INSTANCE.get(this).setLauncherAppIconSize(mDeviceProfile.iconSizePx);
if (mTaskbarManager != null) {
mTaskbarManager.debugWhyTaskbarNotDestroyed("QuickstepLauncher#onDeviceProfileChanged");
}
} }
/** /**
@@ -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.ENABLE_TRANSIENT_TASKBAR;
import static com.android.launcher3.config.FeatureFlags.FORCE_PERSISTENT_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.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.FlagDebugUtils.appendFlag;
import static com.android.launcher3.util.window.WindowManagerProxy.MIN_TABLET_WIDTH; import static com.android.launcher3.util.window.WindowManagerProxy.MIN_TABLET_WIDTH;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@@ -55,6 +56,7 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.StringJoiner;
/** /**
* Utility class to cache properties of default display to avoid a system RPC on every call. * 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 final boolean DEBUG = false;
private static boolean sTransientTaskbarStatusForTests; 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<DisplayController> INSTANCE = public static final MainThreadInitializedObject<DisplayController> INSTANCE =
new MainThreadInitializedObject<>(DisplayController::new); new MainThreadInitializedObject<>(DisplayController::new);
@@ -206,6 +211,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
@Override @Override
@TargetApi(Build.VERSION_CODES.S) @TargetApi(Build.VERSION_CODES.S)
public final void onConfigurationChanged(Configuration config) { public final void onConfigurationChanged(Configuration config) {
Log.d(TASKBAR_NOT_DESTROYED_TAG, "DisplayController#onConfigurationChanged: " + config);
Display display = mWindowContext.getDisplay(); Display display = mWindowContext.getDisplay();
if (config.densityDpi != mInfo.densityDpi if (config.densityDpi != mInfo.densityDpi
|| config.fontScale != mInfo.fontScale || config.fontScale != mInfo.fontScale
@@ -272,7 +278,7 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable {
change |= CHANGE_SUPPORTED_BOUNDS; change |= CHANGE_SUPPORTED_BOUNDS;
} }
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "handleInfoChange - change: 0b" + Integer.toBinaryString(change)); Log.d(TAG, "handleInfoChange - change: " + getChangeFlagsString(change));
} }
if (change != 0) { 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 * Dumps the current state information
*/ */