!8965 abilityruntime解耦rss

Merge pull request !8965 from savior-xzh/rss
This commit is contained in:
openharmony_ci 2024-06-17 12:14:14 +00:00 committed by Gitee
commit 59bbbcc0df
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
30 changed files with 398 additions and 378 deletions

View File

@ -97,7 +97,6 @@ declare_args() {
ability_runtime_ces = true
ability_runtime_resource = true
ability_runtime_appspawn = true
efficiency_manager = true
ability_fault_and_exit_test = false
ability_command_for_test = false
ability_runtime_feature_coverage = false
@ -130,11 +129,6 @@ declare_args() {
ability_runtime_power = false
}
if (defined(global_parts_info) &&
!defined(global_parts_info.resourceschedule_efficiency_manager)) {
efficiency_manager = false
}
if (defined(global_parts_info) &&
!defined(global_parts_info.distributeddatamgr_relational_store)) {
ability_runtime_relational = false

View File

@ -50,7 +50,6 @@
"data_share",
"dlp_permission_service",
"dsoftbus",
"efficiency_manager",
"eventhandler",
"ets_runtime",
"ets_utils",

View File

@ -315,11 +315,6 @@ ohos_shared_library("abilitykit_native") {
defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ]
}
if (efficiency_manager) {
external_deps += [ "efficiency_manager:suspend_manager_client" ]
defines += [ "EFFICIENCY_MANAGER_ENABLE" ]
}
public_deps = [
":abilitykit_utils",
":extensionkit_native",

View File

@ -76,10 +76,6 @@ config("abilityms_config") {
defines += [ "RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
}
if (efficiency_manager) {
defines += [ "EFFICIENCY_MANAGER_ENABLE" ]
}
if (is_asan || asan_detector) {
defines += [ "SUPPORT_ASAN" ]
}
@ -127,6 +123,7 @@ ohos_shared_library("abilityms") {
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
]
@ -177,10 +174,6 @@ ohos_shared_library("abilityms") {
external_deps += [ "resource_schedule_service:ressched_client" ]
}
if (efficiency_manager) {
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (os_dlp_part_enabled) {
cflags_cc += [ "-DWITH_DLP" ]
external_deps += [ "dlp_permission_service:libdlp_permission_sdk" ]

View File

@ -142,7 +142,3 @@ if (ability_runtime_graphics) {
"src/screen_lock/unlock_screen_callback.cpp",
]
}
if (efficiency_manager) {
abilityms_files += [ "src/process_frozen_state_observer.cpp" ]
}

View File

@ -1557,8 +1557,6 @@ public:
*/
virtual bool IsAbilityControllerStart(const Want &want) override;
void HandleProcessFrozen(const std::vector<int32_t> &pidList, int32_t uid);
/**
* @brief Called when insight intent execute finished.
*
@ -1963,11 +1961,11 @@ private:
void UnsubscribeBundleEventCallback();
void ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo);
void ReportAbilitAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo, int64_t type,
const sptr<IRemoteObject> &callerToken);
void ReportEventToSuspendManager(const AppExecFwk::AbilityInfo &abilityInfo);
void RegisterSuspendObserver();
void ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo);
void ReportAppRecoverResult(const int32_t appId, const AppExecFwk::ApplicationInfo &appInfo,
const std::string& abilityName, const std::string& result);

View File

@ -534,9 +534,6 @@ private:
void SendKeyEvent(const AbilityRequest &abilityRequest);
void ReportAbilitAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo, int64_t type,
const std::shared_ptr<AbilityRecord> &callerAbility);
int userId_;
mutable ffrt::mutex managerLock_;
// launcher list is also in currentMissionLists_

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2023 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_PROCESS_FROZEN_STATE_OBSERVER_H
#define OHOS_ABILITY_RUNTIME_PROCESS_FROZEN_STATE_OBSERVER_H
#include <cstdint>
#include <memory>
#include <vector>
#include "suspend_state_observer_stub.h"
#include "task_handler_wrap.h"
namespace OHOS {
namespace AAFwk {
class ProcessFrozenStateObserver : public SuspendManager::SuspendStateObserverStub {
public:
static void RegisterSuspendObserver(std::shared_ptr<TaskHandlerWrap> taskHandler);
void OnActive(const std::vector<int32_t> &pidList, const int32_t uid) override;
void OnDoze(const int32_t uid) override;
void OnFrozen(const std::vector<int32_t> &pidList, const int32_t uid) override;
private:
static int g_registerCount;
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_PROCESS_FROZEN_STATE_OBSERVER_H

View File

@ -87,6 +87,7 @@
#include "permission_constants.h"
#include "process_options.h"
#include "recovery_param.h"
#include "res_sched_util.h"
#include "restart_app_manager.h"
#include "sa_mgr_client.h"
#include "scene_board_judgement.h"
@ -120,16 +121,6 @@
#include "window_focus_changed_listener.h"
#endif
#ifdef EFFICIENCY_MANAGER_ENABLE
#include "suspend_manager_client.h"
#include "process_frozen_state_observer.h"
#endif // EFFICIENCY_MANAGER_ENABLE
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
#include "res_sched_client.h"
#include "res_type.h"
#endif // RESOURCE_SCHEDULE_SERVICE_ENABLE
using OHOS::AppExecFwk::ElementName;
using OHOS::Security::AccessToken::AccessTokenKit;
@ -483,7 +474,6 @@ void AbilityManagerService::InitPushTask()
auto initPrepareTerminateConfigTask = [aams = shared_from_this()]() { aams->InitPrepareTerminateConfig(); };
taskHandler_->SubmitTask(initPrepareTerminateConfigTask, "InitPrepareTerminateConfig");
#endif // SUPPORT_SCREEN
RegisterSuspendObserver();
auto initExtensionConfigTask = []() {
DelayedSingleton<ExtensionConfig>::GetInstance()->LoadExtensionConfiguration();
@ -1189,7 +1179,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
return ERR_INVALID_VALUE;
}
TAG_LOGD(AAFwkTag::ABILITYMGR, "Start service or extension, name is %{public}s.", abilityInfo.name.c_str());
ReportEventToSuspendManager(abilityInfo);
ReportEventToRSS(abilityInfo);
InsightIntentExecuteParam::RemoveInsightIntent(const_cast<Want &>(want));
return connectManager->StartAbility(abilityRequest);
}
@ -1208,7 +1198,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
abilityRequest.want.RemoveParam(PARAM_SPECIFIED_PROCESS_FLAG);
// sceneboard
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
ReportEventToSuspendManager(abilityInfo);
ReportEventToRSS(abilityInfo);
abilityRequest.userId = oriValidUserId;
abilityRequest.want.SetParam(IS_CALL_BY_SCB, false);
// other sa or shell can not use continueSessionId and persistentId
@ -1232,8 +1222,9 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr<IRemot
TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListManager is nullptr. userId=%{public}d", validUserId);
return ERR_INVALID_VALUE;
}
ReportAbilitStartInfoToRSS(abilityInfo);
ReportEventToSuspendManager(abilityInfo);
ReportEventToRSS(abilityInfo);
TAG_LOGD(AAFwkTag::ABILITYMGR, "Start ability, name is %{public}s.", abilityInfo.name.c_str());
return missionListManager->StartAbility(abilityRequest);
}
@ -1909,7 +1900,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const
}
TAG_LOGD(AAFwkTag::ABILITYMGR,
"request dialog service, start service extension,name is %{public}s.", abilityInfo.name.c_str());
ReportEventToSuspendManager(abilityInfo);
ReportEventToRSS(abilityInfo);
return connectManager->StartAbility(abilityRequest);
}
@ -2032,8 +2023,7 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bo
}
ReportAbilitStartInfoToRSS(abilityInfo);
ReportAbilitAssociatedStartInfoToRSS(abilityInfo, static_cast<int64_t>(
ResourceSchedule::ResType::AssociatedStartType::SCB_START_ABILITY), sessionInfo->callerToken);
ReportAbilitAssociatedStartInfoToRSS(abilityInfo, RES_TYPE_SCB_START_ABILITY, sessionInfo->callerToken);
auto uiAbilityManager = GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid());
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
// here we don't need want param "IS_CALL_BY_SCB" any more, remove it.
@ -2353,7 +2343,6 @@ void AbilityManagerService::UnsubscribeBundleEventCallback()
void AbilityManagerService::ReportAbilitStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
if (abilityInfo.type == AppExecFwk::AbilityType::PAGE &&
abilityInfo.launchMode != AppExecFwk::LaunchMode::SPECIFIED) {
@ -2370,76 +2359,31 @@ void AbilityManagerService::ReportAbilitStartInfoToRSS(const AppExecFwk::Ability
break;
}
}
std::unordered_map<std::string, std::string> eventParams {
{ "name", "ability_start" },
{ "uid", std::to_string(abilityInfo.applicationInfo.uid) },
{ "bundleName", abilityInfo.applicationInfo.bundleName },
{ "abilityName", abilityInfo.name },
{ "pid", std::to_string(pid) }
};
ResourceSchedule::ResSchedClient::GetInstance().ReportData(
ResourceSchedule::ResType::RES_TYPE_APP_ABILITY_START, isColdStart ? 1 : 0, eventParams);
ResSchedUtil::GetInstance().ReportAbilitStartInfoToRSS(abilityInfo, pid, isColdStart);
}
#endif
}
void AbilityManagerService::ReportAbilitAssociatedStartInfoToRSS(
const AppExecFwk::AbilityInfo &abilityInfo, int64_t type, const sptr<IRemoteObject> &callerToken)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
if (callerToken == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "associated start caller token is nullptr");
return;
}
CHECK_POINTER_LOG(callerToken, "associated start caller token is nullptr");
auto callerAbility = Token::GetAbilityRecordByToken(callerToken);
if (callerAbility == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "associated start caller ability is nullptr");
return;
}
CHECK_POINTER_LOG(callerAbility, "associated start caller ability is nullptr");
int32_t callerUid = callerAbility->GetUid();
int32_t callerPid = callerAbility->GetPid();
std::unordered_map<std::string, std::string> eventParams {
{ "name", "associated_start" },
{ "caller_uid", std::to_string(callerUid) },
{ "caller_pid", std::to_string(callerPid) },
{ "callee_uid", std::to_string(abilityInfo.applicationInfo.uid) },
{ "callee_bundle_name", abilityInfo.applicationInfo.bundleName }
};
ResourceSchedule::ResSchedClient::GetInstance().ReportData(
ResourceSchedule::ResType::RES_TYPE_APP_ASSOCIATED_START, type, eventParams);
#endif
ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerUid, callerPid);
}
void AbilityManagerService::ReportEventToSuspendManager(const AppExecFwk::AbilityInfo &abilityInfo)
void AbilityManagerService::ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo)
{
#ifdef EFFICIENCY_MANAGER_ENABLE
if (taskHandler_ == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "taskhandler null");
return;
}
CHECK_POINTER_LOG(taskHandler_, "taskhandler null");
std::string reason = (abilityInfo.type == AppExecFwk::AbilityType::PAGE) ?
"THAW_BY_START_PAGE_ABILITY" : "THAW_BY_START_NOT_PAGE_ABILITY";
const auto uid = abilityInfo.applicationInfo.uid;
const auto bundleName = abilityInfo.applicationInfo.bundleName;
taskHandler_->SubmitTask([reason, uid, bundleName]() {
SuspendManager::SuspendManagerClient::GetInstance().ThawOneApplication(
uid, bundleName, reason);
});
#endif // EFFICIENCY_MANAGER_ENABLE
}
void AbilityManagerService::RegisterSuspendObserver()
{
#ifdef EFFICIENCY_MANAGER_ENABLE
if (!taskHandler_) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "taskhandler null");
return;
}
taskHandler_->SubmitTask([taskHandler = taskHandler_]() {
ProcessFrozenStateObserver::RegisterSuspendObserver(taskHandler);
});
#endif // EFFICIENCY_MANAGER_ENABLE
ResSchedUtil::GetInstance().ReportEventToRSS(uid, bundleName, reason);
});
}
int AbilityManagerService::StartExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
@ -2699,8 +2643,7 @@ int AbilityManagerService::StartExtensionAbilityInner(const Want &want, const sp
if (eventInfo.errCode != ERR_OK) {
EventReport::SendExtensionEvent(EventName::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo);
}
ReportAbilitAssociatedStartInfoToRSS(abilityRequest.abilityInfo, static_cast<int64_t>(
ResourceSchedule::ResType::AssociatedStartType::EXTENSION_START_ABILITY), callerToken);
ReportAbilitAssociatedStartInfoToRSS(abilityRequest.abilityInfo, RES_TYPE_EXTENSION_START_ABILITY, callerToken);
return eventInfo.errCode;
}
@ -3887,7 +3830,7 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u
return ERR_INVALID_VALUE;
}
ReportEventToSuspendManager(abilityInfo);
ReportEventToRSS(abilityInfo);
return connectManager->ConnectAbilityLocked(abilityRequest, connect, callerToken, sessionInfo, connectInfo);
}
@ -4760,7 +4703,7 @@ sptr<IAbilityScheduler> AbilityManagerService::AcquireDataAbility(
std::shared_ptr<DataAbilityManager> dataAbilityManager = GetDataAbilityManagerByUserId(userId);
CHECK_POINTER_AND_RETURN(dataAbilityManager, nullptr);
ReportEventToSuspendManager(abilityRequest.abilityInfo);
ReportEventToRSS(abilityRequest.abilityInfo);
bool isNotHap = isSaCall || isShellCall;
UpdateCallerInfo(abilityRequest.want, callerToken);
return dataAbilityManager->Acquire(abilityRequest, tryBind, callerToken, isNotHap);
@ -6812,7 +6755,7 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr<IAbil
result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE :
afterCheckExecuter_->DoProcess(afterCheckParam);
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
ReportEventToSuspendManager(abilityRequest.abilityInfo);
ReportEventToRSS(abilityRequest.abilityInfo);
abilityRequest.want.SetParam(IS_CALL_BY_SCB, false);
auto uiAbilityManager = GetUIAbilityManagerByUserId(oriValidUserId);
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
@ -6824,7 +6767,7 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptr<IAbil
TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListMgr is Null. Designated User Id=%{public}d", oriValidUserId);
return ERR_INVALID_VALUE;
}
ReportEventToSuspendManager(abilityRequest.abilityInfo);
ReportEventToRSS(abilityRequest.abilityInfo);
if (result != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "afterCheckExecuter_ is nullptr or DoProcess return error.");
@ -6840,7 +6783,7 @@ int AbilityManagerService::StartAbilityJust(AbilityRequest &abilityRequest, int3
TAG_LOGD(AAFwkTag::ABILITYMGR, "call");
UpdateCallerInfo(abilityRequest.want, abilityRequest.callerToken);
if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) {
ReportEventToSuspendManager(abilityRequest.abilityInfo);
ReportEventToRSS(abilityRequest.abilityInfo);
auto uiAbilityManager = GetUIAbilityManagerByUserId(validUserId);
CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE);
return uiAbilityManager->ResolveLocked(abilityRequest);
@ -6851,7 +6794,7 @@ int AbilityManagerService::StartAbilityJust(AbilityRequest &abilityRequest, int3
TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListMgr is Null. Designated User Id=%{public}d", validUserId);
return ERR_INVALID_VALUE;
}
ReportEventToSuspendManager(abilityRequest.abilityInfo);
ReportEventToRSS(abilityRequest.abilityInfo);
return missionListMgr->ResolveLocked(abilityRequest);
}
@ -10027,17 +9970,6 @@ int32_t AbilityManagerService::GetForegroundUIAbilities(std::vector<AppExecFwk::
return ERR_OK;
}
void AbilityManagerService::HandleProcessFrozen(const std::vector<int32_t> &pidList, int32_t uid)
{
auto userId = uid / BASE_USER_RANGE;
auto connectManager = GetConnectManagerByUserId(userId);
if (connectManager == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "can not find user connect manager");
return;
}
connectManager->HandleProcessFrozen(pidList, uid);
}
void AbilityManagerService::NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId)
{
auto collaborator = GetCollaborator(CollaboratorType::RESERVE_TYPE);

View File

@ -47,6 +47,7 @@
#include "hilog_tag_wrapper.h"
#include "os_account_manager_wrapper.h"
#include "parameters.h"
#include "res_sched_util.h"
#include "ui_extension_host_info.h"
#include "scene_board_judgement.h"
#include "start_ability_utils.h"
@ -63,10 +64,6 @@
#ifdef SUPPORT_SCREEN
#include "locale_config.h"
#endif
#ifdef EFFICIENCY_MANAGER_ENABLE
#include "suspend_manager_client.h"
#endif // EFFICIENCY_MANAGER_ENABLE
namespace OHOS {
using AbilityRuntime::FreezeUtil;
@ -525,12 +522,9 @@ void AbilityRecord::ProcessForegroundAbility(uint32_t tokenId, uint32_t sceneFla
// background to active state
TAG_LOGD(AAFwkTag::ABILITYMGR, "MoveToForeground, %{public}s", element.c_str());
lifeCycleStateInfo_.sceneFlagBak = sceneFlag;
#ifdef EFFICIENCY_MANAGER_ENABLE
std::string bundleName = GetAbilityInfo().bundleName;
int32_t uid = GetUid();
SuspendManager::SuspendManagerClient::GetInstance().ThawOneApplication(
uid, bundleName, "THAW_BY_FOREGROUND_ABILITY");
#endif // EFFICIENCY_MANAGER_ENABLE
ResSchedUtil::GetInstance().ReportEventToRSS(uid, bundleName, "THAW_BY_FOREGROUND_ABILITY");
DelayedSingleton<AppScheduler>::GetInstance()->MoveToForeground(token_);
}
} else {

View File

@ -30,12 +30,9 @@
#include "hisysevent.h"
#include "mission_info_mgr.h"
#include "in_process_call_wrapper.h"
#include "res_sched_util.h"
#include "server_constant.h"
#include "startup_util.h"
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
#include "res_sched_client.h"
#include "res_type.h"
#endif // RESOURCE_SCHEDULE_SERVICE_ENABLE
#ifdef SUPPORT_GRAPHICS
#include "ability_first_frame_state_observer_manager.h"
#endif
@ -194,8 +191,10 @@ int MissionListManager::StartAbility(AbilityRequest &abilityRequest)
SendKeyEvent(abilityRequest);
}
NotifyStartAbilityResult(abilityRequest, ret);
ReportAbilitAssociatedStartInfoToRSS(abilityRequest.abilityInfo, static_cast<int64_t>(
ResourceSchedule::ResType::AssociatedStartType::MISSION_LIST_START_ABILITY), callerAbility);
if (callerAbility != nullptr) {
ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityRequest.abilityInfo,
RES_TYPE_MISSION_LIST_START_ABILITY, callerAbility->GetUid(), callerAbility->GetPid());
}
return ret;
}
@ -4195,28 +4194,6 @@ void MissionListManager::SendKeyEvent(const AbilityRequest &abilityRequest)
EventReport::SendKeyEvent(EventName::START_PRIVATE_ABILITY, HiSysEventType::BEHAVIOR, eventInfo);
}
void MissionListManager::ReportAbilitAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo,
int64_t type, const std::shared_ptr<AbilityRecord> &callerAbility)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
if (callerAbility == nullptr) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "associated start caller record is nullptr");
return;
}
int32_t callerUid = callerAbility->GetUid();
int32_t callerPid = callerAbility->GetPid();
std::unordered_map<std::string, std::string> eventParams {
{ "name", "associated_start" },
{ "caller_uid", std::to_string(callerUid) },
{ "caller_pid", std::to_string(callerPid) },
{ "callee_uid", std::to_string(abilityInfo.applicationInfo.uid) },
{ "callee_bundle_name", abilityInfo.applicationInfo.bundleName }
};
ResourceSchedule::ResSchedClient::GetInstance().ReportData(
ResourceSchedule::ResType::RES_TYPE_APP_ASSOCIATED_START, type, eventParams);
#endif
}
void MissionListManager::SignRestartAppFlag(const std::string &bundleName)
{
for (const auto& missionList : currentMissionLists_) {

View File

@ -1,113 +0,0 @@
/*
* Copyright (c) 2023-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 "process_frozen_state_observer.h"
#include "ability_manager_service.h"
#include "hilog/log.h"
#include "hilog_tag_wrapper.h"
#include "suspend_manager_client.h"
namespace OHOS {
namespace AAFwk {
namespace {
constexpr int32_t MAX_FAIL_COUNT = 10;
constexpr int32_t FAIL_RETRY_INTERVAL = 5000; // ms
class SuspendMgrDeathRecipient : public IRemoteObject::DeathRecipient {
public:
static void AddSuspendMgrDeathRecipient()
{
auto systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
if (!systemManager) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to get SystemAbilityManager.");
return;
}
auto remoteObj = systemManager->GetSystemAbility(SUSPEND_MANAGER_SYSTEM_ABILITY_ID);
if (!remoteObj) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to get SuspendManager sa.");
return;
}
if (!remoteObj->IsProxyObject()) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Not proxy object.");
return;
}
if (!remoteObj->AddDeathRecipient(sptr(new SuspendMgrDeathRecipient))) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Add death recipient for SuspendManager failed.");
return;
}
}
void OnRemoteDied(const wptr<IRemoteObject>&)
{
auto taskHandler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
if (!taskHandler) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "taskHandler null.");
return;
}
taskHandler->SubmitTask([taskHandler]() {
ProcessFrozenStateObserver::RegisterSuspendObserver(taskHandler);
}, FAIL_RETRY_INTERVAL);
}
};
}
int ProcessFrozenStateObserver::g_registerCount = 0;
void ProcessFrozenStateObserver::RegisterSuspendObserver(std::shared_ptr<TaskHandlerWrap> taskHandler)
{
if (!taskHandler) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "taskHandler null");
return;
}
auto ret = SuspendManager::SuspendManagerClient::GetInstance().RegisterSuspendObserver(
sptr(new ProcessFrozenStateObserver()));
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "failed err: %{public}d", ret);
g_registerCount++;
if (g_registerCount < MAX_FAIL_COUNT) {
taskHandler->SubmitTask([taskHandler]() {
RegisterSuspendObserver(taskHandler);
}, FAIL_RETRY_INTERVAL);
} else {
TAG_LOGE(AAFwkTag::ABILITYMGR, "failed 10 times");
g_registerCount = 0;
}
} else {
g_registerCount = 0;
TAG_LOGI(AAFwkTag::ABILITYMGR, "RegisterSuspendObserver success");
SuspendMgrDeathRecipient::AddSuspendMgrDeathRecipient();
}
}
void ProcessFrozenStateObserver::OnActive(const std::vector<int32_t> &pidList, const int32_t uid)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "OnActive: %{public}d", uid);
}
void ProcessFrozenStateObserver::OnDoze(const int32_t uid)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "OnDoze: %{public}d", uid);
}
void ProcessFrozenStateObserver::OnFrozen(const std::vector<int32_t> &pidList, const int32_t uid)
{
TAG_LOGD(AAFwkTag::ABILITYMGR, "OnFrozen: %{public}d", uid);
if (pidList.empty()) {
TAG_LOGW(AAFwkTag::ABILITYMGR, "OnFrozen pidList empty");
return;
}
DelayedSingleton<AbilityManagerService>::GetInstance()->HandleProcessFrozen(pidList, uid);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -105,6 +105,7 @@ ohos_shared_library("libappms") {
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
]
@ -156,11 +157,6 @@ ohos_shared_library("libappms") {
]
}
if (efficiency_manager) {
defines += [ "EFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (background_task_mgr_continuous_task_enable) {
defines += [ "BGTASKMGR_CONTINUOUS_TASK_ENABLE" ]
}

View File

@ -33,13 +33,11 @@
#include "scene_board_judgement.h"
#include "window_visibility_info.h"
#endif //SUPPORT_SCREEN
#include "ui_extension_utils.h"
#include "app_mgr_service_const.h"
#include "cache_process_manager.h"
#ifdef EFFICIENCY_MANAGER_ENABLE
#include "suspend_manager_client.h"
#endif
#include "app_mgr_service_dump_error_code.h"
#include "cache_process_manager.h"
#include "res_sched_util.h"
#include "ui_extension_utils.h"
namespace OHOS {
@ -767,20 +765,7 @@ bool AppRunningManager::isCollaboratorReserveType(const std::shared_ptr<AppRunni
int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
{
std::unordered_set<int32_t> frozenPids;
#ifdef EFFICIENCY_MANAGER_ENABLE
std::unordered_map<int32_t, std::unordered_map<int32_t, bool>> appSuspendState;
SuspendManager::SuspendManagerClient::GetInstance().GetAllSuspendState(appSuspendState);
if (appSuspendState.empty()) {
TAG_LOGW(AAFwkTag::APPMGR, "Get app state empty");
}
for (auto &[uid, pids] : appSuspendState) {
for (auto &[pid, isFrozen] : pids) {
if (isFrozen) {
frozenPids.insert(pid);
}
}
}
#endif
AAFwk::ResSchedUtil::GetInstance().GetAllFrozenPidsFromRSS(frozenPids);
auto appRunningMap = GetAppRunningRecordMap();
for (const auto &item : appRunningMap) {
const auto &appRecord = item.second;
@ -807,20 +792,7 @@ int32_t AppRunningManager::NotifyMemoryLevel(int32_t level)
int32_t AppRunningManager::NotifyProcMemoryLevel(const std::map<pid_t, MemoryLevel> &procLevelMap)
{
std::unordered_set<int32_t> frozenPids;
#ifdef EFFICIENCY_MANAGER_ENABLE
std::unordered_map<int32_t, std::unordered_map<int32_t, bool>> appSuspendState;
SuspendManager::SuspendManagerClient::GetInstance().GetAllSuspendState(appSuspendState);
if (appSuspendState.empty()) {
TAG_LOGW(AAFwkTag::APPMGR, "Get app state empty");
}
for (auto &[uid, pids] : appSuspendState) {
for (auto &[pid, isFrozen] : pids) {
if (isFrozen) {
frozenPids.insert(pid);
}
}
}
#endif
AAFwk::ResSchedUtil::GetInstance().GetAllFrozenPidsFromRSS(frozenPids);
auto appRunningMap = GetAppRunningRecordMap();
for (const auto &item : appRunningMap) {
const auto &appRecord = item.second;

View File

@ -134,3 +134,33 @@ ohos_shared_library("app_util") {
subsystem_name = "ability"
part_name = "ability_runtime"
}
ohos_shared_library("res_sched_util") {
sanitize = {
integer_overflow = true
ubsan = true
boundary_sanitize = true
cfi = true
cfi_cross_dso = true
debug = false
}
branch_protector_ret = "pac_ret"
public_configs = [ ":common_config" ]
include_dirs = [ "include" ]
sources = [ "src/res_sched_util.cpp" ]
external_deps = [
"bundle_framework:appexecfwk_base",
"hilog:libhilog",
]
if (resource_schedule_service_enable) {
defines = [ "RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]
}
subsystem_name = "ability"
part_name = "ability_runtime"
}

View File

@ -0,0 +1,50 @@
/*
* 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_RES_SCHED_UTIL_H
#define OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H
#include <unordered_set>
#include "nocopyable.h"
namespace OHOS {
namespace AppExecFwk {
struct AbilityInfo;
}
namespace AAFwk {
using AbilityInfo = AppExecFwk::AbilityInfo;
constexpr int64_t RES_TYPE_SCB_START_ABILITY = 0;
constexpr int64_t RES_TYPE_EXTENSION_START_ABILITY = 1;
constexpr int64_t RES_TYPE_MISSION_LIST_START_ABILITY = 2;
class ResSchedUtil final {
public:
static ResSchedUtil &GetInstance();
void ReportAbilitStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart);
void ReportAbilitAssociatedStartInfoToRSS(
const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid);
void ReportEventToRSS(int32_t uid, std::string bundleName, std::string name);
void GetAllFrozenPidsFromRSS(std::unordered_set<int32_t> &frozenPids);
private:
ResSchedUtil() = default;
~ResSchedUtil() = default;
DISALLOW_COPY_AND_MOVE(ResSchedUtil);
int64_t convertType(int64_t resSchedType);
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_RES_SCHED_UTIL_H

View File

@ -0,0 +1,138 @@
/*
* 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 "res_sched_util.h"
#include <string>
#include "ability_info.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
#include "res_sched_client.h"
#include "res_type.h"
#endif
namespace OHOS {
namespace AAFwk {
using AssociatedStartType = ResourceSchedule::ResType::AssociatedStartType;
ResSchedUtil &ResSchedUtil::GetInstance()
{
static ResSchedUtil instance;
return instance;
}
int64_t ResSchedUtil::convertType(int64_t resSchedType)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
if (resSchedType == RES_TYPE_SCB_START_ABILITY) {
return static_cast<int64_t>(AssociatedStartType::SCB_START_ABILITY);
} else if (resSchedType == RES_TYPE_EXTENSION_START_ABILITY) {
return static_cast<int64_t>(AssociatedStartType::EXTENSION_START_ABILITY);
} else if (resSchedType == RES_TYPE_MISSION_LIST_START_ABILITY) {
return static_cast<int64_t>(AssociatedStartType::MISSION_LIST_START_ABILITY);
}
#endif
TAG_LOGE(AAFwkTag::DEFAULT, "res sched type invalid");
return -1;
}
void ResSchedUtil::ReportAbilitStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
uint32_t resType = ResourceSchedule::ResType::RES_TYPE_APP_ABILITY_START;
std::unordered_map<std::string, std::string> eventParams {
{ "name", "ability_start" },
{ "uid", std::to_string(abilityInfo.applicationInfo.uid) },
{ "bundleName", abilityInfo.applicationInfo.bundleName },
{ "abilityName", abilityInfo.name },
{ "pid", std::to_string(pid) }
};
TAG_LOGD(AAFwkTag::DEFAULT, "call");
ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, isColdStart ? 1 : 0, eventParams);
#endif
}
void ResSchedUtil::ReportAbilitAssociatedStartInfoToRSS(
const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
uint32_t resType = ResourceSchedule::ResType::RES_TYPE_APP_ASSOCIATED_START;
std::unordered_map<std::string, std::string> eventParams {
{ "name", "associated_start" },
{ "caller_uid", std::to_string(callerUid) },
{ "caller_pid", std::to_string(callerPid) },
{ "callee_uid", std::to_string(abilityInfo.applicationInfo.uid) },
{ "callee_bundle_name", abilityInfo.applicationInfo.bundleName }
};
int64_t type = convertType(resSchedType);
TAG_LOGD(AAFwkTag::DEFAULT, "call");
ResourceSchedule::ResSchedClient::GetInstance().ReportData(resType, type, eventParams);
#endif
}
void ResSchedUtil::ReportEventToRSS(int32_t uid, std::string bundleName, std::string reason)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
uint32_t resType = ResourceSchedule::ResType::SYNC_RES_TYPE_THAW_ONE_APP;
nlohmann::json payload;
payload.emplace("uid", uid);
payload.emplace("pid", -1);
payload.emplace("bundleName", bundleName);
payload.emplace("reason", reason);
nlohmann::json reply;
TAG_LOGD(AAFwkTag::DEFAULT, "call");
ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent(resType, 0, payload, reply);
#endif
}
void ResSchedUtil::GetAllFrozenPidsFromRSS(std::unordered_set<int32_t> &frozenPids)
{
#ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE
uint32_t resType = ResourceSchedule::ResType::SYNC_RES_TYPE_GET_ALL_SUSPEND_STATE;
nlohmann::json payload;
nlohmann::json reply;
TAG_LOGD(AAFwkTag::DEFAULT, "call");
int32_t ret = ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent(resType, 0, payload, reply);
if (ret != 0 || !reply.contains("allSuspendState") || !reply["allSuspendState"].is_array()) {
TAG_LOGE(AAFwkTag::DEFAULT, "ReportSyncEvent fail");
return;
}
for (nlohmann::json &appObj : reply["allSuspendState"]) {
// Here can get uid if needed
if (!appObj.contains("pidsState") || !appObj["pidsState"].is_array()) {
continue;
}
for (nlohmann::json &pidObj : appObj["pidsState"]) {
if (!pidObj.contains("pid") || !pidObj["pid"].is_number() ||
!pidObj.contains("isFrozen") || !pidObj["isFrozen"].is_boolean()) {
break;
}
int32_t pid = pidObj["pid"].get<int32_t>();
bool isFrozen = pidObj["isFrozen"].get<bool>();
if (isFrozen) {
frozenPids.insert(pid);
}
}
}
if (frozenPids.empty()) {
TAG_LOGW(AAFwkTag::DEFAULT, "Get frozen pids empty");
}
#endif
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -96,7 +96,7 @@ void DoSomethingInterestingWithMyAPI1(AbilityManagerService &abilityms, Want& wa
abilityms.CheckOptExtensionAbility(want, abilityRequest, int32Param, extensionType);
AppExecFwk::AbilityInfo abilityInfo;
abilityms.ReportAbilitStartInfoToRSS(abilityInfo);
abilityms.ReportEventToSuspendManager(abilityInfo);
abilityms.ReportEventToRSS(abilityInfo);
abilityms.StartExtensionAbility(want, token, int32Param, extensionType);
abilityms.StopExtensionAbility(want, token, int32Param, extensionType);
abilityms.TerminateAbility(token, intParam, &want);

View File

@ -86,11 +86,6 @@ ohos_moduletest("AbilityRecordModuleTest") {
"relational_store:native_rdb",
]
if (efficiency_manager) {
cflags_cc += [ "-DEFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (resource_schedule_service_enable) {
cflags_cc += [ "-RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]

View File

@ -106,12 +106,6 @@ ohos_moduletest("ability_timeout_module_test") {
"window_manager:sms",
]
if (efficiency_manager) {
sources += [ "${ability_runtime_services_path}/abilitymgr/src/process_frozen_state_observer.cpp" ]
cflags_cc += [ "-DEFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (resource_schedule_service_enable) {
cflags_cc += [ "-RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]

View File

@ -119,12 +119,6 @@ ohos_moduletest("running_infos_module_test") {
"window_manager:sms",
]
if (efficiency_manager) {
sources += [ "${ability_runtime_services_path}/abilitymgr/src/process_frozen_state_observer.cpp" ]
cflags_cc += [ "-DEFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (resource_schedule_service_enable) {
cflags_cc += [ "-RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]

View File

@ -97,11 +97,6 @@ ohos_moduletest("start_ability_implicit_module_test") {
"relational_store:native_rdb",
]
if (efficiency_manager) {
cflags_cc += [ "-DEFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (resource_schedule_service_enable) {
cflags_cc += [ "-RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]

View File

@ -261,12 +261,6 @@ ohos_source_set("abilityms_test_source") {
"window_manager:sms",
]
if (efficiency_manager) {
sources += [ "${ability_runtime_services_path}/abilitymgr/src/process_frozen_state_observer.cpp" ]
cflags_cc += [ "-DEFFICIENCY_MANAGER_ENABLE" ]
external_deps += [ "efficiency_manager:suspend_manager_client" ]
}
if (resource_schedule_service_enable) {
cflags_cc += [ "-RESOURCE_SCHEDULE_SERVICE_ENABLE" ]
external_deps += [ "resource_schedule_service:ressched_client" ]
@ -488,6 +482,7 @@ group("unittest") {
"render_state_observer_manager_test:unittest",
"render_state_observer_proxy_test:unittest",
"render_state_observer_stub_test:unittest",
"res_sched_util_test:unittest",
"resident_process_manager_test:unittest",
"running_infos_test:unittest",
"runtime_test:unittest",

View File

@ -55,6 +55,7 @@ ohos_unittest("AmsAppLifeCycleTest") {
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/unittest:appmgr_test_source",
"${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk",

View File

@ -53,6 +53,7 @@ ohos_unittest("AmsWorkFlowTest") {
"${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/unittest:appmgr_test_source",
"${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk",

View File

@ -67,6 +67,7 @@ ohos_unittest("AmsRecentAppListTest") {
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/unittest:appmgr_test_source",
"${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk",

View File

@ -69,6 +69,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") {
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/unittest:appmgr_test_source",
"${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk",

View File

@ -64,6 +64,7 @@ ohos_unittest("AMSEventHandlerTest") {
"${ability_runtime_services_path}/common:app_util",
"${ability_runtime_services_path}/common:event_report",
"${ability_runtime_services_path}/common:perm_verification",
"${ability_runtime_services_path}/common:res_sched_util",
"${ability_runtime_services_path}/common:task_handler_wrap",
"${ability_runtime_test_path}/unittest:appmgr_test_source",
"${distributedschedule_path}/safwk/interfaces/innerkits/safwk:system_ability_fwk",

View File

@ -0,0 +1,50 @@
# 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/res_sched_util"
ohos_unittest("res_sched_util_test") {
module_out_path = module_output_path
configs = [ "${ability_runtime_services_path}/common:common_config" ]
if (target_cpu == "arm") {
cflags = [ "-DBINDER_IPC_32BIT" ]
}
sources = [ "res_sched_util_test.cpp" ]
deps = [
"${ability_runtime_services_path}/common:res_sched_util",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_runtime:abilitykit_native",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hilog:libhilog",
"init:libbegetutil",
"ipc:ipc_core",
]
}
group("unittest") {
testonly = true
deps = [ ":res_sched_util_test" ]
}

View File

@ -0,0 +1,85 @@
/*
* 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_info.h"
#include "hilog_tag_wrapper.h"
#include "hilog_wrapper.h"
#define private public
#include "res_sched_util.h"
#undef private
#include "parameters.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace AbilityRuntime {
using AbilityInfo = AppExecFwk::AbilityInfo;
class ResSchedUtilTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
void ResSchedUtilTest::SetUpTestCase(void)
{}
void ResSchedUtilTest::TearDownTestCase(void)
{}
void ResSchedUtilTest::SetUp()
{}
void ResSchedUtilTest::TearDown()
{}
/**
* @tc.number: ResSchedUtilTest_0100
* @tc.desc: Test ReportAbilitStartInfoToRSS works
* @tc.type: FUNC
*/
HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0100, TestSize.Level0)
{
TAG_LOGI(AAFwkTag::TEST, "ResSchedUtilTest_0100 called.");
AbilityInfo abilityInfo;
int64_t resSchedType = -1;
AAFwk::ResSchedUtil::GetInstance().ReportAbilitStartInfoToRSS(abilityInfo, -1, false);
AAFwk::ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityInfo, resSchedType, 0, 0);
int64_t ret = AAFwk::ResSchedUtil::GetInstance().convertType(resSchedType);
EXPECT_EQ(resSchedType, ret);
}
/**
* @tc.number: ResSchedUtilTest_0200
* @tc.desc: Test ReportAbilitStartInfoToRSS works
* @tc.type: FUNC
*/
HWTEST_F(ResSchedUtilTest, ResSchedUtilTest_0200, TestSize.Level0)
{
TAG_LOGI(AAFwkTag::TEST, "ResSchedUtilTest_0200 called.");
std::string testName = "ResSchedUtilTest";
AAFwk::ResSchedUtil::GetInstance().ReportEventToRSS(0, testName, testName);
std::unordered_set<int32_t> frozenPids;
AAFwk::ResSchedUtil::GetInstance().GetAllFrozenPidsFromRSS(frozenPids);
int64_t resSchedType = AAFwk::RES_TYPE_SCB_START_ABILITY;
int64_t ret = AAFwk::ResSchedUtil::GetInstance().convertType(resSchedType);
EXPECT_EQ(resSchedType, ret);
}
} // namespace AbilityRuntime
} // namespace OHOS