IssueNo:#I6CLFD

Description:add quick fix frequency
Sig:SIG_ApplicaitonFramework
Feature or Bugfix:Bugfix
Binary Source:No
Signed-off-by: wangtiantian <wangtiantian19@huawei.com>
This commit is contained in:
wangtiantian 2023-02-03 11:10:08 +08:00
parent 47861fd7c7
commit 8263f4fc56
10 changed files with 110 additions and 2 deletions

View File

@ -166,4 +166,12 @@ BMS_USER_EVENT:
__BASE: {type: BEHAVIOR, level: MINOR, desc: user event}
TYPE: {type: STRING, desc: user event type}
USERID: {type: INT32, desc: userId of the bundle}
TIME: {type: INT64, desc: time stamp}
TIME: {type: INT64, desc: time stamp}
BUNDLE_QUICK_FIX:
__BASE: {type: BEHAVIOR, level: MINOR, desc: bundle apply quick fix}
BUNDLE_NAME: {type: STRING, desc: bundleName}
APP_DISTRIBUTION_TYPE: {type: STRING, desc: app distribution type}
APPLY_QUICK_FIX_FREQUENCY: {type: INT32, desc: apply quick fix frequency}
FILE_PATH: {type: STRING, arrsize: 99, desc: the path of the hqf file}
HASH_VALUE: {type: STRING, arrsize: 99, desc: the hash value of the hqf file}

View File

@ -42,7 +42,8 @@ enum class BMSEventType {
PRE_BUNDLE_RECOVER,
BUNDLE_STATE_CHANGE,
BUNDLE_CLEAN_CACHE,
BMS_USER_EVENT
BMS_USER_EVENT,
APPLY_QUICK_FIX
};
enum class BundleEventType {
@ -51,6 +52,7 @@ enum class BundleEventType {
UNINSTALL,
UPDATE,
RECOVER,
QUICK_FIX
};
enum class InstallScene {
@ -114,6 +116,9 @@ struct EventInfo {
// only used in user event
UserEventType userEventType = UserEventType::UNKNOW;
// for quick fix
int32_t applyQuickFixFrequency = 0;
void Reset()
{
userId = Constants::INVALID_USERID;
@ -137,6 +142,7 @@ struct EventInfo {
fingerprint.clear();
hideDesktopIcon = false;
appDistributionType.clear();
applyQuickFixFrequency = 0;
}
};

View File

@ -1878,6 +1878,9 @@ public:
int64_t GetLastInstallationTime() const;
void UpdateAppDetailAbilityAttrs();
bool IsHideDesktopIcon() const;
void AddApplyQuickFixFrequency();
int32_t GetApplyQuickFixFrequency() const;
void ResetApplyQuickFixFrequency();
private:
bool IsExistLauncherAbility() const;
@ -1936,6 +1939,8 @@ private:
std::vector<SandboxAppPersistentInfo> sandboxPersistentInfo_;
// quick fix hqf info
std::vector<HqfInfo> hqfInfos_;
// apply quick fix frequency
int32_t applyQuickFixFrequency_ = 0;
// overlay bundleInfo
std::vector<OverlayBundleInfo> overlayBundleInfo_;

View File

@ -50,6 +50,7 @@ private:
static void InnerSendBundleStateChangeEvent(const EventInfo& eventInfo);
static void InnerSendBundleCleanCacheEvent(const EventInfo& eventInfo);
static void InnerSendUserEvent(const EventInfo& eventInfo);
static void InnerSendQuickFixEvent(const EventInfo& eventInfo);
template<typename... Types>
static void InnerEventWrite(const std::string &eventName,

View File

@ -98,9 +98,12 @@ private:
bool HasNativeSoInBundle(const AppQuickFix &appQuickFix);
void SendQuickFixSystemEvent(const InnerBundleInfo &innerBundleInfo);
std::vector<std::string> patchPaths_;
std::shared_ptr<QuickFixDataMgr> quickFixDataMgr_ = nullptr;
DeployQuickFixResult deployQuickFixResult_;
std::string appDistributionType_ = Constants::APP_DISTRIBUTION_TYPE_NONE;
};
} // AppExecFwk
} // OHOS

View File

@ -442,6 +442,8 @@ bool BundleDataMgr::UpdateInnerBundleInfo(
oldInfo.SetAsanEnabled(newInfo.GetAsanEnabled());
oldInfo.SetAppCrowdtestDeadline(newInfo.GetAppCrowdtestDeadline());
oldInfo.SetBundlePackInfo(newInfo.GetBundlePackInfo());
// clear apply quick fix frequency
oldInfo.ResetApplyQuickFixFrequency();
oldInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::ENABLED);
#ifdef BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION
if ((newInfo.GetOverlayType() != NON_OVERLAY_TYPE) &&

View File

@ -38,6 +38,7 @@ const std::unordered_map<BundleEventType, BMSEventType> BUNDLE_SYS_EVENT_MAP = {
{ BundleEventType::UNINSTALL, BMSEventType::BUNDLE_UNINSTALL },
{ BundleEventType::UPDATE, BMSEventType::BUNDLE_UPDATE },
{ BundleEventType::RECOVER, BMSEventType::PRE_BUNDLE_RECOVER },
{ BundleEventType::QUICK_FIX, BMSEventType::APPLY_QUICK_FIX }
};
}

View File

@ -116,6 +116,7 @@ const std::string MODULE_TARGET_PRIORITY = "targetPriority";
const std::string MODULE_OVERLAY_MODULE_INFO = "overlayModuleInfo";
const std::string OVERLAY_BUNDLE_INFO = "overlayBundleInfo";
const std::string OVERLAY_TYPE = "overlayType";
const std::string APPLY_QUICK_FIX_FREQUENCY = "applyQuickFixFrequency";
inline CompileMode ConvertCompileMode(const std::string& compileMode)
{
@ -418,6 +419,7 @@ InnerBundleInfo &InnerBundleInfo::operator=(const InnerBundleInfo &info)
this->hqfInfos_ = info.hqfInfos_;
this->overlayBundleInfo_ = info.overlayBundleInfo_;
this->overlayType_ = info.overlayType_;
this->applyQuickFixFrequency_ = info.applyQuickFixFrequency_;
return *this;
}
@ -582,6 +584,7 @@ void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const
jsonObject[BUNDLE_HQF_INFOS] = hqfInfos_;
jsonObject[OVERLAY_BUNDLE_INFO] = overlayBundleInfo_;
jsonObject[OVERLAY_TYPE] = overlayType_;
jsonObject[APPLY_QUICK_FIX_FREQUENCY] = applyQuickFixFrequency_;
}
void from_json(const nlohmann::json &jsonObject, InnerModuleInfo &info)
@ -1523,6 +1526,14 @@ int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject)
false,
parseResult,
ArrayType::NOT_ARRAY);
GetValueIfFindKey<int32_t>(jsonObject,
jsonObjectEnd,
APPLY_QUICK_FIX_FREQUENCY,
applyQuickFixFrequency_,
JsonType::NUMBER,
false,
parseResult,
ArrayType::NOT_ARRAY);
if (parseResult != ERR_OK) {
APP_LOGE("read InnerBundleInfo from database error, error code : %{public}d", parseResult);
return parseResult;
@ -3302,5 +3313,20 @@ std::vector<std::string> InnerBundleInfo::GetDeviceType(const std::string &packa
}
return innerModuleInfos_.at(packageName).deviceTypes;
}
void InnerBundleInfo::AddApplyQuickFixFrequency()
{
++applyQuickFixFrequency_;
}
int32_t InnerBundleInfo::GetApplyQuickFixFrequency() const
{
return applyQuickFixFrequency_;
}
void InnerBundleInfo::ResetApplyQuickFixFrequency()
{
applyQuickFixFrequency_ = 0;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -38,6 +38,7 @@ const std::string PRE_BUNDLE_RECOVER = "PRE_BUNDLE_RECOVER";
const std::string BUNDLE_STATE_CHANGE = "BUNDLE_STATE_CHANGE";
const std::string BUNDLE_CLEAN_CACHE = "BUNDLE_CLEAN_CACHE";
const std::string BMS_USER_EVENT = "BMS_USER_EVENT";
const std::string BUNDLE_QUICK_FIX = "BUNDLE_QUICK_FIX";
// event params
const std::string EVENT_PARAM_USERID = "USERID";
@ -60,6 +61,7 @@ const std::string EVENT_PARAM_APP_DISTRIBUTION_TYPE = "APP_DISTRIBUTION_TYPE";
const std::string EVENT_PARAM_FILE_PATH = "FILE_PATH";
const std::string EVENT_PARAM_HASH_VALUE = "HASH_VALUE";
const std::string EVENT_PARAM_INSTALL_TIME = "INSTALL_TIME";
const std::string EVENT_PARAM_APPLY_QUICK_FIX_FREQUENCY = "APPLY_QUICK_FIX_FREQUENCY";
const std::string FREE_INSTALL_TYPE = "FreeInstall";
const std::string PRE_BUNDLE_INSTALL_TYPE = "PreBundleInstall";
@ -194,6 +196,10 @@ std::unordered_map<BMSEventType, void (*)(const EventInfo& eventInfo)>
[](const EventInfo& eventInfo) {
InnerSendUserEvent(eventInfo);
} },
{ BMSEventType::APPLY_QUICK_FIX,
[](const EventInfo& eventInfo) {
InnerSendQuickFixEvent(eventInfo);
} }
};
void InnerEventReport::SendSystemEvent(BMSEventType bmsEventType, const EventInfo& eventInfo)
@ -402,6 +408,18 @@ void InnerEventReport::InnerSendUserEvent(const EventInfo& eventInfo)
EVENT_PARAM_TIME, eventInfo.timeStamp);
}
void InnerEventReport::InnerSendQuickFixEvent(const EventInfo& eventInfo)
{
InnerEventWrite(
BUNDLE_QUICK_FIX,
HiSysEventType::BEHAVIOR,
EVENT_PARAM_BUNDLE_NAME, eventInfo.bundleName,
EVENT_PARAM_APP_DISTRIBUTION_TYPE, eventInfo.appDistributionType,
EVENT_PARAM_APPLY_QUICK_FIX_FREQUENCY, eventInfo.applyQuickFixFrequency,
EVENT_PARAM_FILE_PATH, eventInfo.filePath,
EVENT_PARAM_HASH_VALUE, eventInfo.hashValue);
}
template<typename... Types>
void InnerEventReport::InnerEventWrite(
const std::string &eventName,

View File

@ -21,12 +21,31 @@
#include "bundle_mgr_service.h"
#include "bundle_util.h"
#include "installd_client.h"
#include "event_report.h"
#include "patch_extractor.h"
#include "patch_parser.h"
#include "scope_guard.h"
namespace OHOS {
namespace AppExecFwk {
namespace {
static std::string GetAppDistributionType(Security::Verify::AppDistType type)
{
std::unordered_map<Security::Verify::AppDistType, std::string> AppDistributionTypeMaps = {
{ Security::Verify::AppDistType::NONE_TYPE, Constants::APP_DISTRIBUTION_TYPE_NONE },
{ Security::Verify::AppDistType::APP_GALLERY, Constants::APP_DISTRIBUTION_TYPE_APP_GALLERY },
{ Security::Verify::AppDistType::ENTERPRISE, Constants::APP_DISTRIBUTION_TYPE_ENTERPRISE },
{ Security::Verify::AppDistType::OS_INTEGRATION, Constants::APP_DISTRIBUTION_TYPE_OS_INTEGRATION },
{ Security::Verify::AppDistType::CROWDTESTING, Constants::APP_DISTRIBUTION_TYPE_CROWDTESTING },
};
auto typeIter = AppDistributionTypeMaps.find(type);
if (typeIter == AppDistributionTypeMaps.end()) {
return Constants::APP_DISTRIBUTION_TYPE_NONE;
}
return typeIter->second;
}
}
QuickFixDeployer::QuickFixDeployer(const std::vector<std::string> &bundleFilePaths) : patchPaths_(bundleFilePaths)
{}
@ -207,6 +226,7 @@ ErrCode QuickFixDeployer::ProcessPatchDeployStart(
APP_LOGE("check AppQuickFixInfos with installed bundle failed, errcode : %{public}d", ret);
return ret;
}
appDistributionType_ = GetAppDistributionType(provisionInfo.distributionType);
APP_LOGI("ProcessPatchDeployStart end.");
return ERR_OK;
}
@ -667,12 +687,16 @@ ErrCode QuickFixDeployer::SaveToInnerBundleInfo(const InnerAppQuickFix &newInner
ScopeGuard enableGuard([&bundleName, &dataMgr] { dataMgr->EnableBundle(bundleName); });
AppQuickFix appQuickFix = newInnerAppQuickFix.GetAppQuickFix();
appQuickFix.deployedAppqfInfo = innerBundleInfo.GetAppQuickFix().deployedAppqfInfo;
// add apply quick fix frequency
innerBundleInfo.AddApplyQuickFixFrequency();
innerBundleInfo.SetAppQuickFix(appQuickFix);
innerBundleInfo.SetBundleStatus(InnerBundleInfo::BundleStatus::ENABLED);
if (!dataMgr->UpdateQuickFixInnerBundleInfo(bundleName, innerBundleInfo)) {
APP_LOGE("update quickfix innerbundleInfo failed");
return ERR_BUNDLEMANAGER_QUICK_FIX_INTERNAL_ERROR;
}
// send quick fix data
SendQuickFixSystemEvent(innerBundleInfo);
return ERR_OK;
}
@ -692,5 +716,19 @@ ErrCode QuickFixDeployer::ProcessBundleFilePaths(const std::vector<std::string>
}
return ERR_OK;
}
void QuickFixDeployer::SendQuickFixSystemEvent(const InnerBundleInfo &innerBundleInfo)
{
EventInfo sysEventInfo;
sysEventInfo.errCode = ERR_OK;
sysEventInfo.bundleName = innerBundleInfo.GetBundleName();
sysEventInfo.appDistributionType = appDistributionType_;
for (const auto &hqfInfo : innerBundleInfo.GetAppQuickFix().deployingAppqfInfo.hqfInfos) {
sysEventInfo.filePath.push_back(hqfInfo.hqfFilePath);
sysEventInfo.hashValue.push_back(hqfInfo.hapSha256);
}
sysEventInfo.applyQuickFixFrequency = innerBundleInfo.GetApplyQuickFixFrequency();
EventReport::SendBundleSystemEvent(BundleEventType::QUICK_FIX, sysEventInfo);
}
} // AppExecFwk
} // OHOS