mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-12-04 05:22:25 +00:00
refactor: move GetRunningMultiAppIndex out of AMS
Signed-off-by: yangxuguang-huawei <yangxuguang3@huawei.com>
This commit is contained in:
parent
e667b0c53d
commit
a913bae203
@ -137,6 +137,7 @@ abilityms_files = [
|
||||
"src/utils/dump_utils.cpp",
|
||||
"src/utils/ability_permission_util.cpp",
|
||||
"src/utils/modal_system_dialog_util.cpp",
|
||||
"src/utils/multi_app_utils.cpp",
|
||||
"src/utils/multi_instance_utils.cpp",
|
||||
]
|
||||
|
||||
|
@ -2259,9 +2259,6 @@ private:
|
||||
int32_t SetBackgroundCall(const AppExecFwk::RunningProcessInfo &processInfo,
|
||||
const AbilityRequest &abilityRequest, bool &isBackgroundCall) const;
|
||||
|
||||
void GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex);
|
||||
ErrCode ConvertToExplicitWant(Want& want);
|
||||
|
||||
int CheckUIExtensionUsage(AppExecFwk::UIExtensionUsage uiExtensionUsage,
|
||||
AppExecFwk::ExtensionAbilityType extensionType);
|
||||
|
||||
|
29
services/abilitymgr/include/utils/multi_app_utils.h
Normal file
29
services/abilitymgr/include/utils/multi_app_utils.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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_MULTI_APP_UTILS_H
|
||||
#define OHOS_ABILITY_RUNTIME_MULTI_APP_UTILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class MultiAppUtils {
|
||||
public:
|
||||
static void GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex);
|
||||
};
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_MULTI_APP_UTILS_H
|
@ -51,6 +51,7 @@
|
||||
#include "mock_session_manager_service.h"
|
||||
#include "modal_system_dialog/modal_system_dialog_ui_extension.h"
|
||||
#include "modal_system_ui_extension.h"
|
||||
#include "multi_app_utils.h"
|
||||
#include "os_account_manager_wrapper.h"
|
||||
#include "permission_constants.h"
|
||||
#include "process_options.h"
|
||||
@ -4643,7 +4644,7 @@ sptr<IWantSender> AbilityManagerService::GetWantSender(
|
||||
if (!wantSenderInfo.allWants.empty()) {
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
std::string bundleName = wantSenderInfo.allWants.back().want.GetElement().GetBundleName();
|
||||
GetRunningMultiAppIndex(bundleName, callerUid, appIndex);
|
||||
MultiAppUtils::GetRunningMultiAppIndex(bundleName, callerUid, appIndex);
|
||||
if (!isSpecifyUidBySa) {
|
||||
bundleMgrResult = IN_PROCESS_CALL(bms->GetCloneBundleInfo(bundleName,
|
||||
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
|
||||
@ -11837,27 +11838,6 @@ int32_t AbilityManagerService::TransferAbilityResultForExtension(const sptr<IRem
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void AbilityManagerService::GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex)
|
||||
{
|
||||
AppExecFwk::RunningMultiAppInfo runningMultiAppInfo;
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
if (appMgr == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
|
||||
return;
|
||||
}
|
||||
auto ret = IN_PROCESS_CALL(appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo));
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "getAppInfo failed, bundle:%{public}s",
|
||||
bundleName.c_str());
|
||||
}
|
||||
for (auto &item : runningMultiAppInfo.runningAppClones) {
|
||||
if (item.uid == uid) {
|
||||
appIndex = item.appCloneIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AbilityManagerService::NotifyFrozenProcessByRSS(const std::vector<int32_t> &pidList, int32_t uid)
|
||||
{
|
||||
if (!PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(RSS_PROCESS_NAME)) {
|
||||
|
46
services/abilitymgr/src/utils/multi_app_utils.cpp
Normal file
46
services/abilitymgr/src/utils/multi_app_utils.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 "multi_app_utils.h"
|
||||
|
||||
#include "app_mgr_util.h"
|
||||
#include "hilog_tag_wrapper.h"
|
||||
#include "in_process_call_wrapper.h"
|
||||
#include "running_multi_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
void MultiAppUtils::GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex)
|
||||
{
|
||||
AppExecFwk::RunningMultiAppInfo runningMultiAppInfo;
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
if (appMgr == nullptr) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "AppMgrUtil::GetAppMgr failed");
|
||||
return;
|
||||
}
|
||||
auto ret = IN_PROCESS_CALL(appMgr->GetRunningMultiAppInfoByBundleName(bundleName, runningMultiAppInfo));
|
||||
if (ret != ERR_OK) {
|
||||
TAG_LOGW(AAFwkTag::ABILITYMGR, "getAppInfo failed, bundle:%{public}s",
|
||||
bundleName.c_str());
|
||||
}
|
||||
for (auto &item : runningMultiAppInfo.runningAppClones) {
|
||||
if (item.uid == uid) {
|
||||
appIndex = item.appCloneIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -535,6 +535,7 @@ group("unittest") {
|
||||
"mission_listener_proxy_test:unittest",
|
||||
"mission_listener_stub_test:unittest",
|
||||
"mission_listener_test:unittest",
|
||||
"multi_app_utils_test:unittest",
|
||||
"multi_instance_utils_test:unittest",
|
||||
"napi_base_context_test:unittest",
|
||||
"native_runtime_test:unittest",
|
||||
|
@ -2304,22 +2304,6 @@ HWTEST_F(AbilityManagerServiceThirdTest, NotifyFrozenProcessByRSS_001, TestSize.
|
||||
abilityMs_->NotifyFrozenProcessByRSS(pidList, UID);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: GetRunningMultiAppIndex
|
||||
* FunctionPoints: GetRunningMultiAppIndex
|
||||
*/
|
||||
HWTEST_F(AbilityManagerServiceThirdTest, GetRunningMultiAppIndex_001, TestSize.Level1)
|
||||
{
|
||||
auto abilityMs_ = std::make_shared<AbilityManagerService>();
|
||||
EXPECT_NE(abilityMs_, nullptr);
|
||||
|
||||
int32_t UID = 1000;
|
||||
int32_t APPINDEX = 28;
|
||||
abilityMs_->GetRunningMultiAppIndex("com.ix.hiservcie", UID, APPINDEX);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Feature: AbilityManagerService
|
||||
* Function: TransferAbilityResultForExtension
|
||||
|
68
test/unittest/multi_app_utils_test/BUILD.gn
Normal file
68
test/unittest/multi_app_utils_test/BUILD.gn
Normal file
@ -0,0 +1,68 @@
|
||||
# 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/abilitymgr"
|
||||
|
||||
ohos_unittest("multi_app_utils_test") {
|
||||
module_out_path = module_output_path
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
blocklist = "../../../test/cfi_blocklist.txt"
|
||||
}
|
||||
branch_protector_ret = "pac_ret"
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${ability_runtime_services_path}/abilitymgr/include/utils",
|
||||
"${ability_runtime_services_path}/abilitymgr/include",
|
||||
"${ability_runtime_services_path}/appmgr/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${ability_runtime_test_path}/mock/services_appmgr_test/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${ability_runtime_services_path}/abilitymgr/src/utils/multi_app_utils.cpp",
|
||||
"multi_app_utils_test.cpp",
|
||||
"src/mock_app_mgr_service.cpp",
|
||||
"src/mock_app_mgr_utils.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:app_manager",
|
||||
"appspawn:appspawn_client",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"ffrt:libffrt",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"ipc:ipc_core",
|
||||
"jsoncpp:jsoncpp",
|
||||
]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":multi_app_utils_test" ]
|
||||
}
|
@ -0,0 +1,273 @@
|
||||
/*
|
||||
* 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 MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_H
|
||||
#define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_H
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "semaphore_ex.h"
|
||||
#include "app_mgr_stub.h"
|
||||
#include "app_malloc_info.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
class MockAppMgrService : public AppMgrStub {
|
||||
public:
|
||||
MOCK_METHOD6(LoadAbility,
|
||||
void(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& preToken,
|
||||
const std::shared_ptr<AbilityInfo>& abilityInfo, const std::shared_ptr<ApplicationInfo>& appInfo,
|
||||
const std::shared_ptr<AAFwk::Want>& want, int32_t abilityRecordId));
|
||||
MOCK_METHOD2(TerminateAbility, void(const sptr<IRemoteObject>& token, bool clearMissionFlag));
|
||||
MOCK_METHOD2(UpdateAbilityState, void(const sptr<IRemoteObject>& token, const AbilityState state));
|
||||
MOCK_METHOD1(AttachApplication, void(const sptr<IRemoteObject>& app));
|
||||
MOCK_METHOD1(NotifyMemoryLevel, int(int32_t level));
|
||||
MOCK_METHOD1(NotifyProcMemoryLevel, int32_t(const std::map<pid_t, MemoryLevel> &procLevelMap));
|
||||
MOCK_METHOD2(DumpHeapMemory, int(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo));
|
||||
MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId));
|
||||
MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId));
|
||||
MOCK_METHOD1(ApplicationTerminated, void(const int32_t recordId));
|
||||
MOCK_METHOD1(AbilityCleaned, void(const sptr<IRemoteObject>& token));
|
||||
MOCK_METHOD2(UpdateApplicationInfoInstalled, int(const std::string&, const int uid));
|
||||
MOCK_METHOD2(KillApplication, int32_t(const std::string& appName, const bool clearPageStack));
|
||||
MOCK_METHOD3(ForceKillApplication, int32_t(const std::string& appName, const int userId, const int appIndex));
|
||||
MOCK_METHOD1(KillProcessesByAccessTokenId, int32_t(const uint32_t accessTokenId));
|
||||
MOCK_METHOD2(KillApplicationByUid, int(const std::string&, const int uid));
|
||||
MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string& bundleName));
|
||||
MOCK_METHOD1(GetAllRunningProcesses, int(std::vector<RunningProcessInfo>& info));
|
||||
MOCK_METHOD2(GetRunningProcessesByBundleType, int(const BundleType bundleType,
|
||||
std::vector<RunningProcessInfo>& info));
|
||||
MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector<RunningProcessInfo>& info, int32_t userId));
|
||||
MOCK_METHOD1(GetAllRenderProcesses, int(std::vector<RenderProcessInfo>& info));
|
||||
MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector<ChildProcessInfo>&));
|
||||
MOCK_METHOD0(GetAmsMgr, sptr<IAmsMgr>());
|
||||
MOCK_METHOD1(GetAppFreezingTime, void(int& time));
|
||||
MOCK_METHOD1(SetAppFreezingTime, void(int time));
|
||||
MOCK_METHOD3(ClearUpApplicationData, int32_t(const std::string& bundleName, int32_t appCloneIndex, int32_t userId));
|
||||
MOCK_METHOD1(ClearUpApplicationDataBySelf, int32_t(int32_t userId));
|
||||
MOCK_METHOD1(StartupResidentProcess, void(const std::vector<AppExecFwk::BundleInfo>& bundleInfos));
|
||||
MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId));
|
||||
MOCK_METHOD0(PreStartNWebSpawnProcess, int());
|
||||
MOCK_METHOD6(StartRenderProcess, int(const std::string&, int32_t, int32_t, int32_t, pid_t&, bool));
|
||||
MOCK_METHOD1(AttachRenderProcess, void(const sptr<IRemoteObject>& renderScheduler));
|
||||
MOCK_METHOD1(SaveBrowserChannel, void(sptr<IRemoteObject> browser));
|
||||
MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int& status));
|
||||
MOCK_METHOD2(RegisterApplicationStateObserver, int32_t(const sptr<IApplicationStateObserver>& observer,
|
||||
const std::vector<std::string>& bundleNameList));
|
||||
MOCK_METHOD1(UnregisterApplicationStateObserver, int32_t(const sptr<IApplicationStateObserver>& observer));
|
||||
MOCK_METHOD3(ScheduleAcceptWantDone,
|
||||
void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag));
|
||||
MOCK_METHOD3(ScheduleNewProcessRequestDone,
|
||||
void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag));
|
||||
MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector<sptr<IRemoteObject>>& tokens));
|
||||
MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config));
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD2(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
const sptr<IQuickFixCallback>& callback));
|
||||
MOCK_METHOD2(NotifyHotReloadPage, int32_t(const std::string& bundleName, const sptr<IQuickFixCallback>& callback));
|
||||
MOCK_METHOD2(NotifyUnLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
const sptr<IQuickFixCallback>& callback));
|
||||
MOCK_METHOD2(IsSharedBundleRunning, bool(const std::string &bundleName, uint32_t versionCode));
|
||||
MOCK_METHOD3(GetBundleNameByPid, int32_t(const int pid, std::string &bundleName, int32_t &uid));
|
||||
|
||||
MOCK_METHOD1(NotifyAppFault, int32_t(const FaultData &faultData));
|
||||
MOCK_METHOD1(NotifyAppFaultBySA, int32_t(const AppFaultDataBySA &faultData));
|
||||
MOCK_METHOD2(GetProcessMemoryByPid, int32_t(const int32_t pid, int32_t & memorySize));
|
||||
MOCK_METHOD3(GetRunningProcessInformation, int32_t(const std::string & bundleName, int32_t userId,
|
||||
std::vector<RunningProcessInfo> &info));
|
||||
MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector<std::string> &instanceKeys));
|
||||
MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName,
|
||||
std::vector<std::string> &instanceKeys, int32_t userId));
|
||||
MOCK_METHOD2(IsApplicationRunning, int32_t(const std::string &bundleName, bool &isRunning));
|
||||
MOCK_METHOD3(IsAppRunning, int32_t(const std::string &bundleName,
|
||||
int32_t appCloneIndex, bool &isRunning));
|
||||
MOCK_METHOD2(StartChildProcess, int32_t(pid_t &childPid, const ChildProcessRequest &request));
|
||||
MOCK_METHOD1(GetChildProcessInfoForSelf, int32_t(ChildProcessInfo &info));
|
||||
MOCK_METHOD1(AttachChildProcess, void(const sptr<IRemoteObject> &childScheduler));
|
||||
MOCK_METHOD0(ExitChildProcessSafely, void());
|
||||
MOCK_METHOD1(RegisterRenderStateObserver, int32_t(const sptr<IRenderStateObserver> &observer));
|
||||
MOCK_METHOD1(UnregisterRenderStateObserver, int32_t(const sptr<IRenderStateObserver> &observer));
|
||||
MOCK_METHOD2(UpdateRenderState, int32_t(pid_t renderPid, int32_t state));
|
||||
|
||||
MOCK_METHOD0(IsFinalAppProcess, bool());
|
||||
MOCK_METHOD1(SetSupportedProcessCacheSelf, int32_t(bool isSupport));
|
||||
MOCK_METHOD2(SetSupportedProcessCache, int32_t(int32_t pid, bool isSupport));
|
||||
MOCK_METHOD3(StartNativeChildProcess, int32_t(const std::string &libName, int32_t childProcessCount,
|
||||
const sptr<IRemoteObject> &callback));
|
||||
MOCK_METHOD2(GetSupportedProcessCachePids, int32_t(const std::string &bundleName,
|
||||
std::vector<int32_t> &pidList));
|
||||
|
||||
MOCK_METHOD1(RegisterKiaInterceptor, int32_t(const sptr<IKiaInterceptor> &interceptor));
|
||||
MOCK_METHOD2(CheckIsKiaProcess, int32_t(pid_t pid, bool &isKia));
|
||||
virtual int StartUserTestProcess(
|
||||
const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t RegisterAppForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t RegisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t UnregisterAppForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t UnregisterAbilityForegroundStateObserver(const sptr<IAbilityForegroundStateObserver> &observer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t RegisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t UnregisterAppForegroundStateObserver(const sptr<IAppForegroundStateObserver> &observer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t StartNativeProcessForDebugger(const AAFwk::Want &want) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int FinishUserTest(const std::string& msg, const int64_t& resultCode, const std::string& bundleName)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int GetProcessRunningInformation(RunningProcessInfo &info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void RegisterAppStateCallback(const sptr<IAppStateCallback>& callback)
|
||||
{
|
||||
callback_ = callback;
|
||||
}
|
||||
|
||||
int32_t CheckPermissionImpl([[maybe_unused]] const int32_t recordId, const std::string& data)
|
||||
{
|
||||
data_ = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int32_t JudgeSandboxByPid(pid_t pid, bool &isSandbox)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void KillApplicationImpl(const std::string& data)
|
||||
{
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
const std::string& GetData() const
|
||||
{
|
||||
return data_;
|
||||
}
|
||||
|
||||
void Wait()
|
||||
{
|
||||
sem_.Wait();
|
||||
}
|
||||
|
||||
void Post()
|
||||
{
|
||||
sem_.Post();
|
||||
}
|
||||
|
||||
void UpdateState() const
|
||||
{
|
||||
if (!callback_) {
|
||||
return;
|
||||
}
|
||||
AppProcessData processData;
|
||||
processData.pid = 1;
|
||||
processData.appState = ApplicationState::APP_STATE_CREATE;
|
||||
callback_->OnAppStateChanged(processData);
|
||||
}
|
||||
|
||||
void Terminate(const sptr<IRemoteObject>& token) const
|
||||
{
|
||||
if (!callback_) {
|
||||
return;
|
||||
}
|
||||
AbilityState st = AbilityState::ABILITY_STATE_CREATE;
|
||||
callback_->OnAbilityRequestDone(token, st);
|
||||
}
|
||||
|
||||
MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel&, MessageParcel&, MessageOption&));
|
||||
|
||||
int InvokeSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
code_ = code;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int code_;
|
||||
|
||||
virtual bool SetAppFreezeFilter(int32_t pid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual int32_t ChangeAppGcState(pid_t pid, int32_t state)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t RegisterAppRunningStatusListener(const sptr<IRemoteObject> &listener)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t UnregisterAppRunningStatusListener(const sptr<IRemoteObject> &listener)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t GetRunningMultiAppInfoByBundleName(const std::string &bundleName,
|
||||
RunningMultiAppInfo &info) override;
|
||||
|
||||
static int32_t retCode_;
|
||||
static RunningMultiAppInfo retInfo_;
|
||||
|
||||
private:
|
||||
Semaphore sem_;
|
||||
std::string data_;
|
||||
sptr<IAppStateCallback> callback_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_H
|
91
test/unittest/multi_app_utils_test/multi_app_utils_test.cpp
Normal file
91
test/unittest/multi_app_utils_test/multi_app_utils_test.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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 "hilog_tag_wrapper.h"
|
||||
#include "app_mgr_util.h"
|
||||
#include "mock_app_mgr_service.h"
|
||||
#include "multi_app_utils.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
class MultiAppUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
|
||||
void MultiAppUtilsTest::SetUpTestCase(void) {}
|
||||
void MultiAppUtilsTest::TearDownTestCase(void) {}
|
||||
void MultiAppUtilsTest::SetUp() {}
|
||||
void MultiAppUtilsTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: GetRunningMultiAppIndex_0100
|
||||
* @tc.desc: GetRunningMultiAppIndex
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NA
|
||||
*/
|
||||
HWTEST_F(MultiAppUtilsTest, GetRunningMultiAppIndex_0100, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppIndex_0100 start");
|
||||
std::string bundleName = "testBundleName";
|
||||
int32_t uid = 1000;
|
||||
int32_t appIndex = -1;
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
EXPECT_NE(appMgr, nullptr);
|
||||
|
||||
AppExecFwk::MockAppMgrService::retCode_ = 0;
|
||||
AppExecFwk::RunningAppClone appClone = {
|
||||
.appCloneIndex = 13,
|
||||
.uid = 1000
|
||||
};
|
||||
std::vector<AppExecFwk::RunningAppClone> appClones = { appClone };
|
||||
AppExecFwk::MockAppMgrService::retInfo_.runningAppClones = appClones;
|
||||
MultiAppUtils::GetRunningMultiAppIndex(bundleName, uid, appIndex);
|
||||
EXPECT_EQ(appIndex, 13);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppIndex_0100 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetRunningMultiAppIndex_0200
|
||||
* @tc.desc: GetRunningMultiAppIndex
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: NA
|
||||
*/
|
||||
HWTEST_F(MultiAppUtilsTest, GetRunningMultiAppIndex_0200, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppIndex_0200 start");
|
||||
std::string bundleName = "testBundleName";
|
||||
int32_t uid = 1000;
|
||||
int32_t appIndex = -1;
|
||||
auto appMgr = AppMgrUtil::GetAppMgr();
|
||||
EXPECT_NE(appMgr, nullptr);
|
||||
|
||||
AppExecFwk::MockAppMgrService::retCode_ = -1;
|
||||
MultiAppUtils::GetRunningMultiAppIndex(bundleName, uid, appIndex);
|
||||
EXPECT_EQ(appIndex, -1);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppIndex_0200 end");
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
int32_t MockAppMgrService::retCode_ = 0;
|
||||
RunningMultiAppInfo MockAppMgrService::retInfo_;
|
||||
|
||||
int32_t MockAppMgrService::GetRunningMultiAppInfoByBundleName(const std::string &bundleName,
|
||||
RunningMultiAppInfo &info)
|
||||
{
|
||||
if (retCode_ != 0) {
|
||||
return retCode_;
|
||||
}
|
||||
|
||||
info = retInfo_;
|
||||
return 0;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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_mgr_util.h"
|
||||
|
||||
#include "mock_app_mgr_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AAFwk {
|
||||
sptr<OHOS::AppExecFwk::IAppMgr> AppMgrUtil::appMgr_ = nullptr;
|
||||
|
||||
OHOS::sptr<AppExecFwk::IAppMgr> AppMgrUtil::GetAppMgr()
|
||||
{
|
||||
if (appMgr_) {
|
||||
return appMgr_;
|
||||
}
|
||||
|
||||
sptr<AppExecFwk::MockAppMgrService> mockAppMgr(new AppExecFwk::MockAppMgrService());
|
||||
appMgr_ = iface_cast<AppExecFwk::IAppMgr>(mockAppMgr);
|
||||
return appMgr_;
|
||||
}
|
||||
} // namespace AAFwk
|
||||
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user