• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.clamper;
18 
19 import static com.android.server.display.DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET;
20 
21 import android.hardware.display.DisplayManagerInternal;
22 import android.os.PowerManager;
23 
24 import com.android.server.display.DisplayBrightnessState;
25 
26 import java.io.PrintWriter;
27 
28 /**
29  * Modifies current brightness based on request
30  */
31 abstract class BrightnessModifier implements BrightnessStateModifier {
32 
33     private boolean mApplied = false;
34 
shouldApply(DisplayManagerInternal.DisplayPowerRequest request)35     abstract boolean shouldApply(DisplayManagerInternal.DisplayPowerRequest request);
36 
getBrightnessAdjusted(float currentBrightness, DisplayManagerInternal.DisplayPowerRequest request)37     abstract float getBrightnessAdjusted(float currentBrightness,
38             DisplayManagerInternal.DisplayPowerRequest request);
39 
getModifier()40     abstract int getModifier();
41 
42     @Override
apply(DisplayManagerInternal.DisplayPowerRequest request, DisplayBrightnessState.Builder stateBuilder)43     public void apply(DisplayManagerInternal.DisplayPowerRequest request,
44             DisplayBrightnessState.Builder stateBuilder) {
45         // If low power mode is enabled, scale brightness by screenLowPowerBrightnessFactor
46         // as long as it is above the minimum threshold.
47         if (shouldApply(request)) {
48             float value = stateBuilder.getBrightness();
49             if (value > PowerManager.BRIGHTNESS_MIN) {
50                 stateBuilder.setBrightness(getBrightnessAdjusted(value, request));
51                 stateBuilder.getBrightnessReason().addModifier(getModifier());
52             }
53             if (!mApplied) {
54                 stateBuilder.setIsSlowChange(false);
55                 stateBuilder.setCustomAnimationRate(CUSTOM_ANIMATION_RATE_NOT_SET);
56             }
57             mApplied = true;
58         } else if (mApplied) {
59             stateBuilder.setIsSlowChange(false);
60             stateBuilder.setCustomAnimationRate(CUSTOM_ANIMATION_RATE_NOT_SET);
61             mApplied = false;
62         }
63     }
64 
65     @Override
dump(PrintWriter pw)66     public void dump(PrintWriter pw) {
67         pw.println("BrightnessModifier:");
68         pw.println("  mApplied=" + mApplied);
69     }
70 
71     @Override
stop()72     public void stop() {
73         // do nothing
74     }
75 }
76