Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64d8bcc8 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

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
parent 5f87e0df
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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);
            }
        }
    }
+24 −2
Original line number Diff line number Diff line
@@ -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<PerfTestActivity> {
        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() {