feat: add kia permission

Signed-off-by: yangxuguang-huawei <yangxuguang3@huawei.com>
This commit is contained in:
yangxuguang-huawei 2024-09-27 16:28:14 +08:00
parent 39e30d75ea
commit 128fab851d
21 changed files with 1492 additions and 6 deletions

View File

@ -981,6 +981,7 @@ napi_value JsApplicationContextUtils::OnGetAllRunningInstanceKeys(napi_env env,
return;
}
if (context->GetCurrentAppMode() != static_cast<int32_t>(AppExecFwk::MultiAppModeType::MULTI_INSTANCE)) {
TAG_LOGE(AAFwkTag::APPKIT, "multi-instance not supported");
*innerErrCode = static_cast<int>(AbilityErrorCode::ERROR_MULTI_INSTANCE_NOT_SUPPORTED);
return;
}
@ -990,7 +991,8 @@ napi_value JsApplicationContextUtils::OnGetAllRunningInstanceKeys(napi_env env,
auto complete = [applicationContext = applicationContext_, innerErrCode, instanceKeys](
napi_env env, NapiAsyncTask& task, int32_t status) {
if (*innerErrCode != ERR_OK) {
task.Reject(env, CreateJsError(env, *innerErrCode, "failed to get instance keys."));
TAG_LOGE(AAFwkTag::APPKIT, "failed to get instance keys,innerErrCode=%{public}d", *innerErrCode);
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode));
return;
}
task.ResolveWithNoError(env, CreateNativeArray(env, *instanceKeys));

View File

@ -236,7 +236,6 @@ constexpr const char* ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId";
constexpr const char* PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task";
constexpr const char* KILL_PROCESS_REASON_PREFIX = "Kill Reason:";
constexpr const char* PRELOAD_APPLIATION_TASK = "PreloadApplicactionTask";
constexpr int32_t FILE_GUARD_UID = 6266;
constexpr const char* KEY_WATERMARK_BUSINESS_NAME = "com.ohos.param.watermarkBusinessName";
constexpr const char* KEY_IS_WATERMARK_ENABLED = "com.ohos.param.isWatermarkEnabled";
@ -8057,8 +8056,9 @@ int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bund
int AppMgrServiceInner::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
if (IPCSkeleton::GetCallingUid() != FILE_GUARD_UID) {
TAG_LOGE(AAFwkTag::APPMGR, "only open to file guard.");
if (!AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation() ||
!AAFwk::PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission()) {
TAG_LOGE(AAFwkTag::APPMGR, "no kia permission.");
return ERR_PERMISSION_DENIED;
}
if (interceptor == nullptr) {
@ -8072,8 +8072,9 @@ int AppMgrServiceInner::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &inte
int32_t AppMgrServiceInner::CheckIsKiaProcess(pid_t pid, bool &isKia)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
if (IPCSkeleton::GetCallingUid() != FILE_GUARD_UID) {
TAG_LOGE(AAFwkTag::APPMGR, "only open to file guard.");
if (!AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation() ||
!AAFwk::PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission()) {
TAG_LOGE(AAFwkTag::APPMGR, "no kia permission.");
return ERR_PERMISSION_DENIED;
}
if (!appRunningManager_) {

View File

@ -65,6 +65,7 @@ constexpr const char* PERMISSION_KILL_PROCESS_DEPENDED_ON_WEB = "ohos.permission
constexpr const char* PERMISSION_START_NATIVE_CHILD_PROCESS = "ohos.permission.START_NATIVE_CHILD_PROCESS";
constexpr const char* PERMISSION_BLOCK_ALL_APP_START = "ohos.permission.BLOCK_ALL_APP_START";
constexpr const char* PERMISSION_START_UIABILITY_TO_HIDDEN = "ohos.permission.START_UIABILITY_TO_HIDDEN";
constexpr const char* PERMISSION_SUPERVISE_KIA_SERVICE = "ohos.permission.SUPERVISE_KIA_SERVICE";
} // namespace PermissionConstants
} // namespace AAFwk
} // namespace OHOS

View File

@ -115,6 +115,8 @@ struct VerificationInfo {
bool VerifyStartUIAbilityToHiddenPermission() const;
bool VerifySuperviseKiaServicePermission() const;
private:
DISALLOW_COPY_AND_MOVE(PermissionVerification);

View File

@ -553,5 +553,15 @@ bool PermissionVerification::VerifyStartUIAbilityToHiddenPermission() const
TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied");
return false;
}
bool PermissionVerification::VerifySuperviseKiaServicePermission() const
{
if (IsSACall() && VerifyCallingPermission(PermissionConstants::PERMISSION_SUPERVISE_KIA_SERVICE)) {
TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted");
return true;
}
TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied");
return false;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -409,6 +409,7 @@ group("unittest") {
"app_mgr_service_dump_ipc_test:unittest",
"app_mgr_service_dump_test:unittest",
"app_mgr_service_event_handler_test:unittest",
"app_mgr_service_inner_mock_test:unittest",
"app_mgr_service_inner_second_test:unittest",
"app_mgr_service_inner_tdd_test:unittest",
"app_mgr_service_inner_test:unittest",

View File

@ -0,0 +1,67 @@
# 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.
import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/appmgrservice"
ohos_unittest("app_mgr_service_inner_mock_test") {
module_out_path = module_output_path
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
blocklist = "../../cfi_blocklist.txt"
}
branch_protector_ret = "pac_ret"
include_dirs = [
"include/",
"${ability_runtime_innerkits_path}/ability_manager/include",
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_services_path}/common/include",
]
sources = [
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/kia_interceptor_proxy.cpp",
"${ability_runtime_innerkits_path}/app_manager/src/appmgr/kia_interceptor_stub.cpp",
"app_mgr_service_inner_mock_test.cpp",
"src/app_utils.cpp",
"src/mock_app_mgr_service_inner.cpp",
"src/mock_kia_interceptor_impl.cpp",
"src/permission_verification.cpp",
"src/window_manager.cpp",
]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_base:zuri",
"c_utils:utils",
"ffrt:libffrt",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
]
defines = [ "INCLUDE_ZURI" ]
}
group("unittest") {
testonly = true
deps = [ ":app_mgr_service_inner_mock_test" ]
}

View File

@ -0,0 +1,793 @@
/*
* 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 <gtest/gtest.h>
#include "ability_manager_errors.h"
#include "app_running_record.h"
#include "app_utils.h"
#include "hilog_tag_wrapper.h"
#include "mock_app_mgr_service_inner.h"
#include "mock_kia_interceptor_impl.h"
#include "permission_verification.h"
#include "window_manager.h"
using namespace testing;
using namespace testing::ext;
using namespace OHOS::AAFwk;
namespace OHOS {
namespace AppExecFwk {
class AppMgrServiceInnerMockTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void AppMgrServiceInnerMockTest::SetUpTestCase() {}
void AppMgrServiceInnerMockTest::TearDownTestCase() {}
void AppMgrServiceInnerMockTest::SetUp() {}
void AppMgrServiceInnerMockTest::TearDown() {}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_001
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_001 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
serviceInner_->kiaInterceptor_ = new (std::nothrow) MockKiaInterceptorImpl();
EXPECT_NE(serviceInner_->kiaInterceptor_, nullptr);
MockKiaInterceptorImpl::onInterceptRetCode = 0;
MockKiaInterceptorImpl::kiaWatermarkBusinessName = "watermark";
MockKiaInterceptorImpl::isWatermarkEnabled = true;
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto want = std::make_shared<AAFwk::Want>();
EXPECT_NE(want, nullptr);
want->SetUri("file://kia-file-uri");
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(want, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, true);
EXPECT_EQ(isFileUri, true);
EXPECT_EQ(watermarkBusinessName, "watermark");
EXPECT_EQ(isWatermarkEnabled, true);
EXPECT_EQ(processName, "process_KIA");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_001 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_002
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_002 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = false;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), false);
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(nullptr, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, false);
EXPECT_EQ(watermarkBusinessName.empty(), true);
EXPECT_EQ(isWatermarkEnabled, false);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_002 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_003
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_003, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_003 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(nullptr, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_INVALID_VALUE);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, false);
EXPECT_EQ(watermarkBusinessName.empty(), true);
EXPECT_EQ(isWatermarkEnabled, false);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_002 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_004
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_004, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_004 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
serviceInner_->kiaInterceptor_ = new (std::nothrow) MockKiaInterceptorImpl();
EXPECT_NE(serviceInner_->kiaInterceptor_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto want = std::make_shared<AAFwk::Want>();
EXPECT_NE(want, nullptr);
want->SetUri("not-kia-file-uri");
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(want, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, false);
EXPECT_EQ(watermarkBusinessName.empty(), true);
EXPECT_EQ(isWatermarkEnabled, false);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_004 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_005
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_005, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_005 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
serviceInner_->kiaInterceptor_ = nullptr;
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto want = std::make_shared<AAFwk::Want>();
EXPECT_NE(want, nullptr);
want->SetUri("file://kia-file-uri");
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(want, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, true);
EXPECT_EQ(watermarkBusinessName.empty(), true);
EXPECT_EQ(isWatermarkEnabled, false);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_005 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_006
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_006, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_006 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
serviceInner_->kiaInterceptor_ = new (std::nothrow) MockKiaInterceptorImpl();
EXPECT_NE(serviceInner_->kiaInterceptor_, nullptr);
MockKiaInterceptorImpl::onInterceptRetCode = -1;
MockKiaInterceptorImpl::kiaWatermarkBusinessName = "watermark";
MockKiaInterceptorImpl::isWatermarkEnabled = true;
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto want = std::make_shared<AAFwk::Want>();
EXPECT_NE(want, nullptr);
want->SetUri("file://kia-file-uri");
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(want, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, true);
EXPECT_EQ(watermarkBusinessName.empty(), true);
EXPECT_EQ(isWatermarkEnabled, false);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_006 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_007
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_007, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_007 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
serviceInner_->kiaInterceptor_ = new (std::nothrow) MockKiaInterceptorImpl();
EXPECT_NE(serviceInner_->kiaInterceptor_, nullptr);
MockKiaInterceptorImpl::onInterceptRetCode = 0;
MockKiaInterceptorImpl::kiaWatermarkBusinessName.clear();
MockKiaInterceptorImpl::isWatermarkEnabled = true;
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto want = std::make_shared<AAFwk::Want>();
EXPECT_NE(want, nullptr);
want->SetUri("file://kia-file-uri");
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(want, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, true);
EXPECT_EQ(watermarkBusinessName.empty(), true);
EXPECT_EQ(isWatermarkEnabled, true);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_007 end");
}
/*
* Feature: AppMgrServiceInner
* Name: MakeKiaProcess_008
* Function: MakeKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner MakeKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, MakeKiaProcess_008, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_008 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
serviceInner_->kiaInterceptor_ = new (std::nothrow) MockKiaInterceptorImpl();
EXPECT_NE(serviceInner_->kiaInterceptor_, nullptr);
MockKiaInterceptorImpl::onInterceptRetCode = 0;
MockKiaInterceptorImpl::kiaWatermarkBusinessName = "watermark";
MockKiaInterceptorImpl::isWatermarkEnabled = false;
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto want = std::make_shared<AAFwk::Want>();
EXPECT_NE(want, nullptr);
want->SetUri("file://kia-file-uri");
bool isKia = false;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
bool isFileUri = false;
std::string processName = "process";
auto retCode = serviceInner_->MakeKiaProcess(want, isKia, watermarkBusinessName,
isWatermarkEnabled, isFileUri, processName);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, false);
EXPECT_EQ(isFileUri, true);
EXPECT_EQ(watermarkBusinessName, "watermark");
EXPECT_EQ(isWatermarkEnabled, false);
EXPECT_EQ(processName, "process");
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest MakeKiaProcess_008 end");
}
/*
* Feature: AppMgrServiceInner
* Name: ProcessKia_001
* Function: ProcessKia
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner ProcessKia
*/
HWTEST_F(AppMgrServiceInnerMockTest, ProcessKia_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_001 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto appRecord = std::make_shared<AppRunningRecord>();
EXPECT_NE(appRecord, nullptr);
appRecord->pid_ = 1000;
EXPECT_EQ(appRecord->GetPid(), 1000);
bool isKia = true;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
WindowManager::retCodeSetProcessWatermark = 0;
WindowManager::retCodeSkipSnapshotForAppProcess = 0;
auto retCode = serviceInner_->ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_001 end");
}
/*
* Feature: AppMgrServiceInner
* Name: ProcessKia_002
* Function: ProcessKia
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner ProcessKia
*/
HWTEST_F(AppMgrServiceInnerMockTest, ProcessKia_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_002 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = false;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), false);
auto retCode = serviceInner_->ProcessKia(false, nullptr, "", false);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_002 end");
}
/*
* Feature: AppMgrServiceInner
* Name: ProcessKia_003
* Function: ProcessKia
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner ProcessKia
*/
HWTEST_F(AppMgrServiceInnerMockTest, ProcessKia_003, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_003 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto retCode = serviceInner_->ProcessKia(false, nullptr, "", false);
EXPECT_EQ(retCode, ERR_OK);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_003 end");
}
/*
* Feature: AppMgrServiceInner
* Name: ProcessKia_004
* Function: ProcessKia
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner ProcessKia
*/
HWTEST_F(AppMgrServiceInnerMockTest, ProcessKia_004, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_004 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto retCode = serviceInner_->ProcessKia(true, nullptr, "", false);
EXPECT_EQ(retCode, ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_004 end");
}
/*
* Feature: AppMgrServiceInner
* Name: ProcessKia_005
* Function: ProcessKia
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner ProcessKia
*/
HWTEST_F(AppMgrServiceInnerMockTest, ProcessKia_005, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_005 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto appRecord = std::make_shared<AppRunningRecord>();
EXPECT_NE(appRecord, nullptr);
appRecord->pid_ = 1000;
EXPECT_EQ(appRecord->GetPid(), 1000);
bool isKia = true;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
WindowManager::retCodeSetProcessWatermark = -1;
auto retCode = serviceInner_->ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled);
EXPECT_EQ(retCode, -1);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_005 end");
}
/*
* Feature: AppMgrServiceInner
* Name: ProcessKia_006
* Function: ProcessKia
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner ProcessKia
*/
HWTEST_F(AppMgrServiceInnerMockTest, ProcessKia_006, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_006 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
auto appRecord = std::make_shared<AppRunningRecord>();
EXPECT_NE(appRecord, nullptr);
appRecord->pid_ = 1000;
EXPECT_EQ(appRecord->GetPid(), 1000);
bool isKia = true;
std::string watermarkBusinessName;
bool isWatermarkEnabled = false;
WindowManager::retCodeSetProcessWatermark = 0;
WindowManager::retCodeSkipSnapshotForAppProcess = -1;
auto retCode = serviceInner_->ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled);
EXPECT_EQ(retCode, -1);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest ProcessKia_006 end");
}
/*
* Feature: AppMgrServiceInner
* Name: RegisterKiaInterceptor_001
* Function: RegisterKiaInterceptor
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner RegisterKiaInterceptor
*/
HWTEST_F(AppMgrServiceInnerMockTest, RegisterKiaInterceptor_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_001 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = true;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), true);
sptr<IKiaInterceptor> kiaInterceptor = new (std::nothrow) MockKiaInterceptorImpl();
EXPECT_NE(kiaInterceptor, nullptr);
auto retCode = serviceInner_->RegisterKiaInterceptor(kiaInterceptor);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(serviceInner_->kiaInterceptor_, kiaInterceptor);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_001 end");
}
/*
* Feature: AppMgrServiceInner
* Name: RegisterKiaInterceptor_002
* Function: RegisterKiaInterceptor
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner RegisterKiaInterceptor
*/
HWTEST_F(AppMgrServiceInnerMockTest, RegisterKiaInterceptor_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_002 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = false;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), false);
auto retCode = serviceInner_->RegisterKiaInterceptor(nullptr);
EXPECT_EQ(retCode, ERR_PERMISSION_DENIED);
EXPECT_EQ(serviceInner_->kiaInterceptor_, nullptr);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_002 end");
}
/*
* Feature: AppMgrServiceInner
* Name: RegisterKiaInterceptor_003
* Function: RegisterKiaInterceptor
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner RegisterKiaInterceptor
*/
HWTEST_F(AppMgrServiceInnerMockTest, RegisterKiaInterceptor_003, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_003 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = 0;
auto retCode = serviceInner_->RegisterKiaInterceptor(nullptr);
EXPECT_EQ(retCode, ERR_PERMISSION_DENIED);
EXPECT_EQ(serviceInner_->kiaInterceptor_, nullptr);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_003 end");
}
/*
* Feature: AppMgrServiceInner
* Name: RegisterKiaInterceptor_004
* Function: RegisterKiaInterceptor
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner RegisterKiaInterceptor
*/
HWTEST_F(AppMgrServiceInnerMockTest, RegisterKiaInterceptor_004, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_004 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = false;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), false);
auto retCode = serviceInner_->RegisterKiaInterceptor(nullptr);
EXPECT_EQ(retCode, ERR_PERMISSION_DENIED);
EXPECT_EQ(serviceInner_->kiaInterceptor_, nullptr);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_004 end");
}
/*
* Feature: AppMgrServiceInner
* Name: RegisterKiaInterceptor_005
* Function: RegisterKiaInterceptor
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner RegisterKiaInterceptor
*/
HWTEST_F(AppMgrServiceInnerMockTest, RegisterKiaInterceptor_005, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_005 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = true;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), true);
auto retCode = serviceInner_->RegisterKiaInterceptor(nullptr);
EXPECT_EQ(retCode, ERR_INVALID_VALUE);
EXPECT_EQ(serviceInner_->kiaInterceptor_, nullptr);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest RegisterKiaInterceptor_005 end");
}
/*
* Feature: AppMgrServiceInner
* Name: CheckIsKiaProcess_001
* Function: CheckIsKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner CheckIsKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, CheckIsKiaProcess_001, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_001 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = true;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), true);
serviceInner_->appRunningManager_ = std::make_shared<AppRunningManager>();
EXPECT_NE(serviceInner_->appRunningManager_, nullptr);
serviceInner_->appRunningManager_->retCode_ = ERR_OK;
serviceInner_->appRunningManager_->isKia_ = true;
bool isKia = false;
auto retCode = serviceInner_->CheckIsKiaProcess(1000, isKia);
EXPECT_EQ(retCode, ERR_OK);
EXPECT_EQ(isKia, true);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_001 end");
}
/*
* Feature: AppMgrServiceInner
* Name: CheckIsKiaProcess_002
* Function: CheckIsKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner CheckIsKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, CheckIsKiaProcess_002, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_002 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = false;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), false);
bool isKia = false;
auto retCode = serviceInner_->CheckIsKiaProcess(1000, isKia);
EXPECT_EQ(retCode, ERR_PERMISSION_DENIED);
EXPECT_EQ(isKia, false);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_002 end");
}
/*
* Feature: AppMgrServiceInner
* Name: CheckIsKiaProcess_003
* Function: CheckIsKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner CheckIsKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, CheckIsKiaProcess_003, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_003 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = 0;
bool isKia = false;
auto retCode = serviceInner_->CheckIsKiaProcess(1000, isKia);
EXPECT_EQ(retCode, ERR_PERMISSION_DENIED);
EXPECT_EQ(isKia, false);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_003 end");
}
/*
* Feature: AppMgrServiceInner
* Name: CheckIsKiaProcess_004
* Function: CheckIsKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner CheckIsKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, CheckIsKiaProcess_004, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_004 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = false;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), false);
bool isKia = false;
auto retCode = serviceInner_->CheckIsKiaProcess(1000, isKia);
EXPECT_EQ(retCode, ERR_PERMISSION_DENIED);
EXPECT_EQ(isKia, false);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_004 end");
}
/*
* Feature: AppMgrServiceInner
* Name: CheckIsKiaProcess_005
* Function: CheckIsKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner CheckIsKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, CheckIsKiaProcess_005, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_005 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = true;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), true);
serviceInner_->appRunningManager_ = nullptr;
EXPECT_EQ(serviceInner_->appRunningManager_, nullptr);
bool isKia = false;
auto retCode = serviceInner_->CheckIsKiaProcess(1000, isKia);
EXPECT_EQ(retCode, ERR_INVALID_VALUE);
EXPECT_EQ(isKia, false);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_005 end");
}
/*
* Feature: AppMgrServiceInner
* Name: CheckIsKiaProcess_006
* Function: CheckIsKiaProcess
* SubFunction: NA
* FunctionPoints: AppMgrServiceInner CheckIsKiaProcess
*/
HWTEST_F(AppMgrServiceInnerMockTest, CheckIsKiaProcess_006, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_006 start");
auto serviceInner_ = std::make_shared<AppMgrServiceInner>();
EXPECT_NE(serviceInner_, nullptr);
AppUtils::isStartOptionsWithAnimation_ = true;
EXPECT_EQ(AppUtils::GetInstance().IsStartOptionsWithAnimation(), true);
PermissionVerification::flag = PermissionVerification::FLAG::IS_SA_CALL;
PermissionVerification::hasSuperviseKiaServicePermission = true;
EXPECT_EQ(PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission(), true);
serviceInner_->appRunningManager_ = std::make_shared<AppRunningManager>();
EXPECT_NE(serviceInner_->appRunningManager_, nullptr);
serviceInner_->appRunningManager_->retCode_ = -1;
bool isKia = false;
auto retCode = serviceInner_->CheckIsKiaProcess(1000, isKia);
EXPECT_EQ(retCode, -1);
EXPECT_EQ(isKia, false);
TAG_LOGI(AAFwkTag::TEST, "AppMgrServiceInnerMockTest CheckIsKiaProcess_006 end");
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2021-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_APP_RUNNING_MANAGER_H
#define OHOS_ABILITY_RUNTIME_APP_RUNNING_MANAGER_H
namespace OHOS {
namespace AppExecFwk {
class AppRunningManager {
public:
AppRunningManager() {}
virtual ~AppRunningManager() {}
inline int CheckIsKiaProcess(int pid, bool &isKia)
{
if (retCode_) {
return retCode_;
}
isKia = isKia_;
return retCode_;
}
int retCode_ = 0;
bool isKia_ = false;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_RUNNING_MANAGER_H

View File

@ -0,0 +1,42 @@
/*
* 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_APP_RUNNING_RECORD_H
#define OHOS_ABILITY_RUNTIME_APP_RUNNING_RECORD_H
#include <memory>
namespace OHOS {
namespace AppExecFwk {
/**
* @class AppRunningRecord
* Record app process info.
*/
class AppRunningRecord : public std::enable_shared_from_this<AppRunningRecord> {
public:
AppRunningRecord() = default;
virtual ~AppRunningRecord() = default;
inline int GetPid() const
{
return pid_;
}
int pid_ = -1;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_RUNNING_RECORD_H

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_APP_UTILS_H
#define OHOS_ABILITY_RUNTIME_APP_UTILS_H
#include "nocopyable.h"
namespace OHOS {
namespace AAFwk {
class AppUtils {
public:
static AppUtils &GetInstance();
static bool isStartOptionsWithAnimation_;
~AppUtils();
bool IsStartOptionsWithAnimation();
private:
AppUtils();
DISALLOW_COPY_AND_MOVE(AppUtils);
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_UTILS_H

View File

@ -0,0 +1,26 @@
/*
* 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_CONSTANTS_H
#define OHOS_ABILITY_RUNTIME_CONSTANTS_H
namespace OHOS {
namespace AppExecFwk {
const static char* KEY_WATERMARK_BUSINESS_NAME = "com.ohos.param.watermarkBusinessName";
const static char* KEY_IS_WATERMARK_ENABLED = "com.ohos.param.isWatermarkEnabled";
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_CONSTANTS_H

View File

@ -0,0 +1,59 @@
/*
* 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_APP_MGR_SERVICE_INNER_H
#define OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H
#include "app_running_manager.h"
#include "app_running_record.h"
#include "kia_interceptor_interface.h"
namespace OHOS {
namespace AppExecFwk {
/**
* @class AppMgrServiceInner
* AppMgrServiceInner provides a facility for managing ability life cycle.
*/
class AppMgrServiceInner : public std::enable_shared_from_this<AppMgrServiceInner> {
public:
AppMgrServiceInner() = default;
virtual ~AppMgrServiceInner() = default;
int32_t MakeKiaProcess(std::shared_ptr<AAFwk::Want> want, bool &isKia, std::string &watermarkBusinessName,
bool &isWatermarkEnabled, bool &isFileUri, std::string &processName);
int32_t ProcessKia(bool isKia, std::shared_ptr<AppRunningRecord> appRecord,
const std::string& watermarkBusinessName, bool isWatermarkEnabled);
/**
* Register KIA interceptor.
* @param interceptor KIA interceptor.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int32_t RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor);
/**
* Check if the given pid is a KIA process.
* @param pid process id.
* @return Returns true if it is a KIA process, false otherwise.
*/
virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia);
public:
sptr<IKiaInterceptor> kiaInterceptor_ = nullptr;
std::shared_ptr<AppRunningManager> appRunningManager_ = nullptr;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H

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_MOCK_KIA_INTERCEPTOR_IMPL_H
#define OHOS_ABILITY_RUNTIME_MOCK_KIA_INTERCEPTOR_IMPL_H
#include "kia_interceptor_stub.h"
#include <iremote_object.h>
#include <iremote_stub.h>
namespace OHOS {
namespace AppExecFwk {
class MockKiaInterceptorImpl : public KiaInterceptorStub {
public:
MockKiaInterceptorImpl() {}
virtual ~MockKiaInterceptorImpl() {}
static int onInterceptRetCode;
static std::string kiaWatermarkBusinessName;
static bool isWatermarkEnabled;
virtual int OnIntercept(AAFwk::Want &want) override;
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_MOCK_KIA_INTERCEPTOR_IMPL_H

View File

@ -0,0 +1,44 @@
/*
* 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.
*/
#ifndef OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H
#define OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H
#include "singleton.h"
namespace OHOS {
namespace AAFwk {
class PermissionVerification : public DelayedSingleton<PermissionVerification> {
public:
PermissionVerification() = default;
~PermissionVerification() = default;
enum FLAG {
IS_SA_CALL = 1,
};
static bool hasSuperviseKiaServicePermission;
static int flag;
bool IsSACall();
bool VerifySuperviseKiaServicePermission();
private:
DISALLOW_COPY_AND_MOVE(PermissionVerification);
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_PERMISSION_VERIFICATION_H

View File

@ -0,0 +1,47 @@
/*
* 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_WINDOW_MANAGER_H
#define OHOS_ABILITY_RUNTIME_WINDOW_MANAGER_H
#include <string>
#include "nocopyable.h"
namespace OHOS {
namespace AppExecFwk {
/**
* @class WindowManager
* Record app process info.
*/
class WindowManager {
public:
static WindowManager &GetInstance();
static int retCodeSetProcessWatermark;
static int retCodeSkipSnapshotForAppProcess;
virtual ~WindowManager() = default;
int SetProcessWatermark(int pid, const std::string& watermarkBusinessName, bool isWatermarkEnabled);
int SkipSnapshotForAppProcess(int pid, bool isWatermarkEnabled);
private:
WindowManager();
DISALLOW_COPY_AND_MOVE(WindowManager);
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_WINDOW_MANAGER_H

View File

@ -0,0 +1,40 @@
/*
* 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 "app_utils.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AAFwk {
bool AppUtils::isStartOptionsWithAnimation_ = false;
AppUtils::~AppUtils() {}
AppUtils::AppUtils() {}
AppUtils &AppUtils::GetInstance()
{
static AppUtils utils;
return utils;
}
bool AppUtils::IsStartOptionsWithAnimation()
{
TAG_LOGD(AAFwkTag::DEFAULT, "called %{public}d", isStartOptionsWithAnimation_);
return isStartOptionsWithAnimation_;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -0,0 +1,116 @@
/*
* 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 "mock_app_mgr_service_inner.h"
#include "ability_manager_errors.h"
#include "app_utils.h"
#include "constants.h"
#include "hilog_tag_wrapper.h"
#include "permission_verification.h"
#include "window_manager.h"
namespace OHOS {
namespace AppExecFwk {
int32_t AppMgrServiceInner::MakeKiaProcess(std::shared_ptr<AAFwk::Want> want, bool &isKia,
std::string &watermarkBusinessName, bool &isWatermarkEnabled,
bool &isFileUri, std::string &processName)
{
if (!AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation()) {
return ERR_OK;
}
if (want == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
return ERR_INVALID_VALUE;
}
#ifdef INCLUDE_ZURI
isFileUri = !want->GetUriString().empty() && want->GetUri().GetScheme() == "file";
#endif
if (isFileUri && kiaInterceptor_ != nullptr) {
auto resultCode = kiaInterceptor_->OnIntercept(*want);
watermarkBusinessName = want->GetStringParam(KEY_WATERMARK_BUSINESS_NAME);
isWatermarkEnabled = want->GetBoolParam(KEY_IS_WATERMARK_ENABLED, false);
TAG_LOGI(AAFwkTag::APPMGR, "After calling kiaInterceptor_->OnIntercept,"
"resultCode=%{public}d,watermarkBusinessName=%{private}s,isWatermarkEnabled=%{private}d",
resultCode, watermarkBusinessName.c_str(),
static_cast<int>(isWatermarkEnabled));
isKia = (resultCode == ERR_OK && !watermarkBusinessName.empty() && isWatermarkEnabled);
if (isKia) {
processName += "_KIA";
}
}
return ERR_OK;
}
int32_t AppMgrServiceInner::ProcessKia(bool isKia, std::shared_ptr<AppRunningRecord> appRecord,
const std::string& watermarkBusinessName, bool isWatermarkEnabled)
{
if (!AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation() || !isKia) {
return ERR_OK;
}
if (appRecord == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "appRecord is nullptr");
return ERR_INVALID_VALUE;
}
TAG_LOGI(AAFwkTag::APPMGR, "Openning KIA file, start setting watermark");
int32_t resultCode = static_cast<int32_t>(WindowManager::GetInstance().SetProcessWatermark(
appRecord->GetPid(), watermarkBusinessName, isWatermarkEnabled));
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "setting watermark fails with result code:%{public}d", resultCode);
return resultCode;
}
TAG_LOGI(AAFwkTag::APPMGR, "setting watermark succeeds, start setting snapshot skip");
resultCode = static_cast<int32_t>(WindowManager::GetInstance().SkipSnapshotForAppProcess(
appRecord->GetPid(), isWatermarkEnabled));
if (resultCode != ERR_OK) {
TAG_LOGE(AAFwkTag::APPMGR, "setting snapshot skip fails with result code:%{public}d", resultCode);
return resultCode;
}
TAG_LOGI(AAFwkTag::APPMGR, "setting snapshot skip succeeds");
return ERR_OK;
}
int AppMgrServiceInner::RegisterKiaInterceptor(const sptr<IKiaInterceptor> &interceptor)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
if (!AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation() ||
!AAFwk::PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission()) {
TAG_LOGE(AAFwkTag::APPMGR, "no kia permission.");
return ERR_PERMISSION_DENIED;
}
if (interceptor == nullptr) {
TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr.");
return ERR_INVALID_VALUE;
}
kiaInterceptor_ = interceptor;
return ERR_OK;
}
int32_t AppMgrServiceInner::CheckIsKiaProcess(pid_t pid, bool &isKia)
{
TAG_LOGI(AAFwkTag::APPMGR, "call");
if (!AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation() ||
!AAFwk::PermissionVerification::GetInstance()->VerifySuperviseKiaServicePermission()) {
TAG_LOGE(AAFwkTag::APPMGR, "no kia permission.");
return ERR_PERMISSION_DENIED;
}
if (!appRunningManager_) {
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr");
return ERR_INVALID_VALUE;
}
return appRunningManager_->CheckIsKiaProcess(pid, isKia);
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -0,0 +1,37 @@
/*
* 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 "mock_kia_interceptor_impl.h"
#include "constants.h"
namespace OHOS {
namespace AppExecFwk {
int MockKiaInterceptorImpl::onInterceptRetCode = 0;
std::string MockKiaInterceptorImpl::kiaWatermarkBusinessName;
bool MockKiaInterceptorImpl::isWatermarkEnabled = false;
int MockKiaInterceptorImpl::OnIntercept(AAFwk::Want &want)
{
if (onInterceptRetCode != 0) {
return onInterceptRetCode;
}
want.SetParam(KEY_WATERMARK_BUSINESS_NAME, kiaWatermarkBusinessName);
want.SetParam(KEY_IS_WATERMARK_ENABLED, isWatermarkEnabled);
return onInterceptRetCode;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -0,0 +1,40 @@
/*
* 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 "permission_verification.h"
#include "hilog_tag_wrapper.h"
namespace OHOS {
namespace AAFwk {
int PermissionVerification::flag = 0;
bool PermissionVerification::hasSuperviseKiaServicePermission = false;
bool PermissionVerification::IsSACall()
{
return (flag == FLAG::IS_SA_CALL);
}
bool PermissionVerification::VerifySuperviseKiaServicePermission()
{
if (IsSACall() && hasSuperviseKiaServicePermission) {
TAG_LOGD(AAFwkTag::DEFAULT, "Permission granted");
return true;
}
TAG_LOGE(AAFwkTag::DEFAULT, "Permission denied");
return false;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -0,0 +1,41 @@
/*
* 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 "window_manager.h"
namespace OHOS {
namespace AppExecFwk {
int WindowManager::retCodeSetProcessWatermark = 0;
int WindowManager::retCodeSkipSnapshotForAppProcess = 0;
WindowManager::WindowManager() {}
WindowManager &WindowManager::GetInstance()
{
static WindowManager windowManager_;
return windowManager_;
}
int WindowManager::SetProcessWatermark(int pid, const std::string& watermarkBusinessName, bool isWatermarkEnabled)
{
return retCodeSetProcessWatermark;
}
int WindowManager::SkipSnapshotForAppProcess(int pid, bool isWatermarkEnabled)
{
return retCodeSkipSnapshotForAppProcess;
}
} // namespace AppExecFwk
} // namespace OHOS