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

Commit 48df7d18 authored by Fiona Campbell's avatar Fiona Campbell
Browse files

Add config.xml fallback in DisplayDeviceConfig

This change adds the default brightness to the ddc, and a fallback to
config.xml when the ddc doesn't exist.

It adds the minimum and maximum brightness constrtaints to the display
device config - which are currently sourced from config.xml.

Bug: 147415200
Test: manual

Change-Id: Ibbfbbbd495048114befb3f867bd5f4e26916ca9e
parent b4766c20
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -686,6 +686,19 @@ public final class Display {
        }
    }

    /**
     * Gets the default brightness configured for the display.
     *
     * @return Default brightness between 0.0-1.0
     * @hide
     */
    public float getBrightnessDefault() {
        synchronized (this) {
            updateDisplayInfoLocked();
            return mDisplayInfo.brightnessDefault;
        }
    }

    /**
     * Gets the size of the display, in pixels.
     * Value returned by this method does not necessarily represent the actual raw size
+40 −2
Original line number Diff line number Diff line
@@ -275,6 +275,27 @@ public final class DisplayInfo implements Parcelable {
    // TODO (b/114338689): Remove the flag and use IWindowManager#getRemoveContentMode
    public int removeMode = Display.REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY;

    /**
     * @hide
     * The current minimum brightness constraint of the display. Value between 0.0 and 1.0,
     * derived from the config constraints of the display device of this logical display.
     */
    public float brightnessMinimum;

    /**
     * @hide
     * The current maximum brightness constraint of the display. Value between 0.0 and 1.0,
     * derived from the config constraints of the display device of this logical display.
     */
    public float brightnessMaximum;

    /**
     * @hide
     * The current default brightness of the display. Value between 0.0 and 1.0,
     * derived from the configuration of the display device of this logical display.
     */
    public float brightnessDefault;

    public static final @android.annotation.NonNull Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
        @Override
        public DisplayInfo createFromParcel(Parcel source) {
@@ -339,7 +360,10 @@ public final class DisplayInfo implements Parcelable {
                && ownerUid == other.ownerUid
                && Objects.equals(ownerPackageName, other.ownerPackageName)
                && removeMode == other.removeMode
                && refreshRateOverride == other.refreshRateOverride;
                && refreshRateOverride == other.refreshRateOverride
                && brightnessMinimum == other.brightnessMinimum
                && brightnessMaximum == other.brightnessMaximum
                && brightnessDefault == other.brightnessDefault;
    }

    @Override
@@ -384,6 +408,9 @@ public final class DisplayInfo implements Parcelable {
        ownerPackageName = other.ownerPackageName;
        removeMode = other.removeMode;
        refreshRateOverride = other.refreshRateOverride;
        brightnessMinimum = other.brightnessMinimum;
        brightnessMaximum = other.brightnessMaximum;
        brightnessDefault = other.brightnessDefault;
    }

    public void readFromParcel(Parcel source) {
@@ -430,6 +457,9 @@ public final class DisplayInfo implements Parcelable {
        uniqueId = source.readString8();
        removeMode = source.readInt();
        refreshRateOverride = source.readFloat();
        brightnessMinimum = source.readFloat();
        brightnessMaximum = source.readFloat();
        brightnessDefault = source.readFloat();
    }

    @Override
@@ -475,6 +505,9 @@ public final class DisplayInfo implements Parcelable {
        dest.writeString8(uniqueId);
        dest.writeInt(removeMode);
        dest.writeFloat(refreshRateOverride);
        dest.writeFloat(brightnessMinimum);
        dest.writeFloat(brightnessMaximum);
        dest.writeFloat(brightnessDefault);
    }

    @Override
@@ -698,7 +731,12 @@ public final class DisplayInfo implements Parcelable {
        sb.append(removeMode);
        sb.append(", refreshRateOverride ");
        sb.append(refreshRateOverride);

        sb.append(", brightnessMinimum ");
        sb.append(brightnessMinimum);
        sb.append(", brightnessMaximum ");
        sb.append(brightnessMaximum);
        sb.append(", brightnessDefault ");
        sb.append(brightnessDefault);
        sb.append("}");
        return sb.toString();
    }
+6 −10
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.res.TypedArray;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.graphics.RectF;
import android.hardware.display.DisplayManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
import android.hardware.fingerprint.IUdfpsOverlayController;
@@ -166,7 +167,7 @@ class UdfpsController implements DozeReceiver {
            @Main Resources resources,
            LayoutInflater inflater,
            @Nullable FingerprintManager fingerprintManager,
            PowerManager powerManager,
            DisplayManager displayManager,
            WindowManager windowManager,
            SystemSettings systemSettings,
            @NonNull StatusBarStateController statusBarStateController,
@@ -246,7 +247,7 @@ class UdfpsController implements DozeReceiver {

        mBacklightToNitsSpline = Spline.createSpline(normalizedBacklightRange, nitsRange);
        mNitsToHbmBacklightSpline = Spline.createSpline(hbmNitsRange, normalizedBacklightRange);
        mDefaultBrightness = obtainDefaultBrightness(powerManager);
        mDefaultBrightness = obtainDefaultBrightness(mContext);

        // TODO(b/160025856): move to the "dump" method.
        Log.v(TAG, String.format("ctor | mNitsRange: [%f, %f]", nitsRange[0],
@@ -450,14 +451,9 @@ class UdfpsController implements DozeReceiver {
        }
    }

    private static float obtainDefaultBrightness(PowerManager powerManager) {
        if (powerManager == null) {
            Log.e(TAG, "PowerManager is unavailable. Can't obtain default brightness.");
            return 0f;
        }
        return MathUtils.constrain(powerManager.getBrightnessConstraint(
                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_DEFAULT), PowerManager.BRIGHTNESS_MIN,
                PowerManager.BRIGHTNESS_MAX);
    private static float obtainDefaultBrightness(Context context) {
        return MathUtils.constrain(context.getDisplay().getBrightnessDefault(),
                PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX);
    }

    private static float[] toFloatArray(TypedArray array) {
+1 −2
Original line number Diff line number Diff line
@@ -316,8 +316,7 @@ public class BrightnessController implements ToggleSlider.Listener {
                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM);
        mMaximumBacklight = pm.getBrightnessConstraint(
                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MAXIMUM);
        mDefaultBacklight = pm.getBrightnessConstraint(
                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_DEFAULT);
        mDefaultBacklight = mContext.getDisplay().getBrightnessDefault();
        mMinimumBacklightForVr = pm.getBrightnessConstraint(
                PowerManager.BRIGHTNESS_CONSTRAINT_TYPE_MINIMUM_VR);
        mMaximumBacklightForVr = pm.getBrightnessConstraint(
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.hardware.biometrics.SensorProperties;
import android.hardware.display.DisplayManager;
import android.hardware.fingerprint.FingerprintManager;
import android.hardware.fingerprint.FingerprintSensorProperties;
import android.hardware.fingerprint.FingerprintSensorPropertiesInternal;
@@ -84,7 +85,7 @@ public class UdfpsControllerTest extends SysuiTestCase {
    @Mock
    private FingerprintManager mFingerprintManager;
    @Mock
    private PowerManager mPowerManager;
    private DisplayManager mDisplayManager;
    @Mock
    private WindowManager mWindowManager;
    @Mock
@@ -124,7 +125,7 @@ public class UdfpsControllerTest extends SysuiTestCase {
                mResources,
                mLayoutInflater,
                mFingerprintManager,
                mPowerManager,
                mDisplayManager,
                mWindowManager,
                mSystemSettings,
                mStatusBarStateController,
Loading