From 0da1e38c825f35e496c6b56f6a7485def38628a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Mon, 28 Feb 2022 21:01:51 +0800 Subject: [PATCH 01/11] handle_warning clear Signed-off-by: pang-wenbin2 --- .../src/ability/standard/dm_ability_manager.cpp | 2 +- ext/profile/src/profile_connector.cpp | 6 +++--- .../inner_kits/native_cpp/include/dm_app_image_info.h | 6 +++--- .../src/ipc/standard/ipc_client_server_proxy.cpp | 2 +- .../native_cpp/src/ipc/standard/ipc_client_stub.cpp | 2 +- .../native_cpp/src/ipc/standard/ipc_cmd_parser.cpp | 10 +++++----- .../native_cpp/src/notify/device_manager_notify.cpp | 2 +- interfaces/kits/js/src/native_devicemanager_js.cpp | 10 +++++----- .../src/authentication/auth_message_processor.cpp | 6 +++--- .../src/device_manager_service_listener.cpp | 2 +- .../src/discovery/dm_discovery_manager.cpp | 6 +++--- .../src/ipc/standard/ipc_cmd_parser.cpp | 10 +++++----- .../src/ipc/standard/ipc_server_client_proxy.cpp | 2 +- .../src/ipc/standard/ipc_server_stub.cpp | 2 +- test/unittest/UTTest_dm_device_state_manager.cpp | 4 ++-- test/unittest/UTTest_dm_discovery_manager.cpp | 4 ++-- test/unittest/UTTest_softbus_connector.cpp | 6 +++--- utils/src/dm_anonymous.cpp | 8 ++++---- utils/src/dm_random.cpp | 2 +- 19 files changed, 46 insertions(+), 46 deletions(-) diff --git a/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp b/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp index e2b026f1c..b1ea6b992 100644 --- a/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp +++ b/ext/pin_auth/src/ability/standard/dm_ability_manager.cpp @@ -61,7 +61,7 @@ void DmAbilityManager::waitForTimeout(uint32_t timeout_s) { struct timespec ts; clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec += timeout_s; + ts.tv_sec += (int32_t)timeout_s; sem_timedwait(&mSem_, &ts); } diff --git a/ext/profile/src/profile_connector.cpp b/ext/profile/src/profile_connector.cpp index 4a709238e..fe46916b1 100644 --- a/ext/profile/src/profile_connector.cpp +++ b/ext/profile/src/profile_connector.cpp @@ -53,7 +53,7 @@ int32_t ProfileConnector::SubscribeProfileEvents(const std::list &s subscribeInfos.emplace_back(eventSync); std::list failedEvents; - u_int32_t errCode = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents( + int32_t errCode = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents( subscribeInfos, profileEventCallback_, failedEvents); LOGI("ProfileConnector::SubscribeProfileEvents result=%d", errCode); return DM_OK; @@ -65,7 +65,7 @@ int32_t ProfileConnector::UnSubscribeProfileEvents() profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); std::list failedEvents; - u_int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents( + int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents( profileEvents, profileEventCallback_, failedEvents); LOGI("ProfileConnector::UnSubscribeProfileEvents result=%d", errCode); return DM_OK; @@ -100,4 +100,4 @@ void ProfileEventCallback::OnSyncCompleted(const SyncResult &syncResults) } } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/interfaces/inner_kits/native_cpp/include/dm_app_image_info.h b/interfaces/inner_kits/native_cpp/include/dm_app_image_info.h index 1f48f40b6..26475008b 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_app_image_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_app_image_info.h @@ -68,7 +68,7 @@ public: return -1; } - if (memcpy_s(appThumbnail + copyIndex, appThumbnailLen - copyIndex, srcBuffer, copyLen) != 0) { + if (memcpy_s(appThumbnail + copyIndex, appThumbnailLen - copyIndex, srcBuffer, (uint32_t)copyLen) != 0) { return -1; } @@ -145,7 +145,7 @@ private: } if (appIcon != nullptr) { appIconLen = appIconLen_; - if (memcpy_s(appIcon, appIconLen, appIcon_, appIconLen_) != 0) { + if (memcpy_s(appIcon, (uint32_t)appIconLen, appIcon_, appIconLen_) != 0) { return; } } @@ -165,7 +165,7 @@ private: } if (appThumbnail != nullptr) { appThumbnailLen = appThumbnailLen_; - if (memcpy_s(appThumbnail, appThumbnailLen, appThumbnail_, appThumbnailLen_) != 0) { + if (memcpy_s(appThumbnail, (uint32_t)appThumbnailLen, appThumbnail_, appThumbnailLen_) != 0) { return; } } diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp index 0a8e93040..c81222fb8 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_server_proxy.cpp @@ -36,7 +36,7 @@ int32_t IpcClientServerProxy::SendCmd(int32_t cmdCode, std::shared_ptr r if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) { return DM_IPC_SEND_REQUEST_FAILED; } - if (remote->SendRequest(cmdCode, data, reply, option) != DM_OK) { + if (remote->SendRequest((uint32_t)cmdCode, data, reply, option) != DM_OK) { LOGE("SendRequest fail, cmd:%d", cmdCode); return DM_IPC_SEND_REQUEST_FAILED; } diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp index 798e5f361..9cacbbf9c 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_client_stub.cpp @@ -26,7 +26,7 @@ namespace DistributedHardware { int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { LOGI("code = %d, flags= %d.", code, option.GetFlags()); - if (IpcCmdRegister::GetInstance().OnIpcCmd(code, data, reply) == DM_OK) { + if (IpcCmdRegister::GetInstance().OnIpcCmd((int32_t)code, data, reply) == DM_OK) { LOGE("on ipc cmd success"); return DM_OK; } diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index be759e55e..e310f85b7 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -101,7 +101,7 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_pt DmDeviceInfo *pDmDeviceinfo = nullptr; for (int32_t i = 0; i < deviceNum; ++i) { pDmDeviceinfo = nullptr; - pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData((int32_t)sizeof(DmDeviceInfo)); + pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData((uint32_t)sizeof(DmDeviceInfo)); if (pDmDeviceinfo == nullptr) { LOGE("GetTrustedDeviceList read node info failed!"); pRsp->SetErrCode(DM_IPC_TRANSACTION_FAILED); @@ -212,7 +212,7 @@ ON_IPC_SET_REQUEST(STOP_DEVICE_DISCOVER, std::shared_ptr pBaseReq, Messa LOGE("write pkgName failed"); return DM_IPC_FLATTEN_OBJECT; } - if (!data.WriteInt16(subscribeId)) { + if (!data.WriteInt16((int16_t)subscribeId)) { LOGE("write subscribeId failed"); return DM_IPC_FLATTEN_OBJECT; } @@ -384,7 +384,7 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); - uint16_t subscribeId = data.ReadInt16(); + int16_t subscribeId = (int16_t)(data.ReadInt16()); DmDeviceInfo dmDeviceInfo; size_t deviceSize = sizeof(DmDeviceInfo); void *deviceInfo = (void *)data.ReadRawData(deviceSize); @@ -400,7 +400,7 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); - uint16_t subscribeId = data.ReadInt16(); + uint16_t subscribeId =(uint16_t)(data.ReadInt16()); int32_t failedReason = data.ReadInt32(); if (failedReason == DM_OK) { @@ -419,7 +419,7 @@ ON_IPC_CMD(SERVER_AUTH_RESULT, MessageParcel &data, MessageParcel &reply) std::string token = data.ReadString(); int32_t status = data.ReadInt32(); int32_t reason = data.ReadInt32(); - DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason); + DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, (uint32_t)status, reason); reply.WriteInt32(DM_OK); return DM_OK; } diff --git a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp index 987ca17c5..9d68e364f 100644 --- a/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp +++ b/interfaces/inner_kits/native_cpp/src/notify/device_manager_notify.cpp @@ -250,7 +250,7 @@ void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::st LOGE("DeviceManager OnAuthResult: no register authCallback for deviceID "); return; } - iter->second->OnAuthResult(deviceId, token, status, reason); + iter->second->OnAuthResult(deviceId, token, status, (int32_t)reason); authenticateCallback_[pkgName].erase(deviceId); if (authenticateCallback_[pkgName].empty()) { authenticateCallback_.erase(pkgName); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index bb96c37a7..8672479c4 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -725,7 +725,7 @@ void DeviceManagerNapi::JsToDmBuffer(const napi_env &env, const napi_value &obje *bufferPtr = nullptr; return; } - bufferLen = length; + bufferLen = (int32_t)length; } void DeviceManagerNapi::JsToJsonObject(const napi_env &env, const napi_value &object, const std::string &fieldStr, @@ -971,7 +971,7 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatusSync(napi_env env, napi_st LOGE("napi_create_array fail"); } for (unsigned int i = 0; i != deviceInfoAsyncCallbackInfo->devList.size(); ++i) { - DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, i, array[1]); + DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList,(int32_t)i, array[1]); } napi_resolve_deferred(env, deviceInfoAsyncCallbackInfo->deferred, array[1]); LOGE("devList is OK"); @@ -1046,7 +1046,7 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status } for (size_t i = 0; i != deviceInfoAsyncCallbackInfo->devList.size(); ++i) { - DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, i, array[1]); + DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, (int32_t)i, array[1]); } LOGE("devList is OK"); } else { @@ -1252,7 +1252,7 @@ napi_value DeviceManagerNapi::GetTrustedDeviceListSync(napi_env env, napi_callba LOGI("DeviceManager::GetTrustedDeviceListSync"); if (devList.size() > 0) { for (size_t i = 0; i != devList.size(); ++i) { - DeviceInfoToJsArray(env, devList, i, result); + DeviceInfoToJsArray(env, devList, (uint32_t)i, result); } } return result; @@ -1685,7 +1685,7 @@ napi_value DeviceManagerNapi::ReleaseDeviceManager(napi_env env, napi_callback_i int32_t ret = DeviceManager::GetInstance().UnInitDeviceManager(deviceManagerWrapper->bundleName_); if (ret != 0) { LOGE("ReleaseDeviceManager for bunderName %s failed, ret %d", deviceManagerWrapper->bundleName_.c_str(), ret); - napi_create_uint32(env, ret, &result); + napi_create_uint32(env, (uint32_t)ret, &result); return result; } diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 9ba556f4a..539fb581b 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -35,7 +35,7 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() { LOGI("AuthMessageProcessor::CreateAuthRequestMessage start."); std::vector jsonStrVec; - int32_t thumbnailSize = authRequestContext_->appThumbnail.size(); + int32_t thumbnailSize =(int32_t)(authRequestContext_->appThumbnail.size()); int32_t thumbnailSlice = ((thumbnailSize / MSG_MAX_SIZE) + (thumbnailSize % MSG_MAX_SIZE) == 0 ? 0 : 1); nlohmann::json jsonObj; jsonObj[TAG_VER] = DM_ITF_VER; @@ -69,7 +69,7 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() int32_t leftLen = thumbnailSize - idx * MSG_MAX_SIZE; int32_t sliceLen = (leftLen > MSG_MAX_SIZE) ? MSG_MAX_SIZE : leftLen; - LOGI("TAG_APP_THUMBNAIL encode, idx %d, sliceLen %d, thumbnailSize %d", idx, sliceLen, thumbnailSize); + LOGI("TAG_APP_THUMBNAIL encode, idx %d, sliceLen %d, thumbnailSize %d", idx, (uint32_t)sliceLen, thumbnailSize); jsonObj[TAG_APP_THUMBNAIL] = authRequestContext_->appThumbnail.substr(idx * MSG_MAX_SIZE, sliceLen); jsonStrVec.push_back(jsonThumbnailObj.dump()); } @@ -289,4 +289,4 @@ std::shared_ptr AuthMessageProcessor::GetRequestContext() return authRequestContext_; } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/devicemanagerservice/src/device_manager_service_listener.cpp b/services/devicemanagerservice/src/device_manager_service_listener.cpp index c67191a3e..91a59333d 100644 --- a/services/devicemanagerservice/src/device_manager_service_listener.cpp +++ b/services/devicemanagerservice/src/device_manager_service_listener.cpp @@ -72,7 +72,7 @@ void DeviceManagerServiceListener::OnDiscoverySuccess(const std::string &pkgName std::shared_ptr pRsp = std::make_shared(); pReq->SetPkgName(pkgName); - pReq->SetSubscribeId(subscribeId); + pReq->SetSubscribeId((uint32_t)subscribeId); pReq->SetResult(DM_OK); ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); } diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index f48689431..a3a6663d1 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -98,14 +98,14 @@ void DmDiscoveryManager::OnDeviceFound(const std::string &pkgName, const DmDevic void DmDiscoveryManager::OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason) { LOGI("DmDiscoveryManager::OnDiscoveryFailed subscribeId=%d reason=%d", subscribeId, failedReason); - StopDeviceDiscovery(pkgName, subscribeId); - listener_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); + StopDeviceDiscovery(pkgName, (uint32_t)subscribeId); + listener_->OnDiscoveryFailed(pkgName, (uint32_t)subscribeId, failedReason); } void DmDiscoveryManager::OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) { LOGI("DmDiscoveryManager::OnDiscoverySuccess subscribeId=%d", subscribeId); - discoveryContextMap_[pkgName].subscribeId = subscribeId; + discoveryContextMap_[pkgName].subscribeId = (uint32_t)subscribeId; listener_->OnDiscoverySuccess(pkgName, subscribeId); } diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp index 2a61266b5..d5da15591 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -68,7 +68,7 @@ ON_IPC_SET_REQUEST(SERVER_DEVICE_FOUND, std::shared_ptr pBaseReq, Messag LOGE("write pkgName failed"); return DM_FLATTEN_OBJECT; } - if (!data.WriteInt16(subscribeId)) { + if (!data.WriteInt16((int16_t)subscribeId)) { LOGE("write subscribeId failed"); return DM_FLATTEN_OBJECT; } @@ -95,7 +95,7 @@ ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, Mes LOGE("write pkgName failed"); return DM_FLATTEN_OBJECT; } - if (!data.WriteInt16(subscribeId)) { + if (!data.WriteInt16((int16_t)subscribeId)) { LOGE("write subscribeId failed"); return DM_FLATTEN_OBJECT; } @@ -211,7 +211,7 @@ ON_IPC_CMD(GET_TRUST_DEVICE_LIST, MessageParcel &data, MessageParcel &reply) LOGI("pkgName:%s, extra:%s", pkgName.c_str(), extra.c_str()); std::vector deviceList; int32_t result = DeviceManagerService::GetInstance().GetTrustedDeviceList(pkgName, extra, deviceList); - int32_t infoNum = deviceList.size(); + int32_t infoNum =(int32_t)(deviceList.size()); DmDeviceInfo deviceInfo; if (!reply.WriteInt32(infoNum)) { LOGE("write infoNum failed"); @@ -280,7 +280,7 @@ ON_IPC_CMD(START_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply) ON_IPC_CMD(STOP_DEVICE_DISCOVER, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); - uint16_t subscribeId = data.ReadInt32(); + uint16_t subscribeId = (uint16_t)(data.ReadInt32()); LOGI("pkgName:%s, subscribeId: %d", pkgName.c_str(), subscribeId); int32_t result = DeviceManagerService::GetInstance().StopDeviceDiscovery(pkgName, subscribeId); if (!reply.WriteInt32(result)) { @@ -394,7 +394,7 @@ ON_IPC_CMD(SERVER_GET_DMFA_INFO, MessageParcel &data, MessageParcel &reply) int32_t ret = DM_OK; ret = DeviceManagerService::GetInstance().GetFaParam(packName, authParam); int32_t appIconLen = authParam.imageinfo.GetAppIconLen(); - int32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); + uint32_t appThumbnailLen = authParam.imageinfo.GetAppThumbnailLen(); if (!reply.WriteInt32(authParam.direction) || !reply.WriteInt32(authParam.authType) || !reply.WriteString(authParam.authToken) || !reply.WriteString(authParam.packageName) || diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp index 28dbc5a5f..fd6adb815 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_client_proxy.cpp @@ -36,7 +36,7 @@ int32_t IpcServerClientProxy::SendCmd(int32_t cmdCode, std::shared_ptr r if (IpcCmdRegister::GetInstance().SetRequest(cmdCode, req, data) != DM_OK) { return DM_IPC_FAILED; } - if (remote->SendRequest(cmdCode, data, reply, option) != DM_OK) { + if (remote->SendRequest((uint32_t)cmdCode, data, reply, option) != DM_OK) { LOGE("SendRequest fail, cmd:%d", cmdCode); return DM_IPC_FAILED; } diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp index ff7e3a148..a20ed4109 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -82,7 +82,7 @@ int32_t IpcServerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa { LOGI("code = %d, flags= %d.", code, option.GetFlags()); int32_t ret = DM_OK; - ret = IpcCmdRegister::GetInstance().OnIpcCmd(code, data, reply); + ret = IpcCmdRegister::GetInstance().OnIpcCmd((int32_t)code, data, reply); if (ret == DM_IPC_NOT_REGISTER_FUNC) { LOGW("unsupport code: %d", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index 507cdca5d..6ab2b2f1b 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -164,7 +164,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceReady_001, testing::ext::TestSize.Lev { std::string pkgName; DmDeviceInfo info; - strncpy(info.deviceId, "123", sizeof(info.deviceId)); + strncpy_s(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceReady(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -205,4 +205,4 @@ HWTEST_F(DmDeviceStateManagerTest, RegisterSoftbusStateCallback_001, testing::ex } } // namespace } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/UTTest_dm_discovery_manager.cpp b/test/unittest/UTTest_dm_discovery_manager.cpp index 03fff20ce..088a392d8 100644 --- a/test/unittest/UTTest_dm_discovery_manager.cpp +++ b/test/unittest/UTTest_dm_discovery_manager.cpp @@ -236,7 +236,7 @@ HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize. std::string pkgName; int32_t subscribeId = 1; discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId); - int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName); + uint32_t ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName); EXPECT_EQ(ret1, 1); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); @@ -254,7 +254,7 @@ HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_001, testing::ext::TestS { std::string pkgName = "com.ohos.helloworld"; discoveryMgr_->HandleDiscoveryTimeout(); - int ret = discoveryMgr_->discoveryContextMap_.count(pkgName); + uint32_t ret = discoveryMgr_->discoveryContextMap_.count(pkgName); EXPECT_EQ(ret, 1); } } // namespace diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp index 4cf2039ce..ae3b865aa 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -87,7 +87,7 @@ HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusDiscoveryCallback_001, testing:: { std::string pkgName = "com.ohos.helloworld"; int ret = softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName); - int ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName); + int ret1 = (int)(SoftbusConnector::discoveryCallbackMap_.count(pkgName)); EXPECT_EQ(ret1, 0); EXPECT_EQ(ret, DM_OK); } @@ -170,7 +170,7 @@ HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_002, testing::ext::TestSize.Level0 { std::string deviceId = "145677"; NodeBasicInfo Info; - strncpy(Info.networkId, "145677", sizeof(Info.networkId)); + strncpy_s(Info.networkId, "145677", sizeof(Info.networkId)); bool ret = softbusConnector->IsDeviceOnLine(deviceId); EXPECT_EQ(ret, false); } @@ -330,4 +330,4 @@ HWTEST_F(SoftbusConnectorTest, OnParameterChgCallback_001, testing::ext::TestSiz } } // namespace } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index 8d9a7be38..c89f47694 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -24,7 +24,7 @@ std::string GetAnonyString(const std::string &value) const int32_t INT32_MIN_ID_LENGTH = 3; std::string tmpStr("******"); - int32_t strLen = value.length(); + int32_t strLen = (int32_t)(value.length()); if (strLen < INT32_MIN_ID_LENGTH) { return tmpStr; } @@ -37,7 +37,7 @@ std::string GetAnonyString(const std::string &value) } else { res.append(value, 0, INT32_PLAINTEXT_LENGTH); res += tmpStr; - res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); + res.append(value, (uint32_t)(strLen - INT32_PLAINTEXT_LENGTH), INT32_PLAINTEXT_LENGTH); } return res; @@ -46,7 +46,7 @@ std::string GetAnonyString(const std::string &value) std::string GetAnonyInt32(const int32_t value) { std::string tempString = std::to_string(value); - int32_t length = tempString.length(); + int32_t length =(int32_t)(tempString.length()); if (length == 0x01) { tempString[0] = '*'; return tempString; @@ -58,4 +58,4 @@ std::string GetAnonyInt32(const int32_t value) return tempString; } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/utils/src/dm_random.cpp b/utils/src/dm_random.cpp index d7d03c242..7a1d6a716 100644 --- a/utils/src/dm_random.cpp +++ b/utils/src/dm_random.cpp @@ -87,7 +87,7 @@ bool MbedtlsGenRandomStr(char *szOut, int32_t szOutLen, bool numberOnly) return false; } szOut[--szOutLen] = 0; - GetRandomData((uint8_t *)szOut, szOutLen); + GetRandomData((uint8_t *)szOut, (uint32_t)szOutLen); const int32_t NUMBER_COUNT = 10; const int32_t ALPHA_COUNT = 26; const int32_t ALPHA_BYTE_COUNT = 2; -- Gitee From 3dce9d17a4077a0b3a8bef69a84e8d25499a796c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Mon, 28 Feb 2022 21:35:33 +0800 Subject: [PATCH 02/11] solve the question of codechecking Signed-off-by: pang-wenbin2 --- interfaces/kits/js/src/native_devicemanager_js.cpp | 2 +- .../src/authentication/auth_message_processor.cpp | 2 +- utils/src/dm_anonymous.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 8672479c4..2398e8a1c 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1046,7 +1046,7 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status } for (size_t i = 0; i != deviceInfoAsyncCallbackInfo->devList.size(); ++i) { - DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, (int32_t)i, array[1]); + DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, (int32_t)i, array[1]); } LOGE("devList is OK"); } else { diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 539fb581b..922c5cdfc 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -35,7 +35,7 @@ std::vector AuthMessageProcessor::CreateAuthRequestMessage() { LOGI("AuthMessageProcessor::CreateAuthRequestMessage start."); std::vector jsonStrVec; - int32_t thumbnailSize =(int32_t)(authRequestContext_->appThumbnail.size()); + int32_t thumbnailSize = (int32_t)(authRequestContext_->appThumbnail.size()); int32_t thumbnailSlice = ((thumbnailSize / MSG_MAX_SIZE) + (thumbnailSize % MSG_MAX_SIZE) == 0 ? 0 : 1); nlohmann::json jsonObj; jsonObj[TAG_VER] = DM_ITF_VER; diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index c89f47694..01ced2638 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -46,7 +46,7 @@ std::string GetAnonyString(const std::string &value) std::string GetAnonyInt32(const int32_t value) { std::string tempString = std::to_string(value); - int32_t length =(int32_t)(tempString.length()); + int32_t length = (int32_t)(tempString.length()); if (length == 0x01) { tempString[0] = '*'; return tempString; -- Gitee From 23259cfab656ad7dfbef1909df602d31310bade4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Tue, 1 Mar 2022 14:02:13 +0800 Subject: [PATCH 03/11] check_handle_warning clear Signed-off-by: pang-wenbin2 --- .../native_cpp/src/ipc/standard/ipc_cmd_parser.cpp | 6 +++--- interfaces/kits/js/src/native_devicemanager_js.cpp | 6 +++--- .../src/device_manager_service_listener.cpp | 2 +- test/unittest/UTTest_dm_device_state_manager.cpp | 2 +- test/unittest/UTTest_softbus_connector.cpp | 4 ++-- utils/src/dm_anonymous.cpp | 6 +++--- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp index e310f85b7..5858e834d 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/standard/ipc_cmd_parser.cpp @@ -101,7 +101,7 @@ ON_IPC_READ_RESPONSE(GET_TRUST_DEVICE_LIST, MessageParcel &reply, std::shared_pt DmDeviceInfo *pDmDeviceinfo = nullptr; for (int32_t i = 0; i < deviceNum; ++i) { pDmDeviceinfo = nullptr; - pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData((uint32_t)sizeof(DmDeviceInfo)); + pDmDeviceinfo = (DmDeviceInfo *)reply.ReadRawData(sizeof(DmDeviceInfo)); if (pDmDeviceinfo == nullptr) { LOGE("GetTrustedDeviceList read node info failed!"); pRsp->SetErrCode(DM_IPC_TRANSACTION_FAILED); @@ -384,7 +384,7 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, MessageParcel &data, MessageParcel &reply ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); - int16_t subscribeId = (int16_t)(data.ReadInt16()); + int16_t subscribeId = data.ReadInt16(); DmDeviceInfo dmDeviceInfo; size_t deviceSize = sizeof(DmDeviceInfo); void *deviceInfo = (void *)data.ReadRawData(deviceSize); @@ -400,7 +400,7 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, MessageParcel &data, MessageParcel &reply) ON_IPC_CMD(SERVER_DISCOVER_FINISH, MessageParcel &data, MessageParcel &reply) { std::string pkgName = data.ReadString(); - uint16_t subscribeId =(uint16_t)(data.ReadInt16()); + int16_t subscribeId = data.ReadInt16(); int32_t failedReason = data.ReadInt32(); if (failedReason == DM_OK) { diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 2398e8a1c..a111affc9 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -1045,8 +1045,8 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatus(napi_env env, napi_status LOGE("napi_create_array fail"); } - for (size_t i = 0; i != deviceInfoAsyncCallbackInfo->devList.size(); ++i) { - DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, (int32_t)i, array[1]); + for (int32_t i = 0; i != deviceInfoAsyncCallbackInfo->devList.size(); ++i) { + DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, i, array[1]); } LOGE("devList is OK"); } else { @@ -1252,7 +1252,7 @@ napi_value DeviceManagerNapi::GetTrustedDeviceListSync(napi_env env, napi_callba LOGI("DeviceManager::GetTrustedDeviceListSync"); if (devList.size() > 0) { for (size_t i = 0; i != devList.size(); ++i) { - DeviceInfoToJsArray(env, devList, (uint32_t)i, result); + DeviceInfoToJsArray(env, devList, (int32_t)i, result); } } return result; diff --git a/services/devicemanagerservice/src/device_manager_service_listener.cpp b/services/devicemanagerservice/src/device_manager_service_listener.cpp index 91a59333d..108fefb2e 100644 --- a/services/devicemanagerservice/src/device_manager_service_listener.cpp +++ b/services/devicemanagerservice/src/device_manager_service_listener.cpp @@ -72,7 +72,7 @@ void DeviceManagerServiceListener::OnDiscoverySuccess(const std::string &pkgName std::shared_ptr pRsp = std::make_shared(); pReq->SetPkgName(pkgName); - pReq->SetSubscribeId((uint32_t)subscribeId); + pReq->SetSubscribeId((uint16_t)subscribeId); pReq->SetResult(DM_OK); ipcServerListener_.SendRequest(SERVER_DISCOVER_FINISH, pReq, pRsp); } diff --git a/test/unittest/UTTest_dm_device_state_manager.cpp b/test/unittest/UTTest_dm_device_state_manager.cpp index 6ab2b2f1b..52e341847 100644 --- a/test/unittest/UTTest_dm_device_state_manager.cpp +++ b/test/unittest/UTTest_dm_device_state_manager.cpp @@ -164,7 +164,7 @@ HWTEST_F(DmDeviceStateManagerTest, OnDeviceReady_001, testing::ext::TestSize.Lev { std::string pkgName; DmDeviceInfo info; - strncpy_s(info.deviceId, "123", sizeof(info.deviceId)); + strncpy(info.deviceId, "123", sizeof(info.deviceId)); dmDeviceStateManager->OnDeviceReady(pkgName, info); std::shared_ptr pReq = std::static_pointer_cast(listener_->ipcServerListener_.req_); diff --git a/test/unittest/UTTest_softbus_connector.cpp b/test/unittest/UTTest_softbus_connector.cpp index ae3b865aa..32491e692 100644 --- a/test/unittest/UTTest_softbus_connector.cpp +++ b/test/unittest/UTTest_softbus_connector.cpp @@ -87,7 +87,7 @@ HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusDiscoveryCallback_001, testing:: { std::string pkgName = "com.ohos.helloworld"; int ret = softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName); - int ret1 = (int)(SoftbusConnector::discoveryCallbackMap_.count(pkgName)); + uint32_t ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName); EXPECT_EQ(ret1, 0); EXPECT_EQ(ret, DM_OK); } @@ -170,7 +170,7 @@ HWTEST_F(SoftbusConnectorTest, IsDeviceOnLine_002, testing::ext::TestSize.Level0 { std::string deviceId = "145677"; NodeBasicInfo Info; - strncpy_s(Info.networkId, "145677", sizeof(Info.networkId)); + strncpy(Info.networkId, "145677", sizeof(Info.networkId)); bool ret = softbusConnector->IsDeviceOnLine(deviceId); EXPECT_EQ(ret, false); } diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index 01ced2638..907c9f208 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -24,7 +24,7 @@ std::string GetAnonyString(const std::string &value) const int32_t INT32_MIN_ID_LENGTH = 3; std::string tmpStr("******"); - int32_t strLen = (int32_t)(value.length()); + int32_t strLen = value.length(); if (strLen < INT32_MIN_ID_LENGTH) { return tmpStr; } @@ -37,7 +37,7 @@ std::string GetAnonyString(const std::string &value) } else { res.append(value, 0, INT32_PLAINTEXT_LENGTH); res += tmpStr; - res.append(value, (uint32_t)(strLen - INT32_PLAINTEXT_LENGTH), INT32_PLAINTEXT_LENGTH); + res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); } return res; @@ -46,7 +46,7 @@ std::string GetAnonyString(const std::string &value) std::string GetAnonyInt32(const int32_t value) { std::string tempString = std::to_string(value); - int32_t length = (int32_t)(tempString.length()); + int32_t length = tempString.length(); if (length == 0x01) { tempString[0] = '*'; return tempString; -- Gitee From 053c518920fa4bc12776bd78118ca5dc425d2341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyour?= Date: Tue, 1 Mar 2022 15:30:59 +0800 Subject: [PATCH 04/11] modify_codecheck Signed-off-by: pang-wenbin2 --- interfaces/kits/js/src/native_devicemanager_js.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index a111affc9..644386adf 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -971,7 +971,7 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatusSync(napi_env env, napi_st LOGE("napi_create_array fail"); } for (unsigned int i = 0; i != deviceInfoAsyncCallbackInfo->devList.size(); ++i) { - DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList,(int32_t)i, array[1]); + DeviceInfoToJsArray(env, deviceInfoAsyncCallbackInfo->devList, (int32_t)i, array[1]); } napi_resolve_deferred(env, deviceInfoAsyncCallbackInfo->deferred, array[1]); LOGE("devList is OK"); -- Gitee From 1dcea0ecb58692bfe364b4b597d7bb779a50f89a Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 16:27:04 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../dependency/softbus/softbus_connector.cpp | 38 +++++++++++++++---- .../devicestate/dm_device_state_manager.cpp | 2 - 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 4ece01e32..93f77db92 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -17,6 +17,8 @@ #include #include +#include +#include #include "dm_anonymous.h" #include "dm_constants.h" @@ -47,6 +49,30 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeOffline = SoftbusConnector::OnSoftbusDeviceOffline, .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; +void DeviceOnLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo) +{ + LOGI("Device on line start"); + std::mutex lockDeviceOnLine; + std::lock_guard lock(lockDeviceOnLine); + for (auto &iter : stateCallbackMap) { + iter.second->OnDeviceOnline(iter.first, deviceInfo); + } + LOGI("Device on line end"); +} + +void DeviceOffLine(std::map> stateCallbackMap, + DmDeviceInfo deviceInfo) +{ + LOGI("Device off line start"); + std::mutex lockDeviceOffLine; + std::lock_guard lock(lockDeviceOffLine); + for (auto &iter : stateCallbackMap) { + iter.second->OnDeviceOffline(iter.first, deviceInfo); + } + LOGI("Device off line end"); +} + SoftbusConnector::SoftbusConnector() { softbusSession_ = std::make_shared(); @@ -445,9 +471,8 @@ void SoftbusConnector::OnSoftBusDeviceOnline(NodeBasicInfo *info) DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); - for (auto &iter : stateCallbackMap_) { - iter.second->OnDeviceOnline(iter.first, dmDeviceInfo); - } + std::thread deviceOnLine(DeviceOnLine, stateCallbackMap_, dmDeviceInfo); + deviceOnLine.detach(); if (discoveryDeviceInfoMap_.empty()) { return; @@ -473,9 +498,8 @@ void SoftbusConnector::OnSoftbusDeviceOffline(NodeBasicInfo *info) } DmDeviceInfo dmDeviceInfo; CovertNodeBasicInfoToDmDevice(*info, dmDeviceInfo); - for (auto &iter : stateCallbackMap_) { - iter.second->OnDeviceOffline(iter.first, dmDeviceInfo); - } + std::thread deviceOffLine(DeviceOffLine, stateCallbackMap_, dmDeviceInfo); + deviceOffLine.detach(); } void SoftbusConnector::OnSoftbusDeviceInfoChanged(NodeBasicInfoType type, NodeBasicInfo *info) @@ -556,4 +580,4 @@ void SoftbusConnector::OnParameterChgCallback(const char *key, const char *value } } } // namespace DistributedHardware -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp index 98ba3c7f2..9318bd0ab 100644 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -87,8 +87,6 @@ void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmD if (profileAdapter == nullptr) { LOGE("OnDeviceOffline profile adapter is null"); } else { - std::string uuid; - SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); if (iter == remoteDeviceInfos_.end()) { } else { -- Gitee From b1d1ee1c8c8b3767674d083afbca4b6a47a32da9 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 16:48:14 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 93f77db92..5d6d2e480 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; @@ -62,7 +62,7 @@ void DeviceOnLine(std::map> } void DeviceOffLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device off line start"); std::mutex lockDeviceOffLine; -- Gitee From d1443587fe5a9f68d4c839e2a51e41b67b2a3521 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 16:54:23 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 5d6d2e480..ab6b70fff 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; @@ -62,7 +62,7 @@ void DeviceOnLine(std::map> } void DeviceOffLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device off line start"); std::mutex lockDeviceOffLine; -- Gitee From cd460218ddd002aea7a2d03afa53e57aadd79548 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 17:12:03 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index ab6b70fff..530938ab2 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; -- Gitee From b76158e998bddc9614a409035eee29917acada3b Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 17:19:12 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E7=BA=BF=EF=BC=9A=E5=A4=9A=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/dependency/softbus/softbus_connector.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp index 530938ab2..f3278fe8e 100644 --- a/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp +++ b/services/devicemanagerservice/src/dependency/softbus/softbus_connector.cpp @@ -50,7 +50,7 @@ INodeStateCb SoftbusConnector::softbusNodeStateCb_ = { .onNodeBasicInfoChanged = SoftbusConnector::OnSoftbusDeviceInfoChanged}; void DeviceOnLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device on line start"); std::mutex lockDeviceOnLine; @@ -62,7 +62,7 @@ void DeviceOnLine(std::map> } void DeviceOffLine(std::map> stateCallbackMap, - DmDeviceInfo deviceInfo) + DmDeviceInfo deviceInfo) { LOGI("Device off line start"); std::mutex lockDeviceOffLine; -- Gitee From 1c7714886b3619ad8f677d114730e24e1512e0a0 Mon Sep 17 00:00:00 2001 From: wuqi0105 Date: Tue, 1 Mar 2022 19:04:23 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E6=B5=8B=E8=AF=95stop?= =?UTF-8?q?=20timer=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuqi0105 --- .../src/authentication/dm_auth_manager.cpp | 17 ++++++++------- .../src/dependency/timer/dm_timer.cpp | 21 ++++++------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index e759e8c4b..4188f510d 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -176,7 +176,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) { LOGI("DmAuthManager::VerifyAuthentication"); std::shared_ptr ptr; - if (authenticationMap_.find(1) == authenticationMap_.end() && timerMap_[INPUT_TIMEOUT_TASK] == nullptr) { + if (authenticationMap_.find(1) == authenticationMap_.end() + || timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return DM_FAILED; } @@ -270,7 +271,7 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) switch (authResponseContext_->msgType) { case MSG_TYPE_NEGOTIATE: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_INIT - && timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK] != nullptr) { + && timerMap_.find(WAIT_NEGOTIATE_TIMEOUT_TASK) != timerMap_.end()) { timerMap_[WAIT_NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseState_->TransitionTo(std::make_shared()); } else { @@ -279,7 +280,7 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) break; case MSG_TYPE_REQ_AUTH: if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_NEGOTIATE - && timerMap_[WAIT_REQUEST_TIMEOUT_TASK] != nullptr) { + && timerMap_.find(WAIT_REQUEST_TIMEOUT_TASK) != timerMap_.end()) { timerMap_[WAIT_REQUEST_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); authResponseState_->TransitionTo(std::make_shared()); } else { @@ -339,7 +340,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) { LOGE("DmAuthManager OnMemberJoin start"); - if (authRequestState_ != nullptr && timerMap_[ADD_TIMEOUT_TASK] != nullptr) { + if (authRequestState_ != nullptr && timerMap_.find(ADD_TIMEOUT_TASK) != timerMap_.end()) { timerMap_[ADD_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); if (status != DM_OK || authResponseContext_->requestId != requestId) { if (authRequestState_ != nullptr) { @@ -446,7 +447,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) void DmAuthManager::SendAuthRequest(const int32_t &sessionId) { LOGE("DmAuthManager::EstablishAuthChannel session id"); - if (timerMap_[NEGOTIATE_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(NEGOTIATE_TIMEOUT_TASK) == timerMap_.end()) { return; } timerMap_[NEGOTIATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); @@ -484,7 +485,7 @@ int32_t DmAuthManager::StartAuthProcess(const int32_t &action) void DmAuthManager::StartRespAuthProcess() { LOGI("DmAuthManager::StartRespAuthProcess StartRespAuthProcess", authResponseContext_->sessionId); - if (timerMap_[CONFIRM_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(CONFIRM_TIMEOUT_TASK) == timerMap_.end()) { return; } timerMap_[CONFIRM_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); @@ -543,7 +544,7 @@ std::string DmAuthManager::GetConnectAddr(std::string deviceId) int32_t DmAuthManager::JoinNetwork() { LOGE("DmAuthManager JoinNetwork start"); - if (timerMap_[AUTHENTICATE_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(AUTHENTICATE_TIMEOUT_TASK) == timerMap_.end()) { return DM_FAILED; } timerMap_[AUTHENTICATE_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); @@ -798,7 +799,7 @@ void DmAuthManager::UserSwitchEventCallback (int32_t userId) void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) { LOGI("DmAuthManager::VerifyPinAuthAuthentication"); - if (timerMap_[INPUT_TIMEOUT_TASK] == nullptr) { + if (timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { return; } timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index 329ee54b9..897800efe 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -92,7 +92,6 @@ void DmTimer::Stop(int32_t code) } LOGI("DmTimer %s Stop success", mTimerName_.c_str()); } - return; } @@ -107,14 +106,8 @@ void DmTimer::WaitForTimeout() int32_t nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); if (nfds < 0) { LOGE("DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno); - if (errno == EINTR) { - LOGI("DmTimer is stop"); - return; - } - } - - char event = 0; - if (nfds > 0) { + } else if (nfds > 0) { + char event = 0; if (mEvents_[0].events & EPOLLIN) { int num = read(mTimeFd_[0], &event, 1); if (num > 0) { @@ -124,13 +117,11 @@ void DmTimer::WaitForTimeout() } } Release(); - return; + } else { + mHandle_(mHandleData_, *this); + Release(); + LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); } - - mHandle_(mHandleData_, *this); - Release(); - - LOGE("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); return; } -- Gitee From 5458047f47f781b994971e3407803b88c4bab970 Mon Sep 17 00:00:00 2001 From: caochao Date: Tue, 1 Mar 2022 04:52:38 -0800 Subject: [PATCH 11/11] the device crashed online and offline Signed-off-by: cao_liu_chao --- common/include/dm_constants.h | 4 + ext/profile/include/device_profile_adapter.h | 21 +-- ext/profile/include/profile_connector.h | 25 ++-- ext/profile/src/device_profile_adapter.cpp | 58 +++++--- ext/profile/src/profile_connector.cpp | 100 +++++++------ services/devicemanagerservice/BUILD.gn | 1 + .../devicestate/dm_device_state_manager.h | 14 +- .../devicestate/dm_device_state_manager.cpp | 132 +++++++++++------- 8 files changed, 213 insertions(+), 142 deletions(-) mode change 100644 => 100755 common/include/dm_constants.h mode change 100644 => 100755 ext/profile/include/device_profile_adapter.h mode change 100644 => 100755 ext/profile/include/profile_connector.h mode change 100644 => 100755 ext/profile/src/device_profile_adapter.cpp mode change 100644 => 100755 ext/profile/src/profile_connector.cpp mode change 100644 => 100755 services/devicemanagerservice/BUILD.gn mode change 100644 => 100755 services/devicemanagerservice/include/devicestate/dm_device_state_manager.h mode change 100644 => 100755 services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h old mode 100644 new mode 100755 index 184e2e1fc..2cf9531cc --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -62,6 +62,10 @@ enum { DM_MAKE_SHARED_FAIL, DM_SERVICE_NOT_READY, DM_DEVICE_ALREADY_TRUSTED, + ERR_DM_KEY_ALREADY_EXISTS, + ERR_DM_INPUT_PARA_INVALID, + ERR_DM_SUBSCRIBE_DP_EVENTS, + ERR_DM_UNSUBSCRIBE_DP_EVENTS, DM_IPC_FAILED = 2000, DM_IPC_TRANSACTION_FAILED, DM_IPC_FLATTEN_OBJECT, diff --git a/ext/profile/include/device_profile_adapter.h b/ext/profile/include/device_profile_adapter.h old mode 100644 new mode 100755 index 3703a619a..28189d1de --- a/ext/profile/include/device_profile_adapter.h +++ b/ext/profile/include/device_profile_adapter.h @@ -17,6 +17,7 @@ #define OHOS_DM_ADAPTER_DEVICE_PROFILE_H #include +#include #include #include "profile_adapter.h" @@ -24,20 +25,20 @@ namespace OHOS { namespace DistributedHardware { -class DeviceProfileAdapter : public IProfileAdapter, public IProfileConnectorCallback { +class DeviceProfileAdapter final : public IProfileAdapter, public IProfileConnectorCallback, + public std::enable_shared_from_this { public: DeviceProfileAdapter(); - ~DeviceProfileAdapter(); + virtual ~DeviceProfileAdapter(); int32_t RegisterProfileListener(const std::string &pkgName, const std::string &deviceId, - std::shared_ptr callback); - int32_t UnRegisterProfileListener(const std::string &pkgName); - int32_t OnProfileClientDeviceReady(const std::string &pkgName, const std::string &deviceId); - void OnProfileChanged(const std::string &pkgName, const std::string &deviceId); - void OnProfileComplete(const std::string &pkgName, const std::string &deviceId); - + std::shared_ptr callback) override; + int32_t UnRegisterProfileListener(const std::string &pkgName) override; + void OnProfileChanged(const std::string &pkgName, const std::string &deviceId) override; + void OnProfileComplete(const std::string &pkgName, const std::string &deviceId) override; private: - std::shared_ptr deviceProfileAdapterCallback_; - static std::shared_ptr profileConnector_; + std::mutex deviceProfileAdapterMutex_; + std::shared_ptr deviceStateManager_; + std::shared_ptr profileConnector_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/profile/include/profile_connector.h b/ext/profile/include/profile_connector.h old mode 100644 new mode 100755 index d83f90749..b9ec0a351 --- a/ext/profile/include/profile_connector.h +++ b/ext/profile/include/profile_connector.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -28,28 +29,20 @@ namespace OHOS { namespace DistributedHardware { -using namespace OHOS::DeviceProfile; - -class ProfileEventCallback : public IProfileEventCallback { -public: - void OnSyncCompleted(const SyncResult &syncResults); - int32_t RegisterProfileCallback(const std::string &pkgName, std::shared_ptr callback); - int32_t UnRegisterProfileCallback(const std::string &pkgName); - -public: - static std::map> profileConnectorCallback_; -}; - -class ProfileConnector : public IProfileEventCallback { +class ProfileConnector final : public OHOS::DeviceProfile::IProfileEventCallback, + public std::enable_shared_from_this { public: + ProfileConnector(); + virtual ~ProfileConnector(); int32_t RegisterProfileCallback(const std::string &pkgName, const std::string &deviceId, - std::shared_ptr callback); + IProfileConnectorCallback* callback); int32_t UnRegisterProfileCallback(const std::string &pkgName); int32_t SubscribeProfileEvents(const std::list &serviceIds, const std::string &deviceId); int32_t UnSubscribeProfileEvents(); - + void OnSyncCompleted(const OHOS::DeviceProfile::SyncResult &syncResults) override; private: - static std::shared_ptr profileEventCallback_; + std::mutex callbackMapMutex_; + std::map callbackMap_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/profile/src/device_profile_adapter.cpp b/ext/profile/src/device_profile_adapter.cpp old mode 100644 new mode 100755 index 5d6165a01..cfe2a79d8 --- a/ext/profile/src/device_profile_adapter.cpp +++ b/ext/profile/src/device_profile_adapter.cpp @@ -21,52 +21,70 @@ namespace OHOS { namespace DistributedHardware { -std::shared_ptr DeviceProfileAdapter::profileConnector_ = std::make_shared(); - DeviceProfileAdapter::DeviceProfileAdapter() { + LOGI("DeviceProfileAdapter construct"); } DeviceProfileAdapter::~DeviceProfileAdapter() { + LOGI("DeviceProfileAdapter Destructor"); } int32_t DeviceProfileAdapter::RegisterProfileListener(const std::string &pkgName, const std::string &deviceId, std::shared_ptr callback) { - LOGI("DeviceProfileAdapter::RegisterProfileListener"); - deviceProfileAdapterCallback_ = callback; - profileConnector_->RegisterProfileCallback(pkgName, deviceId, std::shared_ptr(this)); + if (pkgName.empty() || deviceId.empty() || callback == nullptr) { + LOGE("Not a reasonable function argument"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("register profile listener with pkgName: %s", pkgName.c_str()); + std::lock_guard mutexLock(deviceProfileAdapterMutex_); + deviceStateManager_ = callback; + if (profileConnector_ == nullptr) { + profileConnector_ = std::make_shared(); + } + if (profileConnector_ != nullptr) { + profileConnector_->RegisterProfileCallback(pkgName, deviceId, this); + } return DM_OK; } int32_t DeviceProfileAdapter::UnRegisterProfileListener(const std::string &pkgName) { - LOGI("DeviceProfileAdapter::RegisterProfileListener"); - deviceProfileAdapterCallback_ = nullptr; - profileConnector_->UnRegisterProfileCallback(pkgName); - return DM_OK; -} - -int32_t DeviceProfileAdapter::OnProfileClientDeviceReady(const std::string &pkgName, const std::string &deviceId) -{ - LOGI("DeviceProfileAdapter::OnProfileClientDeviceReady"); - if (deviceProfileAdapterCallback_ != nullptr) { - deviceProfileAdapterCallback_->OnProfileReady(pkgName, deviceId); - } else { - LOGI("deviceProfileAdapterCallback_ is nullptr"); + if (pkgName.empty()) { + LOGE("not a reasonable function argument"); + return ERR_DM_INPUT_PARA_INVALID; + } + LOGI("unregister profile listener with pkgName: %s", pkgName.c_str()); + std::lock_guard mutexLock(deviceProfileAdapterMutex_); + deviceStateManager_ = nullptr; + if (profileConnector_ != nullptr) { + profileConnector_->UnRegisterProfileCallback(pkgName); } return DM_OK; } void DeviceProfileAdapter::OnProfileChanged(const std::string &pkgName, const std::string &deviceId) { - OnProfileClientDeviceReady(pkgName, deviceId); + LOGI("on profile changed with pkgName: %s", pkgName.c_str()); + std::lock_guard mutexLock(deviceProfileAdapterMutex_); + if (deviceStateManager_ == nullptr) { + LOGE("deviceStateManager_ is nullptr"); + return; + } + deviceStateManager_->OnProfileReady(pkgName, deviceId); } void DeviceProfileAdapter::OnProfileComplete(const std::string &pkgName, const std::string &deviceId) { - OnProfileClientDeviceReady(pkgName, deviceId); + LOGI("on profile complete with pkgName: %s", pkgName.c_str()); + std::lock_guard mutexLock(deviceProfileAdapterMutex_); + if (deviceStateManager_ == nullptr) { + LOGE("deviceStateManager_ is nullptr"); + return; + } + deviceStateManager_->OnProfileReady(pkgName, deviceId); } extern "C" IProfileAdapter *CreateDeviceProfileObject(void) diff --git a/ext/profile/src/profile_connector.cpp b/ext/profile/src/profile_connector.cpp old mode 100644 new mode 100755 index fe46916b1..832fddc50 --- a/ext/profile/src/profile_connector.cpp +++ b/ext/profile/src/profile_connector.cpp @@ -18,75 +18,92 @@ #include "dm_constants.h" #include "dm_log.h" +using namespace OHOS::DeviceProfile; + namespace OHOS { namespace DistributedHardware { -std::map> ProfileEventCallback::profileConnectorCallback_ = {}; -std::shared_ptr ProfileConnector::profileEventCallback_ = - std::make_shared(); +ProfileConnector::ProfileConnector() +{ + LOGI("ProfileConnector construct"); +} + +ProfileConnector::~ProfileConnector() +{ + LOGI("ProfileConnector Destructor"); +} int32_t ProfileConnector::RegisterProfileCallback(const std::string &pkgName, const std::string &deviceId, - std::shared_ptr callback) + IProfileConnectorCallback* callback) { - LOGI("ProfileConnector::RegisterProfileCallback"); - profileEventCallback_->RegisterProfileCallback(pkgName, callback); - SubscribeProfileEvents({ "system", "device", "fakeStorage", "fakeSystem" }, deviceId); - return DM_OK; + if (pkgName.empty() || deviceId.empty() || callback == nullptr) { + LOGE("Not a reasonable function argument"); + return ERR_DM_INPUT_PARA_INVALID; + } + + LOGI("register profile callback with pkgName: %s", pkgName.c_str()); + { + std::lock_guard mutexLock(callbackMapMutex_); + if (callbackMap_.find(pkgName) != callbackMap_.end()) { + LOGE("pkgName: %s already exists in the map", pkgName.c_str()); + return ERR_DM_KEY_ALREADY_EXISTS; + } + LOGI("register profile callback pkgName: %s", pkgName.c_str()); + callbackMap_[pkgName] = callback; + } + std::list serviceIds = { "system", "device", "fakeStorage", "fakeSystem" }; + int32_t ret = SubscribeProfileEvents(serviceIds, deviceId); + if (ret != DM_OK) { + LOGE("fail to subscribe profile events"); + } + return ret; } int32_t ProfileConnector::UnRegisterProfileCallback(const std::string &pkgName) { - LOGI("ProfileConnector::UnRegisterProfileCallback"); - profileEventCallback_->UnRegisterProfileCallback(pkgName); + if (pkgName.empty()) { + LOGE("Not a reasonable function argument"); + return ERR_DM_INPUT_PARA_INVALID; + } + + LOGI("unregister profile callback with pkgName: %s", pkgName.c_str()); + std::lock_guard mutexLock(callbackMapMutex_); + if (callbackMap_.find(pkgName) != callbackMap_.end()) { + callbackMap_.erase(pkgName); + } return DM_OK; } int32_t ProfileConnector::SubscribeProfileEvents(const std::list &serviceIds, const std::string &deviceId) { - ExtraInfo extraInfo; - extraInfo["deviceId"] = deviceId; - extraInfo["serviceIds"] = serviceIds; - - std::list subscribeInfos; - SubscribeInfo eventSync; + std::list failedEvents; + std::list subscribeInfos; eventSync.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED; subscribeInfos.emplace_back(eventSync); - - std::list failedEvents; int32_t errCode = DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents( - subscribeInfos, profileEventCallback_, failedEvents); - LOGI("ProfileConnector::SubscribeProfileEvents result=%d", errCode); + subscribeInfos, shared_from_this(), failedEvents); + if (errCode != ERR_OK) { + LOGI("subscribe profile events result: %ud", errCode); + return ERR_DM_UNSUBSCRIBE_DP_EVENTS; + } return DM_OK; } int32_t ProfileConnector::UnSubscribeProfileEvents() { std::list profileEvents; - profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED); - profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); std::list failedEvents; + profileEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED); int32_t errCode = DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents( - profileEvents, profileEventCallback_, failedEvents); - LOGI("ProfileConnector::UnSubscribeProfileEvents result=%d", errCode); - return DM_OK; -} - -int32_t ProfileEventCallback::RegisterProfileCallback(const std::string &pkgName, - std::shared_ptr callback) -{ - LOGI("ProfileEventCallback::RegisterProfileCallback"); - profileConnectorCallback_.emplace(pkgName, callback); - return DM_OK; -} - -int32_t ProfileEventCallback::UnRegisterProfileCallback(const std::string &pkgName) -{ - LOGI("ProfileEventCallback::UnRegisterProfileCallback"); - profileConnectorCallback_.erase(pkgName); + profileEvents, shared_from_this(), failedEvents); + if (errCode != ERR_OK) { + LOGI("unSubscribe profile events result:%ud", errCode); + return ERR_DM_UNSUBSCRIBE_DP_EVENTS; + } return DM_OK; } -void ProfileEventCallback::OnSyncCompleted(const SyncResult &syncResults) +void ProfileConnector::OnSyncCompleted(const SyncResult &syncResults) { std::string deviceId; u_int32_t SyncStatus; @@ -95,7 +112,8 @@ void ProfileEventCallback::OnSyncCompleted(const SyncResult &syncResults) SyncStatus = iterResult.second; } LOGI("ProfileEventCallback::OnSyncCompleted, deviceId = %s", deviceId.c_str()); - for (auto &iter : profileConnectorCallback_) { + std::lock_guard mutexLock(callbackMapMutex_); + for (auto &iter : callbackMap_) { iter.second->OnProfileComplete(iter.first, deviceId); } } diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn old mode 100644 new mode 100755 index 12ddf9c64..ba6da08e0 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -49,6 +49,7 @@ if (defined(ohos_lite)) { "${common_path}/include", "${common_path}/include/ipc", "${common_path}/include/ipc/model", + "${utils_path}/include", "${utils_path}/include/permission/standard", "//base/security/deviceauth/interfaces/innerkits", "//third_party/json/include", diff --git a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h old mode 100644 new mode 100755 index 7e7ccb82f..332976cdc --- a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h +++ b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h @@ -16,11 +16,16 @@ #ifndef OHOS_DM_DEVICE_STATE_MANAGER_H #define OHOS_DM_DEVICE_STATE_MANAGER_H +#include +#include +#include + #include "device_manager_service_listener.h" #include "dm_adapter_manager.h" #include "softbus_connector.h" #include "dm_timer.h" #include "hichain_connector.h" + namespace OHOS { namespace DistributedHardware { #define OFFLINE_TIMEOUT 300 @@ -35,21 +40,20 @@ public: void OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info); void OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &info); void OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &info); - void OnProfileReady(const std::string &pkgName, const std::string deviceId); + void OnProfileReady(const std::string &pkgName, const std::string &deviceId); int32_t RegisterSoftbusStateCallback(); void RegisterOffLineTimer(const DmDeviceInfo &deviceInfo); void StartOffLineTimer(const DmDeviceInfo &deviceInfo); void DeleteTimeOutGroup(std::string deviceId); - private: + std::string profileSoName_; + std::mutex timerMapMutex_; + std::mutex remoteDeviceInfosMutex_; std::shared_ptr softbusConnector_; - std::shared_ptr adapterMgr_; std::shared_ptr listener_; - std::map deviceStateMap_; std::map remoteDeviceInfos_; std::map> timerMap_; std::shared_ptr hiChainConnector_; - std::string profileSoName_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp old mode 100644 new mode 100755 index 9318bd0ab..794837bc7 --- a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp +++ b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp @@ -16,8 +16,10 @@ #include "dm_device_state_manager.h" #include "dm_adapter_manager.h" +#include "dm_anonymous.h" #include "dm_constants.h" #include "dm_log.h" + namespace OHOS { namespace DistributedHardware { const int32_t SESSION_CANCEL_TIMEOUT = 0; @@ -34,121 +36,149 @@ static void TimeOut(void *data, DmTimer& timer) } DmDeviceStateManager::DmDeviceStateManager(std::shared_ptr softbusConnector, - std::shared_ptr listener, - std::shared_ptr hiChainConnector) + std::shared_ptr listener, std::shared_ptr hiChainConnector) : softbusConnector_(softbusConnector), listener_(listener), hiChainConnector_(hiChainConnector) { - LOGI("DmDeviceStateManager constructor"); profileSoName_ = "libdevicemanagerext_profile.z.so"; + LOGI("DmDeviceStateManager constructor"); } DmDeviceStateManager::~DmDeviceStateManager() { LOGI("DmDeviceStateManager destructor"); - softbusConnector_->UnRegisterSoftbusStateCallback("DM_PKG_NAME"); + if (softbusConnector_ != nullptr) { + softbusConnector_->UnRegisterSoftbusStateCallback("DM_PKG_NAME"); + } } void DmDeviceStateManager::OnDeviceOnline(const std::string &pkgName, const DmDeviceInfo &info) { - LOGI("DmDeviceStateManager::OnDeviceOnline in"); + LOGI("OnDeviceOnline function is called back with pkgName: %s", pkgName.c_str()); RegisterOffLineTimer(info); DmAdapterManager &adapterMgrPtr = DmAdapterManager::GetInstance(); std::shared_ptr profileAdapter = adapterMgrPtr.GetProfileAdapter(profileSoName_); - if (profileAdapter == nullptr) { - LOGE("OnDeviceOnline profile adapter is null"); - } else { - uint8_t udid[UDID_BUF_LEN] = {0}; - int32_t ret = SoftbusConnector::GetNodeKeyInfoByNetworkId(info.deviceId, NodeDeviceInfoKey::NODE_KEY_UDID, udid, - sizeof(udid)); - if (ret != DM_OK) { - LOGE("DmDeviceStateManager::OnDeviceOnline GetNodeKeyInfo failed"); - } else { - std::string deviceUdid = (char *)udid; - DmDeviceInfo saveInfo = info; + if (profileAdapter != nullptr) { + uint8_t udid[UDID_BUF_LEN + 1] = {0}; + int32_t ret = SoftbusConnector::GetNodeKeyInfoByNetworkId(info.deviceId, + NodeDeviceInfoKey::NODE_KEY_UDID, udid, sizeof(udid)); + if (ret == DM_OK) { std::string uuid; + DmDeviceInfo saveInfo = info; SoftbusConnector::GetUuidByNetworkId(info.deviceId, uuid); - remoteDeviceInfos_[uuid] = saveInfo; + { + std::lock_guard mutexLock(remoteDeviceInfosMutex_); + remoteDeviceInfos_[uuid] = saveInfo; + } + std::string deviceUdid = (char *)udid; LOGI("RegisterProfileListener in, deviceId = %s, deviceUdid = %s, uuid = %s", info.deviceId, deviceUdid.c_str(), uuid.c_str()); - LOGI("RegisterProfileListener out"); + profileAdapter->RegisterProfileListener(pkgName, deviceUdid, shared_from_this()); } } - DmDeviceState state = DEVICE_STATE_ONLINE; - deviceStateMap_[info.deviceId] = DEVICE_STATE_ONLINE; - listener_->OnDeviceStateChange(pkgName, state, info); - LOGI("DmDeviceStateManager::OnDeviceOnline out"); + if (listener_ != nullptr) { + DmDeviceState state = DEVICE_STATE_ONLINE; + listener_->OnDeviceStateChange(pkgName, state, info); + } } void DmDeviceStateManager::OnDeviceOffline(const std::string &pkgName, const DmDeviceInfo &info) { + LOGI("OnDeviceOnline function is called with pkgName: %s", pkgName.c_str()); StartOffLineTimer(info); DmAdapterManager &adapterMgrPtr = DmAdapterManager::GetInstance(); std::shared_ptr profileAdapter = adapterMgrPtr.GetProfileAdapter(profileSoName_); - if (profileAdapter == nullptr) { - LOGE("OnDeviceOffline profile adapter is null"); - } else { - auto iter = remoteDeviceInfos_.find(std::string(info.deviceId)); - if (iter == remoteDeviceInfos_.end()) { - } else { + if (profileAdapter != nullptr) { + LOGI("UnRegister Profile Listener"); + profileAdapter->UnRegisterProfileListener(pkgName); + } + { + std::lock_guard mutexLock(remoteDeviceInfosMutex_); + if (remoteDeviceInfos_.find(std::string(info.deviceId)) != remoteDeviceInfos_.end()) { remoteDeviceInfos_.erase(std::string(info.deviceId)); } } - DmDeviceState state = DEVICE_STATE_OFFLINE; - deviceStateMap_[info.deviceId] = DEVICE_STATE_OFFLINE; - listener_->OnDeviceStateChange(pkgName, state, info); + if (listener_ != nullptr) { + DmDeviceState state = DEVICE_STATE_OFFLINE; + listener_->OnDeviceStateChange(pkgName, state, info); + } } void DmDeviceStateManager::OnDeviceChanged(const std::string &pkgName, const DmDeviceInfo &info) { - deviceStateMap_[info.deviceId] = DEVICE_INFO_CHANGED; + LOGI("OnDeviceChanged function is called back with pkgName: %s", pkgName.c_str()); } void DmDeviceStateManager::OnDeviceReady(const std::string &pkgName, const DmDeviceInfo &info) { - deviceStateMap_[info.deviceId] = DEVICE_INFO_READY; + LOGI("OnDeviceReady function is called back with pkgName: %s", pkgName.c_str()); } -void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std::string deviceId) +void DmDeviceStateManager::OnProfileReady(const std::string &pkgName, const std::string &deviceId) { + LOGI("OnProfileReady function is called back"); + if (pkgName.empty() || deviceId.empty()) { + LOGE("On profile ready pkgName is empty or deviceId is deviceId"); + return; + } DmDeviceInfo saveInfo; - auto iter = remoteDeviceInfos_.find(deviceId); - if (iter == remoteDeviceInfos_.end()) { - LOGE("DmDeviceStateManager::OnProfileReady complete not find deviceID = %s", deviceId.c_str()); - } else { + { + std::lock_guard mutexLock(remoteDeviceInfosMutex_); + auto iter = remoteDeviceInfos_.find(deviceId); + if (iter == remoteDeviceInfos_.end()) { + LOGE("OnProfileReady complete not find deviceId: %s", GetAnonyString(deviceId).c_str()); + return; + } saveInfo = iter->second; } - DmDeviceState state = DEVICE_INFO_READY; - listener_->OnDeviceStateChange(pkgName, state, saveInfo); + if (listener_ != nullptr) { + DmDeviceState state = DEVICE_INFO_READY; + listener_->OnDeviceStateChange(pkgName, state, saveInfo); + } } int32_t DmDeviceStateManager::RegisterSoftbusStateCallback() { - softbusConnector_->RegisterSoftbusStateCallback(DM_PKG_NAME, - std::shared_ptr(shared_from_this())); + if (softbusConnector_ != nullptr) { + return softbusConnector_->RegisterSoftbusStateCallback(DM_PKG_NAME, shared_from_this()); + } return DM_OK; } void DmDeviceStateManager::RegisterOffLineTimer(const DmDeviceInfo &deviceInfo) { std::string deviceId; - softbusConnector_->GetUdidByNetworkId(deviceInfo.deviceId, deviceId); - LOGI("Device<%s>Online", deviceId.c_str()); + int32_t ret = softbusConnector_->GetUdidByNetworkId(deviceInfo.deviceId, deviceId); + if (ret != DM_OK) { + LOGE("fail to get udid by networkId"); + return; + } + LOGI("Register OffLine Timer with device: %s", GetAnonyString(deviceId).c_str()); + + std::lock_guard mutexLock(timerMapMutex_); auto iter = timerMap_.find(deviceId); if (iter != timerMap_.end()) { iter->second->Stop(SESSION_CANCEL_TIMEOUT); return; } std::shared_ptr offLineTimer = std::make_shared(deviceId); - timerMap_[deviceId] = offLineTimer; + if (offLineTimer != nullptr) { + timerMap_[deviceId] = offLineTimer; + } } void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo) { std::string deviceId; - softbusConnector_->GetUdidByNetworkId(deviceInfo.deviceId, deviceId); - LOGI("Device<%s>Offline", deviceId.c_str()); + int32_t ret = softbusConnector_->GetUdidByNetworkId(deviceInfo.deviceId, deviceId); + if (ret != DM_OK) { + LOGE("fail to get udid by networkId"); + return; + } + + LOGI("start offline timer with device: %s", GetAnonyString(deviceId).c_str()); + std::lock_guard mutexLock(timerMapMutex_); for (auto &iter : timerMap_) { - if (iter.first.compare(deviceId) == 0) { + if (iter.first == deviceId) { iter.second->Start(OFFLINE_TIMEOUT, TimeOut, this); } } @@ -156,8 +186,10 @@ void DmDeviceStateManager::StartOffLineTimer(const DmDeviceInfo &deviceInfo) void DmDeviceStateManager::DeleteTimeOutGroup(std::string deviceId) { - LOGI("Remove DmDevice<%s> Hichain Group", deviceId.c_str()); - hiChainConnector_->DeleteTimeOutGroup(deviceId.c_str()); + LOGI("remove hichain group with device: %s", GetAnonyString(deviceId).c_str()); + if (hiChainConnector_ != nullptr) { + hiChainConnector_->DeleteTimeOutGroup(deviceId.c_str()); + } } } // namespace DistributedHardware } // namespace OHOS -- Gitee