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

Commit 69a1db09 authored by Fiona Campbell's avatar Fiona Campbell
Browse files

Add DisplayId to BrightnessTracker

BrightnessTracker is now global.
Pass in the physicaldisplayid of the primary display device of the
logical display that the display power controller is associated with.
This is so that we can determine the brightness changes for each
physical screen.

Bug: 181767734
Test: manual
Change-Id: Iaebb12ec5fe7785545374cc639d7a345ca469db8
parent dabf902d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3016,6 +3016,7 @@ package android.hardware.display {
    field public final float reduceBrightColorsOffset;
    field public final int reduceBrightColorsStrength;
    field public final long timeStamp;
    field @NonNull public final String uniqueDisplayId;
  }
  public final class BrightnessConfiguration implements android.os.Parcelable {
+23 −8
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ public final class BrightnessChangeEvent implements Parcelable {
     * @hide */
    public final int userId;

    /** The unique id of the screen on which the brightness was changed */
    @NonNull
    public final String uniqueDisplayId;

    /** Lux values of recent sensor data */
    public final float[] luxValues;

@@ -120,15 +124,16 @@ public final class BrightnessChangeEvent implements Parcelable {

    /** @hide */
    private BrightnessChangeEvent(float brightness, long timeStamp, String packageName,
            int userId, float[] luxValues, long[] luxTimestamps, float batteryLevel,
            float powerBrightnessFactor, boolean nightMode, int colorTemperature,
            boolean reduceBrightColors, int reduceBrightColorsStrength,
            int userId, String uniqueDisplayId, float[] luxValues, long[] luxTimestamps,
            float batteryLevel, float powerBrightnessFactor, boolean nightMode,
            int colorTemperature, boolean reduceBrightColors, int reduceBrightColorsStrength,
            float reduceBrightColorsOffset, float lastBrightness, boolean isDefaultBrightnessConfig,
            boolean isUserSetBrightness, long[] colorValueBuckets, long colorSampleDuration) {
        this.brightness = brightness;
        this.timeStamp = timeStamp;
        this.packageName = packageName;
        this.userId = userId;
        this.uniqueDisplayId = uniqueDisplayId;
        this.luxValues = luxValues;
        this.luxTimestamps = luxTimestamps;
        this.batteryLevel = batteryLevel;
@@ -151,6 +156,7 @@ public final class BrightnessChangeEvent implements Parcelable {
        this.timeStamp = other.timeStamp;
        this.packageName = redactPackage ? null : other.packageName;
        this.userId = other.userId;
        this.uniqueDisplayId = other.uniqueDisplayId;
        this.luxValues = other.luxValues;
        this.luxTimestamps = other.luxTimestamps;
        this.batteryLevel = other.batteryLevel;
@@ -172,6 +178,7 @@ public final class BrightnessChangeEvent implements Parcelable {
        timeStamp = source.readLong();
        packageName = source.readString();
        userId = source.readInt();
        uniqueDisplayId = source.readString();
        luxValues = source.createFloatArray();
        luxTimestamps = source.createLongArray();
        batteryLevel = source.readFloat();
@@ -209,6 +216,7 @@ public final class BrightnessChangeEvent implements Parcelable {
        dest.writeLong(timeStamp);
        dest.writeString(packageName);
        dest.writeInt(userId);
        dest.writeString(uniqueDisplayId);
        dest.writeFloatArray(luxValues);
        dest.writeLongArray(luxTimestamps);
        dest.writeFloat(batteryLevel);
@@ -231,6 +239,7 @@ public final class BrightnessChangeEvent implements Parcelable {
        private long mTimeStamp;
        private String mPackageName;
        private int mUserId;
        private String mUniqueDisplayId;
        private float[] mLuxValues;
        private long[] mLuxTimestamps;
        private float mBatteryLevel;
@@ -270,6 +279,12 @@ public final class BrightnessChangeEvent implements Parcelable {
            return this;
        }

        /** {@see BrightnessChangeEvent#uniqueScreenId} */
        public Builder setUniqueDisplayId(String uniqueId) {
            mUniqueDisplayId = uniqueId;
            return this;
        }

        /** {@see BrightnessChangeEvent#luxValues} */
        public Builder setLuxValues(float[] luxValues) {
            mLuxValues = luxValues;
@@ -354,11 +369,11 @@ public final class BrightnessChangeEvent implements Parcelable {
        /** Builds a BrightnessChangeEvent */
        public BrightnessChangeEvent build() {
            return new BrightnessChangeEvent(mBrightness, mTimeStamp,
                    mPackageName, mUserId, mLuxValues, mLuxTimestamps, mBatteryLevel,
                    mPowerBrightnessFactor, mNightMode, mColorTemperature, mReduceBrightColors,
                    mReduceBrightColorsStrength, mReduceBrightColorsOffset, mLastBrightness,
                    mIsDefaultBrightnessConfig, mIsUserSetBrightness, mColorValueBuckets,
                    mColorSampleDuration);
                    mPackageName, mUserId, mUniqueDisplayId, mLuxValues, mLuxTimestamps,
                    mBatteryLevel, mPowerBrightnessFactor, mNightMode, mColorTemperature,
                    mReduceBrightColors, mReduceBrightColorsStrength, mReduceBrightColorsOffset,
                    mLastBrightness, mIsDefaultBrightnessConfig, mIsUserSetBrightness,
                    mColorValueBuckets, mColorSampleDuration);
        }
    }
}
+21 −10
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ public class BrightnessTracker {
    private static final String ATTR_TIMESTAMP = "timestamp";
    private static final String ATTR_PACKAGE_NAME = "packageName";
    private static final String ATTR_USER = "user";
    private static final String ATTR_UNIQUE_DISPLAY_ID = "uniqueDisplayId";
    private static final String ATTR_LUX = "lux";
    private static final String ATTR_LUX_TIMESTAMPS = "luxTimestamps";
    private static final String ATTR_BATTERY_LEVEL = "batteryLevel";
@@ -217,6 +218,9 @@ public class BrightnessTracker {
    }

    private void backgroundStart(float initialBrightness) {
        if (DEBUG) {
            Slog.d(TAG, "Background start");
        }
        readEvents();
        readAmbientBrightnessStats();

@@ -311,7 +315,7 @@ public class BrightnessTracker {
     */
    public void notifyBrightnessChanged(float brightness, boolean userInitiated,
            float powerBrightnessFactor, boolean isUserSetBrightness,
            boolean isDefaultBrightnessConfig) {
            boolean isDefaultBrightnessConfig, String uniqueDisplayId) {
        if (DEBUG) {
            Slog.d(TAG, String.format("notifyBrightnessChanged(brightness=%f, userInitiated=%b)",
                        brightness, userInitiated));
@@ -319,13 +323,13 @@ public class BrightnessTracker {
        Message m = mBgHandler.obtainMessage(MSG_BRIGHTNESS_CHANGED,
                userInitiated ? 1 : 0, 0 /*unused*/, new BrightnessChangeValues(brightness,
                        powerBrightnessFactor, isUserSetBrightness, isDefaultBrightnessConfig,
                        mInjector.currentTimeMillis()));
                        mInjector.currentTimeMillis(), uniqueDisplayId));
        m.sendToTarget();
    }

    private void handleBrightnessChanged(float brightness, boolean userInitiated,
            float powerBrightnessFactor, boolean isUserSetBrightness,
            boolean isDefaultBrightnessConfig, long timestamp) {
            boolean isDefaultBrightnessConfig, long timestamp, String uniqueDisplayId) {
        BrightnessChangeEvent.Builder builder;

        synchronized (mDataCollectionLock) {
@@ -350,6 +354,7 @@ public class BrightnessTracker {
            builder.setPowerBrightnessFactor(powerBrightnessFactor);
            builder.setUserBrightnessPoint(isUserSetBrightness);
            builder.setIsDefaultBrightnessConfig(isDefaultBrightnessConfig);
            builder.setUniqueDisplayId(uniqueDisplayId);

            final int readingCount = mLastSensorReadings.size();
            if (readingCount == 0) {
@@ -562,6 +567,7 @@ public class BrightnessTracker {
                out.attributeLong(null, ATTR_TIMESTAMP, toWrite[i].timeStamp);
                out.attribute(null, ATTR_PACKAGE_NAME, toWrite[i].packageName);
                out.attributeInt(null, ATTR_USER, userSerialNo);
                out.attribute(null, ATTR_UNIQUE_DISPLAY_ID, toWrite[i].uniqueDisplayId);
                out.attributeFloat(null, ATTR_BATTERY_LEVEL, toWrite[i].batteryLevel);
                out.attributeBoolean(null, ATTR_NIGHT_MODE, toWrite[i].nightMode);
                out.attributeInt(null, ATTR_COLOR_TEMPERATURE,
@@ -646,6 +652,8 @@ public class BrightnessTracker {
                    builder.setPackageName(parser.getAttributeValue(null, ATTR_PACKAGE_NAME));
                    builder.setUserId(mInjector.getUserId(mUserManager,
                            parser.getAttributeInt(null, ATTR_USER)));
                    builder.setUniqueDisplayId(
                            parser.getAttributeValue(null, ATTR_UNIQUE_DISPLAY_ID));
                    builder.setBatteryLevel(parser.getAttributeFloat(null, ATTR_BATTERY_LEVEL));
                    builder.setNightMode(parser.getAttributeBoolean(null, ATTR_NIGHT_MODE));
                    builder.setColorTemperature(
@@ -980,7 +988,8 @@ public class BrightnessTracker {
                    boolean userInitiatedChange = (msg.arg1 == 1);
                    handleBrightnessChanged(values.brightness, userInitiatedChange,
                            values.powerBrightnessFactor, values.isUserSetBrightness,
                            values.isDefaultBrightnessConfig, values.timestamp);
                            values.isDefaultBrightnessConfig, values.timestamp,
                            values.uniqueDisplayId);
                    break;
                case MSG_START_SENSOR_LISTENER:
                    startSensorListener();
@@ -1007,20 +1016,22 @@ public class BrightnessTracker {
    }

    private static class BrightnessChangeValues {
        final float brightness;
        final float powerBrightnessFactor;
        final boolean isUserSetBrightness;
        final boolean isDefaultBrightnessConfig;
        final long timestamp;
        public final float brightness;
        public final float powerBrightnessFactor;
        public final boolean isUserSetBrightness;
        public final boolean isDefaultBrightnessConfig;
        public final long timestamp;
        public final String uniqueDisplayId;

        BrightnessChangeValues(float brightness, float powerBrightnessFactor,
                boolean isUserSetBrightness, boolean isDefaultBrightnessConfig,
                long timestamp) {
                long timestamp, String uniqueDisplayId) {
            this.brightness = brightness;
            this.powerBrightnessFactor = powerBrightnessFactor;
            this.isUserSetBrightness = isUserSetBrightness;
            this.isDefaultBrightnessConfig = isDefaultBrightnessConfig;
            this.timestamp = timestamp;
            this.uniqueDisplayId = uniqueDisplayId;
        }
    }

+11 −3
Original line number Diff line number Diff line
@@ -376,6 +376,8 @@ public final class DisplayManagerService extends SystemService {
    private final ColorSpace mWideColorSpace;

    private SensorManager mSensorManager;
    private BrightnessTracker mBrightnessTracker;


    // Whether minimal post processing is allowed by the user.
    @GuardedBy("mSyncRoot")
@@ -1162,7 +1164,7 @@ public final class DisplayManagerService extends SystemService {

        DisplayPowerController dpc = mDisplayPowerControllers.get(displayId);
        if (dpc != null) {
            dpc.onDisplayChanged();
            dpc.onDisplayChangedLocked();
        }
    }

@@ -1852,7 +1854,10 @@ public final class DisplayManagerService extends SystemService {
            for (int i = 0; i < displayPowerControllerCount; i++) {
                mDisplayPowerControllers.valueAt(i).dump(pw);
            }

            if (mBrightnessTracker != null) {
                pw.println();
                mBrightnessTracker.dump(pw);
            }
            pw.println();
            mPersistentDataStore.dump(pw);
        }
@@ -1938,9 +1943,12 @@ public final class DisplayManagerService extends SystemService {
            // initPowerManagement has not yet been called.
            return;
        }
        if (mBrightnessTracker == null) {
            mBrightnessTracker = new BrightnessTracker(mContext, null);
        }
        final DisplayPowerController displayPowerController = new DisplayPowerController(
                mContext, mDisplayPowerCallbacks, mPowerHandler, mSensorManager,
                mDisplayBlanker, display);
                mDisplayBlanker, display, mBrightnessTracker);
        mDisplayPowerControllers.append(display.getDisplayIdLocked(), displayPowerController);
    }

+10 −14
Original line number Diff line number Diff line
@@ -174,6 +174,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // The ID of the LogicalDisplay tied to this DisplayPowerController.
    private final int mDisplayId;

    // The unique ID of the primary display device currently tied to this logical display
    private String mUniqueDisplayId;

    // Tracker for brightness changes.
    @Nullable
    private final BrightnessTracker mBrightnessTracker;
@@ -413,16 +416,15 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
     */
    public DisplayPowerController(Context context,
            DisplayPowerCallbacks callbacks, Handler handler,
            SensorManager sensorManager, DisplayBlanker blanker, LogicalDisplay logicalDisplay) {
            SensorManager sensorManager, DisplayBlanker blanker, LogicalDisplay logicalDisplay,
            BrightnessTracker brightnessTracker) {
        mLogicalDisplay = logicalDisplay;
        mDisplayId = mLogicalDisplay.getDisplayIdLocked();
        mHandler = new DisplayControllerHandler(handler.getLooper());

        if (mDisplayId == Display.DEFAULT_DISPLAY) {
            mBrightnessTracker = new BrightnessTracker(context, null);
            mBatteryStats = BatteryStatsService.getService();
        } else {
            mBrightnessTracker = null;
            mBatteryStats = null;
        }

@@ -432,6 +434,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class);
        mBlanker = blanker;
        mContext = context;
        mBrightnessTracker = brightnessTracker;

        PowerManager pm = context.getSystemService(PowerManager.class);

@@ -750,8 +753,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
     * when displays get swapped on foldable devices.  For example, different brightness properties
     * of each display need to be properly reflected in AutomaticBrightnessController.
     */
    public void onDisplayChanged() {
    public void onDisplayChangedLocked() {
        // TODO: b/175821789 - Support high brightness on multiple (folding) displays

        mUniqueDisplayId = mLogicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId();
    }

    /**
@@ -774,10 +779,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                mAutomaticBrightnessController.stop();
            }

            if (mBrightnessTracker != null) {
                mBrightnessTracker.stop();
            }

            mContext.getContentResolver().unregisterContentObserver(mSettingsObserver);
        }
    }
@@ -1868,7 +1869,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    : 1.0f;
            mBrightnessTracker.notifyBrightnessChanged(brightnessInNits, userInitiated,
                    powerFactor, hadUserDataPoint,
                    mAutomaticBrightnessController.isDefaultConfig());
                    mAutomaticBrightnessController.isDefaultConfig(), mUniqueDisplayId);
        }
    }

@@ -2036,11 +2037,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            mAutomaticBrightnessController.dump(pw);
        }

        if (mBrightnessTracker != null) {
            pw.println();
            mBrightnessTracker.dump(pw);
        }

        pw.println();
        if (mDisplayWhiteBalanceController != null) {
            mDisplayWhiteBalanceController.dump(pw);
Loading