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

Commit 122df868 authored by Dan Gittik's avatar Dan Gittik
Browse files

Added system-wide minimum brightness curve.

The minimum brightness curve guarantess that any brightness curve
that dips below it is rejected by the system.
This prevent auto-brightness from setting the screen so dark as to
prevent the user from resetting or disabling it, and maps lux to
the absolute minimum nits that are still readable in that ambient
brightness.

Test: atest BrightnessConfigurationTest.

Fixes: 77176207

Change-Id: Ibd1e83e9b147f3849d6c907f828cbe5950c8367f
parent b175d0db
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1252,6 +1252,7 @@ package android.hardware.display {
    method public android.hardware.display.BrightnessConfiguration getBrightnessConfiguration();
    method public java.util.List<android.hardware.display.BrightnessChangeEvent> getBrightnessEvents();
    method public android.hardware.display.BrightnessConfiguration getDefaultBrightnessConfiguration();
    method public android.util.Pair<float[], float[]> getMinimumBrightnessCurve();
    method public android.graphics.Point getStableDisplaySize();
    method public void setBrightnessConfiguration(android.hardware.display.BrightnessConfiguration);
    method public void setSaturationLevel(float);
+6 −2
Original line number Diff line number Diff line
@@ -86,7 +86,9 @@ public final class BrightnessConfiguration implements Parcelable {
            sb.append("(").append(mLux[i]).append(", ").append(mNits[i]).append(")");
        }
        sb.append("], '");
        if (mDescription != null) {
            sb.append(mDescription);
        }
        sb.append("'}");
        return sb.toString();
    }
@@ -96,7 +98,9 @@ public final class BrightnessConfiguration implements Parcelable {
        int result = 1;
        result = result * 31 + Arrays.hashCode(mLux);
        result = result * 31 + Arrays.hashCode(mNits);
        if (mDescription != null) {
            result = result * 31 + mDescription.hashCode();
        }
        return result;
    }

+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.display;

parcelable Curve;
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.display;

import android.os.Parcel;
import android.os.Parcelable;

/** @hide */
public final class Curve implements Parcelable {
    private final float[] mX;
    private final float[] mY;

    public Curve(float[] x, float[] y) {
        mX = x;
        mY = y;
    }

    public float[] getX() {
        return mX;
    }

    public float[] getY() {
        return mY;
    }

    public static final Creator<Curve> CREATOR = new Creator<Curve>() {
        public Curve createFromParcel(Parcel in) {
            float[] x = in.createFloatArray();
            float[] y = in.createFloatArray();
            return new Curve(x, y);
        }

        public Curve[] newArray(int size) {
            return new Curve[size];
        }
    };

    @Override
    public void writeToParcel(Parcel out, int flags) {
        out.writeFloatArray(mX);
        out.writeFloatArray(mY);
    }

    @Override
    public int describeContents() {
        return 0;
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.content.Context;
import android.graphics.Point;
import android.media.projection.MediaProjection;
import android.os.Handler;
import android.util.Pair;
import android.util.SparseArray;
import android.view.Display;
import android.view.Surface;
@@ -747,6 +748,22 @@ public final class DisplayManager {
        mGlobal.setTemporaryAutoBrightnessAdjustment(adjustment);
    }

    /**
     * Returns the minimum brightness curve, which guarantess that any brightness curve that dips
     * below it is rejected by the system.
     * This prevent auto-brightness from setting the screen so dark as to prevent the user from
     * resetting or disabling it, and maps lux to the absolute minimum nits that are still readable
     * in that ambient brightness.
     *
     * @return The minimum brightness curve (as lux values and their corresponding nits values).
     *
     * @hide
     */
    @SystemApi
    public Pair<float[], float[]> getMinimumBrightnessCurve() {
        return mGlobal.getMinimumBrightnessCurve();
    }

    /**
     * Listens for changes in available display devices.
     */
Loading