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

Commit c1a0bbc9 authored by Kriti Dang's avatar Kriti Dang Committed by Automerger Merge Worker
Browse files

Merge "Make brightness per-user in PersistentDataStore" into udc-qpr-dev am: cc63ab71

parents 37455637 cc63ab71
Loading
Loading
Loading
Loading
+13 −4
Original line number Original line Diff line number Diff line
@@ -40,6 +40,7 @@ public class BrightnessSetting {


    private final LogicalDisplay mLogicalDisplay;
    private final LogicalDisplay mLogicalDisplay;


    private int mUserSerial;
    private final Handler mHandler = new Handler(Looper.getMainLooper()) {
    private final Handler mHandler = new Handler(Looper.getMainLooper()) {
        @Override
        @Override
        public void handleMessage(Message msg) {
        public void handleMessage(Message msg) {
@@ -56,13 +57,15 @@ public class BrightnessSetting {
    @GuardedBy("mSyncRoot")
    @GuardedBy("mSyncRoot")
    private float mBrightness;
    private float mBrightness;


    BrightnessSetting(@NonNull PersistentDataStore persistentDataStore,
    BrightnessSetting(int userSerial,
            @NonNull PersistentDataStore persistentDataStore,
            @NonNull LogicalDisplay logicalDisplay,
            @NonNull LogicalDisplay logicalDisplay,
            DisplayManagerService.SyncRoot syncRoot) {
            DisplayManagerService.SyncRoot syncRoot) {
        mPersistentDataStore = persistentDataStore;
        mPersistentDataStore = persistentDataStore;
        mLogicalDisplay = logicalDisplay;
        mLogicalDisplay = logicalDisplay;
        mUserSerial = userSerial;
        mBrightness = mPersistentDataStore.getBrightness(
        mBrightness = mPersistentDataStore.getBrightness(
                mLogicalDisplay.getPrimaryDisplayDeviceLocked());
                mLogicalDisplay.getPrimaryDisplayDeviceLocked(), userSerial);
        mSyncRoot = syncRoot;
        mSyncRoot = syncRoot;
    }
    }


@@ -96,8 +99,13 @@ public class BrightnessSetting {
        mListeners.remove(l);
        mListeners.remove(l);
    }
    }


    /** Sets the user serial for the brightness setting */
    public void setUserSerial(int userSerial) {
        mUserSerial = userSerial;
    }

    /**
    /**
     * Sets the brigtness and broadcasts the change to the listeners.
     * Sets the brightness and broadcasts the change to the listeners.
     * @param brightness The value to which the brightness is to be set.
     * @param brightness The value to which the brightness is to be set.
     */
     */
    public void setBrightness(float brightness) {
    public void setBrightness(float brightness) {
@@ -112,7 +120,8 @@ public class BrightnessSetting {
            // changed.
            // changed.
            if (brightness != mBrightness) {
            if (brightness != mBrightness) {
                mPersistentDataStore.setBrightness(mLogicalDisplay.getPrimaryDisplayDeviceLocked(),
                mPersistentDataStore.setBrightness(mLogicalDisplay.getPrimaryDisplayDeviceLocked(),
                        brightness);
                        brightness, mUserSerial
                );
            }
            }
            mBrightness = brightness;
            mBrightness = brightness;
            int toSend = Float.floatToIntBits(mBrightness);
            int toSend = Float.floatToIntBits(mBrightness);
+9 −2
Original line number Original line Diff line number Diff line
@@ -652,6 +652,12 @@ public final class DisplayManagerService extends SystemService {
                            logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId(),
                            logicalDisplay.getPrimaryDisplayDeviceLocked().getUniqueId(),
                            userSerial);
                            userSerial);
                    dpc.setBrightnessConfiguration(config, /* shouldResetShortTermModel= */ true);
                    dpc.setBrightnessConfiguration(config, /* shouldResetShortTermModel= */ true);
                    // change the brightness value according to the selected user.
                    final DisplayDevice device = logicalDisplay.getPrimaryDisplayDeviceLocked();
                    if (device != null) {
                        dpc.setBrightness(
                                mPersistentDataStore.getBrightness(device, userSerial), userSerial);
                    }
                }
                }
                dpc.onSwitchUser(newUserId);
                dpc.onSwitchUser(newUserId);
            });
            });
@@ -3134,8 +3140,9 @@ public final class DisplayManagerService extends SystemService {
            mBrightnessTracker = new BrightnessTracker(mContext, null);
            mBrightnessTracker = new BrightnessTracker(mContext, null);
        }
        }


        final BrightnessSetting brightnessSetting = new BrightnessSetting(mPersistentDataStore,
        final int userSerial = getUserManager().getUserSerialNumber(mContext.getUserId());
                display, mSyncRoot);
        final BrightnessSetting brightnessSetting = new BrightnessSetting(userSerial,
                mPersistentDataStore, display, mSyncRoot);
        final DisplayPowerControllerInterface displayPowerController;
        final DisplayPowerControllerInterface displayPowerController;


        // If display is internal and has a HighBrightnessModeMetadata mapping, use that.
        // If display is internal and has a HighBrightnessModeMetadata mapping, use that.
+2 −1
Original line number Original line Diff line number Diff line
@@ -2664,9 +2664,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }
    }


    @Override
    @Override
    public void setBrightness(float brightnessValue) {
    public void setBrightness(float brightnessValue, int userSerial) {
        // Update the setting, which will eventually call back into DPC to have us actually update
        // Update the setting, which will eventually call back into DPC to have us actually update
        // the display with the new value.
        // the display with the new value.
        mBrightnessSetting.setUserSerial(userSerial);
        mBrightnessSetting.setBrightness(brightnessValue);
        mBrightnessSetting.setBrightness(brightnessValue);
        if (mDisplayId == Display.DEFAULT_DISPLAY && mPersistBrightnessNitsForDefaultDisplay) {
        if (mDisplayId == Display.DEFAULT_DISPLAY && mPersistBrightnessNitsForDefaultDisplay) {
            float nits = convertToNits(brightnessValue);
            float nits = convertToNits(brightnessValue);
+2 −2
Original line number Original line Diff line number Diff line
@@ -2172,8 +2172,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    }
    }


    @Override
    @Override
    public void setBrightness(float brightnessValue) {
    public void setBrightness(float brightnessValue, int userSerial) {
        mDisplayBrightnessController.setBrightness(brightnessValue);
        mDisplayBrightnessController.setBrightness(brightnessValue, userSerial);
    }
    }


    @Override
    @Override
+12 −2
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ import java.io.PrintWriter;
 * An interface to manage the display's power state and brightness
 * An interface to manage the display's power state and brightness
 */
 */
public interface DisplayPowerControllerInterface {
public interface DisplayPowerControllerInterface {

    int DEFAULT_USER_SERIAL = -1;
    /**
    /**
     * Notified when the display is changed.
     * Notified when the display is changed.
     *
     *
@@ -98,7 +98,17 @@ public interface DisplayPowerControllerInterface {
     * Set the screen brightness of the associated display
     * Set the screen brightness of the associated display
     * @param brightness The value to which the brightness is to be set
     * @param brightness The value to which the brightness is to be set
     */
     */
    void setBrightness(float brightness);
    default void setBrightness(float brightness) {
        setBrightness(brightness, DEFAULT_USER_SERIAL);
    }

    /**
     * Set the screen brightness of the associated display
     * @param brightness The value to which the brightness is to be set
     * @param userSerial The user for which the brightness value is to be set. Use userSerial = -1,
     * if brightness needs to be updated for the current user.
     */
    void setBrightness(float brightness, int userSerial);


    /**
    /**
     * Checks if the proximity sensor is available
     * Checks if the proximity sensor is available
Loading