• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /** Current minimum supported brightness. */
64     public final float brightnessMinimum;
65 
66     /** Current maximum supported brightness. */
67     public final float brightnessMaximum;
68 
69     /**
70      * Current state of high brightness mode.
71      * Can be any of HIGH_BRIGHTNESS_MODE_* values.
72      */
73     public final int highBrightnessMode;
74 
BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum, @HighBrightnessMode int highBrightnessMode)75     public BrightnessInfo(float brightness, float brightnessMinimum, float brightnessMaximum,
76             @HighBrightnessMode int highBrightnessMode) {
77         this.brightness = brightness;
78         this.brightnessMinimum = brightnessMinimum;
79         this.brightnessMaximum = brightnessMaximum;
80         this.highBrightnessMode = highBrightnessMode;
81     }
82 
83     /**
84      * @return User-friendly string for specified {@link HighBrightnessMode} parameter.
85      */
hbmToString(@ighBrightnessMode int highBrightnessMode)86     public static String hbmToString(@HighBrightnessMode int highBrightnessMode) {
87         switch (highBrightnessMode) {
88             case HIGH_BRIGHTNESS_MODE_OFF:
89                 return "off";
90             case HIGH_BRIGHTNESS_MODE_HDR:
91                 return "hdr";
92             case HIGH_BRIGHTNESS_MODE_SUNLIGHT:
93                 return "sunlight";
94         }
95         return "invalid";
96     }
97 
98     @Override
describeContents()99     public int describeContents() {
100         return 0;
101     }
102 
103     @Override
writeToParcel(Parcel dest, int flags)104     public void writeToParcel(Parcel dest, int flags) {
105         dest.writeFloat(brightness);
106         dest.writeFloat(brightnessMinimum);
107         dest.writeFloat(brightnessMaximum);
108         dest.writeInt(highBrightnessMode);
109     }
110 
111     public static final @android.annotation.NonNull Creator<BrightnessInfo> CREATOR =
112             new Creator<BrightnessInfo>() {
113                 @Override
114                 public BrightnessInfo createFromParcel(Parcel source) {
115                     return new BrightnessInfo(source);
116                 }
117 
118                 @Override
119                 public BrightnessInfo[] newArray(int size) {
120                     return new BrightnessInfo[size];
121                 }
122             };
123 
BrightnessInfo(Parcel source)124     private BrightnessInfo(Parcel source) {
125         brightness = source.readFloat();
126         brightnessMinimum = source.readFloat();
127         brightnessMaximum = source.readFloat();
128         highBrightnessMode = source.readInt();
129     }
130 
131 }
132