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

Commit 1e16b3c2 authored by Lucas Silva's avatar Lucas Silva
Browse files

Don't start dreams immediately if keyguard is occluded when docked.

The keyguard must be showing and unoccluded, or the device is not
interactive (eg screen off) in order for dreams to be started
immediately when docked. This prevents dreams from starting if there is
an activity currently showing over the lockscreen.

Also includes some refactoring to be able to unit test this change,
since dock state changes were not previously tested.

Fixes: 233412496
Test: atest UiModeManagerServiceTest
Test: manually on device with keyguard occluded, unoccluded, and screen
off while docked

Change-Id: I12f1a4cf3ae4784e391e3c5a3fd1d50b4d4f7ecd
parent d8dac1f6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -45,6 +45,12 @@ public abstract class DreamManagerInternal {
     */
    public abstract boolean isDreaming();

    /**
     * Ask the power manager to nap.  It will eventually call back into startDream() if/when it is
     * appropriate to start dreaming.
     */
    public abstract void requestDream();

    /**
     * Called by the ActivityTaskManagerService to verify that the startDreamActivity
     * request comes from the current active dream component.
+22 −26
Original line number Diff line number Diff line
@@ -20,13 +20,13 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.Slog;

import com.android.server.LocalServices;

/**
 * Internal helper for launching dreams to ensure consistency between the
 * <code>UiModeManagerService</code> system service and the <code>Somnambulator</code> activity.
@@ -75,9 +75,8 @@ public final class Sandman {
    }

    private static void startDream(Context context, boolean docked) {
        try {
            IDreamManager dreamManagerService = IDreamManager.Stub.asInterface(
                    ServiceManager.getService(DreamService.DREAM_SERVICE));
        DreamManagerInternal dreamManagerService =
                LocalServices.getService(DreamManagerInternal.class);
        if (dreamManagerService != null && !dreamManagerService.isDreaming()) {
            if (docked) {
                Slog.i(TAG, "Activating dream while docked.");
@@ -97,10 +96,7 @@ public final class Sandman {
            }

            // Dream.
                dreamManagerService.dream();
            }
        } catch (RemoteException ex) {
            Slog.e(TAG, "Could not start dream when docked.", ex);
            dreamManagerService.requestDream();
        }
    }

+7 −1
Original line number Diff line number Diff line
@@ -359,6 +359,11 @@ final class UiModeManagerService extends SystemService {
        SystemProperties.set(SYSTEM_PROPERTY_DEVICE_THEME, Integer.toString(mode));
    }

    @VisibleForTesting
    void setStartDreamImmediatelyOnDock(boolean startDreamImmediatelyOnDock) {
        mStartDreamImmediatelyOnDock = startDreamImmediatelyOnDock;
    }

    @Override
    public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) {
        mCurrentUser = to.getUserIdentifier();
@@ -1824,7 +1829,8 @@ final class UiModeManagerService extends SystemService {

        // If we did not start a dock app, then start dreaming if appropriate.
        if (category != null && !dockAppStarted && (mStartDreamImmediatelyOnDock
                || mKeyguardManager.isKeyguardLocked())) {
                || mWindowManager.isKeyguardShowingAndNotOccluded()
                || !mPowerManager.isInteractive())) {
            Sandman.startDreamWhenDockedIfAppropriate(getContext());
        }
    }
+5 −0
Original line number Diff line number Diff line
@@ -842,6 +842,11 @@ public final class DreamManagerService extends SystemService {
        public ComponentName getActiveDreamComponent(boolean doze) {
            return getActiveDreamComponentInternal(doze);
        }

        @Override
        public void requestDream() {
            requestDreamInternal();
        }
    }

    private final Runnable mSystemPropertiesChanged = new Runnable() {
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ android_test {
    ],

    static_libs: [
        "frameworks-base-testutils",
        "services.accessibility",
        "services.core",
        "services.devicepolicy",
@@ -32,6 +33,7 @@ android_test {
        "platformprotosnano",
        "statsdprotolite",
        "hamcrest-library",
        "servicestests-utils",
        "testables",
        "truth-prebuilt",
        // TODO: remove once Android migrates to JUnit 4.12,
Loading