From 64d8bcc891df1a72269b7a6f637e553589c6d8ad Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Thu, 6 Feb 2020 21:39:27 +0800 Subject: Reduce unnecessary object creation in relayout test Also change to use STAY_ON_WHILE_PLUGGED_IN for keeping device awake. That eliminates the toggle of wakelock by showing and hiding a window with FLAG_KEEP_SCREEN_ON. Test: atest RelayoutPerfTest InternalWindowOperationPerfTest Bug: 131727899 Change-Id: Ib4608aa1a60c7560b39011cfd2e4740680b3c884 --- .../core/src/android/wm/RelayoutPerfTest.java | 5 ++++- .../src/android/wm/WindowManagerPerfTestBase.java | 26 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'apct-tests') diff --git a/apct-tests/perftests/core/src/android/wm/RelayoutPerfTest.java b/apct-tests/perftests/core/src/android/wm/RelayoutPerfTest.java index b6e39e14602a..8633c9613138 100644 --- a/apct-tests/perftests/core/src/android/wm/RelayoutPerfTest.java +++ b/apct-tests/perftests/core/src/android/wm/RelayoutPerfTest.java @@ -125,7 +125,9 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase { final WindowManager.LayoutParams mParams; final int mWidth; final int mHeight; + final Point mOutSurfaceSize = new Point(); final SurfaceControl mOutSurfaceControl; + final SurfaceControl mOutBlastSurfaceControl = new SurfaceControl(); final IntSupplier mViewVisibility; @@ -150,7 +152,8 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase { mViewVisibility.getAsInt(), mFlags, mFrameNumber, mOutFrame, mOutContentInsets, mOutVisibleInsets, mOutStableInsets, mOutBackDropFrame, mOutDisplayCutout, mOutMergedConfiguration, - mOutSurfaceControl, mOutInsetsState, new Point(), new SurfaceControl()); + mOutSurfaceControl, mOutInsetsState, mOutSurfaceSize, + mOutBlastSurfaceControl); } } } diff --git a/apct-tests/perftests/core/src/android/wm/WindowManagerPerfTestBase.java b/apct-tests/perftests/core/src/android/wm/WindowManagerPerfTestBase.java index 62e9ba84530c..9e17e940a06b 100644 --- a/apct-tests/perftests/core/src/android/wm/WindowManagerPerfTestBase.java +++ b/apct-tests/perftests/core/src/android/wm/WindowManagerPerfTestBase.java @@ -20,15 +20,19 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat import android.app.Activity; import android.app.UiAutomation; +import android.content.Context; import android.content.Intent; +import android.os.BatteryManager; import android.os.ParcelFileDescriptor; import android.perftests.utils.PerfTestActivity; +import android.provider.Settings; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.lifecycle.ActivityLifecycleCallback; import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; import androidx.test.runner.lifecycle.Stage; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.Description; import org.junit.runners.model.Statement; @@ -52,18 +56,36 @@ public class WindowManagerPerfTestBase { */ static final File BASE_OUT_PATH = new File("/data/local/CorePerfTests"); + private static int sOriginalStayOnWhilePluggedIn; + @BeforeClass public static void setUpOnce() { + final Context context = getInstrumentation().getContext(); + sOriginalStayOnWhilePluggedIn = Settings.Global.getInt(context.getContentResolver(), + Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); + // Keep the device awake during testing. + setStayOnWhilePluggedIn(BatteryManager.BATTERY_PLUGGED_USB); + if (!BASE_OUT_PATH.exists()) { executeShellCommand("mkdir -p " + BASE_OUT_PATH); } // In order to be closer to the real use case. executeShellCommand("input keyevent KEYCODE_WAKEUP"); executeShellCommand("wm dismiss-keyguard"); - getInstrumentation().getContext().startActivity(new Intent(Intent.ACTION_MAIN) + context.startActivity(new Intent(Intent.ACTION_MAIN) .addCategory(Intent.CATEGORY_HOME).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } + @AfterClass + public static void tearDownOnce() { + setStayOnWhilePluggedIn(sOriginalStayOnWhilePluggedIn); + } + + private static void setStayOnWhilePluggedIn(int value) { + executeShellCommand(String.format("settings put global %s %d", + Settings.Global.STAY_ON_WHILE_PLUGGED_IN, value)); + } + /** * Executes shell command with reading the output. It may also used to block until the current * command is completed. @@ -97,7 +119,7 @@ public class WindowManagerPerfTestBase { */ static class PerfTestActivityRule extends ActivityTestRule { private final Intent mStartIntent = - new Intent().putExtra(PerfTestActivity.INTENT_EXTRA_KEEP_SCREEN_ON, true); + new Intent(getInstrumentation().getTargetContext(), PerfTestActivity.class); private final LifecycleListener mLifecycleListener = new LifecycleListener(); PerfTestActivityRule() { -- cgit v1.2.3