!11629 应用隐藏窗口启动

Merge pull request !11629 from YeXiao/master_dev
This commit is contained in:
openharmony_ci 2024-11-20 10:44:30 +00:00 committed by Gitee
commit a0a621ee62
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 130 additions and 1 deletions

View File

@ -25,6 +25,7 @@ enum class ProcessMode {
NEW_PROCESS_ATTACH_TO_PARENT = 1,
NEW_PROCESS_ATTACH_TO_STATUS_BAR_ITEM = 2,
ATTACH_TO_STATUS_BAR_ITEM = 3,
NEW_HIDDEN_PROCESS = 4,
NO_ATTACHMENT = 99,
END
};

View File

@ -146,6 +146,7 @@ abilityms_files = [
"src/utils/multi_app_utils.cpp",
"src/utils/multi_instance_utils.cpp",
"src/utils/start_ability_utils.cpp",
"src/utils/hidden_start_utils.cpp",
"src/utils/state_utils.cpp",
"src/utils/update_caller_info_util.cpp",
"src/utils/uri_utils.cpp",

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 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 OHOS_ABILITY_RUNTIME_HIDDEN_START_UTILS_H
#define OHOS_ABILITY_RUNTIME_HIDDEN_START_UTILS_H
#include "want.h"
#include "start_options.h"
namespace OHOS {
namespace AAFwk {
/**
* @class HiddenStartUtils
* provides hidden start utilities.
*/
class HiddenStartUtils final {
public:
static bool IsHiddenStart(const Want &want, const StartOptions &options);
static int32_t CheckHiddenStartSupported(const Want &want, const StartOptions &options);
};
}
}
#endif //OHOS_ABILITY_RUNTIME_HIDDEN_START_UTILS_H

View File

@ -68,6 +68,7 @@
#include "softbus_bus_center.h"
#include "start_ability_handler/start_ability_sandbox_savefile.h"
#include "start_ability_utils.h"
#include "hidden_start_utils.h"
#include "startup_util.h"
#include "status_bar_delegate_interface.h"
#include "string_wrapper.h"
@ -1595,7 +1596,14 @@ int AbilityManagerService::StartUIAbilityForOptionWrap(const Want &want, const S
bool isCallByShortcut)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
auto ret = CheckProcessOptions(want, options, userId);
int32_t ret = ERR_OK;
if (HiddenStartUtils::IsHiddenStart(want, options)) {
ret = HiddenStartUtils::CheckHiddenStartSupported(want, options);
} else {
ret = CheckProcessOptions(want, options, userId);
}
if (ret != ERR_OK) {
return ret;
}

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2024 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 "hidden_start_utils.h"
#include "ability_manager_errors.h"
#include "app_mgr_util.h"
#include "app_utils.h"
#include "process_options.h"
#include "permission_verification.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AAFwk {
namespace {
constexpr const char* APP_TURBO_SERVICE = "app_turbo_service";
}
bool HiddenStartUtils::IsHiddenStart(const Want &want, const StartOptions &options)
{
if (!PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(APP_TURBO_SERVICE)) {
return false;
}
if (options.processOptions == nullptr) {
return false;
}
if (options.processOptions->startupVisibility != OHOS::AAFwk::StartupVisibility::STARTUP_HIDE) {
return false;
}
return true;
}
int32_t HiddenStartUtils::CheckHiddenStartSupported(const Want &want, const StartOptions &options)
{
if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "start ability silently is not supported in this device");
return ERR_NOT_SUPPORTED_PRODUCT_TYPE;
}
if (options.processOptions == nullptr ||
options.processOptions->processMode != ProcessMode::NEW_HIDDEN_PROCESS) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "this processMode is not supported in hidden start");
return ERR_INVALID_VALUE;
}
std::string bundleName = want.GetElement().GetBundleName();
bool isRunning = false;
auto appMgr = AppMgrUtil::GetAppMgr();
if (appMgr == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
return ERR_INVALID_VALUE;
}
auto result = appMgr->IsAppRunning(bundleName, 0, isRunning);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Query for app running failed, error code: %{public}d", result);
return result;
}
if (isRunning) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "ability is running now");
return ERR_ABILITY_ALREADY_RUNNING;
}
return ERR_OK;
}
}
}