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

Commit 7122996a authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12087303 from b92f17c6 to 24Q4-release

Change-Id: I0dbc9857c13687f3878f1d19035e5300aa2392d2
parents b7d2f82d b92f17c6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@ public final class BrightnessInfo implements Parcelable {
    @IntDef(prefix = {"BRIGHTNESS_MAX_REASON_"}, value = {
            BRIGHTNESS_MAX_REASON_NONE,
            BRIGHTNESS_MAX_REASON_THERMAL,
            BRIGHTNESS_MAX_REASON_POWER_IC
            BRIGHTNESS_MAX_REASON_POWER_IC,
            BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BrightnessMaxReason {}
@@ -157,6 +158,8 @@ public final class BrightnessInfo implements Parcelable {
                return "thermal";
            case BRIGHTNESS_MAX_REASON_POWER_IC:
                return "power IC";
            case BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE:
                return "wear bedtime";
        }
        return "invalid";
    }
+31 −21
Original line number Diff line number Diff line
@@ -1063,8 +1063,8 @@ jboolean android_os_Process_readProcFile(JNIEnv* env, jobject clazz,
    }
    env->ReleaseStringUTFChars(file, file8);

    // Most proc files we read are small, so we only go through the
    // loop once and use the stack buffer.  We allocate a buffer big
    // Most proc files we read are small, so we go through the loop
    // with the stack buffer firstly. We allocate a buffer big
    // enough for the whole file.

    char readBufferStack[kProcReadStackBufferSize];
@@ -1072,30 +1072,38 @@ jboolean android_os_Process_readProcFile(JNIEnv* env, jobject clazz,
    char* readBuffer = &readBufferStack[0];
    ssize_t readBufferSize = kProcReadStackBufferSize;
    ssize_t numberBytesRead;
    off_t offset = 0;
    for (;;) {
        ssize_t requestedBufferSize = readBufferSize - offset;
        // By using pread, we can avoid an lseek to rewind the FD
        // before retry, saving a system call.
        numberBytesRead = pread(fd, readBuffer, readBufferSize, 0);
        if (numberBytesRead < 0 && errno == EINTR) {
            continue;
        }
        numberBytesRead =
                TEMP_FAILURE_RETRY(pread(fd, readBuffer + offset, requestedBufferSize, offset));
        if (numberBytesRead < 0) {
            if (kDebugProc) {
                ALOGW("Unable to open process file: %s fd=%d\n", file8, fd.get());
                ALOGW("Unable to read process file err: %s file: %s fd=%d\n",
                      strerror_r(errno, &readBufferStack[0], sizeof(readBufferStack)), file8,
                      fd.get());
            }
            return JNI_FALSE;
        }
        if (numberBytesRead < readBufferSize) {
        if (numberBytesRead == 0) {
            // End of file.
            numberBytesRead = offset;
            break;
        }
        if (numberBytesRead < requestedBufferSize) {
            // Read less bytes than requested, it's not an error per pread(2).
            offset += numberBytesRead;
        } else {
            // Buffer is fully used, try to grow it.
            if (readBufferSize > std::numeric_limits<ssize_t>::max() / 2) {
                if (kDebugProc) {
                    ALOGW("Proc file too big: %s fd=%d\n", file8, fd.get());
                }
                return JNI_FALSE;
            }
        readBufferSize = std::max(readBufferSize * 2,
                                  kProcReadMinHeapBufferSize);
            readBufferSize = std::max(readBufferSize * 2, kProcReadMinHeapBufferSize);
            readBufferHeap.reset(); // Free address space before getting more.
            readBufferHeap = std::make_unique<char[]>(readBufferSize);
            if (!readBufferHeap) {
@@ -1103,6 +1111,8 @@ jboolean android_os_Process_readProcFile(JNIEnv* env, jobject clazz,
                return JNI_FALSE;
            }
            readBuffer = readBufferHeap.get();
            offset = 0;
        }
    }

    // parseProcLineArray below modifies the buffer while parsing!
+36 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.display;

import android.hardware.display.BrightnessInfo;
import android.text.TextUtils;

import com.android.server.display.brightness.BrightnessEvent;
@@ -50,6 +51,8 @@ public final class DisplayBrightnessState {

    private final boolean mIsUserInitiatedChange;

    private @BrightnessInfo.BrightnessMaxReason int mBrightnessMaxReason;

    private DisplayBrightnessState(Builder builder) {
        mBrightness = builder.getBrightness();
        mHdrBrightness = builder.getHdrBrightness();
@@ -64,6 +67,7 @@ public final class DisplayBrightnessState {
        mBrightnessEvent = builder.getBrightnessEvent();
        mBrightnessAdjustmentFlag = builder.getBrightnessAdjustmentFlag();
        mIsUserInitiatedChange = builder.isUserInitiatedChange();
        mBrightnessMaxReason = builder.getBrightnessMaxReason();
    }

    /**
@@ -159,6 +163,13 @@ public final class DisplayBrightnessState {
        return mIsUserInitiatedChange;
    }

    /**
     * Gets reason for max brightness restriction
     */
    public @BrightnessInfo.BrightnessMaxReason int getBrightnessMaxReason() {
        return mBrightnessMaxReason;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:");
@@ -180,6 +191,8 @@ public final class DisplayBrightnessState {
                .append(Objects.toString(mBrightnessEvent, "null"));
        stringBuilder.append("\n    mBrightnessAdjustmentFlag:").append(mBrightnessAdjustmentFlag);
        stringBuilder.append("\n    mIsUserInitiatedChange:").append(mIsUserInitiatedChange);
        stringBuilder.append("\n    mBrightnessMaxReason:")
                .append(BrightnessInfo.briMaxReasonToString(mBrightnessMaxReason));
        return stringBuilder.toString();
    }

@@ -212,7 +225,8 @@ public final class DisplayBrightnessState {
                    == otherState.shouldUpdateScreenBrightnessSetting()
                && Objects.equals(mBrightnessEvent, otherState.getBrightnessEvent())
                && mBrightnessAdjustmentFlag == otherState.getBrightnessAdjustmentFlag()
                && mIsUserInitiatedChange == otherState.isUserInitiatedChange();
                && mIsUserInitiatedChange == otherState.isUserInitiatedChange()
                && mBrightnessMaxReason == otherState.getBrightnessMaxReason();
    }

    @Override
@@ -221,7 +235,7 @@ public final class DisplayBrightnessState {
                mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mMinBrightness,
                mCustomAnimationRate,
                mShouldUpdateScreenBrightnessSetting, mBrightnessEvent, mBrightnessAdjustmentFlag,
                mIsUserInitiatedChange);
                mIsUserInitiatedChange, mBrightnessMaxReason);
    }

    /**
@@ -245,12 +259,11 @@ public final class DisplayBrightnessState {
        private float mMinBrightness;
        private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET;
        private boolean mShouldUpdateScreenBrightnessSetting;

        private BrightnessEvent mBrightnessEvent;

        public int mBrightnessAdjustmentFlag = 0;

        private int mBrightnessAdjustmentFlag = 0;
        private boolean mIsUserInitiatedChange;
        private @BrightnessInfo.BrightnessMaxReason int mBrightnessMaxReason =
                BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;

        /**
         * Create a builder starting with the values from the specified {@link
@@ -274,6 +287,7 @@ public final class DisplayBrightnessState {
            builder.setBrightnessEvent(state.getBrightnessEvent());
            builder.setBrightnessAdjustmentFlag(state.getBrightnessAdjustmentFlag());
            builder.setIsUserInitiatedChange(state.isUserInitiatedChange());
            builder.setBrightnessMaxReason(state.getBrightnessMaxReason());
            return builder;
        }

@@ -496,5 +510,21 @@ public final class DisplayBrightnessState {
            mIsUserInitiatedChange = isUserInitiatedChange;
            return this;
        }

        /**
         * Gets reason for max brightness restriction
         */
        public @BrightnessInfo.BrightnessMaxReason int getBrightnessMaxReason() {
            return mBrightnessMaxReason;
        }

        /**
         * Sets reason for max brightness restriction
         */
        public Builder setBrightnessMaxReason(
                @BrightnessInfo.BrightnessMaxReason int brightnessMaxReason) {
            mBrightnessMaxReason = brightnessMaxReason;
            return this;
        }
    }
}
+9 −5
Original line number Diff line number Diff line
@@ -1580,7 +1580,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        // brightness sources (such as an app override) are not saved to the setting, but should be
        // reflected in HBM calculations.
        mBrightnessRangeController.onBrightnessChanged(brightnessState, unthrottledBrightnessState,
                mBrightnessClamperController.getBrightnessMaxReason());
                clampedState.getBrightnessMaxReason());

        // Animate the screen brightness when the screen is on or dozing.
        // Skip the animation when the screen is off or suspended.
@@ -1783,7 +1783,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call

            if (userSetBrightnessChanged
                    || newEvent.getReason().getReason() != BrightnessReason.REASON_TEMPORARY) {
                logBrightnessEvent(newEvent, unthrottledBrightnessState);
                logBrightnessEvent(newEvent, unthrottledBrightnessState, clampedState);
            }
            if (mBrightnessEventRingBuffer != null) {
                mBrightnessEventRingBuffer.append(newEvent);
@@ -1976,6 +1976,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        synchronized (mCachedBrightnessInfo) {
            float stateMax = state != null ? state.getMaxBrightness() : PowerManager.BRIGHTNESS_MAX;
            float stateMin = state != null ? state.getMinBrightness() : PowerManager.BRIGHTNESS_MAX;
            @BrightnessInfo.BrightnessMaxReason int maxReason =
                    state != null ? state.getBrightnessMaxReason()
                            : BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
            final float minBrightness = Math.max(stateMin, Math.min(
                    mBrightnessRangeController.getCurrentBrightnessMin(), stateMax));
            final float maxBrightness = Math.min(
@@ -2002,7 +2005,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                            mBrightnessRangeController.getTransitionPoint());
            changed |=
                    mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason,
                            mBrightnessClamperController.getBrightnessMaxReason());
                            maxReason);
            return changed;
        }
    }
@@ -2902,7 +2905,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        return FrameworkStatsLog.DISPLAY_BRIGHTNESS_CHANGED__ENTIRE_REASON__REASON_UNKNOWN;
    }

    private void logBrightnessEvent(BrightnessEvent event, float unmodifiedBrightness) {
    private void logBrightnessEvent(BrightnessEvent event, float unmodifiedBrightness,
            DisplayBrightnessState brightnessState) {
        int modifier = event.getReason().getModifier();
        int flags = event.getFlags();
        // It's easier to check if the brightness is at maximum level using the brightness
@@ -2939,7 +2943,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                    event.getHbmMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_SUNLIGHT,
                    event.getHbmMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR,
                    (modifier & BrightnessReason.MODIFIER_LOW_POWER) > 0,
                    mBrightnessClamperController.getBrightnessMaxReason(),
                    brightnessState.getBrightnessMaxReason(),
                    // TODO: (flc) add brightnessMinReason here too.
                    (modifier & BrightnessReason.MODIFIER_DIMMED) > 0,
                    event.isRbcEnabled(),
+2 −12
Original line number Diff line number Diff line
@@ -139,6 +139,7 @@ public class BrightnessClamperController {
        builder.setBrightness(cappedBrightness);
        builder.setMaxBrightness(mBrightnessCap);
        builder.setCustomAnimationRate(mCustomAnimationRate);
        builder.setBrightnessMaxReason(getBrightnessMaxReason());

        if (mClamperType != null) {
            builder.getBrightnessReason().addModifier(BrightnessReason.MODIFIER_THROTTLED);
@@ -163,19 +164,8 @@ public class BrightnessClamperController {
        return builder.build();
    }

    /**
     * See BrightnessThrottler.getBrightnessMaxReason:
     * used in:
     * 1) DPC2.CachedBrightnessInfo to determine changes
     * 2) DPC2.logBrightnessEvent
     * 3) HBMController - for logging
     * Method is called in mHandler thread (DisplayControllerHandler), in the same thread
     * recalculateBrightnessCap and DPC2.updatePowerStateInternal are called.
     * Should be moved to DisplayBrightnessState OR derived from DisplayBrightnessState
     * TODO: b/263362199
     */
    @BrightnessInfo.BrightnessMaxReason
    public int getBrightnessMaxReason() {
    private int getBrightnessMaxReason() {
        if (mClamperType == null) {
            return BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
        } else if (mClamperType == Type.THERMAL) {
Loading