From 0e0e35b33f7655f25e350d6db9e4aa17376d809f Mon Sep 17 00:00:00 2001 From: SoftSquirrel Date: Tue, 29 Mar 2022 14:56:36 +0800 Subject: [PATCH] IssueNo: #I50454: delete moduleUsageRecord code Description: delete moduleUsageRecord code Sig: SIG_ApplicaitonFramework Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: SoftSquirrel --- interfaces/innerkits/appexecfwk_base/BUILD.gn | 1 - .../include/module_usage_record.h | 58 -- .../src/module_usage_record.cpp | 130 ---- .../include/bundlemgr/bundle_mgr_host.h | 14 - .../include/bundlemgr/bundle_mgr_interface.h | 3 - .../src/bundlemgr/bundle_mgr_host.cpp | 46 -- .../src/bundlemgr/bundle_mgr_proxy.cpp | 55 +- kits/appkit/napi/bundlemgr/bundle_mgr.cpp | 125 ---- kits/appkit/napi/bundlemgr/bundle_mgr.h | 8 - kits/appkit/napi/bundlemgr/native_module.cpp | 1 - services/bundlemgr/BUILD.gn | 1 - services/bundlemgr/include/bundle_data_mgr.h | 28 - services/bundlemgr/include/common_profile.h | 1 - .../include/module_usage_data_storage.h | 2 - services/bundlemgr/src/bundle_data_mgr.cpp | 136 ---- .../bundlemgr/src/bundle_mgr_host_impl.cpp | 17 +- .../src/module_usage_data_storage.cpp | 390 ---------- .../bms_bundle_accesstokenid_test/BUILD.gn | 1 - .../unittest/bms_bundle_clone_test/BUILD.gn | 1 - .../bms_bundle_data_storage_test.cpp | 678 ------------------ .../bms_bundle_installer_test/BUILD.gn | 2 - .../bms_bundle_kit_service_test/BUILD.gn | 1 - .../bms_bundle_kit_service_test.cpp | 186 ----- .../bms_bundle_permission_grant_test/BUILD.gn | 1 - .../bms_bundle_uninstaller_test/BUILD.gn | 1 - .../unittest/bms_bundle_updater_test/BUILD.gn | 1 - .../test/unittest/bms_data_mgr_test/BUILD.gn | 1 - .../bms_service_bundle_scan_test/BUILD.gn | 1 - .../bms_service_startup_test/BUILD.gn | 1 - .../common/bms/bundle_installer_test/BUILD.gn | 1 - .../common/bms/bundle_uninstall_test/BUILD.gn | 1 - .../bms/service_start_process_test/BUILD.gn | 1 - .../bundlemgr_proxy_test.cpp | 40 -- .../module_usage_record_test/BUILD.gn | 50 -- .../module_usage_record_test.cpp | 138 ---- tools/test/mock/mock_bundle_mgr_host.h | 4 - 36 files changed, 4 insertions(+), 2122 deletions(-) delete mode 100644 interfaces/innerkits/appexecfwk_base/include/module_usage_record.h delete mode 100644 interfaces/innerkits/appexecfwk_base/src/module_usage_record.cpp delete mode 100644 services/bundlemgr/src/module_usage_data_storage.cpp delete mode 100644 services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_test.cpp delete mode 100644 test/benchmarktest/module_usage_record_test/BUILD.gn delete mode 100644 test/benchmarktest/module_usage_record_test/module_usage_record_test.cpp diff --git a/interfaces/innerkits/appexecfwk_base/BUILD.gn b/interfaces/innerkits/appexecfwk_base/BUILD.gn index f3c1a9f5..d8959d1e 100644 --- a/interfaces/innerkits/appexecfwk_base/BUILD.gn +++ b/interfaces/innerkits/appexecfwk_base/BUILD.gn @@ -40,7 +40,6 @@ ohos_shared_library("appexecfwk_base") { "src/hap_module_info.cpp", "src/install_param.cpp", "src/module_info.cpp", - "src/module_usage_record.cpp", "src/permission_def.cpp", "src/remote_ability_info.cpp", "src/shortcut_info.cpp", diff --git a/interfaces/innerkits/appexecfwk_base/include/module_usage_record.h b/interfaces/innerkits/appexecfwk_base/include/module_usage_record.h deleted file mode 100644 index faf211f2..00000000 --- a/interfaces/innerkits/appexecfwk_base/include/module_usage_record.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_MODULE_USAGE_RECORD_H -#define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_MODULE_USAGE_RECORD_H - -#include - -#include "ability_info.h" -#include "parcel.h" -#include "refbase.h" - -namespace OHOS { -namespace AppExecFwk { -namespace UsageRecordKey { - const std::string LAUNCHED_COUNT = "launchedCount"; - const std::string LAST_LAUNCH_TIME = "lastLaunchTime"; - const std::string IS_REMOVED = "isRemoved"; - const std::string ABILITY_NAME = "abilityName"; - const std::string SCHEMA_LAST_LAUNCH_TIME = "$.lastLaunchTime"; -} // UsageRecordKey - -struct ModuleUsageRecord : public Parcelable { - std::string bundleName; - uint32_t appLabelId = 0; - std::string name; - uint32_t labelId = 0; - uint32_t descriptionId = 0; - std::string abilityName; - uint32_t abilityLabelId = 0; - uint32_t abilityDescriptionId = 0; - uint32_t abilityIconId = 0; - uint32_t launchedCount = 0; - int64_t lastLaunchTime = 0; - bool removed = false; - bool installationFreeSupported = true; - - bool ReadFromParcel(Parcel &parcel); - virtual bool Marshalling(Parcel &parcel) const override; - static ModuleUsageRecord *Unmarshalling(Parcel &parcel); - std::string ToString() const; - bool FromJsonString(const std::string &jsonString); -}; -} // namespace AppExecFwk -} // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_MODULE_USAGE_RECORD_H diff --git a/interfaces/innerkits/appexecfwk_base/src/module_usage_record.cpp b/interfaces/innerkits/appexecfwk_base/src/module_usage_record.cpp deleted file mode 100644 index da1f3f8d..00000000 --- a/interfaces/innerkits/appexecfwk_base/src/module_usage_record.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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 "module_usage_record.h" - -#include "string_ex.h" - -#include "json_util.h" -#include "nlohmann/json.hpp" -#include "parcel_macro.h" - -namespace OHOS { -namespace AppExecFwk { -bool ModuleUsageRecord::ReadFromParcel(Parcel &parcel) -{ - name = Str16ToStr8(parcel.ReadString16()); - bundleName = Str16ToStr8(parcel.ReadString16()); - abilityName = Str16ToStr8(parcel.ReadString16()); - appLabelId = static_cast(parcel.ReadInt32()); - labelId = static_cast(parcel.ReadInt32()); - descriptionId = static_cast(parcel.ReadInt32()); - abilityLabelId = static_cast(parcel.ReadInt32()); - abilityDescriptionId = static_cast(parcel.ReadInt32()); - abilityIconId = static_cast(parcel.ReadInt32()); - launchedCount = static_cast(parcel.ReadInt32()); - lastLaunchTime = parcel.ReadInt64(); - removed = parcel.ReadBool(); - installationFreeSupported = parcel.ReadBool(); - return true; -} - -ModuleUsageRecord *ModuleUsageRecord::Unmarshalling(Parcel &parcel) -{ - ModuleUsageRecord *record = new ModuleUsageRecord(); - if (record && !record->ReadFromParcel(parcel)) { - APP_LOGW("read ModuleUsageRecord from parcel failed"); - delete record; - record = nullptr; - } - return record; -} - -bool ModuleUsageRecord::Marshalling(Parcel &parcel) const -{ - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(name)); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName)); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(abilityName)); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, appLabelId); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, labelId); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, descriptionId); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilityLabelId); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilityDescriptionId); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, abilityIconId); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, launchedCount); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, lastLaunchTime); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, removed); - WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, installationFreeSupported); - return true; -} - -std::string ModuleUsageRecord::ToString() const -{ - nlohmann::json json; - json[UsageRecordKey::LAUNCHED_COUNT] = launchedCount; - json[UsageRecordKey::LAST_LAUNCH_TIME] = lastLaunchTime; - json[UsageRecordKey::IS_REMOVED] = removed; - json[UsageRecordKey::ABILITY_NAME] = abilityName; - return json.dump(); -} - -bool ModuleUsageRecord::FromJsonString(const std::string &jsonString) -{ - nlohmann::json jsonObject; - - jsonObject = nlohmann::json::parse(jsonString); - if (jsonObject.is_discarded()) { - APP_LOGE("failed to parse module usage record: %{public}s.", jsonString.c_str()); - return false; - } - - const auto &jsonObjectEnd = jsonObject.end(); - int32_t parseResult = ERR_OK; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UsageRecordKey::LAUNCHED_COUNT, - launchedCount, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UsageRecordKey::LAST_LAUNCH_TIME, - lastLaunchTime, - JsonType::NUMBER, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UsageRecordKey::IS_REMOVED, - removed, - JsonType::BOOLEAN, - false, - parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UsageRecordKey::ABILITY_NAME, - abilityName, - JsonType::STRING, - false, - parseResult, - ArrayType::NOT_ARRAY); - return parseResult == ERR_OK; -} -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h b/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h index 7f174ba4..fdc3123d 100644 --- a/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h +++ b/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_host.h @@ -471,20 +471,6 @@ private: * @return Returns ERR_OK if called successfully; returns error code otherwise. */ ErrCode HandleGetAllCommonEventInfo(Parcel &data, Parcel &reply); - /** - * @brief Handles the HandleGetModuleUsageRecords function called from a IBundleMgr proxy object. - * @param data Indicates the data to be read. - * @param reply Indicates the reply to be sent; - * @return Returns ERR_OK if called successfully; returns error code otherwise. - */ - ErrCode HandleGetModuleUsageRecords(Parcel &data, Parcel &reply); - /** - * @brief Handles the HandleNotifyAbilityLifeStatus function called from a IBundleMgr proxy object. - * @param data Indicates the data to be read. - * @param reply Indicates the reply to be sent; - * @return Returns ERR_OK if called successfully; returns error code otherwise. - */ - ErrCode HandleNotifyAbilityLifeStatus(Parcel &data, Parcel &reply); /** * @brief Handles the HandleRemoveClonedBundle function called from a IBundleMgr proxy object. * @param data Indicates the data to be read. diff --git a/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index 5b42a344..171b79b6 100644 --- a/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/interfaces/innerkits/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -29,7 +29,6 @@ #include "form_info.h" #include "foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include/permission_def.h" #include "hap_module_info.h" -#include "module_usage_record.h" #include "on_permission_changed_callback_interface.h" #include "ohos/aafwk/content/want.h" #ifdef SUPPORT_GRAPHICS @@ -772,11 +771,9 @@ public: GET_ALL_FORMS_INFO, GET_FORMS_INFO_BY_APP, GET_FORMS_INFO_BY_MODULE, - GET_MODULE_USAGE_RECORD, GET_SHORTCUT_INFO, GET_ALL_COMMON_EVENT_INFO, GET_BUNDLE_INSTALLER, - NOTIFY_ABILITY_LIFE_STATUS, REMOVE_CLONED_BUNDLE, BUNDLE_CLONE, CHECK_BUNDLE_NAME_IN_ALLOWLIST, diff --git a/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp b/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp index b7072241..d5c7e7c2 100644 --- a/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp +++ b/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_host.cpp @@ -256,12 +256,6 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa case static_cast(IBundleMgr::Message::GET_ALL_COMMON_EVENT_INFO): errCode = HandleGetAllCommonEventInfo(data, reply); break; - case static_cast(IBundleMgr::Message::GET_MODULE_USAGE_RECORD): - errCode = HandleGetModuleUsageRecords(data, reply); - break; - case static_cast(IBundleMgr::Message::NOTIFY_ABILITY_LIFE_STATUS): - errCode = HandleNotifyAbilityLifeStatus(data, reply); - break; case static_cast(IBundleMgr::Message::CHECK_BUNDLE_NAME_IN_ALLOWLIST): errCode = HandleCheckBundleNameInAllowList(data, reply); break; @@ -1565,46 +1559,6 @@ ErrCode BundleMgrHost::HandleGetAllCommonEventInfo(Parcel &data, Parcel &reply) return ERR_OK; } -ErrCode BundleMgrHost::HandleGetModuleUsageRecords(Parcel &data, Parcel &reply) -{ - BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); - int32_t number = data.ReadInt32(); - std::vector records; - bool ret = GetModuleUsageRecords(number, records); - if (!reply.WriteBool(ret)) { - APP_LOGE("write failed"); - return ERR_APPEXECFWK_PARCEL_ERROR; - } - - if (ret) { - if (!WriteParcelableVector(records, reply)) { - APP_LOGE("write failed"); - return ERR_APPEXECFWK_PARCEL_ERROR; - } - } - return ERR_OK; -} - -ErrCode BundleMgrHost::HandleNotifyAbilityLifeStatus(Parcel &data, Parcel &reply) -{ - BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); - std::string bundleName = data.ReadString(); - std::string abilityName = data.ReadString(); - int64_t launchTime = data.ReadInt64(); - int32_t uid = data.ReadInt32(); - APP_LOGI("bundleName %{public}s, abilityName %{public}s, launchTime %{public}" PRId64, - bundleName.c_str(), - abilityName.c_str(), - launchTime); - - bool ret = NotifyAbilityLifeStatus(bundleName, abilityName, launchTime, uid); - if (!reply.WriteBool(ret)) { - APP_LOGE("write failed"); - return ERR_APPEXECFWK_PARCEL_ERROR; - } - return ERR_OK; -} - ErrCode BundleMgrHost::HandleCheckBundleNameInAllowList(Parcel &data, Parcel &reply) { BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); diff --git a/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp b/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp index 6c141cce..5d6b4d85 100644 --- a/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp +++ b/interfaces/innerkits/appexecfwk_core/src/bundlemgr/bundle_mgr_proxy.cpp @@ -1965,64 +1965,13 @@ bool BundleMgrProxy::GetAllCommonEventInfo(const std::string &eventKey, std::vec bool BundleMgrProxy::GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) { - BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - APP_LOGE("fail to GetModuleUsageRecords due to write MessageParcel fail"); - return false; - } - - if (!data.WriteInt32(number)) { - APP_LOGE("fail to GetModuleUsageRecords due to write number fail"); - return false; - } - - if (!GetParcelableInfos( - IBundleMgr::Message::GET_MODULE_USAGE_RECORD, data, moduleUsageRecords)) { - APP_LOGE("fail to GetModuleUsageRecords from server"); - return false; - } - return true; + return false; } bool BundleMgrProxy::NotifyAbilityLifeStatus( const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) { - BYTRACE_NAME(BYTRACE_TAG_APP, __PRETTY_FUNCTION__); - APP_LOGI("begin to NotifyAbilityLifeStatus of %{public}s", abilityName.c_str()); - if (bundleName.empty() || abilityName.empty()) { - APP_LOGE("fail to NotifyAbilityLifeStatus due to params empty"); - return false; - } - - MessageParcel data; - if (!data.WriteInterfaceToken(GetDescriptor())) { - APP_LOGE("fail to NotifyAbilityLifeStatus due to write InterfaceToken fail"); - return false; - } - if (!data.WriteString(bundleName)) { - APP_LOGE("fail to NotifyAbilityLifeStatus due to write bundleName fail"); - return false; - } - if (!data.WriteString(abilityName)) { - APP_LOGE("fail to NotifyAbilityLifeStatus due to write abilityName fail"); - return false; - } - if (!data.WriteInt64(launchTime)) { - APP_LOGE("fail to NotifyAbilityLifeStatus due to write launchTime fail"); - return false; - } - if (!data.WriteInt32(uid)) { - APP_LOGE("fail to NotifyAbilityLifeStatus due to write uid fail"); - return false; - } - - MessageParcel reply; - if (!SendTransactCmd(IBundleMgr::Message::NOTIFY_ABILITY_LIFE_STATUS, data, reply)) { - APP_LOGE("fail to NotifyAbilityLifeStatus from server"); - return false; - } - return reply.ReadBool(); + return false; } bool BundleMgrProxy::CheckBundleNameInAllowList(const std::string &bundleName) diff --git a/kits/appkit/napi/bundlemgr/bundle_mgr.cpp b/kits/appkit/napi/bundlemgr/bundle_mgr.cpp index b7ceafcb..1bb1539c 100644 --- a/kits/appkit/napi/bundlemgr/bundle_mgr.cpp +++ b/kits/appkit/napi/bundlemgr/bundle_mgr.cpp @@ -3624,131 +3624,6 @@ napi_value GetFormsInfoByApp(napi_env env, napi_callback_info info) } } -static void ProcessModuleUsageRecords( - napi_env env, napi_value result, const std::vector &moduleUsageRecords) -{ - if (moduleUsageRecords.size() > 0) { - APP_LOGI("-----moduleUsageRecords is not null-----"); - size_t index = 0; - for (const auto &item : moduleUsageRecords) { - APP_LOGI("bundleName{%s} ", item.bundleName.c_str()); - APP_LOGI("abilityName{%s} ", item.abilityName.c_str()); - napi_value objModuleUsageRecord; - NAPI_CALL_RETURN_VOID(env, napi_create_object(env, &objModuleUsageRecord)); - ConvertModuleUsageRecords(env, objModuleUsageRecord, item); - NAPI_CALL_RETURN_VOID(env, napi_set_element(env, result, index, objModuleUsageRecord)); - index++; - } - } else { - APP_LOGI("-----moduleUsageRecords is null-----"); - } -} - -static bool InnerGetModuleUsageRecords( - napi_env env, const int32_t number, std::vector &moduleUsageRecords) -{ - auto iBundleMgr = GetBundleMgr(); - if (!iBundleMgr) { - APP_LOGE("can not get iBundleMgr"); - return false; - } - return iBundleMgr->GetModuleUsageRecords(number, moduleUsageRecords); -} -/** - * Promise and async callback - */ -napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info) -{ - size_t argc = ARGS_SIZE_THREE; - napi_value argv[ARGS_SIZE_THREE] = {nullptr}; - napi_value thisArg; - void *data = nullptr; - NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisArg, &data)); - APP_LOGI("ARGCSIZE is =%{public}zu.", argc); - int number; - ParseInt(env, number, argv[PARAM0]); - AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = - new (std::nothrow) AsyncModuleUsageRecordsCallbackInfo(env); - if (asyncCallbackInfo == nullptr) { - return nullptr; - } - std::unique_ptr callbackPtr {asyncCallbackInfo}; - asyncCallbackInfo->number = number; - if (argc > (ARGS_SIZE_TWO - CALLBACK_SIZE)) { - APP_LOGI("GetModuleUsageRecords asyncCallback."); - napi_value resourceName; - NAPI_CALL(env, napi_create_string_latin1(env, "GetModuleUsageRecords", NAPI_AUTO_LENGTH, &resourceName)); - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[ARGS_SIZE_ONE], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "Wrong argument type. Function expected."); - NAPI_CALL(env, napi_create_reference(env, argv[ARGS_SIZE_ONE], NAPI_RETURN_ONE, &asyncCallbackInfo->callback)); - - NAPI_CALL(env, napi_create_async_work( - env, - nullptr, - resourceName, - [](napi_env env, void *data) { - AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = (AsyncModuleUsageRecordsCallbackInfo *)data; - asyncCallbackInfo->ret = - InnerGetModuleUsageRecords(env, asyncCallbackInfo->number, asyncCallbackInfo->moduleUsageRecords); - }, - [](napi_env env, napi_status status, void *data) { - AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = (AsyncModuleUsageRecordsCallbackInfo *)data; - std::unique_ptr callbackPtr {asyncCallbackInfo}; - napi_value result[ARGS_SIZE_TWO] = {0}; - napi_value callback = 0; - napi_value undefined = 0; - napi_value callResult = 0; - NAPI_CALL_RETURN_VOID(env, napi_get_undefined(env, &undefined)); - NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &result[PARAM1])); - ProcessModuleUsageRecords(env, result[PARAM1], asyncCallbackInfo->moduleUsageRecords); - result[PARAM0] = GetCallbackErrorValue(env, asyncCallbackInfo->ret ? CODE_SUCCESS : CODE_FAILED); - NAPI_CALL_RETURN_VOID(env, napi_get_reference_value(env, asyncCallbackInfo->callback, &callback)); - NAPI_CALL_RETURN_VOID(env, napi_call_function(env, undefined, callback, ARGS_SIZE_TWO, - &result[PARAM0], &callResult)); - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - callbackPtr.release(); - napi_value result; - napi_create_int32(env, NAPI_RETURN_ONE, &result); - return result; - } else { - APP_LOGI("GetModuleUsageRecords promise."); - napi_deferred deferred; - napi_value promise; - NAPI_CALL(env, napi_create_promise(env, &deferred, &promise)); - asyncCallbackInfo->deferred = deferred; - - napi_value resourceName; - NAPI_CALL(env, napi_create_string_latin1(env, "GetModuleUsageRecords", NAPI_AUTO_LENGTH, &resourceName)); - NAPI_CALL(env, napi_create_async_work( - env, - nullptr, - resourceName, - [](napi_env env, void *data) { - AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = (AsyncModuleUsageRecordsCallbackInfo *)data; - InnerGetModuleUsageRecords(env, asyncCallbackInfo->number, asyncCallbackInfo->moduleUsageRecords); - }, - [](napi_env env, napi_status status, void *data) { - APP_LOGI("=================load================="); - AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = (AsyncModuleUsageRecordsCallbackInfo *)data; - std::unique_ptr callbackPtr {asyncCallbackInfo}; - napi_value result; - NAPI_CALL_RETURN_VOID(env, napi_create_array(env, &result)); - ProcessModuleUsageRecords(env, result, asyncCallbackInfo->moduleUsageRecords); - NAPI_CALL_RETURN_VOID(env, napi_resolve_deferred(asyncCallbackInfo->env, asyncCallbackInfo->deferred, - result)); - }, - (void *)asyncCallbackInfo, - &asyncCallbackInfo->asyncWork)); - NAPI_CALL(env, napi_queue_async_work(env, asyncCallbackInfo->asyncWork)); - callbackPtr.release(); - return promise; - } -} - static bool InnerRegisterAllPermissionsChanged(napi_env env, napi_ref callbackRef) { APP_LOGI("InnerRegisterAllPermissionsChanged begin"); diff --git a/kits/appkit/napi/bundlemgr/bundle_mgr.h b/kits/appkit/napi/bundlemgr/bundle_mgr.h index 0c7776fe..93159835 100644 --- a/kits/appkit/napi/bundlemgr/bundle_mgr.h +++ b/kits/appkit/napi/bundlemgr/bundle_mgr.h @@ -187,13 +187,6 @@ struct AsyncGetBundleGidsCallbackInfo : public AsyncWorkData { std::string message; }; -struct AsyncModuleUsageRecordsCallbackInfo : public AsyncWorkData { - explicit AsyncModuleUsageRecordsCallbackInfo(napi_env env) : AsyncWorkData(env) {} - int32_t number; - std::vector moduleUsageRecords; - bool ret = false; -}; - struct AsyncExtensionInfoCallbackInfo : public AsyncWorkData { explicit AsyncExtensionInfoCallbackInfo(napi_env env) : AsyncWorkData(env) {} OHOS::AAFwk::Want want; @@ -292,7 +285,6 @@ napi_value GetAllFormsInfo(napi_env env, napi_callback_info info); napi_value GetFormsInfoByApp(napi_env env, napi_callback_info info); napi_value GetFormsInfoByModule(napi_env env, napi_callback_info info); napi_value GetShortcutInfos(napi_env env, napi_callback_info info); -napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info); napi_value RegisterAllPermissionsChanged(napi_env env, napi_callback_info info); napi_value UnregisterPermissionsChanged(napi_env env, napi_callback_info info); napi_value ClearBundleCache(napi_env env, napi_callback_info info); diff --git a/kits/appkit/napi/bundlemgr/native_module.cpp b/kits/appkit/napi/bundlemgr/native_module.cpp index 485dbfc3..fc8f4355 100644 --- a/kits/appkit/napi/bundlemgr/native_module.cpp +++ b/kits/appkit/napi/bundlemgr/native_module.cpp @@ -112,7 +112,6 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("getFormsInfoByModule", GetFormsInfoByModule), DECLARE_NAPI_FUNCTION("getFormsInfo", GetFormsInfoByApp), DECLARE_NAPI_FUNCTION("getAllFormsInfo", GetAllFormsInfo), - DECLARE_NAPI_FUNCTION("getModuleUsageRecords", GetModuleUsageRecords), DECLARE_NAPI_FUNCTION("on", RegisterAllPermissionsChanged), DECLARE_NAPI_FUNCTION("off", UnregisterPermissionsChanged), DECLARE_NAPI_FUNCTION("cleanBundleCacheFiles", ClearBundleCache), diff --git a/services/bundlemgr/BUILD.gn b/services/bundlemgr/BUILD.gn index 883150a1..b31652a9 100644 --- a/services/bundlemgr/BUILD.gn +++ b/services/bundlemgr/BUILD.gn @@ -141,7 +141,6 @@ ohos_shared_library("libbms") { "src/distributed_data_storage.cpp", "src/hidump_helper.cpp", "src/kvstore_death_recipient_callback.cpp", - "src/module_usage_data_storage.cpp", "src/permission_changed_death_recipient.cpp", "src/preinstall_data_storage.cpp", "src/system_ability_helper.cpp", diff --git a/services/bundlemgr/include/bundle_data_mgr.h b/services/bundlemgr/include/bundle_data_mgr.h index d569cb96..421ff93d 100644 --- a/services/bundlemgr/include/bundle_data_mgr.h +++ b/services/bundlemgr/include/bundle_data_mgr.h @@ -34,8 +34,6 @@ #include "distributed_data_storage.h" #include "inner_bundle_info.h" #include "inner_bundle_user_info.h" -#include "module_usage_data_storage.h" -#include "module_usage_record.h" #include "on_permission_changed_callback_interface.h" #ifdef SUPPORT_GRAPHICS #include "pixel_map.h" @@ -480,23 +478,6 @@ public: * @return Returns true if this function is successfully called; returns false otherwise. */ bool GetAllCommonEventInfo(const std::string &eventKey, std::vector &commonEventInfos) const; - /** - * @brief Notify a specified ability for ability. - * @param bundleName Indicates the bundle name of the ability to ability. - * @param abilityName Indicates the name of the ability to ability. - * @param launchTime Indicates the ability launchTime. - * @param uid Indicates the uid. - * @return Returns true if this function is successfully called; returns false otherwise. - */ - bool NotifyAbilityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) const; - /** - * @brief Query ModuleUsageRecord objects ordered by lastLaunchTime desc - * @param maxNum Indicates the max number ShortcutInfo objects to get. - * @param records List of ModuleUsageRecord objects if obtained. - * @return Returns true if this function is successfully called; returns false otherwise. - */ - bool GetUsageRecords(int32_t maxNum, std::vector &records); /** * @brief Registers a callback for listening for permission changes of all UIDs. * @param callback Indicates the callback method to register. @@ -528,14 +509,6 @@ public: * @return Returns true if this function is successfully called; returns false otherwise. */ bool NotifyPermissionsChanged(int32_t uid); - /** - * @brief Update bundle usage record on bundle removed. - * @param keepUsage Indicates the flag record is remove on bundle removed. - * @param userId Indicates the user Id of the application. - * @param bundleName Indicates the bundle name of the application. - * @return Returns true if this function is successfully called; returns false otherwise. - */ - bool UpdateUsageRecordOnBundleRemoved(bool keepUsage, const int userId, const std::string &bundleName) const; /** * @brief Update bundle usage record on module removed. * @param keepUsage Indicates the flag record is remove on module removed. @@ -806,7 +779,6 @@ private: // current-status:previous-statue pair std::multimap transferStates_; std::shared_ptr dataStorage_; - std::shared_ptr usageRecordStorage_; std::shared_ptr preInstallDataStorage_; std::shared_ptr distributedDataStorage_; std::set> allPermissionsCallbacks_; diff --git a/services/bundlemgr/include/common_profile.h b/services/bundlemgr/include/common_profile.h index 20e8265a..be0dc600 100644 --- a/services/bundlemgr/include/common_profile.h +++ b/services/bundlemgr/include/common_profile.h @@ -232,7 +232,6 @@ const std::string BUNDLE_INSTALL_MARK_STATUS = "installMarkStatus"; const uint32_t VALUE_HOME_SCREEN = 1 << 0; // 000010 represents supporting search box const uint32_t VALUE_SEARCHBOX = 1 << 1; -const int32_t MAX_USAGE_RECORD_SIZE = 1000; const std::string KEY_HOME_SCREEN = "homeScreen"; const std::string KEY_SEARCHBOX = "searchbox"; diff --git a/services/bundlemgr/include/module_usage_data_storage.h b/services/bundlemgr/include/module_usage_data_storage.h index a0fb15e7..3721a63b 100644 --- a/services/bundlemgr/include/module_usage_data_storage.h +++ b/services/bundlemgr/include/module_usage_data_storage.h @@ -19,8 +19,6 @@ #include #include -#include "module_usage_record.h" - #include "bundle_constants.h" #include "distributed_kv_data_manager.h" #include "inner_bundle_info.h" diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 9635346a..fcaf2c7f 100644 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -38,9 +38,6 @@ BundleDataMgr::BundleDataMgr() { InitStateTransferMap(); dataStorage_ = std::make_shared(); - usageRecordStorage_ = std::make_shared(); - // register distributed data process death listener. - usageRecordStorage_->RegisterKvStoreDeathListener(); preInstallDataStorage_ = std::make_shared(); distributedDataStorage_ = DistributedDataStorage::GetInstance(); APP_LOGI("BundleDataMgr instance is created"); @@ -1643,67 +1640,6 @@ bool BundleDataMgr::GenerateCloneUid(InnerBundleInfo &info) return true; } -bool BundleDataMgr::GetUsageRecords(const int32_t maxNum, std::vector &records) -{ - APP_LOGD("GetUsageRecords, maxNum: %{public}d", maxNum); - if ((maxNum <= 0) || (maxNum > ProfileReader::MAX_USAGE_RECORD_SIZE)) { - APP_LOGE("maxNum illegal"); - return false; - } - records.clear(); - std::vector usageRecords; - bool result = usageRecordStorage_->QueryRecordByNum(maxNum, usageRecords, GetUserId()); - if (!result) { - APP_LOGE("GetUsageRecords error"); - return false; - } - for (ModuleUsageRecord &item : usageRecords) { - APP_LOGD("GetUsageRecords item:%{public}s,%{public}s,%{public}s", - item.bundleName.c_str(), - item.name.c_str(), - item.abilityName.c_str()); - - std::lock_guard lock(bundleInfoMutex_); - if (bundleInfos_.empty()) { - APP_LOGW("bundleInfos_ data is empty"); - break; - } - auto infoItem = bundleInfos_.find(item.bundleName); - if (infoItem == bundleInfos_.end()) { - continue; - } - APP_LOGD("GetUsageRecords %{public}s", infoItem->first.c_str()); - if (infoItem->second.IsDisabled()) { - APP_LOGW("app %{public}s is disabled", infoItem->second.GetBundleName().c_str()); - continue; - } - auto innerModuleInfo = infoItem->second.GetInnerModuleInfoByModuleName(item.name); - if (!innerModuleInfo) { - continue; - } - item.labelId = innerModuleInfo->labelId; - item.descriptionId = innerModuleInfo->descriptionId; - item.installationFreeSupported = innerModuleInfo->installationFree; - auto appInfo = infoItem->second.GetBaseApplicationInfo(); - item.appLabelId = static_cast(appInfo.labelId); - auto ability = infoItem->second.FindAbilityInfo(item.bundleName, item.abilityName, GetUserId()); - if (!ability) { - APP_LOGW("ability:%{public}s not find", item.abilityName.c_str()); - continue; - } - if (ability->type != AbilityType::PAGE) { - APP_LOGW("ability:%{public}s type is not PAGE", item.abilityName.c_str()); - continue; - } - item.abilityName = ability->name; - item.abilityLabelId = ability->labelId; - item.abilityDescriptionId = ability->descriptionId; - item.abilityIconId = ability->iconId; - records.emplace_back(item); - } - return true; -} - bool BundleDataMgr::RestoreUidAndGid() { for (const auto &info : bundleInfos_) { @@ -1944,78 +1880,6 @@ bool BundleDataMgr::GetFormsInfoByApp(const std::string &bundleName, std::vector return true; } -bool BundleDataMgr::NotifyAbilityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) const -{ - if (bundleName.empty() || abilityName.empty()) { - return false; - } - std::lock_guard lock(bundleInfoMutex_); - if (bundleInfos_.empty()) { - return false; - } - - int userId = GetUserIdByUid(uid); - std::string cloneBundleName = bundleName; - for (auto it = bundleInfos_.begin(); it != bundleInfos_.end();) { - if (it->first.find(cloneBundleName) != std::string::npos) { - if (it->second.GetUid(userId) == uid) { - cloneBundleName = it->first; - break; - } - ++it; - } else { - ++it; - } - } - auto infoItem = bundleInfos_.find(cloneBundleName); - if (infoItem == bundleInfos_.end()) { - return false; - } - if (infoItem->second.IsDisabled()) { - return false; - } - auto ability = infoItem->second.FindAbilityInfo(bundleName, abilityName, GetUserId(userId)); - if (!ability) { - return false; - } - if (ability->applicationInfo.isCloned) { - userId = Constants::C_UESRID; - } - if (ability->type != AbilityType::PAGE) { - return false; - } - ModuleUsageRecord moduleUsageRecord; - moduleUsageRecord.bundleName = bundleName; - moduleUsageRecord.name = ability->moduleName; - moduleUsageRecord.abilityName = abilityName; - moduleUsageRecord.lastLaunchTime = launchTime; - moduleUsageRecord.launchedCount = 1; - return usageRecordStorage_->AddOrUpdateRecord(moduleUsageRecord, Constants::CURRENT_DEVICE_ID, userId); -} - -bool BundleDataMgr::UpdateUsageRecordOnBundleRemoved( - bool keepUsage, const int userId, const std::string &bundleName) const -{ - std::lock_guard lock(bundleInfoMutex_); - if (bundleInfos_.empty()) { - APP_LOGE("bundleInfos_ data is empty"); - return false; - } - auto infoItem = bundleInfos_.find(bundleName); - if (infoItem == bundleInfos_.end()) { - return false; - } - APP_LOGD("UpdateUsageRecordOnBundleRemoved %{public}s", infoItem->first.c_str()); - if (infoItem->second.IsDisabled()) { - APP_LOGE("app %{public}s is disabled", infoItem->second.GetBundleName().c_str()); - return false; - } - std::vector moduleNames; - return keepUsage ? usageRecordStorage_->MarkUsageRecordRemoved(infoItem->second, GetUserId(userId)) - : usageRecordStorage_->DeleteUsageRecord(infoItem->second, GetUserId(userId)); -} - bool BundleDataMgr::GetShortcutInfos( const std::string &bundleName, int32_t userId, std::vector &shortcutInfos) const { diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 3909ce18..e243e96b 100644 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -1067,26 +1067,13 @@ bool BundleMgrHostImpl::GetAllCommonEventInfo(const std::string &eventKey, bool BundleMgrHostImpl::GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) { - APP_LOGD("start GetModuleUsageRecords, number : %{public}d", number); - auto dataMgr = GetDataMgrFromService(); - if (dataMgr == nullptr) { - APP_LOGE("DataMgr is nullptr"); - return false; - } - return dataMgr->GetUsageRecords(number, moduleUsageRecords); + return false; } bool BundleMgrHostImpl::NotifyAbilityLifeStatus( const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) { - APP_LOGI("NotifyAbilityLifeStatus begin"); - auto task = [this, bundleName, abilityName, launchTime, uid] { - auto dataMgr = GetDataMgrFromService(); - dataMgr->NotifyAbilityLifeStatus(bundleName, abilityName, launchTime, uid); - }; - handler_->PostTask(task); - APP_LOGI("NotifyAbilityLifeStatus end"); - return true; + return false; } bool BundleMgrHostImpl::RemoveClonedBundle(const std::string &bundleName, const int32_t uid) diff --git a/services/bundlemgr/src/module_usage_data_storage.cpp b/services/bundlemgr/src/module_usage_data_storage.cpp deleted file mode 100644 index 04023888..00000000 --- a/services/bundlemgr/src/module_usage_data_storage.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 "module_usage_data_storage.h" - -#include -#include -#include "datetime_ex.h" -#include "string_ex.h" - -#include "bundle_util.h" -#include "json_util.h" -#include "kvstore_death_recipient_callback.h" -#include "nlohmann/json.hpp" - -using namespace OHOS::DistributedKv; - -namespace OHOS { -namespace AppExecFwk { -namespace { -const int32_t MAX_TIMES = 6000; // tem min -const int32_t SLEEP_INTERVAL = 100 * 1000; // 100ms -const std::string POUND_KEY_SEPARATOR = "#"; -const std::string SCHEMA_DEFINE = "{\"SCHEMA_VERSION\":\"1.0\"," - "\"SCHEMA_MODE\":\"COMPATIBLE\"," - "\"SCHEMA_SKIPSIZE\":0," - "\"SCHEMA_DEFINE\":{" - "\"launchedCount\":\"INTEGER, NOT NULL\"," - "\"lastLaunchTime\":\"LONG, NOT NULL\"," - "\"isRemoved\":\"BOOL, NOT NULL\"" - "}," - "\"SCHEMA_INDEXES\":[\"$.lastLaunchTime\"]}"; -} // namespace - -ModuleUsageRecordStorage::ModuleUsageRecordStorage() -{ - APP_LOGI("usage instance is created"); - TryTwice([this] { return GetKvStore(); }); -} - -ModuleUsageRecordStorage::~ModuleUsageRecordStorage() -{ - APP_LOGI("usage instance is destroyed"); - dataManager_.CloseKvStore(appId_, kvStorePtr_); -} - -void ModuleUsageRecordStorage::RegisterKvStoreDeathListener() -{} - -bool ModuleUsageRecordStorage::ParseKey(const std::string &key, ModuleUsageRecord &record) const -{ - std::vector splitKeys; - SplitStr(key, POUND_KEY_SEPARATOR, splitKeys); - if (splitKeys.size() != DATABASE_KEY_INDEX_MAX_LENGTH) { - APP_LOGE("error key, parsed failed!"); - return false; - } - - record.bundleName = (splitKeys[DATABASE_KEY_INDEX_BUNDLE_NAME]); - record.name = (splitKeys[DATABASE_KEY_INDEX_MODULE_NAME]); - APP_LOGD( - "parseKey::bundleName = %{public}s, moduleName = %{public}s", record.bundleName.c_str(), record.name.c_str()); - return true; -} - -void ModuleUsageRecordStorage::AbilityRecordToKey(const std::string &userId, const std::string &deviceId, - const std::string &bundleName, const std::string &moduleName, std::string &key) const -{ - // deviceId_bundleName_moduleName - key.append(userId); - key.append(POUND_KEY_SEPARATOR); - key.append(deviceId); - key.append(POUND_KEY_SEPARATOR); - key.append(bundleName); - key.append(POUND_KEY_SEPARATOR); - key.append(moduleName); - APP_LOGD("userId = %{public}s, bundleName = %{public}s, moduleName = %{public}s", - userId.c_str(), - bundleName.c_str(), - moduleName.c_str()); -} - -void ModuleUsageRecordStorage::UpdateUsageRecord(const std::string &jsonString, ModuleUsageRecord &data) -{ - nlohmann::json jsonObject = nlohmann::json::parse(jsonString); - if (jsonObject.is_discarded()) { - APP_LOGE("failed to parse existing usage record: %{private}s.", jsonString.c_str()); - return; - } - - const auto &jsonObjectEnd = jsonObject.end(); - int32_t parseResult = ERR_OK; - uint32_t launchedCount; - GetValueIfFindKey(jsonObject, - jsonObjectEnd, - UsageRecordKey::LAUNCHED_COUNT, - launchedCount, - JsonType::NUMBER, - true, - parseResult, - ArrayType::NOT_ARRAY); - if (parseResult != ERR_OK) { - APP_LOGE("parsing failed: %{public}d.", parseResult); - return; - } - data.launchedCount = launchedCount + 1; - APP_LOGD("launchedCount = %{public}u", data.launchedCount); - return; -} - -bool ModuleUsageRecordStorage::AddOrUpdateRecord(ModuleUsageRecord &data, const std::string &deviceId, int32_t userId) -{ - APP_LOGI("add usage record data %{public}s", data.bundleName.c_str()); - { - std::lock_guard lock(kvStorePtrMutex_); - if (!CheckKvStore()) { - APP_LOGE("kvStore is nullptr"); - return false; - } - } - Status status; - bool isExist = false; - { - std::string keyOfData; - AbilityRecordToKey(std::to_string(userId), deviceId, data.bundleName, data.name, keyOfData); - Key key(keyOfData); - Value oldValue; - std::lock_guard lock(kvStorePtrMutex_); - status = kvStorePtr_->Get(key, oldValue); - if (status == Status::SUCCESS) { - APP_LOGD("get old value %{public}s", oldValue.ToString().c_str()); - // already isExist, update - UpdateUsageRecord(oldValue.ToString(), data); - isExist = true; - } - if (status == Status::KEY_NOT_FOUND || isExist) { - Value value(data.ToString()); - APP_LOGD("add to DB::value %{public}s", value.ToString().c_str()); - status = kvStorePtr_->Put(key, value); - APP_LOGW("add result = %{public}d", status); - if (status == Status::IPC_ERROR) { - status = kvStorePtr_->Put(key, value); - APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); - } - } - } - - if (status != Status::SUCCESS) { - APP_LOGE("put value to kvStore error: %{public}d", status); - return false; - } - - APP_LOGD("update success"); - return true; -} - -bool ModuleUsageRecordStorage::DeleteRecordByKeys(const std::string &bundleName, std::vector &keys) -{ - if (keys.size() == 0) { - APP_LOGE("delete error: empty key"); - return false; - } - Status status; - { - std::lock_guard lock(kvStorePtrMutex_); - status = kvStorePtr_->DeleteBatch(keys); - if (status == Status::IPC_ERROR) { - status = kvStorePtr_->DeleteBatch(keys); - APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); - } - } - - if (status != Status::SUCCESS) { - APP_LOGE("delete keys error: %{public}d", status); - return false; - } - APP_LOGD("delete success"); - return true; -} - -bool ModuleUsageRecordStorage::DeleteUsageRecord(const InnerBundleInfo &data, int32_t userId) -{ - APP_LOGD("delete usage data"); - { - std::lock_guard lock(kvStorePtrMutex_); - if (!CheckKvStore()) { - APP_LOGE("kvStore is nullptr"); - return false; - } - } - - std::vector keys; - InnerBundleInfoToKeys(data, userId, keys); - APP_LOGD("delete key %{public}zu", keys.size()); - return DeleteRecordByKeys(data.GetBundleName(), keys); -} - -bool ModuleUsageRecordStorage::MarkUsageRecordRemoved(const InnerBundleInfo &data, int32_t userId) -{ - { - std::lock_guard lock(kvStorePtrMutex_); - if (!CheckKvStore()) { - APP_LOGE("kvStore is nullptr"); - return false; - } - } - ModuleUsageRecord record; - Value value; - std::string jsonString; - std::vector keys; - InnerBundleInfoToKeys(data, userId, keys); - { - std::lock_guard lock(kvStorePtrMutex_); - for (const Key &key : keys) { - Status status = kvStorePtr_->Get(key, value); - if (status != Status::SUCCESS) { - APP_LOGD("database query by key error, result = %{public}d", status); - return false; - } - if (!record.FromJsonString(value.ToString())) { - APP_LOGW("database parse entry failed"); - return false; - } - if (!record.removed) { - record.removed = true; - jsonString = record.ToString(); - APP_LOGD("new value %{public}s", jsonString.c_str()); - value = jsonString; - status = kvStorePtr_->Put(key, value); - APP_LOGI("value update result: %{public}d", status); - } - } - } - return true; -} - -void ModuleUsageRecordStorage::InnerBundleInfoToKeys( - const InnerBundleInfo &data, int32_t userId, std::vector &keys) const -{ - std::vector mouduleNames; - data.GetModuleNames(mouduleNames); - const std::string &bundleName = data.GetBundleName(); - for (const auto &moduleName : mouduleNames) { - FillDataStorageKeys(std::to_string(userId), bundleName, moduleName, keys); - } -} - -void ModuleUsageRecordStorage::FillDataStorageKeys(const std::string &userId, const std::string &bundleName, - const std::string &moduleName, std::vector &keys) const -{ - std::string keyOfData; - AbilityRecordToKey(userId, Constants::CURRENT_DEVICE_ID, bundleName, moduleName, keyOfData); - Key key(keyOfData); - keys.push_back(key); -} - -void ModuleUsageRecordStorage::SaveEntries( - const std::vector &allEntries, std::vector &records) const -{ - APP_LOGD("SaveEntries %{public}zu", allEntries.size()); - for (const auto &item : allEntries) { - APP_LOGD("SaveEntries %{public}s", item.value.ToString().c_str()); - ModuleUsageRecord record; - if (!record.FromJsonString(item.value.ToString())) { - APP_LOGE("error entry: %{private}s", item.value.ToString().c_str()); - continue; - } - - if (!ParseKey(item.key.ToString(), record)) { - APP_LOGE("error key"); - continue; - } - records.emplace_back(record); - } -} - -bool ModuleUsageRecordStorage::QueryRecordByNum(int32_t maxNum, std::vector &records, int32_t userId) -{ - APP_LOGI("query record by num %{public}d userId %{public}d", maxNum, userId); - DataQuery query; - query.KeyPrefix(std::to_string(userId) + POUND_KEY_SEPARATOR + Constants::CURRENT_DEVICE_ID + POUND_KEY_SEPARATOR); - query.OrderByDesc(UsageRecordKey::SCHEMA_LAST_LAUNCH_TIME); - query.Limit(maxNum, 0); - std::vector allEntries; - bool queryResult = QueryRecordByCondition(query, allEntries); - if (!queryResult || static_cast(allEntries.size()) > maxNum) { - APP_LOGE("query record error"); - return queryResult; - } - APP_LOGD("query record success"); - SaveEntries(allEntries, records); - return true; -} - -bool ModuleUsageRecordStorage::QueryRecordByCondition(DataQuery &query, std::vector &records) -{ - Status status; - { - std::lock_guard lock(kvStorePtrMutex_); - if (!CheckKvStore()) { - APP_LOGE("kvStore is nullptr"); - return false; - } - } - - status = kvStorePtr_->GetEntriesWithQuery(query, records); - APP_LOGI("query record by condition %{public}d", status); - if (status == Status::IPC_ERROR) { - status = kvStorePtr_->GetEntriesWithQuery(query, records); - APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); - } - - if (status != Status::SUCCESS) { - APP_LOGE("query key error: %{public}d", status); - return false; - } - return true; -} - -Status ModuleUsageRecordStorage::GetKvStore() -{ - Options options = { - .createIfMissing = true, - .encrypt = false, - .autoSync = false, - .kvStoreType = KvStoreType::SINGLE_VERSION - }; - - options.schema = SCHEMA_DEFINE; - Status status = dataManager_.GetSingleKvStore(options, appId_, storeId_, kvStorePtr_); - if (status != Status::SUCCESS) { - APP_LOGE("usage get kvStore error: %{public}d", status); - } else { - APP_LOGI("usage get kvStore success"); - } - return status; -} - -void ModuleUsageRecordStorage::TryTwice(const std::function &func) const -{ - Status status = func(); - if (status == Status::IPC_ERROR) { - status = func(); - APP_LOGW("distribute database ipc error and try to call again, result = %{public}d", status); - } -} - -bool ModuleUsageRecordStorage::CheckKvStore() -{ - if (kvStorePtr_ != nullptr) { - return true; - } - int32_t tryTimes = MAX_TIMES; - while (tryTimes > 0) { - Status status = GetKvStore(); - if (status == Status::SUCCESS && kvStorePtr_ != nullptr) { - return true; - } - APP_LOGD("usage CheckKvStore, Times: %{public}d", tryTimes); - usleep(SLEEP_INTERVAL); - tryTimes--; - } - return kvStorePtr_ != nullptr; -} - -bool ModuleUsageRecordStorage::ResetKvStore() -{ - std::lock_guard lock(kvStorePtrMutex_); - kvStorePtr_ = nullptr; - Status status = GetKvStore(); - if (status == Status::SUCCESS && kvStorePtr_ != nullptr) { - return true; - } - APP_LOGW("usage reset failed"); - return false; -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/services/bundlemgr/test/unittest/bms_bundle_accesstokenid_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_accesstokenid_test/BUILD.gn index f1ad9180..646a2e7d 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_accesstokenid_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_accesstokenid_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("BmsBundleAccessTokenIdTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_bundle_clone_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_clone_test/BUILD.gn index 021e4f3a..ad88f262 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_clone_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_clone_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("BmsBundleCloneTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_test.cpp deleted file mode 100644 index 8149c92f..00000000 --- a/services/bundlemgr/test/unittest/bms_bundle_data_storage_test/bms_bundle_data_storage_test.cpp +++ /dev/null @@ -1,678 +0,0 @@ -/* - * Copyright (c) 2021-2022 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 -#include - -#include "app_log_wrapper.h" -#include "json_constants.h" -#include "json_serializer.h" -#include "nlohmann/json.hpp" -#include "ability_info.h" -#include "bundle_constants.h" -#include "bundle_data_storage.h" -#include "bundle_info.h" -#include "inner_bundle_info.h" - -using namespace testing::ext; -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::JsonConstants; - -namespace { -const std::string NORMAL_BUNDLE_NAME{"com.example.test"}; -} // namespace - -class BmsBundleDataStorageTest : public testing::Test { -public: - BmsBundleDataStorageTest(); - ~BmsBundleDataStorageTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp(); - void TearDown(); - void ClearJsonFile() const; - -protected: - enum class InfoType { - BUNDLE_INFO, - APPLICATION_INFO, - ABILITY_INFO, - }; - - void CheckBundleSaved(const InnerBundleInfo &innerBundleInfo) const; - void CheckBundleDeleted(const InnerBundleInfo &innerBundleInfo) const; - void CheckInvalidPropDeserialize(const nlohmann::json infoJson, const InfoType infoType) const; - -protected: - nlohmann::json innerBundleInfoJson_ = R"( - { - "appFeature": "ohos_system_app", - "appType": 2, - "baseAbilityInfos": { - "com.ohos.launchercom.ohos.launchercom.ohos.launcher.MainAbility": { - "applicationName": "com.ohos.launcher", - "bundleName": "com.ohos.launcher", - "codePath": "", - "description": "$string:mainability_description", - "deviceCapabilities": [], - "deviceId": "", - "deviceTypes": [ - "phone" - ], - "iconPath": "$media:icon", - "enabled": true, - "readPermission": "readPermission", - "writePermission": "writePermission", - "isLauncherAbility": true, - "isNativeAbility": false, - "kind": "page", - "label": "Launcher", - "launchMode": 0, - "libPath": "", - "moduleName": ".MyApplication", - "name": "com.ohos.launcher.MainAbility", - "orientation": 0, - "package": "com.ohos.launcher", - "permissions": [], - "process": "", - "resourcePath": "/data/app/el1/bundle/public/com.ohos.launcher/com.ohos.launcher/assets/launcher/resources.index", - "targetAbility": "", - "type": 1, - "uri": "", - "visible": false - } - }, - "baseApplicationInfo": { - "bundleName": "com.ohos.launcher", - "cacheDir": "/data/app/el2/100/base/com.ohos.launcher/cache", - "codePath": "/data/app/el1/bundle/public/com.ohos.launcher", - "dataBaseDir": "/data/app/el2/100/database/com.ohos.launcher", - "dataDir": "/data/app/el2/100/base/com.ohos.launcher/files", - "description": "$string:mainability_description", - "descriptionId": 16777217, - "deviceId": "PHONE-001", - "enabled": true, - "entryDir": "", - "flags": 0, - "iconId": 16777218, - "iconPath": "$media:icon", - "isLauncherApp": true, - "isSystemApp": false, - "label": "Launcher", - "labelId": 0, - "moduleInfos": [], - "moduleSourceDirs": [], - "name": "com.ohos.launcher", - "permissions": [], - "process": "", - "signatureKey": "", - "supportedModes": 0 - }, - "baseBundleInfo": { - "abilityInfos": [], - "appId": "BNtg4JBClbl92Rgc3jm/RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM=", - "applicationInfo": { - "bundleName": "", - "cacheDir": "", - "codePath": "", - "dataBaseDir": "", - "dataDir": "", - "description": "", - "descriptionId": 0, - "deviceId": "", - "enabled": false, - "entryDir": "", - "flags": 0, - "iconId": 0, - "iconPath": "", - "isLauncherApp": false, - "isSystemApp": false, - "label": "", - "labelId": 0, - "moduleInfos": [], - "moduleSourceDirs": [], - "name": "", - "permissions": [], - "process": "", - "signatureKey": "", - "supportedModes": 0 - }, - "compatibleVersion": 3, - "cpuAbi": "", - "defPermissions": [], - "description": "", - "entryModuleName": "", - "gid": 10000, - "hapModuleNames": [], - "installTime": 17921, - "isKeepAlive": false, - "isNativeApp": false, - "isDifferentName":false, - "jointUserId": "", - "label": "Launcher", - "mainEntry": "", - "maxSdkVersion": 0, - "minSdkVersion": 0, - "moduleDirs": [], - "moduleNames": [], - "modulePublicDirs": [], - "moduleResPaths": [], - "name": "com.ohos.launcher", - "releaseType": "Release", - "reqPermissions": [], - "seInfo": "", - "targetVersion": 3, - "uid": 10000, - "updateTime": 17921, - "vendor": "ohos", - "versionCode": 1, - "versionName": "1.0" - }, - "baseDataDir": "/data/app/el2/100/base/com.ohos.launcher", - "bundleStatus": 1, - "hasEntry": true, - "innerModuleInfos": { - "com.ohos.launcher": { - "abilityKeys": [ - "com.ohos.launchercom.ohos.launchercom.ohos.launcher.MainAbility" - ], - "defPermissions": [], - "description": "", - "distro": { - "deliveryWithInstall": true, - "moduleName": "launcher", - "moduleType": "entry" - }, - "isEntry": true, - "metaData": { - "customizeData": [] - }, - "moduleDataDir": "/data/app/el2/100/base/com.ohos.launcher/haps/com.ohos.launcher", - "moduleName": ".MyApplication", - "modulePackage": "com.ohos.launcher", - "modulePath": "/data/app/el1/bundle/public/com.ohos.launcher/com.ohos.launcher", - "moduleResPath": "/data/app/el1/bundle/public/com.ohos.launcher/com.ohos.launcher/assets/launcher/resources.index", - "reqCapabilities": [], - "reqPermissions": [], - "skillKeys": [ - "com.ohos.launchercom.ohos.launchercom.ohos.launcher.MainAbility" - ] - } - }, - "isSupportBackup": false, - "mainAbility": "com.ohos.launchercom.ohos.launchercom.ohos.launcher.MainAbility", - "skillInfos": { - "com.ohos.launchercom.ohos.launchercom.ohos.launcher.MainAbility": [ - { - "actions": [ - "action.system.home", - "com.ohos.action.main" - ], - "entities": [ - "entity.system.home", - "flag.home.intent.from.system" - ], - "uris": [] - } - ] - }, - "userId_": 0, - "innerBundleUserInfos": { - "com.example.myapplication1_0": { - "accessTokenId":-1, - "bundleName":"com.example.myapplication1_0", - "bundleUserInfo": { - "enabled":true, - "abilities":[ - - ], - "disabledAbilities":[ - - ], - "userId":0 - }, - "gids":[ - 10000 - ], - "installTime":17921, - "uid":10000, - "updateTime":17921 - } - } - } - )"_json; - - nlohmann::json moduleInfoJson_ = R"( - { - "moduleName": "entry", - "moduleSourceDir": "" - } - )"_json; - const std::string deviceId_ = Constants::CURRENT_DEVICE_ID; - const std::string BASE_ABILITY_INFO = "baseAbilityInfos"; - // need modify with innerBundleInfoJson_ - const std::string abilityName = "com.ohos.launchercom.ohos.launchercom.ohos.launcher.MainAbility"; - const std::string BASE_BUNDLE_INFO = "baseBundleInfo"; - const std::string BASE_APPLICATION_INFO = "baseApplicationInfo"; -}; - -BmsBundleDataStorageTest::BmsBundleDataStorageTest() -{} - -BmsBundleDataStorageTest::~BmsBundleDataStorageTest() -{} - -void BmsBundleDataStorageTest::CheckBundleSaved(const InnerBundleInfo &innerBundleInfo) const -{ - BundleDataStorage bundleDataStorage; - EXPECT_TRUE(bundleDataStorage.SaveStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); - std::map> bundleData; - EXPECT_TRUE(bundleDataStorage.LoadAllData(bundleData)); - - // search allDeviceInfos by bundle name - std::string bundleName = innerBundleInfo.GetBundleName(); - auto bundleDataIter = bundleData.find(bundleName); - EXPECT_TRUE(bundleDataIter != bundleData.end()); - - // search InnerBundleInfo by device id - auto allDeviceInfos = bundleDataIter->second; - auto devicesInfosIter = allDeviceInfos.find(deviceId_); - EXPECT_TRUE(devicesInfosIter != allDeviceInfos.end()); - - InnerBundleInfo afterLoadInfo = devicesInfosIter->second; - EXPECT_TRUE(innerBundleInfo.ToString() == afterLoadInfo.ToString()); -} - -void BmsBundleDataStorageTest::CheckBundleDeleted(const InnerBundleInfo &innerBundleInfo) const -{ - BundleDataStorage bundleDataStorage; - EXPECT_TRUE(bundleDataStorage.DeleteStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); - std::map> bundleDates; - EXPECT_TRUE(bundleDataStorage.LoadAllData(bundleDates)); -} - -void BmsBundleDataStorageTest::CheckInvalidPropDeserialize(const nlohmann::json infoJson, const InfoType infoType) const -{ - APP_LOGI("deserialize infoJson = %{public}s", infoJson.dump().c_str()); - nlohmann::json innerBundleInfoJson; - nlohmann::json bundleInfoJson = innerBundleInfoJson_.at(BASE_BUNDLE_INFO); - - switch (infoType) { - case InfoType::BUNDLE_INFO: { - bundleInfoJson = infoJson; - BundleInfo bundleInfo = infoJson; - break; - } - case InfoType::APPLICATION_INFO: { - bundleInfoJson["appInfo"] = infoJson; - ApplicationInfo applicationInfo = infoJson; - break; - } - case InfoType::ABILITY_INFO: { - bundleInfoJson["abilityInfos"].push_back(infoJson); - AbilityInfo abilityInfo = infoJson; - break; - } - default: - break; - } - - innerBundleInfoJson["baseBundleInfo"] = bundleInfoJson; - InnerBundleInfo fromJsonInfo; - EXPECT_FALSE(fromJsonInfo.FromJson(innerBundleInfoJson)); -} - -void BmsBundleDataStorageTest::SetUpTestCase() -{} - -void BmsBundleDataStorageTest::TearDownTestCase() -{} - -void BmsBundleDataStorageTest::SetUp() -{ - // clean bmsdb.json - ClearJsonFile(); -} - -void BmsBundleDataStorageTest::TearDown() -{} - -void BmsBundleDataStorageTest::ClearJsonFile() const -{ - std::string fileName = Constants::BUNDLE_DATA_BASE_FILE; - std::ofstream o(fileName); - if (!o.is_open()) { - return; - } - o.close(); -} - -/** - * @tc.number: BundleInfoJsonSerializer_0100 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.successfully serialize and deserialize all right props in BundleInfo - */ -HWTEST_F(BmsBundleDataStorageTest, BundleInfoJsonSerializer_0100, Function | SmallTest | Level1) -{ - nlohmann::json sourceInfoJson = innerBundleInfoJson_.at(BASE_BUNDLE_INFO); - // deserialize BundleInfo from json - BundleInfo fromJsonInfo = sourceInfoJson; - // serialize fromJsonInfo to json - nlohmann::json toJsonObject = fromJsonInfo; - - EXPECT_TRUE(toJsonObject.dump() == sourceInfoJson.dump()); -} - -/** - * @tc.number: BundleInfoJsonSerializer_0200 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.test can catch deserialize error for type error for name prop in BundleInfo - */ -HWTEST_F(BmsBundleDataStorageTest, BundleInfoJsonSerializer_0200, Function | SmallTest | Level1) -{ - nlohmann::json typeErrorProps; - typeErrorProps["name"] = NOT_STRING_TYPE; - typeErrorProps["label"] = NOT_STRING_TYPE; - typeErrorProps["description"] = NOT_STRING_TYPE; - typeErrorProps["vendor"] = NOT_STRING_TYPE; - typeErrorProps["mainEntry"] = NOT_STRING_TYPE; - typeErrorProps["versionName"] = NOT_STRING_TYPE; - typeErrorProps["versionCode"] = NOT_NUMBER_TYPE; - typeErrorProps["minSdkVersion"] = NOT_NUMBER_TYPE; - typeErrorProps["minSdkVersion"] = NOT_NUMBER_TYPE; - - for (nlohmann::json::iterator iter = typeErrorProps.begin(); iter != typeErrorProps.end(); iter++) { - for (auto valueIter = iter.value().begin(); valueIter != iter.value().end(); valueIter++) { - nlohmann::json infoJson = innerBundleInfoJson_.at(BASE_BUNDLE_INFO); - infoJson[iter.key()] = valueIter.value(); - } - } -} - -/** - * @tc.number: AbilityInfoJsonSerializer_0100 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.successfully serialize and deserialize all right props in AbilityInfo - */ -HWTEST_F(BmsBundleDataStorageTest, AbilityInfoJsonSerializer_0100, Function | SmallTest | Level1) -{ - nlohmann::json sourceInfoJson = innerBundleInfoJson_.at(BASE_ABILITY_INFO).at(abilityName); - // deserialize AbilityInfo from json - AbilityInfo fromJsonInfo = sourceInfoJson; - // serialize fromJsonInfo to json - nlohmann::json toJsonObject = fromJsonInfo; - EXPECT_TRUE(toJsonObject.dump() == sourceInfoJson.dump()); -} - -/** - * @tc.number: AbilityInfoJsonSerializer_0200 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.test can catch deserialize error for type error for name prop in AbilityInfo - */ -HWTEST_F(BmsBundleDataStorageTest, AbilityInfoJsonSerializer_0200, Function | SmallTest | Level1) -{ - nlohmann::json typeErrorProps; - typeErrorProps["package"] = NOT_STRING_TYPE; - typeErrorProps["name"] = NOT_STRING_TYPE; - typeErrorProps["bundleName"] = NOT_STRING_TYPE; - typeErrorProps["applicationName"] = NOT_STRING_TYPE; - typeErrorProps["label"] = NOT_STRING_TYPE; - typeErrorProps["description"] = NOT_STRING_TYPE; - typeErrorProps["iconPath"] = NOT_STRING_TYPE; - typeErrorProps["visible"] = NOT_BOOL_TYPE; - typeErrorProps["kind"] = NOT_STRING_TYPE; - typeErrorProps["type"] = NOT_NUMBER_TYPE; - typeErrorProps["orientation"] = NOT_NUMBER_TYPE; - typeErrorProps["launchMode"] = NOT_NUMBER_TYPE; - typeErrorProps["codePath"] = NOT_STRING_TYPE; - typeErrorProps["resourcePath"] = NOT_STRING_TYPE; - typeErrorProps["libPath"] = NOT_STRING_TYPE; - - for (nlohmann::json::iterator iter = typeErrorProps.begin(); iter != typeErrorProps.end(); iter++) { - for (auto valueIter = iter.value().begin(); valueIter != iter.value().end(); valueIter++) { - APP_LOGD("deserialize check prop key = %{public}s, type = %{public}s", - iter.key().c_str(), - valueIter.key().c_str()); - nlohmann::json infoJson = innerBundleInfoJson_.at(BASE_ABILITY_INFO).at(abilityName); - infoJson[iter.key()] = valueIter.value(); - } - } -} - -/** - * @tc.number: ApplicationInfoJsonSerializer_0100 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.successfully serialize and deserialize all right props in ApplicationInfo - */ -HWTEST_F(BmsBundleDataStorageTest, ApplicationInfoJsonSerializer_0100, Function | SmallTest | Level1) -{ - nlohmann::json sourceInfoJson = innerBundleInfoJson_.at(BASE_APPLICATION_INFO); - // deserialize ApplicationInfo from json - ApplicationInfo fromJsonInfo = sourceInfoJson; - // serialize fromJsonInfo to json - nlohmann::json toJsonObject = fromJsonInfo; - - EXPECT_TRUE(toJsonObject.dump() == sourceInfoJson.dump()); -} - -/** - * @tc.number: ApplicationInfoJsonSerializer_0200 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.test can catch deserialize error for type error for name prop in ApplicationInfo - */ -HWTEST_F(BmsBundleDataStorageTest, ApplicationInfoJsonSerializer_0200, Function | SmallTest | Level1) -{ - nlohmann::json typeErrorProps; - typeErrorProps["name"] = NOT_STRING_TYPE; - typeErrorProps["bundleName"] = NOT_STRING_TYPE; - typeErrorProps["sandboxId"] = NOT_NUMBER_TYPE; - typeErrorProps["signatureKey"] = NOT_STRING_TYPE; - - for (nlohmann::json::iterator iter = typeErrorProps.begin(); iter != typeErrorProps.end(); iter++) { - for (auto valueIter = iter.value().begin(); valueIter != iter.value().end(); valueIter++) { - APP_LOGD("deserialize check prop key = %{public}s, type = %{public}s", - iter.key().c_str(), - valueIter.key().c_str()); - nlohmann::json infoJson = innerBundleInfoJson_.at(BASE_APPLICATION_INFO); - infoJson[iter.key()] = valueIter.value(); - } - } -} - -/** - * @tc.number: ModuleInfoJsonSerializer_0100 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.successfully serialize and deserialize all right props in ModuleInfo - */ -HWTEST_F(BmsBundleDataStorageTest, ModuleInfoJsonSerializer_0100, Function | SmallTest | Level1) -{ - nlohmann::json sourceInfoJson = moduleInfoJson_; - // deserialize ModuleInfo from json - ModuleInfo fromJsonInfo = sourceInfoJson; - // serialize fromJsonInfo to json - nlohmann::json toJsonObject = fromJsonInfo; - - EXPECT_TRUE(toJsonObject.dump() == sourceInfoJson.dump()); -} - -/** - * @tc.number: SaveData_0100 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally and no saved any bundle data - * 2.successfully save a new bundle installation information for the first time - */ -HWTEST_F(BmsBundleDataStorageTest, SaveData_0100, Function | SmallTest | Level0) -{ - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - CheckBundleSaved(innerBundleInfo); -} - -/** - * @tc.number: SaveData_0200 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.successfully save a new bundle installation information for not the first time - */ -HWTEST_F(BmsBundleDataStorageTest, SaveData_0200, Function | SmallTest | Level0) -{ - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - - ApplicationInfo baseApp = innerBundleInfo.GetBaseApplicationInfo(); - baseApp.name = "com.example.other"; - baseApp.bundleName = baseApp.name; - innerBundleInfo.SetBaseApplicationInfo(baseApp); - - InnerBundleInfo otherInnerBundleInfo = innerBundleInfo; - CheckBundleSaved(otherInnerBundleInfo); -} - -/** - * @tc.number: SaveData_0300 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.successfully update an already exist bundle installation information - */ -HWTEST_F(BmsBundleDataStorageTest, SaveData_0300, Function | SmallTest | Level0) -{ - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - CheckBundleSaved(innerBundleInfo); - CheckBundleDeleted(innerBundleInfo); - - BundleInfo bundleInfo = innerBundleInfoJson_.at(BASE_BUNDLE_INFO); - bundleInfo.description = "update test application"; - InnerBundleInfo otherInnerBundleInfo = innerBundleInfo; - otherInnerBundleInfo.SetBaseBundleInfo(bundleInfo); - - CheckBundleSaved(otherInnerBundleInfo); -} - -/** - * @tc.number: SaveData_0400 - * @tc.name: save bundle installation information to persist storage - * @tc.desc: 1.system running normally - * 2.check all props can be serialize and deserialize - */ -HWTEST_F(BmsBundleDataStorageTest, SaveData_0400, Function | SmallTest | Level1) -{ - nlohmann::json sourceInfoJson = innerBundleInfoJson_; - InnerBundleInfo fromJsonInfo; - EXPECT_EQ(fromJsonInfo.FromJson(innerBundleInfoJson_), 0); - EXPECT_TRUE(fromJsonInfo.ToString() == sourceInfoJson.dump()); -} - -/** - * @tc.number: LoadAllData_0100 - * @tc.name: load all installed bundle information from persist storage - * @tc.desc: 1.system running normally - * 2.test can successfully load all installed bundle information from persist storage - */ -HWTEST_F(BmsBundleDataStorageTest, LoadAllData_0100, Function | SmallTest | Level0) -{ - BundleDataStorage bundleDataStorage; - int count = 10; - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - - ApplicationInfo baseApp = innerBundleInfo.GetBaseApplicationInfo(); - - for (int i = 0; i < count; i++) { - baseApp.name = NORMAL_BUNDLE_NAME + std::to_string(i); - baseApp.bundleName = baseApp.name; - innerBundleInfo.SetBaseApplicationInfo(baseApp); - EXPECT_TRUE(bundleDataStorage.SaveStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); - } - - std::map> bundleDates; - EXPECT_TRUE(bundleDataStorage.LoadAllData(bundleDates)); - - for (int i = 0; i < count; i++) { - std::string bundleName = NORMAL_BUNDLE_NAME + std::to_string(i); - baseApp.name = NORMAL_BUNDLE_NAME + std::to_string(i); - baseApp.bundleName = baseApp.name; - innerBundleInfo.SetBaseApplicationInfo(baseApp); - - // search allDeviceInfos by bundle name - auto bundleDatesIter = bundleDates.find(bundleName); - EXPECT_TRUE(bundleDatesIter != bundleDates.end()); - // search InnerBundleInfo by device id - auto allDeviceInfos = bundleDatesIter->second; - auto devicesInfosIter = allDeviceInfos.find(deviceId_); - EXPECT_TRUE(devicesInfosIter != allDeviceInfos.end()); - - InnerBundleInfo afterLoadInfo = devicesInfosIter->second; - EXPECT_TRUE(innerBundleInfo.ToString() == afterLoadInfo.ToString()); - } -} - -/** - * @tc.number: DeleteBundleData_0100 - * @tc.name: delete bundle installation information from persist storage - * @tc.desc: 1.system running normally - * 2.successfully delete a saved bundle installation information - */ -HWTEST_F(BmsBundleDataStorageTest, DeleteBundleData_0100, Function | SmallTest | Level0) -{ - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - - BundleDataStorage bundleDataStorage; - EXPECT_TRUE(bundleDataStorage.SaveStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); - - CheckBundleDeleted(innerBundleInfo); -} - -/** - * @tc.number: DeleteBundleData_0200 - * @tc.name: delete bundle installation information from persist storage - * @tc.desc: 1.system running normally and no saved the bundle to be deleted - * 2.successfully delete an unsaved bundle installation information - */ -HWTEST_F(BmsBundleDataStorageTest, DeleteBundleData_0200, Function | SmallTest | Level1) -{ - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - BundleDataStorage bundleDataStorage; - EXPECT_FALSE(bundleDataStorage.DeleteStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); -} - -/** - * @tc.number: DeleteBundleData_0300 - * @tc.name: delete bundle installation information from persist storage - * @tc.desc: 1.system running normally and no saved the bundle to be deleted - * 2.Unsaved bundle installation information was not removed successfully - */ -HWTEST_F(BmsBundleDataStorageTest, DeleteBundleData_0300, Function | SmallTest | Level1) -{ - EXPECT_EQ(remove(Constants::BUNDLE_DATA_BASE_FILE.c_str()), 0); - - InnerBundleInfo innerBundleInfo; - innerBundleInfo.FromJson(innerBundleInfoJson_); - BundleDataStorage bundleDataStorage; - EXPECT_FALSE(bundleDataStorage.DeleteStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); - - std::map> bundleDates; - EXPECT_FALSE(bundleDataStorage.SaveStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo)); - EXPECT_FALSE(bundleDataStorage.LoadAllData(bundleDates)); -} \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn index dabdfa6f..e91bb884 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("BmsBundleInstallerTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] @@ -151,7 +150,6 @@ ohos_unittest("BmsMultipleBundleInstallerTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/BUILD.gn index 5e69067f..ff8d52ad 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("BmsBundleKitServiceTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp index eb5db9fe..b560e8af 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_kit_service_test/bms_bundle_kit_service_test.cpp @@ -33,7 +33,6 @@ #include "launcher_service.h" #include "mock_clean_cache.h" #include "mock_bundle_status.h" -#include "module_usage_data_storage.h" #include "ohos/aafwk/content/want.h" using namespace testing::ext; @@ -3025,192 +3024,7 @@ HWTEST_F(BmsBundleKitServiceTest, GetShortcutInfos_0500, Function | SmallTest | EXPECT_TRUE(shortcutInfos.empty()); } -/** - * @tc.number: GetUsageRecords_0100 - * @tc.name: test can get usage records by notify ability life status - * @tc.desc: 1.can get usage records - */ -HWTEST_F(BmsBundleKitServiceTest, GetUsageRecords_0100, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, 1629094922, 0); - EXPECT_TRUE(ret); - std::vector records; - auto result = GetBundleDataMgr()->GetUsageRecords(100, records); - EXPECT_TRUE(result); - auto iter = std::find_if(records.begin(), records.end(), [](const auto &item) { - return (item.bundleName == BUNDLE_NAME_TEST && item.name == MODULE_NAME_TEST && - item.abilityName == ABILITY_NAME_TEST); - }); - EXPECT_NE(iter, records.end()); - uint32_t count = 1; - EXPECT_EQ(iter->launchedCount, count); - InnerBundleInfo innerBundleInfo; - MockInnerBundleInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST, innerBundleInfo); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo, 0); - MockUninstallBundle(BUNDLE_NAME_TEST); -} -/** - * @tc.number: GetUsageRecords_0300 - * @tc.name: test can get usage records by notify ability life status - * @tc.desc: 1.can get usage records called two notify ability - */ -HWTEST_F(BmsBundleKitServiceTest, GetUsageRecords_0300, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, time, 0); - auto ret1 = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, time, 0); - EXPECT_TRUE(ret); - EXPECT_TRUE(ret1); - std::vector records; - auto result = GetBundleDataMgr()->GetUsageRecords(100, records); - EXPECT_TRUE(result); - auto iter = std::find_if(records.begin(), records.end(), [](const auto &item) { - return (item.bundleName == BUNDLE_NAME_TEST && item.name == MODULE_NAME_TEST && - item.abilityName == ABILITY_NAME_TEST); - }); - EXPECT_NE(iter, records.end()); - uint32_t count = 2; - EXPECT_EQ(iter->launchedCount, count); - InnerBundleInfo innerBundleInfo1; - MockInnerBundleInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST, innerBundleInfo1); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo1, 0); - MockUninstallBundle(BUNDLE_NAME_TEST); -} - -/** - * @tc.number: GetUsageRecords_0400 - * @tc.name: test can't get usage records if maxNum is Less than 0. - * @tc.desc: 1.can't get usage records. - */ -HWTEST_F(BmsBundleKitServiceTest, GetUsageRecords_0400, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, time, 0); - EXPECT_TRUE(ret); - std::vector records; - auto result = GetBundleDataMgr()->GetUsageRecords(-1, records); - EXPECT_FALSE(result); - EXPECT_EQ(records.size(), RECORDS_SIZE_ZERO); - InnerBundleInfo innerBundleInfo1; - MockInnerBundleInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST, innerBundleInfo1); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo1, 0); - MockUninstallBundle(BUNDLE_NAME_TEST); -} - -/** - * @tc.number: GetUsageRecords_0500 - * @tc.name: test can't get usage records if maxNum is more than 1000. - * @tc.desc: 1.can't get usage records. - */ -HWTEST_F(BmsBundleKitServiceTest, GetUsageRecords_0500, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, time, 0); - EXPECT_TRUE(ret); - std::vector records; - auto result = GetBundleDataMgr()->GetUsageRecords(1001, records); - EXPECT_FALSE(result); - EXPECT_EQ(records.size(), RECORD_SIZE); - InnerBundleInfo innerBundleInfo1; - MockInnerBundleInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST, innerBundleInfo1); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo1, 0); - MockUninstallBundle(BUNDLE_NAME_TEST); -} - -/** - * @tc.number: NotifyAbilityLifeStatus_0100 - * @tc.name: test can called notify ability life status - * @tc.desc: 1. have called notify ability life status - * 2. called notify ability life - */ -HWTEST_F(BmsBundleKitServiceTest, NotifyAbilityLifeStatus_0100, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_DEMO, ABILITY_NAME_TEST); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, time, 0); - EXPECT_TRUE(ret); - InnerBundleInfo innerBundleInfo; - MockInnerBundleInfo(BUNDLE_NAME_TEST, MODULE_NAME_DEMO, ABILITY_NAME_TEST, innerBundleInfo); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo, 0); - MockUninstallBundle(BUNDLE_NAME_TEST); -} - -/** - * @tc.number: NotifyAbilityLifeStatus_0200 - * @tc.name: test can called notify ability life status - * @tc.desc: 1. have two bundle to called notify ability life status - * 2. notify ability life - */ -HWTEST_F(BmsBundleKitServiceTest, NotifyAbilityLifeStatus_0200, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - MockInstallBundle(BUNDLE_NAME_DEMO, MODULE_NAME_DEMO, ABILITY_NAME_DEMO); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_DEMO, ABILITY_NAME_DEMO, time, 0); - auto ret1 = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_TEST, ABILITY_NAME_TEST, time, 0); - EXPECT_TRUE(ret); - EXPECT_TRUE(ret1); - InnerBundleInfo innerBundleInfo1; - InnerBundleInfo innerBundleInfo2; - MockInnerBundleInfo(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST, innerBundleInfo1); - MockInnerBundleInfo(BUNDLE_NAME_DEMO, MODULE_NAME_DEMO, ABILITY_NAME_DEMO, innerBundleInfo2); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo1, 0); - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo2, 0); - MockUninstallBundle(BUNDLE_NAME_DEMO); - MockUninstallBundle(BUNDLE_NAME_TEST); -} - -/** - * @tc.number: NotifyAbilityLifeStatus_0300 - * @tc.name: test can't called notify ability life status by error bundleName - * @tc.desc: 1. can't to called notify ability life status - */ -HWTEST_F(BmsBundleKitServiceTest, NotifyAbilityLifeStatus_0300, Function | SmallTest | Level1) -{ - MockInstallBundle(BUNDLE_NAME_TEST, MODULE_NAME_TEST, ABILITY_NAME_TEST); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_DEMO, ABILITY_NAME_DEMO, time, 0); - EXPECT_FALSE(ret); - InnerBundleInfo innerBundleInfo; - MockInnerBundleInfo(BUNDLE_NAME_DEMO, MODULE_NAME_TEST, ABILITY_NAME_DEMO, innerBundleInfo); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo, 0); - MockUninstallBundle(BUNDLE_NAME_TEST); -} - -/** - * @tc.number: NotifyAbilityLifeStatus_0400 - * @tc.name: test can't called notify ability life status by null bundleName - * @tc.desc: 1. can't to called notify ability life status - */ -HWTEST_F(BmsBundleKitServiceTest, NotifyAbilityLifeStatus_0400, Function | SmallTest | Level1) -{ - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - auto ret = GetBundleDataMgr()->NotifyAbilityLifeStatus(BUNDLE_NAME_DEMO, ABILITY_NAME_DEMO, time, 0); - InnerBundleInfo innerBundleInfo; - MockInnerBundleInfo(BUNDLE_NAME_DEMO, MODULE_NAME_TEST, ABILITY_NAME_DEMO, innerBundleInfo); - ModuleUsageRecordStorage moduleUsageRecordStorage; - moduleUsageRecordStorage.DeleteUsageRecord(innerBundleInfo, 0); - EXPECT_FALSE(ret); -} /** * @tc.number: Ability_0100 diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/BUILD.gn index 85a46fba..620b6dd8 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_grant_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_unittest("BmsBundlePermissionGrantTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/BUILD.gn index bd9e4e33..c7310399 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/BUILD.gn @@ -46,7 +46,6 @@ ohos_unittest("BmsBundleUninstallerTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_bundle_updater_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_bundle_updater_test/BUILD.gn index d79d59a1..e1825f8e 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_updater_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_bundle_updater_test/BUILD.gn @@ -49,7 +49,6 @@ ohos_unittest("BmsBundleUpdaterTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_data_mgr_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_data_mgr_test/BUILD.gn index d667a802..a1a6fed7 100644 --- a/services/bundlemgr/test/unittest/bms_data_mgr_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_data_mgr_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("BmsDataMgrTest") { "${services_path}/bundlemgr/src/distributed_data_storage.cpp", "${services_path}/bundlemgr/src/hidump_helper.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", "//foundation/aafwk/standard/frameworks/kits/content/cpp/src/ohos/aafwk/content/element_name.cpp", diff --git a/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/BUILD.gn index 0677bc55..b720c7e4 100644 --- a/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/BUILD.gn @@ -36,7 +36,6 @@ ohos_unittest("BmsServiceBundleScanTest") { "${services_path}/bundlemgr/src/distributed_data_storage.cpp", "${services_path}/bundlemgr/src/hidump_helper.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/bundlemgr/test/unittest/bms_service_startup_test/BUILD.gn b/services/bundlemgr/test/unittest/bms_service_startup_test/BUILD.gn index 2f24a7f8..c6bba095 100644 --- a/services/bundlemgr/test/unittest/bms_service_startup_test/BUILD.gn +++ b/services/bundlemgr/test/unittest/bms_service_startup_test/BUILD.gn @@ -36,7 +36,6 @@ ohos_unittest("BmsServiceStartupTest") { "${services_path}/bundlemgr/src/distributed_data_storage.cpp", "${services_path}/bundlemgr/src/hidump_helper.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/test/moduletest/common/bms/bundle_installer_test/BUILD.gn b/services/test/moduletest/common/bms/bundle_installer_test/BUILD.gn index 6e9a26be..6de4ed32 100644 --- a/services/test/moduletest/common/bms/bundle_installer_test/BUILD.gn +++ b/services/test/moduletest/common/bms/bundle_installer_test/BUILD.gn @@ -54,7 +54,6 @@ ohos_moduletest("BmsBundleInstallerModuleTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/test/moduletest/common/bms/bundle_uninstall_test/BUILD.gn b/services/test/moduletest/common/bms/bundle_uninstall_test/BUILD.gn index 9009fd78..b3f0c519 100644 --- a/services/test/moduletest/common/bms/bundle_uninstall_test/BUILD.gn +++ b/services/test/moduletest/common/bms/bundle_uninstall_test/BUILD.gn @@ -52,7 +52,6 @@ ohos_moduletest("BmsBundleUninstallerModuleTest") { "${services_path}/bundlemgr/src/installd/installd_operator.cpp", "${services_path}/bundlemgr/src/installd/installd_service.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/services/test/moduletest/common/bms/service_start_process_test/BUILD.gn b/services/test/moduletest/common/bms/service_start_process_test/BUILD.gn index 35132bfa..f197c8bd 100644 --- a/services/test/moduletest/common/bms/service_start_process_test/BUILD.gn +++ b/services/test/moduletest/common/bms/service_start_process_test/BUILD.gn @@ -40,7 +40,6 @@ ohos_moduletest("BmsServiceStartModuleTest") { "${services_path}/bundlemgr/src/bundle_user_mgr_host_impl.cpp", "${services_path}/bundlemgr/src/hidump_helper.cpp", "${services_path}/bundlemgr/src/kvstore_death_recipient_callback.cpp", - "${services_path}/bundlemgr/src/module_usage_data_storage.cpp", "${services_path}/bundlemgr/src/permission_changed_death_recipient.cpp", "${services_path}/bundlemgr/src/preinstall_data_storage.cpp", ] diff --git a/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp b/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp index ccf8ba06..b04ba0dd 100644 --- a/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp +++ b/test/benchmarktest/bundlemgr_proxy_test/bundlemgr_proxy_test.cpp @@ -1668,44 +1668,6 @@ static void BenchmarkTestGetAllCommonEventInfo(benchmark::State &state) } } -/** - * @tc.name: BenchmarkTestGetModuleUsageRecords - * @tc.desc: Testcase for testing GetModuleUsageRecords. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - -static void BenchmarkTestGetModuleUsageRecords(benchmark::State &state) -{ - sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); - std::vector moduleUsageRecords; - ModuleUsageRecord info; - info.bundleName = "com.ohos.contactsdataability"; - info.name = "com.ohos.contactsdataability"; - moduleUsageRecords.push_back(info); - for (auto _ : state) { - /* @tc.steps: step1.call ReadFromParcel in loop */ - bundleMgrProxy->GetModuleUsageRecords(DEFAULT_USERID, moduleUsageRecords); - } -} - -/** - * @tc.name: BenchmarkTestNotifyAbilityLifeStatus - * @tc.desc: Testcase for testing NotifyAbilityLifeStatus. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - -static void BenchmarkTestNotifyAbilityLifeStatus(benchmark::State &state) -{ - sptr bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy(); - int64_t time = - std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - for (auto _ : state) { - /* @tc.steps: step1.call ReadFromParcel in loop */ - bundleMgrProxy->NotifyAbilityLifeStatus(bundleName, abilityName, time, 0); - } -} /** * @tc.name: BenchmarkTestRemoveClonedBundle @@ -2077,8 +2039,6 @@ BENCHMARK(BenchmarkTestGetFormsInfoByApp)->Iterations(1000); BENCHMARK(BenchmarkTestGetFormsInfoByModule)->Iterations(1000); BENCHMARK(BenchmarkTestGetShortcutInfos)->Iterations(1000); BENCHMARK(BenchmarkTestGetAllCommonEventInfo)->Iterations(1000); -BENCHMARK(BenchmarkTestGetModuleUsageRecords)->Iterations(1000); -BENCHMARK(BenchmarkTestNotifyAbilityLifeStatus)->Iterations(1000); BENCHMARK(BenchmarkTestRemoveClonedBundle)->Iterations(1000); BENCHMARK(BenchmarkTestCheckBundleNameInAllowList)->Iterations(1000); BENCHMARK(BenchmarkTestGetDistributedBundleInfo)->Iterations(1000); diff --git a/test/benchmarktest/module_usage_record_test/BUILD.gn b/test/benchmarktest/module_usage_record_test/BUILD.gn deleted file mode 100644 index 2e1cbcc9..00000000 --- a/test/benchmarktest/module_usage_record_test/BUILD.gn +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) 2022 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. - -import("//build/test.gni") -import("//foundation/appexecfwk/standard/appexecfwk.gni") - -module_output_path = "bundle_framework/benchmark/bundle_framework" - -ohos_benchmarktest("BenchmarkTestForModuleUsageRecord") { - module_out_path = module_output_path - sources = [ "module_usage_record_test.cpp" ] - - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - - deps = [ - "${common_path}:libappexecfwk_common", - "${innerkits_path}/appexecfwk_base:appexecfwk_base", - "//third_party/benchmark:benchmark", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "utils_base:utils", - ] -} - -group("benchmarktest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":BenchmarkTestForModuleUsageRecord", - ] -} diff --git a/test/benchmarktest/module_usage_record_test/module_usage_record_test.cpp b/test/benchmarktest/module_usage_record_test/module_usage_record_test.cpp deleted file mode 100644 index 9dcd3d9b..00000000 --- a/test/benchmarktest/module_usage_record_test/module_usage_record_test.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2022 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 "module_usage_record.h" - -#include - -using namespace std; -using namespace OHOS; -using namespace OHOS::AppExecFwk; - -namespace { - /** - * @tc.name: BenchmarkTestForReadFromParcel - * @tc.desc: Testcase for testing 'ReadFromParcel' function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - static void BenchmarkTestForReadFromParcel(benchmark::State &state) - { - ModuleUsageRecord info; - info.bundleName = "com.ohos.contactsdataability"; - info.name = "com.ohos.contactsdataability"; - Parcel parcel; - info.Marshalling(parcel); - for (auto _ : state) { - /* @tc.steps: step1.call ReadFromParcel in loop */ - info.ReadFromParcel(parcel); - } - } - - /** - * @tc.name: BenchmarkTestForMarshalling - * @tc.desc: Testcase for testing 'Marshalling' function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - static void BenchmarkTestForMarshalling(benchmark::State &state) - { - ModuleUsageRecord info; - info.bundleName = "com.ohos.contactsdataability"; - info.name = "com.ohos.contactsdataability"; - Parcel parcel; - for (auto _ : state) { - /* @tc.steps: step1.call Marshalling in loop */ - info.Marshalling(parcel); - } - } - - /** - * @tc.name: BenchmarkTestForUnmarshalling - * @tc.desc: Testcase for testing 'Unmarshalling' function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - static void BenchmarkTestForUnmarshalling(benchmark::State &state) - { - ModuleUsageRecord info; - info.bundleName = "com.ohos.contactsdataability"; - info.name = "com.ohos.contactsdataability"; - Parcel parcel; - info.Marshalling(parcel); - for (auto _ : state) { - /* @tc.steps: step1.call Unmarshalling in loop */ - info.Unmarshalling(parcel); - } - } - - /** - * @tc.name: BenchmarkTestForToString - * @tc.desc: Testcase for testing 'ToString' function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - static void BenchmarkTestForToString(benchmark::State &state) - { - ModuleUsageRecord info; - info.bundleName = "com.ohos.contactsdataability"; - info.name = "com.ohos.contactsdataability"; - for (auto _ : state) { - /* @tc.steps: step1.call ToString in loop */ - info.ToString(); - } - } - - /** - * @tc.name: BenchmarkTestForFromJsonString - * @tc.desc: Testcase for testing 'FromJsonString' function. - * @tc.type: FUNC - * @tc.require: Issue Number - */ - static void BenchmarkTestForFromJsonString(benchmark::State &state) - { - ModuleUsageRecord info; - const std::string jsonString = R"({"appId": "ohos.global.systemres_BNtg4JBClbl92Rgc3jm/ - RfcAdrHXaM8F0QOiwVEhnV5ebE5jNIYnAx+weFRT3QTyUjRNdhmc2aAzWyi+5t5CoBM=", - "bundleUserInfos": [ - { - "abilities": [], - "disabledAbilities": [], - "enabled": true, - "userId": 0 - } - ], - "compatibleVersionCode": 3, - "mainAbility": "", - "minCompatibleVersion": 1, - "name": "ohos.global.systemres", - "targetVersionCode": 3, - "version": 1, - "versionCode": 1, - "versionName": "1.0.0.1"})"; - for (auto _ : state) { - /* @tc.steps: step1.call FromJsonString in loop */ - info.FromJsonString(jsonString); - } - } - - BENCHMARK(BenchmarkTestForReadFromParcel)->Iterations(1000); - BENCHMARK(BenchmarkTestForMarshalling)->Iterations(1000); - BENCHMARK(BenchmarkTestForUnmarshalling)->Iterations(1000); - BENCHMARK(BenchmarkTestForToString)->Iterations(1000); - BENCHMARK(BenchmarkTestForFromJsonString)->Iterations(1000); -} - -BENCHMARK_MAIN(); \ No newline at end of file diff --git a/tools/test/mock/mock_bundle_mgr_host.h b/tools/test/mock/mock_bundle_mgr_host.h index 2eeae728..f1af5e51 100644 --- a/tools/test/mock/mock_bundle_mgr_host.h +++ b/tools/test/mock/mock_bundle_mgr_host.h @@ -103,10 +103,6 @@ public: MOCK_METHOD2(GetShortcutInfos, bool(const std::string &bundleName, std::vector &shortcutInfos)); MOCK_METHOD2(GetAllCommonEventInfo, bool(const std::string &eventKey, std::vector &commonEventInfos)); - MOCK_METHOD2(GetModuleUsageRecords, - bool(const int32_t number, std::vector &moduleUsageRecords)); - MOCK_METHOD4(NotifyAbilityLifeStatus, - bool(const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid)); MOCK_METHOD1(CheckBundleNameInAllowList, bool(const std::string &bundleName)); MOCK_METHOD3(GetBundleGidsByUid, bool(const std::string &bundleName, const int &uid, std::vector &gids)); MOCK_METHOD2(RemoveClonedBundle, bool(const std::string &bundleName, const int32_t uid));