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

Commit e18a6a6f authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov Committed by Automerger Merge Worker
Browse files

Disable auto screen-offs for DocumentsUITests am: 918753f9

parents 2e5fe48c 918753f9
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;
@@ -42,6 +44,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;

/**
@@ -78,6 +82,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);
    }
@@ -129,6 +136,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();
@@ -148,6 +158,7 @@ public abstract class ActivityTest<T extends Activity> extends ActivityInstrumen
    public void tearDown() throws Exception {
        device.unfreezeRotation();
        mDocsHelper.cleanUp();
        restoreScreenOffAndSleepTimeouts();
        super.tearDown();
    }

@@ -211,4 +222,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;
        }
    }
}