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 /** Brightness */ 61 public final float brightness; 62 63 /** Brightness after {@link DisplayPowerController} adjustments */ 64 public final float adjustedBrightness; 65 66 /** Current minimum supported brightness. */ 67 public final float brightnessMinimum; 68 69 /** Current maximum supported brightness. */ 70 public final float brightnessMaximum; 71 72 /** Brightness values greater than this point are only used in High Brightness Mode. */ 73 public final float highBrightnessTransitionPoint; 74 75 /** 76 * Current state of high brightness mode. 77 * Can be any of HIGH_BRIGHTNESS_MODE_* values. 78 */ 79 public final int highBrightnessMode; 80 BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum, @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint)81 public BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum, 82 @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint) { 83 this(brightness, brightness, brightnessMinimum, brightnessMaximum, highBrightnessMode, 84 highBrightnessTransitionPoint); 85 } 86 BrightnessInfo(float brightness, float adjustedBrightness, float brightnessMinimum, float brightnessMaximum, @HighBrightnessMode int highBrightnessMode, float highBrightnessTransitionPoint)87 public BrightnessInfo(float brightness, float adjustedBrightness, float brightnessMinimum, 88 float brightnessMaximum, @HighBrightnessMode int highBrightnessMode, 89 float highBrightnessTransitionPoint) { 90 this.brightness = brightness; 91 this.adjustedBrightness = adjustedBrightness; 92 this.brightnessMinimum = brightnessMinimum; 93 this.brightnessMaximum = brightnessMaximum; 94 this.highBrightnessMode = highBrightnessMode; 95 this.highBrightnessTransitionPoint = highBrightnessTransitionPoint; 96 } 97 98 /** 99 * @return User-friendly string for specified {@link HighBrightnessMode} parameter. 100 */ hbmToString(@ighBrightnessMode int highBrightnessMode)101 public static String hbmToString(@HighBrightnessMode int highBrightnessMode) { 102 switch (highBrightnessMode) { 103 case HIGH_BRIGHTNESS_MODE_OFF: 104 return "off"; 105 case HIGH_BRIGHTNESS_MODE_HDR: 106 return "hdr"; 107 case HIGH_BRIGHTNESS_MODE_SUNLIGHT: 108 return "sunlight"; 109 } 110 return "invalid"; 111 } 112 113 @Override describeContents()114 public int describeContents() { 115 return 0; 116 } 117 118 @Override writeToParcel(Parcel dest, int flags)119 public void writeToParcel(Parcel dest, int flags) { 120 dest.writeFloat(brightness); 121 dest.writeFloat(adjustedBrightness); 122 dest.writeFloat(brightnessMinimum); 123 dest.writeFloat(brightnessMaximum); 124 dest.writeInt(highBrightnessMode); 125 dest.writeFloat(highBrightnessTransitionPoint); 126 } 127 128 public static final @android.annotation.NonNull Creator<BrightnessInfo> CREATOR = 129 new Creator<BrightnessInfo>() { 130 @Override 131 public BrightnessInfo createFromParcel(Parcel source) { 132 return new BrightnessInfo(source); 133 } 134 135 @Override 136 public BrightnessInfo[] newArray(int size) { 137 return new BrightnessInfo[size]; 138 } 139 }; 140 BrightnessInfo(Parcel source)141 private BrightnessInfo(Parcel source) { 142 brightness = source.readFloat(); 143 adjustedBrightness = source.readFloat(); 144 brightnessMinimum = source.readFloat(); 145 brightnessMaximum = source.readFloat(); 146 highBrightnessMode = source.readInt(); 147 highBrightnessTransitionPoint = source.readFloat(); 148 } 149 150 } 151