mirror of
https://gitee.com/openharmony/appexecfwk_standard
synced 2024-11-27 07:00:31 +00:00
IssueNo: #I50454: delete moduleUsageRecord code
Description: delete moduleUsageRecord code Sig: SIG_ApplicaitonFramework Feature or Bugfix: Bugfix Binary Source: No Signed-off-by: SoftSquirrel <xuhao47@huawei.com>
This commit is contained in:
parent
667d890a88
commit
0e0e35b33f
@ -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",
|
||||
|
@ -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 <string>
|
||||
|
||||
#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
|
@ -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<uint32_t>(parcel.ReadInt32());
|
||||
labelId = static_cast<uint32_t>(parcel.ReadInt32());
|
||||
descriptionId = static_cast<uint32_t>(parcel.ReadInt32());
|
||||
abilityLabelId = static_cast<uint32_t>(parcel.ReadInt32());
|
||||
abilityDescriptionId = static_cast<uint32_t>(parcel.ReadInt32());
|
||||
abilityIconId = static_cast<uint32_t>(parcel.ReadInt32());
|
||||
launchedCount = static_cast<uint32_t>(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<uint32_t>(jsonObject,
|
||||
jsonObjectEnd,
|
||||
UsageRecordKey::LAUNCHED_COUNT,
|
||||
launchedCount,
|
||||
JsonType::NUMBER,
|
||||
false,
|
||||
parseResult,
|
||||
ArrayType::NOT_ARRAY);
|
||||
GetValueIfFindKey<int64_t>(jsonObject,
|
||||
jsonObjectEnd,
|
||||
UsageRecordKey::LAST_LAUNCH_TIME,
|
||||
lastLaunchTime,
|
||||
JsonType::NUMBER,
|
||||
false,
|
||||
parseResult,
|
||||
ArrayType::NOT_ARRAY);
|
||||
GetValueIfFindKey<bool>(jsonObject,
|
||||
jsonObjectEnd,
|
||||
UsageRecordKey::IS_REMOVED,
|
||||
removed,
|
||||
JsonType::BOOLEAN,
|
||||
false,
|
||||
parseResult,
|
||||
ArrayType::NOT_ARRAY);
|
||||
GetValueIfFindKey<std::string>(jsonObject,
|
||||
jsonObjectEnd,
|
||||
UsageRecordKey::ABILITY_NAME,
|
||||
abilityName,
|
||||
JsonType::STRING,
|
||||
false,
|
||||
parseResult,
|
||||
ArrayType::NOT_ARRAY);
|
||||
return parseResult == ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -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.
|
||||
|
@ -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,
|
||||
|
@ -256,12 +256,6 @@ int BundleMgrHost::OnRemoteRequest(uint32_t code, MessageParcel &data, MessagePa
|
||||
case static_cast<uint32_t>(IBundleMgr::Message::GET_ALL_COMMON_EVENT_INFO):
|
||||
errCode = HandleGetAllCommonEventInfo(data, reply);
|
||||
break;
|
||||
case static_cast<uint32_t>(IBundleMgr::Message::GET_MODULE_USAGE_RECORD):
|
||||
errCode = HandleGetModuleUsageRecords(data, reply);
|
||||
break;
|
||||
case static_cast<uint32_t>(IBundleMgr::Message::NOTIFY_ABILITY_LIFE_STATUS):
|
||||
errCode = HandleNotifyAbilityLifeStatus(data, reply);
|
||||
break;
|
||||
case static_cast<uint32_t>(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<ModuleUsageRecord> 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__);
|
||||
|
@ -1965,64 +1965,13 @@ bool BundleMgrProxy::GetAllCommonEventInfo(const std::string &eventKey, std::vec
|
||||
|
||||
bool BundleMgrProxy::GetModuleUsageRecords(const int32_t number, std::vector<ModuleUsageRecord> &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<ModuleUsageRecord>(
|
||||
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)
|
||||
|
@ -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<OHOS::AppExecFwk::ModuleUsageRecord> &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<OHOS::AppExecFwk::ModuleUsageRecord> &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<AsyncModuleUsageRecordsCallbackInfo> 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<AsyncModuleUsageRecordsCallbackInfo> 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<AsyncModuleUsageRecordsCallbackInfo> 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");
|
||||
|
@ -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<OHOS::AppExecFwk::ModuleUsageRecord> 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);
|
||||
|
@ -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),
|
||||
|
@ -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",
|
||||
|
@ -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<CommonEventInfo> &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<ModuleUsageRecord> &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<InstallState, InstallState> transferStates_;
|
||||
std::shared_ptr<IBundleDataStorage> dataStorage_;
|
||||
std::shared_ptr<ModuleUsageRecordStorage> usageRecordStorage_;
|
||||
std::shared_ptr<PreInstallDataStorage> preInstallDataStorage_;
|
||||
std::shared_ptr<DistributedDataStorage> distributedDataStorage_;
|
||||
std::set<sptr<OnPermissionChangedCallback>> allPermissionsCallbacks_;
|
||||
|
@ -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";
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "module_usage_record.h"
|
||||
|
||||
#include "bundle_constants.h"
|
||||
#include "distributed_kv_data_manager.h"
|
||||
#include "inner_bundle_info.h"
|
||||
|
@ -38,9 +38,6 @@ BundleDataMgr::BundleDataMgr()
|
||||
{
|
||||
InitStateTransferMap();
|
||||
dataStorage_ = std::make_shared<BundleDataStorageDatabase>();
|
||||
usageRecordStorage_ = std::make_shared<ModuleUsageRecordStorage>();
|
||||
// register distributed data process death listener.
|
||||
usageRecordStorage_->RegisterKvStoreDeathListener();
|
||||
preInstallDataStorage_ = std::make_shared<PreInstallDataStorage>();
|
||||
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<ModuleUsageRecord> &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<ModuleUsageRecord> 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<std::mutex> 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<uint32_t>(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<std::mutex> 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<std::mutex> 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<std::string> 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<ShortcutInfo> &shortcutInfos) const
|
||||
{
|
||||
|
@ -1067,26 +1067,13 @@ bool BundleMgrHostImpl::GetAllCommonEventInfo(const std::string &eventKey,
|
||||
|
||||
bool BundleMgrHostImpl::GetModuleUsageRecords(const int32_t number, std::vector<ModuleUsageRecord> &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)
|
||||
|
@ -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 <cinttypes>
|
||||
#include <unistd.h>
|
||||
#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<std::string> 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<uint32_t>(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<std::mutex> 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<std::mutex> 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<DistributedKv::Key> &keys)
|
||||
{
|
||||
if (keys.size() == 0) {
|
||||
APP_LOGE("delete error: empty key");
|
||||
return false;
|
||||
}
|
||||
Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
APP_LOGE("kvStore is nullptr");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Key> 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<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
APP_LOGE("kvStore is nullptr");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
ModuleUsageRecord record;
|
||||
Value value;
|
||||
std::string jsonString;
|
||||
std::vector<Key> keys;
|
||||
InnerBundleInfoToKeys(data, userId, keys);
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<DistributedKv::Key> &keys) const
|
||||
{
|
||||
std::vector<std::string> 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<DistributedKv::Key> &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<Entry> &allEntries, std::vector<ModuleUsageRecord> &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<ModuleUsageRecord> &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<Entry> allEntries;
|
||||
bool queryResult = QueryRecordByCondition(query, allEntries);
|
||||
if (!queryResult || static_cast<int>(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<Entry> &records)
|
||||
{
|
||||
Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<Status()> &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<std::mutex> 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
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
||||
|
@ -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 <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
|
||||
#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<std::string, std::map<std::string, InnerBundleInfo>> 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<std::string, std::map<std::string, InnerBundleInfo>> 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<std::string, std::map<std::string, InnerBundleInfo>> 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<std::string, std::map<std::string, InnerBundleInfo>> bundleDates;
|
||||
EXPECT_FALSE(bundleDataStorage.SaveStorageBundleInfo(Constants::CURRENT_DEVICE_ID, innerBundleInfo));
|
||||
EXPECT_FALSE(bundleDataStorage.LoadAllData(bundleDates));
|
||||
}
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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<ModuleUsageRecord> 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::seconds>(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<ModuleUsageRecord> 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::seconds>(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<ModuleUsageRecord> 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::seconds>(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<ModuleUsageRecord> 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::seconds>(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::seconds>(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::seconds>(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::seconds>(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
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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",
|
||||
]
|
||||
|
@ -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<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
|
||||
std::vector<ModuleUsageRecord> 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<IBundleMgr> bundleMgrProxy = BundleMgrProxyTest::GetBundleMgrProxy();
|
||||
int64_t time =
|
||||
std::chrono::duration_cast<std::chrono::seconds>(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);
|
||||
|
@ -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",
|
||||
]
|
||||
}
|
@ -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 <benchmark/benchmark.h>
|
||||
|
||||
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();
|
@ -103,10 +103,6 @@ public:
|
||||
MOCK_METHOD2(GetShortcutInfos, bool(const std::string &bundleName, std::vector<ShortcutInfo> &shortcutInfos));
|
||||
MOCK_METHOD2(GetAllCommonEventInfo,
|
||||
bool(const std::string &eventKey, std::vector<CommonEventInfo> &commonEventInfos));
|
||||
MOCK_METHOD2(GetModuleUsageRecords,
|
||||
bool(const int32_t number, std::vector<ModuleUsageRecord> &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<int> &gids));
|
||||
MOCK_METHOD2(RemoveClonedBundle, bool(const std::string &bundleName, const int32_t uid));
|
||||
|
Loading…
Reference in New Issue
Block a user