diff --git a/nfc/aidl/default/Android.bp b/nfc/aidl/default/Android.bp deleted file mode 100644 index 0cda51ddb7..0000000000 --- a/nfc/aidl/default/Android.bp +++ /dev/null @@ -1,33 +0,0 @@ -package { - default_team: "trendy_team_fwk_nfc", - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "hardware_interfaces_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["hardware_interfaces_license"], -} - -cc_binary { - name: "android.hardware.nfc-service.example", - relative_install_path: "hw", - init_rc: ["nfc-service-example.rc"], - vintf_fragments: ["nfc-service-example.xml"], - vendor: true, - cflags: [ - "-Wall", - "-Wextra", - ], - shared_libs: [ - "libbase", - "liblog", - "libutils", - "libbinder_ndk", - "android.hardware.nfc-V1-ndk", - ], - srcs: [ - "main.cpp", - "Nfc.cpp", - "Vendor_hal_api.cpp", - ], -} diff --git a/nfc/aidl/default/Nfc.cpp b/nfc/aidl/default/Nfc.cpp deleted file mode 100644 index 4685b59236..0000000000 --- a/nfc/aidl/default/Nfc.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2021 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 "Nfc.h" - -#include - -#include "Vendor_hal_api.h" - -namespace aidl { -namespace android { -namespace hardware { -namespace nfc { - -std::shared_ptr Nfc::mCallback = nullptr; -AIBinder_DeathRecipient* clientDeathRecipient = nullptr; - -void OnDeath(void* cookie) { - if (Nfc::mCallback != nullptr && !AIBinder_isAlive(Nfc::mCallback->asBinder().get())) { - LOG(INFO) << __func__ << " Nfc service has died"; - Nfc* nfc = static_cast(cookie); - nfc->close(NfcCloseType::DISABLE); - } -} - -::ndk::ScopedAStatus Nfc::open(const std::shared_ptr& clientCallback) { - LOG(INFO) << "open"; - if (clientCallback == nullptr) { - LOG(INFO) << "Nfc::open null callback"; - return ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); - } - Nfc::mCallback = clientCallback; - - clientDeathRecipient = AIBinder_DeathRecipient_new(OnDeath); - auto linkRet = AIBinder_linkToDeath(clientCallback->asBinder().get(), clientDeathRecipient, - this /* cookie */); - if (linkRet != STATUS_OK) { - LOG(ERROR) << __func__ << ": linkToDeath failed: " << linkRet; - // Just ignore the error. - } - - int ret = Vendor_hal_open(eventCallback, dataCallback); - return ret == 0 ? ndk::ScopedAStatus::ok() - : ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); -} - -::ndk::ScopedAStatus Nfc::close(NfcCloseType type) { - LOG(INFO) << "close"; - if (Nfc::mCallback == nullptr) { - LOG(ERROR) << __func__ << "mCallback null"; - return ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); - } - int ret = 0; - if (type == NfcCloseType::HOST_SWITCHED_OFF) { - ret = Vendor_hal_close_off(); - } else { - ret = Vendor_hal_close(); - } - Nfc::mCallback = nullptr; - AIBinder_DeathRecipient_delete(clientDeathRecipient); - clientDeathRecipient = nullptr; - return ret == 0 ? ndk::ScopedAStatus::ok() - : ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); -} - -::ndk::ScopedAStatus Nfc::coreInitialized() { - LOG(INFO) << "coreInitialized"; - if (Nfc::mCallback == nullptr) { - LOG(ERROR) << __func__ << "mCallback null"; - return ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); - } - int ret = Vendor_hal_core_initialized(); - - return ret == 0 ? ndk::ScopedAStatus::ok() - : ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); -} - -::ndk::ScopedAStatus Nfc::factoryReset() { - LOG(INFO) << "factoryReset"; - Vendor_hal_factoryReset(); - return ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus Nfc::getConfig(NfcConfig* _aidl_return) { - LOG(INFO) << "getConfig"; - NfcConfig nfcVendorConfig; - Vendor_hal_getConfig(nfcVendorConfig); - - *_aidl_return = nfcVendorConfig; - return ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus Nfc::powerCycle() { - LOG(INFO) << "powerCycle"; - if (Nfc::mCallback == nullptr) { - LOG(ERROR) << __func__ << "mCallback null"; - return ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); - } - return Vendor_hal_power_cycle() ? ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)) - : ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus Nfc::preDiscover() { - LOG(INFO) << "preDiscover"; - if (Nfc::mCallback == nullptr) { - LOG(ERROR) << __func__ << "mCallback null"; - return ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); - } - return Vendor_hal_pre_discover() ? ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)) - : ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus Nfc::write(const std::vector& data, int32_t* _aidl_return) { - LOG(INFO) << "write"; - if (Nfc::mCallback == nullptr) { - LOG(ERROR) << __func__ << "mCallback null"; - return ndk::ScopedAStatus::fromServiceSpecificError( - static_cast(NfcStatus::FAILED)); - } - *_aidl_return = Vendor_hal_write(data.size(), &data[0]); - return ndk::ScopedAStatus::ok(); -} -::ndk::ScopedAStatus Nfc::setEnableVerboseLogging(bool enable) { - LOG(INFO) << "setVerboseLogging"; - Vendor_hal_setVerboseLogging(enable); - return ndk::ScopedAStatus::ok(); -} - -::ndk::ScopedAStatus Nfc::isVerboseLoggingEnabled(bool* _aidl_return) { - *_aidl_return = Vendor_hal_getVerboseLogging(); - return ndk::ScopedAStatus::ok(); -} - -} // namespace nfc -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/nfc/aidl/default/Nfc.h b/nfc/aidl/default/Nfc.h deleted file mode 100644 index 1b14534e1a..0000000000 --- a/nfc/aidl/default/Nfc.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2021 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 -#include -#include -namespace aidl { -namespace android { -namespace hardware { -namespace nfc { - -using ::aidl::android::hardware::nfc::NfcCloseType; -using ::aidl::android::hardware::nfc::NfcConfig; -using ::aidl::android::hardware::nfc::NfcStatus; - -// Default implementation that reports no support NFC. -struct Nfc : public BnNfc { - public: - Nfc() = default; - - ::ndk::ScopedAStatus open(const std::shared_ptr& clientCallback) override; - ::ndk::ScopedAStatus close(NfcCloseType type) override; - ::ndk::ScopedAStatus coreInitialized() override; - ::ndk::ScopedAStatus factoryReset() override; - ::ndk::ScopedAStatus getConfig(NfcConfig* _aidl_return) override; - ::ndk::ScopedAStatus powerCycle() override; - ::ndk::ScopedAStatus preDiscover() override; - ::ndk::ScopedAStatus write(const std::vector& data, int32_t* _aidl_return) override; - ::ndk::ScopedAStatus setEnableVerboseLogging(bool enable) override; - ::ndk::ScopedAStatus isVerboseLoggingEnabled(bool* _aidl_return) override; - - static void eventCallback(uint8_t event, uint8_t status) { - if (mCallback != nullptr) { - auto ret = mCallback->sendEvent((NfcEvent)event, (NfcStatus)status); - if (!ret.isOk()) { - LOG(ERROR) << "Failed to send event!"; - } - } - } - - static void dataCallback(uint16_t data_len, uint8_t* p_data) { - std::vector data(p_data, p_data + data_len); - if (mCallback != nullptr) { - auto ret = mCallback->sendData(data); - if (!ret.isOk()) { - LOG(ERROR) << "Failed to send data!"; - } - } - } - - static std::shared_ptr mCallback; -}; - -} // namespace nfc -} // namespace hardware -} // namespace android -} // namespace aidl diff --git a/nfc/aidl/default/Vendor_hal_api.cpp b/nfc/aidl/default/Vendor_hal_api.cpp deleted file mode 100644 index 66a2ebc5de..0000000000 --- a/nfc/aidl/default/Vendor_hal_api.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2021 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 -#include -#include - -#include "Vendor_hal_api.h" - -bool logging = false; - -int Vendor_hal_open(nfc_stack_callback_t* p_cback, nfc_stack_data_callback_t* p_data_cback) { - (void)p_cback; - (void)p_data_cback; - // nothing to open in this example - return -1; -} - -int Vendor_hal_write(uint16_t data_len, const uint8_t* p_data) { - (void)data_len; - (void)p_data; - return -1; -} - -int Vendor_hal_core_initialized() { - return -1; -} - -int Vendor_hal_pre_discover() { - return -1; -} - -int Vendor_hal_close() { - return -1; -} - -int Vendor_hal_close_off() { - return -1; -} - -int Vendor_hal_power_cycle() { - return -1; -} - -void Vendor_hal_factoryReset() {} - -void Vendor_hal_getConfig(NfcConfig& config) { - (void)config; -} - -void Vendor_hal_setVerboseLogging(bool enable) { - logging = enable; -} - -bool Vendor_hal_getVerboseLogging() { - return logging; -} diff --git a/nfc/aidl/default/Vendor_hal_api.h b/nfc/aidl/default/Vendor_hal_api.h deleted file mode 100644 index 595c2dd8aa..0000000000 --- a/nfc/aidl/default/Vendor_hal_api.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2021 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 -#include -#include -#include -#include -#include -#include "hardware_nfc.h" - -using aidl::android::hardware::nfc::NfcConfig; -using aidl::android::hardware::nfc::NfcEvent; -using aidl::android::hardware::nfc::NfcStatus; -using aidl::android::hardware::nfc::PresenceCheckAlgorithm; -using aidl::android::hardware::nfc::ProtocolDiscoveryConfig; - -int Vendor_hal_open(nfc_stack_callback_t* p_cback, nfc_stack_data_callback_t* p_data_cback); -int Vendor_hal_write(uint16_t data_len, const uint8_t* p_data); - -int Vendor_hal_core_initialized(); - -int Vendor_hal_pre_discover(); - -int Vendor_hal_close(); - -int Vendor_hal_close_off(); - -int Vendor_hal_power_cycle(); - -void Vendor_hal_factoryReset(); - -void Vendor_hal_getConfig(NfcConfig& config); - -void Vendor_hal_setVerboseLogging(bool enable); - -bool Vendor_hal_getVerboseLogging(); diff --git a/nfc/aidl/default/hardware_nfc.h b/nfc/aidl/default/hardware_nfc.h deleted file mode 100644 index 0f856c5ac7..0000000000 --- a/nfc/aidl/default/hardware_nfc.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2021 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 - -typedef uint8_t nfc_event_t; -typedef uint8_t nfc_status_t; - -/* - * The callback passed in from the NFC stack that the HAL - * can use to pass events back to the stack. - */ -typedef void(nfc_stack_callback_t)(nfc_event_t event, nfc_status_t event_status); - -/* - * The callback passed in from the NFC stack that the HAL - * can use to pass incomming data to the stack. - */ -typedef void(nfc_stack_data_callback_t)(uint16_t data_len, uint8_t* p_data); diff --git a/nfc/aidl/default/main.cpp b/nfc/aidl/default/main.cpp deleted file mode 100644 index 0cc51e7207..0000000000 --- a/nfc/aidl/default/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2021 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 -#include - -#include "Nfc.h" -using ::aidl::android::hardware::nfc::Nfc; - -int main() { - LOG(INFO) << "NFC HAL starting up"; - if (!ABinderProcess_setThreadPoolMaxThreadCount(1)) { - LOG(INFO) << "failed to set thread pool max thread count"; - return 1; - } - std::shared_ptr nfc_service = ndk::SharedRefBase::make(); - - const std::string instance = std::string() + Nfc::descriptor + "/default"; - binder_status_t status = - AServiceManager_addService(nfc_service->asBinder().get(), instance.c_str()); - CHECK(status == STATUS_OK); - ABinderProcess_joinThreadPool(); - return 0; -} diff --git a/nfc/aidl/default/nfc-service-example.rc b/nfc/aidl/default/nfc-service-example.rc deleted file mode 100644 index 7d7052ef0a..0000000000 --- a/nfc/aidl/default/nfc-service-example.rc +++ /dev/null @@ -1,4 +0,0 @@ -service nfc_hal_service /vendor/bin/hw/android.hardware.nfc-service.st - class hal - user nfc - group nfc diff --git a/nfc/aidl/default/nfc-service-example.xml b/nfc/aidl/default/nfc-service-example.xml deleted file mode 100644 index 70fed205b5..0000000000 --- a/nfc/aidl/default/nfc-service-example.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - android.hardware.nfc - INfc/default - -