From 63d45204e763459972666cb0efdeb85758792b91 Mon Sep 17 00:00:00 2001 From: guoyi Date: Fri, 6 Jun 2025 15:32:39 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=EF=BC=9B2.=E7=9B=91?= =?UTF-8?q?=E5=90=AC=E9=94=81=E5=B1=8F=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guoyi --- common/include/dm_error_type.h | 2 +- .../include/dm_device_profile_info.h | 25 +++++--- .../include/i_dm_service_impl_ext_resident.h | 3 +- .../include/notify/device_manager_notify.h | 4 -- .../native_cpp/src/device_manager_impl.cpp | 30 ++++++--- .../src/notify/device_manager_notify.cpp | 61 +++---------------- interfaces/kits/js4.0/src/dm_native_util.cpp | 2 +- .../js4.0/src/native_devicemanager_js.cpp | 56 +++++++++++++---- .../service/include/device_manager_service.h | 2 +- .../service/src/device_manager_service.cpp | 18 ++++-- .../dm_screen_common_event.cpp | 3 +- 11 files changed, 107 insertions(+), 99 deletions(-) diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index 2d2b96fe2..9e4fa560b 100644 --- a/common/include/dm_error_type.h +++ b/common/include/dm_error_type.h @@ -110,7 +110,7 @@ enum { ERR_DM_CRYPTO_OPT_FAILED = 96929822, ERR_DM_CRYPTO_PARA_INVALID = 96929823, ERR_DM_SECURITY_FUNC_FAILED = 96929824, - ERR_DM_MAX_SIZE_FAIL = 96929825, + ERR_DM_CALLBACK_REGISTER_FAILED = 96929825, ERR_DM_HILINKSVC_RSP_PARSE_FAILD = 96929826, ERR_DM_HILINKSVC_REPLY_FAILED = 96929827, ERR_DM_HILINKSVC_ICON_URL_EMPTY = 96929828, diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h index b110b9176..21bde5a1e 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_profile_info.h @@ -30,6 +30,14 @@ typedef struct DmProductInfo { std::string imageVersion = ""; } DmProductInfo; +typedef struct DmDeviceIconInfoFilterOptions { + std::string productId = ""; + std::string subProductId = ""; + std::string internalModel = ""; + std::string imageType = ""; + std::string specName = ""; +} DmDeviceIconInfoFilterOptions; + typedef struct DmDeviceIconInfo { std::string productId = ""; std::string subProductId = ""; @@ -40,6 +48,15 @@ typedef struct DmDeviceIconInfo { std::string version = ""; std::string url = ""; std::vector icon = {}; + + void InitByDmDeviceIconInfoFilterOptions(const DmDeviceIconInfoFilterOptions &filterOptions) + { + productId = filterOptions.productId; + subProductId = filterOptions.subProductId; + internalModel = filterOptions.internalModel; + imageType = filterOptions.imageType; + specName = filterOptions.specName; + } } DmDeviceIconInfo; typedef struct DmServiceProfileInfo { @@ -54,14 +71,6 @@ typedef struct DmDeviceProfileInfoFilterOptions { std::vector deviceIdList = {}; } DmDeviceProfileInfoFilterOptions; -typedef struct DmDeviceIconInfoFilterOptions { - std::string productId = ""; - std::string subProductId = ""; - std::string internalModel = ""; - std::string imageType = ""; - std::string specName = ""; -} DmDeviceIconInfoFilterOptions; - typedef struct DmDeviceProfileInfo { std::string deviceId = ""; std::string deviceSn = ""; diff --git a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h index 5bd4accc4..1740abdf3 100644 --- a/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h +++ b/interfaces/inner_kits/native_cpp/include/i_dm_service_impl_ext_resident.h @@ -101,12 +101,13 @@ public: virtual int32_t PutDeviceProfileInfoList(const std::string &pkgName, const std::vector &deviceProfileInfoList) = 0; virtual std::vector GetDeviceNamePrefixs() = 0; - virtual void CheckRegisterInfoWithWise() = 0; + virtual void HandleNetworkConnected(int32_t networkStatus) = 0; virtual int32_t SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName) = 0; virtual int32_t SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, const std::string &deviceName) = 0; virtual int32_t GetDeviceProfileInfosFromLocalCache(const NetworkIdQueryFilter &queryFilter, std::vector &dmDeviceProfileInfos) = 0; + virtual void HandleScreenLockEvent(bool isLock) = 0; }; using CreateDMServiceExtResidentFuncPtr = IDMServiceImplExtResident *(*)(void); diff --git a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h index c5b25bda6..66f8a83de 100644 --- a/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h +++ b/interfaces/inner_kits/native_cpp/include/notify/device_manager_notify.h @@ -75,20 +75,16 @@ public: int32_t RegisterGetDeviceProfileInfoListCallback(const std::string &pkgName, std::shared_ptr callback); - int32_t UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName); void OnGetDeviceProfileInfoListResult(const std::string &pkgName, const std::vector &deviceProfileInfos, int32_t code); int32_t RegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk, std::shared_ptr callback); - int32_t UnRegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk); void OnGetDeviceIconInfoResult(const std::string &pkgName, const DmDeviceIconInfo &deviceIconInfo, int32_t code); int32_t RegisterSetLocalDeviceNameCallback(const std::string &pkgName, std::shared_ptr callback); - int32_t UnRegisterSetLocalDeviceNameCallback(const std::string &pkgName); void OnSetLocalDeviceNameResult(const std::string &pkgName, int32_t code); int32_t RegisterSetRemoteDeviceNameCallback(const std::string &pkgName, const std::string &deviceId, std::shared_ptr callback); - int32_t UnRegisterSetRemoteDeviceNameCallback(const std::string &pkgName, const std::string &deviceId); void OnSetRemoteDeviceNameResult(const std::string &pkgName, const std::string &deviceId, int32_t code); public: diff --git a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp index 46d78457d..184dee41e 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2648,13 +2648,14 @@ int32_t DeviceManagerImpl::GetDeviceProfileInfoList(const std::string &pkgName, ret = ipcClientProxy_->SendRequest(GET_DEVICE_PROFILE_INFO_LIST, req, rsp); if (ret != DM_OK) { LOGE("error: Send Request failed ret: %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterGetDeviceProfileInfoListCallback(pkgName); + DeviceManagerNotify::GetInstance().OnGetDeviceProfileInfoListResult(pkgName, {}, + ERR_DM_IPC_SEND_REQUEST_FAILED); return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("error: Failed with ret %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterGetDeviceProfileInfoListCallback(pkgName); + DeviceManagerNotify::GetInstance().OnGetDeviceProfileInfoListResult(pkgName, {}, ret); return ret; } LOGI("Completed"); @@ -2679,16 +2680,24 @@ int32_t DeviceManagerImpl::GetDeviceIconInfo(const std::string &pkgName, ret = ipcClientProxy_->SendRequest(GET_DEVICE_ICON_INFO, req, rsp); if (ret != DM_OK) { LOGE("Send Request failed ret: %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterGetDeviceIconInfoCallback(pkgName, uk); + DmDeviceIconInfo deviceIconInfo; + deviceIconInfo.InitByDmDeviceIconInfoFilterOptions(filterOptions); + DeviceManagerNotify::GetInstance().OnGetDeviceIconInfoResult(pkgName, deviceIconInfo, + ERR_DM_IPC_SEND_REQUEST_FAILED); return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("Failed with ret %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterGetDeviceIconInfoCallback(pkgName, uk); + DmDeviceIconInfo deviceIconInfo; + deviceIconInfo.InitByDmDeviceIconInfoFilterOptions(filterOptions); + DeviceManagerNotify::GetInstance().OnGetDeviceIconInfoResult(pkgName, deviceIconInfo, ret); return ret; } #endif + (void)pkgName; + (void)filterOptions; + (void)callback; return DM_OK; } @@ -2823,7 +2832,7 @@ int32_t DeviceManagerImpl::GetLocalServiceInfoByBundleNameAndPinExchangeType( int32_t DeviceManagerImpl::SetLocalDeviceName(const std::string &pkgName, const std::string &deviceName, std::shared_ptr callback) { - if (pkgName.empty() || deviceName.empty()) { + if (pkgName.empty() || deviceName.empty() || deviceName.size() > DEVICE_NAME_MAX_BYTES) { LOGE("param invalid, pkgName : %{public}s, deviceName = %{public}s", pkgName.c_str(), GetAnonyString(deviceName).c_str()); return ERR_DM_INPUT_PARA_INVALID; @@ -2841,13 +2850,13 @@ int32_t DeviceManagerImpl::SetLocalDeviceName(const std::string &pkgName, const ret = ipcClientProxy_->SendRequest(SET_LOCAL_DEVICE_NAME, req, rsp); if (ret != DM_OK) { LOGE("error: Send Request failed ret: %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterSetLocalDeviceNameCallback(pkgName); + DeviceManagerNotify::GetInstance().OnSetLocalDeviceNameResult(pkgName, ERR_DM_IPC_SEND_REQUEST_FAILED); return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("error: Failed with ret %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterSetLocalDeviceNameCallback(pkgName); + DeviceManagerNotify::GetInstance().OnSetLocalDeviceNameResult(pkgName, ret); return ret; } LOGI("Completed"); @@ -2857,7 +2866,7 @@ int32_t DeviceManagerImpl::SetLocalDeviceName(const std::string &pkgName, const int32_t DeviceManagerImpl::SetRemoteDeviceName(const std::string &pkgName, const std::string &deviceId, const std::string &deviceName, std::shared_ptr callback) { - if (pkgName.empty() || deviceName.empty()) { + if (pkgName.empty() || deviceName.empty() || deviceName.size() > DEVICE_NAME_MAX_BYTES || deviceId.empty()) { LOGE("param invalid, pkgName : %{public}s, deviceName = %{public}s", pkgName.c_str(), GetAnonyString(deviceName).c_str()); return ERR_DM_INPUT_PARA_INVALID; @@ -2876,13 +2885,14 @@ int32_t DeviceManagerImpl::SetRemoteDeviceName(const std::string &pkgName, const ret = ipcClientProxy_->SendRequest(SET_REMOTE_DEVICE_NAME, req, rsp); if (ret != DM_OK) { LOGE("error: Send Request failed ret: %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterSetRemoteDeviceNameCallback(pkgName, deviceId); + DeviceManagerNotify::GetInstance().OnSetRemoteDeviceNameResult(pkgName, deviceId, + ERR_DM_IPC_SEND_REQUEST_FAILED); return ERR_DM_IPC_SEND_REQUEST_FAILED; } ret = rsp->GetErrCode(); if (ret != DM_OK) { LOGE("error: Failed with ret %{public}d", ret); - DeviceManagerNotify::GetInstance().UnRegisterSetRemoteDeviceNameCallback(pkgName, deviceId); + DeviceManagerNotify::GetInstance().OnSetRemoteDeviceNameResult(pkgName, deviceId, ret); return ret; } LOGI("Completed"); 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 6dd054fd7..fb0d2d076 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 @@ -1255,20 +1255,12 @@ int32_t DeviceManagerNotify::RegisterGetDeviceProfileInfoListCallback(const std: std::lock_guard autoLock(bindLock_); if (getDeviceProfileInfoCallback_.size() > MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } getDeviceProfileInfoCallback_[pkgName] = callback; return DM_OK; } -int32_t DeviceManagerNotify::UnRegisterGetDeviceProfileInfoListCallback(const std::string &pkgName) -{ - LOGI("In, pkgName: %{public}s.", pkgName.c_str()); - std::lock_guard autoLock(bindLock_); - getDeviceProfileInfoCallback_.erase(pkgName); - return DM_OK; -} - void DeviceManagerNotify::OnGetDeviceProfileInfoListResult(const std::string &pkgName, const std::vector &deviceProfileInfos, int32_t code) { @@ -1301,7 +1293,7 @@ int32_t DeviceManagerNotify::RegisterGetDeviceIconInfoCallback(const std::string std::lock_guard autoLock(bindLock_); if (getDeviceIconInfoCallback_.size() > MAX_CONTAINER_SIZE) { LOGE("callback map size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } auto iter = getDeviceIconInfoCallback_.find(pkgName); if (iter == getDeviceIconInfoCallback_.end()) { @@ -1310,31 +1302,16 @@ int32_t DeviceManagerNotify::RegisterGetDeviceIconInfoCallback(const std::string } if (iter->second.size() > MAX_CONTAINER_SIZE) { LOGE("callback map for pkg size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } if (iter->second[uk].size() > MAX_CONTAINER_SIZE) { LOGE("callback set size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } iter->second[uk].insert(callback); return DM_OK; } -int32_t DeviceManagerNotify::UnRegisterGetDeviceIconInfoCallback(const std::string &pkgName, const std::string &uk) -{ - LOGI("In, pkgName: %{public}s", pkgName.c_str()); - std::lock_guard autoLock(bindLock_); - auto iter = getDeviceIconInfoCallback_.find(pkgName); - if (iter == getDeviceIconInfoCallback_.end()) { - return DM_OK; - } - iter->second.erase(uk); - if (iter->second.empty()) { - getDeviceIconInfoCallback_.erase(pkgName); - } - return DM_OK; -} - void DeviceManagerNotify::OnGetDeviceIconInfoResult(const std::string &pkgName, const DmDeviceIconInfo &deviceIconInfo, int32_t code) { @@ -1382,20 +1359,12 @@ int32_t DeviceManagerNotify::RegisterSetLocalDeviceNameCallback(const std::strin std::lock_guard autoLock(bindLock_); if (setLocalDeviceNameCallback_.size() > MAX_CONTAINER_SIZE) { LOGI("callback map size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } setLocalDeviceNameCallback_[pkgName] = callback; return DM_OK; } -int32_t DeviceManagerNotify::UnRegisterSetLocalDeviceNameCallback(const std::string &pkgName) -{ - LOGI("In, pkgName: %{public}s.", pkgName.c_str()); - std::lock_guard autoLock(bindLock_); - setLocalDeviceNameCallback_.erase(pkgName); - return DM_OK; -} - int32_t DeviceManagerNotify::RegisterSetRemoteDeviceNameCallback(const std::string &pkgName, const std::string &deviceId, std::shared_ptr callback) { @@ -1403,7 +1372,7 @@ int32_t DeviceManagerNotify::RegisterSetRemoteDeviceNameCallback(const std::stri std::lock_guard autoLock(bindLock_); if (setRemoteDeviceNameCallback_.size() > MAX_CONTAINER_SIZE) { LOGI("callback map size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } auto iter = setRemoteDeviceNameCallback_.find(pkgName); if (iter == setRemoteDeviceNameCallback_.end()) { @@ -1412,28 +1381,12 @@ int32_t DeviceManagerNotify::RegisterSetRemoteDeviceNameCallback(const std::stri } if (iter->second.size() > MAX_CONTAINER_SIZE) { LOGI("callback map size is more than max size"); - return ERR_DM_MAX_SIZE_FAIL; + return ERR_DM_CALLBACK_REGISTER_FAILED; } iter->second[deviceId] = callback; return DM_OK; } -int32_t DeviceManagerNotify::UnRegisterSetRemoteDeviceNameCallback(const std::string &pkgName, - const std::string &deviceId) -{ - LOGI("In, pkgName: %{public}s.", pkgName.c_str()); - std::lock_guard autoLock(bindLock_); - auto iter = setRemoteDeviceNameCallback_.find(pkgName); - if (iter == setRemoteDeviceNameCallback_.end()) { - return DM_OK; - } - iter->second.erase(deviceId); - if (iter->second.empty()) { - setRemoteDeviceNameCallback_.erase(pkgName); - } - return DM_OK; -} - void DeviceManagerNotify::OnSetLocalDeviceNameResult(const std::string &pkgName, int32_t code) { if (pkgName.empty()) { diff --git a/interfaces/kits/js4.0/src/dm_native_util.cpp b/interfaces/kits/js4.0/src/dm_native_util.cpp index d1712c2f8..e551b5280 100644 --- a/interfaces/kits/js4.0/src/dm_native_util.cpp +++ b/interfaces/kits/js4.0/src/dm_native_util.cpp @@ -225,7 +225,7 @@ napi_value CreateBusinessError(napi_env env, int32_t errCode, bool isAsync) break; case ERR_DM_INPUT_PARA_INVALID: case ERR_DM_UNSUPPORTED_AUTH_TYPE: - case ERR_DM_MAX_SIZE_FAIL: + case ERR_DM_CALLBACK_REGISTER_FAILED: error = CreateErrorForCall(env, ERR_INVALID_PARAMS, ERR_MESSAGE_INVALID_PARAMS, isAsync); break; case ERR_DM_INIT_FAILED: diff --git a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp index b63adc3ce..3201eec19 100644 --- a/interfaces/kits/js4.0/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js4.0/src/native_devicemanager_js.cpp @@ -40,6 +40,14 @@ namespace { napi_value thisVar = nullptr; \ NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr)) +#define CHECK_NULL_VOID_RET_LOG(ptr, fmt, ...) \ + do { \ + if ((ptr) == NULL) { \ + LOGE(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + const std::string DM_NAPI_EVENT_DEVICE_STATE_CHANGE = "deviceStateChange"; const std::string DM_NAPI_EVENT_DEVICE_DISCOVER_SUCCESS = "discoverSuccess"; const std::string DM_NAPI_EVENT_DEVICE_DISCOVER_FAIL = "discoverFail"; @@ -546,6 +554,7 @@ void DmNapiGetDeviceProfileInfoListCallback::OnResult(const std::vectorcode != DM_OK) { @@ -756,6 +766,7 @@ void DeviceManagerNapi::OnGetDeviceProfileInfoListCallbackResult(DeviceProfileIn void DeviceManagerNapi::OnGetDeviceIconInfoCallbackResult(DeviceIconInfoAsyncCallbackInfo *jsCallback) { LOGI("In"); + CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; napi_open_handle_scope(env_, &scope); if (jsCallback->code != DM_OK) { @@ -775,6 +786,7 @@ void DeviceManagerNapi::OnGetDeviceIconInfoCallbackResult(DeviceIconInfoAsyncCal void DeviceManagerNapi::OnSetLocalDeviceNameCallbackResult(SetLocalDeviceNameAsyncCallbackInfo *jsCallback) { LOGI("In"); + CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; napi_open_handle_scope(env_, &scope); if (jsCallback->code != DM_OK) { @@ -793,6 +805,7 @@ void DeviceManagerNapi::OnSetLocalDeviceNameCallbackResult(SetLocalDeviceNameAsy void DeviceManagerNapi::OnSetRemoteDeviceNameCallbackResult(SetRemoteDeviceNameAsyncCallbackInfo *jsCallback) { LOGI("In"); + CHECK_NULL_VOID_RET_LOG(jsCallback, "jsCallback is nullptr"); napi_handle_scope scope; napi_open_handle_scope(env_, &scope); if (jsCallback->code != DM_OK) { @@ -2004,9 +2017,13 @@ napi_value DeviceManagerNapi::GetDeviceProfileInfoListPromise(napi_env env, (void)status; DeviceProfileInfosAsyncCallbackInfo *jsCallback = reinterpret_cast(data); - if (jsCallback->code != DM_OK) { - napi_value error = CreateBusinessError(env, jsCallback->code, false); - napi_reject_deferred(env, jsCallback->deferred, error); + if (jsCallback->code == ERR_DM_CALLBACK_REGISTER_FAILED) { + if (jsCallback->deferred != nullptr) { + napi_value error = CreateBusinessError(env, jsCallback->code, false); + napi_reject_deferred(env, jsCallback->deferred, error); + } else { + LOGE("jsCallback->deferred is null"); + } } napi_delete_async_work(env, jsCallback->asyncWork); delete jsCallback; @@ -2167,9 +2184,13 @@ napi_value DeviceManagerNapi::GetDeviceIconInfoPromise(napi_env env, DeviceIconI (void)status; DeviceIconInfoAsyncCallbackInfo *jsCallback = reinterpret_cast(data); - if (jsCallback->code != DM_OK) { - napi_value error = CreateBusinessError(env, jsCallback->code, false); - napi_reject_deferred(env, jsCallback->deferred, error); + if (jsCallback->code == ERR_DM_CALLBACK_REGISTER_FAILED) { + if (jsCallback->deferred != nullptr) { + napi_value error = CreateBusinessError(env, jsCallback->code, false); + napi_reject_deferred(env, jsCallback->deferred, error); + } else { + LOGE("jsCallback->deferred is null"); + } } napi_delete_async_work(env, jsCallback->asyncWork); delete jsCallback; @@ -2464,9 +2485,13 @@ napi_value DeviceManagerNapi::SetLocalDeviceNamePromise(napi_env env, (void)status; SetLocalDeviceNameAsyncCallbackInfo *jsCallback = reinterpret_cast(data); - if (jsCallback->code != DM_OK) { - napi_value error = CreateBusinessError(env, jsCallback->code, false); - napi_reject_deferred(env, jsCallback->deferred, error); + if (jsCallback->code == ERR_DM_CALLBACK_REGISTER_FAILED || jsCallback->code == ERR_DM_INPUT_PARA_INVALID) { + if (jsCallback->deferred != nullptr) { + napi_value error = CreateBusinessError(env, jsCallback->code, false); + napi_reject_deferred(env, jsCallback->deferred, error); + } else { + LOGE("jsCallback->deferred is null"); + } } napi_delete_async_work(env, jsCallback->asyncWork); delete jsCallback; @@ -2506,9 +2531,13 @@ napi_value DeviceManagerNapi::SetRemoteDeviceNamePromise(napi_env env, (void)status; SetRemoteDeviceNameAsyncCallbackInfo *jsCallback = reinterpret_cast(data); - if (jsCallback->code != DM_OK) { - napi_value error = CreateBusinessError(env, jsCallback->code, false); - napi_reject_deferred(env, jsCallback->deferred, error); + if (jsCallback->code == ERR_DM_CALLBACK_REGISTER_FAILED || jsCallback->code == ERR_DM_INPUT_PARA_INVALID) { + if (jsCallback->deferred != nullptr) { + napi_value error = CreateBusinessError(env, jsCallback->code, false); + napi_reject_deferred(env, jsCallback->deferred, error); + } else { + LOGE("jsCallback->deferred is null"); + } } napi_delete_async_work(env, jsCallback->asyncWork); delete jsCallback; @@ -2944,6 +2973,7 @@ void DmNapiGetDeviceIconInfoCallback::OnResult(const OHOS::DistributedHardware:: int32_t code) { LOGI("In code:%{public}d", code); + CHECK_NULL_VOID_RET_LOG(deferred_, "deferred_ is nullptr"); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); if (loop == nullptr) { @@ -2993,6 +3023,7 @@ void DmNapiGetDeviceIconInfoCallback::OnResult(const OHOS::DistributedHardware:: void DmNapiSetLocalDeviceNameCallback::OnResult(int32_t code) { LOGI("In code:%{public}d", code); + CHECK_NULL_VOID_RET_LOG(deferred_, "deferred_ is nullptr"); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); if (loop == nullptr) { @@ -3041,6 +3072,7 @@ void DmNapiSetLocalDeviceNameCallback::OnResult(int32_t code) void DmNapiSetRemoteDeviceNameCallback::OnResult(int32_t code) { LOGI("In code:%{public}d", code); + CHECK_NULL_VOID_RET_LOG(deferred_, "deferred_ is nullptr"); uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); if (loop == nullptr) { diff --git a/services/service/include/device_manager_service.h b/services/service/include/device_manager_service.h index 32a09ec3e..00e973d49 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -341,7 +341,7 @@ private: #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI void SubscribeDataShareCommonEvent(); #endif - void CheckRegisterInfoWithWise(); + void HandleNetworkConnected(int32_t networkStatus); void NotifyRemoteLocalLogout(const std::vector &peerUdids, const std::string &accountIdHash, const std::string &accountName, int32_t userId); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index 862623f34..843d9070e 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -69,7 +69,6 @@ namespace { const int32_t NORMAL = 0; const int32_t SYSTEM_BASIC = 1; const int32_t SYSTEM_CORE = 2; - constexpr int32_t NETWORK_AVAILABLE = 3; constexpr const char *ALL_PKGNAME = ""; constexpr const char *NETWORKID = "NETWORK_ID"; constexpr uint32_t INVALIED_BIND_LEVEL = 0; @@ -175,8 +174,8 @@ void DeviceManagerService::SubscribeDataShareCommonEvent() if (arg1 == CommonEventSupport::COMMON_EVENT_LOCALE_CHANGED) { DeviceNameManager::GetInstance().InitDeviceNameWhenLanguageOrRegionChanged(); } - if (arg1 == CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE && arg2 == NETWORK_AVAILABLE) { - this->CheckRegisterInfoWithWise(); + if (arg1 == CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE) { + this->HandleNetworkConnected(arg2); } }; std::vector commonEventVec; @@ -1862,6 +1861,7 @@ void DeviceManagerService::SubscribeScreenLockEvent() ScreenEventCallback callback = [=](const auto &arg1) { this->ScreenCommonEventCallback(arg1); }; std::vector screenEventVec; screenEventVec.emplace_back(CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED); + screenEventVec.emplace_back(CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED); if (screenCommonEventManager_->SubscribeScreenCommonEvent(screenEventVec, callback)) { LOGI("Success"); } @@ -2262,6 +2262,12 @@ void DeviceManagerService::ProcessSyncUserIds(const std::vector &foreg void DeviceManagerService::ScreenCommonEventCallback(std::string commonEventType) { + if (IsDMServiceAdapterResidentLoad()) { + bool isLock = commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED; + dmServiceImplExtResident_->HandleScreenLockEvent(isLock); + } else { + LOGE("ScreenCommonEventCallback failed, dmServiceImplExtResident not init or init failed."); + } if (!IsDMImplSoLoaded()) { LOGE("ScreenCommonEventCallback failed, instance not init or init failed."); return; @@ -3239,14 +3245,14 @@ std::vector DeviceManagerService::GetDeviceNamePrefixs() return dmServiceImplExtResident_->GetDeviceNamePrefixs(); } -void DeviceManagerService::CheckRegisterInfoWithWise() +void DeviceManagerService::HandleNetworkConnected(int32_t networkStatus) { LOGI("In"); if (!IsDMServiceAdapterResidentLoad()) { - LOGE("CheckRegisterInfoWithWise failed, adapter instance not init or init failed."); + LOGE("HandleNetworkConnected failed, adapter instance not init or init failed."); return; } - dmServiceImplExtResident_->CheckRegisterInfoWithWise(); + dmServiceImplExtResident_->HandleNetworkConnected(networkStatus); } int32_t DeviceManagerService::RestoreLocalDeviceName(const std::string &pkgName) diff --git a/services/service/src/publishcommonevent/dm_screen_common_event.cpp b/services/service/src/publishcommonevent/dm_screen_common_event.cpp index a5219b205..ce7d5ecdf 100644 --- a/services/service/src/publishcommonevent/dm_screen_common_event.cpp +++ b/services/service/src/publishcommonevent/dm_screen_common_event.cpp @@ -136,7 +136,8 @@ void DmScreenEventSubscriber::OnReceiveEvent(const CommonEventData &data) { std::string receiveEvent = data.GetWant().GetAction(); LOGI("Received screen event: %{public}s", receiveEvent.c_str()); - if (receiveEvent != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED) { + if (receiveEvent != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED && + receiveEvent != EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { return; } #if !(defined(__LITEOS_M__) || defined(LITE_DEVICE)) -- Gitee