From e120fcfa473535244925307ac16666a7d6d50d24 Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Fri, 4 Aug 2023 15:33:15 +0000 Subject: [PATCH] Add better logging around long launcher operations during unfold This logging helps understanding what's going on in Launcher main thread during unfold from perfetto traces. Test: Perfetto trace after unfolding Bug: 292472402 Change-Id: I7a037d9a129deb4bfe4310fdba664b87164ef2ca --- .../launcher3/taskbar/TaskbarManager.java | 47 +++++++++++-------- src/com/android/launcher3/Launcher.java | 27 ++++++----- .../launcher3/ShortcutAndWidgetContainer.java | 3 ++ .../launcher3/model/BaseLauncherBinder.java | 18 ++++--- 4 files changed, 59 insertions(+), 36 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java index 1809d403d7..528cb309cf 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarManager.java @@ -40,6 +40,7 @@ import android.hardware.display.DisplayManager; import android.net.Uri; import android.os.Handler; import android.os.SystemProperties; +import android.os.Trace; import android.provider.Settings; import android.util.Log; import android.view.Display; @@ -180,6 +181,8 @@ public class TaskbarManager { @Override public void onConfigurationChanged(Configuration newConfig) { + Trace.instantForTrack(Trace.TRACE_TAG_APP, "TaskbarManager", + "onConfigurationChanged: " + newConfig); debugWhyTaskbarNotDestroyed( "TaskbarManager#mComponentCallbacks.onConfigurationChanged: " + newConfig); DeviceProfile dp = mUserUnlocked @@ -347,38 +350,44 @@ public class TaskbarManager { */ @VisibleForTesting public void recreateTaskbar() { - DeviceProfile dp = mUserUnlocked ? + Trace.beginSection("recreateTaskbar"); + try { + DeviceProfile dp = mUserUnlocked ? LauncherAppState.getIDP(mContext).getDeviceProfile(mContext) : null; - destroyExistingTaskbar(); + destroyExistingTaskbar(); - boolean isTaskbarEnabled = dp != null && isTaskbarPresent(dp); - debugWhyTaskbarNotDestroyed("recreateTaskbar: isTaskbarEnabled=" + 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) + if (!isTaskbarEnabled) { + SystemUiProxy.INSTANCE.get(mContext) .notifyTaskbarStatus(/* visible */ false, /* stashed */ false); - return; - } + return; + } - if (mTaskbarActivityContext == null) { - mTaskbarActivityContext = new TaskbarActivityContext(mContext, dp, mNavButtonController, + if (mTaskbarActivityContext == null) { + mTaskbarActivityContext = new TaskbarActivityContext(mContext, dp, + mNavButtonController, mUnfoldProgressProvider); - } else { - mTaskbarActivityContext.updateDeviceProfile(dp); - } - mTaskbarActivityContext.init(mSharedState); + } else { + mTaskbarActivityContext.updateDeviceProfile(dp); + } + mTaskbarActivityContext.init(mSharedState); - if (mActivity != null) { - mTaskbarActivityContext.setUIController( + if (mActivity != null) { + mTaskbarActivityContext.setUIController( createTaskbarUIControllerForActivity(mActivity)); - } + } - // We to wait until user unlocks the device to attach listener. - LauncherPrefs.get(mContext).addListener(mTaskbarPinningPreferenceChangeListener, + // We to wait until user unlocks the device to attach listener. + LauncherPrefs.get(mContext).addListener(mTaskbarPinningPreferenceChangeListener, TASKBAR_PINNING); + } finally { + Trace.endSection(); + } } public void onSystemUiFlagsChanged(int systemUiStateFlags) { diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 6df9aab273..e912fa9e62 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -725,18 +725,23 @@ public class Launcher extends StatefulActivity @Override protected void onHandleConfigurationChanged() { - if (!initDeviceProfile(mDeviceProfile.inv)) { - return; + Trace.beginSection("Launcher#onHandleconfigurationChanged"); + try { + if (!initDeviceProfile(mDeviceProfile.inv)) { + return; + } + + dispatchDeviceProfileChanged(); + reapplyUi(); + mDragLayer.recreateControllers(); + + // Calling onSaveInstanceState ensures that static cache used by listWidgets is + // initialized properly. + onSaveInstanceState(new Bundle()); + mModel.rebindCallbacks(); + } finally { + Trace.endSection(); } - - dispatchDeviceProfileChanged(); - reapplyUi(); - mDragLayer.recreateControllers(); - - // Calling onSaveInstanceState ensures that static cache used by listWidgets is - // initialized properly. - onSaveInstanceState(new Bundle()); - mModel.rebindCallbacks(); } public void onAssistantVisibilityChanged(float visibility) { diff --git a/src/com/android/launcher3/ShortcutAndWidgetContainer.java b/src/com/android/launcher3/ShortcutAndWidgetContainer.java index f921d1d8bf..07b71b32c1 100644 --- a/src/com/android/launcher3/ShortcutAndWidgetContainer.java +++ b/src/com/android/launcher3/ShortcutAndWidgetContainer.java @@ -28,6 +28,7 @@ import android.content.Context; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; +import android.os.Trace; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -182,6 +183,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { + Trace.beginSection("ShortcutAndWidgetConteiner#onLayout"); int count = getChildCount(); for (int i = 0; i < count; i++) { final View child = getChildAt(i); @@ -189,6 +191,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup implements FolderIcon. layoutChild(child); } } + Trace.endSection(); } /** diff --git a/src/com/android/launcher3/model/BaseLauncherBinder.java b/src/com/android/launcher3/model/BaseLauncherBinder.java index 556ac2603f..dbb29b8864 100644 --- a/src/com/android/launcher3/model/BaseLauncherBinder.java +++ b/src/com/android/launcher3/model/BaseLauncherBinder.java @@ -21,6 +21,7 @@ import static com.android.launcher3.model.ModelUtils.filterCurrentWorkspaceItems import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; import android.os.Process; +import android.os.Trace; import android.util.Log; import com.android.launcher3.InvariantDeviceProfile; @@ -83,13 +84,18 @@ public abstract class BaseLauncherBinder { * Binds all loaded data to actual views on the main thread. */ public void bindWorkspace(boolean incrementBindId, boolean isBindSync) { - if (FeatureFlags.ENABLE_WORKSPACE_LOADING_OPTIMIZATION.get()) { - DisjointWorkspaceBinder workspaceBinder = + Trace.beginSection("BaseLauncherBinder#bindWorkspace"); + try { + if (FeatureFlags.ENABLE_WORKSPACE_LOADING_OPTIMIZATION.get()) { + DisjointWorkspaceBinder workspaceBinder = initWorkspaceBinder(incrementBindId, mBgDataModel.collectWorkspaceScreens()); - workspaceBinder.bindCurrentWorkspacePages(isBindSync); - workspaceBinder.bindOtherWorkspacePages(); - } else { - bindWorkspaceAllAtOnce(incrementBindId, isBindSync); + workspaceBinder.bindCurrentWorkspacePages(isBindSync); + workspaceBinder.bindOtherWorkspacePages(); + } else { + bindWorkspaceAllAtOnce(incrementBindId, isBindSync); + } + } finally { + Trace.endSection(); } }