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

Commit 918753f9 authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov
Browse files

Disable auto screen-offs for DocumentsUITests

Make sure to disable screen off and sleep timeout, as well as the
lockscreen, when running DocumentsUITests.

Bug: 259640894
Test: atest DocumentsUIGoogleTests
Change-Id: I64009a6fa40e5ddbe9814bd994690ef576b44245
parent 070e1454
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,14 @@
        <option name="test-file-name" value="DocumentsUITests.apk" />
    </target_preparer>

    <target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
        <!-- Disable keyguard -->
        <!-- Though keyguard is disabled globally in cts-preconditions.xml, this will ensure that
             the test gets the same treatment when running in other test suites (e.g. MTS), as well
             as when running locally (e.g. via atest)  -->
        <option name="run-command" value="locksettings set-disabled true" />
    </target_preparer>

    <option name="test-suite-tag" value="apct" />
    <option name="test-tag" value="DocumentsUITests" />
    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+34 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui;

import static java.util.Objects.requireNonNull;

import android.app.Activity;
import android.app.UiAutomation;
import android.app.UiModeManager;
@@ -41,6 +43,8 @@ import com.android.documentsui.base.UserId;
import com.android.documentsui.bots.Bots;
import com.android.documentsui.files.FilesActivity;

import java.io.IOException;

import javax.annotation.Nullable;

/**
@@ -77,6 +81,9 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
    protected ContentProviderClient mClient;
    protected UiModeManager mUiModeManager;

    private String initialScreenOffTimeoutValue = null;
    private String initialSleepTimeoutValue = null;

    public ActivityTest(Class<T> activityClass) {
        super(activityClass);
    }
@@ -128,6 +135,9 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
        device.setOrientationNatural();
        device.pressKeyCode(KeyEvent.KEYCODE_WAKEUP);
        device.pressKeyCode(KeyEvent.KEYCODE_MENU);

        disableScreenOffAndSleepTimeouts();

        setupTestingRoots();

        launchActivity();
@@ -147,6 +157,7 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
    public void tearDown() throws Exception {
        device.unfreezeRotation();
        mDocsHelper.cleanUp();
        restoreScreenOffAndSleepTimeouts();
        super.tearDown();
    }

@@ -210,4 +221,27 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
            device.waitForIdle(NIGHT_MODE_CHANGE_WAIT_TIME);
        }
    }

    private void disableScreenOffAndSleepTimeouts() throws IOException {
        initialScreenOffTimeoutValue = device.executeShellCommand(
                "settings get system screen_off_timeout");
        initialSleepTimeoutValue = device.executeShellCommand(
                "settings get secure sleep_timeout");
        device.executeShellCommand("settings put system screen_off_timeout -1");
        device.executeShellCommand("settings put secure sleep_timeout -1");
    }

    private void restoreScreenOffAndSleepTimeouts() throws IOException {
        requireNonNull(initialScreenOffTimeoutValue);
        requireNonNull(initialSleepTimeoutValue);
        try {
            device.executeShellCommand(
                    "settings put system screen_off_timeout " + initialScreenOffTimeoutValue);
            device.executeShellCommand(
                    "settings put secure sleep_timeout " + initialSleepTimeoutValue);
        } finally {
            initialScreenOffTimeoutValue = null;
            initialSleepTimeoutValue = null;
        }
    }
}