File: AmbientContextEvent.java

package info (click to toggle)
android-platform-frameworks-base 1%3A14~beta1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 326,092 kB
  • sloc: java: 2,032,373; xml: 343,016; cpp: 304,181; python: 3,683; ansic: 2,090; sh: 1,871; makefile: 117; sed: 19
file content (505 lines) | stat: -rw-r--r-- 17,897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.app.ambientcontext;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Parcelable;

import com.android.internal.util.DataClass;
import com.android.internal.util.Parcelling;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.time.Instant;


/**
 * Represents a detected ambient event. Each event has a type, start time, end time,
 * plus some optional data.
 *
 * @hide
 */
@SystemApi
@DataClass(
        genBuilder = true,
        genConstructor = false,
        genHiddenConstDefs = true,
        genParcelable = true,
        genToString = true
)
public final class AmbientContextEvent implements Parcelable {
    /**
     * The integer indicating an unknown event was detected.
     */
    public static final int EVENT_UNKNOWN = 0;

    /**
     * The integer indicating a cough event was detected.
     */
    public static final int EVENT_COUGH = 1;

    /**
     * The integer indicating a snore event was detected.
     */
    public static final int EVENT_SNORE = 2;

    /**
     * The integer indicating a double-tap event was detected.
     * For detecting this event type, there's no specific consent activity to request access, but
     * the consent is implied through the double tap toggle in the Settings app.
     *
     * @hide
     */
    public static final int EVENT_BACK_DOUBLE_TAP = 3;

    /** @hide */
    @IntDef(prefix = { "EVENT_" }, value = {
            EVENT_UNKNOWN,
            EVENT_COUGH,
            EVENT_SNORE,
            EVENT_BACK_DOUBLE_TAP,
    }) public @interface EventCode {}

    /** The integer indicating an unknown level. */
    public static final int LEVEL_UNKNOWN = 0;

    /** The integer indicating a low level. */
    public static final int LEVEL_LOW = 1;

    /** The integer indicating a medium low level. */
    public static final int LEVEL_MEDIUM_LOW = 2;

    /** The integer indicating a medium Level. */
    public static final int LEVEL_MEDIUM = 3;

    /** The integer indicating a medium high level. */
    public static final int LEVEL_MEDIUM_HIGH = 4;

    /** The integer indicating a high level. */
    public static final int LEVEL_HIGH = 5;

    /** @hide */
    @IntDef(prefix = {"LEVEL_"}, value = {
            LEVEL_UNKNOWN,
            LEVEL_LOW,
            LEVEL_MEDIUM_LOW,
            LEVEL_MEDIUM,
            LEVEL_MEDIUM_HIGH,
            LEVEL_HIGH
    }) public @interface LevelValue {}

    @EventCode private final int mEventType;
    private static int defaultEventType() {
        return EVENT_UNKNOWN;
    }

    /** Event start time */
    @DataClass.ParcelWith(Parcelling.BuiltIn.ForInstant.class)
    @NonNull private final Instant mStartTime;
    @NonNull private static Instant defaultStartTime() {
        return Instant.MIN;
    }

    /** Event end time */
    @DataClass.ParcelWith(Parcelling.BuiltIn.ForInstant.class)
    @NonNull private final Instant mEndTime;
    @NonNull private static Instant defaultEndTime() {
        return Instant.MAX;
    }

    /**
     * Confidence level from LEVEL_LOW to LEVEL_HIGH, or LEVEL_NONE if not available.
     * Apps can add post-processing filter using this value if needed.
     */
    @LevelValue private final int mConfidenceLevel;
    private static int defaultConfidenceLevel() {
        return LEVEL_UNKNOWN;
    }

    /**
     * Density level from LEVEL_LOW to LEVEL_HIGH, or LEVEL_NONE if not available.
     * Apps can add post-processing filter using this value if needed.
     */
    @LevelValue private final int mDensityLevel;
    private static int defaultDensityLevel() {
        return LEVEL_UNKNOWN;
    }



    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/ambientcontext/AmbientContextEvent.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    /** @hide */
    @IntDef(prefix = "EVENT_", value = {
        EVENT_UNKNOWN,
        EVENT_COUGH,
        EVENT_SNORE,
        EVENT_BACK_DOUBLE_TAP
    })
    @Retention(RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
    public @interface Event {}

    /** @hide */
    @DataClass.Generated.Member
    public static String eventToString(@Event int value) {
        switch (value) {
            case EVENT_UNKNOWN:
                    return "EVENT_UNKNOWN";
            case EVENT_COUGH:
                    return "EVENT_COUGH";
            case EVENT_SNORE:
                    return "EVENT_SNORE";
            case EVENT_BACK_DOUBLE_TAP:
                    return "EVENT_BACK_DOUBLE_TAP";
            default: return Integer.toHexString(value);
        }
    }

    /** @hide */
    @IntDef(prefix = "LEVEL_", value = {
        LEVEL_UNKNOWN,
        LEVEL_LOW,
        LEVEL_MEDIUM_LOW,
        LEVEL_MEDIUM,
        LEVEL_MEDIUM_HIGH,
        LEVEL_HIGH
    })
    @Retention(RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
    public @interface Level {}

    /** @hide */
    @DataClass.Generated.Member
    public static String levelToString(@Level int value) {
        switch (value) {
            case LEVEL_UNKNOWN:
                    return "LEVEL_UNKNOWN";
            case LEVEL_LOW:
                    return "LEVEL_LOW";
            case LEVEL_MEDIUM_LOW:
                    return "LEVEL_MEDIUM_LOW";
            case LEVEL_MEDIUM:
                    return "LEVEL_MEDIUM";
            case LEVEL_MEDIUM_HIGH:
                    return "LEVEL_MEDIUM_HIGH";
            case LEVEL_HIGH:
                    return "LEVEL_HIGH";
            default: return Integer.toHexString(value);
        }
    }

    @DataClass.Generated.Member
    /* package-private */ AmbientContextEvent(
            @EventCode int eventType,
            @NonNull Instant startTime,
            @NonNull Instant endTime,
            @LevelValue int confidenceLevel,
            @LevelValue int densityLevel) {
        this.mEventType = eventType;
        com.android.internal.util.AnnotationValidations.validate(
                EventCode.class, null, mEventType);
        this.mStartTime = startTime;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mStartTime);
        this.mEndTime = endTime;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mEndTime);
        this.mConfidenceLevel = confidenceLevel;
        com.android.internal.util.AnnotationValidations.validate(
                LevelValue.class, null, mConfidenceLevel);
        this.mDensityLevel = densityLevel;
        com.android.internal.util.AnnotationValidations.validate(
                LevelValue.class, null, mDensityLevel);

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public @EventCode int getEventType() {
        return mEventType;
    }

    /**
     * Event start time
     */
    @DataClass.Generated.Member
    public @NonNull Instant getStartTime() {
        return mStartTime;
    }

    /**
     * Event end time
     */
    @DataClass.Generated.Member
    public @NonNull Instant getEndTime() {
        return mEndTime;
    }

    /**
     * Confidence level from LEVEL_LOW to LEVEL_HIGH, or LEVEL_NONE if not available.
     * Apps can add post-processing filter using this value if needed.
     */
    @DataClass.Generated.Member
    public @LevelValue int getConfidenceLevel() {
        return mConfidenceLevel;
    }

    /**
     * Density level from LEVEL_LOW to LEVEL_HIGH, or LEVEL_NONE if not available.
     * Apps can add post-processing filter using this value if needed.
     */
    @DataClass.Generated.Member
    public @LevelValue int getDensityLevel() {
        return mDensityLevel;
    }

    @Override
    @DataClass.Generated.Member
    public String toString() {
        // You can override field toString logic by defining methods like:
        // String fieldNameToString() { ... }

        return "AmbientContextEvent { " +
                "eventType = " + mEventType + ", " +
                "startTime = " + mStartTime + ", " +
                "endTime = " + mEndTime + ", " +
                "confidenceLevel = " + mConfidenceLevel + ", " +
                "densityLevel = " + mDensityLevel +
        " }";
    }

    @DataClass.Generated.Member
    static Parcelling<Instant> sParcellingForStartTime =
            Parcelling.Cache.get(
                    Parcelling.BuiltIn.ForInstant.class);
    static {
        if (sParcellingForStartTime == null) {
            sParcellingForStartTime = Parcelling.Cache.put(
                    new Parcelling.BuiltIn.ForInstant());
        }
    }

    @DataClass.Generated.Member
    static Parcelling<Instant> sParcellingForEndTime =
            Parcelling.Cache.get(
                    Parcelling.BuiltIn.ForInstant.class);
    static {
        if (sParcellingForEndTime == null) {
            sParcellingForEndTime = Parcelling.Cache.put(
                    new Parcelling.BuiltIn.ForInstant());
        }
    }

    @Override
    @DataClass.Generated.Member
    public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        dest.writeInt(mEventType);
        sParcellingForStartTime.parcel(mStartTime, dest, flags);
        sParcellingForEndTime.parcel(mEndTime, dest, flags);
        dest.writeInt(mConfidenceLevel);
        dest.writeInt(mDensityLevel);
    }

    @Override
    @DataClass.Generated.Member
    public int describeContents() { return 0; }

    /** @hide */
    @SuppressWarnings({"unchecked", "RedundantCast"})
    @DataClass.Generated.Member
    /* package-private */ AmbientContextEvent(@NonNull android.os.Parcel in) {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        int eventType = in.readInt();
        Instant startTime = sParcellingForStartTime.unparcel(in);
        Instant endTime = sParcellingForEndTime.unparcel(in);
        int confidenceLevel = in.readInt();
        int densityLevel = in.readInt();

        this.mEventType = eventType;
        com.android.internal.util.AnnotationValidations.validate(
                EventCode.class, null, mEventType);
        this.mStartTime = startTime;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mStartTime);
        this.mEndTime = endTime;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mEndTime);
        this.mConfidenceLevel = confidenceLevel;
        com.android.internal.util.AnnotationValidations.validate(
                LevelValue.class, null, mConfidenceLevel);
        this.mDensityLevel = densityLevel;
        com.android.internal.util.AnnotationValidations.validate(
                LevelValue.class, null, mDensityLevel);

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public static final @NonNull Parcelable.Creator<AmbientContextEvent> CREATOR
            = new Parcelable.Creator<AmbientContextEvent>() {
        @Override
        public AmbientContextEvent[] newArray(int size) {
            return new AmbientContextEvent[size];
        }

        @Override
        public AmbientContextEvent createFromParcel(@NonNull android.os.Parcel in) {
            return new AmbientContextEvent(in);
        }
    };

    /**
     * A builder for {@link AmbientContextEvent}
     */
    @SuppressWarnings("WeakerAccess")
    @DataClass.Generated.Member
    public static final class Builder {

        private @EventCode int mEventType;
        private @NonNull Instant mStartTime;
        private @NonNull Instant mEndTime;
        private @LevelValue int mConfidenceLevel;
        private @LevelValue int mDensityLevel;

        private long mBuilderFieldsSet = 0L;

        public Builder() {
        }

        @DataClass.Generated.Member
        public @NonNull Builder setEventType(@EventCode int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x1;
            mEventType = value;
            return this;
        }

        /**
         * Event start time
         */
        @DataClass.Generated.Member
        public @NonNull Builder setStartTime(@NonNull Instant value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x2;
            mStartTime = value;
            return this;
        }

        /**
         * Event end time
         */
        @DataClass.Generated.Member
        public @NonNull Builder setEndTime(@NonNull Instant value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x4;
            mEndTime = value;
            return this;
        }

        /**
         * Confidence level from LEVEL_LOW to LEVEL_HIGH, or LEVEL_NONE if not available.
         * Apps can add post-processing filter using this value if needed.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setConfidenceLevel(@LevelValue int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x8;
            mConfidenceLevel = value;
            return this;
        }

        /**
         * Density level from LEVEL_LOW to LEVEL_HIGH, or LEVEL_NONE if not available.
         * Apps can add post-processing filter using this value if needed.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setDensityLevel(@LevelValue int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x10;
            mDensityLevel = value;
            return this;
        }

        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull AmbientContextEvent build() {
            checkNotUsed();
            mBuilderFieldsSet |= 0x20; // Mark builder used

            if ((mBuilderFieldsSet & 0x1) == 0) {
                mEventType = defaultEventType();
            }
            if ((mBuilderFieldsSet & 0x2) == 0) {
                mStartTime = defaultStartTime();
            }
            if ((mBuilderFieldsSet & 0x4) == 0) {
                mEndTime = defaultEndTime();
            }
            if ((mBuilderFieldsSet & 0x8) == 0) {
                mConfidenceLevel = defaultConfidenceLevel();
            }
            if ((mBuilderFieldsSet & 0x10) == 0) {
                mDensityLevel = defaultDensityLevel();
            }
            AmbientContextEvent o = new AmbientContextEvent(
                    mEventType,
                    mStartTime,
                    mEndTime,
                    mConfidenceLevel,
                    mDensityLevel);
            return o;
        }

        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x20) != 0) {
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
        }
    }

    @DataClass.Generated(
            time = 1659950304931L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/app/ambientcontext/AmbientContextEvent.java",
            inputSignatures = "public static final  int EVENT_UNKNOWN\npublic static final  int EVENT_COUGH\npublic static final  int EVENT_SNORE\npublic static final  int EVENT_BACK_DOUBLE_TAP\npublic static final  int LEVEL_UNKNOWN\npublic static final  int LEVEL_LOW\npublic static final  int LEVEL_MEDIUM_LOW\npublic static final  int LEVEL_MEDIUM\npublic static final  int LEVEL_MEDIUM_HIGH\npublic static final  int LEVEL_HIGH\nprivate final @android.app.ambientcontext.AmbientContextEvent.EventCode int mEventType\nprivate final @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInstant.class) @android.annotation.NonNull java.time.Instant mStartTime\nprivate final @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInstant.class) @android.annotation.NonNull java.time.Instant mEndTime\nprivate final @android.app.ambientcontext.AmbientContextEvent.LevelValue int mConfidenceLevel\nprivate final @android.app.ambientcontext.AmbientContextEvent.LevelValue int mDensityLevel\nprivate static  int defaultEventType()\nprivate static @android.annotation.NonNull java.time.Instant defaultStartTime()\nprivate static @android.annotation.NonNull java.time.Instant defaultEndTime()\nprivate static  int defaultConfidenceLevel()\nprivate static  int defaultDensityLevel()\nclass AmbientContextEvent extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true, genConstructor=false, genHiddenConstDefs=true, genParcelable=true, genToString=true)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}