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