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

Commit b9965f6f authored by Piotr Wilczyński's avatar Piotr Wilczyński Committed by Android (Google) Code Review
Browse files

Merge "Create setBrightnessFromOffload method" into main

parents da8659da 18a0ffdb
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -721,8 +721,19 @@ public abstract class DisplayManagerInternal {
    public interface DisplayOffloadSession {
        /** Provide the display state to use in place of state DOZE. */
        void setDozeStateOverride(int displayState);
        /** Returns the associated DisplayOffloader. */
        DisplayOffloader getDisplayOffloader();

        /** Whether the session is active. */
        boolean isActive();

        /**
         * Update the brightness from the offload chip.
         * @param brightness The brightness value between {@link PowerManager.BRIGHTNESS_MIN} and
         *                   {@link PowerManager.BRIGHTNESS_MAX}, or
         *                   {@link PowerManager.BRIGHTNESS_INVALID_FLOAT} which removes
         *                   the brightness from offload. Other values will be ignored.
         */
        void updateBrightness(float brightness);

        /** Returns whether displayoffload supports the given display state. */
        static boolean isSupportedOffloadState(int displayState) {
            return Display.isSuspendedState(displayState);
+37 −4
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ public final class DisplayBrightnessState {
    private final boolean mShouldUseAutoBrightness;

    private final boolean mIsSlowChange;
    private final boolean mShouldUpdateScreenBrightnessSetting;

    private final float mCustomAnimationRate;

@@ -50,6 +51,7 @@ public final class DisplayBrightnessState {
        mIsSlowChange = builder.isSlowChange();
        mMaxBrightness = builder.getMaxBrightness();
        mCustomAnimationRate = builder.getCustomAnimationRate();
        mShouldUpdateScreenBrightnessSetting = builder.shouldUpdateScreenBrightnessSetting();
    }

    /**
@@ -109,6 +111,13 @@ public final class DisplayBrightnessState {
        return mCustomAnimationRate;
    }

    /**
     * @return {@code true} if the screen brightness setting should be updated
     */
    public boolean shouldUpdateScreenBrightnessSetting() {
        return mShouldUpdateScreenBrightnessSetting;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:");
@@ -123,6 +132,8 @@ public final class DisplayBrightnessState {
        stringBuilder.append("\n    isSlowChange:").append(mIsSlowChange);
        stringBuilder.append("\n    maxBrightness:").append(mMaxBrightness);
        stringBuilder.append("\n    customAnimationRate:").append(mCustomAnimationRate);
        stringBuilder.append("\n    shouldUpdateScreenBrightnessSetting:")
                .append(mShouldUpdateScreenBrightnessSetting);
        return stringBuilder.toString();
    }

@@ -149,13 +160,16 @@ public final class DisplayBrightnessState {
                && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness()
                && mIsSlowChange == otherState.isSlowChange()
                && mMaxBrightness == otherState.getMaxBrightness()
                && mCustomAnimationRate == otherState.getCustomAnimationRate();
                && mCustomAnimationRate == otherState.getCustomAnimationRate()
                && mShouldUpdateScreenBrightnessSetting
                    == otherState.shouldUpdateScreenBrightnessSetting();
    }

    @Override
    public int hashCode() {
        return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason,
                mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mCustomAnimationRate);
                mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mCustomAnimationRate,
                mShouldUpdateScreenBrightnessSetting);
    }

    /**
@@ -177,6 +191,7 @@ public final class DisplayBrightnessState {
        private boolean mIsSlowChange;
        private float mMaxBrightness;
        private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET;
        private boolean mShouldUpdateScreenBrightnessSetting;

        /**
         * Create a builder starting with the values from the specified {@link
@@ -194,6 +209,8 @@ public final class DisplayBrightnessState {
            builder.setIsSlowChange(state.isSlowChange());
            builder.setMaxBrightness(state.getMaxBrightness());
            builder.setCustomAnimationRate(state.getCustomAnimationRate());
            builder.setShouldUpdateScreenBrightnessSetting(
                    state.shouldUpdateScreenBrightnessSetting());
            return builder;
        }

@@ -290,8 +307,8 @@ public final class DisplayBrightnessState {
        /**
         * See {@link DisplayBrightnessState#isSlowChange()}.
         */
        public Builder setIsSlowChange(boolean shouldUseAutoBrightness) {
            this.mIsSlowChange = shouldUseAutoBrightness;
        public Builder setIsSlowChange(boolean isSlowChange) {
            this.mIsSlowChange = isSlowChange;
            return this;
        }

@@ -333,6 +350,22 @@ public final class DisplayBrightnessState {
            return mCustomAnimationRate;
        }

        /**
         * See {@link DisplayBrightnessState#shouldUpdateScreenBrightnessSetting()}.
         */
        public boolean shouldUpdateScreenBrightnessSetting() {
            return mShouldUpdateScreenBrightnessSetting;
        }

        /**
         * See {@link DisplayBrightnessState#shouldUpdateScreenBrightnessSetting()}.
         */
        public Builder setShouldUpdateScreenBrightnessSetting(
                boolean shouldUpdateScreenBrightnessSetting) {
            mShouldUpdateScreenBrightnessSetting = shouldUpdateScreenBrightnessSetting;
            return this;
        }

        /**
         * This is used to construct an immutable DisplayBrightnessState object from its builder
         */
+1 −1
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ abstract class DisplayDevice {
            int state,
            float brightnessState,
            float sdrBrightnessState,
            @Nullable DisplayOffloadSession displayOffloadSession) {
            @Nullable DisplayOffloadSessionImpl displayOffloadSession) {
        return null;
    }

+2 −14
Original line number Diff line number Diff line
@@ -4948,20 +4948,8 @@ public final class DisplayManagerService extends SystemService {
                    return null;
                }

                DisplayOffloadSession session =
                        new DisplayOffloadSession() {
                            @Override
                            public void setDozeStateOverride(int displayState) {
                                synchronized (mSyncRoot) {
                                    displayPowerController.overrideDozeScreenState(displayState);
                                }
                            }

                            @Override
                            public DisplayOffloader getDisplayOffloader() {
                                return displayOffloader;
                            }
                        };
                DisplayOffloadSessionImpl session = new DisplayOffloadSessionImpl(displayOffloader,
                        displayPowerController);
                logicalDisplay.setDisplayOffloadSessionLocked(session);
                displayPowerController.setDisplayOffloadSession(session);
                return session;
+91 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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 com.android.server.display;

import android.annotation.Nullable;
import android.hardware.display.DisplayManagerInternal;
import android.os.PowerManager;
import android.os.Trace;

/**
 * An implementation of the offload session that keeps track of whether the session is active.
 * An offload session is used to control the display's brightness using the offload chip.
 */
public class DisplayOffloadSessionImpl implements DisplayManagerInternal.DisplayOffloadSession {

    @Nullable
    private final DisplayManagerInternal.DisplayOffloader mDisplayOffloader;
    private final DisplayPowerControllerInterface mDisplayPowerController;
    private boolean mIsActive;

    public DisplayOffloadSessionImpl(
            @Nullable DisplayManagerInternal.DisplayOffloader displayOffloader,
            DisplayPowerControllerInterface displayPowerController) {
        mDisplayOffloader = displayOffloader;
        mDisplayPowerController = displayPowerController;
    }

    @Override
    public void setDozeStateOverride(int displayState) {
        mDisplayPowerController.overrideDozeScreenState(displayState);
    }

    @Override
    public boolean isActive() {
        return mIsActive;
    }

    @Override
    public void updateBrightness(float brightness) {
        if (mIsActive) {
            mDisplayPowerController.setBrightnessFromOffload(brightness);
        }
    }

    /**
     * Start the offload session. The method returns if the session is already active.
     * @return Whether the session was started successfully
     */
    public boolean startOffload() {
        if (mDisplayOffloader == null || mIsActive) {
            return false;
        }
        Trace.traceBegin(Trace.TRACE_TAG_POWER, "DisplayOffloader#startOffload");
        try {
            return mIsActive = mDisplayOffloader.startOffload();
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_POWER);
        }
    }

    /**
     * Stop the offload session. The method returns if the session is not active.
     */
    public void stopOffload() {
        if (mDisplayOffloader == null || !mIsActive) {
            return;
        }
        Trace.traceBegin(Trace.TRACE_TAG_POWER, "DisplayOffloader#stopOffload");
        try {
            mDisplayOffloader.stopOffload();
            mIsActive = false;
            mDisplayPowerController.setBrightnessFromOffload(PowerManager.BRIGHTNESS_INVALID_FLOAT);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_POWER);
        }
    }
}
Loading