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.Car; 27 import android.car.annotation.AddedInOrBefore; 28 import android.car.annotation.RequiredFeature; 29 import android.os.Parcel; 30 import android.os.Parcelable; 31 32 import com.android.car.internal.ExcludeFromCodeCoverageGeneratedReport; 33 34 import java.lang.annotation.Retention; 35 36 /** 37 * Complete detection result for a single detected person. Includes presence detection, {@link 38 * GazeDetection} and {@link DriverMonitoringDetection}. 39 * 40 * <p>Register to listen to events via {@link OccupantAwarenessManager}. 41 * 42 * @hide 43 */ 44 @RequiredFeature(Car.OCCUPANT_AWARENESS_SERVICE) 45 public final class OccupantAwarenessDetection implements Parcelable { 46 /** Empty occupant flag. */ 47 @AddedInOrBefore(majorVersion = 33) 48 public static final int VEHICLE_OCCUPANT_NONE = 0; 49 50 /** Occupants that the system detects as the driver. */ 51 @AddedInOrBefore(majorVersion = 33) 52 public static final int VEHICLE_OCCUPANT_DRIVER = 1 << 2; 53 54 /** Occupants that the system detects as front seat passengers. */ 55 @AddedInOrBefore(majorVersion = 33) 56 public static final int VEHICLE_OCCUPANT_FRONT_PASSENGER = 1 << 1; 57 58 /** Occupants that the system detects in the second vehicle row, on the left. */ 59 @AddedInOrBefore(majorVersion = 33) 60 public static final int VEHICLE_OCCUPANT_ROW_2_PASSENGER_LEFT = 1 << 3; 61 62 /** Occupants that the system detects in the second vehicle row, in the center. */ 63 @AddedInOrBefore(majorVersion = 33) 64 public static final int VEHICLE_OCCUPANT_ROW_2_PASSENGER_CENTER = 1 << 4; 65 66 /** Occupants that the system detects in the second vehicle row, on the right. */ 67 @AddedInOrBefore(majorVersion = 33) 68 public static final int VEHICLE_OCCUPANT_ROW_2_PASSENGER_RIGHT = 1 << 5; 69 70 /** Occupants that the system detects in the third vehicle row, on the left. */ 71 @AddedInOrBefore(majorVersion = 33) 72 public static final int VEHICLE_OCCUPANT_ROW_3_PASSENGER_LEFT = 1 << 6; 73 74 /** Occupants that the system detects in the third vehicle row, in the middle. */ 75 @AddedInOrBefore(majorVersion = 33) 76 public static final int VEHICLE_OCCUPANT_ROW_3_PASSENGER_CENTER = 1 << 7; 77 78 /** Occupants that the system detects in the third vehicle row, on the right. */ 79 @AddedInOrBefore(majorVersion = 33) 80 public static final int VEHICLE_OCCUPANT_ROW_3_PASSENGER_RIGHT = 1 << 8; 81 82 /** All occupants that the system detects in the front row of the vehicle. */ 83 @AddedInOrBefore(majorVersion = 33) 84 public static final int VEHICLE_OCCUPANT_ALL_FRONT_OCCUPANTS = 85 VEHICLE_OCCUPANT_DRIVER | VEHICLE_OCCUPANT_FRONT_PASSENGER; 86 87 /** All occupants that the system detects in the second row of the vehicle. */ 88 @AddedInOrBefore(majorVersion = 33) 89 public static final int VEHICLE_OCCUPANT_ALL_ROW_2_OCCUPANTS = 90 VEHICLE_OCCUPANT_ROW_2_PASSENGER_LEFT 91 | VEHICLE_OCCUPANT_ROW_2_PASSENGER_RIGHT 92 | VEHICLE_OCCUPANT_ROW_2_PASSENGER_CENTER; 93 94 /** All occupants that the system detects in the third row of the vehicle. */ 95 @AddedInOrBefore(majorVersion = 33) 96 public static final int VEHICLE_OCCUPANT_ALL_ROW_3_OCCUPANTS = 97 VEHICLE_OCCUPANT_ROW_3_PASSENGER_LEFT 98 | VEHICLE_OCCUPANT_ROW_3_PASSENGER_RIGHT 99 | VEHICLE_OCCUPANT_ROW_3_PASSENGER_CENTER; 100 101 /** All occupants that the system detects in the vehicle. */ 102 @AddedInOrBefore(majorVersion = 33) 103 public static final int VEHICLE_OCCUPANT_ALL_OCCUPANTS = 104 VEHICLE_OCCUPANT_ALL_FRONT_OCCUPANTS 105 | VEHICLE_OCCUPANT_ALL_ROW_2_OCCUPANTS 106 | VEHICLE_OCCUPANT_ALL_ROW_3_OCCUPANTS; 107 108 /** 109 * Vehicle occupant roles based on their location in the vehicle. 110 * 111 * @hide 112 */ 113 @Retention(SOURCE) 114 @IntDef( 115 flag = true, 116 value = { 117 VEHICLE_OCCUPANT_NONE, 118 VEHICLE_OCCUPANT_DRIVER, 119 VEHICLE_OCCUPANT_FRONT_PASSENGER, 120 VEHICLE_OCCUPANT_ROW_2_PASSENGER_LEFT, 121 VEHICLE_OCCUPANT_ROW_2_PASSENGER_CENTER, 122 VEHICLE_OCCUPANT_ROW_2_PASSENGER_RIGHT, 123 VEHICLE_OCCUPANT_ROW_3_PASSENGER_LEFT, 124 VEHICLE_OCCUPANT_ROW_3_PASSENGER_CENTER, 125 VEHICLE_OCCUPANT_ROW_3_PASSENGER_RIGHT, 126 VEHICLE_OCCUPANT_ALL_FRONT_OCCUPANTS, 127 VEHICLE_OCCUPANT_ALL_ROW_2_OCCUPANTS, 128 VEHICLE_OCCUPANT_ALL_ROW_3_OCCUPANTS 129 }) 130 public @interface VehicleOccupantRole {} 131 132 /** No prediction could be made. */ 133 @AddedInOrBefore(majorVersion = 33) 134 public static final int CONFIDENCE_LEVEL_NONE = 0; 135 136 /** 137 * Best-guess, low-confidence prediction. Predictions exceeding this threshold are adequate for 138 * non-critical applications. 139 */ 140 @AddedInOrBefore(majorVersion = 33) 141 public static final int CONFIDENCE_LEVEL_LOW = 1; 142 143 /** 144 * High-confidence prediction. Predictions exceeding this threshold are adequate for 145 * applications that require reliable predictions. 146 */ 147 @AddedInOrBefore(majorVersion = 33) 148 public static final int CONFIDENCE_LEVEL_HIGH = 2; 149 150 /** Highest confidence rate achievable. */ 151 @AddedInOrBefore(majorVersion = 33) 152 public static final int CONFIDENCE_LEVEL_MAX = 3; 153 154 /** 155 * Confidence scores for predictions. 156 * 157 * @hide 158 */ 159 @Retention(SOURCE) 160 @IntDef( 161 value = { 162 CONFIDENCE_LEVEL_NONE, 163 CONFIDENCE_LEVEL_LOW, 164 CONFIDENCE_LEVEL_HIGH, 165 CONFIDENCE_LEVEL_MAX 166 }) 167 public @interface ConfidenceLevel {} 168 169 /** The {@link VehicleOccupantRole} of the face associated with this event. */ 170 @AddedInOrBefore(majorVersion = 33) 171 public final @VehicleOccupantRole int role; 172 173 /** Timestamp when the underlying detection data was detected, in milliseconds since boot. */ 174 @AddedInOrBefore(majorVersion = 33) 175 public final long timestampMillis; 176 177 /** Indicates whether any person was detected for the given role. */ 178 @AddedInOrBefore(majorVersion = 33) 179 public final boolean isPresent; 180 181 /** 182 * {@link GazeDetection} data for the requested role, or {@code null} if no person was found. 183 */ 184 @AddedInOrBefore(majorVersion = 33) 185 public final @Nullable GazeDetection gazeDetection; 186 187 /** 188 * {@link DriverMonitoringDetection} data for the driver, or {@code null} if the role was 189 * non-driver or if the detection could not be computed. 190 */ 191 @AddedInOrBefore(majorVersion = 33) 192 public final @Nullable DriverMonitoringDetection driverMonitoringDetection; 193 OccupantAwarenessDetection( @ehicleOccupantRole int role, long timestampMillis, boolean isPresent, @Nullable GazeDetection gazeDetection, @Nullable DriverMonitoringDetection driverMonitoringDetection)194 public OccupantAwarenessDetection( 195 @VehicleOccupantRole int role, 196 long timestampMillis, 197 boolean isPresent, 198 @Nullable GazeDetection gazeDetection, 199 @Nullable DriverMonitoringDetection driverMonitoringDetection) { 200 this.role = role; 201 this.timestampMillis = timestampMillis; 202 this.isPresent = isPresent; 203 this.gazeDetection = gazeDetection; 204 this.driverMonitoringDetection = driverMonitoringDetection; 205 } 206 207 @Override 208 @ExcludeFromCodeCoverageGeneratedReport(reason = BOILERPLATE_CODE) 209 @AddedInOrBefore(majorVersion = 33) describeContents()210 public int describeContents() { 211 return 0; 212 } 213 214 @Override 215 @AddedInOrBefore(majorVersion = 33) writeToParcel(@onNull Parcel dest, int flags)216 public void writeToParcel(@NonNull Parcel dest, int flags) { 217 dest.writeInt(role); 218 dest.writeLong(timestampMillis); 219 dest.writeBoolean(isPresent); 220 dest.writeParcelable(gazeDetection, flags); 221 dest.writeParcelable(driverMonitoringDetection, flags); 222 } 223 224 @Override toString()225 public String toString() { 226 return "OccupantAwarenessDetection{" 227 + "role=" + role 228 + ", timestampMillis=" + timestampMillis 229 + ", isPresent=" + isPresent 230 + ", gazeDetection=" 231 + (gazeDetection == null ? "(null)" : gazeDetection.toString()) 232 + ", driverMonitoringDetection=" 233 + (driverMonitoringDetection == null 234 ? "(null)" : driverMonitoringDetection.toString()) 235 + "}"; 236 } 237 238 @AddedInOrBefore(majorVersion = 33) 239 public static final @NonNull Parcelable.Creator<OccupantAwarenessDetection> CREATOR = 240 new Parcelable.Creator<OccupantAwarenessDetection>() { 241 public OccupantAwarenessDetection createFromParcel(Parcel in) { 242 return new OccupantAwarenessDetection(in); 243 } 244 245 public OccupantAwarenessDetection[] newArray(int size) { 246 return new OccupantAwarenessDetection[size]; 247 } 248 }; 249 OccupantAwarenessDetection(Parcel in)250 private OccupantAwarenessDetection(Parcel in) { 251 role = in.readInt(); 252 timestampMillis = in.readLong(); 253 isPresent = in.readBoolean(); 254 gazeDetection = in.readParcelable(GazeDetection.class.getClassLoader()); 255 driverMonitoringDetection = 256 in.readParcelable(DriverMonitoringDetection.class.getClassLoader()); 257 } 258 } 259