IssueNo:#I61QHA

Description:新增AppMgrServiceInner TDD
Sig:SIG_ApplicationFramework
Feature or Bugfix:Bugfix
Binary Source: No

Signed-off-by: dy_study <dingyao5@huawei.com>
Change-Id: I3853aeef2d14f6b7540413308ddcf28d40ef3b97
This commit is contained in:
dy_study
2022-11-17 17:32:41 +08:00
parent e897d71b24
commit 2ff03686d2
5 changed files with 1235 additions and 2 deletions
@@ -855,10 +855,12 @@ std::shared_ptr<AppRunningRecord> AppMgrServiceInner::CreateAppRunningRecord(con
{
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
if (!appRunningManager_) {
HILOG_ERROR("appRunningManager nullptr!");
return nullptr;
}
auto appRecord = appRunningManager_->CreateAppRunningRecord(appInfo, processName, bundleInfo);
if (!appRecord) {
HILOG_ERROR("get app record failed");
return nullptr;
}
@@ -971,12 +973,22 @@ void AppMgrServiceInner::UpdateExtensionState(const sptr<IRemoteObject> &token,
void AppMgrServiceInner::OnStop()
{
if (!appRunningManager_) {
HILOG_ERROR("appRunningManager nullptr!");
return;
}
appRunningManager_->ClearAppRunningRecordMap();
CloseAppSpawnConnection();
}
ErrCode AppMgrServiceInner::OpenAppSpawnConnection()
{
if (remoteClientManager_ == nullptr) {
HILOG_ERROR("remoteClientManager_ is null");
return ERR_INVALID_VALUE;
}
if (remoteClientManager_->GetSpawnClient()) {
return remoteClientManager_->GetSpawnClient()->OpenConnection();
}
@@ -985,6 +997,11 @@ ErrCode AppMgrServiceInner::OpenAppSpawnConnection()
void AppMgrServiceInner::CloseAppSpawnConnection() const
{
if (remoteClientManager_ == nullptr) {
HILOG_ERROR("remoteClientManager_ is null");
return;
}
if (remoteClientManager_->GetSpawnClient()) {
remoteClientManager_->GetSpawnClient()->CloseConnection();
}
@@ -992,6 +1009,11 @@ void AppMgrServiceInner::CloseAppSpawnConnection() const
SpawnConnectionState AppMgrServiceInner::QueryAppSpawnConnectionState() const
{
if (remoteClientManager_ == nullptr) {
HILOG_ERROR("remoteClientManager_ is null");
return SpawnConnectionState::STATE_NOT_CONNECT;
}
if (remoteClientManager_->GetSpawnClient()) {
return remoteClientManager_->GetSpawnClient()->QueryConnectionState();
}
@@ -1000,16 +1022,32 @@ SpawnConnectionState AppMgrServiceInner::QueryAppSpawnConnectionState() const
std::map<const int32_t, const std::shared_ptr<AppRunningRecord>> AppMgrServiceInner::GetRecordMap() const
{
if (!appRunningManager_) {
HILOG_ERROR("appRunningManager nullptr!");
std::map<const int32_t, const std::shared_ptr<AppRunningRecord>> appRunningRecordMap;
return appRunningRecordMap;
}
return appRunningManager_->GetAppRunningRecordMap();
}
void AppMgrServiceInner::SetAppSpawnClient(std::shared_ptr<AppSpawnClient> spawnClient)
{
if (remoteClientManager_ == nullptr) {
HILOG_ERROR("remoteClientManager_ is null");
return;
}
remoteClientManager_->SetSpawnClient(std::move(spawnClient));
}
void AppMgrServiceInner::SetBundleManager(sptr<IBundleMgr> bundleManager)
{
if (remoteClientManager_ == nullptr) {
HILOG_ERROR("remoteClientManager_ is null");
return;
}
remoteClientManager_->SetBundleManager(bundleManager);
}
@@ -1179,6 +1217,11 @@ void AppMgrServiceInner::StartAbility(const sptr<IRemoteObject> &token, const sp
std::shared_ptr<AppRunningRecord> AppMgrServiceInner::GetAppRunningRecordByAbilityToken(
const sptr<IRemoteObject> &abilityToken) const
{
if (!appRunningManager_) {
HILOG_ERROR("appRunningManager_ is nullptr");
return nullptr;
}
return appRunningManager_->GetAppRunningRecordByAbilityToken(abilityToken);
}
@@ -409,6 +409,12 @@ void AppRunningRecord::AddAbilityStageDone()
{
HILOG_INFO("Add ability stage done. bundle %{public}s and eventId %{public}d", mainBundleName_.c_str(),
static_cast<int>(eventId_));
if (!eventHandler_) {
HILOG_ERROR("eventHandler_ is nullptr");
return;
}
if (eventHandler_->HasInnerEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG)) {
eventHandler_->RemoveEvent(AMSEventHandler::START_PROCESS_SPECIFIED_ABILITY_TIMEOUT_MSG);
}
@@ -95,6 +95,11 @@ int32_t AppStateObserverManager::UnregisterApplicationStateObserver(const sptr<I
void AppStateObserverManager::OnAppStateChanged(
const std::shared_ptr<AppRunningRecord> &appRecord, const ApplicationState state, bool needNotifyApp)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnAppStateChanged failed.");
return;
}
auto task = [weak = weak_from_this(), appRecord, state, needNotifyApp]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -109,6 +114,11 @@ void AppStateObserverManager::OnAppStateChanged(
void AppStateObserverManager::OnProcessDied(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnProcessDied failed.");
return;
}
auto task = [weak = weak_from_this(), appRecord]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -123,6 +133,11 @@ void AppStateObserverManager::OnProcessDied(const std::shared_ptr<AppRunningReco
void AppStateObserverManager::OnRenderProcessDied(const std::shared_ptr<RenderRecord> &renderRecord)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnRenderProcessDied failed.");
return;
}
auto task = [weak = weak_from_this(), renderRecord]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -137,6 +152,11 @@ void AppStateObserverManager::OnRenderProcessDied(const std::shared_ptr<RenderRe
void AppStateObserverManager::OnProcessStateChanged(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnProcessStateChanged failed.");
return;
}
auto task = [weak = weak_from_this(), appRecord]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -151,6 +171,11 @@ void AppStateObserverManager::OnProcessStateChanged(const std::shared_ptr<AppRun
void AppStateObserverManager::OnProcessCreated(const std::shared_ptr<AppRunningRecord> &appRecord)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnProcessCreated failed.");
return;
}
auto task = [weak = weak_from_this(), appRecord]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -165,6 +190,11 @@ void AppStateObserverManager::OnProcessCreated(const std::shared_ptr<AppRunningR
void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptr<RenderRecord> &renderRecord)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, OnRenderProcessCreated failed.");
return;
}
auto task = [weak = weak_from_this(), renderRecord]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -179,6 +209,11 @@ void AppStateObserverManager::OnRenderProcessCreated(const std::shared_ptr<Rende
void AppStateObserverManager::StateChangedNotifyObserver(const AbilityStateData abilityStateData, bool isAbility)
{
if (handler_ == nullptr) {
HILOG_ERROR("handler is nullptr, StateChangedNotifyObserver failed.");
return;
}
auto task = [weak = weak_from_this(), abilityStateData, isAbility]() {
auto self = weak.lock();
if (self == nullptr) {
@@ -19,7 +19,11 @@ module_output_path = "ability_runtime/appmgrservice"
ohos_unittest("AppMgrServiceInnerTest") {
module_out_path = module_output_path
include_dirs = [ "${ability_runtime_test_path}/mock/common/include" ]
include_dirs = [
"${ability_runtime_test_path}/mock/common/include",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
"${ability_runtime_test_path}/mock/services_appmgr_test/include",
]
sources = [
"${ability_runtime_test_path}/mock/common/src/mock_native_token.cpp",
@@ -30,6 +34,7 @@ ohos_unittest("AppMgrServiceInnerTest") {
deps = [
"${ability_runtime_services_path}/appmgr:libappms",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
File diff suppressed because it is too large Load Diff