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

Commit 131f36e4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Avoid unexpected screen off during perf testing" into rvc-dev am:...

Merge "Avoid unexpected screen off during perf testing" into rvc-dev am: 92b6167f am: 6474cf02 am: b2a46806

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11836347

Change-Id: I15fe73ad69bde7c9820dec2d2716198fbf79417d
parents 00767ed8 b2a46806
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentat
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.Is.is;


import android.app.ActivityManager;
import android.app.ActivityManager.TaskSnapshot;
import android.app.ActivityManager.TaskSnapshot;
import android.app.ActivityTaskManager;
import android.app.ActivityTaskManager;
import android.app.IActivityTaskManager;
import android.app.IActivityTaskManager;
@@ -121,6 +122,12 @@ public class RecentsAnimationPerfTest extends WindowManagerPerfTestBase {
    @AfterClass
    @AfterClass
    public static void tearDownClass() {
    public static void tearDownClass() {
        sSetUpClassException = null;
        sSetUpClassException = null;
        try {
            // Recents activity may stop app switches. Restore the state to avoid affecting
            // the next test.
            ActivityManager.resumeAppSwitches();
        } catch (RemoteException ignored) {
        }
        sUiAutomation.dropShellPermissionIdentity();
        sUiAutomation.dropShellPermissionIdentity();
    }
    }


+1 −4
Original line number Original line Diff line number Diff line
@@ -88,10 +88,7 @@ public class RelayoutPerfTest extends WindowManagerPerfTestBase {
    public void testRelayout() throws Throwable {
    public void testRelayout() throws Throwable {
        final Activity activity = mActivityRule.getActivity();
        final Activity activity = mActivityRule.getActivity();
        final ContentView contentView = new ContentView(activity);
        final ContentView contentView = new ContentView(activity);
        mActivityRule.runOnUiThread(() -> {
        mActivityRule.runOnUiThread(() -> activity.setContentView(contentView));
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            activity.setContentView(contentView);
        });
        getInstrumentation().waitForIdleSync();
        getInstrumentation().waitForIdleSync();


        final RelayoutRunner relayoutRunner = new RelayoutRunner(activity, contentView.getWindow(),
        final RelayoutRunner relayoutRunner = new RelayoutRunner(activity, contentView.getWindow(),
+17 −7
Original line number Original line Diff line number Diff line
@@ -19,11 +19,13 @@ package android.wm;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;


import android.app.Activity;
import android.app.Activity;
import android.app.KeyguardManager;
import android.app.UiAutomation;
import android.app.UiAutomation;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.os.BatteryManager;
import android.os.BatteryManager;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.PowerManager;
import android.perftests.utils.PerfTestActivity;
import android.perftests.utils.PerfTestActivity;
import android.provider.Settings;
import android.provider.Settings;


@@ -61,25 +63,33 @@ public class WindowManagerPerfTestBase {
    @BeforeClass
    @BeforeClass
    public static void setUpOnce() {
    public static void setUpOnce() {
        final Context context = getInstrumentation().getContext();
        final Context context = getInstrumentation().getContext();
        sOriginalStayOnWhilePluggedIn = Settings.Global.getInt(context.getContentResolver(),
        final int stayOnWhilePluggedIn = Settings.Global.getInt(context.getContentResolver(),
                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0);
                Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0);
        sOriginalStayOnWhilePluggedIn = -1;
        if (stayOnWhilePluggedIn != BatteryManager.BATTERY_PLUGGED_ANY) {
            sOriginalStayOnWhilePluggedIn = stayOnWhilePluggedIn;
            // Keep the device awake during testing.
            // Keep the device awake during testing.
        setStayOnWhilePluggedIn(BatteryManager.BATTERY_PLUGGED_USB);
            setStayOnWhilePluggedIn(BatteryManager.BATTERY_PLUGGED_ANY);
        }


        if (!BASE_OUT_PATH.exists()) {
        if (!BASE_OUT_PATH.exists()) {
            executeShellCommand("mkdir -p " + BASE_OUT_PATH);
            executeShellCommand("mkdir -p " + BASE_OUT_PATH);
        }
        }
        // In order to be closer to the real use case.
        if (!context.getSystemService(PowerManager.class).isInteractive()
                || context.getSystemService(KeyguardManager.class).isKeyguardLocked()) {
            executeShellCommand("input keyevent KEYCODE_WAKEUP");
            executeShellCommand("input keyevent KEYCODE_WAKEUP");
            executeShellCommand("wm dismiss-keyguard");
            executeShellCommand("wm dismiss-keyguard");
        }
        context.startActivity(new Intent(Intent.ACTION_MAIN)
        context.startActivity(new Intent(Intent.ACTION_MAIN)
                .addCategory(Intent.CATEGORY_HOME).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
                .addCategory(Intent.CATEGORY_HOME).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    }
    }


    @AfterClass
    @AfterClass
    public static void tearDownOnce() {
    public static void tearDownOnce() {
        if (sOriginalStayOnWhilePluggedIn != -1) {
            setStayOnWhilePluggedIn(sOriginalStayOnWhilePluggedIn);
            setStayOnWhilePluggedIn(sOriginalStayOnWhilePluggedIn);
        }
        }
    }


    private static void setStayOnWhilePluggedIn(int value) {
    private static void setStayOnWhilePluggedIn(int value) {
        executeShellCommand(String.format("settings put global %s %d",
        executeShellCommand(String.format("settings put global %s %d",