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

Commit 97cf2b75 authored by Ruchi Kandoi's avatar Ruchi Kandoi Committed by android-build-merger
Browse files

Merge "Nfc: Null ptr checks in HAL" am: 3b4d423d am: 0ee41f6f

am: 87e7c643

Change-Id: I8706702a3f55ecb6c034e8aa02b3ab4011c2c006
parents 04a9f9ab 87e7c643
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ namespace nfc {
namespace V1_0 {
namespace implementation {

sp<INfcClientCallback> Nfc::mCallback = NULL;
sp<INfcClientCallback> Nfc::mCallback = nullptr;

Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
    mDeathRecipient(new NfcDeathRecipient(this)) {
@@ -21,35 +21,58 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
// Methods from ::android::hardware::nfc::V1_0::INfc follow.
::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback)  {
    mCallback = clientCallback;

    if (mDevice == nullptr || mCallback == nullptr) {
        return NfcStatus::FAILED;
    }
    mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/);
    int ret = mDevice->open(mDevice, eventCallback, dataCallback);
    return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}

::android::hardware::Return<uint32_t> Nfc::write(const hidl_vec<uint8_t>& data)  {
    if (mDevice == nullptr) {
        return -1;
    }
    return mDevice->write(mDevice, data.size(), &data[0]);
}

::android::hardware::Return<NfcStatus> Nfc::coreInitialized(const hidl_vec<uint8_t>& data)  {
    hidl_vec<uint8_t> copy = data;

    if (mDevice == nullptr) {
        return NfcStatus::FAILED;
    }
    int ret = mDevice->core_initialized(mDevice, &copy[0]);
    return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}

::android::hardware::Return<NfcStatus> Nfc::prediscover()  {
    if (mDevice == nullptr) {
        return NfcStatus::FAILED;
    }
    return mDevice->pre_discover(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

::android::hardware::Return<NfcStatus> Nfc::close()  {
    if (mDevice == nullptr || mCallback == nullptr) {
        return NfcStatus::FAILED;
    }
    mCallback->unlinkToDeath(mDeathRecipient);
    return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

::android::hardware::Return<NfcStatus> Nfc::controlGranted()  {
    if (mDevice == nullptr) {
        return NfcStatus::FAILED;
    }
    return mDevice->control_granted(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

::android::hardware::Return<NfcStatus> Nfc::powerCycle()  {
    if (mDevice == nullptr) {
        return NfcStatus::FAILED;
    }
    return mDevice->power_cycle(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}

@@ -57,11 +80,10 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
INfc* HIDL_FETCH_INfc(const char * /*name*/) {
    nfc_nci_device_t* nfc_device;
    int ret = 0;
    const hw_module_t* hw_module = NULL;
    const hw_module_t* hw_module = nullptr;

    ret = hw_get_module (NFC_NCI_HARDWARE_MODULE_ID, &hw_module);
    if (ret == 0)
    {
    if (ret == 0) {
        ret = nfc_nci_open (hw_module, &nfc_device);
        if (ret != 0) {
            ALOGE ("nfc_nci_open failed: %d", ret);