modify extension to flag

Signed-off-by: donglin <donglin9@huawei.com>
Change-Id: Ib53360fbc2774d121949b13a9ba0c97954f10c88
This commit is contained in:
donglin 2024-06-06 14:40:26 +00:00
parent 7c892297b6
commit 1d9a3d098f
7 changed files with 74 additions and 31 deletions

View File

@ -62,6 +62,7 @@ struct RunningProcessInfo : public Parcelable {
bool isTestProcess = false;
bool isAbilityForegrounding = false;
bool isTestMode = false;
bool isStrictMode = false;
std::int32_t bundleType = 0;
std::int32_t appCloneIndex = -1;

View File

@ -46,7 +46,8 @@ private:
bool CheckServiceExtensionUriValid(const std::string &uri);
std::map<std::string, int32_t> extensionAutoDisconnectTimeMap_;
std::unordered_map<std::string, bool> thirdPartyAppBlockedFlags_;
std::unordered_map<std::string, bool> thirdPartyAppEnableFlags_;
std::unordered_map<std::string, bool> serviceEnableFlags_;
std::unordered_map<std::string, std::unordered_set<std::string>> serviceBlockedLists_;
};
} // OHOS

View File

@ -36,6 +36,7 @@ constexpr const char* EXTENSION_AUTO_DISCONNECT_TIME = "auto_disconnect_time";
constexpr const char* EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME = "third_party_app_blocked_flag";
constexpr const char* EXTENSION_SERVICE_BLOCKED_LIST_NAME = "service_blocked_list";
constexpr const char* EXTENSION_SERVICE_STARTUP_ENABLE_FLAG = "service_startup_enable_flag";
const int32_t DEFAULT_EXTENSION_AUTO_DISCONNECT_TIME = -1;
}
@ -72,8 +73,8 @@ int32_t ExtensionConfig::GetExtensionAutoDisconnectTime(std::string extensionTyp
bool ExtensionConfig::IsExtensionStartThirdPartyAppEnable(std::string extensionTypeName)
{
if (thirdPartyAppBlockedFlags_.find(extensionTypeName) != thirdPartyAppBlockedFlags_.end()) {
return thirdPartyAppBlockedFlags_[extensionTypeName];
if (thirdPartyAppEnableFlags_.find(extensionTypeName) != thirdPartyAppEnableFlags_.end()) {
return thirdPartyAppEnableFlags_[extensionTypeName];
}
return true;
}
@ -81,6 +82,10 @@ bool ExtensionConfig::IsExtensionStartThirdPartyAppEnable(std::string extensionT
bool ExtensionConfig::IsExtensionStartServiceEnable(std::string extensionTypeName, std::string targetUri)
{
AppExecFwk::ElementName targetElementName;
if (serviceEnableFlags_.find(extensionTypeName) != serviceEnableFlags_.end() &&
!serviceEnableFlags_[extensionTypeName]) {
return false;
}
if (!targetElementName.ParseURI(targetUri) ||
serviceBlockedLists_.find(extensionTypeName) == serviceBlockedLists_.end()) {
return true;
@ -135,14 +140,25 @@ void ExtensionConfig::LoadExtensionThirdPartyAppBlockedList(const nlohmann::json
TAG_LOGE(AAFwkTag::ABILITYMGR, "Third party config not existed.");
return;
}
thirdPartyAppBlockedFlags_[extensionTypeName] = object.at(EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME).get<bool>();
thirdPartyAppEnableFlags_[extensionTypeName] = object.at(EXTENSION_THIRD_PARTY_APP_BLOCKED_FLAG_NAME).get<bool>();
TAG_LOGD(AAFwkTag::ABILITYMGR, "The %{public}s extension's third party app blocked flag is %{public}d",
extensionTypeName.c_str(), thirdPartyAppBlockedFlags_[extensionTypeName]);
extensionTypeName.c_str(), thirdPartyAppEnableFlags_[extensionTypeName]);
}
void ExtensionConfig::LoadExtensionServiceBlockedList(const nlohmann::json &object, std::string extensionTypeName)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "call.");
if (!object.contains(EXTENSION_SERVICE_STARTUP_ENABLE_FLAG) ||
!object.at(EXTENSION_SERVICE_STARTUP_ENABLE_FLAG).is_boolean()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Service enable config not existed.");
return;
}
bool serviceEnableFlag = object.at(EXTENSION_SERVICE_STARTUP_ENABLE_FLAG).get<bool>();
if (!serviceEnableFlag) {
serviceEnableFlags_[extensionTypeName] = serviceEnableFlag;
TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s Service startup is blocked.", extensionTypeName.c_str());
return;
}
if (!object.contains(EXTENSION_SERVICE_BLOCKED_LIST_NAME) ||
!object.at(EXTENSION_SERVICE_BLOCKED_LIST_NAME).is_array()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Service config not existed.");

View File

@ -17,6 +17,7 @@
#include "ability_info.h"
#include "ability_util.h"
#include "app_scheduler.h"
#include "extension_config.h"
#include "hilog_tag_wrapper.h"
#include "start_ability_utils.h"
@ -29,45 +30,56 @@ constexpr char STRICT_MODE[] = "strictMode";
ErrCode ExtensionControlInterceptor::DoProcess(AbilityInterceptorParam param)
{
TAG_LOGE(AAFwkTag::ABILITYMGR, "call.");
if (!param.want.GetBoolParam(STRICT_MODE, false)) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "call.");
if (param.callerToken == nullptr) {
TAG_LOGD(AAFwkTag::ABILITYMGR, "callerToken is nullptr.");
return ERR_OK;
}
// get caller ability info
AppExecFwk::AbilityInfo callerAbilityInfo;
if (StartAbilityUtils::GetCallerAbilityInfo(param.callerToken, callerAbilityInfo)) {
if (callerAbilityInfo.type != AppExecFwk::AbilityType::EXTENSION ||
callerAbilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE ||
callerAbilityInfo.bundleName == param.want.GetElement().GetBundleName()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "not other extension.");
TAG_LOGD(AAFwkTag::ABILITYMGR, "not other extension.");
return ERR_OK;
}
// get target application info
AppExecFwk::AbilityInfo targetAbilityInfo;
if (StartAbilityUtils::startAbilityInfo != nullptr) {
targetAbilityInfo = StartAbilityUtils::startAbilityInfo->abilityInfo;
} else {
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
if (bundleMgrHelper == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The bundleMgrHelper is nullptr.");
auto appScheduler = DelayedSingleton<AppScheduler>::GetInstance();
AppExecFwk::RunningProcessInfo processInfo;
if (appScheduler != nullptr) {
appScheduler->GetRunningProcessInfoByToken(param.callerToken, processInfo);
if (!processInfo.isStrictMode && !param.want.GetBoolParam(STRICT_MODE, false)) {
return ERR_OK;
}
IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->QueryAbilityInfo(param.want,
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, param.userId, targetAbilityInfo));
}
// check blocked list
if (!targetAbilityInfo.applicationInfo.isSystemApp &&
!DelayedSingleton<ExtensionConfig>::GetInstance()->IsExtensionStartThirdPartyAppEnable(
callerAbilityInfo.extensionTypeName)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The extension start has been blocked by third party app flag.");
return EXTENSION_BLOCKED_BY_THIRD_PARTY_APP_FLAG;
}
if (targetAbilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE &&
!DelayedSingleton<ExtensionConfig>::GetInstance()->IsExtensionStartServiceEnable(
callerAbilityInfo.extensionTypeName, param.want.GetElement().GetURI())) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The extension start has been blocked by service list.");
return EXTENSION_BLOCKED_BY_SERVICE_LIST;
}
}
// get target ability info
AppExecFwk::AbilityInfo targetAbilityInfo;
if (StartAbilityUtils::startAbilityInfo != nullptr) {
targetAbilityInfo = StartAbilityUtils::startAbilityInfo->abilityInfo;
} else {
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
if (bundleMgrHelper == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The bundleMgrHelper is nullptr.");
return ERR_OK;
}
IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->QueryAbilityInfo(param.want,
AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, param.userId, targetAbilityInfo));
}
// check blocked list
if (!targetAbilityInfo.applicationInfo.isSystemApp &&
!DelayedSingleton<ExtensionConfig>::GetInstance()->IsExtensionStartThirdPartyAppEnable(
callerAbilityInfo.extensionTypeName)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The extension start has been blocked by third party app flag.");
return EXTENSION_BLOCKED_BY_THIRD_PARTY_APP_FLAG;
}
if (targetAbilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE &&
!DelayedSingleton<ExtensionConfig>::GetInstance()->IsExtensionStartServiceEnable(
callerAbilityInfo.extensionTypeName, param.want.GetElement().GetURI())) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "The extension start has been blocked by service list.");
return EXTENSION_BLOCKED_BY_SERVICE_LIST;
}
TAG_LOGI(AAFwkTag::ABILITYMGR, "other ok.");
return ERR_OK;
}

View File

@ -795,6 +795,16 @@ public:
pid_t GetGPUPid();
void ScheduleCacheProcess();
inline void SetStrictMode(bool strictMode)
{
isStrictMode_ = strictMode;
}
inline bool IsStrictMode()
{
return isStrictMode_;
}
private:
/**
* SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data.
@ -954,6 +964,7 @@ private:
sptr<IRemoteObject> browserHost_;
bool isGPU_ = false;
pid_t gpuPid_ = 0;
bool isStrictMode_ = false;
};
} // namespace AppExecFwk

View File

@ -715,6 +715,7 @@ void AppMgrServiceInner::LoadAbilityNoAppRecord(const std::shared_ptr<AppRunning
(void)AbilityRuntime::StartupUtil::GetAppIndex(*want, bundleIndex);
}
bool strictMode = (want == nullptr) ? false : want->GetBoolParam(STRICT_MODE, false);
appRecord->SetStrictMode(strictMode);
int32_t maxChildProcess = 0;
PresetMaxChildProcess(abilityInfo, maxChildProcess);
StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord,

View File

@ -617,6 +617,7 @@ int32_t AppRunningManager::AssignRunningProcessInfoByAppRecord(
info.isTestMode = info.isTestProcess && system::GetBoolParameter(DEVELOPER_MODE_STATE, false);
info.extensionType_ = appRecord->GetExtensionType();
info.processType_ = appRecord->GetProcessType();
info.isStrictMode = appRecord->IsStrictMode();
auto appInfo = appRecord->GetApplicationInfo();
if (appInfo) {
info.bundleType = static_cast<int32_t>(appInfo->bundleType);