diff --git a/frameworks/native/source/system_ability_manager_proxy.cpp b/frameworks/native/source/system_ability_manager_proxy.cpp index 77d70dbf9bc3474065d19ff556e1358207ac6c72..fe9d1c0d66b350faa3d3ba991b0c133e45a4203a 100644 --- a/frameworks/native/source/system_ability_manager_proxy.cpp +++ b/frameworks/native/source/system_ability_manager_proxy.cpp @@ -176,24 +176,15 @@ sptr SystemAbilityManagerProxy::GetSystemAbilityWrapper(int32_t s HILOGD("GetSaWrap:Waiting for SA:%{public}d, ", systemAbilityId); do { sptr svc; - int32_t errCode = ERR_NONE; if (deviceId.empty()) { - svc = CheckSystemAbility(systemAbilityId, isExist, errCode); - if (errCode == ERR_PERMISSION_DENIED) { - HILOGE("GetSaWrap SA:%{public}d selinux denied", systemAbilityId); - return nullptr; - } + svc = CheckSystemAbility(systemAbilityId, isExist); if (!isExist) { HILOGD("%{public}s:SA:%{public}d is not exist", __func__, systemAbilityId); usleep(SLEEP_ONE_MILLI_SECOND_TIME * SLEEP_INTERVAL_TIME); continue; } } else { - svc = CheckSystemAbility(systemAbilityId, deviceId, errCode); - if (errCode == ERR_PERMISSION_DENIED) { - HILOGE("GetSaWrap SA:%{public}d deviceId selinux denied", systemAbilityId); - return nullptr; - } + svc = CheckSystemAbility(systemAbilityId, deviceId); } if (svc != nullptr) { @@ -206,13 +197,6 @@ sptr SystemAbilityManagerProxy::GetSystemAbilityWrapper(int32_t s } sptr SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t code, MessageParcel& data) -{ - int32_t errCode = ERR_NONE; - return CheckSystemAbilityWrapper(code, data, errCode); -} - -sptr SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t code, MessageParcel& data, - int32_t& errCode) { auto remote = Remote(); if (remote == nullptr) { @@ -223,7 +207,6 @@ sptr SystemAbilityManagerProxy::CheckSystemAbilityWrapper(int32_t MessageOption option; int32_t err = remote->SendRequest(code, data, reply, option); if (err != ERR_NONE) { - errCode = err; return nullptr; } return reply.ReadRemoteObject(); @@ -264,13 +247,6 @@ sptr SystemAbilityManagerProxy::CheckSystemAbilityTransaction(int } sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId) -{ - int32_t errCode = ERR_NONE; - return CheckSystemAbility(systemAbilityId, deviceId, errCode); -} - -sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId, - int32_t& errCode) { if (!CheckInputSysAbilityId(systemAbilityId) || deviceId.empty()) { HILOGW("CheckSystemAbility:SA:%{public}d or deviceId is nullptr.", systemAbilityId); @@ -301,16 +277,10 @@ sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t system } return CheckSystemAbilityWrapper( - static_cast(SamgrInterfaceCode::CHECK_REMOTE_SYSTEM_ABILITY_TRANSACTION), data, errCode); + static_cast(SamgrInterfaceCode::CHECK_REMOTE_SYSTEM_ABILITY_TRANSACTION), data); } sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, bool& isExist) -{ - int32_t errCode = ERR_NONE; - return CheckSystemAbility(systemAbilityId, isExist, errCode); -} -sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t systemAbilityId, bool& isExist, - int32_t& errCode) { HILOGD("%{public}s called, SA:%{public}d, isExist is %{public}d", __func__, systemAbilityId, isExist); if (!CheckInputSysAbilityId(systemAbilityId)) { @@ -351,7 +321,6 @@ sptr SystemAbilityManagerProxy::CheckSystemAbility(int32_t system int32_t err = remote->SendRequest( static_cast(SamgrInterfaceCode::CHECK_SYSTEM_ABILITY_IMMEDIATELY_TRANSACTION), data, reply, option); if (err != ERR_NONE) { - errCode = err; return nullptr; } diff --git a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h index 4fd0e79af80e2010d5064b45c235ba81d2cce6ed..34b7f266b9a06365cb04ebad9a7fc71cc533811b 100644 --- a/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h +++ b/interfaces/innerkits/samgr_proxy/include/system_ability_manager_proxy.h @@ -268,9 +268,6 @@ public: private: sptr GetSystemAbilityWrapper(int32_t systemAbilityId, const std::string& deviceId = ""); sptr CheckSystemAbilityWrapper(int32_t code, MessageParcel& data); - sptr CheckSystemAbilityWrapper(int32_t code, MessageParcel& data, int32_t& errCode); - sptr CheckSystemAbility(int32_t systemAbilityId, const std::string& deviceId, int32_t& errCode); - sptr CheckSystemAbility(int32_t systemAbilityId, bool& isExist, int32_t& errCode); int32_t MarshalSAExtraProp(const SAExtraProp& extraProp, MessageParcel& data) const; int32_t AddSystemAbilityWrapper(int32_t code, MessageParcel& data); int32_t RemoveSystemAbilityWrapper(int32_t code, MessageParcel& data); diff --git a/services/samgr/native/source/collect/common_event_collect.cpp b/services/samgr/native/source/collect/common_event_collect.cpp index d36972d66be0d12ba7e59f8710cab54b7d21eef1..9efe345bb9eb7197f68a5162e2585f65bc88072a 100644 --- a/services/samgr/native/source/collect/common_event_collect.cpp +++ b/services/samgr/native/source/collect/common_event_collect.cpp @@ -571,22 +571,19 @@ CommonEventSubscriber::CommonEventSubscriber(const EventFwk::CommonEventSubscrib void CommonEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& data) { - auto OnReceiveTask = [=] () { - std::string action = data.GetWant().GetAction(); - int32_t code = data.GetCode(); - auto collect = collect_.promote(); - if (collect == nullptr) { - HILOGE("CommonEventCollect collect is nullptr"); - return; - } - collect->SaveAction(action); - int64_t extraDataId = collect->SaveOnDemandReasonExtraData(data); - HILOGI("OnReceiveEvent get action: %{public}s code: %{public}d, extraDataId %{public}d", - action.c_str(), code, static_cast(extraDataId)); - collect->SaveOnDemandConditionExtraData(data); - OnDemandEvent event = {COMMON_EVENT, action, std::to_string(code), extraDataId}; - collect->ReportEvent(event); - }; - ffrt::submit(OnReceiveTask); + std::string action = data.GetWant().GetAction(); + int32_t code = data.GetCode(); + auto collect = collect_.promote(); + if (collect == nullptr) { + HILOGE("CommonEventCollect collect is nullptr"); + return; + } + collect->SaveAction(action); + int64_t extraDataId = collect->SaveOnDemandReasonExtraData(data); + HILOGI("OnReceiveEvent get action: %{public}s code: %{public}d, extraDataId %{public}d", + action.c_str(), code, static_cast(extraDataId)); + collect->SaveOnDemandConditionExtraData(data); + OnDemandEvent event = {COMMON_EVENT, action, std::to_string(code), extraDataId}; + collect->ReportEvent(event); } } // namespace OHOS \ No newline at end of file diff --git a/services/samgr/native/source/collect/device_status_collect_manager.cpp b/services/samgr/native/source/collect/device_status_collect_manager.cpp index e386faee057a002935ad5779c60403c050eaa697..d273189bc888cf7ccb529ca073bf1f28493dce89 100644 --- a/services/samgr/native/source/collect/device_status_collect_manager.cpp +++ b/services/samgr/native/source/collect/device_status_collect_manager.cpp @@ -274,18 +274,18 @@ void DeviceStatusCollectManager::ReportEvent(const OnDemandEvent& event) HILOGW("DeviceStaMgr collectHandler_ is nullptr"); return; } - std::list saControlList; - GetSaControlListByEvent(event, saControlList); - GetSaControlListByPersistEvent(event, saControlList); - SortSaControlListByLoadPriority(saControlList); - if (saControlList.empty()) { - HILOGD("DeviceStaMgr no matched event"); - if (event.eventId == DEVICE_ONLINE) { - HILOGI("deviceOnline is empty"); + auto callback = [event, this] () { + std::list saControlList; + GetSaControlListByEvent(event, saControlList); + GetSaControlListByPersistEvent(event, saControlList); + SortSaControlListByLoadPriority(saControlList); + if (saControlList.empty()) { + HILOGD("DeviceStaMgr no matched event"); + if (event.eventId == DEVICE_ONLINE) { + HILOGI("deviceOnline is empty"); + } + return; } - return; - } - auto callback = [event, saControlList = std::move(saControlList)] () { SystemAbilityManager::GetInstance()->ProcessOnDemandEvent(event, saControlList); }; collectHandler_->PostTask(callback); @@ -542,28 +542,31 @@ int32_t DeviceStatusCollectManager::UpdateOnDemandEvents(int32_t systemAbilityId const std::vector& events) { HILOGI("UpdateOnDemandEvents begin"); - std::unique_lock writeLock(saProfilesLock_); - auto iter = std::find_if(onDemandSaProfiles_.begin(), onDemandSaProfiles_.end(), [systemAbilityId](auto saProfile) { - return saProfile.saId == systemAbilityId; - }); - if (iter == onDemandSaProfiles_.end()) { - HILOGI("UpdateOnDemandEvents invalid saId:%{public}d", systemAbilityId); - return ERR_INVALID_VALUE; - } - if (AddCollectEvents(events) != ERR_OK) { - HILOGI("AddCollectEvents failed saId:%{public}d", systemAbilityId); - return ERR_INVALID_VALUE; - } std::vector oldEvents; - if (type == OnDemandPolicyType::START_POLICY) { - oldEvents = (*iter).startOnDemand.onDemandEvents; - (*iter).startOnDemand.onDemandEvents = events; - } else if (type == OnDemandPolicyType::STOP_POLICY) { - oldEvents = (*iter).stopOnDemand.onDemandEvents; - (*iter).stopOnDemand.onDemandEvents = events; - } else { - HILOGE("UpdateOnDemandEvents policy types"); - return ERR_INVALID_VALUE; + { + std::unique_lock writeLock(saProfilesLock_); + auto iter = std::find_if(onDemandSaProfiles_.begin(), onDemandSaProfiles_.end(), + [systemAbilityId](auto saProfile) { + return saProfile.saId == systemAbilityId; + }); + if (iter == onDemandSaProfiles_.end()) { + HILOGI("UpdateOnDemandEvents invalid saId:%{public}d", systemAbilityId); + return ERR_INVALID_VALUE; + } + if (AddCollectEvents(events) != ERR_OK) { + HILOGI("AddCollectEvents failed saId:%{public}d", systemAbilityId); + return ERR_INVALID_VALUE; + } + if (type == OnDemandPolicyType::START_POLICY) { + oldEvents = (*iter).startOnDemand.onDemandEvents; + (*iter).startOnDemand.onDemandEvents = events; + } else if (type == OnDemandPolicyType::STOP_POLICY) { + oldEvents = (*iter).stopOnDemand.onDemandEvents; + (*iter).stopOnDemand.onDemandEvents = events; + } else { + HILOGE("UpdateOnDemandEvents policy types"); + return ERR_INVALID_VALUE; + } } PersistOnDemandEvent(systemAbilityId, type, events); if (RemoveUnusedEventsLocked(oldEvents) != ERR_OK) { diff --git a/services/samgr/native/source/ffrt_handler.cpp b/services/samgr/native/source/ffrt_handler.cpp index 425693f1add53c674965ae33a85c41028ddc176a..866605e5dba3768618d83494cda11b4ebbf1b1e8 100644 --- a/services/samgr/native/source/ffrt_handler.cpp +++ b/services/samgr/native/source/ffrt_handler.cpp @@ -56,7 +56,6 @@ void FFRTHandler::SetFfrt(const std::string& name) bool FFRTHandler::PostTask(std::function func) { - std::unique_lock lock(mutex_); task_handle handler = queue_->submit_h(func); if (handler == nullptr) { HILOGE("FFRTHandler post task failed"); @@ -71,7 +70,6 @@ bool FFRTHandler::PostTask(std::function func, uint64_t delayTime) HILOGE("invalid delay time"); return false; } - std::unique_lock lock(mutex_); task_handle handler = queue_->submit_h(func, task_attr().delay(delayTime * CONVERSION_FACTOR)); if (handler == nullptr) { HILOGE("FFRTHandler post task failed");