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

Commit 755dd581 authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Subscribing viewroot impl to only display state changes

Bug: 379250246
Test: Manually verified the callbacks are received only on display state
changes
Flag: com.android.server.display.feature.flags.subscribe_granular_display_events

Change-Id: I85539fb9fe6e5873b671ae667a17e7978752bf97
parent 617b9833
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -1237,6 +1237,8 @@ public final class ViewRootImpl implements ViewParent,
    private @ActivityInfo.ColorMode int mCurrentColorMode = ActivityInfo.COLOR_MODE_DEFAULT;
    private long mColorModeLastSetMillis = -1;
    private final boolean mIsSubscribeGranularDisplayEventsEnabled;
    public ViewRootImpl(Context context, Display display) {
        this(context, display, WindowManagerGlobal.getWindowSession(), new WindowLayout());
    }
@@ -1334,6 +1336,8 @@ public final class ViewRootImpl implements ViewParent,
        // Disable DRAW_WAKE_LOCK starting U.
        mDisableDrawWakeLock =
                CompatChanges.isChangeEnabled(DISABLE_DRAW_WAKE_LOCK) && disableDrawWakeLock();
        mIsSubscribeGranularDisplayEventsEnabled =
                com.android.server.display.feature.flags.Flags.subscribeGranularDisplayEvents();
    }
    public static void addFirstDrawHandler(Runnable callback) {
@@ -1811,14 +1815,22 @@ public final class ViewRootImpl implements ViewParent,
                mAccessibilityInteractionConnectionManager, mHandler);
        mAccessibilityManager.addHighContrastTextStateChangeListener(
                mExecutor, mHighContrastTextManager);
        long eventsToBeRegistered =
                (mIsSubscribeGranularDisplayEventsEnabled)
                ? DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED
                        | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_STATE
                        | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REMOVED
                : DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED
                        | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CHANGED
                        | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REMOVED;
        DisplayManagerGlobal
                .getInstance()
                .registerDisplayListener(
                        mDisplayListener,
                        mHandler,
                        DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_ADDED
                        | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_CHANGED
                        | DisplayManagerGlobal.INTERNAL_EVENT_FLAG_DISPLAY_REMOVED,
                        eventsToBeRegistered,
                        mBasePackageName);
        if (forceInvertColor()) {
+13 −0
Original line number Diff line number Diff line
@@ -251,6 +251,11 @@ public class DisplayManagerFlags {
            Flags::displayListenerPerformanceImprovements
    );

    private final FlagState mSubscribeGranularDisplayEvents = new FlagState(
            Flags.FLAG_SUBSCRIBE_GRANULAR_DISPLAY_EVENTS,
            Flags::subscribeGranularDisplayEvents
    );

    /**
     * @return {@code true} if 'port' is allowed in display layout configuration file.
     */
@@ -537,6 +542,13 @@ public class DisplayManagerFlags {
        return mDisplayListenerPerformanceImprovementsFlagState.isEnabled();
    }

    /**
     * @return {@code true} if the flag for subscribing to granular display events is enabled
     */
    public boolean isSubscribeGranularDisplayEventsEnabled() {
        return mSubscribeGranularDisplayEvents.isEnabled();
    }

    /**
     * dumps all flagstates
     * @param pw printWriter
@@ -590,6 +602,7 @@ public class DisplayManagerFlags {
        pw.println(" " + mAutoBrightnessModeBedtimeWearFlagState);
        pw.println(" " + mEnablePluginManagerFlagState);
        pw.println(" " + mDisplayListenerPerformanceImprovementsFlagState);
        pw.println(" " + mSubscribeGranularDisplayEvents);
    }

    private static class FlagState {
+11 −0
Original line number Diff line number Diff line
@@ -478,3 +478,14 @@ flag {
    bug: "378385869"
    is_fixed_read_only: true
}

flag {
    name: "subscribe_granular_display_events"
    namespace: "display_manager"
    description: "Enable subscription to granular display change events."
    bug: "379250634"
    is_fixed_read_only: true
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}