diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 9b601bb4c75da507bca81e344ccd29783e322ac5..34a2b86793fd2d6a61232a09a87b46c9c5007db4 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -271,7 +271,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st } DHLOGI("RegisterDistributedHardware called, deviceId: %{public}s, dhId: %{public}s, parameters: %{public}s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), SetAnonyId(parameters).c_str()); - int32_t randNumber = GenRandInt(RAND_NUM_MIN, RAND_NUM_MAX); + int32_t randNumber = GetRandomInt32(RAND_NUM_MIN, RAND_NUM_MAX); usleep(randNumber * US_PER_MS); std::lock_guard lock(regDisHardwareMutex_); diff --git a/services/state/src/dinput_sink_state.cpp b/services/state/src/dinput_sink_state.cpp index 747d9f26d5aafeb6807fc0b7289c92ae7a8c25cb..8bf357f70d384bc8ec803c8462daf30ab06940e1 100644 --- a/services/state/src/dinput_sink_state.cpp +++ b/services/state/src/dinput_sink_state.cpp @@ -100,7 +100,7 @@ DhIdState DInputSinkState::GetStateByDhid(const std::string &dhId) void DInputSinkState::SimulateMouseBtnMouseUpState(const std::string &dhId, const struct RawEvent &event) { DHLOGI("Sinmulate Mouse BTN_MOUSE UP state to source, dhId: %{public}s", GetAnonyString(dhId).c_str()); - int32_t scanId = GetRandomInt32(); + int32_t scanId = GetRandomInt32(0, INT32_MAX); RawEvent mscScanEv = { event.when, EV_MSC, MSC_SCAN, scanId, dhId, event.path }; RawEvent btnMouseUpEv = { event.when, EV_KEY, BTN_MOUSE, KEY_UP_STATE, dhId, event.path }; RawEvent sycReportEv = { event.when, EV_SYN, SYN_REPORT, 0x0, dhId, event.path }; diff --git a/utils/include/dinput_utils_tool.h b/utils/include/dinput_utils_tool.h index 2b51b7231cd8cb1bc8a8304ba8311840ca831655..1a9e7ccddfb0c658d18100c0479e99831e22a5a8 100644 --- a/utils/include/dinput_utils_tool.h +++ b/utils/include/dinput_utils_tool.h @@ -65,10 +65,9 @@ void ScanInputDevicesPath(const std::string &dirName, std::vector & void ResetVirtualDevicePressedKeys(const std::vector &nodePaths); std::string GetString(const std::vector &vec); -int32_t GetRandomInt32(); +int32_t GetRandomInt32(int32_t randMin, int32_t randMax); std::string JointDhIds(const std::vector &dhids); std::vector SplitDhIdString(const std::string &dhIdsString); -int32_t GenRandInt(int32_t randMin, int32_t randMax); } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 80a318778ac9f495ba6b7f661706b2ee1f80d888..a6e99fa83a377b93bfa2911240857fb66a445bf5 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -451,11 +451,11 @@ std::string GetString(const std::vector &vec) return retStr; } -int32_t GetRandomInt32() +int32_t GetRandomInt32(int32_t randMin, int32_t randMax) { std::default_random_engine engine(time(nullptr)); - std::uniform_int_distribution distribution(0, INT32_MAX); + std::uniform_int_distribution distribution(randMin, randMax); return distribution(engine); } @@ -474,14 +474,6 @@ std::vector SplitDhIdString(const std::string &dhIdsString) SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec); return dhIdsVec; } - -int32_t GenRandInt(int32_t randMin, int32_t randMax) -{ - std::random_device randDevice; - std::mt19937 genRand(randDevice()); - std::uniform_int_distribution disRand(randMin, randMax); - return disRand(genRand); -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file