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 android.annotation.NonNull;
20 import android.car.occupantawareness.OccupantAwarenessDetection.ConfidenceLevel;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 /**
25  * Detection state data for monitoring driver attention.
26  *
27  * @hide
28  */
29 public final class DriverMonitoringDetection implements Parcelable {
30 
31     /** {@link OccupantAwarenessDetection.ConfidenceLevel} for the driver monitoring detection. */
32     public final @ConfidenceLevel int confidenceLevel;
33 
34     /** Indicates whether the driver is looking on-road. */
35     public final boolean isLookingOnRoad;
36 
37     /**
38      * Duration that the driver has been looking on or off-road, in milliseconds.
39      *
40      * <p>If 'isLookingOnRoad' is true, this indicates the continuous duration of time that the
41      * driver has been looking on-road (in milliseconds). Otherwise, this indicates the continuous
42      * duration of time that the driver is looking off-road (in milliseconds).
43      */
44     public final long gazeDurationMillis;
45 
DriverMonitoringDetection()46     public DriverMonitoringDetection() {
47         confidenceLevel = OccupantAwarenessDetection.CONFIDENCE_LEVEL_NONE;
48         isLookingOnRoad = false;
49         gazeDurationMillis = 0;
50     }
51 
DriverMonitoringDetection( @onfidenceLevel int confidenceLevel, boolean isLookingOnRoad, long gazeDurationMillis)52     public DriverMonitoringDetection(
53             @ConfidenceLevel int confidenceLevel,
54             boolean isLookingOnRoad,
55             long gazeDurationMillis) {
56         this.confidenceLevel = confidenceLevel;
57         this.isLookingOnRoad = isLookingOnRoad;
58         this.gazeDurationMillis = gazeDurationMillis;
59     }
60 
61     @Override
describeContents()62     public int describeContents() {
63         return 0;
64     }
65 
66     @Override
toString()67     public String toString() {
68         return "DriverMonitoringDetection{"
69                 + "confidenceLevel="
70                 + confidenceLevel
71                 + ", isLookingOnRoad="
72                 + isLookingOnRoad
73                 + ", gazeDurationMillis="
74                 + gazeDurationMillis;
75     }
76 
77     @Override
writeToParcel(@onNull Parcel dest, int flags)78     public void writeToParcel(@NonNull Parcel dest, int flags) {
79         dest.writeInt(confidenceLevel);
80         dest.writeBoolean(isLookingOnRoad);
81         dest.writeLong(gazeDurationMillis);
82     }
83 
84     public static final @NonNull Parcelable.Creator<DriverMonitoringDetection> CREATOR =
85             new Parcelable.Creator<DriverMonitoringDetection>() {
86                 public DriverMonitoringDetection createFromParcel(Parcel in) {
87                     return new DriverMonitoringDetection(in);
88                 }
89 
90                 public DriverMonitoringDetection[] newArray(int size) {
91                     return new DriverMonitoringDetection[size];
92                 }
93             };
94 
DriverMonitoringDetection(Parcel in)95     private DriverMonitoringDetection(Parcel in) {
96         confidenceLevel = in.readInt();
97         isLookingOnRoad = in.readBoolean();
98         gazeDurationMillis = in.readLong();
99     }
100 }
101