From 3c5fb381af711f3d1f45e92f945c3d97906343e8 Mon Sep 17 00:00:00 2001 From: oh_ci Date: Mon, 1 Sep 2025 00:37:17 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!609=20:?= =?UTF-8?q?=20=E5=BB=B6=E8=BF=9F=E4=BB=BB=E5=8A=A1=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=85=85=E7=94=B5&=E5=BA=94=E7=94=A8=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=A7=A6=E5=8F=91=E9=97=B4=E9=9A=94'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/native/include/work_status.h | 25 ----- services/native/src/work_status.cpp | 134 +++----------------------- 2 files changed, 11 insertions(+), 148 deletions(-) diff --git a/services/native/include/work_status.h b/services/native/include/work_status.h index c008126..04c9c36 100644 --- a/services/native/include/work_status.h +++ b/services/native/include/work_status.h @@ -180,31 +180,6 @@ public: * @brief get min interval. */ int64_t GetMinInterval(); - /** - * @brief Judge whether the app is a mail application. - * - * @return True if the app is a mail app, false otherwise. - */ - bool IsMailApp(); - /** - * @brief Judge whether the device is currently charging. - * - * @return True if the device is charging, false otherwise. - */ - bool IsChargingState(); - /** - * @brief Set min interval when charging. - * - * @param group The new group. - */ - void SetMinIntervalWhenCharging(int32_t group); - /** - * @brief Set min interval when not charging. - * - * @param group The new group. - */ - void SetMinIntervalWhenNotCharging(int32_t group); - bool IsUriKeySwitchOn(); void ToString(WorkCondition::Type conditionType); void HasTimeout(); diff --git a/services/native/src/work_status.cpp b/services/native/src/work_status.cpp index 23ac3c8..fef833f 100644 --- a/services/native/src/work_status.cpp +++ b/services/native/src/work_status.cpp @@ -24,7 +24,7 @@ #include "work_sched_errors.h" #ifdef DEVICE_USAGE_STATISTICS_ENABLE #include "bundle_active_client.h" -#include "bundle_active_group_common.h" +#include "bundle_active_group_map.h" #endif #include "parameters.h" #include "work_sched_data_manager.h" @@ -32,11 +32,6 @@ #include "work_sched_constants.h" #include #include -#ifdef POWERMGR_BATTERY_MANAGER_ENABLE -#include "battery_srv_client.h" -#endif -#include "res_sched_client.h" -#include "res_type.h" using namespace std; @@ -48,44 +43,11 @@ static const int64_t MIN_INTERVAL_DEFAULT = 2 * 60 * 60 * 1000; std::map WorkStatus::s_uid_last_time_map; const int32_t DEFAULT_PRIORITY = 10000; const int32_t HIGH_PRIORITY = 0; +const int32_t ACTIVE_GROUP = 10; const string SWITCH_ON = "1"; const string DELIMITER = ","; ffrt::mutex WorkStatus::s_uid_last_time_mutex; -#ifdef DEVICE_USAGE_STATISTICS_ENABLE -namespace GroupConst { -constexpr int32_t APP_TYPE_EMAIL = 673; -constexpr int64_t ONE_MINUTE = 60 * 1000LL; -constexpr int64_t TWENTY_MINUTE = 20 * ONE_MINUTE; -constexpr int64_t THIRTY_MINUTE = 30 * ONE_MINUTE; - -const std::unordered_map GROUP_INTERVAL_MAP = { - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_FORCED_SET, 0}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE, - DeviceUsageStats::DeviceUsageStatsGroupConst::TWO_HOUR}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_DAILY, - 2 * DeviceUsageStats::DeviceUsageStatsGroupConst::TWO_HOUR}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_FIXED, - DeviceUsageStats::DeviceUsageStatsGroupConst::TWENTY_FOUR_HOUR}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_RARE, - DeviceUsageStats::DeviceUsageStatsGroupConst::FOURTY_EIGHT_HOUR}, -}; - -const std::unordered_map MAIL_APP_GROUP_INTERVAL_MAP = { - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_FORCED_SET, 0}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE, THIRTY_MINUTE}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_DAILY, - 2 * DeviceUsageStats::DeviceUsageStatsGroupConst::TWO_HOUR}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_FIXED, - DeviceUsageStats::DeviceUsageStatsGroupConst::TWELVE_HOUR}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_RARE, - DeviceUsageStats::DeviceUsageStatsGroupConst::TWENTY_FOUR_HOUR}, - {DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_LIMIT, - DeviceUsageStats::DeviceUsageStatsGroupConst::FOURTY_EIGHT_HOUR}, -}; -} // namespace GroupConst -#endif - std::unordered_map COND_TYPE_STRING_MAP = { {WorkCondition::Type::NETWORK, "NETWORK"}, {WorkCondition::Type::CHARGER, "CHARGER"}, @@ -461,44 +423,13 @@ bool WorkStatus::IsNapReady(WorkCondition::Type type) return true; } -bool WorkStatus::IsChargingState() -{ -#ifdef POWERMGR_BATTERY_MANAGER_ENABLE - auto type = PowerMgr::BatterySrvClient::GetInstance().GetPluggedType(); - return type != PowerMgr::BatteryPluggedType::PLUGGED_TYPE_NONE && - type != PowerMgr::BatteryPluggedType::PLUGGED_TYPE_BUTT; -#else - return false; -#endif -} - -bool WorkStatus::IsMailApp() -{ - nlohmann::json payload; - nlohmann::json reply; - payload["bundleName"] = bundleName_; - int32_t ret = ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent( - ResourceSchedule::ResType::SYNC_RES_TYPE_GET_APP_STATUS, 0, payload, reply); - if (ret != ERR_OK) { - WS_HILOGE("getapp type err:%{public}d", ret); - return false; - } - int32_t pkgType = -1; - if (reply.contains("thirdKindId") && reply.at("thirdKindId").is_number_integer()) { - pkgType = reply["thirdKindId"].get(); - } else { - WS_HILOGD("no thirdKindId"); - } - return pkgType == GroupConst::APP_TYPE_EMAIL; -} - bool WorkStatus::SetMinInterval() { #ifdef DEVICE_USAGE_STATISTICS_ENABLE int32_t group = 0; if (workInfo_->IsCallBySystemApp()) { WS_HILOGD("system app %{public}s, default group is active.", bundleName_.c_str()); - return SetMinIntervalByGroup(DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE); + return SetMinIntervalByGroup(ACTIVE_GROUP); } bool res = DelayedSingleton::GetInstance()->FindGroup(bundleName_, userId_, group); if (!res) { @@ -507,12 +438,12 @@ bool WorkStatus::SetMinInterval() if (errCode != ERR_OK) { WS_HILOGE("query package group failed. userId = %{public}d, bundleName = %{public}s", userId_, bundleName_.c_str()); - group = DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE; + group = ACTIVE_GROUP; } DelayedSingleton::GetInstance()->AddGroup(bundleName_, userId_, group); } #else - int32_t group = DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE; + int32_t group = ACTIVE_GROUP; #endif return SetMinIntervalByGroup(group); } @@ -527,10 +458,13 @@ bool WorkStatus::SetMinIntervalByGroup(int32_t group) group > DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_FIXED) { newGroup = DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_FIXED; } - if (IsChargingState()) { - SetMinIntervalWhenCharging(newGroup); + auto itMap = DeviceUsageStats::DeviceUsageStatsGroupMap::groupIntervalMap_.find(newGroup); + if (itMap != DeviceUsageStats::DeviceUsageStatsGroupMap::groupIntervalMap_.end()) { + minInterval_ = DeviceUsageStats::DeviceUsageStatsGroupMap::groupIntervalMap_[newGroup]; } else { - SetMinIntervalWhenNotCharging(newGroup); + WS_HILOGE("query package group interval failed. group:%{public}d, bundleName:%{public}s", + newGroup, bundleName_.c_str()); + minInterval_ = -1; } #else minInterval_ = MIN_INTERVAL_DEFAULT; @@ -539,52 +473,6 @@ bool WorkStatus::SetMinIntervalByGroup(int32_t group) return true; } -#ifdef DEVICE_USAGE_STATISTICS_ENABLE -void WorkStatus::SetMinIntervalWhenCharging(int32_t group) -{ - int32_t newGroup = group; - if (group < DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_RARE) { - newGroup = DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE; - } else if (group == DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_LIMIT) { - newGroup = DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_RARE; - } - auto itMap = GroupConst::GROUP_INTERVAL_MAP.find(newGroup); - if (itMap == GroupConst::GROUP_INTERVAL_MAP.end()) { - WS_HILOGE("query package group interval failed. group:%{public}d, bundleName:%{public}s", - newGroup, bundleName_.c_str()); - minInterval_ = -1; - } - if (IsMailApp() && group == DeviceUsageStats::DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE) { - minInterval_ = GroupConst::TWENTY_MINUTE; - } else { - minInterval_ = GroupConst::GROUP_INTERVAL_MAP.at(newGroup); - } -} - -void WorkStatus::SetMinIntervalWhenNotCharging(int32_t group) -{ - if (IsMailApp()) { - auto itMap = GroupConst::MAIL_APP_GROUP_INTERVAL_MAP.find(group); - if (itMap != GroupConst::MAIL_APP_GROUP_INTERVAL_MAP.end()) { - minInterval_ = GroupConst::MAIL_APP_GROUP_INTERVAL_MAP.at(group); - } else { - WS_HILOGE("query mail app group interval failed. group:%{public}d, bundleName:%{public}s", - group, bundleName_.c_str()); - minInterval_ = -1; - } - } else { - auto itMap = GroupConst::GROUP_INTERVAL_MAP.find(group); - if (itMap != GroupConst::GROUP_INTERVAL_MAP.end()) { - minInterval_ = GroupConst::GROUP_INTERVAL_MAP.at(group); - } else { - WS_HILOGE("query package group interval failed. group:%{public}d, bundleName:%{public}s", - group, bundleName_.c_str()); - minInterval_ = -1; - } - } -} -#endif - void WorkStatus::SetMinIntervalByDump(int64_t interval) { WS_HILOGD("set min interval by dump to %{public}" PRId64 "", interval); -- Gitee