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

Commit a9868f63 authored by Nick Chameyev's avatar Nick Chameyev Committed by Android (Google) Code Review
Browse files

Merge "Synchronize device state update and display update callbacks" into udc-dev

parents 44a8b4dc b2c876b5
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -238,6 +238,7 @@ public final class DisplayManagerService extends SystemService {
    private static final int MSG_LOAD_BRIGHTNESS_CONFIGURATIONS = 6;
    private static final int MSG_DELIVER_DISPLAY_EVENT_FRAME_RATE_OVERRIDE = 7;
    private static final int MSG_DELIVER_DISPLAY_GROUP_EVENT = 8;
    private static final int MSG_RECEIVED_DEVICE_STATE = 9;
    private static final int[] EMPTY_ARRAY = new int[0];
    private static final HdrConversionMode HDR_CONVERSION_MODE_UNSUPPORTED = new HdrConversionMode(
            HDR_CONVERSION_UNSUPPORTED);
@@ -3213,6 +3214,10 @@ public final class DisplayManagerService extends SystemService {
                    mWindowManagerInternal.requestTraversalFromDisplayManager();
                    break;

                case MSG_RECEIVED_DEVICE_STATE:
                    mWindowManagerInternal.onDisplayManagerReceivedDeviceState(msg.arg1);
                    break;

                case MSG_UPDATE_VIEWPORT: {
                    final boolean changed;
                    synchronized (mSyncRoot) {
@@ -4680,6 +4685,14 @@ public final class DisplayManagerService extends SystemService {
        public void onStateChanged(int deviceState) {
            boolean isDeviceStateOverrideActive = deviceState != mBaseState;
            synchronized (mSyncRoot) {
                // Notify WindowManager that we are about to handle new device state, this should
                // be sent before any work related to the device state in DisplayManager, so
                // WindowManager could do implement that depends on the device state and display
                // changes (serializes device state update and display change events)
                Message msg = mHandler.obtainMessage(MSG_RECEIVED_DEVICE_STATE);
                msg.arg1 = deviceState;
                mHandler.sendMessage(msg);

                mLogicalDisplayMapper
                        .setDeviceStateLocked(deviceState, isDeviceStateOverrideActive);
            }
+16 −16
Original line number Diff line number Diff line
@@ -19,9 +19,6 @@ package com.android.server.wm;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.content.Context;
import android.hardware.devicestate.DeviceStateManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.util.ArrayMap;

import com.android.internal.R;
@@ -36,17 +33,15 @@ import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Class that registers callbacks with the {@link DeviceStateManager} and responds to device
 * Class that listens for a callback from display manager and responds to device state
 * changes.
 */
final class DeviceStateController implements DeviceStateManager.DeviceStateCallback {
final class DeviceStateController {

    // Used to synchronize WindowManager services call paths with DeviceStateManager's callbacks.
    @NonNull
    private final WindowManagerGlobalLock mWmLock;
    @NonNull
    private final DeviceStateManager mDeviceStateManager;
    @NonNull
    private final int[] mOpenDeviceStates;
    @NonNull
    private final int[] mHalfFoldedDeviceStates;
@@ -77,10 +72,8 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
        CONCURRENT,
    }

    DeviceStateController(@NonNull Context context, @NonNull Handler handler,
            @NonNull WindowManagerGlobalLock wmLock) {
    DeviceStateController(@NonNull Context context, @NonNull WindowManagerGlobalLock wmLock) {
        mWmLock = wmLock;
        mDeviceStateManager = context.getSystemService(DeviceStateManager.class);

        mOpenDeviceStates = context.getResources()
                .getIntArray(R.array.config_openDeviceStates);
@@ -97,10 +90,6 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
        mMatchBuiltInDisplayOrientationToDefaultDisplay = context.getResources()
                .getBoolean(R.bool
                        .config_matchSecondaryInternalDisplaysOrientationToReverseDefaultDisplay);

        if (mDeviceStateManager != null) {
            mDeviceStateManager.registerCallback(new HandlerExecutor(handler), this);
        }
    }

    /**
@@ -137,8 +126,19 @@ final class DeviceStateController implements DeviceStateManager.DeviceStateCallb
        return mMatchBuiltInDisplayOrientationToDefaultDisplay;
    }

    @Override
    public void onStateChanged(int state) {
    /**
     * This event is sent from DisplayManager just before the device state is applied to
     * the displays. This is needed to make sure that we first receive this callback before
     * any device state related display updates from the DisplayManager.
     *
     * The flow for this event is the following:
     *  - {@link DeviceStateManager} sends event to {@link android.hardware.display.DisplayManager}
     *  - {@link android.hardware.display.DisplayManager} sends it to {@link WindowManagerInternal}
     *  - {@link WindowManagerInternal} eventually calls this method
     *
     * @param state device state as defined by {@link DeviceStateManager}
     */
    public void onDeviceStateReceivedByDisplayManager(int state) {
        mCurrentState = state;

        final DeviceState deviceState;
+3 −1
Original line number Diff line number Diff line
@@ -1730,7 +1730,9 @@ public class DisplayRotation {
    }

    /**
     * Called by the DeviceStateManager callback when the device state changes.
     * Called by the display manager just before it applied the device state, it is guaranteed
     * that in case of physical display change the {@link DisplayRotation#physicalDisplayChanged}
     * method will be invoked *after* this one.
     */
    void foldStateChanged(DeviceStateController.DeviceState deviceState) {
        if (mFoldController != null) {
+4 −1
Original line number Diff line number Diff line
@@ -71,7 +71,10 @@ public class PhysicalDisplaySwitchTransitionLauncher {
    }

    /**
     *   Called by the DeviceStateManager callback when the state changes.
     * Called by the display manager just before it applied the device state, it is guaranteed
     * that in case of physical display change the
     * {@link PhysicalDisplaySwitchTransitionLauncher#requestDisplaySwitchTransitionIfNeeded}
     * method will be invoked *after* this one.
     */
    void foldStateChanged(DeviceState newDeviceState) {
        boolean isUnfolding = mDeviceState == FOLDED
+10 −2
Original line number Diff line number Diff line
@@ -438,8 +438,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        mTaskSupervisor = mService.mTaskSupervisor;
        mTaskSupervisor.mRootWindowContainer = this;
        mDisplayOffTokenAcquirer = mService.new SleepTokenAcquirerImpl(DISPLAY_OFF_SLEEP_TOKEN_TAG);
        mDeviceStateController = new DeviceStateController(service.mContext, service.mH,
                service.mGlobalLock);
        mDeviceStateController = new DeviceStateController(service.mContext, service.mGlobalLock);
        mDisplayRotationCoordinator = new DisplayRotationCoordinator();
    }

@@ -1283,6 +1282,15 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
                false /* includingParents */);
    }

    /**
     * Called just before display manager has applied the device state to the displays
     * @param deviceState device state as defined by
     *        {@link android.hardware.devicestate.DeviceStateManager}
     */
    void onDisplayManagerReceivedDeviceState(int deviceState) {
        mDeviceStateController.onDeviceStateReceivedByDisplayManager(deviceState);
    }

    // TODO(multi-display): Look at all callpoints to make sure they make sense in multi-display.
    DisplayContent getDefaultDisplay() {
        return mDefaultDisplay;
Loading