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

Commit 4ec2eb53 authored by Daniel Solomon's avatar Daniel Solomon Committed by Automerger Merge Worker
Browse files

Merge changes from topic "b200851199" into sc-qpr1-dev am: 250448c0

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15909960

Change-Id: Icaa01be38637089e703e322e083a52a97dddd771
parents cf301156 250448c0
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -60,12 +60,18 @@ public final class BrightnessInfo implements Parcelable {
    /** Brightness */
    public final float brightness;

    /** Brightness after {@link DisplayPowerController} adjustments */
    public final float adjustedBrightness;

    /** Current minimum supported brightness. */
    public final float brightnessMinimum;

    /** Current maximum supported brightness. */
    public final float brightnessMaximum;

    /** Brightness values greater than this point are only used in High Brightness Mode. */
    public final float highBrightnessTransitionPoint;

    /**
     * Current state of high brightness mode.
     * Can be any of HIGH_BRIGHTNESS_MODE_* values.
@@ -73,11 +79,20 @@ public final class BrightnessInfo implements Parcelable {
    public final int highBrightnessMode;

    public BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum,
            @HighBrightnessMode int highBrightnessMode) {
            @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint) {
        this(brightness, brightness, brightnessMinimum, brightnessMaximum, highBrightnessMode,
                highBrightnessTransitionPoint);
    }

    public BrightnessInfo(float brightness, float adjustedBrightness, float brightnessMinimum,
            float brightnessMaximum, @HighBrightnessMode int highBrightnessMode,
            float highBrightnessTransitionPoint) {
        this.brightness = brightness;
        this.adjustedBrightness = adjustedBrightness;
        this.brightnessMinimum = brightnessMinimum;
        this.brightnessMaximum = brightnessMaximum;
        this.highBrightnessMode = highBrightnessMode;
        this.highBrightnessTransitionPoint = highBrightnessTransitionPoint;
    }

    /**
@@ -103,9 +118,11 @@ public final class BrightnessInfo implements Parcelable {
    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeFloat(brightness);
        dest.writeFloat(adjustedBrightness);
        dest.writeFloat(brightnessMinimum);
        dest.writeFloat(brightnessMaximum);
        dest.writeInt(highBrightnessMode);
        dest.writeFloat(highBrightnessTransitionPoint);
    }

    public static final @android.annotation.NonNull Creator<BrightnessInfo> CREATOR =
@@ -123,9 +140,11 @@ public final class BrightnessInfo implements Parcelable {

    private BrightnessInfo(Parcel source) {
        brightness = source.readFloat();
        adjustedBrightness = source.readFloat();
        brightnessMinimum = source.readFloat();
        brightnessMaximum = source.readFloat();
        highBrightnessMode = source.readInt();
        highBrightnessTransitionPoint = source.readFloat();
    }

}
+75 −70
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.display;

import static android.hardware.display.DisplayManagerInternal.REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE;
import static android.os.PowerManager.BRIGHTNESS_INVALID;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -40,6 +41,7 @@ import android.os.IThermalEventListener;
import android.os.IThermalService;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
@@ -60,6 +62,7 @@ import android.view.DisplayInfo;
import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.internal.os.BackgroundThread;
import com.android.server.LocalServices;
import com.android.server.display.utils.AmbientFilter;
@@ -155,7 +158,7 @@ public class DisplayModeDirector {
        mAppRequestObserver = new AppRequestObserver();
        mSettingsObserver = new SettingsObserver(context, handler);
        mDisplayObserver = new DisplayObserver(context, handler);
        mBrightnessObserver = new BrightnessObserver(context, handler);
        mBrightnessObserver = new BrightnessObserver(context, handler, injector);
        mUdfpsObserver = new UdfpsObserver();
        final BallotBox ballotBox = (displayId, priority, vote) -> {
            synchronized (mLock) {
@@ -1427,8 +1430,6 @@ public class DisplayModeDirector {
        @Override
        public void onDisplayChanged(int displayId) {
            updateDisplayModes(displayId);
            // TODO: Break the coupling between DisplayObserver and BrightnessObserver.
            mBrightnessObserver.onDisplayChanged(displayId);
        }

        private void updateDisplayModes(int displayId) {
@@ -1465,7 +1466,7 @@ public class DisplayModeDirector {
     * {@link R.array#config_ambientThresholdsOfPeakRefreshRate}.
     */
    @VisibleForTesting
    public class BrightnessObserver extends ContentObserver {
    public class BrightnessObserver implements DisplayManager.DisplayListener {
        private final static int LIGHT_SENSOR_RATE_MS = 250;
        private int[] mLowDisplayBrightnessThresholds;
        private int[] mLowAmbientBrightnessThresholds;
@@ -1488,6 +1489,8 @@ public class DisplayModeDirector {
        private int mBrightness = -1;

        private final Context mContext;
        private final Injector mInjector;
        private final Handler mHandler;

        // Enable light sensor only when mShouldObserveAmbientLowChange is true or
        // mShouldObserveAmbientHighChange is true, screen is on, peak refresh rate
@@ -1500,9 +1503,11 @@ public class DisplayModeDirector {
        private int mRefreshRateInLowZone;
        private int mRefreshRateInHighZone;

        BrightnessObserver(Context context, Handler handler) {
            super(handler);
        BrightnessObserver(Context context, Handler handler, Injector injector) {
            mContext = context;
            mHandler = handler;
            mInjector = injector;

            mLowDisplayBrightnessThresholds = context.getResources().getIntArray(
                    R.array.config_brightnessThresholdsOfPeakRefreshRate);
            mLowAmbientBrightnessThresholds = context.getResources().getIntArray(
@@ -1569,8 +1574,7 @@ public class DisplayModeDirector {
        public void observe(SensorManager sensorManager) {
            mSensorManager = sensorManager;
            final ContentResolver cr = mContext.getContentResolver();
            mBrightness = Settings.System.getIntForUser(cr,
                    Settings.System.SCREEN_BRIGHTNESS, -1 /*default*/, cr.getUserId());
            mBrightness = getBrightness(Display.DEFAULT_DISPLAY);

            // DeviceConfig is accessible after system ready.
            int[] lowDisplayBrightnessThresholds =
@@ -1603,6 +1607,10 @@ public class DisplayModeDirector {

            restartObserver();
            mDeviceConfigDisplaySettings.startListening();

            mInjector.registerDisplayListener(this, mHandler,
                    DisplayManager.EVENT_FLAG_DISPLAY_CHANGED |
                    DisplayManager.EVENT_FLAG_DISPLAY_BRIGHTNESS);
        }

        public void setLoggingEnabled(boolean loggingEnabled) {
@@ -1718,28 +1726,30 @@ public class DisplayModeDirector {
            }
        }

        @Override
        public void onDisplayAdded(int displayId) {}

        @Override
        public void onDisplayRemoved(int displayId) {}

        @Override
        public void onDisplayChanged(int displayId) {
            if (displayId == Display.DEFAULT_DISPLAY) {
                updateDefaultDisplayState();
            }
        }

        @Override
        public void onChange(boolean selfChange, Uri uri, int userId) {
                // We don't support multiple display blocking zones yet, so only handle
                // brightness changes for the default display for now.
                int brightness = getBrightness(displayId);
                synchronized (mLock) {
                final ContentResolver cr = mContext.getContentResolver();
                int brightness = Settings.System.getIntForUser(cr,
                        Settings.System.SCREEN_BRIGHTNESS, -1 /*default*/, cr.getUserId());
                    if (brightness != mBrightness) {
                        mBrightness = brightness;
                        onBrightnessChangedLocked();
                    }
                }
            }
        }

        private void restartObserver() {
            final ContentResolver cr = mContext.getContentResolver();

            if (mRefreshRateInLowZone > 0) {
                mShouldObserveDisplayLowChange = hasValidThreshold(
                        mLowDisplayBrightnessThresholds);
@@ -1760,15 +1770,6 @@ public class DisplayModeDirector {
                mShouldObserveAmbientHighChange = false;
            }

            if (mShouldObserveDisplayLowChange || mShouldObserveDisplayHighChange) {
                // Content Service does not check if an listener has already been registered.
                // To ensure only one listener is registered, force an unregistration first.
                mInjector.unregisterBrightnessObserver(cr, this);
                mInjector.registerBrightnessObserver(cr, this);
            } else {
                mInjector.unregisterBrightnessObserver(cr, this);
            }

            if (mShouldObserveAmbientLowChange || mShouldObserveAmbientHighChange) {
                Resources resources = mContext.getResources();
                String lightSensorType = resources.getString(
@@ -1968,6 +1969,15 @@ public class DisplayModeDirector {
            return mDefaultDisplayState == Display.STATE_ON;
        }

        private int getBrightness(int displayId) {
            final BrightnessInfo info = mInjector.getBrightnessInfo(displayId);
            if (info != null) {
                return BrightnessSynchronizer.brightnessFloatToInt(info.adjustedBrightness);
            }

            return BRIGHTNESS_INVALID;
        }

        private final class LightSensorEventListener implements SensorEventListener {
            final private static int INJECT_EVENTS_INTERVAL_MS = LIGHT_SENSOR_RATE_MS;
            private float mLastSensorData;
@@ -2283,6 +2293,7 @@ public class DisplayModeDirector {
        private final BallotBox mBallotBox;
        private final Handler mHandler;
        private final SparseIntArray mHbmMode = new SparseIntArray();
        private final SparseBooleanArray mHbmActive = new SparseBooleanArray();
        private final Injector mInjector;
        private final DeviceConfigDisplaySettings mDeviceConfigDisplaySettings;
        private int mRefreshRateInHbmSunlight;
@@ -2351,6 +2362,7 @@ public class DisplayModeDirector {
        public void onDisplayRemoved(int displayId) {
            mBallotBox.vote(displayId, Vote.PRIORITY_HIGH_BRIGHTNESS_MODE, null);
            mHbmMode.delete(displayId);
            mHbmActive.delete(displayId);
        }

        @Override
@@ -2360,12 +2372,17 @@ public class DisplayModeDirector {
                // Display no longer there. Assume we'll get an onDisplayRemoved very soon.
                return;
            }

            final int hbmMode = info.highBrightnessMode;
            if (hbmMode == mHbmMode.get(displayId)) {
            final boolean isHbmActive = hbmMode != BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF &&
                info.adjustedBrightness > info.highBrightnessTransitionPoint;
            if (hbmMode == mHbmMode.get(displayId) &&
                isHbmActive == mHbmActive.get(displayId)) {
                // no change, ignore.
                return;
            }
            mHbmMode.put(displayId, hbmMode);
            mHbmActive.put(displayId, isHbmActive);
            recalculateVotesForDisplay(displayId);
        }

@@ -2379,8 +2396,10 @@ public class DisplayModeDirector {
        }

        private void recalculateVotesForDisplay(int displayId) {
            final int hbmMode = mHbmMode.get(displayId, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF);
            Vote vote = null;
            if (mHbmActive.get(displayId, false)) {
                final int hbmMode =
                    mHbmMode.get(displayId, BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF);
                if (hbmMode == BrightnessInfo.HIGH_BRIGHTNESS_MODE_SUNLIGHT) {
                    // Device resource properties take priority over DisplayDeviceConfig
                    if (mRefreshRateInHbmSunlight > 0) {
@@ -2392,15 +2411,21 @@ public class DisplayModeDirector {
                        for (int i = 0; limits != null && i < limits.size(); i++) {
                            final RefreshRateLimitation limitation = limits.get(i);
                            if (limitation.type == REFRESH_RATE_LIMIT_HIGH_BRIGHTNESS_MODE) {
                            vote = Vote.forRefreshRates(limitation.range.min, limitation.range.max);
                                vote = Vote.forRefreshRates(limitation.range.min,
                                        limitation.range.max);
                                break;
                            }
                        }
                    }
            }
            if (hbmMode == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR
                    && mRefreshRateInHbmHdr > 0) {
                } else if (hbmMode == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR &&
                        mRefreshRateInHbmHdr > 0) {
                    // HBM for HDR vote isn't supported through DisplayDeviceConfig yet, so look for
                    // a vote from Device properties
                    vote = Vote.forRefreshRates(mRefreshRateInHbmHdr, mRefreshRateInHbmHdr);
                } else {
                    Slog.w(TAG, "Unexpected HBM mode " + hbmMode + " for display ID " + displayId);
                }

            }
            mBallotBox.vote(displayId, Vote.PRIORITY_HIGH_BRIGHTNESS_MODE, vote);
        }
@@ -2408,6 +2433,7 @@ public class DisplayModeDirector {
        void dumpLocked(PrintWriter pw) {
            pw.println("   HbmObserver");
            pw.println("     mHbmMode: " + mHbmMode);
            pw.println("     mHbmActive: " + mHbmActive);
            pw.println("     mRefreshRateInHbmSunlight: " + mRefreshRateInHbmSunlight);
            pw.println("     mRefreshRateInHbmHdr: " + mRefreshRateInHbmHdr);
        }
@@ -2630,19 +2656,11 @@ public class DisplayModeDirector {
    }

    interface Injector {
        // TODO: brightnessfloat: change this to the float setting
        Uri DISPLAY_BRIGHTNESS_URI = Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS);
        Uri PEAK_REFRESH_RATE_URI = Settings.System.getUriFor(Settings.System.PEAK_REFRESH_RATE);

        @NonNull
        DeviceConfigInterface getDeviceConfig();

        void registerBrightnessObserver(@NonNull ContentResolver cr,
                @NonNull ContentObserver observer);

        void unregisterBrightnessObserver(@NonNull ContentResolver cr,
                @NonNull ContentObserver observer);

        void registerPeakRefreshRateObserver(@NonNull ContentResolver cr,
                @NonNull ContentObserver observer);

@@ -2671,19 +2689,6 @@ public class DisplayModeDirector {
            return DeviceConfigInterface.REAL;
        }

        @Override
        public void registerBrightnessObserver(@NonNull ContentResolver cr,
                @NonNull ContentObserver observer) {
            cr.registerContentObserver(DISPLAY_BRIGHTNESS_URI, false /*notifyDescendants*/,
                    observer, UserHandle.USER_SYSTEM);
        }

        @Override
        public void unregisterBrightnessObserver(@NonNull ContentResolver cr,
                @NonNull ContentObserver observer) {
            cr.unregisterContentObserver(observer);
        }

        @Override
        public void registerPeakRefreshRateObserver(@NonNull ContentResolver cr,
                @NonNull ContentObserver observer) {
+29 −5
Original line number Diff line number Diff line
@@ -1259,10 +1259,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            putScreenBrightnessSetting(brightnessState, /* updateCurrent */ true);
        }

        // We save the brightness info *after* the brightness setting has been changed so that
        // the brightness info reflects the latest value.
        saveBrightnessInfo(getScreenBrightnessSetting());

        // Apply dimming by at least some minimum amount when user activity
        // timeout is about to expire.
        if (mPowerRequest.policy == DisplayPowerRequest.POLICY_DIM) {
@@ -1393,6 +1389,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        hadUserBrightnessPoint);
            }

            // We save the brightness info *after* the brightness setting has been changed and
            // adjustments made so that the brightness info reflects the latest value.
            saveBrightnessInfo(getScreenBrightnessSetting(), animateValue);
        } else {
            saveBrightnessInfo(getScreenBrightnessSetting());
        }

        // Log any changes to what is currently driving the brightness setting.
@@ -1509,18 +1510,27 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        synchronized (mCachedBrightnessInfo) {
            return new BrightnessInfo(
                    mCachedBrightnessInfo.brightness,
                    mCachedBrightnessInfo.adjustedBrightness,
                    mCachedBrightnessInfo.brightnessMin,
                    mCachedBrightnessInfo.brightnessMax,
                    mCachedBrightnessInfo.hbmMode);
                    mCachedBrightnessInfo.hbmMode,
                    mCachedBrightnessInfo.highBrightnessTransitionPoint);
        }
    }

    private void saveBrightnessInfo(float brightness) {
        saveBrightnessInfo(brightness, brightness);
    }

    private void saveBrightnessInfo(float brightness, float adjustedBrightness) {
        synchronized (mCachedBrightnessInfo) {
            mCachedBrightnessInfo.brightness = brightness;
            mCachedBrightnessInfo.adjustedBrightness = adjustedBrightness;
            mCachedBrightnessInfo.brightnessMin = mHbmController.getCurrentBrightnessMin();
            mCachedBrightnessInfo.brightnessMax = mHbmController.getCurrentBrightnessMax();
            mCachedBrightnessInfo.hbmMode = mHbmController.getHighBrightnessMode();
            mCachedBrightnessInfo.highBrightnessTransitionPoint =
                mHbmController.getTransitionPoint();
        }
    }

@@ -2195,6 +2205,18 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        pw.println("  mSkipScreenOnBrightnessRamp=" + mSkipScreenOnBrightnessRamp);
        pw.println("  mColorFadeFadesConfig=" + mColorFadeFadesConfig);
        pw.println("  mColorFadeEnabled=" + mColorFadeEnabled);
        synchronized (mCachedBrightnessInfo) {
            pw.println("  mCachedBrightnessInfo.brightness=" + mCachedBrightnessInfo.brightness);
            pw.println("  mCachedBrightnessInfo.adjustedBrightness=" +
                    mCachedBrightnessInfo.adjustedBrightness);
            pw.println("  mCachedBrightnessInfo.brightnessMin=" +
                    mCachedBrightnessInfo.brightnessMin);
            pw.println("  mCachedBrightnessInfo.brightnessMax=" +
                    mCachedBrightnessInfo.brightnessMax);
            pw.println("  mCachedBrightnessInfo.hbmMode=" + mCachedBrightnessInfo.hbmMode);
            pw.println("  mCachedBrightnessInfo.highBrightnessTransitionPoint=" +
                    mCachedBrightnessInfo.highBrightnessTransitionPoint);
        }
        pw.println("  mDisplayBlanksAfterDozeConfig=" + mDisplayBlanksAfterDozeConfig);
        pw.println("  mBrightnessBucketsInDozeConfig=" + mBrightnessBucketsInDozeConfig);

@@ -2606,8 +2628,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

    static class CachedBrightnessInfo {
        public float brightness;
        public float adjustedBrightness;
        public float brightnessMin;
        public float brightnessMax;
        public int hbmMode;
        public float highBrightnessTransitionPoint;
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@ class HighBrightnessModeController {

    private static final float HDR_PERCENT_OF_SCREEN_REQUIRED = 0.50f;

    @VisibleForTesting
    static final float HBM_TRANSITION_POINT_INVALID = Float.POSITIVE_INFINITY;

    private final float mBrightnessMin;
    private final float mBrightnessMax;
    private final Handler mHandler;
@@ -214,6 +217,14 @@ class HighBrightnessModeController {
        return mHbmMode;
    }

    float getTransitionPoint() {
        if (deviceSupportsHbm()) {
            return mHbmData.transitionPoint;
        } else {
            return HBM_TRANSITION_POINT_INVALID;
        }
    }

    void stop() {
        registerHdrListener(null /*displayToken*/);
        mSkinThermalStatusObserver.stopObserving();
+169 −49

File changed.

Preview size limit exceeded, changes collapsed.

Loading