diff --git a/services/native/include/work_sched_data_manager.h b/services/native/include/work_sched_data_manager.h index efd5d90d15b19125d6a5129044d77eacd4bcbc9b..471bf10a4749a7fc88a5e09acbba6ecf35b368fa 100644 --- a/services/native/include/work_sched_data_manager.h +++ b/services/native/include/work_sched_data_manager.h @@ -31,6 +31,9 @@ public: // device sleep void SetDeviceSleep(const bool isSleep); bool GetDeviceSleep() const; + // deep idle + void SetDeepIdle(const bool isDeepIdle); + bool GetDeepIdle() const; bool IsInDeviceStandyWhitelist(const std::string& bundleName); void OnDeviceStandyWhitelistChanged(const std::string& bundleName, const bool add); void AddDeviceStandyWhitelist(const std::list& bundleNames); @@ -48,6 +51,7 @@ public: void ClearAllGroup(); private: std::atomic deviceSleep_ = false; + std::atomic deepIdle_ = false; ffrt::mutex deviceStandySetMutex_; // std::set deviceStandySet {}; diff --git a/services/native/src/conditions/screen_listener.cpp b/services/native/src/conditions/screen_listener.cpp index 9463321f095529cc0a4a6650fbaef46ede908e70..61fb5cbe6184ad5f09dafb3f1e836d84c703e6c4 100644 --- a/services/native/src/conditions/screen_listener.cpp +++ b/services/native/src/conditions/screen_listener.cpp @@ -29,6 +29,7 @@ #include "work_sched_constants.h" #include "conditions/timer_info.h" #include "work_sched_hisysevent_report.h" +#include "work_sched_data_manager.h" namespace OHOS { namespace WorkScheduler { @@ -45,8 +46,11 @@ void ScreenEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &data return; } if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { + if (DelayedSingleton::GetInstance()->GetDeepIdle()) { + DelayedSingleton::GetInstance()->SetDeepIdle(false); + WorkSchedUtil::HiSysEventDeepIdleState(false); + } listener_.StopTimer(); - WorkSchedUtil::HiSysEventDeepIdleState(false); listener_.OnConditionChanged(WorkCondition::Type::DEEP_IDLE, std::make_shared(0, 0, false, std::string())); auto task = [weak = weak_from_this()]() { @@ -128,6 +132,7 @@ void ScreenListener::StartTimer() WS_HILOGI("deep idle timer start with time = %{public}d.", MIN_DEEP_IDLE_SCREEN_OFF_TIME_MIN); auto task = [=]() { WS_HILOGI("Into deep idle mode"); + DelayedSingleton::GetInstance()->SetDeepIdle(true); service_->HandleDeepIdleMsg(); }; auto timerInfo = std::make_shared(); diff --git a/services/native/src/work_policy_manager.cpp b/services/native/src/work_policy_manager.cpp index 848a29aaa3568704545c45c01cdf2351656ad73e..e5318040423f038b6507ce1d348f66301b69e7b1 100644 --- a/services/native/src/work_policy_manager.cpp +++ b/services/native/src/work_policy_manager.cpp @@ -664,8 +664,8 @@ void WorkPolicyManager::Dump(string& result) WorkSchedSystemPolicy systemPolicy; result.append("3. GetMaxRunningCount:"); int32_t maxRunningCount = GetMaxRunningCount(systemPolicy); - result.append(to_string(maxRunningCount) - + (maxRunningCount == MAX_RUNNING_COUNT ? "" : systemPolicy.GetInfo()) + "\n"); + result.append(to_string(maxRunningCount) + + (maxRunningCount == MAX_RUNNING_COUNT ? "" : systemPolicy.GetInfo()) + "\n"); } uint32_t WorkPolicyManager::NewWatchdogId() diff --git a/services/native/src/work_sched_data_manager.cpp b/services/native/src/work_sched_data_manager.cpp index b989a702e168e474653d11904d2d819285e876f2..4c7d4b480cd630f59377b3d399414d2244ad2be8 100644 --- a/services/native/src/work_sched_data_manager.cpp +++ b/services/native/src/work_sched_data_manager.cpp @@ -33,6 +33,16 @@ void DataManager::SetDeviceSleep(const bool isSleep) deviceSleep_ = isSleep; } +bool DataManager::GetDeepIdle() const +{ + return deepIdle_; +} + +void DataManager::SetDeepIdle(const bool isDeepIdle) +{ + deepIdle_ = isDeepIdle; +} + bool DataManager::IsInDeviceStandyWhitelist(const std::string& bundleName) { std::lock_guard lock(deviceStandySetMutex_); diff --git a/services/native/src/work_scheduler_service.cpp b/services/native/src/work_scheduler_service.cpp index b6c410a2aa8c05a22b283408c4d7bc87cde38222..5b8ee0f3834a0069cd9dff7613167d6be268f4de 100644 --- a/services/native/src/work_scheduler_service.cpp +++ b/services/native/src/work_scheduler_service.cpp @@ -415,21 +415,22 @@ void WorkSchedulerService::OnStop() { WS_HILOGI("stop service."); std::lock_guard observerLock(observerMutex_); - #ifdef DEVICE_USAGE_STATISTICS_ENABLE +#ifdef DEVICE_USAGE_STATISTICS_ENABLE DeviceUsageStats::BundleActiveClient::GetInstance().UnRegisterAppGroupCallBack(groupObserver_); groupObserver_ = nullptr; g_hasGroupObserver = -1; - #endif - #ifdef DEVICE_STANDBY_ENABLE +#endif +#ifdef DEVICE_STANDBY_ENABLE DevStandbyMgr::StandbyServiceClient::GetInstance().UnsubscribeStandbyCallback(standbyStateObserver_); standbyStateObserver_ = nullptr; - #endif - #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE +#endif +#ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE ErrCode ret = BackgroundTaskMgr::BackgroundTaskMgrHelper::UnsubscribeBackgroundTask(*subscriber_); if (ret != ERR_OK) { WS_HILOGE("unscribe bgtask failed."); + WorkSchedUtil::HiSysEventException(SERVICE_STOP, __func__, "unsubscribe background task failed"); } - #endif +#endif eventRunner_.reset(); handler_.reset(); ready_ = false; @@ -467,7 +468,7 @@ bool WorkSchedulerService::Init(const std::shared_ptr& bool WorkSchedulerService::InitBgTaskSubscriber() { - #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE +#ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE subscriber_ = make_shared(); ErrCode ret = BackgroundTaskMgr::BackgroundTaskMgrHelper::SubscribeBackgroundTask(*subscriber_); if (ret != ERR_OK) { @@ -489,6 +490,7 @@ ErrCode WorkSchedulerService::QueryResAppliedUid() ErrCode result = BackgroundTaskMgr::BackgroundTaskMgrHelper::GetEfficiencyResourcesInfos(appList, procList); if (result != ERR_OK) { WS_HILOGE("failed to GetEfficiencyResourcesInfos, errcode: %{public}d", result); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "get efficiency resources info failed"); return result; } std::lock_guard lock(whitelistMutex_); @@ -551,6 +553,7 @@ bool WorkSchedulerService::WorkPolicyManagerInit(const std::shared_ptrInit(runner)) { WS_HILOGE("work policy manager init failed!"); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "work policy manager init failed"); return false; } @@ -582,11 +585,13 @@ WEAK_FUNC bool WorkSchedulerService::GetUidByBundleName(const string &bundleName SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!systemAbilityManager) { WS_HILOGE("fail to get system ability mgr."); + WorkSchedUtil::HiSysEventException(WORK_CHECK, __func__, "fail to get system ability manager"); return false; } sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (!remoteObject) { WS_HILOGE("fail to get bundle manager proxy."); + WorkSchedUtil::HiSysEventException(WORK_CHECK, __func__, "fail to get bundle manager proxy"); return false; } sptr bundleMgr = iface_cast(remoteObject); @@ -600,6 +605,7 @@ WEAK_FUNC bool WorkSchedulerService::GetUidByBundleName(const string &bundleName return true; } WS_HILOGE("Get bundle info %{public}s failed.", bundleName.c_str()); + WorkSchedUtil::HiSysEventException(WORK_CHECK, __func__, "fail to get bundle info"); return false; } @@ -1106,11 +1112,13 @@ bool WorkSchedulerService::IsDebugApp(const std::string &bundleName) SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!systemAbilityManager) { WS_HILOGE("fail to get system ability mgr."); + WorkSchedUtil::HiSysEventException(WORK_CHECK, __func__, "fail to get system ability manager"); return false; } sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); if (!remoteObject) { WS_HILOGE("fail to get bundle manager proxy."); + WorkSchedUtil::HiSysEventException(WORK_CHECK, __func__, "fail to get bundle manager proxy"); return false; } sptr bundleMgr = iface_cast(remoteObject); @@ -1122,6 +1130,7 @@ bool WorkSchedulerService::IsDebugApp(const std::string &bundleName) return bundleInfo.applicationInfo.debug; } WS_HILOGE("Get bundle info failed."); + WorkSchedUtil::HiSysEventException(WORK_CHECK, __func__, "fail to get bundle info"); return false; } @@ -1270,6 +1279,7 @@ void WorkSchedulerService::RefreshPersistedWorks() std::string realPath; if (!WorkSchedUtils::ConvertFullPath(PERSISTED_FILE_PATH, realPath)) { WS_HILOGE("Get real path failed"); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "get real path failed"); return; } WS_HILOGD("Refresh path %{private}s", realPath.c_str()); @@ -1288,6 +1298,7 @@ int32_t WorkSchedulerService::CreateNodeDir(std::string dir) WS_HILOGD("Create directory successfully."); } else { WS_HILOGE("Fail to create directory, flag: %{public}d", flag); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "fail to create directory"); return flag; } } else { @@ -1302,12 +1313,14 @@ int32_t WorkSchedulerService::CreateNodeFile() FILE *file = fopen(PERSISTED_FILE_PATH, "w+"); if (file == nullptr) { WS_HILOGE("Fail to open file: %{private}s, errno: %{public}s", PERSISTED_FILE_PATH, strerror(errno)); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "fail to open file"); return errno; } WS_HILOGI("Open file success."); int closeResult = fclose(file); if (closeResult < 0) { WS_HILOGE("Fail to close file: %{private}s, errno: %{public}s", PERSISTED_FILE_PATH, strerror(errno)); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "fail to close file"); return errno; } } else { @@ -1340,6 +1353,7 @@ void WorkSchedulerService::InitDeviceStandyWhitelist() allowInfoArray, DevStandbyMgr::ReasonCodeEnum::REASON_APP_API); if (res != ERR_OK) { WS_HILOGE("GetAllowList fail"); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "get device standby white list failed"); return; } WS_HILOGI("allowInfoArray size is %{public}d", static_cast(allowInfoArray.size())); @@ -1360,6 +1374,7 @@ void WorkSchedulerService::InitDeviceStandyRestrictlist() DevStandbyMgr::AllowType::WORK_SCHEDULER, allowInfoArray, DevStandbyMgr::ReasonCodeEnum::REASON_APP_API); if (res != ERR_OK) { WS_HILOGE("GetRestrictlist fail"); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "get device standby restrict list failed"); return; } WS_HILOGI("restrictInfoArray size is %{public}d", static_cast(allowInfoArray.size())); @@ -1439,12 +1454,14 @@ void WorkSchedulerService::RegisterStandbyStateObserver() } standbyStateObserver_ = new (std::nothrow) WorkStandbyStateChangeCallback(workQueueManager_); if (!standbyStateObserver_) { + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "create standby state observer failed"); return; } standbyStateObserver_->SetSubscriberName(STRATEGY_NAME); ErrCode ret = DevStandbyMgr::StandbyServiceClient::GetInstance().SubscribeStandbyCallback(standbyStateObserver_); if (ret != ERR_OK) { WS_HILOGE("Subscriber standbyStateObserver_ failed."); + WorkSchedUtil::HiSysEventException(SERVICE_INIT, __func__, "subscribe standby state observer failed"); standbyStateObserver_ = nullptr; } #endif @@ -1459,6 +1476,7 @@ bool WorkSchedulerService::CheckProcessName() if (WORK_SCHED_NATIVE_OPERATE_CALLER.find(callingTokenInfo.processName) == WORK_SCHED_NATIVE_OPERATE_CALLER.end()) { WS_HILOGE("check process name illegal access to this interface; process name: %{public}s.", callingTokenInfo.processName.c_str()); + WorkSchedUtil::HiSysEventException(TOKEN_CHECK, __func__, "illegal process name"); return false; } return true; diff --git a/utils/native/include/work_sched_constants.h b/utils/native/include/work_sched_constants.h index d4766c4dc55a659904ef753379bdefc1a447f7e2..54766a185d72cf63da88f59d74ab4435309253fb 100644 --- a/utils/native/include/work_sched_constants.h +++ b/utils/native/include/work_sched_constants.h @@ -20,7 +20,7 @@ namespace OHOS { namespace WorkScheduler { // services\native\src\work_policy_manager.cpp inline constexpr int32_t MAX_RUNNING_COUNT = 3; -inline const int32_t STANDBY_MAX_RUNNING_COUNT = 2 * MAX_RUNNING_COUNT; +inline constexpr int32_t STANDBY_MAX_RUNNING_COUNT = 2 * MAX_RUNNING_COUNT; inline constexpr uint32_t MAX_WORK_COUNT_PER_UID = 10; inline constexpr int32_t DELAY_TIME_LONG = 30000; inline constexpr int32_t DELAY_TIME_SHORT = 5000; @@ -50,6 +50,9 @@ inline const std::string WATCHDOG_TIMEOUT = "WATCHDOG_TIMEOUT"; inline const std::string LOAD_WORK = "LOAD_WORK"; inline const std::string SERVICE_INIT = "SERVICE_INIT"; inline const std::string LOAD_SA = "LOAD_SA"; +inline const std::string TOKEN_CHECK = "TOKEN_CHECK"; +inline const std::string WORK_CHECK = "WORK_CHECK"; +inline const std::string SERVICE_STOP = "SERVICE_STOP"; } // namespace WorkScheduler } // namespace OHOS #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_UTILS_CONSTANTS_H \ No newline at end of file diff --git a/utils/native/include/work_sched_hisysevent_report.h b/utils/native/include/work_sched_hisysevent_report.h index 0d56f02bc87e808fc4bdc71eed94b33c593a1433..05eb90b9227fd9694443ebede08f4890b97c25b4 100644 --- a/utils/native/include/work_sched_hisysevent_report.h +++ b/utils/native/include/work_sched_hisysevent_report.h @@ -40,7 +40,7 @@ namespace WorkSchedUtil { * * @param systemPolicy The system policy limit. */ - void HiSysEventSystemPolicyLimit(WorkSchedSystemPolicy& systemPolicy); + void HiSysEventSystemPolicyLimit(const WorkSchedSystemPolicy& systemPolicy); /** * @brief Send a exception event to the system. @@ -49,7 +49,8 @@ namespace WorkSchedUtil { * @param funcName the function name of the exception. * @param exceptionInfo the exception info. */ - void HiSysEventException(const std::string& moduleName, const std::string& funcName, const std::string& exceptionInfo); + void HiSysEventException( + const std::string &moduleName, const std::string &funcName, const std::string &exceptionInfo); } // namespace WorkSchedUtil } // namespace WorkScheduler } // namespace OHOS diff --git a/utils/native/src/work_sched_hisysevent_report.cpp b/utils/native/src/work_sched_hisysevent_report.cpp index 7e12617620c7c1c93704915b68870861d0385bc4..642f72c1c9108843d94e0159f1e91c49b6b69c55 100644 --- a/utils/native/src/work_sched_hisysevent_report.cpp +++ b/utils/native/src/work_sched_hisysevent_report.cpp @@ -36,7 +36,7 @@ void HiSysEventDeviceStandbyState(bool deviceStandbyState) "DEVICE_STANDBY_STATE", HiviewDFX::HiSysEvent::EventType::STATISTIC, "STATE", deviceStandbyState); } -void HiSysEventSystemPolicyLimit(WorkSchedSystemPolicy& systemPolicy) +void HiSysEventSystemPolicyLimit(const WorkSchedSystemPolicy& systemPolicy) { HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::WORK_SCHEDULER, "SYSTEM_POLICY_LIMIT", HiviewDFX::HiSysEvent::EventType::STATISTIC, "POLICY", systemPolicy.GetInfo());