1 /* 2 * Copyright (C) 2019 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 #include <utils/SystemClock.h> 18 19 #include "DetectionGenerator.h" 20 21 namespace android { 22 namespace hardware { 23 namespace automotive { 24 namespace occupant_awareness { 25 namespace V1_0 { 26 namespace implementation { 27 28 using ::aidl::android::hardware::automotive::occupant_awareness::ConfidenceLevel; 29 using ::aidl::android::hardware::automotive::occupant_awareness::DriverMonitoringDetection; 30 using ::aidl::android::hardware::automotive::occupant_awareness::OccupantDetection; 31 using ::aidl::android::hardware::automotive::occupant_awareness::PresenceDetection; 32 33 static int64_t kNanoSecondsPerMilliSecond = 1000 * 1000; 34 GetNextDetections()35OccupantDetections DetectionGenerator::GetNextDetections() { 36 OccupantDetections detections; 37 detections.timeStampMillis = android::elapsedRealtimeNano() / kNanoSecondsPerMilliSecond; 38 int remainingRoles = getSupportedRoles(); 39 while (remainingRoles) { 40 int currentRole = remainingRoles & (~(remainingRoles - 1)); 41 remainingRoles = remainingRoles & (remainingRoles - 1); 42 43 OccupantDetection occupantDetection; 44 occupantDetection.role = static_cast<Role>(currentRole); 45 46 // Add presence detection object for this occupant. 47 PresenceDetection presenceDetection; 48 presenceDetection.isOccupantDetected = true; 49 presenceDetection.detectionDurationMillis = detections.timeStampMillis; 50 occupantDetection.presenceData.emplace_back(presenceDetection); 51 52 if (occupantDetection.role == Role::DRIVER) { 53 // Add driver monitoring detection object for this occupant. 54 DriverMonitoringDetection driverMonitoringDetection; 55 driverMonitoringDetection.confidenceScore = ConfidenceLevel::HIGH; 56 driverMonitoringDetection.isLookingOnRoad = 0; 57 driverMonitoringDetection.gazeDurationMillis = detections.timeStampMillis; 58 occupantDetection.attentionData.emplace_back(driverMonitoringDetection); 59 } 60 61 detections.detections.emplace_back(occupantDetection); 62 } 63 return detections; 64 } 65 66 } // namespace implementation 67 } // namespace V1_0 68 } // namespace occupant_awareness 69 } // namespace automotive 70 } // namespace hardware 71 } // namespace android 72