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

Commit 4421930b authored by Oleg Petšjonkin's avatar Oleg Petšjonkin Committed by Android (Google) Code Review
Browse files

Merge "Introducing FeatureProvider and using it for NormalBrightnessController...

Merge "Introducing FeatureProvider and using it for NormalBrightnessController enabling" into udc-qpr-dev
parents f93b8d67 1129bf75
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -1762,6 +1762,24 @@ public final class DisplayManager {
         * 123,1,critical,0.8,default;123,1,moderate,0.6,id_2;456,2,moderate,0.9,critical,0.7
         */
        String KEY_BRIGHTNESS_THROTTLING_DATA = "brightness_throttling_data";

        /**
         * Key for new power controller feature flag. If enabled new DisplayPowerController will
         * be used.
         * Read value via {@link android.provider.DeviceConfig#getBoolean(String, String, boolean)}
         * with {@link android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER} as the namespace.
         * @hide
         */
        String KEY_NEW_POWER_CONTROLLER = "use_newly_structured_display_power_controller";

        /**
         * Key for normal brightness mode controller feature flag.
         * It enables NormalBrightnessModeController.
         * Read value via {@link android.provider.DeviceConfig#getBoolean(String, String, boolean)}
         * with {@link android.provider.DeviceConfig#NAMESPACE_DISPLAY_MANAGER} as the namespace.
         * @hide
         */
        String KEY_USE_NORMAL_BRIGHTNESS_MODE_CONTROLLER = "use_normal_brightness_mode_controller";
    }

    /**
+18 −5
Original line number Diff line number Diff line
@@ -18,29 +18,42 @@ package com.android.server.display;

import android.hardware.display.BrightnessInfo;
import android.os.IBinder;
import android.provider.DeviceConfigInterface;

import com.android.server.display.feature.DeviceConfigParameterProvider;

import java.io.PrintWriter;
import java.util.function.BooleanSupplier;

class BrightnessRangeController {

    private static final boolean NBM_FEATURE_FLAG = false;

    private final HighBrightnessModeController mHbmController;
    private final NormalBrightnessModeController mNormalBrightnessModeController =
            new NormalBrightnessModeController();

    private final Runnable mModeChangeCallback;
    private final boolean mUseNbmController;


    BrightnessRangeController(HighBrightnessModeController hbmController,
            Runnable modeChangeCallback) {
        this(hbmController, modeChangeCallback,
                new DeviceConfigParameterProvider(DeviceConfigInterface.REAL));
    }

    BrightnessRangeController(HighBrightnessModeController hbmController,
            Runnable modeChangeCallback, DeviceConfigParameterProvider configParameterProvider) {
        mHbmController = hbmController;
        mModeChangeCallback = modeChangeCallback;
        mUseNbmController = configParameterProvider.isNormalBrightnessControllerFeatureEnabled();
    }


    void dump(PrintWriter pw) {
        pw.println("BrightnessRangeController:");
        pw.println("  mUseNormalBrightnessController=" + mUseNbmController);
        mHbmController.dump(pw);
        mNormalBrightnessModeController.dump(pw);

    }

    void onAmbientLuxChange(float ambientLux) {
@@ -90,7 +103,7 @@ class BrightnessRangeController {


    float getCurrentBrightnessMax() {
        if (NBM_FEATURE_FLAG && mHbmController.getHighBrightnessMode()
        if (mUseNbmController && mHbmController.getHighBrightnessMode()
                == BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF) {
            return Math.min(mHbmController.getCurrentBrightnessMax(),
                    mNormalBrightnessModeController.getCurrentBrightnessMax());
@@ -111,7 +124,7 @@ class BrightnessRangeController {
    }

    private void applyChanges(BooleanSupplier nbmChangesFunc, Runnable hbmChangesFunc) {
        if (NBM_FEATURE_FLAG) {
        if (mUseNbmController) {
            boolean nbmTransitionChanged = nbmChangesFunc.getAsBoolean();
            hbmChangesFunc.run();
            // if nbm transition changed - trigger callback
+7 −13
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.hardware.display.BrightnessInfo;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.IThermalEventListener;
@@ -38,6 +37,7 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.DisplayDeviceConfig.ThermalBrightnessThrottlingData;
import com.android.server.display.DisplayDeviceConfig.ThermalBrightnessThrottlingData.ThrottlingLevel;
import com.android.server.display.feature.DeviceConfigParameterProvider;

import java.io.PrintWriter;
import java.util.ArrayList;
@@ -63,7 +63,7 @@ class BrightnessThrottler {
    private final Runnable mThrottlingChangeCallback;
    private final SkinThermalStatusObserver mSkinThermalStatusObserver;
    private final DeviceConfigListener mDeviceConfigListener;
    private final DeviceConfigInterface mDeviceConfig;
    private final DeviceConfigParameterProvider mConfigParameterProvider;

    private int mThrottlingStatus;

@@ -118,7 +118,7 @@ class BrightnessThrottler {
        mSkinThermalStatusObserver = new SkinThermalStatusObserver(mInjector, mHandler);

        mUniqueDisplayId = uniqueDisplayId;
        mDeviceConfig = injector.getDeviceConfig();
        mConfigParameterProvider = new DeviceConfigParameterProvider(injector.getDeviceConfig());
        mDeviceConfigListener = new DeviceConfigListener();
        mThermalBrightnessThrottlingDataId = throttlingDataId;
        mDdcThermalThrottlingDataMap = thermalBrightnessThrottlingDataMap;
@@ -145,7 +145,7 @@ class BrightnessThrottler {

    void stop() {
        mSkinThermalStatusObserver.stopObserving();
        mDeviceConfig.removeOnPropertiesChangedListener(mDeviceConfigListener);
        mConfigParameterProvider.removeOnPropertiesChangedListener(mDeviceConfigListener);
        // We're asked to stop throttling, so reset brightness restrictions.
        mBrightnessCap = PowerManager.BRIGHTNESS_MAX;
        mBrightnessMaxReason = BrightnessInfo.BRIGHTNESS_MAX_REASON_NONE;
@@ -248,12 +248,6 @@ class BrightnessThrottler {
        mSkinThermalStatusObserver.dump(pw);
    }

    private String getThermalBrightnessThrottlingDataString() {
        return mDeviceConfig.getString(DeviceConfig.NAMESPACE_DISPLAY_MANAGER,
                DisplayManager.DeviceConfig.KEY_BRIGHTNESS_THROTTLING_DATA,
                /* defaultValue= */ null);
    }

    // The brightness throttling data id may or may not be specified in the string that is passed
    // in, if there is none specified, we assume it is for the default case. Each string passed in
    // here must be for one display and one throttling id.
@@ -318,7 +312,8 @@ class BrightnessThrottler {
    private void loadThermalBrightnessThrottlingDataFromDeviceConfig() {
        HashMap<String, HashMap<String, ThermalBrightnessThrottlingData>> tempThrottlingData =
                new HashMap<>(1);
        mThermalBrightnessThrottlingDataString = getThermalBrightnessThrottlingDataString();
        mThermalBrightnessThrottlingDataString =
                mConfigParameterProvider.getBrightnessThrottlingData();
        boolean validConfig = true;
        mThermalBrightnessThrottlingDataOverride.clear();
        if (mThermalBrightnessThrottlingDataString != null) {
@@ -390,8 +385,7 @@ class BrightnessThrottler {
        public Executor mExecutor = new HandlerExecutor(mDeviceConfigHandler);

        public void startListening() {
            mDeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_DISPLAY_MANAGER,
                    mExecutor, this);
            mConfigParameterProvider.addOnPropertiesChangedListener(mExecutor, this);
        }

        @Override
+10 −15
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import static android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_CACHED;
import static android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_GONE;
import static android.hardware.display.DisplayManager.EventsMask;
import static android.hardware.display.DisplayManager.HDR_OUTPUT_CONTROL_FLAG;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ALWAYS_UNLOCKED;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
@@ -42,7 +41,6 @@ import static android.hardware.display.DisplayViewport.VIEWPORT_VIRTUAL;
import static android.hardware.display.HdrConversionMode.HDR_CONVERSION_UNSUPPORTED;
import static android.os.Process.FIRST_APPLICATION_UID;
import static android.os.Process.ROOT_UID;
import static android.provider.DeviceConfig.NAMESPACE_DISPLAY_MANAGER;

import android.Manifest;
import android.annotation.NonNull;
@@ -116,7 +114,7 @@ import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.provider.DeviceConfigInterface;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArraySet;
@@ -152,6 +150,7 @@ import com.android.server.SystemService;
import com.android.server.UiThread;
import com.android.server.companion.virtual.VirtualDeviceManagerInternal;
import com.android.server.display.DisplayDeviceConfig.SensorData;
import com.android.server.display.feature.DeviceConfigParameterProvider;
import com.android.server.display.layout.Layout;
import com.android.server.display.mode.DisplayModeDirector;
import com.android.server.display.utils.SensorUtils;
@@ -506,6 +505,8 @@ public final class DisplayManagerService extends SystemService {

    private final BrightnessSynchronizer mBrightnessSynchronizer;

    private final DeviceConfigParameterProvider mConfigParameterProvider;

    /**
     * Applications use {@link android.view.Display#getRefreshRate} and
     * {@link android.view.Display.Mode#getRefreshRate} to know what is the display refresh rate.
@@ -558,6 +559,7 @@ public final class DisplayManagerService extends SystemService {
        mWideColorSpace = colorSpaces[1];
        mOverlayProperties = SurfaceControl.getOverlaySupport();
        mSystemReady = false;
        mConfigParameterProvider = new DeviceConfigParameterProvider(DeviceConfigInterface.REAL);
    }

    public void setupSchedulerPolicies() {
@@ -694,11 +696,11 @@ public final class DisplayManagerService extends SystemService {
        synchronized (mSyncRoot) {
            mSafeMode = safeMode;
            mSystemReady = true;
            mIsHdrOutputControlEnabled = isDeviceConfigHdrOutputControlEnabled();
            DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_DISPLAY_MANAGER,
                    BackgroundThread.getExecutor(),
            mIsHdrOutputControlEnabled =
                    mConfigParameterProvider.isHdrOutputControlFeatureEnabled();
            mConfigParameterProvider.addOnPropertiesChangedListener(BackgroundThread.getExecutor(),
                    properties -> mIsHdrOutputControlEnabled =
                            isDeviceConfigHdrOutputControlEnabled());
                            mConfigParameterProvider.isHdrOutputControlFeatureEnabled());
            // Just in case the top inset changed before the system was ready. At this point, any
            // relevant configuration should be in place.
            recordTopInsetLocked(mLogicalDisplayMapper.getDisplayLocked(Display.DEFAULT_DISPLAY));
@@ -729,12 +731,6 @@ public final class DisplayManagerService extends SystemService {
        mContext.registerReceiver(mIdleModeReceiver, filter);
    }

    private boolean isDeviceConfigHdrOutputControlEnabled() {
        return DeviceConfig.getBoolean(NAMESPACE_DISPLAY_MANAGER,
                HDR_OUTPUT_CONTROL_FLAG,
                true);
    }

    @VisibleForTesting
    Handler getDisplayHandler() {
        return mHandler;
@@ -3158,8 +3154,7 @@ public final class DisplayManagerService extends SystemService {
                    + "display: " + display.getDisplayIdLocked());
            return null;
        }
        if (DeviceConfig.getBoolean("display_manager",
                "use_newly_structured_display_power_controller", true)) {
        if (mConfigParameterProvider.isNewPowerControllerFeatureEnabled()) {
            displayPowerController = new DisplayPowerController2(
                    mContext, /* injector= */ null, mDisplayPowerCallbacks, mPowerHandler,
                    mSensorManager, mDisplayBlanker, display, mBrightnessTracker, brightnessSetting,
+9 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.PowerManager;

import com.android.server.display.DisplayDeviceConfig.BrightnessLimitMapType;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

@@ -60,6 +61,14 @@ class NormalBrightnessModeController {
        return recalculateMaxBrightness();
    }

    void dump(PrintWriter pw) {
        pw.println("NormalBrightnessModeController:");
        pw.println("  mAutoBrightnessEnabled=" + mAutoBrightnessEnabled);
        pw.println("  mAmbientLux=" + mAmbientLux);
        pw.println("  mMaxBrightness=" + mMaxBrightness);
        pw.println("  mMaxBrightnessLimits=" + mMaxBrightnessLimits);
    }

    private boolean recalculateMaxBrightness() {
        float foundAmbientBoundary = Float.MAX_VALUE;
        float foundMaxBrightness = PowerManager.BRIGHTNESS_MAX;
Loading