From 382ed1d65dbec0cb6e38f418de927c37e84c92cb Mon Sep 17 00:00:00 2001 From: Kathan Shukla Date: Mon, 25 Nov 2019 22:50:53 -0800 Subject: [PATCH 1/2] Occupant Awareness HAL definitions. Occupant awareness default HAL and VTS tests will be added as part of a separate commit / CL. Bug: 142383127 Test: Verified that system starts default hal. Change-Id: I24e1c52c9873fc4e0fc09db24d0def9a04175120 --- automotive/occupant_awareness/aidl/Android.bp | 13 +++ .../occupant_awareness/ConfidenceLevel.aidl | 40 +++++++++ .../DriverMonitoringDetection.aidl | 36 ++++++++ .../occupant_awareness/GazeDetection.aidl | 57 ++++++++++++ .../IOccupantAwareness.aidl | 88 +++++++++++++++++++ .../IOccupantAwarenessClientCallback.aidl | 38 ++++++++ .../OccupantAwarenessStatus.aidl | 41 +++++++++ .../occupant_awareness/OccupantDetection.aidl | 50 +++++++++++ .../OccupantDetections.aidl | 34 +++++++ .../occupant_awareness/PresenceDetection.aidl | 31 +++++++ .../automotive/occupant_awareness/Role.aidl | 83 +++++++++++++++++ .../occupant_awareness/VehicleRegion.aidl | 39 ++++++++ 12 files changed, 550 insertions(+) create mode 100644 automotive/occupant_awareness/aidl/Android.bp create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/ConfidenceLevel.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/DriverMonitoringDetection.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/GazeDetection.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwareness.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwarenessClientCallback.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantAwarenessStatus.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetection.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetections.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/PresenceDetection.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/Role.aidl create mode 100644 automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/VehicleRegion.aidl diff --git a/automotive/occupant_awareness/aidl/Android.bp b/automotive/occupant_awareness/aidl/Android.bp new file mode 100644 index 0000000000..6e9e8aa386 --- /dev/null +++ b/automotive/occupant_awareness/aidl/Android.bp @@ -0,0 +1,13 @@ +aidl_interface { + name: "android.hardware.automotive.occupant_awareness", + vendor_available: true, + srcs: [ + "android/hardware/automotive/occupant_awareness/*.aidl", + ], + stability: "vintf", + backend: { + java: { + enabled: false, + }, + } +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/ConfidenceLevel.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/ConfidenceLevel.aidl new file mode 100644 index 0000000000..8597ddbbd5 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/ConfidenceLevel.aidl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +@VintfStability +@Backing(type="byte") +enum ConfidenceLevel { + /** + * No prediction could be made. + */ + NONE, + /** + * Best-guess, low-confidence prediction. Predictions exceeding this threshold are adequate + * for non-critical applications. + */ + LOW, + /** + * High-confidence prediction. Predictions exceeding this threshold are adequate for + * applications that require reliable predictions. + */ + HIGH, + /** + * Highest confidence rate achievable. + */ + MAX, +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/DriverMonitoringDetection.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/DriverMonitoringDetection.aidl new file mode 100644 index 0000000000..f5cc9d5a42 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/DriverMonitoringDetection.aidl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +import android.hardware.automotive.occupant_awareness.ConfidenceLevel; + +@VintfStability +parcelable DriverMonitoringDetection { + /* + * Confidence of the computed attention data. + */ + ConfidenceLevel confidenceScore; + /* + * Is the driver currently looking on-road? + */ + boolean isLookingOnRoad; + /* + * Duration the driver has been looking on or off road, in milliseconds. + */ + long gazeDurationMillis; +} + diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/GazeDetection.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/GazeDetection.aidl new file mode 100644 index 0000000000..fc36e13904 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/GazeDetection.aidl @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +import android.hardware.automotive.occupant_awareness.VehicleRegion; +import android.hardware.automotive.occupant_awareness.ConfidenceLevel; + +@VintfStability +parcelable GazeDetection { + /* + * Confidence level for the gaze detection. + */ + ConfidenceLevel gazeConfidence; + /* + * Head position, in millimeters. The vehicle coordinate system is specified in the cabin space + * configuration. headPosition is double[3] array. + */ + double[] headPosition; + /* + * Unit vector for the head pose direction. The vehicle coordinate system is specified in the + * cabin space configuration. headAngleUnitVector is double[3] array. + */ + double[] headAngleUnitVector; + /* + * Unit vector for the gaze direction. The vehicle coordinate system is specified in the cabin + * space configuration. gazeAngleUnitVector is double[3] array. + */ + double[] gazeAngleUnitVector; + /* + * Current gaze target. + */ + VehicleRegion gazeTarget; + /* + * Custom gaze target string. This only need to be populated when gazeTarget is CUSTOM_TARGET. + * Vendors should use "com.vendor_name.target_name" format to avoid name collision with other + * vendors. + */ + String customGazeTarget; + /* + * Duration that the subject has been looking at the current gaze target in milliseconds. + */ + long timeOnTargetMillis; +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwareness.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwareness.aidl new file mode 100644 index 0000000000..86d9e2f206 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwareness.aidl @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +import android.hardware.automotive.occupant_awareness.OccupantAwarenessStatus; +import android.hardware.automotive.occupant_awareness.Role; +import android.hardware.automotive.occupant_awareness.IOccupantAwarenessClientCallback; +import android.hardware.automotive.occupant_awareness.OccupantDetections; + +@VintfStability +interface IOccupantAwareness { + /* + * System not able to generate any occupancy awareness. + */ + const int CAP_NONE = 0; + /* + * System is able to detect the presence of humans. + */ + const int CAP_PRESENSE_DETECTION = 1 << 0; + /* + * System is able to detect the gaze of humans. + */ + const int CAP_GAZE_DETECTION = 1 << 1; + /* + * System is able to compute the attention details of humans. + */ + const int CAP_DRIVER_MONITORING_DETECTION = 1 << 2; + + /** + * Starts the occupant awareness detection system. This is a non-blocking function call. + * Once system is ready, state will be modified. State update can be inrquired using callback + * or getState() function. + * @return status is the current system state. + */ + OccupantAwarenessStatus startDetection(); + + /** + * Stops the occupant awareness detection system. This is a non-blocking function call. + * Once system is reset, state will be modified. State update can be inrquired using callback + * or getState() function. + * @return status is the current system state. + */ + OccupantAwarenessStatus stopDetection(); + + /** + * Returns list of Awareness Capability supported for the given type of occupants. + * + * @param out Bitwise OR of supported capabilities (CAP_* mask). + */ + int getCapabilityForRole(in Role occupantRole); + + /** + * Inquires the current state of the occupant awareness system. + * @param occupantRole specifies the role of occupants of interest. + * @param detectionCapability specifies a single detection capability (CAP_* ) of interest. + * + * @return status is the current system state. + */ + OccupantAwarenessStatus getState(in Role occupantRole, in int detectionCapability); + + /** + * Registers a callback for data streaming. Only single callback is supported. setCallback() + * should replace existing callback with new callback. + * @return: returns ok if successful. + */ + void setCallback(in IOccupantAwarenessClientCallback callback); + + /** + * Returns the most recent set of detections. + * @param OccupantDetections output detections. + * @return returns ok if successful. + */ + void getLatestDetection(out OccupantDetections detections); +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwarenessClientCallback.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwarenessClientCallback.aidl new file mode 100644 index 0000000000..69f7b0b082 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/IOccupantAwarenessClientCallback.aidl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +import android.hardware.automotive.occupant_awareness.OccupantAwarenessStatus; +import android.hardware.automotive.occupant_awareness.OccupantDetections; + +@VintfStability +interface IOccupantAwarenessClientCallback { + /** + * A callback invoked when the system status changes. + * + * @param detectionFlags The detection subsystem(s) whose status has changed. + * @param status The new system status. + */ + oneway void onSystemStatusChanged(in int detectionFlags, in OccupantAwarenessStatus status); + + /** + * A callback invoked when a new set of detections are available. + * + * @param detections Occupant detections. + */ + oneway void onDetectionEvent(in OccupantDetections detections); +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantAwarenessStatus.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantAwarenessStatus.aidl new file mode 100644 index 0000000000..6a3453d5aa --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantAwarenessStatus.aidl @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +@VintfStability +@Backing(type="byte") +enum OccupantAwarenessStatus { + /* + * System is online and ready to serve requests. + */ + READY = 0, + /** + * Detection is not supported in this vehicle due to a permanent lack of capabilities. Clients + * need not retry. + */ + NOT_SUPPORTED = 1, + /* + * The system has not yet been initialized. No requests can be served until the + * initialization process completes. This state does not indicate any error and + * clients should retry later. + */ + NOT_INITIALIZED = 2, + /* + * A permanent failure has occurred. No detections will be provided. + */ + FAILURE = 3, +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetection.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetection.aidl new file mode 100644 index 0000000000..47ca35a6b1 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetection.aidl @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +import android.hardware.automotive.occupant_awareness.Role; +import android.hardware.automotive.occupant_awareness.PresenceDetection; +import android.hardware.automotive.occupant_awareness.GazeDetection; +import android.hardware.automotive.occupant_awareness.DriverMonitoringDetection; + +/* + * A complete detection for a single occupant in the vehicle. Includes data about the subject's + * presence in the vehicle, gaze and attention. + */ + @VintfStability +parcelable OccupantDetection { + /* + * Role of the occupant (e.g., driver, passenger). + */ + Role role; + /* + * Occupant presence state for a single occupant. + * If the vector is empty, no data could be generated. + */ + PresenceDetection[] presenceData; + /* + * Gaze data for a single occupant. + * If the vector is empty, no data could be generated. + */ + GazeDetection[] gazeData; + /* + * Attention data for a single occupant. + * If the vector is empty, no data could be generated. + */ + DriverMonitoringDetection[] attentionData; +} + diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetections.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetections.aidl new file mode 100644 index 0000000000..e8f6621cd2 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/OccupantDetections.aidl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +import android.hardware.automotive.occupant_awareness.OccupantDetection; + +@VintfStability +parcelable OccupantDetections { + /** + * Timestamp that the underlying source image was captured, in milliseconds since Jan 1, 1970 + * (Unix time). + */ + long timeStampMillis; + /** + * A vector of detections for all occupants in the vehicle. One OccupantDetection will be + * generated per detected face. + */ + OccupantDetection[] detections; +} + diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/PresenceDetection.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/PresenceDetection.aidl new file mode 100644 index 0000000000..a018106280 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/PresenceDetection.aidl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +@VintfStability +parcelable PresenceDetection { + /* + * Boolean representing whether an occupant was detected. + */ + boolean isOccupantDetected; + /** + * Duration that a particular occupant has been continuously + * detected, in milliseconds. Will be zero duration if the occupant is not + * currently detected. + */ + long detectionDurationMillis; +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/Role.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/Role.aidl new file mode 100644 index 0000000000..42e86ad3a5 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/Role.aidl @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +@VintfStability +@Backing(type="int") +enum Role { + /* + * All valid role(s) must have at least 1 bit set. + */ + INVALID = 0, + /* + * System could not determine role for this occupant. + */ + UNKNOWN = 1 << 0, + /* + * Occupants that the system detects as front seat passengers. + */ + FRONT_PASSENGER = 1 << 1, + /* + * Occupants that the system detects as driver(s). + */ + DRIVER = 1 << 2, + /* + * Occupants on left seat of row 2. + */ + ROW_2_PASSENGER_LEFT = 1 << 3, + /* + * Occupants on center seat of row 2. + */ + ROW_2_PASSENGER_CENTER = 1 << 4, + /* + * Occupants on right seat of row 2. + */ + ROW_2_PASSENGER_RIGHT = 1 << 5, + /* + * Occupants on left seat of row 3. + */ + ROW_3_PASSENGER_LEFT = 1 << 6, + /* + * Occupants on center seat of row 3. + */ + ROW_3_PASSENGER_CENTER = 1 << 7, + /* + * Occupants on right seat of row 3. + */ + ROW_3_PASSENGER_RIGHT = 1 << 8, + + /* + * Occupants that the system detects as front seat occupant. + * FRONT_OCCUPANTS = DRIVER | FRONT_PASSENGER + */ + FRONT_OCCUPANTS = 1 << 1 | 1 << 2, + /* + * Occupants of row 2. + * ROW_2_OCCUPANTS = ROW_2_PASSENGER_LEFT | ROW_2_PASSENGER_CENTER | ROW_2_PASSENGER_RIGHT + */ + ROW_2_OCCUPANTS = 1 << 3 | 1 << 4 | 1 << 5, + /* + * Occupants of row 3. + * ROW_3_OCCUPANTS = ROW_3_PASSENGER_LEFT | ROW_3_PASSENGER_CENTER | ROW_3_PASSENGER_RIGHT + */ + ROW_3_OCCUPANTS = 1 << 6 | 1 << 7 | 1 << 8, + /* + * All the occupants in the vehicle. + * ALL_OCCUPANTS = UNKNOWN | FRONT_OCCUPANTS | ROW_2_OCCUPANTS | ROW_3_OCCUPANTS + */ + ALL_OCCUPANTS = 0x1FF, +} diff --git a/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/VehicleRegion.aidl b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/VehicleRegion.aidl new file mode 100644 index 0000000000..9ee9d52f39 --- /dev/null +++ b/automotive/occupant_awareness/aidl/android/hardware/automotive/occupant_awareness/VehicleRegion.aidl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.automotive.occupant_awareness; + +@VintfStability +@Backing(type="int") +enum VehicleRegion { + /* + * List of targets in the car. + */ + UNKNOWN = 0, + INSTRUMENT_CLUSTER = 1, + REAR_VIEW_MIRROR = 2, + LEFT_SIDE_MIRROR = 3, + RIGHT_SIDE_MIRROR = 4, + FORWARD_ROADWAY = 5, + LEFT_ROADWAY = 6, + RIGHT_ROADWAY = 7, + HEAD_UNIT_DISPLAY = 8, + /* + * Vendors can use this value along with customGazeTarget string to uniquely identify their + * custom region. + */ + CUSTOM_TARGET = 200, +} From b6261cb2ae1cd3099d0549f14c757944f6159dba Mon Sep 17 00:00:00 2001 From: Kathan Shukla Date: Mon, 25 Nov 2019 22:52:12 -0800 Subject: [PATCH 2/2] Default hal for Occupant Awareness. Bug: 142383127 Test: Verified that the system starts the default hal automatically. Change-Id: I851f85bc283165891943b82c6c07f3273847b032 --- .../aidl/default/Android.bp | 32 +++++ .../aidl/default/OccupantAwareness.cpp | 122 ++++++++++++++++++ .../aidl/default/OccupantAwareness.h | 67 ++++++++++ ...tomotive.occupant_awareness@1.0-service.rc | 4 + .../aidl/default/service.cpp | 55 ++++++++ .../compatibility_matrix.current.xml | 7 + 6 files changed, 287 insertions(+) create mode 100644 automotive/occupant_awareness/aidl/default/Android.bp create mode 100644 automotive/occupant_awareness/aidl/default/OccupantAwareness.cpp create mode 100644 automotive/occupant_awareness/aidl/default/OccupantAwareness.h create mode 100644 automotive/occupant_awareness/aidl/default/android.hardware.automotive.occupant_awareness@1.0-service.rc create mode 100644 automotive/occupant_awareness/aidl/default/service.cpp diff --git a/automotive/occupant_awareness/aidl/default/Android.bp b/automotive/occupant_awareness/aidl/default/Android.bp new file mode 100644 index 0000000000..1b2fba2ea4 --- /dev/null +++ b/automotive/occupant_awareness/aidl/default/Android.bp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +cc_binary { + name: "android.hardware.automotive.occupant_awareness@1.0-service", + init_rc: ["android.hardware.automotive.occupant_awareness@1.0-service.rc"], + relative_install_path: "hw", + vendor: true, + srcs: [ + "service.cpp", + "OccupantAwareness.cpp", + ], + shared_libs: [ + "libbase", + "libbinder_ndk", + "libutils", + "android.hardware.automotive.occupant_awareness-ndk_platform", + ], +} diff --git a/automotive/occupant_awareness/aidl/default/OccupantAwareness.cpp b/automotive/occupant_awareness/aidl/default/OccupantAwareness.cpp new file mode 100644 index 0000000000..ef5055f599 --- /dev/null +++ b/automotive/occupant_awareness/aidl/default/OccupantAwareness.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "OccupantAwareness.h" + +namespace android { +namespace hardware { +namespace automotive { +namespace occupant_awareness { +namespace V1_0 { +namespace implementation { + +using ndk::ScopedAStatus; + +static const int32_t kAllCapabilities = OccupantAwareness::CAP_PRESENSE_DETECTION | + OccupantAwareness::CAP_GAZE_DETECTION | + OccupantAwareness::CAP_DRIVER_MONITORING_DETECTION; + +ScopedAStatus OccupantAwareness::startDetection(OccupantAwarenessStatus* status) { + std::lock_guard lock(mMutex); + if (mStatus != OccupantAwarenessStatus::NOT_SUPPORTED) { + mStatus = OccupantAwarenessStatus::NOT_SUPPORTED; + if (mCallback) { + mCallback->onSystemStatusChanged(kAllCapabilities, + OccupantAwarenessStatus::NOT_SUPPORTED); + } + } + *status = mStatus; + return ScopedAStatus::ok(); +} + +ScopedAStatus OccupantAwareness::stopDetection(OccupantAwarenessStatus* status) { + std::lock_guard lock(mMutex); + if (mStatus != OccupantAwarenessStatus::NOT_INITIALIZED) { + mStatus = OccupantAwarenessStatus::NOT_INITIALIZED; + if (mCallback) { + mCallback->onSystemStatusChanged(kAllCapabilities, + OccupantAwarenessStatus::NOT_INITIALIZED); + } + } + *status = mStatus; + return ScopedAStatus::ok(); +} + +ScopedAStatus OccupantAwareness::getCapabilityForRole(Role occupantRole, int32_t* capabilities) { + if (!isValidRole(occupantRole)) { + return ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED); + } + + // No awareness capability for default HAL. + *capabilities = 0; + return ScopedAStatus::ok(); +} + +ScopedAStatus OccupantAwareness::getState(Role occupantRole, int detectionCapability, + OccupantAwarenessStatus* status) { + if (!isValidRole(occupantRole)) { + return ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED); + } + + if (!isValidDetectionCapabilities(detectionCapability) || + !isSingularCapability(detectionCapability)) { + return ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED); + } + + std::lock_guard lock(mMutex); + *status = mStatus; + return ScopedAStatus::ok(); +} + +ScopedAStatus OccupantAwareness::setCallback( + const std::shared_ptr& callback) { + if (callback == nullptr) { + return ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED); + } + + std::lock_guard lock(mMutex); + mCallback = callback; + return ScopedAStatus::ok(); +} + +ScopedAStatus OccupantAwareness::getLatestDetection(OccupantDetections* detections) { + // No detection generated for default hal. + (void)detections; + return ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED); +} + +bool OccupantAwareness::isValidRole(Role occupantRole) { + int intVal = static_cast(occupantRole); + int allOccupants = static_cast(Role::ALL_OCCUPANTS); + return (occupantRole != Role::INVALID) && ((intVal & (~allOccupants)) == 0); +} + +bool OccupantAwareness::isValidDetectionCapabilities(int detectionCapabilities) { + return (detectionCapabilities != CAP_NONE) && + ((detectionCapabilities & (~kAllCapabilities)) == 0); +} + +bool OccupantAwareness::isSingularCapability(int detectionCapability) { + // Check whether the value is 0, or the value has only one bit set. + return (detectionCapability & (detectionCapability - 1)) == 0; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace occupant_awareness +} // namespace automotive +} // namespace hardware +} // namespace android diff --git a/automotive/occupant_awareness/aidl/default/OccupantAwareness.h b/automotive/occupant_awareness/aidl/default/OccupantAwareness.h new file mode 100644 index 0000000000..ac51aa4327 --- /dev/null +++ b/automotive/occupant_awareness/aidl/default/OccupantAwareness.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once +#include +#include +#include + +namespace android { +namespace hardware { +namespace automotive { +namespace occupant_awareness { +namespace V1_0 { +namespace implementation { + +using ::aidl::android::hardware::automotive::occupant_awareness::BnOccupantAwareness; +using ::aidl::android::hardware::automotive::occupant_awareness::IOccupantAwarenessClientCallback; +using ::aidl::android::hardware::automotive::occupant_awareness::OccupantAwarenessStatus; +using ::aidl::android::hardware::automotive::occupant_awareness::OccupantDetections; +using ::aidl::android::hardware::automotive::occupant_awareness::Role; + +/** + * The default HAL mimics a system which has no Occupant awareness capability. The hal does not + * do any useful work, and returns appropriate failure code / status. + **/ +class OccupantAwareness : public BnOccupantAwareness { + public: + // Methods from ::android::hardware::automotive::occupant_awareness::IOccupantAwareness + // follow. + ndk::ScopedAStatus startDetection(OccupantAwarenessStatus* status) override; + ndk::ScopedAStatus stopDetection(OccupantAwarenessStatus* status) override; + ndk::ScopedAStatus getCapabilityForRole(Role occupantRole, int32_t* capabilities) override; + ndk::ScopedAStatus getState(Role occupantRole, int detectionCapability, + OccupantAwarenessStatus* status) override; + ndk::ScopedAStatus setCallback( + const std::shared_ptr& callback) override; + ndk::ScopedAStatus getLatestDetection(OccupantDetections* detections) override; + + private: + bool isValidRole(Role occupantRole); + bool isValidDetectionCapabilities(int detectionCapabilities); + bool isSingularCapability(int detectionCapability); + + std::mutex mMutex; + std::shared_ptr mCallback = nullptr; + OccupantAwarenessStatus mStatus = OccupantAwarenessStatus::NOT_INITIALIZED; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace occupant_awareness +} // namespace automotive +} // namespace hardware +} // namespace android diff --git a/automotive/occupant_awareness/aidl/default/android.hardware.automotive.occupant_awareness@1.0-service.rc b/automotive/occupant_awareness/aidl/default/android.hardware.automotive.occupant_awareness@1.0-service.rc new file mode 100644 index 0000000000..35d5bca66c --- /dev/null +++ b/automotive/occupant_awareness/aidl/default/android.hardware.automotive.occupant_awareness@1.0-service.rc @@ -0,0 +1,4 @@ +service hal_occupant_awareness_default /vendor/bin/hw/android.hardware.automotive.occupant_awareness@1.0-service + class hal + user system + group system diff --git a/automotive/occupant_awareness/aidl/default/service.cpp b/automotive/occupant_awareness/aidl/default/service.cpp new file mode 100644 index 0000000000..44960fb13d --- /dev/null +++ b/automotive/occupant_awareness/aidl/default/service.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "android.hardware.automotive.occupant_awareness@1.0-service" + +#include + +#include +#include +#include + +#include "OccupantAwareness.h" + +using ::aidl::android::hardware::automotive::occupant_awareness::IOccupantAwareness; +using ::android::hardware::automotive::occupant_awareness::V1_0::implementation::OccupantAwareness; +using ::ndk::ScopedAStatus; +using ::ndk::SharedRefBase; + +const static char kOccupantAwarenessServiceName[] = "default"; + +int main() { + ABinderProcess_setThreadPoolMaxThreadCount(0); + LOG(INFO) << "Occupant Awareness service is starting"; + std::shared_ptr occupantAwareness = SharedRefBase::make(); + + const std::string instance = + std::string() + IOccupantAwareness::descriptor + "/" + kOccupantAwarenessServiceName; + + binder_status_t status = + AServiceManager_addService(occupantAwareness->asBinder().get(), instance.c_str()); + if (status == STATUS_OK) { + LOG(INFO) << "Service " << kOccupantAwarenessServiceName << " is ready"; + ABinderProcess_joinThreadPool(); + } else { + LOG(ERROR) << "Could not register service " << kOccupantAwarenessServiceName + << ", status: " << status; + } + + // In normal operation, we don't expect the thread pool to exit. + LOG(ERROR) << "Occupant Awareness service is shutting down"; + return 1; +} diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 4bd833251a..c9eb6d4ef9 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -49,6 +49,13 @@ default + + android.hardware.automotive.occupant_awareness + + IOccupantAwareness + default + + android.hardware.automotive.vehicle 2.0