diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 3364826..f80f3f7 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -352,8 +352,6 @@ std::vector InputHub::GetAllInputDevices() void InputHub::ScanInputDevices(const std::string& dirname) { - char devname[PATH_MAX]; - char *filename; DIR *dir; struct dirent *de; dir = opendir(dirname.c_str()); @@ -362,22 +360,14 @@ void InputHub::ScanInputDevices(const std::string& dirname) return; } - if (strcpy_s(devname, PATH_MAX, dirname.c_str()) != 0) { - DHLOGE("error strcpy_s :%{public}s\n", strerror(errno)); - } - filename = devname + strlen(devname); - *filename++ = '/'; while ((de = readdir(dir))) { if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || (de->d_name[1] == '.' && de->d_name[DIR_FILE_NAME_SECOND] == '\0'))) { continue; } - if (strcpy_s(filename, sizeof(de->d_name), de->d_name) != 0) { - DHLOGE("error strcpy_s second :%{public}s\n", strerror(errno)); - } - DHLOGE("scan dir failed for %{public}s", filename); - OpenInputDeviceLocked(devname); + std::string devName = dirname + "/" + std::string(de->d_name); + OpenInputDeviceLocked(devName); } closedir(dir); } diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index 60d8a78..25c3e6d 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -28,7 +28,6 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { namespace { - const char* WHITE_LIST_FILE_PATH = "/etc/dinput_business_event_whitelist.cfg"; const char* SPLIT_LINE = "|"; const char* SPLIT_COMMA = ","; } @@ -50,6 +49,7 @@ int32_t WhiteListUtil::Init(const std::string &deviceId) { DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); ClearWhiteList(); + const char* whiteListFilePath = "/etc/dinput_business_event_whitelist.cfg"; if (deviceId.empty()) { // device id error @@ -57,10 +57,10 @@ int32_t WhiteListUtil::Init(const std::string &deviceId) return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } - std::ifstream inFile(WHITE_LIST_FILE_PATH, std::ios::in | std::ios::binary); + std::ifstream inFile(whiteListFilePath, std::ios::in | std::ios::binary); if (!inFile.is_open()) { // file open error - DHLOGE("%s error, file open fail path=%s", __func__, WHITE_LIST_FILE_PATH); + DHLOGE("%s error, file open fail path=%s", __func__, whiteListFilePath); return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp index a99ab13..27d4200 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -39,10 +39,8 @@ void DistributedInputInnerTest::TearDownTestCase() { } - void DistributedInputInnerTest::TestPrepareDInputCallback::OnResult( const std::string& deviceId, const int32_t& status) - { (void)deviceId; (void)status; @@ -69,6 +67,9 @@ void DistributedInputInnerTest::TestStartDInputCallback::OnResult( void DistributedInputInnerTest::TestStopDInputCallback::OnResult( const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) { + (void)deviceId; + (void)inputTypes; + (void)status; return; } diff --git a/interfaces/ipc/include/distributed_input_source_stub.h b/interfaces/ipc/include/distributed_input_source_stub.h index 2805b8b..ba93d7e 100644 --- a/interfaces/ipc/include/distributed_input_source_stub.h +++ b/interfaces/ipc/include/distributed_input_source_stub.h @@ -34,6 +34,8 @@ public: uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; private: + int32_t HandleInitDistributedHardware(MessageParcel &reply); + int32_t HandleReleaseDistributedHardware(MessageParcel &reply); int32_t HandleRegisterDistributedHardware(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterDistributedHardware(MessageParcel &data, MessageParcel &reply); int32_t HandlePrepareRemoteInput(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/ipc/src/distributed_input_source_stub.cpp b/interfaces/ipc/src/distributed_input_source_stub.cpp index 30359f0..bdb8151 100644 --- a/interfaces/ipc/src/distributed_input_source_stub.cpp +++ b/interfaces/ipc/src/distributed_input_source_stub.cpp @@ -27,6 +27,24 @@ DistributedInputSourceStub::DistributedInputSourceStub() DistributedInputSourceStub::~DistributedInputSourceStub() {} +int32_t DistributedInputSourceStub::HandleInitDistributedHardware(MessageParcel &reply) +{ + int32_t ret = Init(); + if (!reply.WriteInt32(ret)) { + return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL; + } + return DH_SUCCESS; +} + +int32_t DistributedInputSourceStub::HandleReleaseDistributedHardware(MessageParcel &reply) +{ + int32_t ret = Release(); + if (!reply.WriteInt32(ret)) { + return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL; + } + return DH_SUCCESS; +} + int32_t DistributedInputSourceStub::HandleRegisterDistributedHardware(MessageParcel &data, MessageParcel &reply) { std::string devId = data.ReadString(); @@ -120,21 +138,11 @@ int32_t DistributedInputSourceStub::OnRemoteRequest(uint32_t code, MessageParcel { switch (code) { case static_cast(IDistributedSourceInput::MessageCode::INIT): { - int32_t ret = Init(); - if (!reply.WriteInt32(ret)) { - return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL; - } else { - return DH_SUCCESS; - } + return HandleInitDistributedHardware(reply); break; } case static_cast(IDistributedSourceInput::MessageCode::RELEASE): { - int32_t ret = Release(); - if (!reply.WriteInt32(ret)) { - return ERR_DH_INPUT_SOURCE_STUB_ON_REMOTE_REQUEST_FAIL; - } else { - return DH_SUCCESS; - } + return HandleReleaseDistributedHardware(reply); break; } case static_cast(IDistributedSourceInput::MessageCode::REGISTER_REMOTE_INPUT): { diff --git a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h index 174aa3d..a329e61 100644 --- a/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h +++ b/test/fuzztest/distributedinputkit_fuzzer/distributed_input_kit_fuzzer.h @@ -13,7 +13,6 @@ * limitations under the License. */ - #ifndef DISTRIBUTED_INPUT_KIT_FUZZER_H #define DISTRIBUTED_INPUT_KIT_FUZZER_H