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 android.annotation.NonNull; 20 import android.os.Handler; 21 import android.os.PowerManager; 22 23 import com.android.server.display.DisplayBrightnessState; 24 25 import java.io.PrintWriter; 26 27 /** 28 * Provides brightness range constraints 29 */ 30 abstract class BrightnessClamper<T> { 31 32 protected float mBrightnessCap = PowerManager.BRIGHTNESS_MAX; 33 34 protected boolean mIsActive = false; 35 36 @NonNull 37 protected final Handler mHandler; 38 39 @NonNull 40 protected final BrightnessClamperController.ClamperChangeListener mChangeListener; 41 BrightnessClamper(Handler handler, BrightnessClamperController.ClamperChangeListener changeListener)42 BrightnessClamper(Handler handler, 43 BrightnessClamperController.ClamperChangeListener changeListener) { 44 mHandler = handler; 45 mChangeListener = changeListener; 46 } 47 getBrightnessCap()48 float getBrightnessCap() { 49 return mBrightnessCap; 50 } 51 getCustomAnimationRate()52 float getCustomAnimationRate() { 53 return DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; 54 } 55 isActive()56 boolean isActive() { 57 return mIsActive; 58 } 59 dump(PrintWriter writer)60 void dump(PrintWriter writer) { 61 writer.println("BrightnessClamper:" + getType()); 62 writer.println(" mBrightnessCap: " + mBrightnessCap); 63 writer.println(" mIsActive: " + mIsActive); 64 } 65 66 @NonNull getType()67 abstract Type getType(); 68 onDeviceConfigChanged()69 abstract void onDeviceConfigChanged(); 70 onDisplayChanged(T displayData)71 abstract void onDisplayChanged(T displayData); 72 stop()73 abstract void stop(); 74 75 protected enum Type { 76 THERMAL, 77 POWER, 78 WEAR_BEDTIME_MODE, 79 } 80 } 81