1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.display.brightness;
18 
19 import android.hardware.display.DisplayManagerInternal;
20 
21 import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy;
22 
23 import java.util.Objects;
24 
25 /**
26  * A wrapper class to encapsulate the request to notify the strategies about the selection of a
27  * DisplayBrightnessStrategy
28  */
29 public final class StrategySelectionNotifyRequest {
30     // The request to change the associated display's state and brightness
31     private DisplayManagerInternal.DisplayPowerRequest mDisplayPowerRequest;
32 
33     // The display state to which the screen is switching to
34     private int mTargetDisplayState;
35 
36     // The strategy that was selected with the current request
37     private final DisplayBrightnessStrategy mSelectedDisplayBrightnessStrategy;
38 
39     // The last brightness that was set by the user and not temporary. Set to
40     // PowerManager.BRIGHTNESS_INVALID_FLOAT when a brightness has yet to be recorded.
41     private float mLastUserSetScreenBrightness;
42 
43     // Represents if the user set screen brightness was changed or not.
44     private boolean mUserSetBrightnessChanged;
45 
46     // True if light sensor is to be used to automatically determine doze screen brightness.
47     private final boolean mAllowAutoBrightnessWhileDozingConfig;
48     // True if the auto brightness is enabled in the settings
49     private final boolean mIsAutoBrightnessEnabled;
50 
StrategySelectionNotifyRequest( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState, DisplayBrightnessStrategy displayBrightnessStrategy, float lastUserSetScreenBrightness, boolean userSetBrightnessChanged, boolean allowAutoBrightnessWhileDozingConfig, boolean isAutoBrightnessEnabled)51     public StrategySelectionNotifyRequest(
52             DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState,
53             DisplayBrightnessStrategy displayBrightnessStrategy,
54             float lastUserSetScreenBrightness,
55             boolean userSetBrightnessChanged, boolean allowAutoBrightnessWhileDozingConfig,
56             boolean isAutoBrightnessEnabled) {
57         mDisplayPowerRequest = displayPowerRequest;
58         mTargetDisplayState = targetDisplayState;
59         mSelectedDisplayBrightnessStrategy = displayBrightnessStrategy;
60         mLastUserSetScreenBrightness = lastUserSetScreenBrightness;
61         mUserSetBrightnessChanged = userSetBrightnessChanged;
62         mAllowAutoBrightnessWhileDozingConfig = allowAutoBrightnessWhileDozingConfig;
63         mIsAutoBrightnessEnabled = isAutoBrightnessEnabled;
64     }
65 
getSelectedDisplayBrightnessStrategy()66     public DisplayBrightnessStrategy getSelectedDisplayBrightnessStrategy() {
67         return mSelectedDisplayBrightnessStrategy;
68     }
69 
70     @Override
equals(Object obj)71     public boolean equals(Object obj) {
72         if (!(obj instanceof StrategySelectionNotifyRequest)) {
73             return false;
74         }
75         StrategySelectionNotifyRequest other = (StrategySelectionNotifyRequest) obj;
76         return other.getSelectedDisplayBrightnessStrategy()
77                 == getSelectedDisplayBrightnessStrategy()
78                 && Objects.equals(mDisplayPowerRequest, other.getDisplayPowerRequest())
79                 && mTargetDisplayState == other.getTargetDisplayState()
80                 && mUserSetBrightnessChanged == other.isUserSetBrightnessChanged()
81                 && mLastUserSetScreenBrightness == other.getLastUserSetScreenBrightness()
82                 && mAllowAutoBrightnessWhileDozingConfig
83                 == other.isAllowAutoBrightnessWhileDozingConfig()
84                 && mIsAutoBrightnessEnabled == other.isAutoBrightnessEnabled();
85     }
86 
87     @Override
hashCode()88     public int hashCode() {
89         return Objects.hash(mSelectedDisplayBrightnessStrategy, mDisplayPowerRequest,
90                 mTargetDisplayState, mUserSetBrightnessChanged, mLastUserSetScreenBrightness,
91                 mAllowAutoBrightnessWhileDozingConfig, mIsAutoBrightnessEnabled);
92     }
93 
getLastUserSetScreenBrightness()94     public float getLastUserSetScreenBrightness() {
95         return mLastUserSetScreenBrightness;
96     }
97 
isUserSetBrightnessChanged()98     public boolean isUserSetBrightnessChanged() {
99         return mUserSetBrightnessChanged;
100     }
101 
getDisplayPowerRequest()102     public DisplayManagerInternal.DisplayPowerRequest getDisplayPowerRequest() {
103         return mDisplayPowerRequest;
104     }
105 
getTargetDisplayState()106     public int getTargetDisplayState() {
107         return mTargetDisplayState;
108     }
109 
isAllowAutoBrightnessWhileDozingConfig()110     public boolean isAllowAutoBrightnessWhileDozingConfig() {
111         return mAllowAutoBrightnessWhileDozingConfig;
112     }
113 
isAutoBrightnessEnabled()114     public boolean isAutoBrightnessEnabled() {
115         return mIsAutoBrightnessEnabled;
116     }
117 
118     /**
119      * A utility to stringify a StrategySelectionNotifyRequest
120      */
toString()121     public String toString() {
122         return "StrategySelectionNotifyRequest:"
123                 + " mDisplayPowerRequest=" + mDisplayPowerRequest
124                 + " mTargetDisplayState=" + mTargetDisplayState
125                 + " mSelectedDisplayBrightnessStrategy=" + mSelectedDisplayBrightnessStrategy
126                 + " mLastUserSetScreenBrightness=" + mLastUserSetScreenBrightness
127                 + " mUserSetBrightnessChanged=" + mUserSetBrightnessChanged
128                 + " mAllowAutoBrightnessWhileDozingConfig=" + mAllowAutoBrightnessWhileDozingConfig
129                 + " mIsAutoBrightnessEnabled=" + mIsAutoBrightnessEnabled;
130     }
131 }
132