From 45d480c2b1e77546130b723364b2434bb2fd145a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9C=BC=E7=A5=9E=E4=B8=8D=E6=92=92=E6=97=A6?= Date: Sun, 12 Jan 2025 11:04:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E8=83=BD=E5=8A=9B=E5=A2=9E?= =?UTF-8?q?=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 眼神不撒旦 --- BUILD.gn | 1 + bundle.json | 1 + interfaces/inner_api/include/form_constants.h | 12 ++ interfaces/inner_api/include/form_instance.h | 5 + interfaces/kits/native/src/form_mgr.cpp | 5 - services/include/form_data_mgr.h | 32 ++++- services/include/form_event_util.h | 4 + services/include/form_item_info.h | 22 ++++ services/include/form_mgr_adapter.h | 10 ++ services/include/form_mgr_service.h | 18 +++ services/include/form_record.h | 3 + services/include/form_task_mgr.h | 12 ++ services/include/form_timer.h | 20 ++++ services/include/form_timer_mgr.h | 10 ++ services/src/form_data_mgr.cpp | 101 +++++++++++++++- services/src/form_event_util.cpp | 97 ++++++++++++++- services/src/form_item_info.cpp | 27 +++++ services/src/form_mgr_adapter.cpp | 41 ++++++- services/src/form_mgr_service.cpp | 113 ++++++++++++++++++ services/src/form_provider_mgr.cpp | 30 ++++- services/src/form_task_mgr.cpp | 22 ++++ services/src/form_timer_mgr.cpp | 113 ++++++++++++++++-- .../formdatamgrtwo_fuzzer.cpp | 5 +- .../fms_form_data_mgr_test.cpp | 12 +- 24 files changed, 682 insertions(+), 34 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 6c6bb1ffe0..f9ce5a2065 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -162,6 +162,7 @@ ohos_shared_library("libfms") { "ipc:ipc_core", "kv_store:distributeddata_inner", "libxml2:libxml2", + "netmanager_base:net_conn_manager_if", "os_account:os_account_innerkits", "relational_store:native_rdb", "resource_management:global_resmgr", diff --git a/bundle.json b/bundle.json index 60cf349f0b..6e31b747f4 100644 --- a/bundle.json +++ b/bundle.json @@ -55,6 +55,7 @@ "hicollie", "hisysevent", "kv_store", + "netmanager_base", "resource_management", "time_service", "device_usage_statistics", diff --git a/interfaces/inner_api/include/form_constants.h b/interfaces/inner_api/include/form_constants.h index 56b56a5816..600a1fe34d 100644 --- a/interfaces/inner_api/include/form_constants.h +++ b/interfaces/inner_api/include/form_constants.h @@ -54,6 +54,8 @@ namespace Constants { constexpr const char* PARAM_FORM_USER_ID = "ohos.extra.param.key.form_user_id"; constexpr const char* KEY_IS_TIMER = "isCountTimerRefresh"; constexpr const char* KEY_TIMER_REFRESH = "isTimerRefresh"; + constexpr const char* KEY_CONNECT_REFRESH = "isConnectRefresh"; + constexpr const char* PARAM_FORM_REFRESH_TYPE = "ohos.extra.param.key.refresh_type"; constexpr const char* SYSTEM_PARAM_FORM_UPDATE_TIME = "persist.sys.fms.form.update.time"; constexpr const char* SYSTEM_PARAM_FORM_REFRESH_MIN_TIME = "persist.sys.fms.form.refresh.min.time"; constexpr const char* ACTION_UPDATEATTIMER = "form_update_at_timer"; @@ -137,7 +139,9 @@ namespace Constants { const long MAX_PERIOD = MAX_CONFIG_DURATION * TIME_CONVERSION; // 1 week in ms unit const long ABS_TIME = 30 * TIME_1000; // 30s abs time constexpr const char* TIME_DELIMETER = ":"; + constexpr const char* TIMES_DELIMETER = ","; constexpr int32_t UPDATE_AT_CONFIG_COUNT = 2; + constexpr int32_t UPDATE_AT_CONFIG_MAX_COUNT = 24; constexpr int32_t LIMIT_COUNT = 50; constexpr int32_t MIN_NEXT_TIME = 300; // seconds @@ -270,6 +274,14 @@ namespace Constants { PublishFormErrorCode code; std::string message; }; + // refresh type + constexpr int32_t REFRESHTYPE_DEFAULT = -1; + constexpr int32_t REFRESHTYPE_HOST = 0; + constexpr int32_t REFRESHTYPE_INTERVAL = 1; + constexpr int32_t REFRESHTYPE_UPDATETIMES = 2; + constexpr int32_t REFRESHTYPE_UPDATENEXTTIME = 3; + constexpr int32_t REFRESHTYPE_NETWORKCHANGED = 4; + constexpr int32_t REFRESHTYPE_VISIABLE = 99; // rdb const std::string FORM_MANAGER_SERVICE_PATH = "/data/service/el1/public/database/form_storage"; diff --git a/interfaces/inner_api/include/form_instance.h b/interfaces/inner_api/include/form_instance.h index e90b7b1133..101d1d761a 100644 --- a/interfaces/inner_api/include/form_instance.h +++ b/interfaces/inner_api/include/form_instance.h @@ -38,6 +38,11 @@ enum class RecycleStatus { NON_RECYCLABLE, }; +enum class ConditionUpdateType { + NOCONDITON = 0, + NETWORK, +}; + struct FormInstance : public Parcelable { int64_t formId = 0; std::string formHostName = ""; diff --git a/interfaces/kits/native/src/form_mgr.cpp b/interfaces/kits/native/src/form_mgr.cpp index 2d94190c64..45a884566b 100644 --- a/interfaces/kits/native/src/form_mgr.cpp +++ b/interfaces/kits/native/src/form_mgr.cpp @@ -591,11 +591,6 @@ int FormMgr::SetNextRefreshTime(const int64_t formId, const int64_t nextTime) { HILOG_INFO("call"); - if (nextTime < (Constants::MIN_NEXT_TIME / Constants::SEC_PER_MIN)) { - HILOG_ERROR("next time less than 5 mins"); - return ERR_APPEXECFWK_FORM_INVALID_REFRESH_TIME; - } - if (GetInstance().GetRecoverStatus() == Constants::IN_RECOVERING) { HILOG_ERROR("formManager is in recovering"); return ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR; diff --git a/services/include/form_data_mgr.h b/services/include/form_data_mgr.h index 4710ed33dc..3b2531753f 100644 --- a/services/include/form_data_mgr.h +++ b/services/include/form_data_mgr.h @@ -154,6 +154,14 @@ public: */ bool GetFormRecord(const std::string &bundleName, std::vector &formInfos, int32_t userId = Constants::INVALID_USER_ID) const; + + /** + * @brief Get form record. + * @param conditionType refresh type. + * @param formInfos The form record list. + * @return Returns true if this function is successfully called; returns false otherwise. + */ + bool GetFormRecordByCondition(int32_t conditionType, std::vector &formInfos) const; /** * @brief Get temporary form record. * @param formTempRecords The temp form record. @@ -256,6 +264,20 @@ public: * @param needRefresh true or false. */ void SetNeedRefresh(const int64_t formId, const bool needRefresh); + + /** + * @brief Set refreshType for FormRecord. + * @param formId The Id of the form. + * @param needRefresh true or false. + */ + void SetRefreshType(const int64_t formId, const int refreshType); + + /** + * @brief Get refreshType for FormRecord. + * @param formId The Id of the form. + * @param refreshType the form refresh type. + */ + void GetRefreshType(const int64_t formId, int &refreshType); /** * @brief Set needAddForm for FormRecord. @@ -299,9 +321,10 @@ public: * @param updateDuration Update duration. * @param updateAtHour Update at hour. * @param updateAtMin Update at minute. + * @param updateAtTimes Update times. */ void SetUpdateInfo(const int64_t formId, const bool enableUpdate, const long updateDuration, - const int updateAtHour, const int updateAtMin); + const int updateAtHour, const int updateAtMin, std::vector> updateAtTimes); /** * @brief Clean removed form records. * @param bundleName BundleName. @@ -823,6 +846,13 @@ private: */ void ParseIntervalConfig(FormRecord &record, const int configDuration) const; + /** + * @brief Parse multi update time config. + * @param record The form record. + * @param info form item info. + */ + void ParseMultiUpdateTimeConfig(FormRecord &record, const FormItemInfo &info) const; + /** * @brief Parse at time config. * @param record The form record. diff --git a/services/include/form_event_util.h b/services/include/form_event_util.h index fb0dbfa35c..7ec90b7155 100644 --- a/services/include/form_event_util.h +++ b/services/include/form_event_util.h @@ -49,6 +49,9 @@ public: std::map &foundFormsMap); static void GetTimerCfg(const bool updateEnabled, const int updateDuration, const std::string &configUpdateAt, FormTimerCfg &cfg); + static void SetTimerCfgByMultUpdate(const std::string &configMultUpdateAt, FormTimerCfg& cfg); + static void HandleAddMultiUpdateTimes(const int64_t formId, const FormRecord &record, + const FormTimerCfg &timerCfg); static void HandleTimerUpdate(const int64_t formId, const FormRecord &record, const FormTimerCfg &timerCfg); static void ReCreateForm(const int64_t formId); static void BatchDeleteNoHostDBForms(const int uid, std::map> &noHostFormDbMap, @@ -57,6 +60,7 @@ public: static bool HandleAdditionalInfoChanged(const std::string &bundleName); private: + static void UpdateMultiUpdateTime(std::string multiScheduledUpdateTime, FormRecord &formRecord); static void UpdateFormRecord(const FormInfo &formInfo, FormRecord &formRecord); static void UpdateFormRecord(const AbilityFormInfo &formInfo, FormRecord &formRecord); static UpdateType GetUpdateType(const FormRecord &record, const FormTimerCfg &timerCfg); diff --git a/services/include/form_item_info.h b/services/include/form_item_info.h index 9d7eab2c6e..1fef02edea 100644 --- a/services/include/form_item_info.h +++ b/services/include/form_item_info.h @@ -152,11 +152,21 @@ public: * @return scheduledUpdateTime_. */ std::string GetScheduledUpdateTime() const; + /** + * @brief Get multiScheduledUpdateTime_. + * @return multiScheduledUpdateTime_. + */ + std::string GetMultiScheduledUpdateTime() const; /** * @brief Set value of scheduledUpdateTime_. * @param scheduledUpdateTime Scheduled update time. */ void SetScheduledUpdateTime(const std::string &scheduledUpdateTime); + /** + * @brief Set value of multiScheduledUpdateTime_. + * @param multiScheduledUpdateTime Scheduled update time. + */ + void SetMultiScheduledUpdateTime(const std::string &multiScheduledUpdateTime); /** * @brief Get hapSourceDirs_. * @param dirs Hap source dirs. @@ -453,6 +463,16 @@ public: * @param lockForm True for lock, false for unlock. */ void SetLockForm(bool lockForm); + /** + * @brief Get updateDuration_. + * @return updateDuration_. + */ + std::vector GetConditionUpdate() const; + /** + * @brief Set value of updateDuration_. + * @param updateDuration Update duration. + */ + void SetConditionUpdate(const std::vector &conditionUpdate); private: /** @@ -475,6 +495,7 @@ private: bool updateFlag_ = false; int32_t updateDuration_ = 0; std::string scheduledUpdateTime_ = ""; + std::string multiScheduledUpdateTime_ = ""; std::vector hapSourceDirs_; bool temporaryFlag_ = false; bool formVisibleNotify_ = false; @@ -504,6 +525,7 @@ private: bool enableForm_ = true; Constants::RenderingMode renderingMode_ = Constants::RenderingMode::FULL_COLOR; bool lockForm_ = false; + std::vector conditionUpdate_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_mgr_adapter.h b/services/include/form_mgr_adapter.h index 585ea3a98c..fd1ac5dd63 100644 --- a/services/include/form_mgr_adapter.h +++ b/services/include/form_mgr_adapter.h @@ -664,6 +664,14 @@ public: ErrCode UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth); int32_t OnNotifyRefreshForm(const int64_t &formId); + + /** + * @brief Update form by condition. + * @param UpdateType The type of the form to update. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode UpdateFormByCondition(int type); + private: /** * @brief Get form configure info. @@ -1230,6 +1238,8 @@ private: std::mutex reUpdateFormMapMutex_; std::unordered_map> reUpdateFormMap_; + + std::map> conditionUpdateFormMap; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_mgr_service.h b/services/include/form_mgr_service.h index b346b445b1..041607cb3c 100644 --- a/services/include/form_mgr_service.h +++ b/services/include/form_mgr_service.h @@ -34,6 +34,14 @@ enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING, }; + +enum class ConNetStatus { + DIS_CONNECT_NETWORK = 0, + CONNECT_NETWORK, + PRE_CONNECT_NETWORK, + PRE_DISCONNECT_NETWORK, +}; + /** * @class FormMgrService * FormMgrService provides a facility for managing form life cycle. @@ -673,6 +681,10 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth) override; + + void SubscribeNetConn(); + + friend class NetConnCallbackObserver; private: /** * OnAddSystemAbility, OnAddSystemAbility will be called when the listening SA starts. @@ -719,6 +731,9 @@ private: void HiDumpFormBlockedApps([[maybe_unused]] const std::string &args, std::string &result); bool CheckCallerIsSystemApp() const; static std::string GetCurrentDateTime(); + void SetNetConnect(); + void SetDisConnectTypeTime(); + private: static const int32_t ENABLE_FORM_UPDATE = 5; const static std::map dumpKeyMap_; @@ -730,6 +745,9 @@ private: std::shared_ptr handler_ = nullptr; std::shared_ptr serialQueue_ = nullptr; std::shared_ptr formSysEventReceiver_ = nullptr; + uint32_t NetSceneCallbackId_ = 0; + int32_t netConTime = 0; + int64_t lastNetLostTime_ = FormUtil::GetCurrentMillisecond(); mutable std::mutex instanceMutex_; DISALLOW_COPY_AND_MOVE(FormMgrService); #ifdef MEM_MGR_ENABLE diff --git a/services/include/form_record.h b/services/include/form_record.h index 013d200ec5..8c28475a2a 100644 --- a/services/include/form_record.h +++ b/services/include/form_record.h @@ -36,6 +36,7 @@ public: bool needFreeInstall = false; bool versionUpgrade = false; bool needRefresh = false; + int refreshType; bool needAddForm = false; bool isCountTimerRefresh = false; std::string packageName = ""; @@ -49,6 +50,7 @@ public: int64_t updateDuration = 0; int updateAtHour = -1; int updateAtMin = -1; + std::vector> updateAtTimes; FormProviderInfo formProviderInfo; std::vector hapSourceDirs; std::map modulePkgNameMap; @@ -84,6 +86,7 @@ public: bool isUpdateDuringDisableForm = false; Constants::RenderingMode renderingMode = Constants::RenderingMode::FULL_COLOR; bool lockForm = false; + std::vector conditionUpdate; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_task_mgr.h b/services/include/form_task_mgr.h index 8aa6af65c8..b3e7227913 100644 --- a/services/include/form_task_mgr.h +++ b/services/include/form_task_mgr.h @@ -29,6 +29,7 @@ #include "form_state_info.h" #include "iremote_object.h" #include "running_form_info.h" +#include "form_mgr_service.h" #include "want.h" namespace OHOS { @@ -47,6 +48,7 @@ constexpr int32_t FORM_FRS_DIED_TASK_DELAY_TIME = 100; // ms constexpr int32_t FORM_BUILD_DELAY_TIME = 1400; // ms constexpr int32_t ENTERPRISE_APP_INSTALL_FAILED_DELAY_TIME = 5000; // ms constexpr int32_t CLEAN_FORM_HOST_TASK_DELAY_TIME = 100; // ms +constexpr int32_t FORM_CON_NETWORK_DELAY_TIME = 500; // ms } /** * @class FormTaskMgr @@ -338,6 +340,11 @@ public: */ void PostFrsDiedTaskToHost(const sptr &remoteObject); + /** + * @brief Post task to connect NetWork. + */ + void PostConnectNetWork(); + private: /** * @brief Acquire form data from form provider. @@ -588,6 +595,11 @@ private: */ void FrsDiedTaskToHost(const sptr &remoteObject); + /** + * @brief Post task to connect NetWork. + */ + void ConnectNetWork(); + private: std::mutex formRecoverTimesMutex_; std::unordered_map formLastRecoverTimes; diff --git a/services/include/form_timer.h b/services/include/form_timer.h index eb76662acd..f47d4a5de3 100644 --- a/services/include/form_timer.h +++ b/services/include/form_timer.h @@ -32,6 +32,19 @@ enum UpdateType { TYPE_INTERVAL_ONCE, TYPE_NO_CHANGE, }; + +/** + * @enum RefreshType + * Refresh type. + */ +enum RefreshType { + TYPE_NO_TIMER, + TYPE_INTERVAL, + TYPE_UPDATETIMES, + TYPE_UPDATENEXTTIME, + TYPE_VISIABLE, +}; + /** * @class FormTimer * form timer task. @@ -48,6 +61,8 @@ public: bool isEnable = true; bool isCountTimer; UpdateType type = UpdateType::TYPE_INTERVAL_CHANGE; + RefreshType refreshType = RefreshType::TYPE_NO_TIMER; + bool needUpdateAlarm = true; FormTimer() { @@ -60,6 +75,7 @@ public: isCountTimer = false; refreshTime = FormUtil::GetCurrentMillisecond(); type = UpdateType::TYPE_INTERVAL_CHANGE; + refreshType = RefreshType::TYPE_NO_TIMER; } FormTimer(int64_t id, bool countTimer, int32_t uId = 0) @@ -73,6 +89,7 @@ public: isCountTimer = countTimer; refreshTime = FormUtil::GetCurrentMillisecond(); type = UpdateType::TYPE_INTERVAL_CHANGE; + refreshType = RefreshType::TYPE_NO_TIMER; } FormTimer(int64_t id, long repeatTime, int32_t uId = 0) @@ -86,6 +103,7 @@ public: isCountTimer = true; refreshTime = FormUtil::GetCurrentMillisecond(); type = UpdateType::TYPE_INTERVAL_CHANGE; + refreshType = RefreshType::TYPE_NO_TIMER; } FormTimer(int64_t id, int hourTime, int minTime, int32_t uId = 0) @@ -99,6 +117,7 @@ public: isCountTimer = false; refreshTime = FormUtil::GetCurrentMillisecond(); type = UpdateType::TYPE_INTERVAL_CHANGE; + refreshType = RefreshType::TYPE_NO_TIMER; } ~FormTimer(void) {} @@ -152,6 +171,7 @@ struct FormTimerCfg { int64_t updateDuration = 0L; int updateAtHour = -1; int updateAtMin = -1; + std::vector> updateAtTimes; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/include/form_timer_mgr.h b/services/include/form_timer_mgr.h index 6ba4dd5b54..5a3513207c 100644 --- a/services/include/form_timer_mgr.h +++ b/services/include/form_timer_mgr.h @@ -64,6 +64,16 @@ public: * @return Returns true on success, false on failure. */ bool AddFormTimer(int64_t formId, long updateAtHour, long updateAtMin, int32_t userId = 0); + + /** + * @brief Add scheduled form timer. + * @param formId The Id of the form. + * @param updateAtTimes multi updatetime. + * @param userId User ID. + * @return Returns true on success, false on failure. + */ + bool AddFormTimerForMultiUpdate(int64_t formId, std::vector> updateAtTimes, int32_t userId = 0); + /** * @brief Remove form timer by form id. * @param formId The Id of the form. diff --git a/services/src/form_data_mgr.cpp b/services/src/form_data_mgr.cpp index 47626886de..a2321e91f9 100644 --- a/services/src/form_data_mgr.cpp +++ b/services/src/form_data_mgr.cpp @@ -224,6 +224,7 @@ FormRecord FormDataMgr::CreateFormRecord(const FormItemInfo &formInfo, const int newRecord.formBundleType = formInfo.GetFormBundleType(); formInfo.GetHapSourceDirs(newRecord.hapSourceDirs); newRecord.renderingMode = formInfo.GetRenderingMode(); + newRecord.conditionUpdate = formInfo.GetConditionUpdate(); HILOG_DEBUG("end"); return newRecord; } @@ -570,6 +571,33 @@ bool FormDataMgr::GetFormRecord(const std::string &bundleName, std::vector &formInfos) const +{ + HILOG_DEBUG("get form record by conditionType"); + std::lock_guard lock(formRecordMutex_); + for (auto itFormRecord = formRecords_.begin(); itFormRecord != formRecords_.end(); itFormRecord++) { + std::vector conditionUpdate = itFormRecord->second.conditionUpdate; + for (int32_t item : conditionUpdate) { + if (item == conditionType) { + formInfos.emplace_back(itFormRecord->second); + break; + } + } + } + if (formInfos.size() > 0) { + return true; + } else { + HILOG_DEBUG("formInfo not find"); + return false; + } +} + /** * @brief Get temporary form record. * @param formTempRecords The temp form record. @@ -947,6 +975,38 @@ void FormDataMgr::SetNeedRefresh(const int64_t formId, const bool needRefresh) itFormRecord->second.needRefresh = needRefresh; } +/** + * @brief Set needRefresh for FormRecord. + * @param formId The Id of the form. + * @param needRefresh true or false. + */ +void FormDataMgr::SetRefreshType(const int64_t formId, const int refreshType) +{ + std::lock_guard lock(formRecordMutex_); + auto itFormRecord = formRecords_.find(formId); + if (itFormRecord == formRecords_.end()) { + HILOG_ERROR("form info not find"); + return; + } + itFormRecord->second.refreshType = refreshType; +} + +/** + * @brief get needRefresh for FormRecord. + * @param formId The Id of the form. + * @param needRefresh true or false. + */ +void FormDataMgr::GetRefreshType(const int64_t formId, int &refreshType) +{ + std::lock_guard lock(formRecordMutex_); + auto itFormRecord = formRecords_.find(formId); + if (itFormRecord == formRecords_.end()) { + HILOG_ERROR("form info not find"); + return; + } + refreshType = itFormRecord->second.refreshType; +} + /** * @brief Set needRefresh for FormRecord. * @param formId The Id of the form. @@ -1047,7 +1107,8 @@ void FormDataMgr::SetUpdateInfo( const bool enableUpdate, const long updateDuration, const int updateAtHour, - const int updateAtMin) + const int updateAtMin, + const std::vector> updateAtTimes) { std::lock_guard lock(formRecordMutex_); auto itFormRecord = formRecords_.find(formId); @@ -1060,6 +1121,7 @@ void FormDataMgr::SetUpdateInfo( itFormRecord->second.updateDuration = updateDuration; itFormRecord->second.updateAtHour = updateAtHour; itFormRecord->second.updateAtMin = updateAtMin; + itFormRecord->second.updateAtTimes = updateAtTimes; } /** * @brief Check if two forms is same or not. @@ -1404,6 +1466,7 @@ void FormDataMgr::ParseUpdateConfig(FormRecord &record, const FormItemInfo &info ParseIntervalConfig(record, configDuration); } else { ParseAtTimerConfig(record, info); + ParseMultiUpdateTimeConfig(record, info); } } @@ -1425,6 +1488,42 @@ void FormDataMgr::ParseIntervalConfig(FormRecord &record, const int configDurati HILOG_INFO("end"); } +void FormDataMgr::ParseMultiUpdateTimeConfig(FormRecord &record, const FormItemInfo &info) const +{ + std::string configAtMultiTime = info.GetMultiScheduledUpdateTime(); + HILOG_INFO("ParseMultiUpdateTimeConfig updateAt:%{public}s", configAtMultiTime.c_str()); + if (configAtMultiTime.empty()) { + return; + } + std::vector timeList = FormUtil::StringSplit(configAtMultiTime, Constants::TIMES_DELIMETER); + if (timeList.size() > Constants::UPDATE_AT_CONFIG_MAX_COUNT) { + HILOG_ERROR("invalid config, size: %{public}zu", timeList.size()); + return; + } + std::vector> updateAtTimes; + for (const auto &time : timeList) { + std::vector temp = FormUtil::StringSplit(time, Constants::TIME_DELIMETER); + if (temp.size() != Constants::UPDATE_AT_CONFIG_COUNT) { + HILOG_ERROR("invalid config"); + continue; + } + int hour = std::stoi(temp[0]); + int min = std::stoi(temp[1]); + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > + Constants::MAX_MINUTE) { + HILOG_ERROR("invalid time, hour:%{public}d, min:%{public}d", hour, min); + continue; + } + std::vector newElement = {hour, min}; + updateAtTimes.push_back(newElement); + } + + HILOG_INFO("parseAsUpdateAt updateAtTimes size:%{public}zu", updateAtTimes.size()); + if (updateAtTimes.size() > 0) { + record.updateAtTimes = updateAtTimes; + } +} + /** * @brief Parse at time config. * @param record The form record. diff --git a/services/src/form_event_util.cpp b/services/src/form_event_util.cpp index e43e05d10e..68093c82c9 100644 --- a/services/src/form_event_util.cpp +++ b/services/src/form_event_util.cpp @@ -263,6 +263,7 @@ bool FormEventUtil::ProviderFormUpdated(const int64_t formId, FormRecord &formRe FormBmsHelper::GetInstance().NotifyModuleNotRemovable(formRecord.bundleName, formRecord.moduleName); FormTimerCfg timerCfg; GetTimerCfg(updatedForm.updateEnabled, updatedForm.updateDuration, updatedForm.scheduledUpdateTime, timerCfg); + SetTimerCfgByMultUpdate(updatedForm.multiScheduledUpdateTime, timerCfg); HandleTimerUpdate(formId, formRecord, timerCfg); UpdateRecordByBundleInfo(bundleInfo, formRecord); UpdateFormRecord(updatedForm, formRecord); @@ -284,6 +285,7 @@ bool FormEventUtil::ProviderFormUpdated(const int64_t formId, FormRecord &formRe FormDataMgr::GetInstance().SetRecordNeedFreeInstall(formId, true); FormTimerCfg timerCfg; GetTimerCfg(packForm.updateEnabled, packForm.updateDuration, packForm.scheduledUpdateTime, timerCfg); + SetTimerCfgByMultUpdate(packForm.multiScheduledUpdateTime, timerCfg); HandleTimerUpdate(formId, formRecord, timerCfg); UpdateRecordByBundleInfo(bundleInfo, formRecord); UpdateFormRecord(packForm, formRecord); @@ -399,6 +401,51 @@ void FormEventUtil::GetTimerCfg(const bool updateEnabled, } } +void FormEventUtil::SetTimerCfgByMultUpdate(const std::string &configMultUpdateAt, FormTimerCfg& cfg) +{ + if (configMultUpdateAt.empty()) { + return; + } + std::vector timeList = FormUtil::StringSplit(configMultUpdateAt, Constants::TIMES_DELIMETER); + if (timeList.size() > Constants::UPDATE_AT_CONFIG_MAX_COUNT) { + HILOG_ERROR("invalid config"); + return; + } + std::vector> updateAtTimes; + for (const auto &time: timeList) { + std::vector temp = FormUtil::StringSplit(time, Constants::TIME_DELIMETER); + if (temp.size() != Constants::UPDATE_AT_CONFIG_COUNT) { + HILOG_ERROR("invalid config"); + continue; + } + int hour = std::stoi(temp[0]); + int min = std::stoi(temp[1]); + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > + Constants::MAX_MINUTE) { + HILOG_ERROR("invalid time"); + continue; + } + std::vector newElement = {hour, min}; + updateAtTimes.push_back(newElement); + } + if (updateAtTimes.size() > 0) { + cfg.updateAtTimes = updateAtTimes; + } +} + +void FormEventUtil::HandleAddMultiUpdateTimes(const int64_t formId, + const FormRecord &record, const FormTimerCfg &timerCfg) +{ + std::vector> updateAtTimes = timerCfg.updateAtTimes; + if (updateAtTimes.size() > 0) { + for (const auto &time: updateAtTimes) { + HILOG_INFO("add at timer:%{public}d,%{public}d", time[0], time[1]); + FormTimerMgr::GetInstance().AddFormTimer(formId, + time[0], time[1], record.providerUserId); + } + } +} + void FormEventUtil::HandleTimerUpdate(const int64_t formId, const FormRecord &record, const FormTimerCfg &timerCfg) { @@ -417,7 +464,7 @@ void FormEventUtil::HandleTimerUpdate(const int64_t formId, // disable to enable if (!record.isEnableUpdate && timerCfg.enableUpdate) { FormDataMgr::GetInstance().SetUpdateInfo(formId, true, - timerCfg.updateDuration, timerCfg.updateAtHour, timerCfg.updateAtMin); + timerCfg.updateDuration, timerCfg.updateAtHour, timerCfg.updateAtMin, timerCfg.updateAtTimes); if (timerCfg.updateDuration > 0) { HILOG_INFO("add interval timer:%{public}" PRId64, timerCfg.updateDuration); int64_t updateDuration = timerCfg.updateDuration; @@ -429,6 +476,8 @@ void FormEventUtil::HandleTimerUpdate(const int64_t formId, HILOG_INFO("add at timer:%{public}d,%{public}d", timerCfg.updateAtHour, timerCfg.updateAtMin); FormTimerMgr::GetInstance().AddFormTimer(formId, timerCfg.updateAtHour, timerCfg.updateAtMin, record.providerUserId); + + HandleAddMultiUpdateTimes(formId, record, timerCfg); } return; } @@ -440,7 +489,7 @@ void FormEventUtil::HandleTimerUpdate(const int64_t formId, } FormDataMgr::GetInstance().SetUpdateInfo(formId, true, - timerCfg.updateDuration, timerCfg.updateAtHour, timerCfg.updateAtMin); + timerCfg.updateDuration, timerCfg.updateAtHour, timerCfg.updateAtMin, timerCfg.updateAtTimes); auto newTimerCfg = timerCfg; if (type == TYPE_INTERVAL_CHANGE || type == TYPE_ATTIME_TO_INTERVAL) { int64_t updateDuration = timerCfg.updateDuration; @@ -472,7 +521,8 @@ UpdateType FormEventUtil::GetUpdateType(const FormRecord &record, const FormTime // update at time to interval return TYPE_ATTIME_TO_INTERVAL; } else { - if (record.updateAtHour == timerCfg.updateAtHour && record.updateAtMin == timerCfg.updateAtMin) { + if (record.updateAtHour == timerCfg.updateAtHour && record.updateAtMin == timerCfg.updateAtMin + && record.updateAtTimes == timerCfg.updateAtTimes) { return TYPE_NO_CHANGE; } // update at time change @@ -581,6 +631,39 @@ bool FormEventUtil::HandleAdditionalInfoChanged(const std::string &bundleName) return true; } + +void FormEventUtil::UpdateMultiUpdateTime(std::string multiScheduledUpdateTime, FormRecord &formRecord) +{ + std::vector timeList = FormUtil::StringSplit(multiScheduledUpdateTime, + Constants::TIMES_DELIMETER); + if (timeList.size() > Constants::UPDATE_AT_CONFIG_MAX_COUNT) { + HILOG_ERROR("invalid config"); + return; + } + + std::vector> updateAtTimes; + for (const auto &time: timeList) { + HILOG_INFO("UpdateFormRecord add updateAtTimes"); + std::vector temp = FormUtil::StringSplit(time, Constants::TIME_DELIMETER); + if (temp.size() != Constants::UPDATE_AT_CONFIG_COUNT) { + HILOG_ERROR("invalid config"); + continue; + } + int hour = std::stoi(temp[0]); + int min = std::stoi(temp[1]); + if (hour < Constants::MIN_TIME || hour > Constants::MAX_HOUR || min < Constants::MIN_TIME || min > + Constants::MAX_MINUTE) { + HILOG_ERROR("invalid time"); + continue; + } + std::vector newElement = {hour, min}; + updateAtTimes.push_back(newElement); + } + if (updateAtTimes.size() > 0) { + formRecord.updateAtTimes = updateAtTimes; + } +} + void FormEventUtil::UpdateFormRecord(const FormInfo &formInfo, FormRecord &formRecord) { formRecord.formSrc = formInfo.src; @@ -595,6 +678,10 @@ void FormEventUtil::UpdateFormRecord(const FormInfo &formInfo, FormRecord &formR formRecord.updateAtHour = std::stoi(time[0]); formRecord.updateAtMin = std::stoi(time[1]); } + std::string multiScheduledUpdateTime_ = formInfo.scheduledUpdateTime; + if (!multiScheduledUpdateTime_.empty()) { + UpdateMultiUpdateTime(multiScheduledUpdateTime_, formRecord); + } HILOG_DEBUG("formId:%{public}" PRId64 "", formRecord.formId); FormDataMgr::GetInstance().UpdateFormRecord(formRecord.formId, formRecord); } @@ -609,6 +696,10 @@ void FormEventUtil::UpdateFormRecord(const AbilityFormInfo &formInfo, FormRecord formRecord.updateAtHour = std::stoi(time[0]); formRecord.updateAtMin = std::stoi(time[1]); } + std::string multiScheduledUpdateTime_ = formInfo.scheduledUpdateTime; + if (!multiScheduledUpdateTime_.empty()) { + UpdateMultiUpdateTime(multiScheduledUpdateTime_, formRecord); + } HILOG_DEBUG("formId:%{public}" PRId64 "", formRecord.formId); FormDataMgr::GetInstance().UpdateFormRecord(formRecord.formId, formRecord); } diff --git a/services/src/form_item_info.cpp b/services/src/form_item_info.cpp index f1675dae48..74c84febea 100644 --- a/services/src/form_item_info.cpp +++ b/services/src/form_item_info.cpp @@ -123,6 +123,15 @@ std::string FormItemInfo::GetScheduledUpdateTime() const return scheduledUpdateTime_; } +/** + * @brief Get multiScheduledUpdateTime_. + * @return multiScheduledUpdateTime_. + */ +std::string FormItemInfo::GetMultiScheduledUpdateTime() const +{ + return multiScheduledUpdateTime_; +} + /** * @brief Get hapSourceDirs_. * @param dirs Hap source dirs. @@ -333,6 +342,14 @@ void FormItemInfo::SetScheduledUpdateTime(const std::string &scheduledUpdateTime { scheduledUpdateTime_ = scheduledUpdateTime; } +/** + * @brief Set value of multiScheduledUpdateTime_. + * @param multiScheduledUpdateTime Scheduled update time. + */ +void FormItemInfo::SetMultiScheduledUpdateTime(const std::string &multiScheduledUpdateTime) +{ + multiScheduledUpdateTime_ = multiScheduledUpdateTime; +} /** * @brief Add hap source dir. * @param hapSourceDir Hap source dir. @@ -614,6 +631,16 @@ void FormItemInfo::SetEnableForm(bool enableForm) enableForm_ = enableForm; } +std::vector FormItemInfo::GetConditionUpdate() const +{ + return conditionUpdate_; +} + +void FormItemInfo::SetConditionUpdate(const std::vector &conditionUpdate) +{ + conditionUpdate_ = conditionUpdate; +} + Constants::RenderingMode FormItemInfo::GetRenderingMode() const { return renderingMode_; diff --git a/services/src/form_mgr_adapter.cpp b/services/src/form_mgr_adapter.cpp index 1b406b2146..ca65b07a22 100644 --- a/services/src/form_mgr_adapter.cpp +++ b/services/src/form_mgr_adapter.cpp @@ -877,6 +877,7 @@ int FormMgrAdapter::RequestForm(const int64_t formId, const sptr Want reqWant(want); int32_t currentActiveUserId = FormUtil::GetCurrentAccountId(); reqWant.SetParam(Constants::PARAM_FORM_USER_ID, currentActiveUserId); + reqWant.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_HOST); return FormProviderMgr::GetInstance().RefreshForm(matchedFormId, reqWant, true); } @@ -1709,10 +1710,23 @@ ErrCode FormMgrAdapter::AddFormTimer(const FormRecord &formRecord) updateDuration, formRecord.providerUserId); return ret ? ERR_OK : ERR_APPEXECFWK_FORM_COMMON_CODE; } + bool scheduledUpdateFlag = false; + bool result1 = true; if (formRecord.updateAtHour >= 0 && formRecord.updateAtMin >= 0) { - bool ret = FormTimerMgr::GetInstance().AddFormTimer(formRecord.formId, + scheduledUpdateFlag = true; + result1 = FormTimerMgr::GetInstance().AddFormTimer(formRecord.formId, formRecord.updateAtHour, formRecord.updateAtMin, formRecord.providerUserId); - return ret ? ERR_OK : ERR_APPEXECFWK_FORM_COMMON_CODE; + } + bool result2 = true; + std::vector> updateAtTimes = formRecord.updateAtTimes; + if (updateAtTimes.size() > 0) { + scheduledUpdateFlag = true; + HILOG_INFO("updateAtTimes size:%{public}zu", updateAtTimes.size()); + result2 = FormTimerMgr::GetInstance().AddFormTimerForMultiUpdate(formRecord.formId, + updateAtTimes, formRecord.providerUserId); + } + if (scheduledUpdateFlag) { + return (result1 && result2)? ERR_OK : ERR_APPEXECFWK_FORM_COMMON_CODE; } HILOG_INFO("no need add form timer"); return ERR_OK; @@ -1965,6 +1979,7 @@ ErrCode FormMgrAdapter::CreateFormItemInfo(const BundleInfo &bundleInfo, itemInfo.SetEnableUpdateFlag(formInfo.updateEnabled); itemInfo.SetUpdateDuration(formInfo.updateDuration); itemInfo.SetScheduledUpdateTime(formInfo.scheduledUpdateTime); + itemInfo.SetMultiScheduledUpdateTime(formInfo.multiScheduledUpdateTime); itemInfo.SetJsComponentName(formInfo.jsComponentName); itemInfo.SetFormVisibleNotify(formInfo.formVisibleNotify); auto formSrc = formInfo.src; @@ -1980,6 +1995,7 @@ ErrCode FormMgrAdapter::CreateFormItemInfo(const BundleInfo &bundleInfo, itemInfo.SetPrivacyLevel(formInfo.privacyLevel); itemInfo.SetDataProxyFlag(formInfo.dataProxyEnabled); itemInfo.SetFormBundleType(formInfo.bundleType); + itemInfo.SetConditionUpdate(formInfo.conditionUpdate); SetFormItemInfoParams(bundleInfo, formInfo, itemInfo); return ERR_OK; @@ -4038,5 +4054,26 @@ int32_t FormMgrAdapter::OnNotifyRefreshForm(const int64_t &formId) } return ERR_OK; } +ErrCode FormMgrAdapter::UpdateFormByCondition(int32_t type) +{ + HILOG_INFO("UpdateFormByCondition type:%{public}d", type); + std::vector formInfos; + if (!FormDataMgr::GetInstance().GetFormRecordByCondition(type, formInfos)) { + return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; + } + + for (FormRecord& formRecord : formInfos) { + if (!formRecord.isSystemApp) { + continue; + } + int32_t userId = FormUtil::GetCurrentAccountId(); + Want want; + want.SetParam(Constants::PARAM_FORM_USER_ID, userId); + want.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_NETWORKCHANGED); + want.SetParam(Constants::KEY_CONNECT_REFRESH, true); + FormProviderMgr::GetInstance().RefreshForm(formRecord.formId, want, true); + } + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/src/form_mgr_service.cpp b/services/src/form_mgr_service.cpp index 2add316d3a..e9c0c31968 100644 --- a/services/src/form_mgr_service.cpp +++ b/services/src/form_mgr_service.cpp @@ -58,6 +58,9 @@ #include "xcollie/watchdog.h" #include "xcollie/xcollie.h" #include "xcollie/xcollie_define.h" +#include "net_conn_callback_stub.h" +#include "net_conn_client.h" +#include "net_handle.h" #include "form_bundle_lock_mgr.h" #ifdef MEM_MGR_ENABLE #include "mem_mgr_client.h" @@ -78,12 +81,15 @@ constexpr int MILLISECOND_WIDTH = 3; constexpr char MILLISECOND_FILLCHAR = '0'; const int32_t API_TIME_OUT = 5; const int32_t API_TIME_OUT_30S = 30; +const int32_t CONDITION_NETWORK = 1; +const long FORM_DISCON_NETWORK_CHECK_TIME = 600000; // ms #ifdef RES_SCHEDULE_ENABLE constexpr int32_t SYSTEMLOADLEVEL_TIMERSTOP_THRESHOLD = static_cast(ResourceSchedule::ResType::SystemloadLevel::HIGH); #endif // RES_SCHEDULE_ENABLE } using namespace std::chrono; +using namespace OHOS::NetManagerStandard; const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); @@ -94,6 +100,8 @@ const std::string FORM_MGR_SERVICE_QUEUE = "FormMgrServiceQueue"; constexpr int32_t FORM_DUMP_ARGC_MAX = 2; +constexpr int32_t FORM_CON_NET_MAX = 100; + const std::string FORM_DUMP_HELP = "options list:\n" " -h, --help list available commands\n" " -b, --bundle-form-info query all form infos from bundle, Un-added form info will also be dumped\n" @@ -774,6 +782,96 @@ void FormMgrService::SubscribeSysEventReceiver() } } +class NetConnCallbackObserver : public NetManagerStandard::NetConnCallbackStub { +public: + explicit NetConnCallbackObserver(FormMgrService &fmservice); + ~NetConnCallbackObserver() override = default; + int32_t NetAvailable(sptr &netHandle) override; + int32_t NetCapabilitiesChange(sptr &netHandle, + const sptr &netAllCap) override; + int32_t NetConnectionPropertiesChange(sptr &netHandle, + const sptr &info) override; + int32_t NetLost(sptr &netHandle) override; + int32_t NetUnavailable() override; + int32_t NetBlockStatusChange(sptr &netHandle, bool blocked) override; + +private: + FormMgrService &fmservice_; +}; + +NetConnCallbackObserver::NetConnCallbackObserver(FormMgrService &fmservice):fmservice_(fmservice) +{ +} + +int32_t NetConnCallbackObserver::NetAvailable(sptr &netHandle) +{ + HILOG_INFO("OnNetworkAvailable"); + this->fmservice_.SetNetConnect(); + return ERR_OK; +} + +int32_t NetConnCallbackObserver::NetUnavailable() +{ + HILOG_DEBUG("OnNetworkUnavailable"); + return ERR_OK; +} + +int32_t NetConnCallbackObserver::NetCapabilitiesChange(sptr &netHandle, + const sptr &netAllCap) +{ + HILOG_DEBUG("OnNetCapabilitiesChange"); + + return ERR_OK; +} + +int32_t NetConnCallbackObserver::NetConnectionPropertiesChange(sptr &netHandle, + const sptr &info) +{ + HILOG_DEBUG("OnNetConnectionPropertiesChange"); + return ERR_OK; +} + +int32_t NetConnCallbackObserver::NetLost(sptr &netHandle) +{ + HILOG_INFO("OnNetLost"); + this->fmservice_.SetDisConnectTypeTime(); + return ERR_OK; +} + +int32_t NetConnCallbackObserver::NetBlockStatusChange(sptr &netHandle, bool blocked) +{ + HILOG_DEBUG("OnNetBlockStatusChange"); + return ERR_OK; +} + + +void FormMgrService::SubscribeNetConn() +{ + HILOG_INFO("Register SubscribeNetConn begin"); + sptr defaultNetworkCallback_ = new (std::nothrow) NetConnCallbackObserver(*this); + if (defaultNetworkCallback_ == nullptr) { + HILOG_ERROR("new operator error.observer is nullptr"); + return ; + } + int result = NetConnClient::GetInstance().RegisterNetConnCallback(defaultNetworkCallback_); + if (result == ERR_OK) { + HILOG_INFO("Register defaultNetworkCallback_ successful"); + std::list> netList; + NetConnClient::GetInstance().GetAllNets(netList); + if (netList.size() > 0) { + SetNetConnect(); + } + } else { + HILOG_ERROR("Register defaultNetworkCallback_ failed, netConTime:%{public}d", netConTime); + netConTime++; + if (netConTime > FORM_CON_NET_MAX) { + HILOG_ERROR("Register defaultNetworkCallback_ failed 10 time"); + return; + } + FormTaskMgr::GetInstance().PostConnectNetWork(); + } +} + /** * @brief initialization of form manager service. */ @@ -823,6 +921,7 @@ ErrCode FormMgrService::Init() } FormMgrAdapter::GetInstance().Init(); FormAmsHelper::GetInstance().RegisterConfigurationObserver(); + SubscribeNetConn(); return ERR_OK; } @@ -1783,5 +1882,19 @@ ErrCode FormMgrService::UpdateFormSize(const int64_t &formId, float width, float } return FormMgrAdapter::GetInstance().UpdateFormSize(formId, width, height, borderWidth); } + +void FormMgrService::SetNetConnect() +{ + int64_t currentTime = FormUtil::GetCurrentMillisecond(); + if ((currentTime - lastNetLostTime_) >= FORM_DISCON_NETWORK_CHECK_TIME) { + FormMgrAdapter::GetInstance().UpdateFormByCondition(CONDITION_NETWORK); + } +} + +void FormMgrService::SetDisConnectTypeTime() +{ + lastNetLostTime_ = FormUtil::GetCurrentMillisecond(); +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/services/src/form_provider_mgr.cpp b/services/src/form_provider_mgr.cpp index fdb478de96..68414b6ce1 100644 --- a/services/src/form_provider_mgr.cpp +++ b/services/src/form_provider_mgr.cpp @@ -120,23 +120,43 @@ ErrCode FormProviderMgr::RefreshForm(const int64_t formId, const Want &want, boo Want newWant(want); newWant.RemoveParam(Constants::KEY_IS_TIMER); - if (isCountTimerRefresh) { - FormDataMgr::GetInstance().SetCountTimerRefresh(formId, true); - } - bool isTimerRefresh = want.GetBoolParam(Constants::KEY_TIMER_REFRESH, false); + bool isConnectRefresh = want.GetBoolParam(Constants::KEY_CONNECT_REFRESH, false); newWant.RemoveParam(Constants::KEY_TIMER_REFRESH); + newWant.RemoveParam(Constants::KEY_CONNECT_REFRESH); - if (isTimerRefresh) { + int refreshType = newWant.GetIntParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_DEFAULT); + + if (isTimerRefresh || isConnectRefresh) { FormDataMgr::GetInstance().SetTimerRefresh(formId, true); bool isFormVisible = record.formVisibleNotifyState == Constants::FORM_VISIBLE; if (!isFormVisible) { HILOG_DEBUG("form is invisible"); FormDataMgr::GetInstance().SetNeedRefresh(formId, true); + FormDataMgr::GetInstance().SetRefreshType(formId, refreshType); FormRecordReport::GetInstance().IncreaseUpdateTimes(formId, HiSysEventPointType::TYPE_INVISIBLE_INTERCEPT); return ERR_OK; } } + + if (refreshType == Constants::REFRESHTYPE_VISIABLE) { + FormDataMgr::GetInstance().GetRefreshType(formId, refreshType); + HILOG_INFO("refreshType:%{public}d", refreshType); + if (refreshType == Constants::REFRESHTYPE_NETWORKCHANGED) { + isCountTimerRefresh = false; + } + } + + if (record.isSystemApp && refreshType != Constants::REFRESHTYPE_DEFAULT + && refreshType != Constants::REFRESHTYPE_VISIABLE) { + newWant.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, refreshType); + } else { + newWant.RemoveParam(Constants::PARAM_FORM_REFRESH_TYPE); + } + + if (isCountTimerRefresh) { + FormDataMgr::GetInstance().SetCountTimerRefresh(formId, true); + } #ifdef SUPPORT_POWER bool isFormProviderUpdate = want.GetBoolParam(Constants::FORM_ENABLE_UPDATE_REFRESH_KEY, false); diff --git a/services/src/form_task_mgr.cpp b/services/src/form_task_mgr.cpp index 5b24af380c..11b295c432 100644 --- a/services/src/form_task_mgr.cpp +++ b/services/src/form_task_mgr.cpp @@ -1538,5 +1538,27 @@ void FormTaskMgr::UpdateFormSize(const int64_t &formId, float width, float heigh HILOG_DEBUG("end"); } +void FormTaskMgr::PostConnectNetWork() +{ + HILOG_DEBUG("start"); + if (serialQueue_ == nullptr) { + HILOG_ERROR("null serialQueue_"); + return; + } + + auto connectNetWork = []() { + FormTaskMgr::GetInstance().ConnectNetWork(); + }; + serialQueue_->ScheduleTask(FORM_CON_NETWORK_DELAY_TIME, connectNetWork); + HILOG_DEBUG("end"); +} + +void FormTaskMgr::ConnectNetWork() +{ + HILOG_INFO("call"); + DelayedSingleton::GetInstance()->SubscribeNetConn(); +} + + } // namespace AppExecFwk } // namespace OHOS diff --git a/services/src/form_timer_mgr.cpp b/services/src/form_timer_mgr.cpp index bf04becb86..2006265875 100644 --- a/services/src/form_timer_mgr.cpp +++ b/services/src/form_timer_mgr.cpp @@ -32,6 +32,7 @@ #include "want.h" #include "form_event_report.h" #include "form_record_report.h" +#include "form_data_mgr.h" namespace OHOS { namespace AppExecFwk { @@ -114,6 +115,46 @@ bool FormTimerMgr::AddFormTimer(int64_t formId, long updateAtHour, long updateAt FormTimer timerTask(formId, updateAtHour, updateAtMin, userId); return AddFormTimer(timerTask); } + +/** + * @brief Add scheduled form timer. + * @param formId The Id of the form. + * @param updateAtTimes multi updatetime. + * @param userId User ID. + * @return Returns true on success, false on failure. + */ +bool FormTimerMgr::AddFormTimerForMultiUpdate(int64_t formId, std::vector> updateAtTimes, + int32_t userId) +{ + if (updateAtTimes.size() == 0) { + HILOG_ERROR("no multiUpdateAtTimes"); + return false; + } + bool result = true; + for (const auto &time : updateAtTimes) { + FormTimer timerTask(formId, time[0], time[1], userId); + timerTask.needUpdateAlarm = false; + result = AddFormTimer(timerTask); + if (!result) { + HILOG_ERROR("set multiUpdateAtTimes failed time[0] : %{public}d ,time[1] : %{public}d ", + (int)time[0], (int)time[1]); + return false; + } + } + + if (!UpdateLimiterAlarm()) { + HILOG_ERROR("UpdateLimiterAlarm failed"); + return false; + } + + if (!UpdateAtTimerAlarm()) { + HILOG_ERROR("updateAtTimerAlarm failed"); + return false; + } + return true; +} + + /** * @brief Remove form timer by form id. * @param formId The Id of the form. @@ -230,6 +271,19 @@ bool FormTimerMgr::UpdateAtTimerValue(int64_t formId, const FormTimerCfg &timerC changedItem.refreshTask.min = timerCfg.updateAtMin; changedItem.updateAtTime = changedItem.refreshTask.hour * Constants::MIN_PER_HOUR + changedItem.refreshTask.min; AddUpdateAtItem(changedItem); + std::vector> updateAtTimes = timerCfg.updateAtTimes; + if (updateAtTimes.size() > 0) { + bool ret = ERR_OK; + for (const auto &time: updateAtTimes) { + HILOG_INFO("time[0] : %{public}d ,time[1] : %{public}d ", (int)time[0], (int)time[1]); + UpdateAtItem changedItem_ = changedItem; + changedItem_.refreshTask.hour = time[0]; + changedItem_.refreshTask.min = time[1]; + auto updateAtTime = time[0] * Constants::MIN_PER_HOUR + time[1]; + changedItem_.updateAtTime = updateAtTime; + AddUpdateAtItem(changedItem_); + } + } } if (!UpdateAtTimerAlarm()) { @@ -266,6 +320,20 @@ bool FormTimerMgr::IntervalToAtTimer(int64_t formId, const FormTimerCfg &timerCf HILOG_ERROR("fail AddUpdateAtTimer"); return false; } + std::vector> updateAtTimes = timerCfg.updateAtTimes; + if (updateAtTimes.size() == 0) { + return true; + } + for (const auto &time: updateAtTimes) { + FormTimer timerTask_ = timerTask; + timerTask_.isUpdateAt = true; + timerTask_.hour = time[0]; + timerTask_.min = time[1]; + if (!AddUpdateAtTimer(timerTask_)) { + HILOG_ERROR("fail AddUpdateAtTimer"); + return false; + } + } return true; } else { HILOG_ERROR("intervalTimer not exist"); @@ -294,7 +362,6 @@ bool FormTimerMgr::AtTimerToIntervalTimer(int64_t formId, const FormTimerCfg &ti if (itItem->refreshTask.formId == formId) { targetItem = *itItem; updateAtTimerTasks_.erase(itItem); - break; } } } @@ -343,7 +410,14 @@ void FormTimerMgr::IncreaseRefreshCount(int64_t formId) */ bool FormTimerMgr::SetNextRefreshTime(int64_t formId, long nextGapTime, int32_t userId) { - if (nextGapTime < Constants::MIN_NEXT_TIME) { + FormRecord record; + bool bGetRecord = FormDataMgr::GetInstance().GetFormRecord(formId, record); + if (!bGetRecord) { + HILOG_ERROR("not exist such form:%{public}" PRId64 "", formId); + return false; + } + + if (!record.isSystemApp && nextGapTime < Constants::MIN_NEXT_TIME) { HILOG_ERROR("invalid nextGapTime:%{public}ld", nextGapTime); return false; } @@ -426,8 +500,9 @@ bool FormTimerMgr::AddUpdateAtTimer(const FormTimer &task) HILOG_INFO("start"); { std::lock_guard lock(updateAtMutex_); + auto updateAtTime = task.hour * Constants::MIN_PER_HOUR + task.min; for (const auto &updateAtTimer : updateAtTimerTasks_) { - if (updateAtTimer.refreshTask.formId == task.formId) { + if (updateAtTimer.refreshTask.formId == task.formId && updateAtTimer.updateAtTime == updateAtTime) { HILOG_WARN("already exist formTimer, formId:%{public}" PRId64 " task", task.formId); return true; @@ -435,18 +510,19 @@ bool FormTimerMgr::AddUpdateAtTimer(const FormTimer &task) } UpdateAtItem atItem; atItem.refreshTask = task; - atItem.updateAtTime = task.hour * Constants::MIN_PER_HOUR + task.min; + atItem.updateAtTime = updateAtTime; AddUpdateAtItem(atItem); } - if (!UpdateLimiterAlarm()) { - HILOG_ERROR("UpdateLimiterAlarm failed"); - return false; - } - - if (!UpdateAtTimerAlarm()) { - HILOG_ERROR("updateAtTimerAlarm failed"); - return false; + if (task.needUpdateAlarm) { + if (!UpdateLimiterAlarm()) { + HILOG_ERROR("UpdateLimiterAlarm failed"); + return false; + } + if (!UpdateAtTimerAlarm()) { + HILOG_ERROR("updateAtTimerAlarm failed"); + return false; + } } return refreshLimiter_.AddItem(task.formId); @@ -575,6 +651,7 @@ bool FormTimerMgr::OnUpdateAtTrigger(long updateTime) if (!updateList.empty()) { HILOG_INFO("update at timer triggered, trigger time:%{public}ld", updateTime); for (auto &item : updateList) { + item.refreshTask.refreshType = RefreshType::TYPE_UPDATETIMES; ExecTimerTask(item.refreshTask); } } @@ -619,6 +696,7 @@ bool FormTimerMgr::OnDynamicTimeTrigger(int64_t updateTime) if (!updateList.empty()) { HILOG_INFO("trigger time:%{public}" PRId64, updateTime); for (auto &task : updateList) { + task.refreshType = RefreshType::TYPE_UPDATENEXTTIME; ExecTimerTask(task); } } @@ -846,6 +924,7 @@ void FormTimerMgr::OnIntervalTimeOut() if (!updateList.empty()) { for (auto &task : updateList) { + task.refreshType = RefreshType::TYPE_INTERVAL; ExecTimerTask(task); } } @@ -1409,6 +1488,15 @@ void FormTimerMgr::ExecTimerTask(const FormTimer &timerTask) HILOG_BRIEF("timerTask.userId is current user"); want.SetParam(Constants::PARAM_FORM_USER_ID, timerTask.userId); } + if (timerTask.refreshType == RefreshType::TYPE_INTERVAL) { + want.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_INTERVAL); + } else if (timerTask.refreshType == RefreshType::TYPE_UPDATETIMES) { + want.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_UPDATETIMES); + } else if (timerTask.refreshType == RefreshType::TYPE_UPDATENEXTTIME) { + want.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_UPDATENEXTTIME); + } else if (timerTask.refreshType == RefreshType::TYPE_VISIABLE) { + want.SetParam(Constants::PARAM_FORM_REFRESH_TYPE, Constants::REFRESHTYPE_VISIABLE); + } HILOG_BRIEF("userId:%{public}d", timerTask.userId); auto task = [id = timerTask.formId, want]() { FormProviderMgr::GetInstance().RefreshForm(id, want, false); @@ -1419,6 +1507,7 @@ void FormTimerMgr::ExecTimerTask(const FormTimer &timerTask) void FormTimerMgr::RefreshWhenFormVisible(const int64_t &formId, const int32_t &userId) { FormTimer timerTask(formId, true, userId); + timerTask.refreshType = RefreshType::TYPE_VISIABLE; ExecTimerTask(timerTask); } diff --git a/test/fuzztest/formdatamgrtwo_fuzzer/formdatamgrtwo_fuzzer.cpp b/test/fuzztest/formdatamgrtwo_fuzzer/formdatamgrtwo_fuzzer.cpp index 4b8d0fbc8a..e00aa14d2a 100644 --- a/test/fuzztest/formdatamgrtwo_fuzzer/formdatamgrtwo_fuzzer.cpp +++ b/test/fuzztest/formdatamgrtwo_fuzzer/formdatamgrtwo_fuzzer.cpp @@ -65,7 +65,10 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) long updateDuration = static_cast(GetU32Data(data)); int updateAtHour = static_cast(GetU32Data(data)); int updateAtMin = static_cast(GetU32Data(data)); - formDataMgr.SetUpdateInfo(formId, enableUpdate, updateDuration, updateAtHour, updateAtMin); + std::vector> updateAtTimes; + std::vector newElement = {updateAtHour, updateAtMin}; + updateAtTimes.push_back(newElement); + formDataMgr.SetUpdateInfo(formId, enableUpdate, updateDuration, updateAtHour, updateAtMin, updateAtTimes); formDataMgr.IsSameForm(records, updatedForm); std::string bundleName(data, size); std::set removedForms; diff --git a/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp b/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp index 68d0c1e6d8..2cd6a60af6 100644 --- a/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp +++ b/test/unittest/fms_form_data_mgr_test/fms_form_data_mgr_test.cpp @@ -1523,10 +1523,12 @@ HWTEST_F(FmsFormDataMgrTest, FmsFormDataMgrTest_SetUpdateInfo_001, TestSize.Leve long updateDuration = 100; int updateAtHour = 24; int updateAtMin = 59; - + std::vector> updateAtTimes; + std::vector newElement = {updateAtHour, updateAtMin}; + updateAtTimes.push_back(newElement); std::shared_ptr formDataMgr = std::make_shared(); ASSERT_NE(nullptr, formDataMgr); - formDataMgr->SetUpdateInfo(formId, enableUpdate, updateDuration, updateAtHour, updateAtMin); + formDataMgr->SetUpdateInfo(formId, enableUpdate, updateDuration, updateAtHour, updateAtMin, updateAtTimes); GTEST_LOG_(INFO) << "FmsFormDataMgrTest_SetUpdateInfo_001 end"; } @@ -1547,7 +1549,9 @@ HWTEST_F(FmsFormDataMgrTest, FmsFormDataMgrTest_SetUpdateInfo_002, TestSize.Leve long updateDuration = 100; int updateAtHour = 24; int updateAtMin = 59; - + std::vector> updateAtTimes; + std::vector newElement = {updateAtHour, updateAtMin}; + updateAtTimes.push_back(newElement); // create formRecords int callingUid = 0; FormItemInfo formItemInfo; @@ -1555,7 +1559,7 @@ HWTEST_F(FmsFormDataMgrTest, FmsFormDataMgrTest_SetUpdateInfo_002, TestSize.Leve FormRecord record = formDataMgr_.CreateFormRecord(formItemInfo, callingUid); formDataMgr_.formRecords_.emplace(formId, record); - formDataMgr_.SetUpdateInfo(formId, enableUpdate, updateDuration, updateAtHour, updateAtMin); + formDataMgr_.SetUpdateInfo(formId, enableUpdate, updateDuration, updateAtHour, updateAtMin, updateAtTimes); EXPECT_EQ(true, formDataMgr_.formRecords_.find(formId)->second.isEnableUpdate); EXPECT_EQ(100, formDataMgr_.formRecords_.find(formId)->second.updateDuration); EXPECT_EQ(24, formDataMgr_.formRecords_.find(formId)->second.updateAtHour); -- Gitee