mirror of
https://github.com/openharmony/bundlemanager_app_domain_verify.git
synced 2026-07-01 02:47:59 -04:00
新增预装应用类别
Signed-off-by: zhangrn98 <zhangrunan3@huawei.com> Signed-off-by: zhangrn98 <zhangrunan3@outlook.com>
This commit is contained in:
@@ -30,6 +30,7 @@ public:
|
||||
static bool GetBundleAbilityInfos(const std::string& bundleName, std::vector<AbilityInfo>& abilityInfos);
|
||||
static bool QueryAbilityInfos(
|
||||
const std::string& url, bool withDefault, std::vector<AbilityInfo>& abilityInfos, bool& findDefaultApp);
|
||||
static bool IsPreInstalledApp(const std::string& bundleName);
|
||||
|
||||
private:
|
||||
static sptr<AppExecFwk::IBundleMgr> GetBundleMgrProxy();
|
||||
|
||||
@@ -175,5 +175,31 @@ bool BundleInfoQuery::QueryAbilityInfos(
|
||||
abilityInfos.size(), findDefaultApp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool BundleInfoQuery::IsPreInstalledApp(const std::string& bundleName)
|
||||
{
|
||||
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_MODULE_COMMON, "called");
|
||||
sptr<AppExecFwk::IBundleMgr> bundleMgrProxy = BundleInfoQuery::GetBundleMgrProxy();
|
||||
if (bundleMgrProxy == nullptr) {
|
||||
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "bundleMgrProxy is nullptr.");
|
||||
return false;
|
||||
}
|
||||
int32_t userId = BundleInfoQuery::GetCurrentAccountId();
|
||||
if (userId < 0) {
|
||||
return false;
|
||||
}
|
||||
OHOS::AppExecFwk::BundleInfo bundleInfo;
|
||||
// use sa identity
|
||||
std::string identity = IPCSkeleton::ResetCallingIdentity();
|
||||
auto ret = bundleMgrProxy->GetBundleInfoV9(bundleName,
|
||||
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO), bundleInfo, userId);
|
||||
IPCSkeleton::SetCallingIdentity(identity);
|
||||
if (ret != ERR_OK) {
|
||||
APP_DOMAIN_VERIFY_HILOGE(APP_DOMAIN_VERIFY_MODULE_COMMON, "GetBundleInfo failed, ret: %{public}d.", ret);
|
||||
return false;
|
||||
}
|
||||
// Check if the app is pre-installed (system app)
|
||||
return bundleInfo.isPreInstallApp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,14 +26,14 @@ namespace AppDomainVerify {
|
||||
class DomainVerifier {
|
||||
public:
|
||||
static InnerVerifyStatus VerifyHost(OHOS::NetStack::HttpClient::ResponseCode responseCode,
|
||||
const std::string &assetJsonsStr, AppVerifyBaseInfo &appVerifyBaseInfo);
|
||||
const std::string& assetJsonsStr, AppVerifyBaseInfo& appVerifyBaseInfo);
|
||||
|
||||
private:
|
||||
static InnerVerifyStatus GetVerifyStatusFromHttpError(OHOS::NetStack::HttpClient::ResponseCode responseCode);
|
||||
static InnerVerifyStatus VerifyHostWithAppIdentifier(const AssetJsonObj &assetJsonObj,
|
||||
AppVerifyBaseInfo &appVerifyBaseInfo);
|
||||
static InnerVerifyStatus VerifyHostWithBundleName(const AssetJsonObj &assetJsonObj,
|
||||
AppVerifyBaseInfo &appVerifyBaseInfo);
|
||||
static InnerVerifyStatus VerifyHostWithAppIdentifier(
|
||||
const AssetJsonObj& assetJsonObj, AppVerifyBaseInfo& appVerifyBaseInfo);
|
||||
static InnerVerifyStatus VerifyHostWithBundleName(
|
||||
const AssetJsonObj& assetJsonObj, AppVerifyBaseInfo& appVerifyBaseInfo);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "domain_verifier.h"
|
||||
#include "app_domain_verify_hilog.h"
|
||||
#include "domain_json_util.h"
|
||||
#include "bundle_info_query.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppDomainVerify {
|
||||
@@ -24,7 +25,15 @@ InnerVerifyStatus DomainVerifier::VerifyHost(OHOS::NetStack::HttpClient::Respons
|
||||
{
|
||||
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE, "called");
|
||||
if (responseCode != OHOS::NetStack::HttpClient::ResponseCode::OK) {
|
||||
return GetVerifyStatusFromHttpError(responseCode);
|
||||
InnerVerifyStatus status = GetVerifyStatusFromHttpError(responseCode);
|
||||
if (status == InnerVerifyStatus::FAILURE_HTTP_UNKNOWN &&
|
||||
BundleInfoQuery::IsPreInstalledApp(appVerifyBaseInfo.bundleName)) {
|
||||
APP_DOMAIN_VERIFY_HILOGD(APP_DOMAIN_VERIFY_AGENT_MODULE_SERVICE,
|
||||
"pre installed app, bundleName: %{public}s", appVerifyBaseInfo.bundleName.c_str());
|
||||
return InnerVerifyStatus::PRE_INSTALLED;
|
||||
} else {
|
||||
return status;
|
||||
}
|
||||
}
|
||||
AssetJsonObj assetJsonObj;
|
||||
if (JsonUtil::Parse(assetJsonsStr, assetJsonObj)) {
|
||||
|
||||
@@ -76,13 +76,14 @@ private:
|
||||
// with check caller's bundleName and appIdentifier
|
||||
int QueryVerifiedBundleWithDomains(std::string& bundleName, std::vector<std::string>& domains);
|
||||
void SendVerifiedEvent(const std::string& bundleName, const VerifyResultInfo& verifyResultInfo);
|
||||
int QueryVerifiedBundleWithDomainsByAppIdentifer(const std::string& appIdentifer,
|
||||
std::string& bundleName, std::vector<std::string>& domains);
|
||||
int QueryVerifiedBundleWithDomainsByAppIdentifer(
|
||||
const std::string& appIdentifer, std::string& bundleName, std::vector<std::string>& domains);
|
||||
void FilterAbilitiesInner(std::string hostVerifyKey,
|
||||
const std::vector<OHOS::AppExecFwk::AbilityInfo>& originAbilityInfos,
|
||||
std::vector<OHOS::AppExecFwk::AbilityInfo>& filteredAbilityInfos);
|
||||
bool ResetDBSecurityByPath();
|
||||
bool IsExistDir(const std::string& dirPath);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AppDetailsDataMgr> appDetailsDataMgr_ = nullptr;
|
||||
bool InitConfigMgr();
|
||||
|
||||
@@ -39,7 +39,9 @@ enum InnerVerifyStatus {
|
||||
|
||||
FAILURE_CONFIG = 8,
|
||||
|
||||
FORBIDDEN_FOREVER = 9
|
||||
FORBIDDEN_FOREVER = 9,
|
||||
|
||||
PRE_INSTALLED = 10
|
||||
};
|
||||
|
||||
static std::unordered_map<InnerVerifyStatus, std::string> InnerVerifyStatusMap = {
|
||||
@@ -52,7 +54,8 @@ static std::unordered_map<InnerVerifyStatus, std::string> InnerVerifyStatusMap =
|
||||
{ FAILURE_HTTP_UNKNOWN, "http_unknown" },
|
||||
{ FAILURE_TIMEOUT, "timeout" },
|
||||
{ FAILURE_CONFIG, "config_error" },
|
||||
{ FORBIDDEN_FOREVER, "forbidden_forever" }
|
||||
{ FORBIDDEN_FOREVER, "forbidden_forever" },
|
||||
{ PRE_INSTALLED, "pre_installed" }
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -132,7 +132,8 @@ void AppDomainVerifyMgrService::FilterAbilitiesInner(std::string hostVerifyKey,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (itr->second.status == InnerVerifyStatus::STATE_SUCCESS) {
|
||||
if (itr->second.status == InnerVerifyStatus::STATE_SUCCESS ||
|
||||
itr->second.status == InnerVerifyStatus::PRE_INSTALLED) {
|
||||
auto ability = *it;
|
||||
auto priority = itr->second.priority;
|
||||
auto tuple = std::make_tuple(ability, priority);
|
||||
|
||||
Reference in New Issue
Block a user