Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4372ea1b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove the default implementation for NFC aidl HAL" into main

parents bb35effe 60cd14a5
Loading
Loading
Loading
Loading

nfc/aidl/default/Android.bp

deleted100644 → 0
+0 −33
Original line number Diff line number Diff line
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",
    ],
}

nfc/aidl/default/Nfc.cpp

deleted100644 → 0
+0 −160
Original line number Diff line number Diff line
/*
 * 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 <android-base/logging.h>

#include "Vendor_hal_api.h"

namespace aidl {
namespace android {
namespace hardware {
namespace nfc {

std::shared_ptr<INfcClientCallback> 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<Nfc*>(cookie);
        nfc->close(NfcCloseType::DISABLE);
    }
}

::ndk::ScopedAStatus Nfc::open(const std::shared_ptr<INfcClientCallback>& clientCallback) {
    LOG(INFO) << "open";
    if (clientCallback == nullptr) {
        LOG(INFO) << "Nfc::open null callback";
        return ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(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<int32_t>(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<int32_t>(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<int32_t>(NfcStatus::FAILED));
}

::ndk::ScopedAStatus Nfc::coreInitialized() {
    LOG(INFO) << "coreInitialized";
    if (Nfc::mCallback == nullptr) {
        LOG(ERROR) << __func__ << "mCallback null";
        return ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(NfcStatus::FAILED));
    }
    int ret = Vendor_hal_core_initialized();

    return ret == 0 ? ndk::ScopedAStatus::ok()
                    : ndk::ScopedAStatus::fromServiceSpecificError(
                              static_cast<int32_t>(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<int32_t>(NfcStatus::FAILED));
    }
    return Vendor_hal_power_cycle() ? ndk::ScopedAStatus::fromServiceSpecificError(
                                              static_cast<int32_t>(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<int32_t>(NfcStatus::FAILED));
    }
    return Vendor_hal_pre_discover() ? ndk::ScopedAStatus::fromServiceSpecificError(
                                               static_cast<int32_t>(NfcStatus::FAILED))
                                     : ndk::ScopedAStatus::ok();
}

::ndk::ScopedAStatus Nfc::write(const std::vector<uint8_t>& data, int32_t* _aidl_return) {
    LOG(INFO) << "write";
    if (Nfc::mCallback == nullptr) {
        LOG(ERROR) << __func__ << "mCallback null";
        return ndk::ScopedAStatus::fromServiceSpecificError(
                static_cast<int32_t>(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

nfc/aidl/default/Nfc.h

deleted100644 → 0
+0 −72
Original line number Diff line number Diff line
/*
 * 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 <aidl/android/hardware/nfc/BnNfc.h>
#include <aidl/android/hardware/nfc/INfcClientCallback.h>
#include <android-base/logging.h>
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<INfcClientCallback>& 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<uint8_t>& 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<uint8_t> 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<INfcClientCallback> mCallback;
};

}  // namespace nfc
}  // namespace hardware
}  // namespace android
}  // namespace aidl
+0 −71
Original line number Diff line number Diff line
/*
 * 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 <android-base/properties.h>
#include <dlfcn.h>
#include <errno.h>
#include <string.h>

#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;
}

nfc/aidl/default/Vendor_hal_api.h

deleted100644 → 0
+0 −51
Original line number Diff line number Diff line
/*
 * 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 <aidl/android/hardware/nfc/INfc.h>
#include <aidl/android/hardware/nfc/NfcConfig.h>
#include <aidl/android/hardware/nfc/NfcEvent.h>
#include <aidl/android/hardware/nfc/NfcStatus.h>
#include <aidl/android/hardware/nfc/PresenceCheckAlgorithm.h>
#include <aidl/android/hardware/nfc/ProtocolDiscoveryConfig.h>
#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();
Loading