diff --git a/services/formmgr/BUILD.gn b/services/formmgr/BUILD.gn old mode 100644 new mode 100755 index a05731a41cca55c0b96532b25a3929b6416c9498..a120dc034d202ccb8e3524598e0afc2bd09290b1 --- a/services/formmgr/BUILD.gn +++ b/services/formmgr/BUILD.gn @@ -66,6 +66,7 @@ ohos_shared_library("libfms") { "src/form_task_mgr.cpp", "src/form_timer_mgr.cpp", "src/form_util.cpp", + "src/kvstore_death_recipient_callback.cpp", ] defines = [ @@ -88,6 +89,7 @@ ohos_shared_library("libfms") { "//base/miscservices/time/services:time_service", "//base/notification/ans_standard/frameworks/wantagent:wantagent_innerkits", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr:distributedschedsvr", + "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata:distributeddata_inner", "//utils/native/base:utils", # "//third_party/libuuid:libuuid_static", diff --git a/services/formmgr/include/form_db_cache.h b/services/formmgr/include/form_db_cache.h old mode 100644 new mode 100755 index 1be4e0fdd20955967e5fa78c2d968495ba37bf4c..786723efe36c067d9c2440eb2411555b3e30be21 --- a/services/formmgr/include/form_db_cache.h +++ b/services/formmgr/include/form_db_cache.h @@ -17,6 +17,7 @@ #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_DB_CACHE_H #include +#include #include #include @@ -111,8 +112,10 @@ public: * @return Returns match count. */ int GetMatchCount(const std::string &bundleName, const std::string &moduleName); + + std::shared_ptr GetDataStorage() const; private: - std::unique_ptr dataStorage_; + std::shared_ptr dataStorage_; mutable std::mutex formDBInfosMutex_; std::vector formDBInfos_; }; diff --git a/services/formmgr/include/form_db_info.h b/services/formmgr/include/form_db_info.h old mode 100644 new mode 100755 index 6ec95d79d32c9ff218557adb54738ba2b6035dd7..0f6306174227aa28923f6beb39263c07874ea6cd --- a/services/formmgr/include/form_db_info.h +++ b/services/formmgr/include/form_db_info.h @@ -149,6 +149,17 @@ public: formDBInfo_.abilityName = formRecord.abilityName; formDBInfo_.formUserUids = formRecord.formUserUids; } + std::string ToString() const + { + nlohmann::json j; + j["formId"] = formDBInfo_.formId; + j["formName"] = formDBInfo_.formName; + j["bundleName"] = formDBInfo_.bundleName; + j["moduleName"] = formDBInfo_.moduleName; + j["abilityName"] = formDBInfo_.abilityName; + j["formUserUids"] = formDBInfo_.formUserUids; + return j.dump(); + } /** * @brief Destructor * diff --git a/services/formmgr/include/form_storage_mgr.h b/services/formmgr/include/form_storage_mgr.h index ac3e13e5f3a91aaccfdaa6ebf98730436bc28848..d3db9084ad70b14a3a16d0c1776c8bb95a464a76 100644 --- a/services/formmgr/include/form_storage_mgr.h +++ b/services/formmgr/include/form_storage_mgr.h @@ -22,6 +22,7 @@ #include #include "appexecfwk_errors.h" +#include "distributed_kv_data_manager.h" #include "form_db_info.h" namespace OHOS { @@ -32,42 +33,61 @@ namespace AppExecFwk { */ class FormStorageMgr { public: - FormStorageMgr() = default; - virtual ~FormStorageMgr() = default; + FormStorageMgr(); + virtual ~FormStorageMgr(); /** * @brief Load all form data from DB to innerFormInfos. * @param innerFormInfos Storage all form data. * @return Returns ERR_OK on success, others on failure. */ - ErrCode LoadFormData(std::vector &innerFormInfos) const; + ErrCode LoadFormData(std::vector &innerFormInfos); /** * @brief Get form data from DB to innerFormInfo with formId. * @param innerFormInfo Storage form data. * @return Returns ERR_OK on success, others on failure. */ - ErrCode GetStorageFormInfoById(const std::string &formId, InnerFormInfo &innerFormInfo) const; + ErrCode GetStorageFormInfoById(const std::string &formId, InnerFormInfo &innerFormInfo); /** * @brief Save or update the form data in DB. * @param innerFormInfo Indicates the InnerFormInfo object to be save. * @return Returns ERR_OK on success, others on failure. */ - ErrCode SaveStorageFormInfo(const InnerFormInfo &innerFormInfo) const; + ErrCode SaveStorageFormInfo(const InnerFormInfo &innerFormInfo); /** * @brief Modify the form data in DB. * @param innerFormInfo Indicates the InnerFormInfo object to be Modify. * @return Returns ERR_OK on success, others on failure. */ - ErrCode ModifyStorageFormInfo(const InnerFormInfo &innerFormInfo) const; + ErrCode ModifyStorageFormInfo(const InnerFormInfo &innerFormInfo); /** * @brief Delete the form data in DB. * @param formId The form data Id. * @return Returns ERR_OK on success, others on failure. */ - ErrCode DeleteStorageFormInfo(const std::string &formId) const; + ErrCode DeleteStorageFormInfo(const std::string &formId); + + void RegisterKvStoreDeathListener(); + bool ResetKvStore(); + +private: + void SaveEntries( + const std::vector &allEntries, std::vector &innerFormInfos); + DistributedKv::Status GetEntries(std::vector &allEntries); + void TryTwice(const std::function &func); + bool CheckKvStore(); + DistributedKv::Status GetKvStore(); + +private: + const DistributedKv::AppId appId_ {"form_manager_service"}; + const DistributedKv::StoreId storeId_ {"installed_form_datas"}; + DistributedKv::DistributedKvDataManager dataManager_; + std::unique_ptr kvStorePtr_; + // std::shared_ptr dataChangeListener_; + mutable std::mutex kvStorePtrMutex_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/include/kvstore_death_recipient_callback.h b/services/formmgr/include/kvstore_death_recipient_callback.h new file mode 100755 index 0000000000000000000000000000000000000000..084b35ca7112cbbfafb9a7a4889daf3866486c28 --- /dev/null +++ b/services/formmgr/include/kvstore_death_recipient_callback.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_KVSTORE_DEATH_RECIPIENT_CALLBACK_H +#define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_KVSTORE_DEATH_RECIPIENT_CALLBACK_H + +#include "kvstore_death_recipient.h" + +namespace OHOS { +namespace AppExecFwk { + +class KvStoreDeathRecipientCallback : public DistributedKv::KvStoreDeathRecipient { +public: + KvStoreDeathRecipientCallback(); + virtual ~KvStoreDeathRecipientCallback(); + + virtual void OnRemoteDied() override; + +}; + +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_KVSTORE_DEATH_RECIPIENT_CALLBACK_H \ No newline at end of file diff --git a/services/formmgr/src/form_db_cache.cpp b/services/formmgr/src/form_db_cache.cpp old mode 100644 new mode 100755 index 1625e676ecb3846927d9455dcf13606a3ee893f5..7bf3fbe519b9d4dbcbd25d369c7f7724cbe6f779 --- a/services/formmgr/src/form_db_cache.cpp +++ b/services/formmgr/src/form_db_cache.cpp @@ -26,7 +26,7 @@ namespace AppExecFwk { FormDbCache::FormDbCache() { APP_LOGI("FormDbCache is created"); - dataStorage_ = std::make_unique(); + dataStorage_ = std::make_shared(); formDBInfos_.clear(); } @@ -277,5 +277,10 @@ int FormDbCache::GetMatchCount(const std::string &bundleName, const std::string } return matchCount; } + +std::shared_ptr FormDbCache::GetDataStorage() const +{ + return dataStorage_; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/src/form_mgr_adapter.cpp b/services/formmgr/src/form_mgr_adapter.cpp old mode 100644 new mode 100755 index 7a065d01b67eca51604355265756ee6840967f2c..6aa23be1f1c12e3a6d86197b28ea76d95ea9b3e8 --- a/services/formmgr/src/form_mgr_adapter.cpp +++ b/services/formmgr/src/form_mgr_adapter.cpp @@ -70,7 +70,7 @@ int FormMgrAdapter::AddForm(const int64_t formId, const Want &want, // check form count limit bool tempFormFlag = want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false); int callingUid = IPCSkeleton::GetCallingUid(); - int checkCode; + int checkCode = 0; if (tempFormFlag) { if (formId > 0) { APP_LOGE("%{public}s fail, temp form id is invalid, formId:%{public}" PRId64 "", __func__, formId); @@ -78,7 +78,9 @@ int FormMgrAdapter::AddForm(const int64_t formId, const Want &want, } checkCode = FormDataMgr::GetInstance().CheckTempEnoughForm(); } else { - checkCode = FormDataMgr::GetInstance().CheckEnoughForm(callingUid); + if (formId == 0) { + checkCode = FormDataMgr::GetInstance().CheckEnoughForm(callingUid); + } } if (checkCode != 0) { APP_LOGE("%{public}s fail, too much forms in system", __func__); @@ -391,12 +393,6 @@ int FormMgrAdapter::UpdateForm(const int64_t formId, return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; } - // check then form under current user - if (!FormDataMgr::GetInstance().IsCallingUidValid(formRecord.formUserUids)) { - APP_LOGE("%{public}s error, not under current user, formId:%{public}" PRId64 ".", __func__, matchedFormId); - return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; - } - // check bundleName match if (formRecord.bundleName.compare(bundleName) != 0) { APP_LOGE("%{public}s error, not match bundleName:%{public}s.", __func__, bundleName.c_str()); diff --git a/services/formmgr/src/form_mgr_service.cpp b/services/formmgr/src/form_mgr_service.cpp old mode 100644 new mode 100755 index 948c33d0d8b810c1408f5ee7cb5e518200e9d614..2b406424d407a98e583507dbcb8f31dcd6785fe1 --- a/services/formmgr/src/form_mgr_service.cpp +++ b/services/formmgr/src/form_mgr_service.cpp @@ -136,10 +136,6 @@ int FormMgrService::ReleaseForm(const int64_t formId, const sptr int FormMgrService::UpdateForm(const int64_t formId, const std::string &bundleName, const FormProviderData &formBindingData) { - if (!CheckFormPermission()) { - APP_LOGE("%{public}s fail, update form permission denied", __func__); - return ERR_APPEXECFWK_FORM_PERMISSION_DENY; - } return FormMgrAdapter::GetInstance().UpdateForm(formId, bundleName, formBindingData); } diff --git a/services/formmgr/src/form_provider_mgr.cpp b/services/formmgr/src/form_provider_mgr.cpp old mode 100644 new mode 100755 index 3712752d68c9a9de0f26899d66461897b5eea5a2..a0a4ff72b60c05693c64dda75c74ef2a8f995004 --- a/services/formmgr/src/form_provider_mgr.cpp +++ b/services/formmgr/src/form_provider_mgr.cpp @@ -310,6 +310,8 @@ ErrCode FormProviderMgr::UpdateForm(const int64_t formId, if (jsonData.size() <= Constants::MAX_FORM_DATA_SIZE) { APP_LOGI("%{public}s, updateJsForm, data is less than 1k, cache data.", __func__); FormCacheMgr::GetInstance().AddData(formId, jsonData); + } else { + FormCacheMgr::GetInstance().DeleteData(formId); } // the update form is successfully diff --git a/services/formmgr/src/form_storage_mgr.cpp b/services/formmgr/src/form_storage_mgr.cpp index 58157a1d550ee79f488a2f2cd52de155dfb73d1a..f3bf4bfa4e49591670960ed155b72893763ab2de 100644 --- a/services/formmgr/src/form_storage_mgr.cpp +++ b/services/formmgr/src/form_storage_mgr.cpp @@ -22,55 +22,70 @@ #include #include #include +#include #include "securec.h" #include "app_log_wrapper.h" #include "form_storage_mgr.h" +#include "kvstore_death_recipient_callback.h" #include "string_ex.h" +#include "types.h" namespace OHOS { namespace AppExecFwk { namespace { -const char* FORM_DB_DATA_BASE_FILE_DIR = "/data/formmgr"; -const int32_t FORM_DB_DATA_BASE_FILE_PATH_LEN = 255; +const int32_t MAX_TIMES = 600; // 1min +const int32_t SLEEP_INTERVAL = 100 * 1000; // 100ms +} // namespace + +FormStorageMgr::FormStorageMgr() +{ + APP_LOGI("instance:%{private}p is created", this); + TryTwice([this] { return GetKvStore(); }); + RegisterKvStoreDeathListener(); } -/** - * @brief Load form data from fileNamePath to innerFormInfos. - * @param fileNamePath load file path. - * @param innerFormInfos Save form data. - * @return Returns true if the data is successfully loaded; returns false otherwise. - */ -static bool LoadFormDataFile(const char* fileNamePath, std::vector &innerFormInfos) +FormStorageMgr::~FormStorageMgr() { - bool ret = false; - std::ifstream i(fileNamePath); - if (!i.is_open()) { - APP_LOGE("%{public}s, failed to open file[%{public}s]", __func__, fileNamePath); - return false; - } + APP_LOGI("instance:%{private}p is destroyed", this); + dataManager_.CloseKvStore(appId_, std::move(kvStorePtr_)); +} - nlohmann::json jParse; - i.seekg(0, std::ios::end); - int len = static_cast(i.tellg()); - if (len != 0) { - i.seekg(0, std::ios::beg); - i >> jParse; - for (auto &it : jParse.items()) { - InnerFormInfo innerFormInfo; - if (innerFormInfo.FromJson(it.value())) { - innerFormInfos.emplace_back(innerFormInfo); - } else { - APP_LOGE("%{public}s, failed to parse json, formId[%{public}s]", __func__, it.key().c_str()); +void FormStorageMgr::SaveEntries( + const std::vector &allEntries, std::vector &innerFormInfos) +{ + for (const auto &item : allEntries) { + std::string formId; + InnerFormInfo innerFormInfo; + + nlohmann::json jsonObject = nlohmann::json::parse(item.value.ToString(), nullptr, false); + if (jsonObject.is_discarded()) { + APP_LOGE("error key: %{private}s", item.key.ToString().c_str()); + // it's an bad json, delete it + { + std::lock_guard lock(kvStorePtrMutex_); + kvStorePtr_->Delete(item.key); } + continue; + } + if (innerFormInfo.FromJson(jsonObject) != ERR_OK) { + APP_LOGE("error key: %{private}s", item.key.ToString().c_str()); + // it's an error value, delete it + { + std::lock_guard lock(kvStorePtrMutex_); + kvStorePtr_->Delete(item.key); + } + continue; + } + + if (std::find(innerFormInfos.begin(),innerFormInfos.end(),innerFormInfo) == innerFormInfos.end()) { + APP_LOGD("emplace FormInfos: %{public}s", formId.c_str()); + std::map allDevicesInfos; + allDevicesInfos.emplace(formId, innerFormInfo); + innerFormInfos.emplace_back(innerFormInfo); } - ret = true; - } else { - APP_LOGE("%{public}s, file[%{public}s] is empty", __func__, fileNamePath); - ret = false; } - i.close(); - return ret; + APP_LOGD("SaveEntries end"); } /** @@ -78,35 +93,33 @@ static bool LoadFormDataFile(const char* fileNamePath, std::vector &innerFormInfos) const +ErrCode FormStorageMgr::LoadFormData(std::vector &innerFormInfos) { APP_LOGI("%{public}s called.", __func__); - DIR *dirptr = opendir(FORM_DB_DATA_BASE_FILE_DIR); - if (dirptr == NULL) { - APP_LOGE("%{public}s, opendir failed, should no formmgr dir", __func__); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - - struct dirent *ptr; - while ((ptr = readdir(dirptr)) != NULL) { - APP_LOGI("%{public}s, readdir fileName[%{public}s]", __func__, ptr->d_name); - if ((strcmp(ptr->d_name, ".") == 0) || (strcmp(ptr->d_name, "..") == 0)) { - continue; - } - char fileNamePath[FORM_DB_DATA_BASE_FILE_PATH_LEN] = {0}; - if (sprintf_s(fileNamePath, FORM_DB_DATA_BASE_FILE_PATH_LEN, "%s/%s", - FORM_DB_DATA_BASE_FILE_DIR, ptr->d_name) < 0) { - APP_LOGE("%{public}s,strcat fileNamePath path fail", __func__); - closedir(dirptr); + bool ret = ERR_OK; + { + std::lock_guard lock(kvStorePtrMutex_); + if (!CheckKvStore()) { + APP_LOGE("kvStore is nullptr"); return ERR_APPEXECFWK_FORM_COMMON_CODE; } - if (!LoadFormDataFile(fileNamePath, innerFormInfos)) { - APP_LOGE("%{public}s, LoadFormDataFile failed, file[%{public}s]", __func__, ptr->d_name); - } } + DistributedKv::Status status; + std::vector allEntries; + TryTwice([this, &status, &allEntries] { + status = GetEntries(allEntries); + return status; + }); + + if (status != DistributedKv::Status::SUCCESS) { + APP_LOGE("get entries error: %{public}d", status); + ret = ERR_APPEXECFWK_FORM_COMMON_CODE; + } else { + SaveEntries(allEntries, innerFormInfos); + } + APP_LOGI("%{public}s, readdir over", __func__); - closedir(dirptr); - return ERR_OK; + return ret; } /** @@ -114,45 +127,38 @@ ErrCode FormStorageMgr::LoadFormData(std::vector &innerFormInfos) * @param innerFormInfo Storage form data. * @return Returns ERR_OK on success, others on failure. */ -ErrCode FormStorageMgr::GetStorageFormInfoById(const std::string &formId, InnerFormInfo &innerFormInfo) const +ErrCode FormStorageMgr::GetStorageFormInfoById(const std::string &formId, InnerFormInfo &innerFormInfo) { ErrCode ret = ERR_OK; APP_LOGD("%{public}s called, formId[%{public}s]", __func__, formId.c_str()); - char fileNamePath[FORM_DB_DATA_BASE_FILE_PATH_LEN] = {0}; - if (sprintf_s(fileNamePath, FORM_DB_DATA_BASE_FILE_PATH_LEN, "%s/%s.json", - FORM_DB_DATA_BASE_FILE_DIR, formId.c_str()) < 0) { - APP_LOGE("%{public}s,strcat fileNamePath path fail", __func__); - return ERR_APPEXECFWK_FORM_COMMON_CODE; + + DistributedKv::Status status = DistributedKv::Status::ERROR; + std::vector allEntries; + DistributedKv::Key key(formId); + if (kvStorePtr_) { + // sync call GetEntries, the callback will be trigger at once + status = kvStorePtr_->GetEntries(key, allEntries); } - std::ifstream i(fileNamePath); - nlohmann::json jParse; - if (!i.is_open()) { - APP_LOGE("%{public}s, open failed, should no this file[%{public}s.json]", __func__, formId.c_str()); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - APP_LOGD("%{public}s, open success file[%{public}s.json]", __func__, formId.c_str()); - i.seekg(0, std::ios::end); - int len = static_cast(i.tellg()); - if (len != 0) { - i.seekg(0, std::ios::beg); - i >> jParse; - auto it = jParse.find(formId); - if (it != jParse.end()) { - if (innerFormInfo.FromJson(it.value()) == false) { - APP_LOGE("%{public}s, fromJson parse failed formId[%{public}s]", __func__, it.key().c_str()); + + if (status != DistributedKv::Status::SUCCESS) { + APP_LOGE("get entries error: %{public}d", status); + ret = ERR_APPEXECFWK_FORM_COMMON_CODE; + } else { + if(allEntries.empty()){ + APP_LOGE("%{public}s not match any FormInfo", formId.c_str()); + ret = ERR_APPEXECFWK_FORM_COMMON_CODE; + }else{ + nlohmann::json jsonObject = nlohmann::json::parse(allEntries.front().value.ToString(), nullptr, false); + if (jsonObject.is_discarded()) { + APP_LOGE("error key: %{private}s", allEntries.front().key.ToString().c_str()); + ret = ERR_APPEXECFWK_FORM_COMMON_CODE; + } + if (innerFormInfo.FromJson(jsonObject) != ERR_OK) { + APP_LOGE("error key: %{private}s", allEntries.front().key.ToString().c_str()); ret = ERR_APPEXECFWK_FORM_COMMON_CODE; - } else { - ret = ERR_OK; } - } else { - APP_LOGE("%{public}s, not find formId[%{public}s]", __func__, formId.c_str()); - ret = ERR_APPEXECFWK_FORM_COMMON_CODE; } - } else { - APP_LOGE("%{public}s, file is empty formId[%{public}s]", __func__, formId.c_str()); - ret = ERR_APPEXECFWK_FORM_COMMON_CODE; } - i.close(); return ret; } @@ -162,58 +168,35 @@ ErrCode FormStorageMgr::GetStorageFormInfoById(const std::string &formId, InnerF * @param innerFormInfo Indicates the InnerFormInfo object to be save. * @return Returns ERR_OK on success, others on failure. */ -ErrCode FormStorageMgr::SaveStorageFormInfo(const InnerFormInfo &innerFormInfo) const +ErrCode FormStorageMgr::SaveStorageFormInfo(const InnerFormInfo &innerFormInfo) { APP_LOGI("%{public}s called, formId[%{public}" PRId64 "]", __func__, innerFormInfo.GetFormId()); ErrCode ret = ERR_OK; std::string formId = std::to_string(innerFormInfo.GetFormId()); - DIR *dirptr = opendir(FORM_DB_DATA_BASE_FILE_DIR); - if (dirptr == NULL) { - APP_LOGW("%{public}s, failed to open dir", __func__); - if (-1 == mkdir(FORM_DB_DATA_BASE_FILE_DIR, S_IRWXU)) { - APP_LOGE("%{public}s, failed to create dir", __func__); + { + std::lock_guard lock(kvStorePtrMutex_); + if (!CheckKvStore()) { + APP_LOGE("kvStore is nullptr"); return ERR_APPEXECFWK_FORM_COMMON_CODE; } - } else { - closedir(dirptr); } - char tmpFilePath[FORM_DB_DATA_BASE_FILE_PATH_LEN] = {0}; - if (sprintf_s(tmpFilePath, FORM_DB_DATA_BASE_FILE_PATH_LEN, "%s/%s.json", - FORM_DB_DATA_BASE_FILE_DIR, formId.c_str()) < 0) { - APP_LOGE("%{public}s,strcat tmpFilePath path fail", __func__); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - std::fstream f(tmpFilePath); - nlohmann::json jParse; - if (!f.is_open()) { - std::ofstream o(tmpFilePath); // if file not exist, should create file here - if (!o.is_open()) { - APP_LOGE("%{public}s, touch new file[%{public}s] failed", __func__, tmpFilePath); - return ERR_APPEXECFWK_FORM_COMMON_CODE; + + DistributedKv::Key key(formId); + DistributedKv::Value value(innerFormInfo.ToString()); + DistributedKv::Status status; + { + std::lock_guard lock(kvStorePtrMutex_); + status = kvStorePtr_->Put(key, value); + if (status == DistributedKv::Status::IPC_ERROR) { + status = kvStorePtr_->Put(key, value); + APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); } - o.close(); - APP_LOGI("%{public}s, touch new file[%{public}s.json]", __func__, formId.c_str()); - f.open(tmpFilePath); } - bool isExist = f.good(); - if (isExist) { - nlohmann::json innerInfo; - innerFormInfo.ToJson(innerInfo); - f.seekg(0, std::ios::end); - int len = static_cast(f.tellg()); - if (len == 0) { - nlohmann::json formRoot; - formRoot[formId] = innerInfo; - f << formRoot << std::endl; - } else { - APP_LOGE("%{public}s, file[%{public}s.json] is not empty", __func__, formId.c_str()); - } - } else { - APP_LOGE("%{public}s, touch new file[%{public}s] failed", __func__, formId.c_str()); + if (status != DistributedKv::Status::SUCCESS) { + APP_LOGE("put innerFormInfo to kvStore error: %{public}d", status); ret = ERR_APPEXECFWK_FORM_COMMON_CODE; } - f.close(); return ret; } @@ -222,32 +205,18 @@ ErrCode FormStorageMgr::SaveStorageFormInfo(const InnerFormInfo &innerFormInfo) * @param innerFormInfo Indicates the InnerFormInfo object to be Modify. * @return Returns ERR_OK on success, others on failure. */ -ErrCode FormStorageMgr::ModifyStorageFormInfo(const InnerFormInfo &innerFormInfo) const +ErrCode FormStorageMgr::ModifyStorageFormInfo(const InnerFormInfo &innerFormInfo) { APP_LOGI("%{public}s called, formId[%{public}" PRId64 "]", __func__, innerFormInfo.GetFormId()); - char fileNamePath[FORM_DB_DATA_BASE_FILE_PATH_LEN] = {0}; - if (sprintf_s(fileNamePath, FORM_DB_DATA_BASE_FILE_PATH_LEN, "%s/%" PRId64 ".json", - FORM_DB_DATA_BASE_FILE_DIR, innerFormInfo.GetFormId()) < 0) { - APP_LOGE("%{public}s,strcat fileNamePath path fail", __func__); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - - std::ofstream o(fileNamePath, std::ios_base::trunc | std::ios_base::out); - if (!o.is_open()) { - APP_LOGE("%{public}s, open failed file[%{public}s]", __func__, fileNamePath); - return ERR_APPEXECFWK_FORM_COMMON_CODE; - } - nlohmann::json innerInfo; - innerFormInfo.ToJson(innerInfo); - nlohmann::json formRoot; + ErrCode ret = ERR_OK; std::string formId = std::to_string(innerFormInfo.GetFormId()); - - formRoot[formId] = innerInfo; - o << formRoot << std::endl; - - o.close(); - return ERR_OK; + ret = DeleteStorageFormInfo(formId); + if(ret == ERR_OK){ + SaveStorageFormInfo(innerFormInfo); + } + + return ret; } /** @@ -255,22 +224,123 @@ ErrCode FormStorageMgr::ModifyStorageFormInfo(const InnerFormInfo &innerFormInfo * @param formId The form data Id. * @return Returns ERR_OK on success, others on failure. */ -ErrCode FormStorageMgr::DeleteStorageFormInfo(const std::string &formId) const +ErrCode FormStorageMgr::DeleteStorageFormInfo(const std::string &formId) { APP_LOGI("%{public}s called, formId[%{public}s]", __func__, formId.c_str()); - char fileNamePath[FORM_DB_DATA_BASE_FILE_PATH_LEN] = {0}; - if (sprintf_s(fileNamePath, FORM_DB_DATA_BASE_FILE_PATH_LEN, "%s/%s.json", - FORM_DB_DATA_BASE_FILE_DIR, formId.c_str()) < 0) { - APP_LOGE("%{public}s,strcat fileNamePath path fail", __func__); - return ERR_APPEXECFWK_FORM_COMMON_CODE; + + { + std::lock_guard lock(kvStorePtrMutex_); + if (!CheckKvStore()) { + APP_LOGE("kvStore is nullptr"); + return ERR_APPEXECFWK_FORM_COMMON_CODE; + } + } + DistributedKv::Key key(formId); + DistributedKv::Status status; + + { + std::lock_guard lock(kvStorePtrMutex_); + status = kvStorePtr_->Delete(key); + if (status == DistributedKv::Status::IPC_ERROR) { + status = kvStorePtr_->Delete(key); + APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); + } } - if (std::remove(fileNamePath) != 0) { - APP_LOGE("%{public}s, delete failed file[%{public}s]", __func__, fileNamePath); + if (status != DistributedKv::Status::SUCCESS) { + APP_LOGE("delete key error: %{public}d", status); return ERR_APPEXECFWK_FORM_COMMON_CODE; + } else { + APP_LOGE("delete value to kvStore success"); } return ERR_OK; } + +void FormStorageMgr::RegisterKvStoreDeathListener() +{ + APP_LOGI("register kvStore death listener"); + std::shared_ptr callback = + std::make_shared(); + dataManager_.RegisterKvStoreServiceDeathRecipient(callback); +} + +bool FormStorageMgr::CheckKvStore() +{ + if (kvStorePtr_ != nullptr) { + return true; + } + int32_t tryTimes = MAX_TIMES; + while (tryTimes > 0) { + DistributedKv::Status status = GetKvStore(); + if (status == DistributedKv::Status::SUCCESS && kvStorePtr_ != nullptr) { + return true; + } + APP_LOGD("CheckKvStore, Times: %{public}d", tryTimes); + usleep(SLEEP_INTERVAL); + tryTimes--; + } + return kvStorePtr_ != nullptr; +} + +DistributedKv::Status FormStorageMgr::GetKvStore() +{ + DistributedKv::Status status; + DistributedKv::Options options = { + .createIfMissing = true, + .encrypt = false, + .autoSync = true, + .kvStoreType = DistributedKv::KvStoreType::SINGLE_VERSION + }; + + dataManager_.GetSingleKvStore( + options, appId_, storeId_, [this, &status](DistributedKv::Status paramStatus, std::unique_ptr singleKvStore) { + status = paramStatus; + if (status != DistributedKv::Status::SUCCESS) { + APP_LOGE("return error: %{public}d", status); + return; + } + { + kvStorePtr_ = std::move(singleKvStore); + } + APP_LOGI("get kvStore success"); + }); + + return status; +} + +DistributedKv::Status FormStorageMgr::GetEntries(std::vector &allEntries) +{ + DistributedKv::Status status = DistributedKv::Status::ERROR; + // if prefix is empty, get all entries. + DistributedKv::Key key(""); + if (kvStorePtr_) { + // sync call GetEntries, the callback will be trigger at once + status = kvStorePtr_->GetEntries(key, allEntries); + } + APP_LOGI("get all entries status: %{public}d", status); + return status; +} + +void FormStorageMgr::TryTwice(const std::function &func) +{ + DistributedKv::Status status = func(); + if (status == DistributedKv::Status::IPC_ERROR) { + status = func(); + APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); + } +} + +bool FormStorageMgr::ResetKvStore() +{ + std::lock_guard lock(kvStorePtrMutex_); + kvStorePtr_ = nullptr; + DistributedKv::Status status = GetKvStore(); + if (status == DistributedKv::Status::SUCCESS && kvStorePtr_ != nullptr) { + return true; + } + APP_LOGW("failed"); + return false; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/src/kvstore_death_recipient_callback.cpp b/services/formmgr/src/kvstore_death_recipient_callback.cpp new file mode 100755 index 0000000000000000000000000000000000000000..6c28300f5d8bcca019d03355306b274a2dc70a8c --- /dev/null +++ b/services/formmgr/src/kvstore_death_recipient_callback.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "kvstore_death_recipient_callback.h" + +#include +#include + +#include "app_log_wrapper.h" +#include "form_db_cache.h" + +using namespace OHOS::DistributedKv; + +namespace OHOS { +namespace AppExecFwk { +namespace { + +const int32_t CHECK_TIMES = 300; +const int32_t CHECK_INTERVAL = 100000; // 100ms + +} // namespace + +KvStoreDeathRecipientCallback::KvStoreDeathRecipientCallback() +{ + APP_LOGI("create kvstore death recipient callback instance %{public}p", this); +} + +KvStoreDeathRecipientCallback::~KvStoreDeathRecipientCallback() +{ + APP_LOGI("destroy kvstore death recipient callback instance %{public}p", this); +} + +void KvStoreDeathRecipientCallback::OnRemoteDied() +{ + APP_LOGI("OnRemoteDied, register data change listener begin"); + + auto dataStorage = FormDbCache::GetInstance().GetDataStorage(); + if (!dataStorage) { + APP_LOGE("dataStorage is nullptr"); + return; + } + + std::thread([dataStorage] { + int32_t times = 0; + while (times < CHECK_TIMES) { + times++; + // init kvStore. + if (dataStorage && dataStorage->ResetKvStore()) { + // register data change listener again. + APP_LOGI("current times is %{public}d", times); + break; + } + usleep(CHECK_INTERVAL); + } + }).detach(); + + APP_LOGI("OnRemoteDied, register data change listener end"); +} + +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h old mode 100644 new mode 100755 diff --git a/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn old mode 100644 new mode 100755 index 22051724cddd4a3f0ed2b4003a9a82044edd5b23..8654a7dfab9c0eaece3d5311738ca932de154651 --- a/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_db_record_test/BUILD.gn @@ -35,6 +35,7 @@ ohos_unittest("FmsFormDbRecordTest") { #"//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler/include", + "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata/include", ] configs = [ diff --git a/services/formmgr/test/unittest/fms_form_host_record_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_host_record_test/BUILD.gn old mode 100644 new mode 100755 index 8f7fc495b49e59f90b2a875e85a937b0ffe78340..a6cc3f35586468b0ef62d8cce98c5daff423cdb6 --- a/services/formmgr/test/unittest/fms_form_host_record_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_host_record_test/BUILD.gn @@ -40,6 +40,7 @@ ohos_unittest("FmsFormHostRecordTest") { "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/formmgr/", "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include/", "//foundation/distributedschedule/samgr/adapter/interfaces/innerkits/include/", + "//foundation/distributeddatamgr/distributeddatamgr/interfaces/innerkits/distributeddata/include", ] configs = [ diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h index 89ae25797a8519d67509d0860d9832ea2a9a887b..bd37d22f82400675d865d8ba9bf7553b67858fbe 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h @@ -29,19 +29,24 @@ public: void handleEvent(std::string action, std::string data); void FMS_acquireForm(std::string data); void FMS_deleteForm(std::string data); + void FMS_acquireForm_001(std::string data); + void FMS_deleteForm_001(std::string data); void FMS_acquireForm_batch(std::string data); void FMS_deleteFormBatch(std::string data); std::shared_ptr subscriber_; class AcquireFormCallback : public FormCallback { public: - AcquireFormCallback() + AcquireFormCallback(std::string name, int code):caseName_(name), code_(code) { } virtual ~AcquireFormCallback() = default; void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; void OnFormUninstall(const int64_t formId) const override; + std::string caseName_ = ""; + int code_ = 0; + FormAbilityCommonA *ability_; }; protected: virtual void Init(const std::shared_ptr &abilityInfo, @@ -52,9 +57,11 @@ protected: virtual void OnActive() override; virtual void OnInactive() override; virtual void OnBackground() override; - +private: + void Clear(); using FormFunc = void (FormAbilityCommonA::*)(std::string data); std::map memberFuncMap_; + std::map calledFuncMap_; std::shared_ptr callback_; }; diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp index 401b391d0da4f05d8a717ec874ef315ad4e29403..55d913bb53afbf7ff194b8a669f6a6f1cdd3638c 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp @@ -28,6 +28,8 @@ namespace AppExecFwk { std::vector eventList = { FORM_EVENT_REQ_ONE_NORMAL_FORM, FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, + FORM_EVENT_REQ_ONE_NORMAL_FORM_001, + FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL_001, FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, FORM_EVENT_REQ_CLEAR_FORM_BATCH }; @@ -37,8 +39,8 @@ void FormAbilityCommonA::AcquireFormCallback::OnAcquired(const int32_t result, c } void FormAbilityCommonA::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { - APP_LOGI("%{public}s called", __func__); - FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100, std::to_string(formJsInfo.formId)); + APP_LOGI("%{public}s called, caseName_[%{public}s]", __func__, this->caseName_.c_str()); + FormTestUtils::PublishEvent(this->caseName_, this->code_, std::to_string(formJsInfo.formId).c_str()); } void FormAbilityCommonA::AcquireFormCallback::OnFormUninstall(const int64_t formId) const @@ -50,7 +52,7 @@ void FormAbilityCommonA::AcquireFormCallback::OnFormUninstall(const int64_t form void FormAbilityCommonA::FMS_acquireForm(std::string data) { APP_LOGI("%{public}s called, data: %{public}s", __func__, data.c_str()); - std::shared_ptr callback = std::make_shared(); + std::shared_ptr callback = std::make_shared(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); // Set Want info begin Want want; want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); @@ -83,6 +85,41 @@ void FormAbilityCommonA::FMS_deleteForm(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, "false"); } } + +void FormAbilityCommonA::FMS_acquireForm_001(std::string data) +{ + APP_LOGI("%{public}s called, data: %{public}s", __func__, data.c_str()); + std::shared_ptr callback = std::make_shared(FORM_EVENT_RECV_ONE_NORMAL_FORM_001, EVENT_CODE_100); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME2); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[form_ability_commonA]AcquireForm end"); + } else { + APP_LOGE("[form_ability_commonA]AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_001, EVENT_CODE_100, ""); + } +} + +void FormAbilityCommonA::FMS_deleteForm_001(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001, EVENT_CODE_101, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001, EVENT_CODE_101, "false"); + } +} + void FormAbilityCommonA::FMS_acquireForm_batch(std::string data) { APP_LOGI("%{public}s called", __func__); @@ -177,6 +214,8 @@ void FormAbilityCommonA::Init(const std::shared_ptr &abilityInfo, Ability::Init(abilityInfo, application, handler, token); memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM] = &FormAbilityCommonA::FMS_acquireForm; memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL] = &FormAbilityCommonA::FMS_deleteForm; + memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM_001] = &FormAbilityCommonA::FMS_acquireForm_001; + memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL_001] = &FormAbilityCommonA::FMS_deleteForm_001; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityCommonA::FMS_acquireForm_batch; memberFuncMap_[FORM_EVENT_REQ_CLEAR_FORM_BATCH] = &FormAbilityCommonA::FMS_deleteFormBatch; SubscribeEvent(); @@ -185,6 +224,10 @@ void FormAbilityCommonA::Init(const std::shared_ptr &abilityInfo, void FormAbilityCommonA::handleEvent(std::string action, std::string data) { APP_LOGI("%{public}s called", __func__); + if (calledFuncMap_.find(action) != calledFuncMap_.end()) { + return; + } + calledFuncMap_.emplace(action, 0); auto itFunc = memberFuncMap_.find(action); if (itFunc != memberFuncMap_.end()) { auto memberFunc = itFunc->second; @@ -194,6 +237,10 @@ void FormAbilityCommonA::handleEvent(std::string action, std::string data) } } +void FormAbilityCommonA::Clear() +{ +} + void FormEventSubscriberForCommonA::OnReceiveEvent(const CommonEventData &data) { APP_LOGI("FormEventSubscriberForCommonA::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn index 97d3331b98207bc600a1ba2bca42070b57a0410c..acf930d530e156c37bc3544b7743257444ecb7ba 100755 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn @@ -26,6 +26,7 @@ config("fmsSystemTestHostNormalConfig") { "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", "${appexecfwk_path}/kits/appkit/native/app", "${appexecfwk_path}/services/bundlemgr/include", + "${appexecfwk_path}/interfaces/innerkits/fmskit/native/include", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//utils/system/safwk/native/include", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", @@ -61,6 +62,7 @@ ohos_shared_library("fmsSystemTestHostNormal") { "${appexecfwk_path}/common:libappexecfwk_common", "${appexecfwk_path}/kits:appkit_native", "${appexecfwk_path}/services/bundlemgr:libbms", + "${appexecfwk_path}/interfaces/innerkits/fmskit:fmskit_native", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h index bb63b78c256d89c587711c50deb4851853b93fab..7efe314180d81034077e1455dd8202cded9b97aa 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h @@ -31,6 +31,7 @@ public: void FMS_deleteFormCommon(std::string strFormId); void FMS_acquireForm_0300(std::string data); + void FMS_acquireForm_0300_1(std::string data); void FMS_acquireForm_0400(std::string data); void FMS_acquireForm_0500(std::string data); void FMS_acquireForm_0600(std::string data); @@ -60,6 +61,9 @@ public: void FMS_acquireForm_3300(std::string data); void FMS_acquireForm_3400(std::string data); void FMS_acquireForm_3500(std::string data); + void FMS_acquireForm_3700(std::string data); + void FMS_acquireForm_3800(std::string data); + void FMS_acquireForm_3800_1(std::string data); void FMS_acquireForm_tempForm(std::string data); void FMS_acquireFormBatch(std::string data); void FMS_acquireFormBatchB(std::string data); diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h index 9af88ac6a13eec2f82e19aa71c69f4dd00e522e5..88fb39f36140a247242352c920b6f8cc5c199ca7 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h @@ -32,6 +32,8 @@ public: void FMS_deleteForm_0500(std::string data); void FMS_deleteForm_0600(std::string data); void FMS_deleteForm_0700(std::string data); + void FMS_deleteForm_0700_1(std::string data); + void FMS_deleteForm_0700_2(std::string data); void FMS_deleteForm_0800(std::string data); void FMS_deleteForm_0900(std::string data); void FMS_deleteForm_1000(std::string data); @@ -52,11 +54,11 @@ public: void FMS_acquire_tempForm_batch(std::string data); void FMS_acquireForm_batch(std::string data); void FMS_deleteFormBatch(std::string data); - + void FMS_deleteFormCommon(std::string data); std::shared_ptr subscriber_; class AcquireFormCallback : public FormCallback { public: - AcquireFormCallback(std::string name):caseName_(name) + AcquireFormCallback(std::string name, int code):caseName_(name), code_(code) { } virtual ~AcquireFormCallback() = default; @@ -65,6 +67,7 @@ public: void OnFormUninstall(const int64_t formId) const override; FormAbilityDeleteForm *ability_; std::string caseName_; + int code_ = 0; }; protected: virtual void Init(const std::shared_ptr &abilityInfo, @@ -82,6 +85,8 @@ private: void DeleteForm_0500(int64_t form_id); void DeleteForm_0600(int64_t form_id); void DeleteForm_0700(int64_t form_id); + void DeleteForm_0700_1(int64_t form_id); + void DeleteForm_0700_2(int64_t form_id); void DeleteForm_0800(int64_t form_id); void DeleteForm_0900(int64_t form_id); void DeleteForm_1000(int64_t form_id); diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp index 344a14cf92aa96bb183f4b9441c321d10799b473..192aa9289fef53851f4bc2d13a69e245cd5bb143 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp @@ -14,6 +14,7 @@ */ #include "form_ability_a.h" #include "app_log_wrapper.h" +#include "form_host_client.h" #include "form_st_common_info.h" #include "form_test_utils.h" #include "system_test_form_util.h" @@ -26,8 +27,8 @@ using namespace OHOS::EventFwk; namespace OHOS { namespace AppExecFwk { std::vector eventList = { - FORM_EVENT_REQ_DELETE_FORM_COMMON, FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, - FORM_EVENT_REQ_ACQUIRE_FORM_0300, FORM_EVENT_REQ_ACQUIRE_FORM_0400, FORM_EVENT_REQ_ACQUIRE_FORM_0500, + FORM_EVENT_REQ_DELETE_FORM_COMMON, FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, FORM_EVENT_REQ_ACQUIRE_FORM_0300, + FORM_EVENT_REQ_ACQUIRE_FORM_0300_1, FORM_EVENT_REQ_ACQUIRE_FORM_0400, FORM_EVENT_REQ_ACQUIRE_FORM_0500, FORM_EVENT_REQ_ACQUIRE_FORM_0600, FORM_EVENT_REQ_ACQUIRE_FORM_0700, FORM_EVENT_REQ_ACQUIRE_FORM_1000, FORM_EVENT_REQ_ACQUIRE_FORM_1100, FORM_EVENT_REQ_ACQUIRE_FORM_1200, FORM_EVENT_REQ_ACQUIRE_FORM_1500_1, FORM_EVENT_REQ_ACQUIRE_FORM_1600, FORM_EVENT_REQ_ACQUIRE_FORM_1600_1, FORM_EVENT_REQ_ACQUIRE_FORM_1800, @@ -37,7 +38,8 @@ std::vector eventList = { FORM_EVENT_REQ_ACQUIRE_FORM_2700, FORM_EVENT_REQ_ACQUIRE_FORM_2800, FORM_EVENT_REQ_ACQUIRE_FORM_2900, FORM_EVENT_REQ_ACQUIRE_FORM_2900_1, FORM_EVENT_REQ_ACQUIRE_FORM_3000, FORM_EVENT_REQ_ACQUIRE_FORM_3100, FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, FORM_EVENT_REQ_CLEAR_FORM_BATCH, - FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B, FORM_EVENT_REQ_ACQUIRE_FORM_3700, FORM_EVENT_REQ_ACQUIRE_FORM_3800, + FORM_EVENT_REQ_ACQUIRE_FORM_3800_1 }; void FormAbilityA::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const { @@ -47,6 +49,11 @@ void FormAbilityA::AcquireFormCallback::OnAcquired(const int32_t result, const F void FormAbilityA::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const { APP_LOGI("%{public}s called", __func__); + if (this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_3800) { + FormTestUtils::PublishEvent(this->caseName_, this->code_ + 1, std::to_string(formJsInfo.formId)); + ability_->FMS_acquireForm_3800_1(std::to_string(formJsInfo.formId)); + return; + } FormTestUtils::PublishEvent(this->caseName_, this->code_ + 1, formJsInfo.formData); if (this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1200 @@ -107,6 +114,32 @@ void FormAbilityA::FMS_acquireForm_0300(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0300, EVENT_CODE_300, "false"); } } + +void FormAbilityA::FMS_acquireForm_0300_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_0300_1, EVENT_CODE_300_1); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + int64_t int64MaxId = 9223372036854775807; + + bool bResult = AcquireForm(int64MaxId, want, callback); + if (bResult) { + std::string strFormId = std::to_string(int64MaxId); + APP_LOGI("AcquireForm end, formId: %{public}s", strFormId.c_str()); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0300_1, EVENT_CODE_300_1, "false"); + } +} + void FormAbilityA::FMS_acquireForm_0400(std::string data) { APP_LOGI("%{public}s called", __func__); @@ -660,6 +693,78 @@ void FormAbilityA::FMS_acquireForm_3400(std::string data) void FormAbilityA::FMS_acquireForm_3500(std::string data) { } +void FormAbilityA::FMS_acquireForm_3700(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3700, EVENT_CODE_3700); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_3700, EVENT_CODE_3700, "false"); + } +} + +void FormAbilityA::FMS_acquireForm_3800(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3800, EVENT_CODE_3800); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_3800, EVENT_CODE_3800 + 1, ""); + } +} + +void FormAbilityA::FMS_acquireForm_3800_1(std::string data) +{ + if(FormHostClient::GetInstance()->ContainsForm(std::stoll(data))){ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_3800, EVENT_CODE_3800 + 2, "true"); + } + APP_LOGI("%{public}s called, formId: %{public}s", __func__, data.c_str()); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3800_1, EVENT_CODE_3801); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(std::stoll(data), want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_3800_1, EVENT_CODE_3801, "false"); + } + + FMS_deleteFormCommon(data); +} void FormAbilityA::FMS_acquireForm_tempForm(std::string data) { @@ -826,6 +931,7 @@ void FormAbilityA::Init(const std::shared_ptr &abilityInfo, APP_LOGI("FormAbilityA::Init"); Ability::Init(abilityInfo, application, handler, token); memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0300] = &FormAbilityA::FMS_acquireForm_0300; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0300_1] = &FormAbilityA::FMS_acquireForm_0300_1; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0400] = &FormAbilityA::FMS_acquireForm_0400; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0500] = &FormAbilityA::FMS_acquireForm_0500; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0600] = &FormAbilityA::FMS_acquireForm_0600; @@ -852,6 +958,9 @@ void FormAbilityA::Init(const std::shared_ptr &abilityInfo, memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2900_1] = &FormAbilityA::FMS_acquireForm_2900_1; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3000] = &FormAbilityA::FMS_acquireForm_3000; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3100] = &FormAbilityA::FMS_acquireForm_3100; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3700] = &FormAbilityA::FMS_acquireForm_3700; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3800] = &FormAbilityA::FMS_acquireForm_3800; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3800_1] = &FormAbilityA::FMS_acquireForm_3800_1; memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_COMMON] = &FormAbilityA::FMS_deleteFormCommon; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_TEMP] = &FormAbilityA::FMS_acquireForm_tempForm; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityA::FMS_acquireFormBatch; @@ -901,4 +1010,4 @@ void FormEventSubscriber::KitTerminateAbility() REGISTER_AA(FormAbilityA) } // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp index f50e5b4f7beab31ec5ff6fd7a7954f74d15af978..1ff9fee255c84d7294add09ca17ab18117a42dc8 100644 --- a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp @@ -37,14 +37,18 @@ void FormAbilityDeleteForm::AcquireFormCallback::OnUpdate(const int32_t result, { APP_LOGI("%{public}s called", __func__); APP_LOGI("%{public}s receive formData:%{public}s", __func__, formJsInfo.formData.c_str()); + if (this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0700_1 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0700_2) { + FormTestUtils::PublishEvent(this->caseName_, this->code_, std::to_string(formJsInfo.formId).c_str()); + } + if (this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0300 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0400 - || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0700 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0800 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0700 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1701 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0700_2 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0800 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0900 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1000 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1100 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1200 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1400 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1500 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1501 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1600 - || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1601 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1700 - || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1701) { + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1601 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1700) { ability_->FMS_deleteForm_common(formJsInfo.formId, this->caseName_); } } @@ -66,6 +70,10 @@ void FormAbilityDeleteForm::FMS_deleteForm_common(int64_t formId, std::string ca DeleteForm_0600(formId); } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0700) { DeleteForm_0700(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0700_1) { + DeleteForm_0700_1(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0700_2) { + DeleteForm_0700_2(formId); } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0800) { DeleteForm_0800(formId); } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0900) { @@ -98,7 +106,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_common(int64_t formId, std::string ca void FormAbilityDeleteForm::FMS_deleteForm_0300(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0300); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300); callback->ability_ = this; // Set Want info begin Want want; @@ -119,7 +127,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0300(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_0400(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0400); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400); callback->ability_ = this; // Set Want info begin Want want; @@ -155,7 +163,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0600(std::string data) { APP_LOGI("%{public}s start[%{public}s]", __func__, data.c_str()); std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0600); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600); callback->ability_ = this; // Set Want info begin Want want; @@ -177,7 +185,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0600(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_0700(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0700); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700); callback->ability_ = this; // Set Want info begin Want want; @@ -195,11 +203,54 @@ void FormAbilityDeleteForm::FMS_deleteForm_0700(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700, ""); } } - +void FormAbilityDeleteForm::FMS_deleteForm_0700_1(std::string data) +{ + APP_LOGI("%{public}s start.", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0700_1, EVENT_CODE_700_1); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME2, FORM_PROVIDER_ABILITY_NAME2); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700_1, EVENT_CODE_700_1, ""); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_0700_2(std::string data) +{ + APP_LOGI("%{public}s start.", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0700_2, EVENT_CODE_700_2); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME2, FORM_PROVIDER_ABILITY_NAME2); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700_2, EVENT_CODE_700_2, ""); + } +} void FormAbilityDeleteForm::FMS_deleteForm_0800(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0800); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800); callback->ability_ = this; // Set Want info begin Want want; @@ -220,7 +271,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0800(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_0900(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0900); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900); callback->ability_ = this; // Set Want info begin Want want; @@ -242,7 +293,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_0900(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1000(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1000); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000); callback->ability_ = this; // Set Want info begin Want want; @@ -264,7 +315,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1000(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1100(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1100); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100); callback->ability_ = this; // Set Want info begin Want want; @@ -286,7 +337,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1100(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1200(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1200); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1200, EVENT_CODE_1200); callback->ability_ = this; // Set Want info begin Want want; @@ -315,7 +366,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1201(std::string data) bool bResult = DeleteForm(atoll(data.c_str())); if (bResult) { APP_LOGI("%{public}s DeleteForm end", __func__); - FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201, "true"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201, data.c_str()); } else { APP_LOGE("%{public}s DeleteForm error", __func__); FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201, "false"); @@ -325,7 +376,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1201(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1400(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1400); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400); callback->ability_ = this; // Set Want info begin Want want; @@ -363,7 +414,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1401(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1500(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1500); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1500, EVENT_CODE_1500); callback->ability_ = this; // Set Want info begin Want want; @@ -389,7 +440,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1501(std::string data) if (bResult) { APP_LOGI("%{public}s DeleteForm end", __func__); std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1501); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510); callback->ability_ = this; // Set Want info begin Want want; @@ -426,7 +477,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1502(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1600(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1600); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600); callback->ability_ = this; // Set Want info begin Want want; @@ -451,7 +502,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1601(std::string data) if (bResult) { APP_LOGI("%{public}s DeleteForm end", __func__); std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1601); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610); callback->ability_ = this; // Set Want info begin Want want; @@ -489,7 +540,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1602(std::string data) void FormAbilityDeleteForm::FMS_deleteForm_1700(std::string data) { std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1700); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1700, EVENT_CODE_1700); callback->ability_ = this; // Set Want info begin Want want; @@ -515,7 +566,7 @@ void FormAbilityDeleteForm::FMS_deleteForm_1701(std::string data) if (bResult) { APP_LOGI("%{public}s DeleteForm end", __func__); std::shared_ptr callback = - std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1701); + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701); callback->ability_ = this; // Set Want info begin Want want; @@ -549,6 +600,28 @@ void FormAbilityDeleteForm::FMS_deleteForm_1702(std::string data) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1702, EVENT_CODE_1702, "false"); } } + +void FormAbilityDeleteForm::FMS_deleteFormCommon(std::string strFormId) +{ + APP_LOGI("%{public}s called, formId: %{public}s", __func__, strFormId.c_str()); + if (strFormId.empty()) { + APP_LOGE("DeleteForm error, formId is 0"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + return; + } + int64_t formId = std::stoll(strFormId); + sleep(1); + bool bResult = DeleteForm(formId); + sleep(1); + if (bResult) { + APP_LOGI("DeleteForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "true"); + } else { + APP_LOGE("DeleteForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + } +} + void FormAbilityDeleteForm::FMS_acquire_tempForm_batch(std::string data) { APP_LOGI("%{public}s called", __func__); @@ -662,7 +735,28 @@ void FormAbilityDeleteForm::DeleteForm_0700(int64_t form_id) FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700, "false"); } } - +void FormAbilityDeleteForm::DeleteForm_0700_1(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700_1, EVENT_CODE_700_1, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700_1, EVENT_CODE_700_1, "false"); + } +} +void FormAbilityDeleteForm::DeleteForm_0700_2(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700_2, EVENT_CODE_700_2, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700_2, EVENT_CODE_700_2, "false"); + } +} void FormAbilityDeleteForm::DeleteForm_0800(int64_t form_id) { bool bResult = DeleteForm(form_id); @@ -702,7 +796,7 @@ void FormAbilityDeleteForm::DeleteForm_1000(int64_t form_id) bool realResult = DeleteForm(form_id); if (realResult) { APP_LOGI("%{public}s DeleteForm end", __func__); - FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, "true"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, std::to_string(form_id)); } else { APP_LOGE("%{public}s DeleteForm error", __func__); FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, "false"); @@ -766,6 +860,8 @@ void FormAbilityDeleteForm::OnStart(const Want &want) FORM_EVENT_REQ_DELETE_FORM_0500, FORM_EVENT_REQ_DELETE_FORM_0600, FORM_EVENT_REQ_DELETE_FORM_0700, + FORM_EVENT_REQ_DELETE_FORM_0700_1, + FORM_EVENT_REQ_DELETE_FORM_0700_2, FORM_EVENT_REQ_DELETE_FORM_0800, FORM_EVENT_REQ_DELETE_FORM_0900, FORM_EVENT_REQ_DELETE_FORM_1000, @@ -785,7 +881,8 @@ void FormAbilityDeleteForm::OnStart(const Want &want) FORM_EVENT_REQ_DELETE_FORM_1702, FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, - FORM_EVENT_REQ_CLEAR_FORM_BATCH + FORM_EVENT_REQ_CLEAR_FORM_BATCH, + FORM_EVENT_REQ_DELETE_FORM_COMMON }; SubscribeEvent(eventList); } @@ -840,6 +937,8 @@ void FormAbilityDeleteForm::Init(const std::shared_ptr &abilityInfo memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0500] = &FormAbilityDeleteForm::FMS_deleteForm_0500; memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0600] = &FormAbilityDeleteForm::FMS_deleteForm_0600; memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0700] = &FormAbilityDeleteForm::FMS_deleteForm_0700; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0700_1] = &FormAbilityDeleteForm::FMS_deleteForm_0700_1; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0700_2] = &FormAbilityDeleteForm::FMS_deleteForm_0700_2; memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0800] = &FormAbilityDeleteForm::FMS_deleteForm_0800; memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0900] = &FormAbilityDeleteForm::FMS_deleteForm_0900; memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1000] = &FormAbilityDeleteForm::FMS_deleteForm_1000; @@ -860,6 +959,7 @@ void FormAbilityDeleteForm::Init(const std::shared_ptr &abilityInfo memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityDeleteForm::FMS_acquireForm_batch; memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH] = &FormAbilityDeleteForm::FMS_acquire_tempForm_batch; memberFuncMap_[FORM_EVENT_REQ_CLEAR_FORM_BATCH] = &FormAbilityDeleteForm::FMS_deleteFormBatch; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_COMMON] = &FormAbilityDeleteForm::FMS_deleteFormCommon; } void FormAbilityDeleteForm::handleEvent(std::string action, std::string data) diff --git a/test/systemtest/common/fms/common/include/form_st_common_info.h b/test/systemtest/common/fms/common/include/form_st_common_info.h index 122acb5cb523547f8b1006c2830b0ba772583ba1..ef64ef4883a5fc860f6ded5bc073713121e4aacf 100755 --- a/test/systemtest/common/fms/common/include/form_st_common_info.h +++ b/test/systemtest/common/fms/common/include/form_st_common_info.h @@ -54,6 +54,8 @@ const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0100 = "fms_recv_acquireForm_0100 const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0200 = "fms_req_acquireForm_0200"; const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0200 = "fms_recv_acquireForm_0200"; const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0300 = "fms_req_acquireForm_0300"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0300_1 = "fms_recv_acquireForm_0300_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0300_1 = "fms_req_acquireForm_0300_1"; const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0300 = "fms_recv_acquireForm_0300"; const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0400 = "fms_req_acquireForm_0400"; const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0400 = "fms_recv_acquireForm_0400"; @@ -128,6 +130,12 @@ const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3200 = "fms_req_acquireForm_3200"; const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3200 = "fms_recv_acquireForm_3200"; const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3300 = "fms_req_acquireForm_3300"; const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3300 = "fms_recv_acquireForm_3300"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3700 = "fms_req_acquireForm_3700"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3700 = "fms_recv_acquireForm_3700"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3800 = "fms_req_acquireForm_3800"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3800 = "fms_recv_acquireForm_3800"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3800_1 = "fms_req_acquireForm_3800_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3800_1 = "fms_recv_acquireForm_3800_1"; const std::string FORM_EVENT_REQ_ACQUIRE_FORM_BATCH = "fms_req_acquireForm_batch"; const std::string FORM_EVENT_RECV_ACQUIRE_FORM_BATCH = "fms_recv_acquireForm_batch"; const std::string FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B = "fms_req_acquireForm_batch_b"; @@ -153,6 +161,10 @@ const std::string FORM_EVENT_REQ_DELETE_FORM_0600 = "fms_req_deleteForm_0600"; const std::string FORM_EVENT_RECV_DELETE_FORM_0600 = "fms_recv_deleteForm_0600"; const std::string FORM_EVENT_REQ_DELETE_FORM_0700 = "fms_req_deleteForm_0700"; const std::string FORM_EVENT_RECV_DELETE_FORM_0700 = "fms_recv_deleteForm_0700"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0700_1 = "fms_req_deleteForm_0700_1"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0700_1 = "fms_recv_deleteForm_0700_1"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0700_2 = "fms_req_deleteForm_0700_2"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0700_2 = "fms_recv_deleteForm_0700_2"; const std::string FORM_EVENT_REQ_DELETE_FORM_0800 = "fms_req_deleteForm_0800"; const std::string FORM_EVENT_RECV_DELETE_FORM_0800 = "fms_recv_deleteForm_0800"; const std::string FORM_EVENT_REQ_DELETE_FORM_0900 = "fms_req_deleteForm_0900"; @@ -189,6 +201,8 @@ const std::string FORM_EVENT_REQ_DELETE_FORM_1702 = "fms_req_deleteForm_1702"; const std::string FORM_EVENT_RECV_DELETE_FORM_1702 = "fms_recv_deleteForm_1702"; // OnDelete const std::string COMMON_EVENT_ON_DELETE = "usual.event.ondelete"; +// OnUpdate +const std::string COMMON_EVENT_ON_UPDATE = "usual.event.onupdate"; typedef enum { FORM_EVENT_TRIGGER_RESULT_NG = 0, FORM_EVENT_TRIGGER_RESULT_OK = 1, @@ -279,6 +293,10 @@ const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM = "fms_req_one_normal_form"; const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM = "fms_recv_one_normal_form"; const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL = "fms_req_one_normal_form_del"; const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL = "fms_recv_one_normal_form_del"; +const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_001 = "fms_req_one_normal_form_001"; +const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM_001 = "fms_recv_one_normal_form_001"; +const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL_001 = "fms_req_one_normal_form_del_001"; +const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001 = "fms_recv_one_normal_form_del_001"; // CommonB(acquire one normal form) const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_B = "fms_req_one_normal_form_b"; @@ -318,6 +336,96 @@ const std::string FORM_EVENT_RECV_SELF_STARTING_TEST_0200 = "fms_recv_selfStarti const std::string FORM_EVENT_REQ_SELF_STARTING_TEST_0300 = "fms_req_selfStartingTest_0300"; const std::string FORM_EVENT_RECV_SELF_STARTING_TEST_0300 = "fms_recv_selfStartingTest_0300"; +// Uninstall App Test +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0100 = "fms_req_uninstallTest_0100"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0100 = "fms_recv_uninstallTest_0100"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0200 = "fms_req_uninstallTest_0200"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0200 = "fms_recv_uninstallTest_0200"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0300 = "fms_req_uninstallTest_0300"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0300 = "fms_recv_uninstallTest_0300"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0400 = "fms_req_uninstallTest_0400"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0400 = "fms_recv_uninstallTest_0400"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0500 = "fms_req_uninstallTest_0500"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0500 = "fms_recv_uninstallTest_0500"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0600 = "fms_req_uninstallTest_0600"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0600 = "fms_recv_uninstallTest_0600"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0700 = "fms_req_uninstallTest_0700"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0700 = "fms_recv_uninstallTest_0700"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0800 = "fms_req_uninstallTest_0800"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0800 = "fms_recv_uninstallTest_0800"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0900 = "fms_req_uninstallTest_0900"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0900 = "fms_recv_uninstallTest_0900"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1000 = "fms_req_uninstallTest_1000"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1000 = "fms_recv_uninstallTest_1000"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1100 = "fms_req_uninstallTest_1100"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1100 = "fms_recv_uninstallTest_1100"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1200 = "fms_req_uninstallTest_1200"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1200 = "fms_recv_uninstallTest_1200"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1300 = "fms_req_uninstallTest_1300"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1300 = "fms_recv_uninstallTest_1300"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1400 = "fms_req_uninstallTest_1400"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1400 = "fms_recv_uninstallTest_1400"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1500 = "fms_req_uninstallTest_1500"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1500 = "fms_recv_uninstallTest_1500"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1600 = "fms_req_uninstallTest_1600"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1600 = "fms_recv_uninstallTest_1600"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1700 = "fms_req_uninstallTest_1700"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1700 = "fms_recv_uninstallTest_1700"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1800 = "fms_req_uninstallTest_1800"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1800 = "fms_recv_uninstallTest_1800"; + +// Host Refresh +const std::string FORM_EVENT_REQ_HOST_REFRESH_0100 = "fms_req_hostRefresh_0100"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0100 = "fms_recv_hostRefresh_0100"; +const std::string FORM_EVENT_REQ_HOST_REFRESH_0200 = "fms_req_hostRefresh_0200"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0200 = "fms_recv_hostRefresh_0200"; +const std::string FORM_EVENT_REQ_HOST_REFRESH_0300 = "fms_req_hostRefresh_0300"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0300 = "fms_recv_hostRefresh_0300"; +const std::string FORM_EVENT_REQ_HOST_REFRESH_0400 = "fms_req_hostRefresh_0400"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0400 = "fms_recv_hostRefresh_0400"; +const std::string FORM_EVENT_REQ_HOST_REFRESH_0500 = "fms_req_hostRefresh_0500"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0500 = "fms_recv_hostRefresh_0500"; +const std::string FORM_EVENT_REQ_HOST_REFRESH_0600 = "fms_req_hostRefresh_0600"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0600 = "fms_recv_hostRefresh_0600"; +const std::string FORM_EVENT_REQ_HOST_REFRESH_0700 = "fms_req_hostRefresh_0700"; +const std::string FORM_EVENT_RECV_HOST_REFRESH_0700 = "fms_recv_hostRefresh_0700"; + +// UpdateForm +const std::string FORM_EVENT_REQ_UPDATE_FORM_CREATE_COMMON = "fms_req_updateForm_create_common"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_CREATE_COMMON = "fms_recv_updateForm_create_common"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_CREATE_CATCH_FORM = "fms_req_updateForm_create_cache_form"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_CREATE_CATCH_FORM = "fms_recv_updateForm_create_cache_form"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_DELETE_COMMON = "fms_req_updateForm_delete_common"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_DELETE_COMMON = "fms_recv_updateForm_delete_common"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_NOTIFY_INVISIBLE = "fms_req_updateForm_notify_invisible"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_NOTIFY_INVISIBLE = "fms_recv_updateForm_notify_invisible"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_DISABLE_UPDATE = "fms_req_updateForm_disable_update"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_DISABLE_UPDATE = "fms_recv_updateForm_disable_update"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0100 = "fms_req_updateForm_0100"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0100 = "fms_recv_updateForm_0100"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0200 = "fms_req_updateForm_0200"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0200 = "fms_recv_updateForm_0200"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0300 = "fms_req_updateForm_0300"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0300 = "fms_recv_updateForm_0300"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0400 = "fms_req_updateForm_0400"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0400 = "fms_recv_updateForm_0400"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0500 = "fms_req_updateForm_0500"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0500 = "fms_recv_updateForm_0500"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0600 = "fms_req_updateForm_0600"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0600 = "fms_recv_updateForm_0600"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0700 = "fms_req_updateForm_0700"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0700 = "fms_recv_updateForm_0700"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0800 = "fms_req_updateForm_0800"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0800 = "fms_recv_updateForm_0800"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_0900 = "fms_req_updateForm_0900"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_0900 = "fms_recv_updateForm_0900"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_1000 = "fms_req_updateForm_1000"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_1000 = "fms_recv_updateForm_1000"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_1100 = "fms_req_updateForm_1100"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_1100 = "fms_recv_updateForm_1100"; +const std::string FORM_EVENT_REQ_UPDATE_FORM_1200 = "fms_req_updateForm_1200"; +const std::string FORM_EVENT_RECV_UPDATE_FORM_1200 = "fms_recv_updateForm_1200"; + // common event data code const int EVENT_CODE_100 = 100; const int EVENT_CODE_101 = 101; @@ -330,6 +438,7 @@ const int EVENT_CODE_203 = 203; const int EVENT_CODE_204 = 204; const int EVENT_CODE_205 = 205; const int EVENT_CODE_300 = 300; +const int EVENT_CODE_300_1 = 301; const int EVENT_CODE_301 = 301; const int EVENT_CODE_302 = 302; const int EVENT_CODE_303 = 303; @@ -342,6 +451,8 @@ const int EVENT_CODE_501 = 501; const int EVENT_CODE_502 = 502; const int EVENT_CODE_600 = 600; const int EVENT_CODE_700 = 700; +const int EVENT_CODE_700_1 = 701; +const int EVENT_CODE_700_2 = 702; const int EVENT_CODE_800 = 800; const int EVENT_CODE_900 = 900; const int EVENT_CODE_999 = 999; @@ -407,6 +518,9 @@ const int EVENT_CODE_3101 = 3101; const int EVENT_CODE_3200 = 3200; const int EVENT_CODE_3300 = 3300; const int EVENT_CODE_3301 = 3301; +const int EVENT_CODE_3700 = 3700; +const int EVENT_CODE_3800 = 3800; +const int EVENT_CODE_3801 = 3801; const int EVENT_CODE_BATCH = 9000; const int EVENT_CODE_BATCH_B = 9010; @@ -417,4 +531,4 @@ const int EVENT_CODE_TEMP = 9900; const int EVENT_CODE_TEMP_1 = 9901; } // namespace AppExecFwk } // namespace OHOS -#endif // FORM_ST_COMMON_INFO_H \ No newline at end of file +#endif // FORM_ST_COMMON_INFO_H diff --git a/test/systemtest/common/fms/common/include/system_test_form_util.h b/test/systemtest/common/fms/common/include/system_test_form_util.h index 2e4f801581eb130a7a32053550d293d204accfe5..cea14aeeb5d9495b1e0a99849129c7c639b4cc89 100644 --- a/test/systemtest/common/fms/common/include/system_test_form_util.h +++ b/test/systemtest/common/fms/common/include/system_test_form_util.h @@ -320,6 +320,11 @@ public: * @return Returns forms count to delete. */ static int ClearFormRecords(); + /** + * @brief Get form manager service. + * @return Returns form manager servic remoteObject. + */ + static sptr GetFmsService(); private: /** * @@ -333,12 +338,6 @@ private: */ static sptr GetInstallerProxy(); - /** - * @brief Get form manager service. - * @return Returns form manager servic remoteObject. - */ - static sptr GetFmsService(); - static bool WriteInterfaceToken(MessageParcel &data); static int GetStringInfo(AppExecFwk::IFormMgr::Message code, MessageParcel &data, std::string &stringInfo); static int SendTransactCmd(AppExecFwk::IFormMgr::Message code, MessageParcel &data, MessageParcel &reply); diff --git a/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn b/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn index 3437550f9fed3ebabc8e0d7998c40d4c7c774b36..1a1d1cf69cd000ce46533286b95cb369f3b9b40e 100644 --- a/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn +++ b/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn @@ -20,6 +20,7 @@ ohos_systemtest("FmsAcquireFormTest") { module_out_path = module_output_path include_dirs = [ "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/interfaces/innerkits/fmskit/native/include", "${appexecfwk_path}/test/systemtest/common/fms/common/include", "//base/notification/ces_standard/test/systemtest/common/resource", "//foundation/distributedschedule/safwk/services/safwk/include", @@ -45,6 +46,7 @@ ohos_systemtest("FmsAcquireFormTest") { "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", "${aafwk_path}/services/abilitymgr:abilityms", "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/fmskit:fmskit_native", "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", "//third_party/googletest:gtest_main", diff --git a/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp b/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp index a623fd2547b82551f966ce229ac90cb9effdbc88..ca8270601b8794d53ef823ccb72437dbf6ac86ca 100644 --- a/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp +++ b/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp @@ -27,6 +27,7 @@ #include "common_event_manager.h" #include "context_deal.h" #include "form_event.h" +#include "form_host_client.h" #include "form_st_common_info.h" #include "iservice_registry.h" #include "nlohmann/json.hpp" @@ -90,6 +91,7 @@ public: std::string FmsAcquireForm2400(); void FmsAcquireForm2400_1(std::string strFormId); void FmsAcquireFormDeleteA(std::string strFormId); + void FMS_deleteFormBatch(); }; std::vector FmsAcquireFormTest::eventList = { @@ -103,7 +105,8 @@ std::vector FmsAcquireFormTest::eventList = { FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, FORM_EVENT_RECV_ACQUIRE_FORM_1900, FORM_EVENT_RECV_ACQUIRE_FORM_2100, FORM_EVENT_RECV_ACQUIRE_FORM_2200, FORM_EVENT_RECV_ACQUIRE_FORM_2300, FORM_EVENT_RECV_ACQUIRE_FORM_2500, FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, FORM_EVENT_RECV_ACQUIRE_FORM_2600, FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, - FORM_EVENT_RECV_ACQUIRE_FORM_2400, FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, + FORM_EVENT_RECV_ACQUIRE_FORM_2400, FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, FORM_EVENT_RECV_CLEAR_FORM_BATCH, + FORM_EVENT_RECV_ACQUIRE_FORM_0300_1, FORM_EVENT_RECV_ACQUIRE_FORM_3800, FORM_EVENT_RECV_ACQUIRE_FORM_3800_1 }; @@ -288,11 +291,11 @@ HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1500, Function | MediumTest | Level } GTEST_LOG_(INFO) << "FMS_acquireForm_1500, add no catch form end"; + FMS_deleteFormBatch(); + sleep(1); FmsAcquireFormCatched1500(strFormId); - - sleep(1); - FmsAcquireFormDeleteA(strFormId); + std::cout << "END FMS_acquireForm_1500" << std::endl; } @@ -307,7 +310,7 @@ HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1600, Function | MediumTest | Level sleep(1); int normalCount = 0; int tempCount = 0; - for (int iCount = 0; iCount < 2; iCount++) { + for (int iCount = 0; iCount < 5; iCount++) { sleep(1); FmsAcquireForm1600(); normalCount++; @@ -540,6 +543,34 @@ HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0300, Function | MediumTest | Level std::cout << "END FMS_acquireForm_0300" << std::endl; } +/** + * @tc.number: FMS_acquireForm_0300_1 + * @tc.name: Failed to add form when parameter formId is wrong. + * @tc.desc: Failed to create form when verifying that the parameter (formId) of creating form is wrong. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0300_1, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0300_1" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0300_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0300_1, EVENT_CODE_300_1, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0300_1, EVENT_CODE_300_1)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0300_1, EVENT_CODE_300_1); + bool result = data == "false"; + EXPECT_TRUE(result); + + GTEST_LOG_(INFO) << "FMS_acquireForm_0300_1, result:" << result; + std::cout << "END FMS_acquireForm_0300_1" << std::endl; +} + /** * @tc.number: FMS_acquireForm_0400 * @tc.name: Failed to add form when parameter bundlename is wrong. @@ -815,6 +846,53 @@ HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2500, Function | MediumTest | Level std::cout << "END FMS_acquireForm_2500" << std::endl; } +/** + * @tc.number: FMS_acquireForm_3800 + * @tc.name: check the same host can't add the same form id twice. + * @tc.desc:the value of second add form is failed. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_3800, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3800" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_3800; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3800, EVENT_CODE_3800, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3800, EVENT_CODE_3800 + 1)); + std::string formIdStr = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3800, EVENT_CODE_3800 + 1); + bool result = (formIdStr != "false" && formIdStr != ""); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_3800 first add form, result:" << result << ", formId:" << formIdStr; + + std::string eventData2 = FORM_EVENT_REQ_ACQUIRE_FORM_3800_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3800_1, EVENT_CODE_3801, eventData2); + + // Check host client contains this form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3800, EVENT_CODE_3800 + 2)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3800_1, EVENT_CODE_3801)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3800_1, EVENT_CODE_3801); + result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_3800 second add form, result:" << result; + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result2 = data2 == "true"; + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_3800, delete form, result:" << result2; + } + + std::cout << "END FMS_acquireForm_3800" << std::endl; +} + void FmsAcquireFormTest::FmsAcquireFormCatched1500(std::string strFormId) { std::string bundleName1 = "com.ohos.form.manager.normalb"; @@ -1195,5 +1273,25 @@ void FmsAcquireFormTest::FmsAcquireFormDeleteA(std::string strFormId) std::cout << "END FmsAcquireFormDeleteA end" << std::endl; } + +void FmsAcquireFormTest::FMS_deleteFormBatch() +{ + std::cout << "START FMS_deleteFormBatch, delete form cache" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + std::string eventData = FORM_EVENT_REQ_CLEAR_FORM_BATCH; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_CLEAR_FORM_BATCH, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_deleteFormBatch, result:" << result; + + std::cout << "END FMS_deleteFormBatch, delete form cache" << std::endl; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp b/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp index 0e8a711b4558cff4e471dadbac116f04c8616f29..b0d4f3d2f018e97f2cb52b6da9192941b8b13d4d 100644 --- a/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp +++ b/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp @@ -96,7 +96,7 @@ public: std::string FmsAcquireForm3100(const std::string &bundleName, const std::string &abilityName); void FmsAcquireForm2800(std::string strFormId); void FmsAcquireForm3200(); - + void FmsAcquireForm3700(); void FmsAcquireFormDeleteA(const std::string &strFormId); void FmsAcquireFormDeleteB(const std::string &strFormId); void FmsAcquireFormDeleteC(const std::string &strFormId); @@ -114,7 +114,7 @@ std::vector FmsAcquireFormTestBatch::eventList = { FORM_EVENT_RECV_ACQUIRE_FORM_2700, FORM_EVENT_RECV_ACQUIRE_FORM_2800, FORM_EVENT_RECV_ACQUIRE_FORM_2900, FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, FORM_EVENT_RECV_ACQUIRE_FORM_3000, FORM_EVENT_RECV_ACQUIRE_FORM_3100, FORM_EVENT_RECV_ACQUIRE_FORM_3200, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, - FORM_EVENT_RECV_CLEAR_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + FORM_EVENT_RECV_CLEAR_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_FORM_3700, }; @@ -223,8 +223,9 @@ HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_2700, Function | MediumTest | std::cout << "END FMS_acquireForm_2700" << std::endl; std::cout << "the host A, delete form start" << std::endl; - if (normalFormsMaxA.size() > 0) { - for (int count = 0; count < normalFormsMaxA.size(); count++) { + + if(normalFormsMaxA.size() > 0) { + for (unsigned int count = 0; count < normalFormsMaxA.size(); count++) { FmsAcquireFormDeleteA(normalFormsMaxA[count]); } } @@ -443,6 +444,105 @@ HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3500, Function | MediumTest | std::cout << "END FMS_acquireForm_3500" << std::endl; } +/** + * @tc.number: FMS_acquireForm_3600 + * @tc.name: Multiple hosts create 512 forms respectively. + * @tc.desc: Verify that multiple hosts can create 512 forms. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3600, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3600" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireFormBatchA(bundleNameA, abilityNameA, FORM_COUNT_200); + std::cout << "FMS_acquireForm_3600, normal form size:" << FORM_COUNT_200 << std::endl; + sleep(1); + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireFormBatchA(bundleNameB, abilityNameB, FORM_COUNT_200); + std::cout << "FMS_acquireForm_3600, normal form size:" << FORM_COUNT_200 << std::endl; + sleep(1); + std::string bundleNameC = "com.ohos.form.manager.normalc"; + std::string abilityNameC = "FormAbilityC"; + std::cout << "bundleName: " << bundleNameC << std::endl; + std::cout << "abilityName: " << abilityNameC << std::endl; + FMS_acquireFormBatchA(bundleNameC, abilityNameC, FORM_COUNT_111); + std::cout << "FMS_acquireForm_3600, normal form size:" << FORM_COUNT_111 << std::endl; + sleep(1); + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireTempFormBatch(bundleNameA, abilityNameA, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3600, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + sleep(1); + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireTempFormBatch(bundleNameB, abilityNameB, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3600, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + sleep(1); + bool result = FmsAcquireFormTempForFailed(bundleNameA, abilityNameA); + EXPECT_TRUE(result); + if (result) { + std::cout << "END add temp form to the host B, Failed to create the 257th temporary form." << std::endl; + } + sleep(1); + std::cout << "FMS_acquireForm_3600, dlete temp form start" << std::endl; + FMS_deleteFormBatch(); + std::cout << "FMS_acquireForm_3600, dlete temp form end" << std::endl; + std::cout << "END FMS_acquireForm_3600" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_3700 + * @tc.name: Multiple hosts create 512 forms respectively. + * @tc.desc: Verify that multiple hosts can create 512 forms. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3700, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3700" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireFormBatchA(bundleNameA, abilityNameA, FORM_COUNT_200); + std::cout << "FMS_acquireForm_3700, normal form size:" << FORM_COUNT_200 << std::endl; + sleep(1); + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireFormBatchA(bundleNameB, abilityNameB, FORM_COUNT_200); + std::cout << "FMS_acquireForm_3700, normal form size:" << FORM_COUNT_200 << std::endl; + sleep(1); + std::string bundleNameC = "com.ohos.form.manager.normalc"; + std::string abilityNameC = "FormAbilityC"; + std::cout << "bundleName: " << bundleNameC << std::endl; + std::cout << "abilityName: " << abilityNameC << std::endl; + FMS_acquireFormBatchA(bundleNameC, abilityNameC, FORM_COUNT_112); + std::cout << "FMS_acquireForm_3700, normal form size:" << FORM_COUNT_112 << std::endl; + sleep(1); + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireTempFormBatch(bundleNameA, abilityNameA, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3700, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + sleep(1); + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireTempFormBatch(bundleNameB, abilityNameB, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3700, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + sleep(1); + FmsAcquireForm3700(); + sleep(1); + std::cout << "FMS_acquireForm_3700, dlete temp form start" << std::endl; + FMS_deleteFormBatch(); + std::cout << "FMS_acquireForm_3700, dlete temp form end" << std::endl; + std::cout << "END FMS_acquireForm_3700" << std::endl; +} std::string FmsAcquireFormTestBatch::FmsAcquireForm3100(const std::string &bundleName, const std::string &abilityName) { MAP_STR_STR params; @@ -596,6 +696,28 @@ void FmsAcquireFormTestBatch::FmsAcquireForm3000() std::cout << "END FmsAcquireForm3000" << std::endl; } +void FmsAcquireFormTestBatch::FmsAcquireForm3700() +{ + std::cout << "START FmsAcquireForm3700" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_3700; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3700, EVENT_CODE_3700, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3700, EVENT_CODE_3700)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3700, EVENT_CODE_3700); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireForm3700, result:" << result; + + std::cout << "END FmsAcquireForm3700" << std::endl; +} + void FmsAcquireFormTestBatch::FMS_acquireFormBatchA(const std::string &bundleName, const std::string &abilityName, const int count) { diff --git a/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp b/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp index 4aae43bb0d63ec86c0847bb0e0f81733f715db1c..1ec3b67412b27559cc3b3594b05f4c869ac714b7 100644 --- a/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp +++ b/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp @@ -90,6 +90,7 @@ public: void FMS_acquireNormalFormBatch(const std::string &bundleName, const std::string &abilityName, const int count); void FMS_deleteFormBatch(const std::string &bundleName, const std::string &abilityName); + void FMS_deleteFormDeleteA(std::string delFormId); }; std::vector FmsDeleteFormTest::eventList = { @@ -101,6 +102,8 @@ std::vector FmsDeleteFormTest::eventList = { FORM_EVENT_RECV_DELETE_FORM_0500, FORM_EVENT_RECV_DELETE_FORM_0600, FORM_EVENT_RECV_DELETE_FORM_0700, + FORM_EVENT_RECV_DELETE_FORM_0700_1, + FORM_EVENT_RECV_DELETE_FORM_0700_2, FORM_EVENT_RECV_DELETE_FORM_0800, FORM_EVENT_RECV_DELETE_FORM_0900, FORM_EVENT_RECV_DELETE_FORM_1000, @@ -123,9 +126,12 @@ std::vector FmsDeleteFormTest::eventList = { FORM_EVENT_RECV_ONE_NORMAL_FORM_B, FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, COMMON_EVENT_ON_DELETE, + FORM_EVENT_RECV_DELETE_FORM_COMMON, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, - FORM_EVENT_RECV_CLEAR_FORM_BATCH + FORM_EVENT_RECV_CLEAR_FORM_BATCH, + FORM_EVENT_RECV_ONE_NORMAL_FORM_001, + FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001 }; FormEvent FmsDeleteFormTest::event = FormEvent(); @@ -172,6 +178,8 @@ bool FmsDeleteFormTest::SubscribeEvent() FORM_EVENT_RECV_DELETE_FORM_0500, FORM_EVENT_RECV_DELETE_FORM_0600, FORM_EVENT_RECV_DELETE_FORM_0700, + FORM_EVENT_RECV_DELETE_FORM_0700_1, + FORM_EVENT_RECV_DELETE_FORM_0700_2, FORM_EVENT_RECV_DELETE_FORM_0800, FORM_EVENT_RECV_DELETE_FORM_0900, FORM_EVENT_RECV_DELETE_FORM_1000, @@ -194,9 +202,13 @@ bool FmsDeleteFormTest::SubscribeEvent() FORM_EVENT_RECV_ONE_NORMAL_FORM_B, FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, COMMON_EVENT_ON_DELETE, + FORM_EVENT_RECV_DELETE_FORM_COMMON, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, - FORM_EVENT_RECV_CLEAR_FORM_BATCH + FORM_EVENT_RECV_CLEAR_FORM_BATCH, + FORM_EVENT_RECV_ONE_NORMAL_FORM_001, + FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001 + }; MatchingSkills matchingSkills; for (const auto &e : eventList) { @@ -509,6 +521,143 @@ HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0700, Function | MediumTest | Level1) std::cout << "============END FMS_deleteForm_0700" << std::endl; } +/** + * @tc.number: FMS_deleteForm_0700_1 + * @tc.name: After deleting a normal form, the form reference is 0. + * After deleting a form, there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A delete the form and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0700_1, Function | MediumTest | Level1) +{ + std::cout << "============START FMS_deleteForm_0700_1" << std::endl; + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_001, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_001, EVENT_CODE_100)); + std::string formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_001, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_1, formOne:[" << formOne << "]" << std::endl; + EXPECT_TRUE(formOne != ""); + if (formOne != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityDeleteForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = formOne; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0700_1, EVENT_CODE_700_1, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0700_1, EVENT_CODE_700_1)); + std::string formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0700_1, EVENT_CODE_700_1); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_1, formTwo:[" << formTwo << "]" << std::endl; + bool result = (formTwo != "false" && formTwo != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_1, result:" << result; + } + + want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + // can receive onDelete + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL_001, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001, EVENT_CODE_101)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formOne.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formOne.c_str())); + bool timerResA = FmsGetFormTimerTask(atoll(formOne.c_str())); + bool timerResB = FmsGetFormTimerTask(atoll(formTwo.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); + EXPECT_FALSE(timerResA); + EXPECT_TRUE(timerResB); + + FMS_deleteFormDeleteA(formTwo); + + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_deleteForm_0700_1" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0700_2 + * @tc.name: After deleting a normal form, the form reference is 0. + * After deleting a form, there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A delete the form and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0700_2, Function | MediumTest | Level1) +{ + std::cout << "============START FMS_deleteForm_0700_2" << std::endl; + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_001, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_001, EVENT_CODE_100)); + std::string formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_001, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_2, formOne:[" << formOne << "]" << std::endl; + EXPECT_TRUE(formOne != ""); + if (formOne != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityDeleteForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = formOne; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0700_2, EVENT_CODE_700_2, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0700_2, EVENT_CODE_700_2)); + std::string formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0700_2, EVENT_CODE_700_2); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_2, formTwo:[" << formTwo << "]" << std::endl; + bool result = (formTwo != "false" && formTwo != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_2, result:" << result; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0700_2, + EVENT_CODE_700_2)); + std::string onDeleteData = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0700_2, + EVENT_CODE_700_2); + EXPECT_TRUE(onDeleteData == formTwo); + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formTwo.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formTwo.c_str())); + bool timerResA = FmsGetFormTimerTask(atoll(formOne.c_str())); + bool timerResB = FmsGetFormTimerTask(atoll(formTwo.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); + EXPECT_TRUE(timerResA); + EXPECT_FALSE(timerResB); + + want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL_001, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL_001, EVENT_CODE_101)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_deleteForm_0700_2" << std::endl; +} + /** * @tc.number: FMS_deleteForm_0800 * @tc.name: After deleting a normal form, there is no created normal form in FMS. @@ -518,35 +667,61 @@ HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0700, Function | MediumTest | Level1) HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0800, Function | MediumTest | Level1) { std::cout << "============START FMS_deleteForm_0800" << std::endl; - - std::string bundleName = "com.ohos.form.manager.normal"; - std::string abilityName = "FormAbilityDeleteForm"; + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; MAP_STR_STR params; Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); SystemTestFormUtil::StartAbility(want, abilityManager); EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); - std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0800; - SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0800, EVENT_CODE_800, eventData); - EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800)); - std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800); - bool result = (data != "false" && data != ""); - EXPECT_TRUE(result); - if (!result) { - GTEST_LOG_(INFO) << "FMS_deleteForm_0800, result:" << result; + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700_2, formOne:[" << formOne << "]" << std::endl; + EXPECT_TRUE(formOne != ""); + if (formOne != "") { + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0800; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0800, EVENT_CODE_800, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800); + bool result = (data != "false" && data != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0800, result:" << result; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + std::string onDeleteData = SystemTestFormUtil::GetData(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK); + EXPECT_TRUE(onDeleteData == data); + + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + + bool cacheResA = FmsGetCacheInfoByFormId(atoll(formOne.c_str())); + bool storageResA = FmsGetStorageFormInfos(atoll(formOne.c_str())); + bool cacheResB = FmsGetCacheInfoByFormId(atoll(data.c_str())); + bool storageResB = FmsGetStorageFormInfos(atoll(data.c_str())); + bool timerResA = FmsGetFormTimerTask(atoll(formOne.c_str())); + bool timerResB = FmsGetFormTimerTask(atoll(data.c_str())); + EXPECT_FALSE(cacheResA); + EXPECT_FALSE(storageResA); + EXPECT_FALSE(cacheResB); + EXPECT_FALSE(storageResB); + EXPECT_FALSE(timerResA); + EXPECT_FALSE(timerResB); } - // can receive onDelete - EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, - FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); - std::string onDeleteData = SystemTestFormUtil::GetData(event, COMMON_EVENT_ON_DELETE, - FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK); - EXPECT_TRUE(onDeleteData == data); - bool cacheRes = FmsGetCacheInfoByFormId(atoll(data.c_str())); - bool storageRes = FmsGetStorageFormInfos(atoll(data.c_str())); - bool timerRes = FmsGetFormTimerTask(atoll(data.c_str())); - EXPECT_FALSE(cacheRes); - EXPECT_FALSE(storageRes); - EXPECT_FALSE(timerRes); SystemTestFormUtil::CleanMsg(event); std::cout << "============END FMS_deleteForm_0800" << std::endl; } @@ -608,7 +783,7 @@ HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1000, Function | MediumTest | Level1) SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1000, EVENT_CODE_1000, eventData); EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000)); std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000); - bool result = data == "true"; + bool result = (data != "false" && data != ""); EXPECT_TRUE(result); if (!result) { GTEST_LOG_(INFO) << "FMS_deleteForm_1000, result:" << result; @@ -618,6 +793,11 @@ HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1000, Function | MediumTest | Level1) FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); SystemTestFormUtil::CleanMsg(event); + bool cacheRes = FmsGetCacheInfoByFormId(atoll(data.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(data.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); + std::cout << "============END FMS_deleteForm_1000" << std::endl; } @@ -724,11 +904,15 @@ HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1200, Function | MediumTest | Level2) EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201)); std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201); GTEST_LOG_(INFO) << "========FMS_deleteForm_1200 [#Delete#]formId:[" << formIds[i] << "]======>>index:" << i; - bool result = data == "true"; + bool result = (data != "false" && data != ""); EXPECT_TRUE(result); if (!result) { GTEST_LOG_(INFO) << "FMS_deleteForm_1201, result:" << result; } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(data.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(data.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); } SystemTestFormUtil::CleanMsg(event); std::cout << "============END FMS_deleteForm_1200" << std::endl; @@ -921,6 +1105,10 @@ void FmsDeleteFormTest::FMS_deleteForm_1400_A() } EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formIds[i].c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formIds[i].c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); } } void FmsDeleteFormTest::FMS_deleteForm_1400_B() @@ -963,6 +1151,10 @@ void FmsDeleteFormTest::FMS_deleteForm_1400_B() } EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formIds[i].c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formIds[i].c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); } } void FmsDeleteFormTest::FMS_deleteForm_1500_Create_Delete(std::string delFormId, std::string &createFormId) @@ -1200,5 +1392,28 @@ void FmsDeleteFormTest::FMS_deleteFormBatch(const std::string &bundleName, const GTEST_LOG_(INFO) << "FMS_deleteFormBatch, result:" << result; std::cout << "END FMS_deleteFormBatch, delete forms" << std::endl; } + +void FmsDeleteFormTest::FMS_deleteFormDeleteA(std::string strFormId) +{ + std::cout << "START FMS_deleteFormDeleteA, start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + std::cout << "START FMS_deleteFormDeleteA, bundleName: " << bundleName << std::endl; + std::cout << "START FMS_deleteFormDeleteA, abilityName: " << abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + std::string eventData = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_COMMON, EVENT_CODE_999, eventData); + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result = data == "true"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_deleteFormDeleteA, delete form, result:" << result; + + std::cout << "END FMS_deleteFormDeleteA end" << std::endl; +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh b/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh index 3e71c7655ebe4ced726e040587371d4b8eff0db0..e9d4e267fc6ec90f33d86948421bad5dd29aa226 100644 --- a/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh +++ b/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh @@ -13,16 +13,32 @@ sleepSeconds=20 -echo "acquire forms" -./FmsSelfStartingTest +rm -rf /data/formmgr +mkdir /data/formmgr -if [ $? -eq 0 ]; then - sleep 10 - echo "acquire forms succeed" -else - echo "acquire forms failed" - exit -fi +chown system /data/formmgr +chgrp system /data/formmgr + +for i in $(seq 1 256) +do + echo {\"${i}\":{\"abilityName\":\"FormStServiceAbilityA\",\"bundleName\":\"com.form.formsystemtestservicea\",\"formId\":${i},\"formName\":\"Form_Js001\",\"formUserUids\":[2116],\"moduleName\":\"formmodule001\"}} > "/data/formmgr/${i}.json"; + chown system /data/formmgr/${i}.json + chgrp system /data/formmgr/${i}.json +done + +for i in $(seq 257 512) +do + echo {\"${i}\":{\"abilityName\":\"FormStServiceAbilityA\",\"bundleName\":\"com.form.formsystemtestservicea\",\"formId\":${i},\"formName\":\"Form_Js001\",\"formUserUids\":[2117],\"moduleName\":\"formmodule001\"}} > "/data/formmgr/${i}.json"; + chown system /data/formmgr/${i}.json + chgrp system /data/formmgr/${i}.json +done + +sleep 2 +echo "kill foundation" +pgrep foundation | xargs kill -9 + +echo "sleep ${sleepSeconds} seconds" +sleep ${sleepSeconds} formStorage=`fm query -s` echo "get form storage:" @@ -40,9 +56,11 @@ echo "get form storage after FMS restart:" echo "${newFormStorage}" if [ "${formStorage}" == "${newFormStorage}" ]; then - echo "same form storage" + echo "form storage verify OK" else - echo "not same form storage" + echo "form storage verify NG" fi -exit \ No newline at end of file +rm -rf /data/formmgr + +exit diff --git a/tools/fm/src/fms_command.cpp b/tools/fm/src/fms_command.cpp index 462165df9a8f3367e9b8f15e57fb03010cec9ca0..bcc3b184ed542d129cb925926ff765e1489e6afc 100755 --- a/tools/fm/src/fms_command.cpp +++ b/tools/fm/src/fms_command.cpp @@ -445,7 +445,7 @@ int FormMgrShellCommand::GetStringInfo(IFormMgr::Message code, MessageParcel &da std::vector stringInfoList; if (!reply.ReadStringVector(&stringInfoList)) { APP_LOGE("%{public}s, failed to read string vector from reply", __func__); - return false; + return ERR_APPEXECFWK_PARCEL_ERROR; } if (stringInfoList.empty()) { APP_LOGI("%{public}s, No string info", __func__);