1 /*
2  * Copyright (C) 2022 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 #ifndef FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERASERVICELISTENER_H_
18 #define FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERASERVICELISTENER_H_
19 
20 
21 #include <aidl/DeathPipe.h>
22 #include <aidl/android/frameworks/cameraservice/service/CameraDeviceStatus.h>
23 #include <aidl/android/frameworks/cameraservice/service/ICameraServiceListener.h>
24 #include <android/hardware/BnCameraServiceListener.h>
25 
26 namespace android::frameworks::cameraservice::service::implementation {
27 
28 using ::android::frameworks::cameraservice::utils::DeathPipe;
29 
30 // VNDK classes
31 using SCameraDeviceStatus = ::aidl::android::frameworks::cameraservice::service::CameraDeviceStatus;
32 using SICameraServiceListener =
33         ::aidl::android::frameworks::cameraservice::service::ICameraServiceListener;
34 // NDK classes
35 using UBnCameraServiceListener = ::android::hardware::BnCameraServiceListener;
36 
37 /**
38  * A simple shim to pass calls from CameraService to VNDK client.
39  */
40 class AidlCameraServiceListener : public UBnCameraServiceListener {
41   public:
AidlCameraServiceListener(const std::shared_ptr<SICameraServiceListener> & base)42     AidlCameraServiceListener(const std::shared_ptr<SICameraServiceListener>& base):
43           mBase(base), mDeathPipe(this, base->asBinder()) {}
44 
45     ~AidlCameraServiceListener() = default;
46 
47     ::android::binder::Status onStatusChanged(int32_t status,
48             const std::string& cameraId, int32_t deviceId) override;
49     ::android::binder::Status onPhysicalCameraStatusChanged(int32_t status,
50             const std::string& cameraId,
51             const std::string& physicalCameraId,
52             int32_t deviceId) override;
53 
54     ::android::binder::Status onTorchStatusChanged(
55             int32_t status, const std::string& cameraId, int32_t deviceId) override;
56     ::android::binder::Status onTorchStrengthLevelChanged(
57             const std::string& cameraId, int32_t newStrengthLevel, int32_t deviceId) override;
onCameraAccessPrioritiesChanged()58     binder::Status onCameraAccessPrioritiesChanged() override {
59         // TODO: no implementation yet.
60         return binder::Status::ok();
61     }
onCameraOpened(const std::string &,const std::string &,int32_t)62     binder::Status onCameraOpened([[maybe_unused]] const std::string& /*cameraId*/,
63             [[maybe_unused]] const std::string& /*clientPackageId*/,
64             [[maybe_unused]] int32_t /*deviceId*/) override {
65         // empty implementation
66         return binder::Status::ok();
67     }
onCameraClosed(const std::string &,int32_t)68     binder::Status onCameraClosed([[maybe_unused]] const std::string& /*cameraId*/,
69             [[maybe_unused]] int32_t /*deviceId*/) override {
70         // empty implementation
71         return binder::Status::ok();
72     }
73 
74     status_t linkToDeath(const sp<DeathRecipient>& recipient, void* cookie,
75                          uint32_t flags) override;
76     status_t unlinkToDeath(const wp<DeathRecipient>& recipient, void* cookie, uint32_t flags,
77                            wp<DeathRecipient>* outRecipient) override;
78 
79   private:
80     std::shared_ptr<SICameraServiceListener> mBase;
81 
82     // Pipes death subscription to current NDK AIDL interface to VNDK mBase.
83     // Should consume calls to linkToDeath and unlinkToDeath.
84     DeathPipe mDeathPipe;
85 };
86 
87 } // android
88 
89 #endif // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERASERVICELISTENER_H_