• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static java.lang.annotation.RetentionPolicy.SOURCE;
22 
23 import android.annotation.IntDef;
24 import android.annotation.NonNull;
25 import android.annotation.Nullable;
26 import android.car.annotation.AddedInOrBefore;
27 import android.os.Parcel;
28 import android.os.Parcelable;
29 
30 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport;
31 
32 import java.lang.annotation.Retention;
33 
34 /**
35  * Detection result for gaze detection for the respective {@link VehicleOccupantRole}.
36  *
37  * @hide
38  */
39 public final class GazeDetection implements Parcelable {
40 
41     /** A unknown gaze region, not otherwise specified. */
42     @AddedInOrBefore(majorVersion = 33)
43     public static final int VEHICLE_REGION_UNKNOWN = 0;
44 
45     /** Center instrument cluster in front of the driver. */
46     @AddedInOrBefore(majorVersion = 33)
47     public static final int VEHICLE_REGION_CENTER_INSTRUMENT_CLUSTER = 1;
48 
49     /** The rear-view mirror. */
50     @AddedInOrBefore(majorVersion = 33)
51     public static final int VEHICLE_REGION_REAR_VIEW_MIRROR = 2;
52 
53     /** The left side mirror. */
54     @AddedInOrBefore(majorVersion = 33)
55     public static final int VEHICLE_REGION_LEFT_SIDE_MIRROR = 3;
56 
57     /** The right side mirror. */
58     @AddedInOrBefore(majorVersion = 33)
59     public static final int VEHICLE_REGION_RIGHT_SIDE_MIRROR = 4;
60 
61     /** The forward roadway. */
62     @AddedInOrBefore(majorVersion = 33)
63     public static final int VEHICLE_REGION_FORWARD_ROADWAY = 5;
64 
65     /** Out-the-window to the right. */
66     @AddedInOrBefore(majorVersion = 33)
67     public static final int VEHICLE_REGION_LEFT_ROADWAY = 6;
68 
69     /** Out-the-window to the right. */
70     @AddedInOrBefore(majorVersion = 33)
71     public static final int VEHICLE_REGION_RIGHT_ROADWAY = 7;
72 
73     /** Center head-unit display. */
74     @AddedInOrBefore(majorVersion = 33)
75     public static final int VEHICLE_REGION_HEAD_UNIT_DISPLAY = 8;
76 
77     /**
78      * Vehicle regions
79      *
80      * @hide
81      */
82     @Retention(SOURCE)
83     @IntDef({
84         VEHICLE_REGION_UNKNOWN,
85         VEHICLE_REGION_CENTER_INSTRUMENT_CLUSTER,
86         VEHICLE_REGION_REAR_VIEW_MIRROR,
87         VEHICLE_REGION_LEFT_SIDE_MIRROR,
88         VEHICLE_REGION_RIGHT_SIDE_MIRROR,
89         VEHICLE_REGION_FORWARD_ROADWAY,
90         VEHICLE_REGION_LEFT_ROADWAY,
91         VEHICLE_REGION_RIGHT_ROADWAY,
92         VEHICLE_REGION_HEAD_UNIT_DISPLAY
93     })
94     public @interface VehicleRegion {}
95 
96     /** {@link OccupantAwarenessDetection.ConfidenceLevel} for the gaze detection. */
97     @AddedInOrBefore(majorVersion = 33)
98     @OccupantAwarenessDetection.ConfidenceLevel public final int confidenceLevel;
99 
100     /**
101      * Location of the subject's left eye, in millimeters.
102      *
103      * <p>Vehicle origin is defined as part of the Cabin Space API. All units in millimeters. +x is
104      * right (from driver perspective), +y is up, -z is forward.
105      *
106      * <p>May be {@code null} if the underlying detection system does not export eye position data.
107      */
108     @AddedInOrBefore(majorVersion = 33)
109     public final @Nullable Point3D leftEyePosition;
110 
111     /**
112      * Location of the subject's right eye, in millimeters.
113      *
114      * <p>Vehicle origin is defined as part of the Cabin Space API. All units in millimeters. +x is
115      * right (from driver perspective), +y is up, -z is forward.
116      *
117      * <p>May be {@code null} if the underlying detection system does not export eye position data.
118      */
119     @AddedInOrBefore(majorVersion = 33)
120     public final @Nullable Point3D rightEyePosition;
121 
122     /**
123      * Direction of the subject's head orientation, as a <a
124      * href="https://en.wikipedia.org/wiki/Unit_vector">unit-vector</a>.
125      *
126      * <p>May be {@code null} if the underlying system does not support head orientation vectors.
127      */
128     @AddedInOrBefore(majorVersion = 33)
129     public final @Nullable Point3D headAngleUnitVector;
130 
131     /**
132      * Direction of the gaze angle, as a <a
133      * href="https://en.wikipedia.org/wiki/Unit_vector">unit-vector</a>.
134      *
135      * <p>May be {@code null} if the underlying system does not support vectors.
136      */
137     @AddedInOrBefore(majorVersion = 33)
138     public final @Nullable Point3D gazeAngleUnitVector;
139 
140     /** {@link VehicleRegion} where the subject is currently looking. */
141     @AddedInOrBefore(majorVersion = 33)
142     @VehicleRegion public final int gazeTarget;
143 
144     /** Duration on the current gaze target, in milliseconds. */
145     @AddedInOrBefore(majorVersion = 33)
146     public final long durationOnTargetMillis;
147 
GazeDetection( @ccupantAwarenessDetection.ConfidenceLevel int confidenceLevel, @Nullable Point3D leftEyePosition, @Nullable Point3D rightEyePosition, @Nullable Point3D headAngleUnitVector, @Nullable Point3D gazeAngleUnitVector, @VehicleRegion int gazeTarget, long durationOnTargetMillis)148     public GazeDetection(
149             @OccupantAwarenessDetection.ConfidenceLevel int confidenceLevel,
150             @Nullable Point3D leftEyePosition,
151             @Nullable Point3D rightEyePosition,
152             @Nullable Point3D headAngleUnitVector,
153             @Nullable Point3D gazeAngleUnitVector,
154             @VehicleRegion int gazeTarget,
155             long durationOnTargetMillis) {
156 
157         this.confidenceLevel = confidenceLevel;
158         this.leftEyePosition = leftEyePosition;
159         this.rightEyePosition = rightEyePosition;
160         this.headAngleUnitVector = headAngleUnitVector;
161         this.gazeAngleUnitVector = gazeAngleUnitVector;
162         this.gazeTarget = gazeTarget;
163         this.durationOnTargetMillis = durationOnTargetMillis;
164     }
165 
166     @Override
167     @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE)
168     @AddedInOrBefore(majorVersion = 33)
describeContents()169     public int describeContents() {
170         return 0;
171     }
172 
173     @Override
174     @AddedInOrBefore(majorVersion = 33)
writeToParcel(@onNull Parcel dest, int flags)175     public void writeToParcel(@NonNull Parcel dest, int flags) {
176         dest.writeInt(confidenceLevel);
177         dest.writeParcelable(leftEyePosition, flags);
178         dest.writeParcelable(rightEyePosition, flags);
179         dest.writeParcelable(headAngleUnitVector, flags);
180         dest.writeParcelable(gazeAngleUnitVector, flags);
181         dest.writeInt(gazeTarget);
182         dest.writeLong(durationOnTargetMillis);
183     }
184 
185     @Override
toString()186     public String toString() {
187         return "GazeDetection{"
188                 + "confidenceLevel=" + confidenceLevel
189                 + ", leftEyePosition=" + (leftEyePosition == null ? "(null)" : leftEyePosition)
190                 + ", rightEyePosition=" + (rightEyePosition == null ? "(null)" : rightEyePosition)
191                 + ", headAngleUnitVector="
192                 + (headAngleUnitVector == null ? "(null)" : headAngleUnitVector)
193                 + ", gazeAngleUnitVector="
194                 + (gazeAngleUnitVector == null ? "(null)" : gazeAngleUnitVector)
195                 + ", gazeTarget=" + gazeTarget
196                 + ", durationOnTargetMillis=" + durationOnTargetMillis
197                 + "}";
198     }
199 
200     @AddedInOrBefore(majorVersion = 33)
201     public static final @NonNull Parcelable.Creator<GazeDetection> CREATOR =
202             new Parcelable.Creator<GazeDetection>() {
203                 public GazeDetection createFromParcel(Parcel in) {
204                     return new GazeDetection(in);
205                 }
206 
207                 public GazeDetection[] newArray(int size) {
208                     return new GazeDetection[size];
209                 }
210             };
211 
GazeDetection(Parcel in)212     private GazeDetection(Parcel in) {
213         confidenceLevel = in.readInt();
214         leftEyePosition = in.readParcelable(Point3D.class.getClassLoader());
215         rightEyePosition = in.readParcelable(Point3D.class.getClassLoader());
216         headAngleUnitVector = in.readParcelable(Point3D.class.getClassLoader());
217         gazeAngleUnitVector = in.readParcelable(Point3D.class.getClassLoader());
218         gazeTarget = in.readInt();
219         durationOnTargetMillis = in.readLong();
220     }
221 }
222