From a85b5b1923f7dfb0dbcaf6bb6264fe1cc792b2ea Mon Sep 17 00:00:00 2001 From: guoyi Date: Thu, 29 May 2025 14:56:48 +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 | 52 ++++++++++++---- .../service/include/device_manager_service.h | 2 +- .../service/src/device_manager_service.cpp | 16 +++-- .../dm_screen_common_event.cpp | 3 +- 11 files changed, 102 insertions(+), 98 deletions(-) diff --git a/common/include/dm_error_type.h b/common/include/dm_error_type.h index 1c5128cef..a22dffc64 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 cfe782f52..0b9578252 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 @@ -102,7 +102,7 @@ public: virtual int32_t PutDeviceProfileInfoList(const std::string &pkgName, const std::vector &deviceProfileInfoList) = 0; virtual std::vector GetDeviceNamePrefixs() = 0; - virtual void HandleNetworkConnected() = 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; @@ -110,6 +110,7 @@ public: std::vector &dmDeviceProfileInfos) = 0; virtual int32_t RestoreLocalDeviceName() = 0; virtual void ClearCacheWhenLogout(int32_t userId, const std::string &oldAccountId) = 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 2b7ac8049..39a229cc8 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); void UnRegisterPinHolderCallback(const std::string &pkgName); 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 c0fb5e3b4..1d5e00c6f 100644 --- a/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp +++ b/interfaces/inner_kits/native_cpp/src/device_manager_impl.cpp @@ -2612,13 +2612,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"); @@ -2643,16 +2644,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; } @@ -2787,7 +2796,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; @@ -2805,13 +2814,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"); @@ -2821,7 +2830,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; @@ -2840,13 +2849,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 b12abce24..ac2d02da1 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 @@ -1261,20 +1261,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) { @@ -1307,7 +1299,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()) { @@ -1316,31 +1308,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) { @@ -1388,20 +1365,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) { @@ -1409,7 +1378,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()) { @@ -1418,28 +1387,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 d9092f571..6148bbc94 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) { @@ -2000,12 +2013,12 @@ 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); + 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 nullptr"); + LOGE("jsCallback->deferred is null"); } } napi_delete_async_work(env, jsCallback->asyncWork); @@ -2167,9 +2180,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 +2481,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 +2527,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 +2969,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 +3019,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 +3068,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 bd88a76f2..da3023d9a 100644 --- a/services/service/include/device_manager_service.h +++ b/services/service/include/device_manager_service.h @@ -410,7 +410,7 @@ private: #endif // SUPPORT_BLUETOOTH SUPPORT_WIFI DM_EXPORT void SubscribeDataShareCommonEvent(); #endif - void HandleNetworkConnected(); + void HandleNetworkConnected(int32_t networkStatus); void NotifyRemoteLocalLogout(const std::vector &peerUdids, const std::string &accountIdHash, const std::string &accountName, int32_t userId); void CheckPermission(bool &isOnlyShowNetworkId); diff --git a/services/service/src/device_manager_service.cpp b/services/service/src/device_manager_service.cpp index d1b9d1e50..78277327a 100644 --- a/services/service/src/device_manager_service.cpp +++ b/services/service/src/device_manager_service.cpp @@ -73,7 +73,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; @@ -188,8 +187,8 @@ DM_EXPORT void DeviceManagerService::SubscribeDataShareCommonEvent() if (arg1 == CommonEventSupport::COMMON_EVENT_LOCALE_CHANGED) { DeviceNameManager::GetInstance().InitDeviceNameWhenLanguageOrRegionChanged(); } - if (arg1 == CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE && arg2 == NETWORK_AVAILABLE) { - this->HandleNetworkConnected(); + if (arg1 == CommonEventSupport::COMMON_EVENT_CONNECTIVITY_CHANGE) { + this->HandleNetworkConnected(arg2); } }; std::vector commonEventVec; @@ -2004,6 +2003,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"); } @@ -2699,6 +2699,12 @@ void DeviceManagerService::ProcessCommonUserStatusEvent(const std::vectorHandleScreenLockEvent(isLock); + } else { + LOGE("ScreenCommonEventCallback failed, dmServiceImplExtResident not init or init failed."); + } if (!IsDMImplSoLoaded()) { LOGE("ScreenCommonEventCallback failed, instance not init or init failed."); return; @@ -4007,14 +4013,14 @@ std::vector DeviceManagerService::GetDeviceNamePrefixs() return dmServiceImplExtResident_->GetDeviceNamePrefixs(); } -void DeviceManagerService::HandleNetworkConnected() +void DeviceManagerService::HandleNetworkConnected(int32_t networkStatus) { LOGI("In"); if (!IsDMServiceAdapterResidentLoad()) { LOGE("HandleNetworkConnected failed, adapter instance not init or init failed."); return; } - dmServiceImplExtResident_->HandleNetworkConnected(); + 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