1 /* 2 * Copyright (C) 2021 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 android.hardware.display; 18 19 import android.annotation.IntDef; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 26 /** 27 * Data about the current brightness state. 28 * {@see android.view.Display.getBrightnessInfo()} 29 * 30 * @hide 31 */ 32 public final class BrightnessInfo implements Parcelable { 33 34 @IntDef(prefix = {"HIGH_BRIGHTNESS_MODE_"}, value = { 35 HIGH_BRIGHTNESS_MODE_OFF, 36 HIGH_BRIGHTNESS_MODE_SUNLIGHT, 37 HIGH_BRIGHTNESS_MODE_HDR 38 }) 39 @Retention(RetentionPolicy.SOURCE) 40 public @interface HighBrightnessMode {} 41 42 /** 43 * High brightness mode is OFF. The high brightness range is not currently accessible to the 44 * user. 45 */ 46 public static final int HIGH_BRIGHTNESS_MODE_OFF = 0; 47 48 /** 49 * High brightness mode is ON due to high ambient light (sunlight). The high brightness range is 50 * currently accessible to the user. 51 */ 52 public static final int HIGH_BRIGHTNESS_MODE_SUNLIGHT = 1; 53 54 /** 55 * High brightness mode is ON due to high ambient light (sunlight). The high brightness range is 56 * currently accessible to the user. 57 */ 58 public static final int HIGH_BRIGHTNESS_MODE_HDR = 2; 59 60 @IntDef(prefix = {"BRIGHTNESS_MAX_REASON_"}, value = { 61 BRIGHTNESS_MAX_REASON_NONE, 62 BRIGHTNESS_MAX_REASON_THERMAL, 63 BRIGHTNESS_MAX_REASON_POWER_IC 64 }) 65 @Retention(RetentionPolicy.SOURCE) 66 public @interface BrightnessMaxReason {} 67 68 /** 69 * Maximum brightness is unrestricted. 70 */ 71 public static final int BRIGHTNESS_MAX_REASON_NONE = 0; 72 73 /** 74 * Maximum brightness is restricted due to thermal throttling. 75 */ 76 public static final int BRIGHTNESS_MAX_REASON_THERMAL = 1; 77 78 /** 79 * Maximum brightness is restricted due to power throttling. 80 */ 81 public static final int BRIGHTNESS_MAX_REASON_POWER_IC = 2; 82 83 /** 84 * Maximum brightness is restricted due to the Wear bedtime mode. 85 */ 86 public static final int BRIGHTNESS_MAX_REASON_WEAR_BEDTIME_MODE = 3; 87 88 /** Brightness */ 89 public final float brightness; 90 91 /** Brightness after {@link DisplayPowerController} adjustments */ 92 public final float adjustedBrightness; 93 94 /** Current minimum supported brightness. */ 95 public final float brightnessMinimum; 96 97 /** Current maximum supported brightness. */ 98 public final float brightnessMaximum; 99 100 /** Brightness values greater than this point are only used in High Brightness Mode. */ 101 public final float highBrightnessTransitionPoint; 102 103 /** 104 * Current state of high brightness mode. 105 * Can be any of HIGH_BRIGHTNESS_MODE_* values. 106 */ 107 public final int highBrightnessMode; 108 109 /** 110 * The current reason for restricting maximum brightness. 111 * Can be any of BRIGHTNESS_MAX_REASON_* values. 112 */ 113 public final int brightnessMaxReason; 114 BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum, @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint, @BrightnessMaxReason int brightnessMaxReason)115 public BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum, 116 @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint, 117 @BrightnessMaxReason int brightnessMaxReason) { 118 this(brightness, brightness, brightnessMinimum, brightnessMaximum, highBrightnessMode, 119 highBrightnessTransitionPoint, brightnessMaxReason); 120 } 121 BrightnessInfo(float brightness, float adjustedBrightness, float brightnessMinimum, float brightnessMaximum, @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint, @BrightnessMaxReason int brightnessMaxReason)122 public BrightnessInfo(float brightness, float adjustedBrightness, float brightnessMinimum, 123 float brightnessMaximum, @HighBrightnessMode int highBrightnessMode, 124 float highBrightnessTransitionPoint, @BrightnessMaxReason int brightnessMaxReason) { 125 this.brightness = brightness; 126 this.adjustedBrightness = adjustedBrightness; 127 this.brightnessMinimum = brightnessMinimum; 128 this.brightnessMaximum = brightnessMaximum; 129 this.highBrightnessMode = highBrightnessMode; 130 this.highBrightnessTransitionPoint = highBrightnessTransitionPoint; 131 this.brightnessMaxReason = brightnessMaxReason; 132 } 133 134 /** 135 * @return User-friendly string for specified {@link HighBrightnessMode} parameter. 136 */ hbmToString(@ighBrightnessMode int highBrightnessMode)137 public static String hbmToString(@HighBrightnessMode int highBrightnessMode) { 138 switch (highBrightnessMode) { 139 case HIGH_BRIGHTNESS_MODE_OFF: 140 return "off"; 141 case HIGH_BRIGHTNESS_MODE_HDR: 142 return "hdr"; 143 case HIGH_BRIGHTNESS_MODE_SUNLIGHT: 144 return "sunlight"; 145 } 146 return "invalid"; 147 } 148 149 /** 150 * @return User-friendly string for specified {@link BrightnessMaxReason} parameter. 151 */ briMaxReasonToString(@rightnessMaxReason int reason)152 public static String briMaxReasonToString(@BrightnessMaxReason int reason) { 153 switch (reason) { 154 case BRIGHTNESS_MAX_REASON_NONE: 155 return "none"; 156 case BRIGHTNESS_MAX_REASON_THERMAL: 157 return "thermal"; 158 case BRIGHTNESS_MAX_REASON_POWER_IC: 159 return "power IC"; 160 } 161 return "invalid"; 162 } 163 164 @Override describeContents()165 public int describeContents() { 166 return 0; 167 } 168 169 @Override writeToParcel(Parcel dest, int flags)170 public void writeToParcel(Parcel dest, int flags) { 171 dest.writeFloat(brightness); 172 dest.writeFloat(adjustedBrightness); 173 dest.writeFloat(brightnessMinimum); 174 dest.writeFloat(brightnessMaximum); 175 dest.writeInt(highBrightnessMode); 176 dest.writeFloat(highBrightnessTransitionPoint); 177 dest.writeInt(brightnessMaxReason); 178 } 179 180 public static final @android.annotation.NonNull Creator<BrightnessInfo> CREATOR = 181 new Creator<BrightnessInfo>() { 182 @Override 183 public BrightnessInfo createFromParcel(Parcel source) { 184 return new BrightnessInfo(source); 185 } 186 187 @Override 188 public BrightnessInfo[] newArray(int size) { 189 return new BrightnessInfo[size]; 190 } 191 }; 192 BrightnessInfo(Parcel source)193 private BrightnessInfo(Parcel source) { 194 brightness = source.readFloat(); 195 adjustedBrightness = source.readFloat(); 196 brightnessMinimum = source.readFloat(); 197 brightnessMaximum = source.readFloat(); 198 highBrightnessMode = source.readInt(); 199 highBrightnessTransitionPoint = source.readFloat(); 200 brightnessMaxReason = source.readInt(); 201 } 202 203 } 204