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

Commit 09d6e260 authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Send display property change events in onDisplayChanged callbacks

This will enable the feature to subscribe for refresh rate and display
state changes via onDisplayChanged callbacks

Bug: 372700957
Test: CTS linked with the topic
Flag: com.android.server.display.feature.flags.display_listener_performance_improvements
Change-Id: I7ca4dc97af8675e92d9330b0d0aa9acfbd71e142
parent e9a51667
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ public final class DisplayManagerGlobal {
            EVENT_DISPLAY_HDR_SDR_RATIO_CHANGED,
            EVENT_DISPLAY_CONNECTED,
            EVENT_DISPLAY_DISCONNECTED,
            EVENT_DISPLAY_REFRESH_RATE_CHANGED,
            EVENT_DISPLAY_STATE_CHANGED
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface DisplayEvent {}
@@ -120,6 +122,8 @@ public final class DisplayManagerGlobal {
    public static final int EVENT_DISPLAY_HDR_SDR_RATIO_CHANGED = 5;
    public static final int EVENT_DISPLAY_CONNECTED = 6;
    public static final int EVENT_DISPLAY_DISCONNECTED = 7;
    public static final int EVENT_DISPLAY_REFRESH_RATE_CHANGED = 8;
    public static final int EVENT_DISPLAY_STATE_CHANGED = 9;

    @LongDef(prefix = {"INTERNAL_EVENT_DISPLAY"}, flag = true, value = {
            INTERNAL_EVENT_FLAG_DISPLAY_ADDED,
@@ -1432,6 +1436,18 @@ public final class DisplayManagerGlobal {
                        mListener.onDisplayDisconnected(displayId);
                    }
                    break;
                case EVENT_DISPLAY_REFRESH_RATE_CHANGED:
                    if ((mInternalEventFlagsMask
                            & INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE) != 0) {
                        mListener.onDisplayChanged(displayId);
                    }
                    break;
                case EVENT_DISPLAY_STATE_CHANGED:
                    if ((mInternalEventFlagsMask
                            & INTERNAL_EVENT_FLAG_DISPLAY_STATE) != 0) {
                        mListener.onDisplayChanged(displayId);
                    }
                    break;
            }
            if (DEBUG) {
                Trace.endSection();
@@ -1571,6 +1587,10 @@ public final class DisplayManagerGlobal {
                return "EVENT_DISPLAY_CONNECTED";
            case EVENT_DISPLAY_DISCONNECTED:
                return "EVENT_DISPLAY_DISCONNECTED";
            case EVENT_DISPLAY_REFRESH_RATE_CHANGED:
                return "EVENT_DISPLAY_REFRESH_RATE_CHANGED";
            case EVENT_DISPLAY_STATE_CHANGED:
                return "EVENT_DISPLAY_STATE_CHANGED";
        }
        return "UNKNOWN";
    }
+89 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package android.hardware.display;

import static android.hardware.display.DisplayManagerGlobal.EVENT_DISPLAY_STATE_CHANGED;
import static android.hardware.display.DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE;
import static android.hardware.display.DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_STATE;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
@@ -28,13 +33,19 @@ import android.content.Context;
import android.os.Handler;
import android.os.RemoteException;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.view.DisplayInfo;

import androidx.test.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.server.display.feature.flags.Flags;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
@@ -55,6 +66,10 @@ import org.mockito.MockitoAnnotations;
@RunWith(AndroidJUnit4.class)
public class DisplayManagerGlobalTest {

    @Rule
    public final CheckFlagsRule mCheckFlagsRule =
            DeviceFlagsValueProvider.createCheckFlagsRule();

    private static final long ALL_DISPLAY_EVENTS =
            DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED
            | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CHANGED
@@ -116,6 +131,33 @@ public class DisplayManagerGlobalTest {
        Mockito.verifyNoMoreInteractions(mListener);
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public void testDisplayListenerIsCalled_WhenDisplayPropertyChangeEventOccurs()
            throws RemoteException {
        mDisplayManagerGlobal.registerDisplayListener(mListener, mHandler,
                INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE
                        | INTERNAL_EVENT_FLAG_DISPLAY_STATE,
                null);
        Mockito.verify(mDisplayManager)
                .registerCallbackWithEventMask(mCallbackCaptor.capture(), anyLong());
        IDisplayManagerCallback callback = mCallbackCaptor.getValue();

        int displayId = 1;

        Mockito.reset(mListener);
        callback.onDisplayEvent(displayId, DisplayManagerGlobal.EVENT_DISPLAY_REFRESH_RATE_CHANGED);
        waitForHandler();
        Mockito.verify(mListener).onDisplayChanged(eq(displayId));
        Mockito.verifyNoMoreInteractions(mListener);

        Mockito.reset(mListener);
        callback.onDisplayEvent(displayId, EVENT_DISPLAY_STATE_CHANGED);
        waitForHandler();
        Mockito.verify(mListener).onDisplayChanged(eq(displayId));
        Mockito.verifyNoMoreInteractions(mListener);
    }

    @Test
    public void testDisplayListenerIsNotCalled_WhenClientIsNotSubscribed() throws RemoteException {
        // First we subscribe to all events in order to test that the subsequent calls to
@@ -231,6 +273,53 @@ public class DisplayManagerGlobalTest {
        verify(mListener2, never()).onDisplayChanged(anyInt());
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_DISPLAY_LISTENER_PERFORMANCE_IMPROVEMENTS)
    public void testMapFlagsToInternalEventFlag() {
        // Test public flags mapping
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(DisplayManager.EVENT_FLAG_DISPLAY_ADDED, 0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(DisplayManager.EVENT_FLAG_DISPLAY_CHANGED, 0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REMOVED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(DisplayManager.EVENT_FLAG_DISPLAY_REMOVED, 0));
        assertEquals(INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(
                                DisplayManager.EVENT_FLAG_DISPLAY_REFRESH_RATE,
                                0));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_STATE,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(
                                DisplayManager.EVENT_FLAG_DISPLAY_STATE,
                                0));

        // test private flags mapping
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_HDR_SDR_RATIO_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_FLAG_HDR_SDR_RATIO_CHANGED));
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(0,
                                DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS));

        // Test both public and private flags mapping
        assertEquals(DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_BRIGHTNESS_CHANGED
                        | INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE,
                mDisplayManagerGlobal
                        .mapFlagsToInternalEventFlag(
                                DisplayManager.EVENT_FLAG_DISPLAY_REFRESH_RATE,
                                DisplayManager.PRIVATE_EVENT_FLAG_DISPLAY_BRIGHTNESS));
    }

    private void waitForHandler() {
        mHandler.runWithScissors(() -> {
        }, 0);
+22 −0
Original line number Diff line number Diff line
@@ -2460,6 +2460,15 @@ public final class DisplayManagerService extends SystemService {
                DisplayManagerGlobal.EVENT_DISPLAY_HDR_SDR_RATIO_CHANGED);
    }

    private void handleLogicalDisplayRefreshRateChangedLocked(@NonNull LogicalDisplay display) {
        sendDisplayEventIfEnabledLocked(display,
                DisplayManagerGlobal.EVENT_DISPLAY_REFRESH_RATE_CHANGED);
    }

    private void handleLogicalDisplayStateChangedLocked(@NonNull LogicalDisplay display) {
        sendDisplayEventIfEnabledLocked(display, DisplayManagerGlobal.EVENT_DISPLAY_STATE_CHANGED);
    }

    private void notifyDefaultDisplayDeviceUpdated(LogicalDisplay display) {
        mDisplayModeDirector.defaultDisplayDeviceUpdated(display.getPrimaryDisplayDeviceLocked()
                .mDisplayDeviceConfig);
@@ -3991,6 +4000,12 @@ public final class DisplayManagerService extends SystemService {
                case LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_DISCONNECTED:
                    handleLogicalDisplayDisconnectedLocked(display);
                    break;
                case LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_REFRESH_RATE_CHANGED:
                    handleLogicalDisplayRefreshRateChangedLocked(display);
                    break;
                case LogicalDisplayMapper.LOGICAL_DISPLAY_EVENT_STATE_CHANGED:
                    handleLogicalDisplayStateChangedLocked(display);
                    break;
            }
        }

@@ -4198,6 +4213,13 @@ public final class DisplayManagerService extends SystemService {
                    return (mask
                            & DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CONNECTION_CHANGED)
                            != 0;
                case DisplayManagerGlobal.EVENT_DISPLAY_REFRESH_RATE_CHANGED:
                    return (mask
                            & DisplayManagerGlobal
                            .INTERNAL_EVENT_FLAG_DISPLAY_REFRESH_RATE) != 0;
                case DisplayManagerGlobal.EVENT_DISPLAY_STATE_CHANGED:
                    return (mask & DisplayManagerGlobal
                            .INTERNAL_EVENT_FLAG_DISPLAY_STATE) != 0;
                default:
                    // This should never happen.
                    Slog.e(TAG, "Unknown display event " + event);
+62 −37
Original line number Diff line number Diff line
@@ -79,15 +79,18 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
    // 'adb shell setprop persist.log.tag.LogicalDisplayMapper DEBUG && adb reboot'
    private static final boolean DEBUG = DebugUtils.isDebuggable(TAG);

    public static final int LOGICAL_DISPLAY_EVENT_ADDED = 1;
    public static final int LOGICAL_DISPLAY_EVENT_CHANGED = 2;
    public static final int LOGICAL_DISPLAY_EVENT_REMOVED = 3;
    public static final int LOGICAL_DISPLAY_EVENT_SWAPPED = 4;
    public static final int LOGICAL_DISPLAY_EVENT_FRAME_RATE_OVERRIDES_CHANGED = 5;
    public static final int LOGICAL_DISPLAY_EVENT_DEVICE_STATE_TRANSITION = 6;
    public static final int LOGICAL_DISPLAY_EVENT_HDR_SDR_RATIO_CHANGED = 7;
    public static final int LOGICAL_DISPLAY_EVENT_CONNECTED = 8;
    public static final int LOGICAL_DISPLAY_EVENT_DISCONNECTED = 9;
    public static final int LOGICAL_DISPLAY_EVENT_BASE = 0;
    public static final int LOGICAL_DISPLAY_EVENT_ADDED = 1 << 0;
    public static final int LOGICAL_DISPLAY_EVENT_CHANGED = 1 << 1;
    public static final int LOGICAL_DISPLAY_EVENT_REMOVED = 1 << 2;
    public static final int LOGICAL_DISPLAY_EVENT_SWAPPED = 1 << 3;
    public static final int LOGICAL_DISPLAY_EVENT_FRAME_RATE_OVERRIDES_CHANGED = 1 << 4;
    public static final int LOGICAL_DISPLAY_EVENT_DEVICE_STATE_TRANSITION = 1 << 5;
    public static final int LOGICAL_DISPLAY_EVENT_HDR_SDR_RATIO_CHANGED = 1 << 6;
    public static final int LOGICAL_DISPLAY_EVENT_CONNECTED = 1 << 7;
    public static final int LOGICAL_DISPLAY_EVENT_DISCONNECTED = 1 << 8;
    public static final int LOGICAL_DISPLAY_EVENT_REFRESH_RATE_CHANGED = 1 << 9;
    public static final int LOGICAL_DISPLAY_EVENT_STATE_CHANGED = 1 << 10;

    public static final int DISPLAY_GROUP_EVENT_ADDED = 1;
    public static final int DISPLAY_GROUP_EVENT_CHANGED = 2;
@@ -804,6 +807,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
            final boolean wasPreviouslyUpdated = updateState != UPDATE_STATE_NEW;
            final boolean wasPreviouslyEnabled = mDisplaysEnabledCache.get(displayId);
            final boolean isCurrentlyEnabled = display.isEnabledLocked();
            int logicalDisplayEventMask = mLogicalDisplaysToUpdate
                    .get(displayId, LOGICAL_DISPLAY_EVENT_BASE);

            // The display is no longer valid and needs to be removed.
            if (!display.isValidLocked()) {
@@ -821,20 +826,20 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                        if (mDisplaysEnabledCache.get(displayId)) {
                            // We still need to send LOGICAL_DISPLAY_EVENT_DISCONNECTED
                            reloop = true;
                            mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_REMOVED);
                            logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_REMOVED;
                        } else {
                            mUpdatedLogicalDisplays.delete(displayId);
                            mLogicalDisplaysToUpdate.put(displayId,
                                    LOGICAL_DISPLAY_EVENT_DISCONNECTED);
                            logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_DISCONNECTED;
                        }
                    } else {
                        mUpdatedLogicalDisplays.delete(displayId);
                        mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_REMOVED);
                        logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_REMOVED;
                    }
                } else {
                    // This display never left this class, safe to remove without notification
                    mLogicalDisplays.removeAt(i);
                }
                mLogicalDisplaysToUpdate.put(displayId, logicalDisplayEventMask);
                continue;

            // The display is new.
@@ -842,38 +847,40 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                if (mFlags.isConnectedDisplayManagementEnabled()) {
                    // We still need to send LOGICAL_DISPLAY_EVENT_ADDED
                    reloop = true;
                    mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_CONNECTED);
                    logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_CONNECTED;
                } else {
                    mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_ADDED);
                    logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_ADDED;
                }
            // Underlying displays device has changed to a different one.
            } else if (!TextUtils.equals(mTempDisplayInfo.uniqueId, newDisplayInfo.uniqueId)) {
                mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_SWAPPED);
                logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_SWAPPED;

            // Something about the display device has changed.
            } else if (mFlags.isConnectedDisplayManagementEnabled()
                    && wasPreviouslyEnabled != isCurrentlyEnabled) {
                int event = isCurrentlyEnabled ? LOGICAL_DISPLAY_EVENT_ADDED :
                        LOGICAL_DISPLAY_EVENT_REMOVED;
                mLogicalDisplaysToUpdate.put(displayId, event);
                logicalDisplayEventMask |= event;
            } else if (wasDirty || !mTempDisplayInfo.equals(newDisplayInfo)) {
                // If only the hdr/sdr ratio changed, then send just the event for that case
                if ((diff == DisplayDeviceInfo.DIFF_HDR_SDR_RATIO)) {
                    mLogicalDisplaysToUpdate.put(displayId,
                            LOGICAL_DISPLAY_EVENT_HDR_SDR_RATIO_CHANGED);
                    logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_HDR_SDR_RATIO_CHANGED;
                } else {
                    mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_CHANGED);
                    logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_CHANGED;
                }

                if (mFlags.isDisplayListenerPerformanceImprovementsEnabled()) {
                    logicalDisplayEventMask
                            |= updateAndGetMaskForDisplayPropertyChanges(newDisplayInfo);
                }

                // The display is involved in a display layout transition
            } else if (updateState == UPDATE_STATE_TRANSITION) {
                mLogicalDisplaysToUpdate.put(displayId,
                        LOGICAL_DISPLAY_EVENT_DEVICE_STATE_TRANSITION);
                logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_DEVICE_STATE_TRANSITION;

            // Display frame rate overrides changed.
            } else if (!display.getPendingFrameRateOverrideUids().isEmpty()) {
                mLogicalDisplaysToUpdate.put(
                        displayId, LOGICAL_DISPLAY_EVENT_FRAME_RATE_OVERRIDES_CHANGED);
                logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_FRAME_RATE_OVERRIDES_CHANGED;

            // Non-override display values changed.
            } else {
@@ -882,10 +889,10 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                // things like display cutouts.
                display.getNonOverrideDisplayInfoLocked(mTempDisplayInfo);
                if (!mTempNonOverrideDisplayInfo.equals(mTempDisplayInfo)) {
                    mLogicalDisplaysToUpdate.put(displayId, LOGICAL_DISPLAY_EVENT_CHANGED);
                    logicalDisplayEventMask |= LOGICAL_DISPLAY_EVENT_CHANGED;
                }
            }

            mLogicalDisplaysToUpdate.put(displayId, logicalDisplayEventMask);
            mUpdatedLogicalDisplays.put(displayId, UPDATE_STATE_UPDATED);
        }

@@ -922,6 +929,8 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
            sendUpdatesForDisplaysLocked(LOGICAL_DISPLAY_EVENT_DISCONNECTED);
        }
        sendUpdatesForDisplaysLocked(LOGICAL_DISPLAY_EVENT_CHANGED);
        sendUpdatesForDisplaysLocked(LOGICAL_DISPLAY_EVENT_REFRESH_RATE_CHANGED);
        sendUpdatesForDisplaysLocked(LOGICAL_DISPLAY_EVENT_STATE_CHANGED);
        sendUpdatesForDisplaysLocked(LOGICAL_DISPLAY_EVENT_FRAME_RATE_OVERRIDES_CHANGED);
        sendUpdatesForDisplaysLocked(LOGICAL_DISPLAY_EVENT_SWAPPED);
        if (mFlags.isConnectedDisplayManagementEnabled()) {
@@ -944,13 +953,25 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
        }
    }

    @VisibleForTesting
    int updateAndGetMaskForDisplayPropertyChanges(DisplayInfo newDisplayInfo) {
        int mask = LOGICAL_DISPLAY_EVENT_BASE;
        if (mTempDisplayInfo.getRefreshRate() != newDisplayInfo.getRefreshRate()) {
            mask |= LOGICAL_DISPLAY_EVENT_REFRESH_RATE_CHANGED;
        }

        if (mTempDisplayInfo.state != newDisplayInfo.state) {
            mask |= LOGICAL_DISPLAY_EVENT_STATE_CHANGED;
        }
        return mask;
    }
    /**
     * Send the specified message for all relevant displays in the specified display-to-message map.
     */
    private void sendUpdatesForDisplaysLocked(int msg) {
    private void sendUpdatesForDisplaysLocked(int logicalDisplayEvent) {
        for (int i = mLogicalDisplaysToUpdate.size() - 1; i >= 0; --i) {
            final int currMsg = mLogicalDisplaysToUpdate.valueAt(i);
            if (currMsg != msg) {
            final int logicalDisplayEventMask = mLogicalDisplaysToUpdate.valueAt(i);
            if ((logicalDisplayEventMask & logicalDisplayEvent) == 0) {
                continue;
            }

@@ -959,25 +980,25 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
            if (DEBUG) {
                final DisplayDevice device = display.getPrimaryDisplayDeviceLocked();
                final String uniqueId = device == null ? "null" : device.getUniqueId();
                Slog.d(TAG, "Sending " + displayEventToString(msg) + " for display=" + id
                        + " with device=" + uniqueId);
                Slog.d(TAG, "Sending " + displayEventToString(logicalDisplayEvent) + " for "
                        + "display=" + id + " with device=" + uniqueId);
            }

            if (mFlags.isConnectedDisplayManagementEnabled()) {
                if (msg == LOGICAL_DISPLAY_EVENT_ADDED) {
                if (logicalDisplayEvent == LOGICAL_DISPLAY_EVENT_ADDED) {
                    mDisplaysEnabledCache.put(id, true);
                } else if (msg == LOGICAL_DISPLAY_EVENT_REMOVED) {
                } else if (logicalDisplayEvent == LOGICAL_DISPLAY_EVENT_REMOVED) {
                    mDisplaysEnabledCache.delete(id);
                }
            }

            mListener.onLogicalDisplayEventLocked(display, msg);
            mListener.onLogicalDisplayEventLocked(display, logicalDisplayEvent);

            if (mFlags.isConnectedDisplayManagementEnabled()) {
                if (msg == LOGICAL_DISPLAY_EVENT_DISCONNECTED) {
                if (logicalDisplayEvent == LOGICAL_DISPLAY_EVENT_DISCONNECTED) {
                    mLogicalDisplays.delete(id);
                }
            } else if (msg == LOGICAL_DISPLAY_EVENT_REMOVED) {
            } else if (logicalDisplayEvent == LOGICAL_DISPLAY_EVENT_REMOVED) {
                // We wait until we sent the EVENT_REMOVED event before actually removing the
                // display.
                mLogicalDisplays.delete(id);
@@ -1348,6 +1369,10 @@ class LogicalDisplayMapper implements DisplayDeviceRepository.Listener {
                return "connected";
            case LOGICAL_DISPLAY_EVENT_DISCONNECTED:
                return "disconnected";
            case LOGICAL_DISPLAY_EVENT_STATE_CHANGED:
                return "state_changed";
            case LOGICAL_DISPLAY_EVENT_REFRESH_RATE_CHANGED:
                return "refresh_rate_changed";
        }
        return null;
    }
+7 −0
Original line number Diff line number Diff line
@@ -226,6 +226,9 @@ public class DisplayManagerServiceTest {
            "EVENT_DISPLAY_HDR_SDR_RATIO_CHANGED";
    private static final String EVENT_DISPLAY_CONNECTED = "EVENT_DISPLAY_CONNECTED";
    private static final String EVENT_DISPLAY_DISCONNECTED = "EVENT_DISPLAY_DISCONNECTED";
    private static final String EVENT_DISPLAY_REFRESH_RATE_CHANGED =
            "EVENT_DISPLAY_REFRESH_RATE_CHANGED";
    private static final String EVENT_DISPLAY_STATE_CHANGED = "EVENT_DISPLAY_STATE_CHANGED";
    private static final String DISPLAY_GROUP_EVENT_ADDED = "DISPLAY_GROUP_EVENT_ADDED";
    private static final String DISPLAY_GROUP_EVENT_REMOVED = "DISPLAY_GROUP_EVENT_REMOVED";
    private static final String DISPLAY_GROUP_EVENT_CHANGED = "DISPLAY_GROUP_EVENT_CHANGED";
@@ -4234,6 +4237,10 @@ public class DisplayManagerServiceTest {
                    return EVENT_DISPLAY_CONNECTED;
                case DisplayManagerGlobal.EVENT_DISPLAY_DISCONNECTED:
                    return EVENT_DISPLAY_DISCONNECTED;
                case DisplayManagerGlobal.EVENT_DISPLAY_REFRESH_RATE_CHANGED:
                    return EVENT_DISPLAY_REFRESH_RATE_CHANGED;
                case DisplayManagerGlobal.EVENT_DISPLAY_STATE_CHANGED:
                    return EVENT_DISPLAY_STATE_CHANGED;
                default:
                    return "UNKNOWN: " + eventType;
            }
Loading