From 1d10db6063758091ceb22b5fde75e448def976f1 Mon Sep 17 00:00:00 2001 From: Pomai Ahlo Date: Mon, 12 Dec 2022 13:58:55 -0800 Subject: [PATCH] [ISap hidl2aidl] Compat Support Add support for ISap in the compat shim. Test: atest VtsHalRadioTargetTest:PerInstance/SapTest Bug: 241969533 Change-Id: I9fe5fe194de877bcd2b85ccfa822bd6565e2dc72 Merged-In: I9fe5fe194de877bcd2b85ccfa822bd6565e2dc72 --- .../compatibility_matrix.current.xml | 10 ++ radio/aidl/compat/libradiocompat/Android.bp | 4 + .../compat/libradiocompat/commonStructs.cpp | 4 + .../compat/libradiocompat/commonStructs.h | 1 + .../include/libradiocompat/Sap.h | 64 ++++++++++ .../include/libradiocompat/SapCallback.h | 54 +++++++++ radio/aidl/compat/libradiocompat/sap/Sap.cpp | 94 +++++++++++++++ .../compat/libradiocompat/sap/SapCallback.cpp | 111 ++++++++++++++++++ .../compat/libradiocompat/sap/structs.cpp | 47 ++++++++ .../aidl/compat/libradiocompat/sap/structs.h | 33 ++++++ radio/aidl/compat/service/Android.bp | 1 + 11 files changed, 423 insertions(+) create mode 100644 radio/aidl/compat/libradiocompat/include/libradiocompat/Sap.h create mode 100644 radio/aidl/compat/libradiocompat/include/libradiocompat/SapCallback.h create mode 100644 radio/aidl/compat/libradiocompat/sap/Sap.cpp create mode 100644 radio/aidl/compat/libradiocompat/sap/SapCallback.cpp create mode 100644 radio/aidl/compat/libradiocompat/sap/structs.cpp create mode 100644 radio/aidl/compat/libradiocompat/sap/structs.h diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 5e1589b49b..1d7dd649ae 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -589,6 +589,16 @@ slot3 + + android.hardware.radio.sap + 1 + + ISap + slot1 + slot2 + slot3 + + android.hardware.radio.voice 1 diff --git a/radio/aidl/compat/libradiocompat/Android.bp b/radio/aidl/compat/libradiocompat/Android.bp index 487d91b6b9..aa20fc3fd5 100644 --- a/radio/aidl/compat/libradiocompat/Android.bp +++ b/radio/aidl/compat/libradiocompat/Android.bp @@ -40,6 +40,7 @@ cc_library { "android.hardware.radio.messaging-V1-ndk", "android.hardware.radio.modem-V1-ndk", "android.hardware.radio.network-V1-ndk", + "android.hardware.radio.sap-V1-ndk", "android.hardware.radio.sim-V1-ndk", "android.hardware.radio.voice-V1-ndk", "android.hardware.radio@1.0", @@ -82,6 +83,9 @@ cc_library { "network/RadioResponse-network.cpp", "network/structs.cpp", "network/utils.cpp", + "sap/Sap.cpp", + "sap/SapCallback.cpp", + "sap/structs.cpp", "sim/RadioIndication-sim.cpp", "sim/RadioResponse-sim.cpp", "sim/RadioSim.cpp", diff --git a/radio/aidl/compat/libradiocompat/commonStructs.cpp b/radio/aidl/compat/libradiocompat/commonStructs.cpp index 6e4c873d65..d65ed1a1e4 100644 --- a/radio/aidl/compat/libradiocompat/commonStructs.cpp +++ b/radio/aidl/compat/libradiocompat/commonStructs.cpp @@ -48,6 +48,10 @@ int32_t toAidl(uint32_t v) { return v; } +uint8_t toHidl(int8_t v) { + return v; +} + aidl::RadioIndicationType toAidl(V1_0::RadioIndicationType type) { return aidl::RadioIndicationType(type); } diff --git a/radio/aidl/compat/libradiocompat/commonStructs.h b/radio/aidl/compat/libradiocompat/commonStructs.h index a4a4869e61..f43a599193 100644 --- a/radio/aidl/compat/libradiocompat/commonStructs.h +++ b/radio/aidl/compat/libradiocompat/commonStructs.h @@ -28,6 +28,7 @@ hidl_string toHidl(const std::string& str); uint8_t toAidl(int8_t v); int8_t toAidl(uint8_t v); int32_t toAidl(uint32_t v); +uint8_t toHidl(int8_t v); aidl::android::hardware::radio::RadioIndicationType toAidl(V1_0::RadioIndicationType type); aidl::android::hardware::radio::RadioResponseType toAidl(V1_0::RadioResponseType type); diff --git a/radio/aidl/compat/libradiocompat/include/libradiocompat/Sap.h b/radio/aidl/compat/libradiocompat/include/libradiocompat/Sap.h new file mode 100644 index 0000000000..a293d11d22 --- /dev/null +++ b/radio/aidl/compat/libradiocompat/include/libradiocompat/Sap.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2022 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 "RadioCompatBase.h" +#include "SapCallback.h" + +#include +#include +#include + +namespace android::hardware::radio::compat { + +/** + * HAL translator from HIDL ISap to AIDL ISap + * + * This class wraps existing HIDL implementation (either a binder stub or real + * class implementing the HAL) and implements AIDL HAL. It's up to the caller to + * fetch source implementation and publish resulting HAL instance. + */ +class Sap : public aidl::android::hardware::radio::sap::BnSap { + const sp mHal; + + const sp mSapCallback; + + ::ndk::ScopedAStatus apduReq(int32_t serial, + aidl::android::hardware::radio::sap::SapApduType type, + const std::vector& command) override; + ::ndk::ScopedAStatus connectReq(int32_t serial, int32_t maxMsgSize) override; + ::ndk::ScopedAStatus disconnectReq(int32_t serial) override; + ::ndk::ScopedAStatus powerReq(int32_t serial, bool state) override; + ::ndk::ScopedAStatus resetSimReq(int32_t serial) override; + ::ndk::ScopedAStatus setCallback( + const std::shared_ptr<::aidl::android::hardware::radio::sap::ISapCallback>& sapCallback) + override; + ::ndk::ScopedAStatus setTransferProtocolReq( + int32_t serial, + aidl::android::hardware::radio::sap::SapTransferProtocol transferProtocol) override; + ::ndk::ScopedAStatus transferAtrReq(int32_t serial) override; + ::ndk::ScopedAStatus transferCardReaderStatusReq(int32_t serial) override; + + public: + /** + * Constructs AIDL ISap instance wrapping existing HIDL ISap instance. + * + * \param hidlHal existing HIDL ISap HAL instance + */ + Sap(sp hidlHal); +}; + +} // namespace android::hardware::radio::compat diff --git a/radio/aidl/compat/libradiocompat/include/libradiocompat/SapCallback.h b/radio/aidl/compat/libradiocompat/include/libradiocompat/SapCallback.h new file mode 100644 index 0000000000..7e72106416 --- /dev/null +++ b/radio/aidl/compat/libradiocompat/include/libradiocompat/SapCallback.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 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 "GuaranteedCallback.h" + +#include +#include + +namespace android::hardware::radio::compat { + +class SapCallback : public V1_0::ISapCallback { + GuaranteedCallback + mCallback; + + Return apduResponse(int32_t serial, V1_0::SapResultCode resultCode, + const ::android::hardware::hidl_vec& apduRsp) override; + Return connectResponse(int32_t serial, V1_0::SapConnectRsp sapConnectRsp, + int32_t maxMsgSize) override; + Return disconnectIndication(int32_t serial, + V1_0::SapDisconnectType disconnectType) override; + Return disconnectResponse(int32_t serial) override; + Return errorResponse(int32_t serial) override; + Return powerResponse(int32_t serial, V1_0::SapResultCode resultCode) override; + Return resetSimResponse(int32_t serial, V1_0::SapResultCode resultCode) override; + Return statusIndication(int32_t serial, V1_0::SapStatus status) override; + Return transferAtrResponse(int32_t serial, V1_0::SapResultCode resultCode, + const ::android::hardware::hidl_vec& atr) override; + Return transferCardReaderStatusResponse(int32_t serial, V1_0::SapResultCode resultCode, + int32_t cardReaderStatus) override; + Return transferProtocolResponse(int32_t serial, V1_0::SapResultCode resultCode) override; + + public: + void setResponseFunction( + const std::shared_ptr& callback); + + std::shared_ptr respond(); +}; + +} // namespace android::hardware::radio::compat diff --git a/radio/aidl/compat/libradiocompat/sap/Sap.cpp b/radio/aidl/compat/libradiocompat/sap/Sap.cpp new file mode 100644 index 0000000000..1a77169ab1 --- /dev/null +++ b/radio/aidl/compat/libradiocompat/sap/Sap.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2022 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 + +#include "commonStructs.h" +#include "debug.h" +#include "structs.h" + +#include "collections.h" + +#define RADIO_MODULE "Sap" + +namespace android::hardware::radio::compat { + +using ::ndk::ScopedAStatus; +namespace aidl = ::aidl::android::hardware::radio::sap; +constexpr auto ok = &ScopedAStatus::ok; + +Sap::Sap(sp hidlHal) : mHal(hidlHal), mSapCallback(sp::make()) {} + +ScopedAStatus Sap::apduReq(int32_t serial, aidl::SapApduType type, + const std::vector& command) { + LOG_CALL << serial; + mHal->apduReq(serial, toHidl(type), toHidl(command)); + return ok(); +} + +ScopedAStatus Sap::connectReq(int32_t serial, int32_t maxMsgSize) { + LOG_CALL << serial; + mHal->connectReq(serial, maxMsgSize); + return ok(); +} + +ScopedAStatus Sap::disconnectReq(int32_t serial) { + LOG_CALL << serial; + mHal->disconnectReq(serial); + return ok(); +} + +ScopedAStatus Sap::powerReq(int32_t serial, bool state) { + LOG_CALL << serial; + mHal->powerReq(serial, state); + return ok(); +} + +ScopedAStatus Sap::resetSimReq(int32_t serial) { + LOG_CALL << serial; + mHal->resetSimReq(serial); + return ok(); +} + +ScopedAStatus Sap::setCallback( + const std::shared_ptr<::aidl::android::hardware::radio::sap::ISapCallback>& sapCallback) { + LOG_CALL << sapCallback; + + CHECK(sapCallback); + + mSapCallback->setResponseFunction(sapCallback); + mHal->setCallback(mSapCallback).assertOk(); + return ok(); +} +ScopedAStatus Sap::setTransferProtocolReq(int32_t serial, + aidl::SapTransferProtocol transferProtocol) { + LOG_CALL << serial; + mHal->setTransferProtocolReq(serial, toHidl(transferProtocol)); + return ok(); +} + +ScopedAStatus Sap::transferAtrReq(int32_t serial) { + LOG_CALL << serial; + mHal->transferAtrReq(serial); + return ok(); +} +ScopedAStatus Sap::transferCardReaderStatusReq(int32_t serial) { + LOG_CALL << serial; + mHal->transferCardReaderStatusReq(serial); + return ok(); +} + +} // namespace android::hardware::radio::compat diff --git a/radio/aidl/compat/libradiocompat/sap/SapCallback.cpp b/radio/aidl/compat/libradiocompat/sap/SapCallback.cpp new file mode 100644 index 0000000000..a40dff8d78 --- /dev/null +++ b/radio/aidl/compat/libradiocompat/sap/SapCallback.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2022 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 + +#include "commonStructs.h" +#include "debug.h" +#include "structs.h" + +#include "collections.h" + +#define RADIO_MODULE "SapCallback" + +namespace android::hardware::radio::compat { + +namespace aidl = ::aidl::android::hardware::radio::sap; + +void SapCallback::setResponseFunction(const std::shared_ptr& callback) { + mCallback = callback; +} + +std::shared_ptr SapCallback::respond() { + return mCallback.get(); +} + +Return SapCallback::apduResponse(int32_t serial, V1_0::SapResultCode resultCode, + const hidl_vec& apduRsp) { + LOG_CALL << serial; + respond()->apduResponse(serial, toAidl(resultCode), apduRsp); + return {}; +} + +Return SapCallback::connectResponse(int32_t serial, V1_0::SapConnectRsp sapConnectRsp, + int32_t maxMsgSize) { + LOG_CALL << serial; + respond()->connectResponse(serial, toAidl(sapConnectRsp), maxMsgSize); + return {}; +} + +Return SapCallback::disconnectIndication(int32_t serial, + V1_0::SapDisconnectType disconnectType) { + LOG_CALL << serial; + respond()->disconnectIndication(serial, toAidl(disconnectType)); + return {}; +} + +Return SapCallback::disconnectResponse(int32_t serial) { + LOG_CALL << serial; + respond()->disconnectResponse(serial); + return {}; +} + +Return SapCallback::errorResponse(int32_t serial) { + LOG_CALL << serial; + respond()->errorResponse(serial); + return {}; +} + +Return SapCallback::powerResponse(int32_t serial, V1_0::SapResultCode resultCode) { + LOG_CALL << serial; + respond()->powerResponse(serial, toAidl(resultCode)); + return {}; +} + +Return SapCallback::resetSimResponse(int32_t serial, V1_0::SapResultCode resultCode) { + LOG_CALL << serial; + respond()->resetSimResponse(serial, toAidl(resultCode)); + return {}; +} + +Return SapCallback::statusIndication(int32_t serial, V1_0::SapStatus status) { + LOG_CALL << serial; + respond()->statusIndication(serial, toAidl(status)); + return {}; +} + +Return SapCallback::transferAtrResponse(int32_t serial, V1_0::SapResultCode resultCode, + const hidl_vec& atr) { + LOG_CALL << serial; + respond()->transferAtrResponse(serial, toAidl(resultCode), atr); + return {}; +} + +Return SapCallback::transferCardReaderStatusResponse(int32_t serial, + V1_0::SapResultCode resultCode, + int32_t cardReaderStatus) { + LOG_CALL << serial; + respond()->transferCardReaderStatusResponse(serial, toAidl(resultCode), cardReaderStatus); + return {}; +} + +Return SapCallback::transferProtocolResponse(int32_t serial, V1_0::SapResultCode resultCode) { + LOG_CALL << serial; + respond()->transferProtocolResponse(serial, toAidl(resultCode)); + return {}; +} + +} // namespace android::hardware::radio::compat diff --git a/radio/aidl/compat/libradiocompat/sap/structs.cpp b/radio/aidl/compat/libradiocompat/sap/structs.cpp new file mode 100644 index 0000000000..522056b0ca --- /dev/null +++ b/radio/aidl/compat/libradiocompat/sap/structs.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2022 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 "structs.h" + +namespace android::hardware::radio::compat { + +namespace aidl = ::aidl::android::hardware::radio::sap; + +V1_0::SapApduType toHidl(const aidl::SapApduType sapApduType) { + return V1_0::SapApduType(sapApduType); +} + +V1_0::SapTransferProtocol toHidl(const aidl::SapTransferProtocol sapTransferProtocol) { + return V1_0::SapTransferProtocol(sapTransferProtocol); +} + +aidl::SapResultCode toAidl(const V1_0::SapResultCode sapResultCode) { + return aidl::SapResultCode(sapResultCode); +} + +aidl::SapConnectRsp toAidl(const V1_0::SapConnectRsp sapConnectRsp) { + return aidl::SapConnectRsp(sapConnectRsp); +} + +aidl::SapDisconnectType toAidl(const V1_0::SapDisconnectType sapDisconnectType) { + return aidl::SapDisconnectType(sapDisconnectType); +} + +aidl::SapStatus toAidl(const V1_0::SapStatus sapStatus) { + return aidl::SapStatus(sapStatus); +} + +} // namespace android::hardware::radio::compat diff --git a/radio/aidl/compat/libradiocompat/sap/structs.h b/radio/aidl/compat/libradiocompat/sap/structs.h new file mode 100644 index 0000000000..d88120de70 --- /dev/null +++ b/radio/aidl/compat/libradiocompat/sap/structs.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 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, eithe r express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include + +namespace android::hardware::radio::compat { + +V1_0::SapApduType toHidl(aidl::android::hardware::radio::sap::SapApduType sapAdpuType); +V1_0::SapTransferProtocol toHidl( + aidl::android::hardware::radio::sap::SapTransferProtocol sapTransferProtocol); + +aidl::android::hardware::radio::sap::SapResultCode toAidl(V1_0::SapResultCode sapResultCode); +aidl::android::hardware::radio::sap::SapConnectRsp toAidl(V1_0::SapConnectRsp sapConnectRsp); +aidl::android::hardware::radio::sap::SapDisconnectType toAidl( + V1_0::SapDisconnectType sapDisconnectType); +aidl::android::hardware::radio::sap::SapStatus toAidl(V1_0::SapStatus sapStatus); + +} // namespace android::hardware::radio::compat diff --git a/radio/aidl/compat/service/Android.bp b/radio/aidl/compat/service/Android.bp index 52eb71ff14..933e3e18d2 100644 --- a/radio/aidl/compat/service/Android.bp +++ b/radio/aidl/compat/service/Android.bp @@ -43,6 +43,7 @@ cc_binary { "android.hardware.radio.messaging-V1-ndk", "android.hardware.radio.modem-V1-ndk", "android.hardware.radio.network-V1-ndk", + "android.hardware.radio.sap-V1-ndk", "android.hardware.radio.sim-V1-ndk", "android.hardware.radio.voice-V1-ndk", "android.hardware.radio@1.0",