From cb7bd50247beae0c8298bfe01330b46589c5e354 Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Mon, 16 Jan 2023 19:46:30 +0000 Subject: [PATCH 1/2] Log device profile changes in perfetto traces This is needed to easily spot unwanted DeviceProfile changes in perfetto traces, as each one causes many new inflation and slows down the ui thread considerably. Test: recorded trace with this log Bug: 258214245 Change-Id: I805d56d4dfe1c08d7f28215c0462d01fcaece84e --- .../launcher3/taskbar/TaskbarActivityContext.java | 9 +++++++++ .../launcher3/uioverrides/QuickstepLauncher.java | 9 +++++++++ .../src/com/android/quickstep/RecentsActivity.java | 9 +++++++++ src/com/android/launcher3/DeviceProfile.java | 10 ++++++++++ 4 files changed, 37 insertions(+) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 4e795d9090..6caa904071 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -16,6 +16,7 @@ package com.android.launcher3.taskbar; import static android.content.pm.PackageManager.FEATURE_PC; +import static android.os.Trace.TRACE_TAG_APP; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; @@ -46,6 +47,7 @@ import android.graphics.PixelFormat; import android.graphics.Rect; import android.os.Process; import android.os.SystemProperties; +import android.os.Trace; import android.provider.Settings; import android.util.Log; import android.view.Display; @@ -266,6 +268,13 @@ public class TaskbarActivityContext extends BaseTaskbarContext { dispatchDeviceProfileChanged(); } + @Override + public void dispatchDeviceProfileChanged() { + super.dispatchDeviceProfileChanged(); + Trace.instantForTrack(TRACE_TAG_APP, "TaskbarActivityContext#DeviceProfileChanged", + getDeviceProfile().toSmallString()); + } + /** * Copy the original DeviceProfile, match the number of hotseat icons and qsb width and update * the icon size diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index a7651b6a06..0114457909 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -15,6 +15,7 @@ */ package com.android.launcher3.uioverrides; +import static android.os.Trace.TRACE_TAG_APP; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; @@ -62,6 +63,7 @@ import android.os.Bundle; import android.os.CancellationSignal; import android.os.IBinder; import android.os.SystemProperties; +import android.os.Trace; import android.view.Display; import android.view.HapticFeedbackConstants; import android.view.RemoteAnimationTarget; @@ -1036,6 +1038,13 @@ public class QuickstepLauncher extends Launcher { return false; } + @Override + public void dispatchDeviceProfileChanged() { + super.dispatchDeviceProfileChanged(); + Trace.instantForTrack(TRACE_TAG_APP, "QuickstepLauncher#DeviceProfileChanged", + getDeviceProfile().toSmallString()); + } + private static final class LauncherTaskViewController extends TaskViewTouchController { diff --git a/quickstep/src/com/android/quickstep/RecentsActivity.java b/quickstep/src/com/android/quickstep/RecentsActivity.java index 6f86bf5de6..f26189ce57 100644 --- a/quickstep/src/com/android/quickstep/RecentsActivity.java +++ b/quickstep/src/com/android/quickstep/RecentsActivity.java @@ -15,6 +15,7 @@ */ package com.android.quickstep; +import static android.os.Trace.TRACE_TAG_APP; import static android.view.RemoteAnimationTarget.MODE_CLOSING; import static android.view.RemoteAnimationTarget.MODE_OPENING; @@ -36,6 +37,7 @@ import android.content.res.Configuration; import android.os.Bundle; import android.os.Handler; import android.os.Looper; +import android.os.Trace; import android.view.Display; import android.view.RemoteAnimationAdapter; import android.view.RemoteAnimationTarget; @@ -448,6 +450,13 @@ public final class RecentsActivity extends StatefulActivity { return new RecentsAtomicAnimationFactory<>(this); } + @Override + public void dispatchDeviceProfileChanged() { + super.dispatchDeviceProfileChanged(); + Trace.instantForTrack(TRACE_TAG_APP, "RecentsActivity#DeviceProfileChanged", + getDeviceProfile().toSmallString()); + } + private AnimatorListenerAdapter resetStateListener() { return new AnimatorListenerAdapter() { @Override diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index f124940e3d..e4f3614ccd 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -1679,6 +1679,16 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("getCellLayoutWidth()", getCellLayoutWidth())); } + /** Returns a reduced representation of this DeviceProfile. */ + public String toSmallString() { + return "isTablet:" + isTablet + ", " + + "isMultiDisplay:" + isMultiDisplay + ", " + + "widthPx:" + widthPx + ", " + + "heightPx:" + heightPx + ", " + + "insets:" + mInsets + ", " + + "rotationHint:" + rotationHint; + } + private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) { Configuration config = new Configuration(c.getResources().getConfiguration()); config.orientation = orientation; From 62fe4445c79c70bb4f62d3740229ad041b2558b9 Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Wed, 18 Jan 2023 17:20:03 +0000 Subject: [PATCH 2/2] Add OPTIMIZE_MEASURE flag to QuickSteplauncher window This flag allows to avoid an initial measure pass by getting the window size by the LayoutParams. Test: Recorded a trace before and after this change and compared the doFrames Bug: 265150323 Change-Id: I2c1e440b73437df9f328d64c98d160bed11282f3 --- .../com/android/launcher3/uioverrides/QuickstepLauncher.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java index 0114457909..078865fd02 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/uioverrides/QuickstepLauncher.java @@ -16,6 +16,7 @@ package com.android.launcher3.uioverrides; import static android.os.Trace.TRACE_TAG_APP; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_OPTIMIZE_MEASURE; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_FOCUSED; import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; @@ -543,6 +544,7 @@ public class QuickstepLauncher extends Launcher { if (FeatureFlags.CONTINUOUS_VIEW_TREE_CAPTURE.get()) { mViewCapture = ViewCapture.getInstance().startCapture(getWindow()); } + getWindow().addPrivateFlags(PRIVATE_FLAG_OPTIMIZE_MEASURE); } @Override