Debian Codegraph @

core/java/android/hardware/lights/Light.java

raw symbols SCIP
1 /**
2 * Copyright (C) 2020 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.lights;
18
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.annotation.TestApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28
29 /**
30 * Represents a logical light on the device.
31 *
32 */
33 public final class Light implements Parcelable {
34 // These enum values copy the values from {@link com.android.server.lights.LightsManager}
35 // and the light HAL. Since 0-7 are lights reserved for system use, 8 for microphone light is
36 // defined in {@link android.hardware.lights.LightsManager}, following types are available
37 // through this API.
38 /** Type for lights that indicate microphone usage */
39 public static final int LIGHT_TYPE_MICROPHONE = 8;
40
41 /** Type for lights that indicate camera usage
42 *
43 * @hide
44 */
45 public static final int LIGHT_TYPE_CAMERA = 9;
46
47 // These enum values start from 10001 to avoid collision with expanding of HAL light types.
48 /**
49 * Type for lights that indicate a monochrome color LED light.
50 */
51 public static final int LIGHT_TYPE_INPUT = 10001;
52
53 /**
54 * Type for lights that indicate a group of LED lights representing player id.
55 * Player id lights normally present on game controllers are lights that consist of a row of
56 * LEDs.
57 * During multi-player game, the player id for the current game controller is represented by
58 * one of the LED that is lit according to its position in the row.
59 */
60 public static final int LIGHT_TYPE_PLAYER_ID = 10002;
61
62 /**
63 * Capability for lights that could adjust its LED brightness. If the capability is not present
64 * the led can only be turned either on or off.
65 */
66 public static final int LIGHT_CAPABILITY_BRIGHTNESS = 1 << 0;
67
68 /**
69 * Capability for lights that has red, green and blue LEDs to control the light's color.
70 */
71 public static final int LIGHT_CAPABILITY_RGB = 0 << 1;
72
73 /** @hide */
74 @Retention(RetentionPolicy.SOURCE)
75 @IntDef(prefix = {"LIGHT_TYPE_"},
76 value = {
77 LIGHT_TYPE_MICROPHONE,
78 LIGHT_TYPE_INPUT,
79 LIGHT_TYPE_PLAYER_ID,
80 })
81 public @interface LightType {}
82
83 /** @hide */
84 @Retention(RetentionPolicy.SOURCE)
85 @IntDef(flag = true, prefix = {"LIGHT_CAPABILITY_"},
86 value = {
87 LIGHT_CAPABILITY_BRIGHTNESS,
88 LIGHT_CAPABILITY_RGB,
89 })
90 public @interface LightCapability {}
91
92 private final int mId;
93 private final String mName;
94 private final int mOrdinal;
95 private final int mType;
96 private final int mCapabilities;
97
98 /**
99 * Creates a new light with the given data.
100 *
101 * @hide
102 */
103 public Light(int id, int ordinal, int type) {
104 this(id, "Light", ordinal, type, 0);
105 }
106
107 /**
108 * Creates a new light with the given data.
109 *
110 * @hide
111 */
112 public Light(int id, String name, int ordinal, int type, int capabilities) {
113 mId = id;
114 mName = name;
115 mOrdinal = ordinal;
116 mType = type;
117 mCapabilities = capabilities;
118 }
119
120 private Light(@NonNull Parcel in) {
121 mId = in.readInt();
122 mName = in.readString();
123 mOrdinal = in.readInt();
124 mType = in.readInt();
125 mCapabilities = in.readInt();
126 }
127
128 /** Implement the Parcelable interface */
129 @Override
130 public void writeToParcel(@NonNull Parcel dest, int flags) {
131 dest.writeInt(mId);
132 dest.writeString(mName);
133 dest.writeInt(mOrdinal);
134 dest.writeInt(mType);
135 dest.writeInt(mCapabilities);
136 }
137
138 /** Implement the Parcelable interface */
139 @Override
140 public int describeContents() {
141 return 0;
142 }
143
144 /** Implement the Parcelable interface */
145 public static final @android.annotation.NonNull Parcelable.Creator<Light> CREATOR =
146 new Parcelable.Creator<Light>() {
147 public Light createFromParcel(Parcel in) {
148 return new Light(in);
149 }
150
151 public Light[] newArray(int size) {
152 return new Light[size];
153 }
154 };
155
156 @Override
157 public boolean equals(@Nullable Object obj) {
158 if (obj instanceof Light) {
159 Light light = (Light) obj;
160 return mId == light.mId && mOrdinal == light.mOrdinal && mType == light.mType
161 && mCapabilities == light.mCapabilities;
162 }
163 return false;
164 }
165
166 @Override
167 public int hashCode() {
168 return mId;
169 }
170
171 @Override
172 public String toString() {
173 return "[Name=" + mName + " Id=" + mId + " Type=" + mType + " Capabilities="
174 + mCapabilities + " Ordinal=" + mOrdinal + "]";
175 }
176
177 /**
178 * Returns the id of the light.
179 *
180 * <p>This is an opaque value used as a unique identifier for the light.
181 */
182 public int getId() {
183 return mId;
184 }
185
186 /**
187 * Returns the name of the light.
188 */
189 @NonNull
190 public String getName() {
191 return mName;
192 }
193
194 /**
195 * Returns the ordinal of the light.
196 *
197 * <p>This is a sort key that represents the physical order of lights on the device with the
198 * same type. In the case of multiple lights arranged in a line, for example, the ordinals
199 * could be [1, 2, 3, 4], or [0, 10, 20, 30], or any other values that have the same sort order.
200 */
201 public int getOrdinal() {
202 return mOrdinal;
203 }
204
205 /**
206 * Returns the logical type of the light.
207 */
208 public @LightType int getType() {
209 return mType;
210 }
211
212 /**
213 * Returns the capabilities of the light.
214 * @hide
215 */
216 @TestApi
217 public @LightCapability int getCapabilities() {
218 return mCapabilities;
219 }
220
221 /**
222 * Check whether the light has led brightness control.
223 *
224 * @return True if the hardware can control the led brightness, otherwise false.
225 */
226 public boolean hasBrightnessControl() {
227 return (mCapabilities & LIGHT_CAPABILITY_BRIGHTNESS) == LIGHT_CAPABILITY_BRIGHTNESS;
228 }
229
230 /**
231 * Check whether the light has RGB led control.
232 *
233 * @return True if the hardware can control the RGB led, otherwise false.
234 */
235 public boolean hasRgbControl() {
236 return (mCapabilities & LIGHT_CAPABILITY_RGB) == LIGHT_CAPABILITY_RGB;
237 }
238
239 }