1 /*
2  * Copyright (C) 2021 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 #pragma once
17 
18 #include "RadioConfigIndication.h"
19 #include "RadioConfigResponse.h"
20 
21 #include <aidl/android/hardware/radio/config/BnRadioConfig.h>
22 #include <android/hardware/radio/config/1.2/IRadioConfigIndication.h>
23 #include <android/hardware/radio/config/1.3/IRadioConfig.h>
24 #include <android/hardware/radio/config/1.3/IRadioConfigResponse.h>
25 
26 namespace android::hardware::radio::compat {
27 
28 /**
29  * HAL translator from HIDL IRadioConfig to AIDL IRadioConfig.
30  *
31  * This class wraps existing HIDL implementation (either a binder stub or real
32  * class implementing the HAL) and implements AIDL HAL. It's up to the caller to
33  * fetch source implementation and publish resulting HAL instance.
34  */
35 class RadioConfig : public aidl::android::hardware::radio::config::BnRadioConfig {
36     const sp<config::V1_1::IRadioConfig> mHal1_1;
37     const sp<config::V1_3::IRadioConfig> mHal1_3;
38 
39     const sp<RadioConfigResponse> mRadioConfigResponse;
40     const sp<RadioConfigIndication> mRadioConfigIndication;
41 
42     ::ndk::ScopedAStatus getHalDeviceCapabilities(int32_t serial) override;
43     ::ndk::ScopedAStatus getNumOfLiveModems(int32_t serial) override;
44     ::ndk::ScopedAStatus getPhoneCapability(int32_t serial) override;
45     ::ndk::ScopedAStatus getSimultaneousCallingSupport(int32_t serial) override;
46     ::ndk::ScopedAStatus getSimSlotsStatus(int32_t serial) override;
47     ::ndk::ScopedAStatus setNumOfLiveModems(int32_t serial, int8_t numOfLiveModems) override;
48     ::ndk::ScopedAStatus setPreferredDataModem(int32_t serial, int8_t modemId) override;
49     ::ndk::ScopedAStatus setResponseFunctions(
50             const std::shared_ptr<aidl::android::hardware::radio::config::IRadioConfigResponse>&
51                     radioConfigResponse,
52             const std::shared_ptr<aidl::android::hardware::radio::config::IRadioConfigIndication>&
53                     radioConfigIndication) override;
54     ::ndk::ScopedAStatus setSimSlotsMapping(
55             int32_t serial,
56             const std::vector<aidl::android::hardware::radio::config::SlotPortMapping>& slotMap)
57             override;
58 
59   protected:
60     std::shared_ptr<::aidl::android::hardware::radio::config::IRadioConfigResponse> respond();
61 
62   public:
63     /**
64      * Constructs AIDL IRadioConfig instance wrapping existing HIDL IRadioConfig instance.
65      *
66      * \param hidlHal existing HIDL IRadioConfig HAL instance
67      */
68     RadioConfig(sp<config::V1_1::IRadioConfig> hidlHal);
69 };
70 
71 }  // namespace android::hardware::radio::compat
72