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 #pragma once
18 #include <aidl/android/hardware/automotive/occupant_awareness/BnOccupantAwareness.h>
19 #include <aidl/android/hardware/automotive/occupant_awareness/BnOccupantAwarenessClientCallback.h>
20 #include <utils/StrongPointer.h>
21 
22 namespace android {
23 namespace hardware {
24 namespace automotive {
25 namespace occupant_awareness {
26 namespace V1_0 {
27 namespace implementation {
28 
29 using ::aidl::android::hardware::automotive::occupant_awareness::BnOccupantAwareness;
30 using ::aidl::android::hardware::automotive::occupant_awareness::IOccupantAwarenessClientCallback;
31 using ::aidl::android::hardware::automotive::occupant_awareness::OccupantAwarenessStatus;
32 using ::aidl::android::hardware::automotive::occupant_awareness::OccupantDetections;
33 using ::aidl::android::hardware::automotive::occupant_awareness::Role;
34 
35 /**
36  * The default HAL mimics a system which has no Occupant awareness capability. The hal does not
37  * do any useful work, and returns appropriate failure code / status.
38  **/
39 class OccupantAwareness : public BnOccupantAwareness {
40   public:
41     // Methods from ::android::hardware::automotive::occupant_awareness::IOccupantAwareness
42     // follow.
43     ndk::ScopedAStatus startDetection(OccupantAwarenessStatus* status) override;
44     ndk::ScopedAStatus stopDetection(OccupantAwarenessStatus* status) override;
45     ndk::ScopedAStatus getCapabilityForRole(Role occupantRole, int32_t* capabilities) override;
46     ndk::ScopedAStatus getState(Role occupantRole, int detectionCapability,
47                                 OccupantAwarenessStatus* status) override;
48     ndk::ScopedAStatus setCallback(
49             const std::shared_ptr<IOccupantAwarenessClientCallback>& callback) override;
50     ndk::ScopedAStatus getLatestDetection(OccupantDetections* detections) override;
51 
52   private:
53     bool isValidRole(Role occupantRole);
54     bool isValidDetectionCapabilities(int detectionCapabilities);
55     bool isSingularCapability(int detectionCapability);
56 
57     std::mutex mMutex;
58     std::shared_ptr<IOccupantAwarenessClientCallback> mCallback = nullptr;
59     OccupantAwarenessStatus mStatus = OccupantAwarenessStatus::NOT_INITIALIZED;
60 };
61 
62 }  // namespace implementation
63 }  // namespace V1_0
64 }  // namespace occupant_awareness
65 }  // namespace automotive
66 }  // namespace hardware
67 }  // namespace android
68