1 #include "android/hardware/nfc/1.0/NfcClientCallback.vts.h"
2 #include "vts_measurement.h"
3 #include <android-base/logging.h>
4 #include <android/hidl/allocator/1.0/IAllocator.h>
5 #include <fcntl.h>
6 #include <fmq/MessageQueue.h>
7 #include <sys/stat.h>
8 #include <unistd.h>
9 
10 
11 using namespace android::hardware::nfc::V1_0;
12 namespace android {
13 namespace vts {
GetService(bool get_stub,const char * service_name)14 bool FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback::GetService(bool get_stub, const char* service_name) {
15     static bool initialized = false;
16     if (!initialized) {
17         LOG(INFO) << "HIDL getService";
18         if (service_name) {
19           LOG(INFO) << "  - service name: " << service_name;
20         }
21         hw_binder_proxy_ = ::android::hardware::nfc::V1_0::INfcClientCallback::getService(service_name, get_stub);
22         if (hw_binder_proxy_ == nullptr) {
23             LOG(ERROR) << "getService() returned a null pointer.";
24             return false;
25         }
26         LOG(DEBUG) << "hw_binder_proxy_ = " << hw_binder_proxy_.get();
27         initialized = true;
28     }
29     return true;
30 }
31 
32 
sendEvent(::android::hardware::nfc::V1_0::NfcEvent arg0,::android::hardware::nfc::V1_0::NfcStatus arg1)33 ::android::hardware::Return<void> Vts_android_hardware_nfc_V1_0_INfcClientCallback::sendEvent(
34     ::android::hardware::nfc::V1_0::NfcEvent arg0 __attribute__((__unused__)),
35     ::android::hardware::nfc::V1_0::NfcStatus arg1 __attribute__((__unused__))) {
36     LOG(INFO) << "sendEvent called";
37     AndroidSystemCallbackRequestMessage callback_message;
38     callback_message.set_id(GetCallbackID("sendEvent"));
39     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfcClientCallback::sendEvent");
40     VariableSpecificationMessage* var_msg0 = callback_message.add_arg();
41     var_msg0->set_type(TYPE_ENUM);
42     SetResult__android__hardware__nfc__V1_0__NfcEvent(var_msg0, arg0);
43     VariableSpecificationMessage* var_msg1 = callback_message.add_arg();
44     var_msg1->set_type(TYPE_ENUM);
45     SetResult__android__hardware__nfc__V1_0__NfcStatus(var_msg1, arg1);
46     RpcCallToAgent(callback_message, callback_socket_name_);
47     return ::android::hardware::Void();
48 }
49 
sendData(const::android::hardware::hidl_vec<uint8_t> & arg0)50 ::android::hardware::Return<void> Vts_android_hardware_nfc_V1_0_INfcClientCallback::sendData(
51     const ::android::hardware::hidl_vec<uint8_t>& arg0 __attribute__((__unused__))) {
52     LOG(INFO) << "sendData called";
53     AndroidSystemCallbackRequestMessage callback_message;
54     callback_message.set_id(GetCallbackID("sendData"));
55     callback_message.set_name("Vts_android_hardware_nfc_V1_0_INfcClientCallback::sendData");
56     VariableSpecificationMessage* var_msg0 = callback_message.add_arg();
57     var_msg0->set_type(TYPE_VECTOR);
58     var_msg0->set_vector_size(arg0.size());
59     for (int i = 0; i < (int)arg0.size(); i++) {
60         auto *var_msg0_vector_i = var_msg0->add_vector_value();
61         var_msg0_vector_i->set_type(TYPE_SCALAR);
62         var_msg0_vector_i->set_scalar_type("uint8_t");
63         var_msg0_vector_i->mutable_scalar_value()->set_uint8_t(arg0[i]);
64     }
65     RpcCallToAgent(callback_message, callback_socket_name_);
66     return ::android::hardware::Void();
67 }
68 
VtsFuzzerCreateVts_android_hardware_nfc_V1_0_INfcClientCallback(const string & callback_socket_name)69 sp<::android::hardware::nfc::V1_0::INfcClientCallback> VtsFuzzerCreateVts_android_hardware_nfc_V1_0_INfcClientCallback(const string& callback_socket_name) {
70     static sp<::android::hardware::nfc::V1_0::INfcClientCallback> result;
71     result = new Vts_android_hardware_nfc_V1_0_INfcClientCallback(callback_socket_name);
72     return result;
73 }
74 
Fuzz(FunctionSpecificationMessage *,void **,const string &)75 bool FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback::Fuzz(
76     FunctionSpecificationMessage* /*func_msg*/,
77     void** /*result*/, const string& /*callback_socket_name*/) {
78     return true;
79 }
GetAttribute(FunctionSpecificationMessage *,void **)80 bool FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback::GetAttribute(
81     FunctionSpecificationMessage* /*func_msg*/,
82     void** /*result*/) {
83     LOG(ERROR) << "attribute not found.";
84     return false;
85 }
CallFunction(const FunctionSpecificationMessage & func_msg,const string & callback_socket_name,FunctionSpecificationMessage * result_msg)86 bool FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback::CallFunction(
87     const FunctionSpecificationMessage& func_msg,
88     const string& callback_socket_name __attribute__((__unused__)),
89     FunctionSpecificationMessage* result_msg) {
90     const char* func_name = func_msg.name().c_str();
91     if (hw_binder_proxy_ == nullptr) {
92         LOG(ERROR) << "hw_binder_proxy_ is null. ";
93         return false;
94     }
95     if (!strcmp(func_name, "sendEvent")) {
96         ::android::hardware::nfc::V1_0::NfcEvent arg0;
97         MessageTo__android__hardware__nfc__V1_0__NfcEvent(func_msg.arg(0), &(arg0), callback_socket_name);
98         ::android::hardware::nfc::V1_0::NfcStatus arg1;
99         MessageTo__android__hardware__nfc__V1_0__NfcStatus(func_msg.arg(1), &(arg1), callback_socket_name);
100         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
101         hw_binder_proxy_->sendEvent(arg0, arg1);
102         result_msg->set_name("sendEvent");
103         return true;
104     }
105     if (!strcmp(func_name, "sendData")) {
106         ::android::hardware::hidl_vec<uint8_t> arg0;
107         arg0.resize(func_msg.arg(0).vector_value_size());
108         for (int arg0_index = 0; arg0_index < func_msg.arg(0).vector_value_size(); arg0_index++) {
109             arg0[arg0_index] = func_msg.arg(0).vector_value(arg0_index).scalar_value().uint8_t();
110         }
111         LOG(DEBUG) << "local_device = " << hw_binder_proxy_.get();
112         hw_binder_proxy_->sendData(arg0);
113         result_msg->set_name("sendData");
114         return true;
115     }
116     if (!strcmp(func_name, "notifySyspropsChanged")) {
117         LOG(INFO) << "Call notifySyspropsChanged";
118         hw_binder_proxy_->notifySyspropsChanged();
119         result_msg->set_name("notifySyspropsChanged");
120         return true;
121     }
122     return false;
123 }
124 
VerifyResults(const FunctionSpecificationMessage & expected_result,const FunctionSpecificationMessage & actual_result)125 bool FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback::VerifyResults(const FunctionSpecificationMessage& expected_result __attribute__((__unused__)),
126     const FunctionSpecificationMessage& actual_result __attribute__((__unused__))) {
127     if (!strcmp(actual_result.name().c_str(), "sendEvent")) {
128         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
129         return true;
130     }
131     if (!strcmp(actual_result.name().c_str(), "sendData")) {
132         if (actual_result.return_type_hidl_size() != expected_result.return_type_hidl_size() ) { return false; }
133         return true;
134     }
135     return false;
136 }
137 
138 extern "C" {
vts_func_4_android_hardware_nfc_V1_0_INfcClientCallback_()139 android::vts::DriverBase* vts_func_4_android_hardware_nfc_V1_0_INfcClientCallback_() {
140     return (android::vts::DriverBase*) new android::vts::FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback();
141 }
142 
vts_func_4_android_hardware_nfc_V1_0_INfcClientCallback_with_arg(uint64_t hw_binder_proxy)143 android::vts::DriverBase* vts_func_4_android_hardware_nfc_V1_0_INfcClientCallback_with_arg(uint64_t hw_binder_proxy) {
144     ::android::hardware::nfc::V1_0::INfcClientCallback* arg = nullptr;
145     if (hw_binder_proxy) {
146         arg = reinterpret_cast<::android::hardware::nfc::V1_0::INfcClientCallback*>(hw_binder_proxy);
147     } else {
148         LOG(INFO) << " Creating DriverBase with null proxy.";
149     }
150     android::vts::DriverBase* result =
151         new android::vts::FuzzerExtended_android_hardware_nfc_V1_0_INfcClientCallback(
152             arg);
153     if (arg != nullptr) {
154         arg->decStrong(arg);
155     }
156     return result;
157 }
158 
159 }
160 }  // namespace vts
161 }  // namespace android
162