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

Commit ee4e1c14 authored by Vladimir Komsiyski's avatar Vladimir Komsiyski
Browse files

Check isDeviceLocked instead of isKeyguardLocked

when creating ComputerControlSession

Bug: 437903965
Fix: 437903965
Test: presubmit
Flag: android.companion.virtualdevice.flags.computer_control_access
Change-Id: Ic7cfbd0605b14f0d3aabcb2ffa67cd84aea22041
parent 81dbf32b
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -71,14 +71,14 @@ public final class ComputerControlSession implements AutoCloseable {
    public static final int ERROR_SESSION_LIMIT_REACHED = 1;

    /**
     * Error code indicating that a new session cannot be created because the lock screen (also
     * known as Keyguard) is showing.
     * Error code indicating that a new session cannot be created because the device is currently
     * locked.
     *
     * <p>This is a transient error and the session creation request can be retried later.</p>
     *
     * @see android.app.KeyguardManager#isKeyguardLocked()
     * @see android.app.KeyguardManager#isDeviceLocked()
     */
    public static final int ERROR_KEYGUARD_LOCKED = 2;
    public static final int ERROR_DEVICE_LOCKED = 2;

    /**
     * Error code indicating that the user did not approve the creation of a new session.
@@ -89,7 +89,7 @@ public final class ComputerControlSession implements AutoCloseable {
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = "ERROR_", value = {
            ERROR_SESSION_LIMIT_REACHED,
            ERROR_KEYGUARD_LOCKED,
            ERROR_DEVICE_LOCKED,
            ERROR_PERMISSION_DENIED})
    @Target({ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})
    public @interface SessionCreationError {
+2 −2
Original line number Diff line number Diff line
@@ -197,9 +197,9 @@ public class ComputerControlSessionProcessor {
    private boolean checkSessionCreationPreconditionsLocked(
            @NonNull ComputerControlSessionParams params,
            @NonNull IComputerControlSessionCallback callback) {
        if (mKeyguardManager.isKeyguardLocked()) {
        if (mKeyguardManager.isDeviceLocked()) {
            dispatchSessionCreationFailed(callback, params,
                    ComputerControlSession.ERROR_KEYGUARD_LOCKED);
                    ComputerControlSession.ERROR_DEVICE_LOCKED);
            return false;
        }
        if (mSessions.size() >= MAXIMUM_CONCURRENT_SESSIONS) {
+2 −2
Original line number Diff line number Diff line
@@ -133,12 +133,12 @@ public class ComputerControlSessionProcessorTest {

    @Test
    public void keyguardLocked_sessionNotCreated() throws Exception {
        when(mKeyguardManager.isKeyguardLocked()).thenReturn(true);
        when(mKeyguardManager.isDeviceLocked()).thenReturn(true);

        mProcessor.processNewSessionRequest(AttributionSource.myAttributionSource(),
                mParams, mComputerControlSessionCallback);
        verify(mComputerControlSessionCallback, timeout(CALLBACK_TIMEOUT_MS))
                .onSessionCreationFailed(ComputerControlSession.ERROR_KEYGUARD_LOCKED);
                .onSessionCreationFailed(ComputerControlSession.ERROR_DEVICE_LOCKED);
    }

    @Test