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.car.occupantawareness;
18 
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20 
21 import android.annotation.IntDef;
22 import android.annotation.NonNull;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import java.lang.annotation.Retention;
27 
28 /**
29  * Current system status.
30  *
31  * <p>Detection system may be ready, not-supported, in a failure mode or not-yet-ready.
32  *
33  * @hide
34  */
35 public final class SystemStatusEvent implements Parcelable {
36     /** The system is ready to provide data. */
37     public static final int SYSTEM_STATUS_READY = 0;
38 
39     /**
40      * Detection is not supported in this vehicle due to a permanent lack of capabilities. Clients
41      * need not retry.
42      */
43     public static final int SYSTEM_STATUS_NOT_SUPPORTED = 1;
44 
45     /** The system is not yet ready to serve requests. Clients should check back again later. */
46     public static final int SYSTEM_STATUS_NOT_READY = 2;
47 
48     /**
49      * A permanent hardware failure has occurred. Clients need not retry until the underlying
50      * hardware has been fixed.
51      */
52     public static final int SYSTEM_STATUS_SYSTEM_FAILURE = 3;
53 
54     /**
55      * System state status values.
56      *
57      * @hide
58      */
59     @Retention(SOURCE)
60     @IntDef({
61         SYSTEM_STATUS_READY,
62         SYSTEM_STATUS_NOT_SUPPORTED,
63         SYSTEM_STATUS_SYSTEM_FAILURE,
64         SYSTEM_STATUS_NOT_READY
65     })
66     public @interface SystemStatus {}
67 
68     /** No detection types are supported. */
69     public static final int DETECTION_TYPE_NONE = 0;
70 
71     /** Presence detection for occupants in the vehicle. */
72     public static final int DETECTION_TYPE_PRESENCE = 1 << 0;
73 
74     /** Gaze data for occupant in the vehicle. */
75     public static final int DETECTION_TYPE_GAZE = 1 << 1;
76 
77     /** Driver monitoring state for the driver in the vehicle. */
78     public static final int DETECTION_TYPE_DRIVER_MONITORING = 1 << 2;
79 
80     /**
81      * Detection types.
82      *
83      * @hide
84      */
85     @Retention(SOURCE)
86     @IntDef(
87             flag = true,
88             value = {
89                 DETECTION_TYPE_PRESENCE,
90                 DETECTION_TYPE_GAZE,
91                 DETECTION_TYPE_DRIVER_MONITORING
92             })
93     public @interface DetectionTypeFlags {}
94 
95     public final @SystemStatus int systemStatus;
96     public final @DetectionTypeFlags int detectionType;
97 
SystemStatusEvent(@ystemStatus int status, @DetectionTypeFlags int type)98     public SystemStatusEvent(@SystemStatus int status, @DetectionTypeFlags int type) {
99         systemStatus = status;
100         detectionType = type;
101     }
102 
SystemStatusEvent()103     public SystemStatusEvent() {
104         systemStatus = SYSTEM_STATUS_NOT_READY;
105         detectionType = DETECTION_TYPE_NONE;
106     }
107 
108     @Override
describeContents()109     public int describeContents() {
110         return 0;
111     }
112 
113     @Override
writeToParcel(@onNull Parcel dest, int flags)114     public void writeToParcel(@NonNull Parcel dest, int flags) {
115         dest.writeInt(systemStatus);
116         dest.writeInt(detectionType);
117     }
118 
119     @Override
toString()120     public String toString() {
121         return "SystemStatusEvent{"
122                 + "systemStatus="
123                 + systemStatus
124                 + ", detectionType="
125                 + detectionType
126                 + "}";
127     }
128 
129     public static final @NonNull Parcelable.Creator<SystemStatusEvent> CREATOR =
130             new Parcelable.Creator<SystemStatusEvent>() {
131                 public SystemStatusEvent createFromParcel(Parcel in) {
132                     return new SystemStatusEvent(in);
133                 }
134 
135                 public SystemStatusEvent[] newArray(int size) {
136                     return new SystemStatusEvent[size];
137                 }
138             };
139 
SystemStatusEvent(Parcel in)140     private SystemStatusEvent(Parcel in) {
141         systemStatus = in.readInt();
142         detectionType = in.readInt();
143     }
144 }
145