• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     // True if wear bedtime mode is enabled in the settings.
51     private final boolean mIsBedtimeModeWearEnabled;
52 
StrategySelectionNotifyRequest( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState, DisplayBrightnessStrategy displayBrightnessStrategy, float lastUserSetScreenBrightness, boolean userSetBrightnessChanged, boolean allowAutoBrightnessWhileDozingConfig, boolean isAutoBrightnessEnabled, boolean isBedtimeModeWearEnabled)53     public StrategySelectionNotifyRequest(
54             DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState,
55             DisplayBrightnessStrategy displayBrightnessStrategy,
56             float lastUserSetScreenBrightness,
57             boolean userSetBrightnessChanged, boolean allowAutoBrightnessWhileDozingConfig,
58             boolean isAutoBrightnessEnabled, boolean isBedtimeModeWearEnabled) {
59         mDisplayPowerRequest = displayPowerRequest;
60         mTargetDisplayState = targetDisplayState;
61         mSelectedDisplayBrightnessStrategy = displayBrightnessStrategy;
62         mLastUserSetScreenBrightness = lastUserSetScreenBrightness;
63         mUserSetBrightnessChanged = userSetBrightnessChanged;
64         mAllowAutoBrightnessWhileDozingConfig = allowAutoBrightnessWhileDozingConfig;
65         mIsAutoBrightnessEnabled = isAutoBrightnessEnabled;
66         mIsBedtimeModeWearEnabled = isBedtimeModeWearEnabled;
67     }
68 
getSelectedDisplayBrightnessStrategy()69     public DisplayBrightnessStrategy getSelectedDisplayBrightnessStrategy() {
70         return mSelectedDisplayBrightnessStrategy;
71     }
72 
73     @Override
equals(Object obj)74     public boolean equals(Object obj) {
75         if (!(obj instanceof StrategySelectionNotifyRequest)) {
76             return false;
77         }
78         StrategySelectionNotifyRequest other = (StrategySelectionNotifyRequest) obj;
79         return other.getSelectedDisplayBrightnessStrategy()
80                 == getSelectedDisplayBrightnessStrategy()
81                 && Objects.equals(mDisplayPowerRequest, other.getDisplayPowerRequest())
82                 && mTargetDisplayState == other.getTargetDisplayState()
83                 && mUserSetBrightnessChanged == other.isUserSetBrightnessChanged()
84                 && mLastUserSetScreenBrightness == other.getLastUserSetScreenBrightness()
85                 && mAllowAutoBrightnessWhileDozingConfig
86                 == other.isAllowAutoBrightnessWhileDozingConfig()
87                 && mIsAutoBrightnessEnabled == other.isAutoBrightnessEnabled()
88                 && mIsBedtimeModeWearEnabled == other.isBedtimeModeWearEnabled();
89     }
90 
91     @Override
hashCode()92     public int hashCode() {
93         return Objects.hash(mSelectedDisplayBrightnessStrategy, mDisplayPowerRequest,
94                 mTargetDisplayState, mUserSetBrightnessChanged, mLastUserSetScreenBrightness,
95                 mAllowAutoBrightnessWhileDozingConfig, mIsAutoBrightnessEnabled);
96     }
97 
getLastUserSetScreenBrightness()98     public float getLastUserSetScreenBrightness() {
99         return mLastUserSetScreenBrightness;
100     }
101 
isUserSetBrightnessChanged()102     public boolean isUserSetBrightnessChanged() {
103         return mUserSetBrightnessChanged;
104     }
105 
isBedtimeModeWearEnabled()106     public boolean isBedtimeModeWearEnabled() {
107         return mIsBedtimeModeWearEnabled;
108     }
109 
getDisplayPowerRequest()110     public DisplayManagerInternal.DisplayPowerRequest getDisplayPowerRequest() {
111         return mDisplayPowerRequest;
112     }
113 
getTargetDisplayState()114     public int getTargetDisplayState() {
115         return mTargetDisplayState;
116     }
117 
isAllowAutoBrightnessWhileDozingConfig()118     public boolean isAllowAutoBrightnessWhileDozingConfig() {
119         return mAllowAutoBrightnessWhileDozingConfig;
120     }
121 
isAutoBrightnessEnabled()122     public boolean isAutoBrightnessEnabled() {
123         return mIsAutoBrightnessEnabled;
124     }
125 
126     /**
127      * A utility to stringify a StrategySelectionNotifyRequest
128      */
toString()129     public String toString() {
130         return "StrategySelectionNotifyRequest:"
131                 + " mDisplayPowerRequest=" + mDisplayPowerRequest
132                 + " mTargetDisplayState=" + mTargetDisplayState
133                 + " mSelectedDisplayBrightnessStrategy=" + mSelectedDisplayBrightnessStrategy
134                 + " mLastUserSetScreenBrightness=" + mLastUserSetScreenBrightness
135                 + " mUserSetBrightnessChanged=" + mUserSetBrightnessChanged
136                 + " mAllowAutoBrightnessWhileDozingConfig=" + mAllowAutoBrightnessWhileDozingConfig
137                 + " mIsAutoBrightnessEnabled=" + mIsAutoBrightnessEnabled
138                 + " mIsBedtimeModeWearEnabled" + mIsBedtimeModeWearEnabled;
139     }
140 }
141