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

Commit a14ab664 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added postprocessor functionality to the strategy selector" into main

parents e766b788 26e5db0c
Loading
Loading
Loading
Loading
+26 −1
Original line number Diff line number Diff line
@@ -71,8 +71,14 @@ public class DisplayBrightnessStrategySelector {
    @Nullable
    private final OffloadBrightnessStrategy mOffloadBrightnessStrategy;

    // A collective representation of all the strategies that the selector is aware of. This is
    // non null, but the strategies this is tracking can be null
    @NonNull
    private final DisplayBrightnessStrategy[] mDisplayBrightnessStrategies;

    @NonNull
    private final DisplayManagerFlags mDisplayManagerFlags;

    // We take note of the old brightness strategy so that we can know when the strategy changes.
    private String mOldBrightnessStrategyName;

@@ -86,6 +92,7 @@ public class DisplayBrightnessStrategySelector {
        if (injector == null) {
            injector = new Injector();
        }
        mDisplayManagerFlags = flags;
        mDisplayId = displayId;
        mDozeBrightnessStrategy = injector.getDozeBrightnessStrategy();
        mScreenOffBrightnessStrategy = injector.getScreenOffBrightnessStrategy();
@@ -139,6 +146,10 @@ public class DisplayBrightnessStrategySelector {
            displayBrightnessStrategy = mOffloadBrightnessStrategy;
        }

        if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) {
            postProcess(constructStrategySelectionNotifyRequest(displayBrightnessStrategy));
        }

        if (!mOldBrightnessStrategyName.equals(displayBrightnessStrategy.getName())) {
            Slog.i(TAG,
                    "Changing the DisplayBrightnessStrategy from " + mOldBrightnessStrategyName
@@ -193,6 +204,20 @@ public class DisplayBrightnessStrategySelector {
        }
    }

    private StrategySelectionNotifyRequest constructStrategySelectionNotifyRequest(
            DisplayBrightnessStrategy selectedDisplayBrightnessStrategy) {
        return new StrategySelectionNotifyRequest(selectedDisplayBrightnessStrategy);
    }

    private void postProcess(StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
        for (DisplayBrightnessStrategy displayBrightnessStrategy : mDisplayBrightnessStrategies) {
            if (displayBrightnessStrategy != null) {
                displayBrightnessStrategy.strategySelectionPostProcessor(
                        strategySelectionNotifyRequest);
            }
        }
    }

    /**
     * Validates if the conditions are met to qualify for the DozeBrightnessStrategy.
     */
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.brightness;

import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy;

import java.util.Objects;

/**
 * A wrapper class to encapsulate the request to notify the strategies about the selection of a
 * DisplayBrightnessStrategy
 */
public final class StrategySelectionNotifyRequest {
    // The strategy that was selected with the current request
    private final DisplayBrightnessStrategy mSelectedDisplayBrightnessStrategy;

    public StrategySelectionNotifyRequest(DisplayBrightnessStrategy displayBrightnessStrategy) {
        mSelectedDisplayBrightnessStrategy = displayBrightnessStrategy;
    }

    public DisplayBrightnessStrategy getSelectedDisplayBrightnessStrategy() {
        return mSelectedDisplayBrightnessStrategy;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof StrategySelectionNotifyRequest)) {
            return false;
        }
        StrategySelectionNotifyRequest other = (StrategySelectionNotifyRequest) obj;
        return other.getSelectedDisplayBrightnessStrategy()
                == getSelectedDisplayBrightnessStrategy();
    }

    @Override
    public int hashCode() {
        return Objects.hash(mSelectedDisplayBrightnessStrategy);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.PowerManager;
import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.BrightnessReason;
import com.android.server.display.brightness.BrightnessUtils;
import com.android.server.display.brightness.StrategySelectionNotifyRequest;

import java.io.PrintWriter;

@@ -53,4 +54,10 @@ public class BoostBrightnessStrategy implements DisplayBrightnessStrategy {

    @Override
    public void dump(PrintWriter writer) {}

    @Override
    public void strategySelectionPostProcessor(
            StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
        // DO NOTHING
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.hardware.display.DisplayManagerInternal;

import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.StrategySelectionNotifyRequest;

import java.io.PrintWriter;

@@ -48,4 +49,10 @@ public interface DisplayBrightnessStrategy {
     * @param writer
     */
    void dump(PrintWriter writer);

     /**
     * Notifies this strategy about the selection of a DisplayBrightnessStrategy
     */
    void strategySelectionPostProcessor(
            StrategySelectionNotifyRequest strategySelectionNotifyRequest);
}
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.hardware.display.DisplayManagerInternal;
import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.BrightnessReason;
import com.android.server.display.brightness.BrightnessUtils;
import com.android.server.display.brightness.StrategySelectionNotifyRequest;

import java.io.PrintWriter;

@@ -46,4 +47,10 @@ public class DozeBrightnessStrategy implements DisplayBrightnessStrategy {

    @Override
    public void dump(PrintWriter writer) {}

    @Override
    public void strategySelectionPostProcessor(
            StrategySelectionNotifyRequest strategySelectionNotifyRequest) {
        // DO NOTHING
    }
}
Loading