[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
This commit is contained in:
Pomai Ahlo 2022-12-12 13:58:55 -08:00
parent 26ae127557
commit 1d10db6063
11 changed files with 423 additions and 0 deletions

View file

@ -589,6 +589,16 @@
<instance>slot3</instance>
</interface>
</hal>
<hal format="aidl" optional="true">
<name>android.hardware.radio.sap</name>
<version>1</version>
<interface>
<name>ISap</name>
<instance>slot1</instance>
<instance>slot2</instance>
<instance>slot3</instance>
</interface>
</hal>
<hal format="aidl" optional="true">
<name>android.hardware.radio.voice</name>
<version>1</version>

View file

@ -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",

View file

@ -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);
}

View file

@ -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);

View file

@ -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 <aidl/android/hardware/radio/sap/BnSap.h>
#include <android/hardware/radio/1.0/ISap.h>
#include <android/hardware/radio/1.0/ISapCallback.h>
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<radio::V1_0::ISap> mHal;
const sp<SapCallback> mSapCallback;
::ndk::ScopedAStatus apduReq(int32_t serial,
aidl::android::hardware::radio::sap::SapApduType type,
const std::vector<uint8_t>& 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<V1_0::ISap> hidlHal);
};
} // namespace android::hardware::radio::compat

View file

@ -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 <aidl/android/hardware/radio/sap/ISapCallback.h>
#include <android/hardware/radio/1.0/ISapCallback.h>
namespace android::hardware::radio::compat {
class SapCallback : public V1_0::ISapCallback {
GuaranteedCallback<aidl::android::hardware::radio::sap::ISapCallback,
aidl::android::hardware::radio::sap::ISapCallbackDefault>
mCallback;
Return<void> apduResponse(int32_t serial, V1_0::SapResultCode resultCode,
const ::android::hardware::hidl_vec<uint8_t>& apduRsp) override;
Return<void> connectResponse(int32_t serial, V1_0::SapConnectRsp sapConnectRsp,
int32_t maxMsgSize) override;
Return<void> disconnectIndication(int32_t serial,
V1_0::SapDisconnectType disconnectType) override;
Return<void> disconnectResponse(int32_t serial) override;
Return<void> errorResponse(int32_t serial) override;
Return<void> powerResponse(int32_t serial, V1_0::SapResultCode resultCode) override;
Return<void> resetSimResponse(int32_t serial, V1_0::SapResultCode resultCode) override;
Return<void> statusIndication(int32_t serial, V1_0::SapStatus status) override;
Return<void> transferAtrResponse(int32_t serial, V1_0::SapResultCode resultCode,
const ::android::hardware::hidl_vec<uint8_t>& atr) override;
Return<void> transferCardReaderStatusResponse(int32_t serial, V1_0::SapResultCode resultCode,
int32_t cardReaderStatus) override;
Return<void> transferProtocolResponse(int32_t serial, V1_0::SapResultCode resultCode) override;
public:
void setResponseFunction(
const std::shared_ptr<aidl::android::hardware::radio::sap::ISapCallback>& callback);
std::shared_ptr<aidl::android::hardware::radio::sap::ISapCallback> respond();
};
} // namespace android::hardware::radio::compat

View file

@ -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 <libradiocompat/Sap.h>
#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<V1_0::ISap> hidlHal) : mHal(hidlHal), mSapCallback(sp<SapCallback>::make()) {}
ScopedAStatus Sap::apduReq(int32_t serial, aidl::SapApduType type,
const std::vector<uint8_t>& 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

View file

@ -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 <libradiocompat/SapCallback.h>
#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<aidl::ISapCallback>& callback) {
mCallback = callback;
}
std::shared_ptr<aidl::ISapCallback> SapCallback::respond() {
return mCallback.get();
}
Return<void> SapCallback::apduResponse(int32_t serial, V1_0::SapResultCode resultCode,
const hidl_vec<uint8_t>& apduRsp) {
LOG_CALL << serial;
respond()->apduResponse(serial, toAidl(resultCode), apduRsp);
return {};
}
Return<void> SapCallback::connectResponse(int32_t serial, V1_0::SapConnectRsp sapConnectRsp,
int32_t maxMsgSize) {
LOG_CALL << serial;
respond()->connectResponse(serial, toAidl(sapConnectRsp), maxMsgSize);
return {};
}
Return<void> SapCallback::disconnectIndication(int32_t serial,
V1_0::SapDisconnectType disconnectType) {
LOG_CALL << serial;
respond()->disconnectIndication(serial, toAidl(disconnectType));
return {};
}
Return<void> SapCallback::disconnectResponse(int32_t serial) {
LOG_CALL << serial;
respond()->disconnectResponse(serial);
return {};
}
Return<void> SapCallback::errorResponse(int32_t serial) {
LOG_CALL << serial;
respond()->errorResponse(serial);
return {};
}
Return<void> SapCallback::powerResponse(int32_t serial, V1_0::SapResultCode resultCode) {
LOG_CALL << serial;
respond()->powerResponse(serial, toAidl(resultCode));
return {};
}
Return<void> SapCallback::resetSimResponse(int32_t serial, V1_0::SapResultCode resultCode) {
LOG_CALL << serial;
respond()->resetSimResponse(serial, toAidl(resultCode));
return {};
}
Return<void> SapCallback::statusIndication(int32_t serial, V1_0::SapStatus status) {
LOG_CALL << serial;
respond()->statusIndication(serial, toAidl(status));
return {};
}
Return<void> SapCallback::transferAtrResponse(int32_t serial, V1_0::SapResultCode resultCode,
const hidl_vec<uint8_t>& atr) {
LOG_CALL << serial;
respond()->transferAtrResponse(serial, toAidl(resultCode), atr);
return {};
}
Return<void> SapCallback::transferCardReaderStatusResponse(int32_t serial,
V1_0::SapResultCode resultCode,
int32_t cardReaderStatus) {
LOG_CALL << serial;
respond()->transferCardReaderStatusResponse(serial, toAidl(resultCode), cardReaderStatus);
return {};
}
Return<void> SapCallback::transferProtocolResponse(int32_t serial, V1_0::SapResultCode resultCode) {
LOG_CALL << serial;
respond()->transferProtocolResponse(serial, toAidl(resultCode));
return {};
}
} // namespace android::hardware::radio::compat

View file

@ -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

View file

@ -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 <aidl/android/hardware/radio/sap/ISap.h>
#include <android/hardware/radio/1.0/types.h>
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

View file

@ -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",