blob: dc5b7cc1e13a18cdc0a9fc291787097f8e7abd99 [file] [log] [blame]
Siarhei Vishniakoucf075282020-01-15 17:35:58 -08001/*
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
17package android.view;
18
19import static android.view.KeyEvent.FLAG_CANCELED;
20
21import static java.lang.annotation.RetentionPolicy.SOURCE;
22
23import android.annotation.IntDef;
24import android.annotation.Nullable;
25import android.annotation.SuppressLint;
26import android.os.Parcel;
27import android.os.Parcelable;
28
29import com.android.internal.util.DataClass;
30
31import java.lang.annotation.Retention;
32
33/**
34 * KeyEvent that has been verified by the system.
35 * The data contained in this class is always a subset of a {@link KeyEvent}. Use this class to
36 * check which data has been confirmed by the system to be authentic.
37 *
38 * Most applications do not need to use this class.
39 *
40 * {@see android.hardware.input.InputManager#verifyInputEvent}
41 */
42@DataClass(genHiddenConstructor = true, genEqualsHashCode = true)
43public final class VerifiedKeyEvent extends VerifiedInputEvent implements Parcelable {
44 private static final String TAG = "VerifiedKeyEvent";
45
46 /** @hide */
47 @Retention(SOURCE)
48 @IntDef({KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP})
49 public @interface KeyEventAction {};
50
51 /**
52 * The action of this key event. May be either {@link KeyEvent#ACTION_DOWN} or
53 * {@link KeyEvent#ACTION_UP}.
54 *
55 * @see KeyEvent#getAction()
56 */
57 @KeyEventAction
58 private int mAction;
59
60 /**
61 * Retrieve the time of the most recent key down event, in the
62 * {@link android.os.SystemClock#uptimeMillis} time base, but in nanoseconds. If this
63 * is a down event, this will be the same as {@link VerifiedInputEvent#getEventTimeNanos()}.
64 *
65 * @see KeyEvent#getDownTime()
66 */
67 @SuppressLint({"MethodNameUnits"})
68 private long mDownTimeNanos;
69
70 /**
71 * Returns the flags for this key event.
72 *
73 * @see KeyEvent#getFlags()
74 * @see KeyEvent#FLAG_CANCELED
75 *
76 * @hide
77 */
78 private int mFlags;
79
80 /**
81 * Retrieve the key code of the key event.
82 *
83 * @see KeyEvent#getKeyCode()
84 */
85 private int mKeyCode;
86
87 /**
88 * Retrieve the hardware key id of this key event. These values are not reliable
89 * and vary from device to device.
90 *
91 * @see KeyEvent#getScanCode()
92 */
93 private int mScanCode;
94
95 /**
96 * <p>Returns the state of the meta keys.</p>
97 *
98 * @return an integer in which each bit set to 1 represents a pressed meta key
99 * @see KeyEvent#getMetaState()
100 */
101 private int mMetaState;
102
103 /**
104 * Retrieve the repeat count of the event. For key down events, this is the number of times
105 * the key has repeated with the first down starting at 0 and counting up from there.
106 * For key up events, this is always equal to zero. For multiple key events,
107 * this is the number of down/up pairs that have occurred.
108 */
109 private int mRepeatCount;
110
111 /**
112 * Get a specific flag of this key event, if possible. Return null if the flag value could
113 * not be checked.
114 *
115 * @param flag the flag of interest
116 * @return Boolean(true) if the key event has the requested flag
117 * Boolean(false) if the key event does not have the requested flag
118 * null if the flag value could not be checked
119 *
120 * @see KeyEvent#getFlags()
121 * @see KeyEvent#FLAG_CANCELED
122 */
123 public @Nullable Boolean getFlag(int flag) {
124 switch(flag) {
125 // InputDispatcher only verifies a subset of the KeyEvent flags.
126 // These values must be kept in sync with Input.cpp
127 case FLAG_CANCELED:
128 return (mFlags & flag) != 0;
129 }
130 return null;
131 }
132
133 // The codegen tool doesn't fully support subclasses, since it works on a per-file basis.
134 // To modify this file:
135 // 1. run codegen on this file
136 // 2. edit the constructor signature
137 // 3. add the "super" call for constructor that receives a Parcel
138 // 4. add the "super" call to the writeToParcel method
139 // 5. Update "equals" and "hashcode" methods to include VerifiedInputEvent fields
140 // 6. Edit "inputSignatures" to ensure KeyEventAction is properly qualified
141
142
143
144 // Code below generated by codegen v1.0.14.
145 //
146 // DO NOT MODIFY!
147 // CHECKSTYLE:OFF Generated code
148 //
149 // To regenerate run:
150 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/VerifiedKeyEvent.java
151 //
152 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
153 // Settings > Editor > Code Style > Formatter Control
154 //@formatter:off
155
156
157 /**
158 * Creates a new VerifiedKeyEvent.
159 *
160 * @param action
161 * The action of this key event. May be either {@link KeyEvent#ACTION_DOWN} or
162 * {@link KeyEvent#ACTION_UP}.
163 * @param downTimeNanos
164 * Retrieve the time of the most recent key down event, in the
165 * {@link android.os.SystemClock#uptimeMillis} time base, but in nanoseconds. If this
166 * is a down event, this will be the same as {@link VerifiedInputEvent#getEventTimeNanos()}.
167 * @param flags
168 * Returns the flags for this key event.
169 * @param keyCode
170 * Retrieve the key code of the key event.
171 * @param scanCode
172 * Retrieve the hardware key id of this key event. These values are not reliable
173 * and vary from device to device.
174 * @param metaState
175 * <p>Returns the state of the meta keys.</p>
176 * @param repeatCount
177 * Retrieve the repeat count of the event. For key down events, this is the number of times
178 * the key has repeated with the first down starting at 0 and counting up from there.
179 * For key up events, this is always equal to zero. For multiple key events,
180 * this is the number of down/up pairs that have occurred.
181 * @hide
182 */
183 @DataClass.Generated.Member
184 public VerifiedKeyEvent(
185 int deviceId,
186 long eventTimeNanos,
187 int source,
188 int displayId,
189 @KeyEventAction int action,
190 @SuppressLint({"MethodNameUnits"}) long downTimeNanos,
191 int flags,
192 int keyCode,
193 int scanCode,
194 int metaState,
195 int repeatCount) {
196 super(VERIFIED_KEY, deviceId, eventTimeNanos, source, displayId);
197 this.mAction = action;
198 com.android.internal.util.AnnotationValidations.validate(
199 KeyEventAction.class, null, mAction);
200 this.mDownTimeNanos = downTimeNanos;
201 com.android.internal.util.AnnotationValidations.validate(
202 SuppressLint.class, null, mDownTimeNanos,
203 "value", "MethodNameUnits");
204 this.mFlags = flags;
205 this.mKeyCode = keyCode;
206 this.mScanCode = scanCode;
207 this.mMetaState = metaState;
208 this.mRepeatCount = repeatCount;
209
210 // onConstructed(); // You can define this method to get a callback
211 }
212
213 /**
214 * The action of this key event. May be either {@link KeyEvent#ACTION_DOWN} or
215 * {@link KeyEvent#ACTION_UP}.
216 *
217 * @see KeyEvent#getAction()
218 */
219 @DataClass.Generated.Member
220 public @KeyEventAction int getAction() {
221 return mAction;
222 }
223
224 /**
225 * Retrieve the time of the most recent key down event, in the
226 * {@link android.os.SystemClock#uptimeMillis} time base, but in nanoseconds. If this
227 * is a down event, this will be the same as {@link VerifiedInputEvent#getEventTimeNanos()}.
228 *
229 * @see KeyEvent#getDownTime()
230 */
231 @DataClass.Generated.Member
232 public @SuppressLint({"MethodNameUnits"}) long getDownTimeNanos() {
233 return mDownTimeNanos;
234 }
235
236 /**
237 * Returns the flags for this key event.
238 *
239 * @see KeyEvent#getFlags()
240 * @see KeyEvent#FLAG_CANCELED
241 * @hide
242 */
243 @DataClass.Generated.Member
244 public int getFlags() {
245 return mFlags;
246 }
247
248 /**
249 * Retrieve the key code of the key event.
250 *
251 * @see KeyEvent#getKeyCode()
252 */
253 @DataClass.Generated.Member
254 public int getKeyCode() {
255 return mKeyCode;
256 }
257
258 /**
259 * Retrieve the hardware key id of this key event. These values are not reliable
260 * and vary from device to device.
261 *
262 * @see KeyEvent#getScanCode()
263 */
264 @DataClass.Generated.Member
265 public int getScanCode() {
266 return mScanCode;
267 }
268
269 /**
270 * <p>Returns the state of the meta keys.</p>
271 *
272 * @return an integer in which each bit set to 1 represents a pressed meta key
273 * @see KeyEvent#getMetaState()
274 */
275 @DataClass.Generated.Member
276 public int getMetaState() {
277 return mMetaState;
278 }
279
280 /**
281 * Retrieve the repeat count of the event. For key down events, this is the number of times
282 * the key has repeated with the first down starting at 0 and counting up from there.
283 * For key up events, this is always equal to zero. For multiple key events,
284 * this is the number of down/up pairs that have occurred.
285 */
286 @DataClass.Generated.Member
287 public int getRepeatCount() {
288 return mRepeatCount;
289 }
290
291 @Override
292 @DataClass.Generated.Member
293 public boolean equals(@Nullable Object o) {
294 // You can override field equality logic by defining either of the methods like:
295 // boolean fieldNameEquals(VerifiedKeyEvent other) { ... }
296 // boolean fieldNameEquals(FieldType otherValue) { ... }
297
298 if (this == o) return true;
299 if (o == null || getClass() != o.getClass()) return false;
300 @SuppressWarnings("unchecked")
301 VerifiedKeyEvent that = (VerifiedKeyEvent) o;
302 //noinspection PointlessBooleanExpression
303 return true
304 && getDeviceId() == that.getDeviceId()
305 && getEventTimeNanos() == that.getEventTimeNanos()
306 && getSource() == that.getSource()
307 && getDisplayId() == that.getDisplayId()
308 && mAction == that.mAction
309 && mDownTimeNanos == that.mDownTimeNanos
310 && mFlags == that.mFlags
311 && mKeyCode == that.mKeyCode
312 && mScanCode == that.mScanCode
313 && mMetaState == that.mMetaState
314 && mRepeatCount == that.mRepeatCount;
315 }
316
317 @Override
318 @DataClass.Generated.Member
319 public int hashCode() {
320 // You can override field hashCode logic by defining methods like:
321 // int fieldNameHashCode() { ... }
322
323 int _hash = 1;
324 _hash = 31 * _hash + getDeviceId();
325 _hash = 31 * _hash + Long.hashCode(getEventTimeNanos());
326 _hash = 31 * _hash + getSource();
327 _hash = 31 * _hash + getDisplayId();
328 _hash = 31 * _hash + mAction;
329 _hash = 31 * _hash + Long.hashCode(mDownTimeNanos);
330 _hash = 31 * _hash + mFlags;
331 _hash = 31 * _hash + mKeyCode;
332 _hash = 31 * _hash + mScanCode;
333 _hash = 31 * _hash + mMetaState;
334 _hash = 31 * _hash + mRepeatCount;
335 return _hash;
336 }
337
338 @Override
339 @DataClass.Generated.Member
340 public void writeToParcel(@android.annotation.NonNull Parcel dest, int flags) {
341 // You can override field parcelling by defining methods like:
342 // void parcelFieldName(Parcel dest, int flags) { ... }
343 super.writeToParcel(dest, flags);
344 dest.writeInt(mAction);
345 dest.writeLong(mDownTimeNanos);
346 dest.writeInt(mFlags);
347 dest.writeInt(mKeyCode);
348 dest.writeInt(mScanCode);
349 dest.writeInt(mMetaState);
350 dest.writeInt(mRepeatCount);
351 }
352
353 @Override
354 @DataClass.Generated.Member
355 public int describeContents() { return 0; }
356
357 /** @hide */
358 @SuppressWarnings({"unchecked", "RedundantCast"})
359 @DataClass.Generated.Member
360 /* package-private */ VerifiedKeyEvent(@android.annotation.NonNull Parcel in) {
361 // You can override field unparcelling by defining methods like:
362 // static FieldType unparcelFieldName(Parcel in) { ... }
363 super(in, VERIFIED_KEY);
364 int action = in.readInt();
365 long downTimeNanos = in.readLong();
366 int flags = in.readInt();
367 int keyCode = in.readInt();
368 int scanCode = in.readInt();
369 int metaState = in.readInt();
370 int repeatCount = in.readInt();
371
372 this.mAction = action;
373 com.android.internal.util.AnnotationValidations.validate(
374 KeyEventAction.class, null, mAction);
375 this.mDownTimeNanos = downTimeNanos;
376 com.android.internal.util.AnnotationValidations.validate(
377 SuppressLint.class, null, mDownTimeNanos,
378 "value", "MethodNameUnits");
379 this.mFlags = flags;
380 this.mKeyCode = keyCode;
381 this.mScanCode = scanCode;
382 this.mMetaState = metaState;
383 this.mRepeatCount = repeatCount;
384
385 // onConstructed(); // You can define this method to get a callback
386 }
387
388 @DataClass.Generated.Member
389 public static final @android.annotation.NonNull Parcelable.Creator<VerifiedKeyEvent> CREATOR
390 = new Parcelable.Creator<VerifiedKeyEvent>() {
391 @Override
392 public VerifiedKeyEvent[] newArray(int size) {
393 return new VerifiedKeyEvent[size];
394 }
395
396 @Override
397 public VerifiedKeyEvent createFromParcel(@android.annotation.NonNull Parcel in) {
398 return new VerifiedKeyEvent(in);
399 }
400 };
401
402 @DataClass.Generated(
403 time = 1581107066890L,
404 codegenVersion = "1.0.14",
405 sourceFile = "frameworks/base/core/java/android/view/VerifiedKeyEvent.java",
406 inputSignatures = "private static final java.lang.String TAG\nprivate @android.view.VerifiedKeyEvent.KeyEventAction int mAction\nprivate @android.annotation.SuppressLint({\"MethodNameUnits\"}) long mDownTimeNanos\nprivate int mFlags\nprivate int mKeyCode\nprivate int mScanCode\nprivate int mMetaState\nprivate int mRepeatCount\npublic @android.annotation.Nullable java.lang.Boolean getFlag(int)\nclass VerifiedKeyEvent extends android.view.VerifiedInputEvent implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true)")
407 @Deprecated
408 private void __metadata() {}
409
410
411 //@formatter:on
412 // End of generated code
413
414}