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

Commit b7d2f2b5 authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Restore flicker votes" into main

parents 64d21aea 8f8b5679
Loading
Loading
Loading
Loading
+27 −17
Original line number Original line Diff line number Diff line
@@ -465,6 +465,7 @@ public class DisplayModeDirector {
    }
    }


    // TODO(b/372019752) Rename all the occurrences of the VRR with ARR.
    // TODO(b/372019752) Rename all the occurrences of the VRR with ARR.
    @GuardedBy("mLock")
    private boolean isVrrSupportedLocked(int displayId) {
    private boolean isVrrSupportedLocked(int displayId) {
        if (mHasArrSupportFlagEnabled) {
        if (mHasArrSupportFlagEnabled) {
            Boolean hasArrSupport = mHasArrSupport.get(displayId);
            Boolean hasArrSupport = mHasArrSupport.get(displayId);
@@ -642,6 +643,7 @@ public class DisplayModeDirector {
        return maxRefreshRate;
        return maxRefreshRate;
    }
    }


    @GuardedBy("mLock")
    private void notifyDesiredDisplayModeSpecsChangedLocked() {
    private void notifyDesiredDisplayModeSpecsChangedLocked() {
        if (mDesiredDisplayModeSpecsListener != null
        if (mDesiredDisplayModeSpecsListener != null
                && !mHandler.hasMessages(MSG_REFRESH_RATE_RANGE_CHANGED)) {
                && !mHandler.hasMessages(MSG_REFRESH_RATE_RANGE_CHANGED)) {
@@ -655,6 +657,7 @@ public class DisplayModeDirector {
        }
        }
    }
    }


    @GuardedBy("mLock")
    boolean isExternalDisplayLocked(int displayId) {
    boolean isExternalDisplayLocked(int displayId) {
        return mExternalDisplaysConnected.contains(displayId);
        return mExternalDisplaysConnected.contains(displayId);
    }
    }
@@ -1139,6 +1142,7 @@ public class DisplayModeDirector {
            mDefaultPeakRefreshRate = defaultPeakRefreshRate;
            mDefaultPeakRefreshRate = defaultPeakRefreshRate;
        }
        }


        @GuardedBy("mLock")
        private void updateLowPowerModeSettingLocked() {
        private void updateLowPowerModeSettingLocked() {
            mIsLowPower = Settings.Global.getInt(mContext.getContentResolver(),
            mIsLowPower = Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.LOW_POWER_MODE, 0 /*default*/) != 0;
                    Settings.Global.LOW_POWER_MODE, 0 /*default*/) != 0;
@@ -1153,6 +1157,7 @@ public class DisplayModeDirector {
            updateLowPowerModeAllowedModesLocked();
            updateLowPowerModeAllowedModesLocked();
        }
        }


        @GuardedBy("mLock")
        private void updateLowPowerModeAllowedModesLocked() {
        private void updateLowPowerModeAllowedModesLocked() {
            if (!mVsyncLowPowerVoteEnabled) {
            if (!mVsyncLowPowerVoteEnabled) {
                return;
                return;
@@ -1286,6 +1291,7 @@ public class DisplayModeDirector {
            mVotesStorage.updateVote(displayId, Vote.PRIORITY_DEFAULT_RENDER_FRAME_RATE, null);
            mVotesStorage.updateVote(displayId, Vote.PRIORITY_DEFAULT_RENDER_FRAME_RATE, null);
        }
        }


        @GuardedBy("mLock")
        private void updateModeSwitchingTypeSettingLocked() {
        private void updateModeSwitchingTypeSettingLocked() {
            final ContentResolver cr = mContext.getContentResolver();
            final ContentResolver cr = mContext.getContentResolver();
            int switchingType = Settings.Secure.getIntForUser(cr,
            int switchingType = Settings.Secure.getIntForUser(cr,
@@ -1297,6 +1303,7 @@ public class DisplayModeDirector {
            }
            }
        }
        }


        @GuardedBy("mLock")
        public void dumpLocked(PrintWriter pw) {
        public void dumpLocked(PrintWriter pw) {
            pw.println("  SettingsObserver");
            pw.println("  SettingsObserver");
            pw.println("    mDefaultRefreshRate: " + mDefaultRefreshRate);
            pw.println("    mDefaultRefreshRate: " + mDefaultRefreshRate);
@@ -1341,6 +1348,7 @@ public class DisplayModeDirector {
            }
            }
        }
        }


        @GuardedBy("mLock")
        private Display.Mode findModeLocked(int displayId, int modeId, float requestedRefreshRate) {
        private Display.Mode findModeLocked(int displayId, int modeId, float requestedRefreshRate) {
            Display.Mode mode = null;
            Display.Mode mode = null;
            if (modeId != 0) {
            if (modeId != 0) {
@@ -1392,6 +1400,7 @@ public class DisplayModeDirector {
        }
        }


        @Nullable
        @Nullable
        @GuardedBy("mLock")
        private Display.Mode findDefaultModeByRefreshRateLocked(int displayId, float refreshRate) {
        private Display.Mode findDefaultModeByRefreshRateLocked(int displayId, float refreshRate) {
            Display.Mode[] modes = mAppSupportedModesByDisplay.get(displayId);
            Display.Mode[] modes = mAppSupportedModesByDisplay.get(displayId);
            Display.Mode defaultMode = mDefaultModeByDisplay.get(displayId);
            Display.Mode defaultMode = mDefaultModeByDisplay.get(displayId);
@@ -1404,6 +1413,7 @@ public class DisplayModeDirector {
            return null;
            return null;
        }
        }


        @GuardedBy("mLock")
        private Display.Mode findAppModeByIdLocked(int displayId, int modeId) {
        private Display.Mode findAppModeByIdLocked(int displayId, int modeId) {
            Display.Mode[] modes = mAppSupportedModesByDisplay.get(displayId);
            Display.Mode[] modes = mAppSupportedModesByDisplay.get(displayId);
            if (modes == null) {
            if (modes == null) {
@@ -1417,6 +1427,7 @@ public class DisplayModeDirector {
            return null;
            return null;
        }
        }


        @GuardedBy("mLock")
        private void dumpLocked(PrintWriter pw) {
        private void dumpLocked(PrintWriter pw) {
            pw.println("  AppRequestObserver");
            pw.println("  AppRequestObserver");
            pw.println("    mIgnorePreferredRefreshRate: " + mIgnorePreferredRefreshRate);
            pw.println("    mIgnorePreferredRefreshRate: " + mIgnorePreferredRefreshRate);
@@ -1811,7 +1822,7 @@ public class DisplayModeDirector {
                            if (mThermalStatus != currentStatus) {
                            if (mThermalStatus != currentStatus) {
                                mThermalStatus = currentStatus;
                                mThermalStatus = currentStatus;
                            }
                            }
                            onBrightnessChangedLocked();
                            updateFlickerRefreshRateVotes();
                        }
                        }
                    }
                    }
                };
                };
@@ -2108,34 +2119,26 @@ public class DisplayModeDirector {
        }
        }


        @VisibleForTesting
        @VisibleForTesting
        @GuardedBy("mLock")
        public void onRefreshRateSettingChangedLocked(float min, float max) {
        public void onRefreshRateSettingChangedLocked(float min, float max) {
            boolean changeable = (max - min > 1f && max > 60f);
            boolean changeable = (max - min > 1f && max > 60f);
            if (mRefreshRateChangeable != changeable) {
            if (mRefreshRateChangeable != changeable) {
                mRefreshRateChangeable = changeable;
                mRefreshRateChangeable = changeable;
                updateSensorStatus();
                updateSensorStatus();
                if (!changeable) {
                updateFlickerRefreshRateVotes();
                    removeFlickerRefreshRateVotes();
                }
            }
            }
        }
        }


        @VisibleForTesting
        @VisibleForTesting
        @GuardedBy("mLock")
        void onLowPowerModeEnabledLocked(boolean enabled) {
        void onLowPowerModeEnabledLocked(boolean enabled) {
            if (mLowPowerModeEnabled != enabled) {
            if (mLowPowerModeEnabled != enabled) {
                mLowPowerModeEnabled = enabled;
                mLowPowerModeEnabled = enabled;
                updateSensorStatus();
                updateSensorStatus();
                if (enabled) {
                updateFlickerRefreshRateVotes();
                    removeFlickerRefreshRateVotes();
                }
            }
            }
        }
        }


        private void removeFlickerRefreshRateVotes() {
            // Revoke previous vote from BrightnessObserver
            mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE, null);
            mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH, null);
        }

        private void onDeviceConfigLowBrightnessThresholdsChanged(float[] displayThresholds,
        private void onDeviceConfigLowBrightnessThresholdsChanged(float[] displayThresholds,
                float[] ambientThresholds) {
                float[] ambientThresholds) {
            if (displayThresholds != null && ambientThresholds != null
            if (displayThresholds != null && ambientThresholds != null
@@ -2228,6 +2231,7 @@ public class DisplayModeDirector {
            }
            }
        }
        }


        @GuardedBy("mLock")
        void dumpLocked(PrintWriter pw) {
        void dumpLocked(PrintWriter pw) {
            pw.println("  BrightnessObserver");
            pw.println("  BrightnessObserver");
            pw.println("    mAmbientLux: " + mAmbientLux);
            pw.println("    mAmbientLux: " + mAmbientLux);
@@ -2288,7 +2292,7 @@ public class DisplayModeDirector {
                synchronized (mLock) {
                synchronized (mLock) {
                    if (!BrightnessSynchronizer.floatEquals(brightness, mBrightness)) {
                    if (!BrightnessSynchronizer.floatEquals(brightness, mBrightness)) {
                        mBrightness = brightness;
                        mBrightness = brightness;
                        onBrightnessChangedLocked();
                        updateFlickerRefreshRateVotes();
                    }
                    }
                }
                }
            }
            }
@@ -2341,7 +2345,7 @@ public class DisplayModeDirector {


            updateSensorStatus();
            updateSensorStatus();
            synchronized (mLock) {
            synchronized (mLock) {
                onBrightnessChangedLocked();
                updateFlickerRefreshRateVotes();
            }
            }
        }
        }


@@ -2448,8 +2452,11 @@ public class DisplayModeDirector {
        }
        }


        @GuardedBy("mLock")
        @GuardedBy("mLock")
        private void onBrightnessChangedLocked() {
        private void updateFlickerRefreshRateVotes() {
            if (!mRefreshRateChangeable || mLowPowerModeEnabled) {
            if (!mRefreshRateChangeable || mLowPowerModeEnabled) {
                // Revoke previous vote from BrightnessObserver
                mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE, null);
                mVotesStorage.updateGlobalVote(Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH, null);
                return;
                return;
            }
            }
            Vote refreshRateVote = null;
            Vote refreshRateVote = null;
@@ -2637,6 +2644,7 @@ public class DisplayModeDirector {
            private long mTimestamp;
            private long mTimestamp;
            private boolean mLoggingEnabled;
            private boolean mLoggingEnabled;


            @GuardedBy("mLock")
            public void dumpLocked(PrintWriter pw) {
            public void dumpLocked(PrintWriter pw) {
                pw.println("    mLastSensorData: " + mLastSensorData);
                pw.println("    mLastSensorData: " + mLastSensorData);
                pw.println("    mTimestamp: " + formatTimestamp(mTimestamp));
                pw.println("    mTimestamp: " + formatTimestamp(mTimestamp));
@@ -2715,7 +2723,7 @@ public class DisplayModeDirector {
                }
                }


                synchronized (mLock) {
                synchronized (mLock) {
                    onBrightnessChangedLocked();
                    updateFlickerRefreshRateVotes();
                }
                }
            }
            }


@@ -2832,6 +2840,7 @@ public class DisplayModeDirector {
            mVotesStorage.updateVote(displayId, votePriority, vote);
            mVotesStorage.updateVote(displayId, votePriority, vote);
        }
        }


        @GuardedBy("mLock")
        void dumpLocked(PrintWriter pw) {
        void dumpLocked(PrintWriter pw) {
            pw.println("  UdfpsObserver");
            pw.println("  UdfpsObserver");
            pw.println("    mUdfpsRefreshRateEnabled: ");
            pw.println("    mUdfpsRefreshRateEnabled: ");
@@ -3011,6 +3020,7 @@ public class DisplayModeDirector {
            mVotesStorage.updateVote(displayId, Vote.PRIORITY_HIGH_BRIGHTNESS_MODE, vote);
            mVotesStorage.updateVote(displayId, Vote.PRIORITY_HIGH_BRIGHTNESS_MODE, vote);
        }
        }


        @GuardedBy("mLock")
        void dumpLocked(PrintWriter pw) {
        void dumpLocked(PrintWriter pw) {
            pw.println("   HbmObserver");
            pw.println("   HbmObserver");
            pw.println("     mHbmMode: " + mHbmMode);
            pw.println("     mHbmMode: " + mHbmMode);
+66 −18
Original line number Original line Diff line number Diff line
@@ -867,24 +867,6 @@ public class DisplayModeDirectorTest {
        verifyBrightnessObserverCall(director, 120, 90, 0, 120, 90);
        verifyBrightnessObserverCall(director, 120, 90, 0, 120, 90);
    }
    }


    @Test
    public void testBrightnessObserver_LowPowerModeRemovesFlickerVotes() {
        float[] refreshRates = {60.f, 90.f, 120.f};
        DisplayModeDirector director =
                createDirectorFromRefreshRateArray(refreshRates, /*baseModeId=*/0);
        SparseArray<Vote> votes = new SparseArray<>();
        SparseArray<SparseArray<Vote>> votesByDisplay = new SparseArray<>();
        votesByDisplay.put(-1, votes); // Global Vote
        votes.put(Vote.PRIORITY_FLICKER_REFRESH_RATE, Vote.forPhysicalRefreshRates(0, 60));
        votes.put(Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH, Vote.forRenderFrameRates(60, 90));
        director.injectVotesByDisplay(votesByDisplay);

        director.getBrightnessObserver().onLowPowerModeEnabledLocked(true);

        assertNull(director.getVote(-1, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(-1, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));
    }

    @Test
    @Test
    public void testVotingWithAlwaysRespectAppRequest() {
    public void testVotingWithAlwaysRespectAppRequest() {
        Display.Mode[] modes = new Display.Mode[3];
        Display.Mode[] modes = new Display.Mode[3];
@@ -1304,6 +1286,7 @@ public class DisplayModeDirectorTest {
    }
    }


    @Test
    @Test
    @SuppressWarnings("GuardedBy")
    public void testLockFpsForLowZone() throws Exception {
    public void testLockFpsForLowZone() throws Exception {
        DisplayModeDirector director =
        DisplayModeDirector director =
                createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
                createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
@@ -1351,6 +1334,38 @@ public class DisplayModeDirectorTest {
        DisableRefreshRateSwitchingVote disableVote = (DisableRefreshRateSwitchingVote) vote;
        DisableRefreshRateSwitchingVote disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();


        // Disabling Smooth Display should remove the vote
        setPeakRefreshRate(60);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-enabling Smooth Display should restore the vote
        setPeakRefreshRate(90);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 90 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Enabling low power mode should remove the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(true);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-disabling low power mode should restore the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(false);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 90 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // We expect DisplayModeDirector to act on BrightnessInfo.adjustedBrightness; set only this
        // We expect DisplayModeDirector to act on BrightnessInfo.adjustedBrightness; set only this
        // parameter to the necessary threshold
        // parameter to the necessary threshold
        setBrightness(10, 125, displayListener);
        setBrightness(10, 125, displayListener);
@@ -1443,6 +1458,7 @@ public class DisplayModeDirectorTest {
    }
    }


    @Test
    @Test
    @SuppressWarnings("GuardedBy")
    public void testLockFpsForHighZone() throws Exception {
    public void testLockFpsForHighZone() throws Exception {
        DisplayModeDirector director =
        DisplayModeDirector director =
                createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
                createDirectorFromRefreshRateArray(new float[] {60.f, 90.f}, 0);
@@ -1500,6 +1516,38 @@ public class DisplayModeDirectorTest {
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        DisableRefreshRateSwitchingVote disableVote = (DisableRefreshRateSwitchingVote) vote;
        DisableRefreshRateSwitchingVote disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Disabling Smooth Display should remove the vote
        setPeakRefreshRate(60);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-enabling Smooth Display should restore the vote
        setPeakRefreshRate(90);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 60 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();

        // Enabling low power mode should remove the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(true);
        assertNull(director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE));
        assertNull(director.getVote(Display.DEFAULT_DISPLAY,
                Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH));

        // Re-disabling low power mode should restore the vote
        director.getBrightnessObserver().onLowPowerModeEnabledLocked(false);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE);
        assertVoteForPhysicalRefreshRate(vote, 60 /*fps*/);
        vote = director.getVote(Display.DEFAULT_DISPLAY, Vote.PRIORITY_FLICKER_REFRESH_RATE_SWITCH);
        assertThat(vote).isNotNull();
        assertThat(vote).isInstanceOf(DisableRefreshRateSwitchingVote.class);
        disableVote = (DisableRefreshRateSwitchingVote) vote;
        assertThat(disableVote.mDisableRefreshRateSwitching).isTrue();
    }
    }


    @Test
    @Test