diff --git a/display/@ohos.distributedHardware.deviceManager.d.ts b/display/@ohos.distributedHardware.deviceManager.d.ts index 69179ba17e203845da9658da477386deed0167ee..d00376306a92181187afa2623d4f18fff21648cd 100644 --- a/display/@ohos.distributedHardware.deviceManager.d.ts +++ b/display/@ohos.distributedHardware.deviceManager.d.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Huawei Device Co., Ltd. + * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h b/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h index d2975263ac10e4d43744466ba7e1a9543709a7d2..c0be7ad119c887234ef30dee4e85366ee6f9042a 100644 --- a/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h +++ b/ext/mini/interfaces_mini/kits/js/include/dm_native_event.h @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// + #ifndef OHOS_DEVICE_MANAGER_NATIVE_EVENT_H #define OHOS_DEVICE_MANAGER_NATIVE_EVENT_H diff --git a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp index 50686dfb69f2650e75f51eff73cd4466dc77da4c..e90ff6dcb04682a236380d3dd75e1ffe1d3dd649 100644 --- a/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp +++ b/ext/mini/interfaces_mini/kits/js/src/native_devicemanager_js.cpp @@ -549,7 +549,7 @@ void DeviceManagerModule::JsToDmBuffer(const JSIValue &object, } *bufferPtr = (uint8_t*)calloc(sizeof(uint8_t), length); if (*bufferPtr == nullptr) { - DMLOG(DM_LOG_ERROR, "low memory, calloc return nullptr, length is %d, filed %s", length, fieldStr.c_str()); + DMLOG(DM_LOG_ERROR, "low memory, calloc return nullptr, length is %zu, filed %s", length, fieldStr.c_str()); return; } if (memcpy_s(*bufferPtr, length, data, length) != 0) { diff --git a/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp b/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp index 472831899564ac47325d82d36e1a0d4c71296e3f..69143cada59c7de41f2db6d12482b737e6f15deb 100644 --- a/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp +++ b/ext/mini/services/devicemanagerservice/src/ability/standard/dm_ability_manager.cpp @@ -72,7 +72,7 @@ AbilityStatus DmAbilityManager::StartAbility(AbilityRole role) if (result == OHOS::ERR_OK) { DMLOG(DM_LOG_INFO, "Start Ability succeed"); } else { - DMLOG(DM_LOG_INFO, "Start Ability faild"); + DMLOG(DM_LOG_INFO, "Start Ability failed"); mStatus_ = AbilityStatus::ABILITY_STATUS_FAILED; return mStatus_; } diff --git a/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp b/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp index 5e867efa0ec262079982225a2517ee10303d8a5a..6fed5fda6aeef49d8d97627ad104642eed779591 100644 --- a/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp +++ b/ext/mini/services/devicemanagerservice/src/auth/hichain_connector.cpp @@ -141,7 +141,7 @@ int32_t HichainConnector::CreateGroup(int64_t requestId, const std::string &grou ret = deviceGroupManager_->createGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), jsonObj.dump().c_str()); if (ret != 0) { - DMLOG(DM_LOG_ERROR, "Faild to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId); + DMLOG(DM_LOG_ERROR, "Failed to start CreateGroup task, ret: %d, requestId %lld.", ret, requestId); return ret; } @@ -176,12 +176,12 @@ int32_t HichainConnector::GetGroupInfo(std::string queryParams, std::vectorgetGroupInfo(userId, DEVICE_MANAGER_APP.c_str(), queryParams.c_str(), &groupVec, &num); if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo faild , ret: %d.", ret); + DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo failed , ret: %d.", ret); return false; } if (groupVec == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo faild , returnGroups is nullptr"); + DMLOG(DM_LOG_ERROR, "HichainConnector::GetGroupInfo failed , returnGroups is nullptr"); return false; } @@ -333,12 +333,12 @@ void HichainConnector::GetRelatedGroups(std::string deviceId, std::vectorgetRelatedGroups(userId, DEVICE_MANAGER_APP.c_str(), deviceId.c_str(), &returnGroups, &groupNum); if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups faild , ret: %d.", ret); + DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups failed , ret: %d.", ret); return; } if (returnGroups == nullptr) { - DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups faild , returnGroups is nullptr"); + DMLOG(DM_LOG_ERROR, "HichainConnector::GetRelatedGroups failed , returnGroups is nullptr"); return; } @@ -422,7 +422,7 @@ int32_t HichainConnector::DelMemberFromGroup(std::string groupId, std::string de int32_t ret = deviceGroupManager_->deleteMemberFromGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), deleteParams.c_str()); if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::DelMemberFromGroup faild , ret: %d.", ret); + DMLOG(DM_LOG_ERROR, "HichainConnector::DelMemberFromGroup failed , ret: %d.", ret); return ret; } return 0; @@ -443,7 +443,7 @@ void HichainConnector::DeleteGroup(std::string &groupId) ret = deviceGroupManager_->deleteGroup(userId, requestId, DEVICE_MANAGER_APP.c_str(), disbandParams.c_str()); if (ret != 0) { - DMLOG(DM_LOG_ERROR, "HichainConnector::DeleteGroup faild , ret: %d.", ret); + DMLOG(DM_LOG_ERROR, "HichainConnector::DeleteGroup failed , ret: %d.", ret); } } diff --git a/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp b/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp index bb83afe69afccda47b79bc2c31195edda7a83ddc..33c73579028db98a975e9d952582e35bf5d89f2a 100644 --- a/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp +++ b/ext/mini/services/devicemanagerservice/src/dispatch/server_stub.cpp @@ -57,7 +57,7 @@ static const char *GetName(Service *service) static BOOL Initialize(Service *service, Identity identity) { - if (service == NULL) { + if (service == nullptr) { DMLOG(DM_LOG_WARN, "invalid param"); return FALSE; } @@ -71,7 +71,7 @@ static BOOL Initialize(Service *service, Identity identity) static BOOL MessageHandle(Service *service, Request *request) { - if ((service == NULL) || (request == NULL)) { + if ((service == nullptr) || (request == nullptr)) { DMLOG(DM_LOG_WARN, "invalid param"); return FALSE; } @@ -85,9 +85,6 @@ static TaskConfig GetTaskConfig(Service *service) return config; } - - - static void DevMgrSvcInit(void) { sleep(WAIT_FOR_SERVER); @@ -96,9 +93,6 @@ static void DevMgrSvcInit(void) .Initialize = Initialize, .MessageHandle = MessageHandle, .GetTaskConfig = GetTaskConfig, - // SERVER_IPROXY_IMPL_BEGIN, - // .Invoke = OnRemoteRequest, - // IPROXY_END, }; if (!SAMGR_GetInstance()->RegisterService((Service *)&service)) { diff --git a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp index e1a881b907105d52639c356acd1a7d089b6d44e4..659df2210b1cf166c26ee0d81de933d5e19c1ecc 100644 --- a/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp +++ b/interfaces/inner_kits/native_cpp/src/ipc/lite/ipc_cmd_parser.cpp @@ -229,7 +229,7 @@ ON_IPC_CMD(SERVER_DEVICE_STATE_NOTIFY, IpcIo &reply) DmDeviceState deviceState = static_cast(IpcIoPopInt32(&reply)); uint32_t size; const DmDeviceInfo *deviceInfo = (const DmDeviceInfo *)IpcIoPopFlatObj(&reply, &size); - if (pkgName == "" || len == 0 || deviceInfo == NULL) { + if (pkgName == "" || len == 0 || deviceInfo == nullptr) { LOGE("OnDeviceOnline, get para failed"); return; } @@ -256,7 +256,7 @@ ON_IPC_CMD(SERVER_DEVICE_FOUND, IpcIo &reply) uint16_t subscribeId = IpcIoPopUint16(&reply); uint32_t size; const DmDeviceInfo *deviceInfo = (const DmDeviceInfo *)IpcIoPopFlatObj(&reply, &size); - if (pkgName == "" || len == 0 || deviceInfo == NULL) { + if (pkgName == "" || len == 0 || deviceInfo == nullptr) { LOGE("OnDeviceChanged, get para failed"); return; } 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 aa022b55ff41fe7406d413450cf61aa6a349bc9a..855de3b704ae1b2920c31fb142d63a8ad720595f 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 @@ -25,7 +25,7 @@ namespace OHOS { namespace DistributedHardware { int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - LOGI("code = %d, flags= %d.", code, option.GetFlags()); + LOGI("code = %u, flags= %d.", code, option.GetFlags()); auto remoteDescriptor = data.ReadInterfaceToken(); if (GetDescriptor() != remoteDescriptor) { LOGI("ReadInterfaceToken fail!"); @@ -36,7 +36,7 @@ int32_t IpcClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Messa LOGE("on ipc cmd success"); return DM_OK; } - LOGW("unsupport code: %d", code); + LOGW("unsupport code: %u", code); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } 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 9d68e364fe5bc24852ebf5b925a5963f56a94b6b..89c945640ee3ad38c14ed9f238d1f71f4cbac253 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 @@ -238,7 +238,7 @@ void DeviceManagerNotify::OnDiscoverySuccess(const std::string &pkgName, uint16_ void DeviceManagerNotify::OnAuthResult(const std::string &pkgName, const std::string &deviceId, const std::string &token, uint32_t status, uint32_t reason) { - LOGI("DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%d", pkgName.c_str(), status, reason); + LOGI("DeviceManagerNotify::OnAuthResult pkgName:%s, status:%d, reason:%u", pkgName.c_str(), status, reason); std::lock_guard autoLock(lock_); if (authenticateCallback_.count(pkgName) == 0) { LOGE("DeviceManager OnAuthResult: no register authCallback for this package"); diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp index dd4afeb86adcd5c1bd8604daf978477f2b0bf78e..b2a5bdfc17ac556048689c8f567b186b21d451fb 100644 --- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp +++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp @@ -161,7 +161,7 @@ int32_t HiChainConnector::GetGroupInfo(std::string queryParams, std::vectordestroyInfo(&groupVec); nlohmann::json jsonObject = nlohmann::json::parse(relatedGroups); @@ -188,7 +188,7 @@ int32_t HiChainConnector::GetGroupInfo(const int32_t userId, std::string queryPa return false; } if (groupVec == nullptr) { - LOGE("HiChainConnector::GetGroupInfo failed , returnGroups is nullptr"); + LOGE("HiChainConnector::GetGroupInfo failed , returnGroups is nullptr."); return false; } if (num == 0) { diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index c4f95b94eb19988f25a217d2235ed957075fa25a..0dadbdf98216742db8862d53e9589e3fae6427cc 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -126,9 +126,8 @@ int32_t DmTimer::CreateTimeFd() return DM_STATUS_FINISH; } LOGI("DmTimer %s creatTimeFd", mTimerName_.c_str()); - int ret = 0; - ret = pipe(mTimeFd_); + int ret = pipe(mTimeFd_); if (ret < 0) { LOGE("DmTimer %s CreateTimeFd fail:(%d) errno(%d)", mTimerName_.c_str(), ret, errno); return ret; diff --git a/services/devicemanagerservice/src/device_manager_service_listener.cpp b/services/devicemanagerservice/src/device_manager_service_listener.cpp index 432481830ed686ee0e793095c630780c4c82025b..c7f53eee4f9c6b9d2b47ed5ce55d383c8457d46c 100644 --- a/services/devicemanagerservice/src/device_manager_service_listener.cpp +++ b/services/devicemanagerservice/src/device_manager_service_listener.cpp @@ -46,7 +46,7 @@ void DeviceManagerServiceListener::OnDeviceStateChange(const std::string &pkgNam void DeviceManagerServiceListener::OnDeviceFound(const std::string &pkgName, uint16_t subscribeId, const DmDeviceInfo &info) { - LOGI("call OnDeviceFound for %s, originId %d, deviceId %s", pkgName.c_str(), subscribeId, + LOGI("call OnDeviceFound for %s, originId %hu, deviceId %s", pkgName.c_str(), subscribeId, GetAnonyString(std::string(info.deviceId)).c_str()); std::shared_ptr pReq = std::make_shared(); std::shared_ptr pRsp = std::make_shared(); diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index f4f0d6837a9f3784a93a4392537db9714e879555..4942143390f1bdc5e34e76b397bdd4ad77ae5950 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -27,7 +27,7 @@ const int32_t SESSION_CANCEL_TIMEOUT = 0; static void TimeOut(void *data, DmTimer& timer) { - LOGE("time out "); + LOGE("time out"); DmDiscoveryManager *discoveryMgr = (DmDiscoveryManager *)data; if (discoveryMgr == nullptr) { LOGE("time out error"); diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp index e4373c2ad2fcc52596c318129d31308bab2a0bf5..18258ff4faa9aa9d0d183dbf6085d1c041278913 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_main.cpp @@ -20,7 +20,7 @@ int32_t main(int32_t argc, char *argv[]) { (void)argc; (void)argv; - while (1) { + while (true) { pause(); } return 0; diff --git a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp index 1a09f1cb6a15df237dab7c1b785d4cf4ea4e645e..ebdc8241ac1fbffd4abb907e8c525c0feadd6724 100644 --- a/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/lite/ipc_server_stub.cpp @@ -51,7 +51,7 @@ static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, voi (void)context; (void)ipcMsg; (void)data; - if (arg == NULL) { + if (arg == nullptr) { LOGE("package name is NULL."); return DM_INVALID_VALUE; } @@ -60,12 +60,12 @@ static int32_t DeathCb(const IpcContext *context, void *ipcMsg, IpcIo *data, voi if (IpcServerListenermgr::GetInstance().GetListenerByPkgName(pkgName, &svcId) != DM_OK) { LOGE("not found client by package name."); free(arg); - arg = NULL; + arg = nullptr; return DM_FAILED; } IpcServerListenermgr::GetInstance().UnregisterListener(pkgName); free(arg); - arg = NULL; + arg = nullptr; #ifdef __LINUX__ BinderRelease(svcId.ipcCtx, svcId.handle); #endif @@ -83,7 +83,7 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) size_t len = 0; uint8_t *name = IpcIoPopString(req, &len); SvcIdentity *svc = IpcIoPopSvc(req); - if (name == NULL || svc == NULL || len == 0) { + if (name == nullptr || svc == nullptr || len == 0) { LOGE("get para failed"); return DM_INVALID_VALUE; } @@ -98,7 +98,7 @@ int32_t RegisterDeviceManagerListener(IpcIo *req, IpcIo *reply) svcId.ipcCtx = svc->ipcContext; BinderAcquire(svcId.ipcCtx, svcId.handle); free(svc); - svc = NULL; + svc = nullptr; #endif if (len == 0 || len > MALLOC_MAX_LEN) { LOGE("malloc length invalid!"); @@ -157,7 +157,7 @@ static const char *GetName(Service *service) static BOOL Initialize(Service *service, Identity identity) { - if (service == NULL) { + if (service == nullptr) { LOGW("invalid param"); return FALSE; } @@ -169,7 +169,7 @@ static BOOL Initialize(Service *service, Identity identity) static BOOL MessageHandle(Service *service, Request *request) { - if ((service == NULL) || (request == NULL)) { + if ((service == nullptr) || (request == nullptr)) { LOGW("invalid param"); return FALSE; } diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp index 42654f175cfe3560a2a5f6756767181bbebeecb5..3feaaadf8b3db4775df3409972bdb386876f1385 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_cmd_parser.cpp @@ -108,6 +108,10 @@ ON_IPC_SET_REQUEST(SERVER_DISCOVER_FINISH, std::shared_ptr pBaseReq, Mes ON_IPC_READ_RESPONSE(SERVER_DISCOVER_FINISH, MessageParcel &reply, std::shared_ptr pBaseRsp) { + if (pBaseRsp == nullptr) { + LOGE("pBaseRsp is null"); + return DM_FAILED; + } pBaseRsp->SetErrCode(reply.ReadInt32()); return DM_OK; } diff --git a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp index 30f37fc6bf28db25333fcd537c218bbb4c3e1a9d..762ff63ea5f8231b3f70e41850974bb854bd7cc6 100644 --- a/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp +++ b/services/devicemanagerservice/src/ipc/standard/ipc_server_stub.cpp @@ -80,7 +80,7 @@ void IpcServerStub::OnStop() int32_t IpcServerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - LOGI("code = %d, flags= %d.", code, option.GetFlags()); + LOGI("code = %u, flags= %d.", code, option.GetFlags()); auto remoteDescriptor = data.ReadInterfaceToken(); if (GetDescriptor() != remoteDescriptor) { LOGI("ReadInterfaceToken fail!"); diff --git a/utils/src/dm_random.cpp b/utils/src/dm_random.cpp index 7a1d6a71647d23aa10ee0aa9dbb73d311e54ecf9..738d33442b8fc5e255af979ef9ee3f16588698d8 100644 --- a/utils/src/dm_random.cpp +++ b/utils/src/dm_random.cpp @@ -70,7 +70,7 @@ int32_t GetRandomData(uint8_t *randStr, uint32_t len) break; } ret = DM_OK; - } while (0); + } while (false); if (entropy != nullptr) { free(entropy); } @@ -91,9 +91,9 @@ bool MbedtlsGenRandomStr(char *szOut, int32_t szOutLen, bool numberOnly) const int32_t NUMBER_COUNT = 10; const int32_t ALPHA_COUNT = 26; const int32_t ALPHA_BYTE_COUNT = 2; - int32_t M = numberOnly ? NUMBER_COUNT : (NUMBER_COUNT + ALPHA_BYTE_COUNT * ALPHA_COUNT); + int32_t tmpNum = numberOnly ? NUMBER_COUNT : (NUMBER_COUNT + ALPHA_BYTE_COUNT * ALPHA_COUNT); for (int32_t i = 0; i < szOutLen; i++) { - uint32_t idx = ((uint32_t)szOut[i] % M); + uint32_t idx = ((uint32_t)szOut[i] % tmpNum); char base; if (idx < NUMBER_COUNT) { base = '0';