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

Commit c45e60c5 authored by Bryce Lee's avatar Bryce Lee
Browse files

Send dream state updates through DreamManagerStateListener.

This changelist extends DreamManagerStateListener to also send updates
about the dream state, including when the dream started and stopped.
This allows system server components to receive state updates without
needed to listen to the dream state broadcasts.

Test: atest DreamControllerTest#startDream_dreamListenerNotified
Test: atest DreamControllerTest#stopDream_dreamListenerNotified
Bug: 275108597
Change-Id: Ifb1e1266b938d50e0744aa106557c8c7db52f442
parent 4a88a91a
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -84,6 +84,19 @@ public abstract class DreamManagerInternal {
         *
         * @param keepDreaming True if the current dream should continue when undocking.
         */
        void onKeepDreamingWhenUnpluggingChanged(boolean keepDreaming);
        default void onKeepDreamingWhenUnpluggingChanged(boolean keepDreaming) {
        }

        /**
         * Called when dreaming has started.
         */
        default void onDreamingStarted() {
        }

        /**
         * Called when dreaming has stopped.
         */
        default void onDreamingStopped() {
        }
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -345,6 +345,7 @@ final class DreamController {
        if (!mCurrentDream.mIsPreviewMode && !mSentStartBroadcast) {
            mContext.sendBroadcastAsUser(mDreamingStartedIntent, UserHandle.ALL,
                    null /* receiverPermission */, mDreamingStartedStoppedOptions);
            mListener.onDreamStarted(mCurrentDream.mToken);
            mSentStartBroadcast = true;
        }
    }
@@ -353,6 +354,7 @@ final class DreamController {
     * Callback interface to be implemented by the {@link DreamManagerService}.
     */
    public interface Listener {
        void onDreamStarted(Binder token);
        void onDreamStopped(Binder token);
    }

+27 −1
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Consumer;

/**
 * Service api for managing dreams.
@@ -341,10 +342,24 @@ public final class DreamManagerService extends SystemService {
    }

    private void reportKeepDreamingWhenUnpluggingChanged(boolean keepDreaming) {
        notifyDreamStateListeners(
                listener -> listener.onKeepDreamingWhenUnpluggingChanged(keepDreaming));
    }

    private void reportDreamingStarted() {
        notifyDreamStateListeners(listener -> listener.onDreamingStarted());
    }

    private void reportDreamingStopped() {
        notifyDreamStateListeners(listener -> listener.onDreamingStopped());
    }

    private void notifyDreamStateListeners(
            Consumer<DreamManagerInternal.DreamManagerStateListener> notifier) {
        mHandler.post(() -> {
            for (DreamManagerInternal.DreamManagerStateListener listener
                    : mDreamManagerStateListeners) {
                listener.onKeepDreamingWhenUnpluggingChanged(keepDreaming);
                notifier.accept(listener);
            }
        });
    }
@@ -766,6 +781,15 @@ public final class DreamManagerService extends SystemService {
    }

    private final DreamController.Listener mControllerListener = new DreamController.Listener() {
        @Override
        public void onDreamStarted(Binder token) {
            // Note that this event is distinct from DreamManagerService#startDreamLocked as it
            // tracks the DreamService attach point from DreamController, closest to the broadcast
            // of ACTION_DREAMING_STARTED.

            reportDreamingStarted();
        }

        @Override
        public void onDreamStopped(Binder token) {
            synchronized (mLock) {
@@ -773,6 +797,8 @@ public final class DreamManagerService extends SystemService {
                    cleanupDreamLocked();
                }
            }

            reportDreamingStopped();
        }
    };

+0 −21
Original line number Diff line number Diff line
@@ -2186,12 +2186,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
                    Intent.EXTRA_DOCK_STATE_UNDOCKED));
        }

        // register for dream-related broadcasts
        filter = new IntentFilter();
        filter.addAction(Intent.ACTION_DREAMING_STARTED);
        filter.addAction(Intent.ACTION_DREAMING_STOPPED);
        mContext.registerReceiver(mDreamReceiver, filter);

        // register for multiuser-relevant broadcasts
        filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
        mContext.registerReceiver(mMultiuserReceiver, filter);
@@ -4774,21 +4768,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    };

    BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
                if (mKeyguardDelegate != null) {
                    mKeyguardDelegate.onDreamingStarted();
                }
            } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
                if (mKeyguardDelegate != null) {
                    mKeyguardDelegate.onDreamingStopped();
                }
            }
        }
    };

    BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
+20 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.os.IBinder;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.UserHandle;
import android.service.dreams.DreamManagerInternal;
import android.util.Log;
import android.util.Slog;
import android.util.proto.ProtoOutputStream;
@@ -27,6 +28,7 @@ import com.android.internal.policy.IKeyguardDismissCallback;
import com.android.internal.policy.IKeyguardDrawnCallback;
import com.android.internal.policy.IKeyguardExitCallback;
import com.android.internal.policy.IKeyguardService;
import com.android.server.LocalServices;
import com.android.server.UiThread;
import com.android.server.policy.WindowManagerPolicy.OnKeyguardExitResult;
import com.android.server.wm.EventLogTags;
@@ -60,6 +62,19 @@ public class KeyguardServiceDelegate {

    private DrawnListener mDrawnListenerWhenConnect;

    private final DreamManagerInternal.DreamManagerStateListener mDreamManagerStateListener =
            new DreamManagerInternal.DreamManagerStateListener() {
                @Override
                public void onDreamingStarted() {
                    KeyguardServiceDelegate.this.onDreamingStarted();
                }

                @Override
                public void onDreamingStopped() {
                    KeyguardServiceDelegate.this.onDreamingStopped();
                }
            };

    private static final class KeyguardState {
        KeyguardState() {
            reset();
@@ -158,6 +173,11 @@ public class KeyguardServiceDelegate {
        } else {
            if (DEBUG) Log.v(TAG, "*** Keyguard started");
        }

        final DreamManagerInternal dreamManager =
                LocalServices.getService(DreamManagerInternal.class);

        dreamManager.registerDreamManagerStateListener(mDreamManagerStateListener);
    }

    private final ServiceConnection mKeyguardConnection = new ServiceConnection() {
Loading