From 5af0f6ce6c1986e3333fcd64f710073cf37407c5 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Tue, 13 Dec 2022 12:43:55 +0000 Subject: [PATCH 01/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../napi/app/app_manager/js_app_manager.cpp | 46 +++++++++++++++++++ .../include/ability_manager_service.h | 17 +++++++ services/abilitymgr/include/app_scheduler.h | 7 +++ .../src/ability_manager_service.cpp | 16 +++++++ services/abilitymgr/src/app_scheduler.cpp | 13 ++++++ 5 files changed, 99 insertions(+) mode change 100644 => 100755 frameworks/js/napi/app/app_manager/js_app_manager.cpp diff --git a/frameworks/js/napi/app/app_manager/js_app_manager.cpp b/frameworks/js/napi/app/app_manager/js_app_manager.cpp old mode 100644 new mode 100755 index e968ef10085..cf8d4890d2d --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -102,6 +102,12 @@ public: return (me != nullptr) ? me->OnkillProcessByBundleName(*engine, *info) : nullptr; } + static NativeValue* KillProcessSelf(NativeEngine* engine, NativeCallbackInfo* info) + { + JsAppManager* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnkillProcessSelf(*engine, *info) : nullptr; + } + static NativeValue* ClearUpApplicationData(NativeEngine* engine, NativeCallbackInfo* info) { JsAppManager* me = CheckParamsAndGetThis(engine, info); @@ -371,6 +377,44 @@ private: return result; } + NativeValue* OnkillProcessSelf(NativeEngine &engine, const NativeCallbackInfo &info) + { + HILOG_INFO("%{public}s is called", __FUNCTION__); + int32_t errCode = 0; + + // only support 0 or 1 params + if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { + HILOG_ERROR("Not enough params"); + errCode = ERR_NOT_OK; + } + + HILOG_INFO("kill self process"); + AsyncTask::CompleteCallback complete = + [abilityManager = abilityManager_, errCode](NativeEngine& engine, AsyncTask& task, + int32_t status) { + if (errCode != 0) { + task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); + return; + } + if (abilityManager == nullptr) { + HILOG_WARN("abilityManager nullptr"); + task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "abilityManager nullptr")); + return; + } + auto ret = abilityManager->KillProcessSelf(); + if (ret == 0) { + task.Resolve(engine, CreateJsValue(engine, ret)); + } else { + task.Reject(engine, CreateJsError(engine, ret, "kill process by self failed.")); + } + }; + + NativeValue* result = nullptr; + AsyncTask::Schedule("JSAppManager::OnkillProcessSelf", + engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); + return result; + } + NativeValue* OnClearUpApplicationData(NativeEngine &engine, const NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); @@ -580,6 +624,8 @@ NativeValue* JsAppManagerInit(NativeEngine* engine, NativeValue* exportObj) JsAppManager::KillProcessWithAccount); BindNativeFunction(*engine, *object, "killProcessesByBundleName", moduleName, JsAppManager::KillProcessesByBundleName); + BindNativeFunction(*engine, *object, "killProcessSelf", moduleName, + JsAppManager::killProcessSelf); BindNativeFunction(*engine, *object, "clearUpApplicationData", moduleName, JsAppManager::ClearUpApplicationData); BindNativeFunction(*engine, *object, "getAppMemorySize", moduleName, diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 19924e98ed4..9a518b25129 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -432,6 +432,13 @@ public: */ virtual int KillProcess(const std::string &bundleName) override; + /** + * Kill the process Itself. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual int KillProcessSelf() override; + /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, * clear the application data. @@ -728,6 +735,8 @@ public: */ virtual int SendANRProcessID(int pid) override; + + #ifdef ABILITY_COMMAND_FOR_TEST /** * Block ability manager service. @@ -1117,6 +1126,14 @@ private: */ int CheckStartByCallPermission(const AbilityRequest &abilityRequest); + /** + * Check if application is allowed to excute code file. + * + * @param abilityRequest, abilityRequest. + * @return Returns whether the caller is allowed to start Ability by call. + */ + int VerifyCallingPermission(const std::string &permissionName); + /** * Judge if Caller-Application is in background state. * diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index a9b3a31a949..ca280288aa7 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -212,6 +212,13 @@ public: */ int KillApplication(const std::string &bundleName); + /** + * kill self + * + */ + int KillApplicationSelf(); + + /** * kill the application by uid * diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a198316fc3a..00083116605 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3285,6 +3285,17 @@ int AbilityManagerService::KillProcess(const std::string &bundleName) return ERR_OK; } +int AbilityManagerService::KillProcessSelf() +{ + HILOG_DEBUG("Kill process by self"); + + int ret = DelayedSingleton::GetInstance()->KillApplicationSelf(); + if (ret != ERR_OK) { + return KILL_PROCESS_FAILED; + } + return ERR_OK; +} + int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) { HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); @@ -5409,6 +5420,11 @@ int AbilityManagerService::CheckStartByCallPermission(const AbilityRequest &abil return ERR_OK; } +bool AbilityManagerService::VerifyCallingPermission(const std::string &permissionName) +{ + return AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(permissionName); +} + int AbilityManagerService::IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall) { if (AAFwk::PermissionVerification::GetInstance()->IsSACall()) { diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 98d5759cb1b..da4c1c28cf1 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -201,6 +201,19 @@ int AppScheduler::KillApplication(const std::string &bundleName) return ERR_OK; } +int AppScheduler::KillApplicationSelf() +{ + HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); + int ret = (int)appMgrClient_->KillApplicationSelf(); + if (ret != ERR_OK) { + HILOG_ERROR("Fail to kill application."); + return INNER_ERR; + } + + return ERR_OK; +} + int AppScheduler::KillApplicationByUid(const std::string &bundleName, int32_t uid) { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); -- Gitee From 029015128e9edb2e5574ae88128e26270a5a9fa7 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 01:11:22 +0000 Subject: [PATCH 02/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/abilitymgr/include/ability_manager_service.h | 10 +--------- services/abilitymgr/src/ability_manager_service.cpp | 5 ----- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 9a518b25129..a4a6b108eef 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf() override; + virtual int KillProcessSelf(); /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, @@ -1126,14 +1126,6 @@ private: */ int CheckStartByCallPermission(const AbilityRequest &abilityRequest); - /** - * Check if application is allowed to excute code file. - * - * @param abilityRequest, abilityRequest. - * @return Returns whether the caller is allowed to start Ability by call. - */ - int VerifyCallingPermission(const std::string &permissionName); - /** * Judge if Caller-Application is in background state. * diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 00083116605..36371acf8e8 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5420,11 +5420,6 @@ int AbilityManagerService::CheckStartByCallPermission(const AbilityRequest &abil return ERR_OK; } -bool AbilityManagerService::VerifyCallingPermission(const std::string &permissionName) -{ - return AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission(permissionName); -} - int AbilityManagerService::IsCallFromBackground(const AbilityRequest &abilityRequest, bool &isBackgroundCall) { if (AAFwk::PermissionVerification::GetInstance()->IsSACall()) { -- Gitee From 6b3766667c4d4a4b34a0ec92640b14e09b70af19 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 03:05:57 +0000 Subject: [PATCH 03/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../napi/app/app_manager/js_app_manager.cpp | 0 .../include/ability_manager_service.h | 2 +- services/appmgr/src/app_mgr_service_inner.cpp | 30 ++++++++++++------- 3 files changed, 20 insertions(+), 12 deletions(-) mode change 100755 => 100644 frameworks/js/napi/app/app_manager/js_app_manager.cpp diff --git a/frameworks/js/napi/app/app_manager/js_app_manager.cpp b/frameworks/js/napi/app/app_manager/js_app_manager.cpp old mode 100755 new mode 100644 diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index a4a6b108eef..22870136fd3 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf(); + virtual int KillProcesSelf(); /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 979a4afc17b..e4374bcf326 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -553,21 +553,29 @@ int32_t AppMgrServiceInner::KillApplicationSelf() } auto callerPid = IPCSkeleton::GetCallingPid(); - if (!appRunningManager_->ProcessExitByPid(callerPid)) { - HILOG_INFO("The callerPid is invalid"); - return ERR_OK; - } - std::list pids; - pids.push_back(callerPid); + auto appRecord = GetAppRunningRecordByPid(callerpid); + auto bundleName = appRecord->GetBundleName(); + int result = ERR_OK; int64_t startTime = SystemTimeMillisecond(); + std::list pids; + + if (!appRunningManager_->ProcessExitByBundleName(bundleName, pids)) { + HILOG_INFO("The process corresponding to the package name did not start"); + return result; + } if (WaitForRemoteProcessExit(pids, startTime)) { - HILOG_INFO("The remote process exited successfully"); - return ERR_OK; + HILOG_INFO("The remote process exited successfully "); + NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); + return result; } - int result = KillProcessByPid(callerPid); - if (result < 0) { - HILOG_ERROR("KillApplication is fail, pid: %{public}d", callerPid); + for (auto iter = pids.begin(); iter != pids.end(); ++iter) { + result = KillProcessByPid(*iter); + if (result < 0) { + HILOG_ERROR("KillApplicationSelf is fail, pid:%{public}d", callerPid); + return result; + } } + NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); return result; } -- Gitee From 6e0a0abd28987e9dedcffa9ea9495c343495b95f Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 03:20:15 +0000 Subject: [PATCH 04/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/abilitymgr/include/ability_manager_service.h | 2 -- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 22870136fd3..77df58f1353 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -735,8 +735,6 @@ public: */ virtual int SendANRProcessID(int pid) override; - - #ifdef ABILITY_COMMAND_FOR_TEST /** * Block ability manager service. diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index e4374bcf326..b3600ce766b 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -553,7 +553,7 @@ int32_t AppMgrServiceInner::KillApplicationSelf() } auto callerPid = IPCSkeleton::GetCallingPid(); - auto appRecord = GetAppRunningRecordByPid(callerpid); + auto appRecord = GetAppRunningRecordByPid(callerPid); auto bundleName = appRecord->GetBundleName(); int result = ERR_OK; int64_t startTime = SystemTimeMillisecond(); -- Gitee From 6d5fb80f84bc07daffe810d2cf01b608df7b5ce4 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 03:37:09 +0000 Subject: [PATCH 05/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/abilitymgr/include/ability_manager_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 77df58f1353..88c5cacda1f 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcesSelf(); + virtual int KillProcessSelf(); /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, -- Gitee From fab767ffabd1a511fe8a25abc31817f9df2bd44c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 03:50:39 +0000 Subject: [PATCH 06/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- frameworks/js/napi/app/app_manager/js_app_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/app/app_manager/js_app_manager.cpp b/frameworks/js/napi/app/app_manager/js_app_manager.cpp index cf8d4890d2d..d58a60c4db3 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -625,7 +625,7 @@ NativeValue* JsAppManagerInit(NativeEngine* engine, NativeValue* exportObj) BindNativeFunction(*engine, *object, "killProcessesByBundleName", moduleName, JsAppManager::KillProcessesByBundleName); BindNativeFunction(*engine, *object, "killProcessSelf", moduleName, - JsAppManager::killProcessSelf); + JsAppManager::KillProcessSelf); BindNativeFunction(*engine, *object, "clearUpApplicationData", moduleName, JsAppManager::ClearUpApplicationData); BindNativeFunction(*engine, *object, "getAppMemorySize", moduleName, -- Gitee From 363eb3079df90d16665460efadda40b2fc311a74 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 04:04:50 +0000 Subject: [PATCH 07/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/abilitymgr/include/ability_manager_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 88c5cacda1f..1794d96f3b4 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf(); + virtual int KillProcessSelf() override; /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, -- Gitee From 1902f9a5f5cd89f300da4a840722c5b958e44d08 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 06:05:03 +0000 Subject: [PATCH 08/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/abilitymgr/include/ability_manager_service.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 1794d96f3b4..7eb0243861a 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf() override; + int KillProcessSelf(); /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, -- Gitee From 7f08e45d932b2ef9b9b95e763a3211692ebc68cd Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 06:23:40 +0000 Subject: [PATCH 09/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_manager/include/ability_manager_client.h | 7 +++++++ services/abilitymgr/src/ability_manager_client.cpp | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 6c53c0a9679..8636c86ca6e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -341,6 +341,13 @@ public: */ ErrCode KillProcess(const std::string &bundleName); + /** + * Kill the process itself immediately. + * + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode KillProcessSelf(); + #ifdef ABILITY_COMMAND_FOR_TEST /** * Force ability timeout. diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 6bab0c1861c..2cc04c606c5 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -359,6 +359,14 @@ ErrCode AbilityManagerClient::KillProcess(const std::string &bundleName) return abms->KillProcess(bundleName); } +ErrCode AbilityManagerClient::KillProcessSelf() +{ + HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->KillProcessSelf(bundleName); +} + #ifdef ABILITY_COMMAND_FOR_TEST ErrCode AbilityManagerClient::ForceTimeoutForTest(const std::string &abilityName, const std::string &state) { -- Gitee From baaeef4d030dde273fb35447a1095202e915661f Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 06:44:47 +0000 Subject: [PATCH 10/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../abilitymgr/include/ability_manager_proxy.h | 7 +++++++ .../include/ability_manager_service.h | 2 +- .../abilitymgr/src/ability_manager_client.cpp | 2 +- .../abilitymgr/src/ability_manager_proxy.cpp | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index b8d3ff48286..616d594edc1 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -316,6 +316,13 @@ public: */ virtual int KillProcess(const std::string &bundleName) override; + /** + * Kill the process itself immediately. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual int KillProcessSelf() override; + #ifdef ABILITY_COMMAND_FOR_TEST /** * force timeout ability. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 7eb0243861a..1794d96f3b4 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - int KillProcessSelf(); + virtual int KillProcessSelf() override; /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 2cc04c606c5..0509c095980 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -364,7 +364,7 @@ ErrCode AbilityManagerClient::KillProcessSelf() HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->KillProcessSelf(bundleName); + return abms->KillProcessSelf(); } #ifdef ABILITY_COMMAND_FOR_TEST diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 1ac3ca199f9..b0b879f1c1f 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -998,6 +998,23 @@ int AbilityManagerProxy::KillProcess(const std::string &bundleName) return reply.ReadInt32(); } +int AbilityManagerProxy::KillProcessSelf() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + int error = Remote()->SendRequest(IAbilityManager::KILL_PROCESS, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + #ifdef ABILITY_COMMAND_FOR_TEST int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, const std::string &state) { -- Gitee From 8e4e838f23d1593f4a16d27a03c29ecc519e0bdd Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 07:08:55 +0000 Subject: [PATCH 11/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_manager/include/ability_manager_interface.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 9b9f80197ca..47190ed5bf5 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -374,6 +374,13 @@ public: */ virtual int KillProcess(const std::string &bundleName) = 0; + /** + * Kill the process itself immediately. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual int KillProcessSelf() = 0; + #ifdef ABILITY_COMMAND_FOR_TEST /** * force timeout ability. -- Gitee From 6130658587e1c886767e2b31cc9e81e3db0438f3 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 07:47:06 +0000 Subject: [PATCH 12/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../AMS/mock_serviceability_manager_service.h | 1 + .../AMS/mock_serviceability_manager_service.h | 1 + 2 files changed, 2 insertions(+) diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index bbabf3b5808..fdcca4eae80 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -93,6 +93,7 @@ public: int ReleaseCall(const sptr& connect, const AppExecFwk::ElementName& element) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 75527be0e17..9e7bfe0de84 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -87,6 +87,7 @@ public: int TerminateAbilityByCaller(const sptr& callerToken, int requestCode) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); -- Gitee From fa8378508179210c75f4278a6f8717ebfa173187 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 08:08:50 +0000 Subject: [PATCH 13/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_delegator/mock_ability_delegator_stub.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index acaad958b5e..bd2ade77f28 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -64,6 +64,7 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); @@ -201,6 +202,7 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); -- Gitee From 755d9d304cef692d7ea39a3e10eb7ddcfcfe9a79 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 08:58:14 +0000 Subject: [PATCH 14/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/abilitymgr/include/app_scheduler.h | 1 - .../ability_manager_proxy_test/ability_manager_stub_mock.h | 5 +++++ .../ability_manager_test/ability_manager_stub_mock.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index ca280288aa7..d119ebaca85 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -218,7 +218,6 @@ public: */ int KillApplicationSelf(); - /** * kill the application by uid * diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index ae846c95dad..fed37dbf83a 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -164,6 +164,11 @@ public: return 0; } + virtual int KillProcessSelf() + { + return 0; + } + virtual int UninstallApp(const std::string& bundleName, int32_t uid) { return 0; diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 5a5bd4dc2d8..47e4bc38889 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -58,6 +58,7 @@ public: MOCK_METHOD2(TerminateAbilityResult, int(const sptr&, int)); MOCK_METHOD1(StopServiceAbility, int(const Want&)); MOCK_METHOD1(KillProcess, int(const std::string&)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); -- Gitee From be258a23d168d91755c79e4a50492464daa4d9cb Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 09:38:01 +0000 Subject: [PATCH 15/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../include/mock_ability_mgr_service.h | 1 + test/moduletest/mock/include/mock_ability_mgr_service.h | 1 + .../ability_manager_stub_impl_mock.h | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h index b30cee3d1cb..e31d2d74a97 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h @@ -55,6 +55,7 @@ public: MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD1(TerminateAbilityByRecordId, int(const int64_t recordId)); diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index 82e978504be..a1c29542c45 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -58,6 +58,7 @@ public: MOCK_METHOD2(StopServiceAbility, int(const Want&, int32_t userId)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD1(KillProcess, int(const std::string&)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD2( diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 3297c4c602c..8d4b6f30d93 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -197,6 +197,11 @@ public: return 0; } + virtual int KillProcessSelf() + { + return 0; + } + virtual int UninstallApp(const std::string& bundleName, int32_t uid) { return 0; -- Gitee From 72d88a0ec9bb69e7fe3ca22b22b8ed8057b63784 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 14 Dec 2022 10:11:37 +0000 Subject: [PATCH 16/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../include/mock_ability_manager_service.h | 2 ++ .../frameworks_kits_test/AMS/mock_ability_manager_service.h | 1 + 2 files changed, 3 insertions(+) diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index 47dd3e50b3b..d9b6f7b2a0b 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -150,6 +150,8 @@ public: int KillProcess(const std::string& bundleName) override; + int KillProcessSelf() override; + int UninstallApp(const std::string& bundleName, int32_t uid) override; int TerminateAbilityByCaller(const sptr& callerToken, int requestCode) override diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 930d9b078b4..f33456841fd 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -86,6 +86,7 @@ public: int StopServiceAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); -- Gitee From b2d94b7cd38d82ee8416142cef29a1b715d09597 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 15 Dec 2022 01:03:21 +0000 Subject: [PATCH 17/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_manager_stub_mock_test.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h index 49bf5375f74..c60344bc182 100644 --- a/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h @@ -158,6 +158,11 @@ public: return 0; } + virtual int KillProcessSelf() + { + return 0; + } + virtual int UninstallApp(const std::string& bundleName, int32_t uid) { return 0; -- Gitee From 5598fcb1c2160bd2f0f9e0a7373aac7ba64d6041 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 15 Dec 2022 01:24:03 +0000 Subject: [PATCH 18/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- tools/test/mock/mock_ability_manager_stub.h | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 1e3eb470f69..c78e922b629 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -63,6 +63,7 @@ public: MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD0(KillProcessSelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( -- Gitee From 359ff9982f871edecf19383a1e1e2d17c3220271 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 15 Dec 2022 02:13:39 +0000 Subject: [PATCH 19/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../js/napi/app/app_manager/js_app_manager.cpp | 14 +++++++------- .../include/ability_manager_client.h | 2 +- .../include/ability_manager_interface.h | 5 ++++- .../abilitymgr/include/ability_manager_proxy.h | 2 +- .../abilitymgr/include/ability_manager_service.h | 2 +- services/abilitymgr/include/ability_manager_stub.h | 1 + services/abilitymgr/src/ability_manager_client.cpp | 4 ++-- services/abilitymgr/src/ability_manager_proxy.cpp | 4 ++-- .../abilitymgr/src/ability_manager_service.cpp | 2 +- services/abilitymgr/src/ability_manager_stub.cpp | 11 +++++++++++ .../AMS/mock_serviceability_manager_service.h | 2 +- .../include/mock_ability_manager_service.h | 2 +- .../mock_ability_delegator_stub.h | 4 ++-- .../include/mock_ability_mgr_service.h | 2 +- .../AMS/mock_ability_manager_service.h | 2 +- .../AMS/mock_serviceability_manager_service.h | 2 +- .../mock/include/mock_ability_mgr_service.h | 2 +- .../ability_manager_stub_mock_test.h | 2 +- .../ability_manager_stub_mock.h | 2 +- .../ability_manager_stub_impl_mock.h | 2 +- .../ability_manager_stub_mock.h | 2 +- tools/test/mock/mock_ability_manager_stub.h | 2 +- 22 files changed, 44 insertions(+), 29 deletions(-) diff --git a/frameworks/js/napi/app/app_manager/js_app_manager.cpp b/frameworks/js/napi/app/app_manager/js_app_manager.cpp index d58a60c4db3..bf897746406 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -102,10 +102,10 @@ public: return (me != nullptr) ? me->OnkillProcessByBundleName(*engine, *info) : nullptr; } - static NativeValue* KillProcessSelf(NativeEngine* engine, NativeCallbackInfo* info) + static NativeValue* KillProcessBySelf(NativeEngine* engine, NativeCallbackInfo* info) { JsAppManager* me = CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnkillProcessSelf(*engine, *info) : nullptr; + return (me != nullptr) ? me->OnkillProcessBySelf(*engine, *info) : nullptr; } static NativeValue* ClearUpApplicationData(NativeEngine* engine, NativeCallbackInfo* info) @@ -377,7 +377,7 @@ private: return result; } - NativeValue* OnkillProcessSelf(NativeEngine &engine, const NativeCallbackInfo &info) + NativeValue* OnkillProcessBySelf(NativeEngine &engine, const NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); int32_t errCode = 0; @@ -401,7 +401,7 @@ private: task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "abilityManager nullptr")); return; } - auto ret = abilityManager->KillProcessSelf(); + auto ret = abilityManager->KillProcessBySelf(); if (ret == 0) { task.Resolve(engine, CreateJsValue(engine, ret)); } else { @@ -410,7 +410,7 @@ private: }; NativeValue* result = nullptr; - AsyncTask::Schedule("JSAppManager::OnkillProcessSelf", + AsyncTask::Schedule("JSAppManager::OnkillProcessBySelf", engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); return result; } @@ -624,8 +624,8 @@ NativeValue* JsAppManagerInit(NativeEngine* engine, NativeValue* exportObj) JsAppManager::KillProcessWithAccount); BindNativeFunction(*engine, *object, "killProcessesByBundleName", moduleName, JsAppManager::KillProcessesByBundleName); - BindNativeFunction(*engine, *object, "killProcessSelf", moduleName, - JsAppManager::KillProcessSelf); + BindNativeFunction(*engine, *object, "killProcessBySelf", moduleName, + JsAppManager::KillProcessBySelf); BindNativeFunction(*engine, *object, "clearUpApplicationData", moduleName, JsAppManager::ClearUpApplicationData); BindNativeFunction(*engine, *object, "getAppMemorySize", moduleName, diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_client.h b/interfaces/inner_api/ability_manager/include/ability_manager_client.h index 8636c86ca6e..d246c322e6b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -346,7 +346,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - ErrCode KillProcessSelf(); + ErrCode KillProcessBySelf(); #ifdef ABILITY_COMMAND_FOR_TEST /** diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 47190ed5bf5..c52713c0282 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -379,7 +379,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf() = 0; + virtual int KillProcessBySelf() = 0; #ifdef ABILITY_COMMAND_FOR_TEST /** @@ -867,6 +867,9 @@ public: // stop extension ability (61) STOP_EXTENSION_ABILITY, + // kill process itself (62) + KILL_PROCESS_SELF, + // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 616d594edc1..3f9d3f8a447 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -321,7 +321,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf() override; + virtual int KillProcessBySelf() override; #ifdef ABILITY_COMMAND_FOR_TEST /** diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 1794d96f3b4..2cbf5daec37 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -437,7 +437,7 @@ public: * * @return Returns ERR_OK on success, others on failure. */ - virtual int KillProcessSelf() override; + virtual int KillProcessBySelf() override; /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 1c9ff1666a7..db377cd949b 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -80,6 +80,7 @@ private: int AcquireDataAbilityInner(MessageParcel &data, MessageParcel &reply); int ReleaseDataAbilityInner(MessageParcel &data, MessageParcel &reply); int KillProcessInner(MessageParcel &data, MessageParcel &reply); + int KillProcessBySelfInner(MessageParcel &data, MessageParcel &reply); int UninstallAppInner(MessageParcel &data, MessageParcel &reply); int StartAbilityInner(MessageParcel &data, MessageParcel &reply); int StartExtensionAbilityInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 0509c095980..e574bba8cdd 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -359,12 +359,12 @@ ErrCode AbilityManagerClient::KillProcess(const std::string &bundleName) return abms->KillProcess(bundleName); } -ErrCode AbilityManagerClient::KillProcessSelf() +ErrCode AbilityManagerClient::KillProcessBySelf() { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->KillProcessSelf(); + return abms->KillProcessBySelf(); } #ifdef ABILITY_COMMAND_FOR_TEST diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index b0b879f1c1f..08712f67a95 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -998,7 +998,7 @@ int AbilityManagerProxy::KillProcess(const std::string &bundleName) return reply.ReadInt32(); } -int AbilityManagerProxy::KillProcessSelf() +int AbilityManagerProxy::KillProcessBySelf() { MessageParcel data; MessageParcel reply; @@ -1007,7 +1007,7 @@ int AbilityManagerProxy::KillProcessSelf() if (!WriteInterfaceToken(data)) { return INNER_ERR; } - int error = Remote()->SendRequest(IAbilityManager::KILL_PROCESS, data, reply, option); + int error = Remote()->SendRequest(IAbilityManager::KILL_PROCESS_SELF, data, reply, option); if (error != NO_ERROR) { HILOG_ERROR("Send request error: %{public}d", error); return error; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 36371acf8e8..40a09589bf2 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3285,7 +3285,7 @@ int AbilityManagerService::KillProcess(const std::string &bundleName) return ERR_OK; } -int AbilityManagerService::KillProcessSelf() +int AbilityManagerService::KillProcessBySelf() { HILOG_DEBUG("Kill process by self"); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 4192d082c45..145bfaa4101 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -52,6 +52,7 @@ void AbilityManagerStub::FirstStepInit() requestFuncMap_[ACQUIRE_DATA_ABILITY] = &AbilityManagerStub::AcquireDataAbilityInner; requestFuncMap_[RELEASE_DATA_ABILITY] = &AbilityManagerStub::ReleaseDataAbilityInner; requestFuncMap_[KILL_PROCESS] = &AbilityManagerStub::KillProcessInner; + requestFuncMap_[KILL_PROCESS_SELF] = &AbilityManagerStub::KillProcessBySelfInner; requestFuncMap_[UNINSTALL_APP] = &AbilityManagerStub::UninstallAppInner; requestFuncMap_[START_ABILITY] = &AbilityManagerStub::StartAbilityInner; requestFuncMap_[START_ABILITY_ADD_CALLER] = &AbilityManagerStub::StartAbilityAddCallerInner; @@ -342,6 +343,16 @@ int AbilityManagerStub::KillProcessInner(MessageParcel &data, MessageParcel &rep return NO_ERROR; } +int AbilityManagerStub::KillProcessBySelfInner(MessageParcel &data, MessageParcel &reply) +{ + int result = KillProcessBySelf(); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("remove stack error"); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply) { std::string bundleName = Str16ToStr8(data.ReadString16()); diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index fdcca4eae80..b9dc85f94e5 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -93,7 +93,7 @@ public: int ReleaseCall(const sptr& connect, const AppExecFwk::ElementName& element) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index d9b6f7b2a0b..c6bad07e2ff 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -150,7 +150,7 @@ public: int KillProcess(const std::string& bundleName) override; - int KillProcessSelf() override; + int KillProcessBySelf() override; int UninstallApp(const std::string& bundleName, int32_t uid) override; diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index bd2ade77f28..540cc9e5eef 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -64,7 +64,7 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); @@ -202,7 +202,7 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h index e31d2d74a97..8acd8318859 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h @@ -55,7 +55,7 @@ public: MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD1(TerminateAbilityByRecordId, int(const int64_t recordId)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index f33456841fd..04e4bea7161 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -86,7 +86,7 @@ public: int StopServiceAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index 9e7bfe0de84..a0e91b76b42 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -87,7 +87,7 @@ public: int TerminateAbilityByCaller(const sptr& callerToken, int requestCode) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index a1c29542c45..d5c1c448945 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -58,7 +58,7 @@ public: MOCK_METHOD2(StopServiceAbility, int(const Want&, int32_t userId)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD1(KillProcess, int(const std::string&)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD2( diff --git a/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h index c60344bc182..fd13d4e007c 100644 --- a/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h @@ -158,7 +158,7 @@ public: return 0; } - virtual int KillProcessSelf() + virtual int KillProcessBySelf() { return 0; } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index fed37dbf83a..b687465bcf3 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -164,7 +164,7 @@ public: return 0; } - virtual int KillProcessSelf() + virtual int KillProcessBySelf() { return 0; } diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 8d4b6f30d93..0888b433c56 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -197,7 +197,7 @@ public: return 0; } - virtual int KillProcessSelf() + virtual int KillProcessBySelf() { return 0; } diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 47e4bc38889..8da04bcdcdb 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -58,7 +58,7 @@ public: MOCK_METHOD2(TerminateAbilityResult, int(const sptr&, int)); MOCK_METHOD1(StopServiceAbility, int(const Want&)); MOCK_METHOD1(KillProcess, int(const std::string&)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index c78e922b629..bea3ce9f0ce 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -63,7 +63,7 @@ public: MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessSelf, int()); + MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( -- Gitee From 7f019722e854531e7efaf3c6835887b277d998a0 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 15 Dec 2022 06:40:02 +0000 Subject: [PATCH 20/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../include/mock_ability_manager_service.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp index 7208303ae42..f2d018f5c21 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp @@ -150,6 +150,11 @@ int MockAbilityManagerService::KillProcess(const std::string& bundleName) return 0; } +int MockAbilityManagerService::KillProcessBySelf() +{ + return 0; +} + int MockAbilityManagerService::UninstallApp(const std::string& bundleName, int32_t uid) { return 0; -- Gitee From 5ecfb832d9e8f7e435351a1b99e57476b3c0452b Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 15 Dec 2022 07:32:12 +0000 Subject: [PATCH 21/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_manager_client_test.cpp | 11 +++++++++++ .../ability_manager_proxy_test.cpp | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp b/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp index 2985ca8f018..dbb234040d5 100644 --- a/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp +++ b/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp @@ -591,6 +591,17 @@ HWTEST_F(AbilityManagerClientTest, KillProcess_0100, TestSize.Level1) EXPECT_EQ(ERR_OK, result); } +/** + * @tc.name: AbilityManagerClient_KillProcessSelf_0100 + * @tc.desc: KillProcessSelf + * @tc.type: FUNC + */ +HWTEST_F(AbilityManagerClientTest, KillProcessSelf_0100, TestSize.Level1) +{ + auto result = client_->KillProcessSelf(); + EXPECT_EQ(ERR_OK, result); +} + /** * @tc.name: AbilityManagerClient_GetPendingWantUid_0100 * @tc.desc: GetPendingWantUid diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index 76b01e707d4..3b1dcefb72d 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1027,6 +1027,24 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcess_001, TestSize. EXPECT_EQ(res, NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: KillProcessSelf + * SubFunction: NA + * FunctionPoints: AbilityManagerService KillProcessSelf + * EnvConditions: NA + * CaseDescription: Verify the normal process of KillProcessSelf + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcessSelf_001, TestSize.Level1) +{ + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); + auto res = proxy_->KillProcessSelf(); + EXPECT_EQ(IAbilityManager::KILL_PROCESS_SELF, mock_->code_); + EXPECT_EQ(res, NO_ERROR); +} + #ifdef ABILITY_COMMAND_FOR_TEST /* * Feature: AbilityManagerService -- Gitee From a7a8bab1f4bf3a13215c422e5edcff1a80eb0be2 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 15 Dec 2022 07:51:25 +0000 Subject: [PATCH 22/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_manager_client_test.cpp | 8 ++++---- .../ability_manager_proxy_test.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp b/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp index dbb234040d5..c43678316ab 100644 --- a/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp +++ b/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp @@ -592,13 +592,13 @@ HWTEST_F(AbilityManagerClientTest, KillProcess_0100, TestSize.Level1) } /** - * @tc.name: AbilityManagerClient_KillProcessSelf_0100 - * @tc.desc: KillProcessSelf + * @tc.name: AbilityManagerClient_KillProcessBySelf_0100 + * @tc.desc: KillProcessBySelf * @tc.type: FUNC */ -HWTEST_F(AbilityManagerClientTest, KillProcessSelf_0100, TestSize.Level1) +HWTEST_F(AbilityManagerClientTest, KillProcessBySelf_0100, TestSize.Level1) { - auto result = client_->KillProcessSelf(); + auto result = client_->KillProcessBySelf(); EXPECT_EQ(ERR_OK, result); } diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index 3b1dcefb72d..d961acaa505 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1029,18 +1029,18 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcess_001, TestSize. /* * Feature: AbilityManagerService - * Function: KillProcessSelf + * Function: KillProcessBySelf * SubFunction: NA - * FunctionPoints: AbilityManagerService KillProcessSelf + * FunctionPoints: AbilityManagerService KillProcessBySelf * EnvConditions: NA - * CaseDescription: Verify the normal process of KillProcessSelf + * CaseDescription: Verify the normal process of KillProcessBySelf */ -HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcessSelf_001, TestSize.Level1) +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcessBySelf_001, TestSize.Level1) { EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) .Times(1) .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - auto res = proxy_->KillProcessSelf(); + auto res = proxy_->KillProcessBySelf(); EXPECT_EQ(IAbilityManager::KILL_PROCESS_SELF, mock_->code_); EXPECT_EQ(res, NO_ERROR); } -- Gitee From 51640fdbf0bcdcb43f2e0ecbda68d99efc1facd6 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 16 Dec 2022 08:34:34 +0000 Subject: [PATCH 23/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../napi/app/app_manager/js_app_manager.cpp | 46 ------------------- .../context/application_context.cpp | 5 ++ .../ability_runtime/context/context_impl.cpp | 26 +++++++++++ .../context/js_application_context_utils.cpp | 45 ++++++++++++++++++ .../include/ability_manager_client.h | 7 --- .../context/application_context.h | 1 + .../ability_runtime/context/context_impl.h | 15 ++++++ .../abilitymgr/src/ability_manager_client.cpp | 8 ---- 8 files changed, 92 insertions(+), 61 deletions(-) diff --git a/frameworks/js/napi/app/app_manager/js_app_manager.cpp b/frameworks/js/napi/app/app_manager/js_app_manager.cpp index bf897746406..e968ef10085 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -102,12 +102,6 @@ public: return (me != nullptr) ? me->OnkillProcessByBundleName(*engine, *info) : nullptr; } - static NativeValue* KillProcessBySelf(NativeEngine* engine, NativeCallbackInfo* info) - { - JsAppManager* me = CheckParamsAndGetThis(engine, info); - return (me != nullptr) ? me->OnkillProcessBySelf(*engine, *info) : nullptr; - } - static NativeValue* ClearUpApplicationData(NativeEngine* engine, NativeCallbackInfo* info) { JsAppManager* me = CheckParamsAndGetThis(engine, info); @@ -377,44 +371,6 @@ private: return result; } - NativeValue* OnkillProcessBySelf(NativeEngine &engine, const NativeCallbackInfo &info) - { - HILOG_INFO("%{public}s is called", __FUNCTION__); - int32_t errCode = 0; - - // only support 0 or 1 params - if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { - HILOG_ERROR("Not enough params"); - errCode = ERR_NOT_OK; - } - - HILOG_INFO("kill self process"); - AsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_, errCode](NativeEngine& engine, AsyncTask& task, - int32_t status) { - if (errCode != 0) { - task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); - return; - } - if (abilityManager == nullptr) { - HILOG_WARN("abilityManager nullptr"); - task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "abilityManager nullptr")); - return; - } - auto ret = abilityManager->KillProcessBySelf(); - if (ret == 0) { - task.Resolve(engine, CreateJsValue(engine, ret)); - } else { - task.Reject(engine, CreateJsError(engine, ret, "kill process by self failed.")); - } - }; - - NativeValue* result = nullptr; - AsyncTask::Schedule("JSAppManager::OnkillProcessBySelf", - engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); - return result; - } - NativeValue* OnClearUpApplicationData(NativeEngine &engine, const NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); @@ -624,8 +580,6 @@ NativeValue* JsAppManagerInit(NativeEngine* engine, NativeValue* exportObj) JsAppManager::KillProcessWithAccount); BindNativeFunction(*engine, *object, "killProcessesByBundleName", moduleName, JsAppManager::KillProcessesByBundleName); - BindNativeFunction(*engine, *object, "killProcessBySelf", moduleName, - JsAppManager::KillProcessBySelf); BindNativeFunction(*engine, *object, "clearUpApplicationData", moduleName, JsAppManager::ClearUpApplicationData); BindNativeFunction(*engine, *object, "getAppMemorySize", moduleName, diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 97a95141df7..aa91d7204ea 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -294,6 +294,11 @@ std::string ApplicationContext::GetFilesDir() return (contextImpl_ != nullptr) ? contextImpl_->GetFilesDir() : ""; } +std::string ApplicationContext::KillApplioationBySelf() +{ + return (contextImpl_ != nullptr) ? contextImpl_->KillApplioationBySelf() : ""; +} + bool ApplicationContext::IsUpdatingConfigurations() { return (contextImpl_ != nullptr) ? contextImpl_->IsUpdatingConfigurations() : false; diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 655ec710eda..274728cabf6 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -32,6 +32,7 @@ #include "sys_mgr_client.h" #include "system_ability_definition.h" #include "bundle_mgr_proxy.h" +#include "ability_mgr_proxy.h" #include "configuration_convertor.h" namespace OHOS { @@ -418,6 +419,23 @@ sptr ContextImpl::GetBundleManager() const return bms; } +sptr ContextImpl::GetAbilityManager() const +{ + HILOG_DEBUG("ContextImpl::GetAbilityManager"); + auto instance = OHOS::DelayedSingleton::GetInstance(); + if (instance == nullptr) { + HILOG_ERROR("failed to get SysMrgClient instance"); + return nullptr; + } + auto abilityObj = instance->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + if (abilityObj == nullptr) { + HILOG_ERROR("failed to get ability manager service"); + return nullptr; + } + sptr ams = iface_cast(abilityObj); + return ams; +} + void ContextImpl::SetApplicationInfo(const std::shared_ptr &info) { if (info == nullptr) { @@ -548,6 +566,14 @@ void ContextImpl::SetConfiguration(const std::shared_ptrKillProcessBySelf(); +} + std::shared_ptr ContextImpl::GetConfiguration() const { return config_; diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 5b67da9b377..c40da17c6a6 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -77,6 +77,7 @@ public: NativeValue* OnGetDatabaseDir(NativeEngine &engine, NativeCallbackInfo &info); NativeValue* OnGetPreferencesDir(NativeEngine &engine, NativeCallbackInfo &info); NativeValue* OnGetBundleCodeDir(NativeEngine &engine, NativeCallbackInfo &info); + NativeValue* OnKillProcessBySelf(NativeEngine &engine, NativeCallbackInfo &info); static NativeValue* GetCacheDir(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue* GetTempDir(NativeEngine *engine, NativeCallbackInfo *info); @@ -86,6 +87,7 @@ public: static NativeValue* GetPreferencesDir(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue* GetBundleCodeDir(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue* GetApplicationContext(NativeEngine *engine, NativeCallbackInfo *info); + static NativeValue* KillProcessBySelf(NativeEngine *engine, NativeCallbackInfo *info); void KeepApplicationContext(std::shared_ptr applicationContext) { @@ -435,6 +437,47 @@ NativeValue *JsApplicationContextUtils::OnGetBundleCodeDir(NativeEngine &engine, return engine.CreateString(path.c_str(), path.length()); } +NativeValue *JsApplicationContextUtils::KillProcessBySelf(NativeEngine *engine, NativeCallbackInfo *info) +{ + HILOG_INFO("JsApplicationContextUtils::KillProcessBySelf is called"); + JsApplicationContextUtils *me = + CheckParamsAndGetThis(engine, info, APPLICATION_CONTEXT_NAME); + return me != nullptr ? me->OnKillProcessBySelf(*engine, *info) : nullptr; +} + +NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine, NativeCallbackInfo &info) +{ + HILOG_INFO("%{public}s is called", __FUNCTION__); + int32_t errCode = 0; + + // only support 0 or 1 params + if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { + HILOG_ERROR("Not enough params"); + errCode = ERR_NOT_OK; + } + + HILOG_INFO("kill self process"); + AsyncTask::CompleteCallback complete = + [errCode](NativeEngine& engine, AsyncTask& task, + int32_t status) { + if (errCode != 0) { + task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); + return; + } + auto ret = applicationContext->KillProcessBySelf(); + if (ret == 0) { + task.Resolve(engine, CreateJsValue(engine, ret)); + } else { + task.Reject(engine, CreateJsError(engine, ret, "kill process by self failed.")); + } + }; + + NativeValue* result = nullptr; + AsyncTask::Schedule("JSAppManager::OnkillProcessBySelf", + engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); + return result; +} + void JsApplicationContextUtils::Finalizer(NativeEngine *engine, void *data, void *hint) { HILOG_INFO("JsApplicationContextUtils::Finalizer is called"); @@ -909,6 +952,8 @@ NativeValue *CreateJsApplicationContext(NativeEngine &engine, std::shared_ptr GetBundleManager() const; + /** + * @brief Obtains an IAbilityManager instance. + * You can use this instance to obtain information about the ability. + * + * @return Returns an IAbilityManager instance. + */ + sptr GetAbilityManager() const; + /** * @brief Set ApplicationInfo * @@ -239,6 +247,13 @@ public: */ void SetConfiguration(const std::shared_ptr &config); + /** + * @brief Kill process itself + * + * @return error code + */ + ErrCode KillProcessBySelf(); + /** * @brief Get the token witch the app launched. * diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index e574bba8cdd..6bab0c1861c 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -359,14 +359,6 @@ ErrCode AbilityManagerClient::KillProcess(const std::string &bundleName) return abms->KillProcess(bundleName); } -ErrCode AbilityManagerClient::KillProcessBySelf() -{ - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - auto abms = GetAbilityManager(); - CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->KillProcessBySelf(); -} - #ifdef ABILITY_COMMAND_FOR_TEST ErrCode AbilityManagerClient::ForceTimeoutForTest(const std::string &abilityName, const std::string &state) { -- Gitee From f52269da3ea97caa20d4138f5db874dae5bdbd30 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 16 Dec 2022 09:05:44 +0000 Subject: [PATCH 24/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../native/appkit/ability_runtime/context/context_impl.cpp | 4 ++-- .../appkit/ability_runtime/context/application_context.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 274728cabf6..a3bffd0533e 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -432,8 +432,8 @@ sptr ContextImpl::GetAbilityManager() const HILOG_ERROR("failed to get ability manager service"); return nullptr; } - sptr ams = iface_cast(abilityObj); - return ams; + sptr abms = iface_cast(abilityObj); + return abms; } void ContextImpl::SetApplicationInfo(const std::shared_ptr &info) diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index 6f920c89ca4..08fbb424385 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -62,7 +62,7 @@ public: std::string GetCacheDir() override; std::string GetTempDir() override; std::string GetFilesDir() override; - std::string KillApplioationBySelf() override; + std::string KillApplioationBySelf(); bool IsUpdatingConfigurations() override; bool PrintDrawnCompleted() override; std::string GetDatabaseDir() override; -- Gitee From 4708f623eac6ca442c433149149cca55e802a31b Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 16 Dec 2022 09:08:21 +0000 Subject: [PATCH 25/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../kits/native/appkit/ability_runtime/context/context_impl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 065a86bf992..8c351b290c1 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -20,6 +20,7 @@ #include "configuration.h" #include "bundle_mgr_interface.h" +#include "ability_manager_interface.h" namespace OHOS { namespace AbilityRuntime { -- Gitee From 48b2f4ba15ad7db8af41e6e0c6bfc6d1c50b39cd Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 03:13:34 +0000 Subject: [PATCH 26/66] test Signed-off-by: gongyuechen --- .../context/application_context.cpp | 4 +-- .../ability_runtime/context/context_impl.cpp | 33 +++++++------------ .../context/js_application_context_utils.cpp | 2 +- .../ability_runtime/context/context_impl.h | 9 ----- .../include/ability_manager_service.h | 7 ---- .../abilitymgr/src/ability_manager_proxy.cpp | 17 ---------- .../src/ability_manager_service.cpp | 25 -------------- .../abilitymgr/src/ability_manager_stub.cpp | 1 - services/abilitymgr/src/app_scheduler.cpp | 13 -------- 9 files changed, 14 insertions(+), 97 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index aa91d7204ea..ebfb0ca61fe 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -294,9 +294,9 @@ std::string ApplicationContext::GetFilesDir() return (contextImpl_ != nullptr) ? contextImpl_->GetFilesDir() : ""; } -std::string ApplicationContext::KillApplioationBySelf() +ErrCode ApplicationContext::KillProcessBySelf() { - return (contextImpl_ != nullptr) ? contextImpl_->KillApplioationBySelf() : ""; + return (contextImpl_ != nullptr) ? contextImpl_->KillProcessBySelf() : INNER_ERR; } bool ApplicationContext::IsUpdatingConfigurations() diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index a3bffd0533e..d44770b5e5b 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -30,9 +30,9 @@ #include "os_account_manager_wrapper.h" #include "parameters.h" #include "sys_mgr_client.h" +#include "app_mgr_clinet.h" #include "system_ability_definition.h" #include "bundle_mgr_proxy.h" -#include "ability_mgr_proxy.h" #include "configuration_convertor.h" namespace OHOS { @@ -419,23 +419,6 @@ sptr ContextImpl::GetBundleManager() const return bms; } -sptr ContextImpl::GetAbilityManager() const -{ - HILOG_DEBUG("ContextImpl::GetAbilityManager"); - auto instance = OHOS::DelayedSingleton::GetInstance(); - if (instance == nullptr) { - HILOG_ERROR("failed to get SysMrgClient instance"); - return nullptr; - } - auto abilityObj = instance->GetSystemAbility(ABILITY_MGR_SERVICE_ID); - if (abilityObj == nullptr) { - HILOG_ERROR("failed to get ability manager service"); - return nullptr; - } - sptr abms = iface_cast(abilityObj); - return abms; -} - void ContextImpl::SetApplicationInfo(const std::shared_ptr &info) { if (info == nullptr) { @@ -566,12 +549,18 @@ void ContextImpl::SetConfiguration(const std::shared_ptrKillProcessBySelf(); + CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); + std::unique_ptr appMgrClient; + int ret = (int)appMgrClient->KillApplicationSelf(); + if (ret != ERR_OK) { + HILOG_ERROR("Fail to kill application."); + return INNER_ERR; + } + + return ERR_OK; } std::shared_ptr ContextImpl::GetConfiguration() const diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index c40da17c6a6..24124e6e3a6 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -465,7 +465,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine return; } auto ret = applicationContext->KillProcessBySelf(); - if (ret == 0) { + if (ret == ERR_OK) { task.Resolve(engine, CreateJsValue(engine, ret)); } else { task.Reject(engine, CreateJsError(engine, ret, "kill process by self failed.")); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 8c351b290c1..070d11e468e 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -20,7 +20,6 @@ #include "configuration.h" #include "bundle_mgr_interface.h" -#include "ability_manager_interface.h" namespace OHOS { namespace AbilityRuntime { @@ -168,14 +167,6 @@ public: */ sptr GetBundleManager() const; - /** - * @brief Obtains an IAbilityManager instance. - * You can use this instance to obtain information about the ability. - * - * @return Returns an IAbilityManager instance. - */ - sptr GetAbilityManager() const; - /** * @brief Set ApplicationInfo * diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 4e93bb344ad..555059eace1 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -432,13 +432,6 @@ public: */ virtual int KillProcess(const std::string &bundleName) override; - /** - * Kill the process Itself. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int KillProcessBySelf() override; - /** * ClearUpApplicationData, call ClearUpApplicationData() through proxy project, * clear the application data. diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index a89bbd050ec..3efef2f6c2f 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -998,23 +998,6 @@ int AbilityManagerProxy::KillProcess(const std::string &bundleName) return reply.ReadInt32(); } -int AbilityManagerProxy::KillProcessBySelf() -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - int error = Remote()->SendRequest(IAbilityManager::KILL_PROCESS_SELF, data, reply, option); - if (error != NO_ERROR) { - HILOG_ERROR("Send request error: %{public}d", error); - return error; - } - return reply.ReadInt32(); -} - #ifdef ABILITY_COMMAND_FOR_TEST int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, const std::string &state) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 4cca8c7dd98..59502bf3613 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3399,31 +3399,6 @@ void AbilityManagerService::GetMaxRestartNum(int &max) } } -int AbilityManagerService::KillProcess(const std::string &bundleName) -{ - HILOG_DEBUG("Kill process, bundleName: %{public}s", bundleName.c_str()); - auto bms = GetBundleManager(); - CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); - int32_t userId = GetUserId(); - AppExecFwk::BundleInfo bundleInfo; - if (!IN_PROCESS_CALL( - bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { - HILOG_ERROR("Failed to get bundle info when kill process."); - return GET_BUNDLE_INFO_FAILED; - } - - if (bundleInfo.isKeepAlive) { - HILOG_ERROR("Can not kill keep alive process."); - return KILL_PROCESS_KEEP_ALIVE; - } - - int ret = DelayedSingleton::GetInstance()->KillApplication(bundleName); - if (ret != ERR_OK) { - return KILL_PROCESS_FAILED; - } - return ERR_OK; -} - int AbilityManagerService::KillProcessBySelf() { HILOG_DEBUG("Kill process by self"); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 62fa10298b4..7a5b8b3d22b 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -52,7 +52,6 @@ void AbilityManagerStub::FirstStepInit() requestFuncMap_[ACQUIRE_DATA_ABILITY] = &AbilityManagerStub::AcquireDataAbilityInner; requestFuncMap_[RELEASE_DATA_ABILITY] = &AbilityManagerStub::ReleaseDataAbilityInner; requestFuncMap_[KILL_PROCESS] = &AbilityManagerStub::KillProcessInner; - requestFuncMap_[KILL_PROCESS_SELF] = &AbilityManagerStub::KillProcessBySelfInner; requestFuncMap_[UNINSTALL_APP] = &AbilityManagerStub::UninstallAppInner; requestFuncMap_[START_ABILITY] = &AbilityManagerStub::StartAbilityInner; requestFuncMap_[START_ABILITY_ADD_CALLER] = &AbilityManagerStub::StartAbilityAddCallerInner; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index da4c1c28cf1..98d5759cb1b 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -201,19 +201,6 @@ int AppScheduler::KillApplication(const std::string &bundleName) return ERR_OK; } -int AppScheduler::KillApplicationSelf() -{ - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); - int ret = (int)appMgrClient_->KillApplicationSelf(); - if (ret != ERR_OK) { - HILOG_ERROR("Fail to kill application."); - return INNER_ERR; - } - - return ERR_OK; -} - int AppScheduler::KillApplicationByUid(const std::string &bundleName, int32_t uid) { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); -- Gitee From c3fc9fced8fdbb18ffdd68ef83217b5357702e68 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 06:20:47 +0000 Subject: [PATCH 27/66] test Signed-off-by: gongyuechen --- .../ability_runtime/context/application_context.cpp | 6 ++++-- .../context/js_application_context_utils.cpp | 7 ++++--- .../include/ability_manager_interface.h | 7 ------- .../ability_runtime/context/application_context.h | 2 +- services/abilitymgr/include/ability_manager_proxy.h | 7 ------- services/abilitymgr/include/app_scheduler.h | 6 ------ services/abilitymgr/src/ability_manager_service.cpp | 11 ----------- 7 files changed, 9 insertions(+), 37 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index ebfb0ca61fe..4a1d5402c8d 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -294,9 +294,11 @@ std::string ApplicationContext::GetFilesDir() return (contextImpl_ != nullptr) ? contextImpl_->GetFilesDir() : ""; } -ErrCode ApplicationContext::KillProcessBySelf() +void ApplicationContext::KillProcessBySelf() { - return (contextImpl_ != nullptr) ? contextImpl_->KillProcessBySelf() : INNER_ERR; + if (contextImpl_ != nullptr) { + contextImpl_-contextImpl_->KillProcessBySelf(); + } } bool ApplicationContext::IsUpdatingConfigurations() diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 24124e6e3a6..2fa54d0aa46 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -30,6 +30,7 @@ namespace OHOS { namespace AbilityRuntime { namespace { constexpr char APPLICATION_CONTEXT_NAME[] = "__application_context_ptr__"; +constexpr size_t ARGC_ZERO = 0; constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_THREE = 3; @@ -453,7 +454,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine // only support 0 or 1 params if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { HILOG_ERROR("Not enough params"); - errCode = ERR_NOT_OK; + errCode = -1; } HILOG_INFO("kill self process"); @@ -465,7 +466,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine return; } auto ret = applicationContext->KillProcessBySelf(); - if (ret == ERR_OK) { + if (ret == 0) { task.Resolve(engine, CreateJsValue(engine, ret)); } else { task.Reject(engine, CreateJsError(engine, ret, "kill process by self failed.")); @@ -475,7 +476,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine NativeValue* result = nullptr; AsyncTask::Schedule("JSAppManager::OnkillProcessBySelf", engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); - return result; + return engine.CreateUndefined(); } void JsApplicationContextUtils::Finalizer(NativeEngine *engine, void *data, void *hint) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 829f2594fd9..cd8054b4c45 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -375,13 +375,6 @@ public: */ virtual int KillProcess(const std::string &bundleName) = 0; - /** - * Kill the process itself immediately. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int KillProcessBySelf() = 0; - #ifdef ABILITY_COMMAND_FOR_TEST /** * force timeout ability. diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index 08fbb424385..aea4375e7d9 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -62,7 +62,6 @@ public: std::string GetCacheDir() override; std::string GetTempDir() override; std::string GetFilesDir() override; - std::string KillApplioationBySelf(); bool IsUpdatingConfigurations() override; bool PrintDrawnCompleted() override; std::string GetDatabaseDir() override; @@ -75,6 +74,7 @@ public: std::shared_ptr GetConfiguration() const override; std::string GetBaseDir() const override; Global::Resource::DeviceType GetDeviceType() const override; + void KillProcessBySelf(); void InitApplicationContext(); void AttachContextImpl(const std::shared_ptr &contextImpl); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index b8952a19cd5..5fd932a555f 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -316,13 +316,6 @@ public: */ virtual int KillProcess(const std::string &bundleName) override; - /** - * Kill the process itself immediately. - * - * @return Returns ERR_OK on success, others on failure. - */ - virtual int KillProcessBySelf() override; - #ifdef ABILITY_COMMAND_FOR_TEST /** * force timeout ability. diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index d119ebaca85..a9b3a31a949 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -212,12 +212,6 @@ public: */ int KillApplication(const std::string &bundleName); - /** - * kill self - * - */ - int KillApplicationSelf(); - /** * kill the application by uid * diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 59502bf3613..fd73138259a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3399,17 +3399,6 @@ void AbilityManagerService::GetMaxRestartNum(int &max) } } -int AbilityManagerService::KillProcessBySelf() -{ - HILOG_DEBUG("Kill process by self"); - - int ret = DelayedSingleton::GetInstance()->KillApplicationSelf(); - if (ret != ERR_OK) { - return KILL_PROCESS_FAILED; - } - return ERR_OK; -} - int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) { HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); -- Gitee From 0aae7d613b02d8d50b9886a4e483f162ec42659d Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 07:10:28 +0000 Subject: [PATCH 28/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 1 + .../ability_runtime/context/application_context.cpp | 2 +- .../appkit/ability_runtime/context/context_impl.cpp | 2 +- .../context/js_application_context_utils.cpp | 3 ++- services/abilitymgr/include/ability_manager_stub.h | 1 - services/abilitymgr/include/app_scheduler.h | 1 - services/abilitymgr/src/ability_manager_stub.cpp | 10 ---------- 7 files changed, 5 insertions(+), 15 deletions(-) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 8786059f7a5..84b814c31e5 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -200,6 +200,7 @@ ohos_shared_library("app_context") { external_deps = [ "ability_base:configuration", "ability_runtime:ability_deps_wrapper", + "ability_runtime:app_manager", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 4a1d5402c8d..83d8f134822 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -297,7 +297,7 @@ std::string ApplicationContext::GetFilesDir() void ApplicationContext::KillProcessBySelf() { if (contextImpl_ != nullptr) { - contextImpl_-contextImpl_->KillProcessBySelf(); + contextImpl_->KillProcessBySelf(); } } diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index d44770b5e5b..919f047c970 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -30,7 +30,7 @@ #include "os_account_manager_wrapper.h" #include "parameters.h" #include "sys_mgr_client.h" -#include "app_mgr_clinet.h" +#include "app_mgr_client.h" #include "system_ability_definition.h" #include "bundle_mgr_proxy.h" #include "configuration_convertor.h" diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 2fa54d0aa46..49f679b4bae 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -459,8 +459,9 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine HILOG_INFO("kill self process"); AsyncTask::CompleteCallback complete = - [errCode](NativeEngine& engine, AsyncTask& task, + [applicationContext_, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { + auto applicationContext = applicationContext_.lock(); if (errCode != 0) { task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); return; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 7e0ad411056..c46c54b7eda 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -80,7 +80,6 @@ private: int AcquireDataAbilityInner(MessageParcel &data, MessageParcel &reply); int ReleaseDataAbilityInner(MessageParcel &data, MessageParcel &reply); int KillProcessInner(MessageParcel &data, MessageParcel &reply); - int KillProcessBySelfInner(MessageParcel &data, MessageParcel &reply); int UninstallAppInner(MessageParcel &data, MessageParcel &reply); int StartAbilityInner(MessageParcel &data, MessageParcel &reply); int StartExtensionAbilityInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index a9b3a31a949..8931e53a692 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -20,7 +20,6 @@ #include #include "ability_info.h" -#include "appmgr/app_mgr_client.h" #include "appmgr/app_state_callback_host.h" #include "appmgr/start_specified_ability_response_stub.h" #include "application_info.h" diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 7a5b8b3d22b..2eec8424440 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -343,16 +343,6 @@ int AbilityManagerStub::KillProcessInner(MessageParcel &data, MessageParcel &rep return NO_ERROR; } -int AbilityManagerStub::KillProcessBySelfInner(MessageParcel &data, MessageParcel &reply) -{ - int result = KillProcessBySelf(); - if (!reply.WriteInt32(result)) { - HILOG_ERROR("remove stack error"); - return ERR_INVALID_VALUE; - } - return NO_ERROR; -} - int AbilityManagerStub::ClearUpApplicationDataInner(MessageParcel &data, MessageParcel &reply) { std::string bundleName = Str16ToStr8(data.ReadString16()); -- Gitee From 2bd4d7d3bd88945163a76676f60150c4f689d415 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 07:38:09 +0000 Subject: [PATCH 29/66] test Signed-off-by: gongyuechen --- .../appkit/ability_runtime/context/context_impl.cpp | 12 +++--------- .../context/js_application_context_utils.cpp | 12 +++--------- services/abilitymgr/include/app_scheduler.h | 1 + 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 919f047c970..8438a453f47 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -549,18 +549,12 @@ void ContextImpl::SetConfiguration(const std::shared_ptr appMgrClient; - int ret = (int)appMgrClient->KillApplicationSelf(); - if (ret != ERR_OK) { - HILOG_ERROR("Fail to kill application."); - return INNER_ERR; - } - - return ERR_OK; + appMgrClient->KillApplicationSelf(); + return; } std::shared_ptr ContextImpl::GetConfiguration() const diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 49f679b4bae..7398830b646 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -456,22 +456,16 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine HILOG_ERROR("Not enough params"); errCode = -1; } - + auto applicationContext = applicationContext_.lock(); HILOG_INFO("kill self process"); AsyncTask::CompleteCallback complete = - [applicationContext_, errCode](NativeEngine& engine, AsyncTask& task, + [applicationContext, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) { - auto applicationContext = applicationContext_.lock(); if (errCode != 0) { task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); return; } - auto ret = applicationContext->KillProcessBySelf(); - if (ret == 0) { - task.Resolve(engine, CreateJsValue(engine, ret)); - } else { - task.Reject(engine, CreateJsError(engine, ret, "kill process by self failed.")); - } + applicationContext->KillProcessBySelf(); }; NativeValue* result = nullptr; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 8931e53a692..a9b3a31a949 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -20,6 +20,7 @@ #include #include "ability_info.h" +#include "appmgr/app_mgr_client.h" #include "appmgr/app_state_callback_host.h" #include "appmgr/start_specified_ability_response_stub.h" #include "application_info.h" -- Gitee From 26161eab105de27ee60687c06e469a84bda37e6f Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 07:56:27 +0000 Subject: [PATCH 30/66] test Signed-off-by: gongyuechen --- .../kits/native/appkit/ability_runtime/context/context_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 070d11e468e..79dd063892d 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -244,7 +244,7 @@ public: * * @return error code */ - ErrCode KillProcessBySelf(); + void KillProcessBySelf(); /** * @brief Get the token witch the app launched. -- Gitee From 3e812cc91812a45e750536e9133247986281bf31 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 08:12:57 +0000 Subject: [PATCH 31/66] test Signed-off-by: gongyuechen --- .../native/appkit/ability_runtime/context/context_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 8438a453f47..c0f6cd78c2f 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -549,7 +549,7 @@ void ContextImpl::SetConfiguration(const std::shared_ptr appMgrClient; -- Gitee From 57e2208689543f6989ef63abaa135cd8f054292a Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 08:45:00 +0000 Subject: [PATCH 32/66] test Signed-off-by: gongyuechen --- .../AMS/mock_serviceability_manager_service.h | 1 - .../include/mock_ability_manager_service.cpp | 5 ----- .../mock_ability_delegator_stub.h | 2 -- .../include/mock_ability_mgr_service.h | 1 - .../AMS/mock_ability_manager_service.h | 1 - .../AMS/mock_serviceability_manager_service.h | 1 - .../mock/include/mock_ability_mgr_service.h | 1 - .../ability_manager_client_test.cpp | 11 ----------- .../ability_manager_stub_mock_test.h | 5 ----- .../ability_manager_proxy_test.cpp | 18 ------------------ .../ability_manager_stub_mock.h | 5 ----- .../ability_manager_stub_impl_mock.h | 5 ----- .../ability_manager_stub_mock.h | 1 - tools/test/mock/mock_ability_manager_stub.h | 1 - 14 files changed, 58 deletions(-) diff --git a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h index b9dc85f94e5..bbabf3b5808 100644 --- a/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.h @@ -93,7 +93,6 @@ public: int ReleaseCall(const sptr& connect, const AppExecFwk::ElementName& element) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp index f2d018f5c21..7208303ae42 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.cpp @@ -150,11 +150,6 @@ int MockAbilityManagerService::KillProcess(const std::string& bundleName) return 0; } -int MockAbilityManagerService::KillProcessBySelf() -{ - return 0; -} - int MockAbilityManagerService::UninstallApp(const std::string& bundleName, int32_t uid) { return 0; diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h index 540cc9e5eef..acaad958b5e 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.h @@ -64,7 +64,6 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); @@ -202,7 +201,6 @@ public: MOCK_METHOD1(RemoveMission, int(int id)); MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h index 8acd8318859..b30cee3d1cb 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_ability_mgr_service.h @@ -55,7 +55,6 @@ public: MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD1(TerminateAbilityByRecordId, int(const int64_t recordId)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h index 04e4bea7161..930d9b078b4 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_ability_manager_service.h @@ -86,7 +86,6 @@ public: int StopServiceAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h index a0e91b76b42..75527be0e17 100644 --- a/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h +++ b/test/mock/frameworks_kits_test/AMS/mock_serviceability_manager_service.h @@ -87,7 +87,6 @@ public: int TerminateAbilityByCaller(const sptr& callerToken, int requestCode) override; MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index d5c1c448945..82e978504be 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -58,7 +58,6 @@ public: MOCK_METHOD2(StopServiceAbility, int(const Want&, int32_t userId)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD1(KillProcess, int(const std::string&)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD2( diff --git a/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp b/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp index c43678316ab..2985ca8f018 100644 --- a/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp +++ b/test/unittest/ability_manager_client_test/ability_manager_client_test.cpp @@ -591,17 +591,6 @@ HWTEST_F(AbilityManagerClientTest, KillProcess_0100, TestSize.Level1) EXPECT_EQ(ERR_OK, result); } -/** - * @tc.name: AbilityManagerClient_KillProcessBySelf_0100 - * @tc.desc: KillProcessBySelf - * @tc.type: FUNC - */ -HWTEST_F(AbilityManagerClientTest, KillProcessBySelf_0100, TestSize.Level1) -{ - auto result = client_->KillProcessBySelf(); - EXPECT_EQ(ERR_OK, result); -} - /** * @tc.name: AbilityManagerClient_GetPendingWantUid_0100 * @tc.desc: GetPendingWantUid diff --git a/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h index fd13d4e007c..49bf5375f74 100644 --- a/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_test/ability_manager_stub_mock_test.h @@ -158,11 +158,6 @@ public: return 0; } - virtual int KillProcessBySelf() - { - return 0; - } - virtual int UninstallApp(const std::string& bundleName, int32_t uid) { return 0; diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp index d961acaa505..76b01e707d4 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp +++ b/test/unittest/ability_manager_proxy_test/ability_manager_proxy_test.cpp @@ -1027,24 +1027,6 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcess_001, TestSize. EXPECT_EQ(res, NO_ERROR); } -/* - * Feature: AbilityManagerService - * Function: KillProcessBySelf - * SubFunction: NA - * FunctionPoints: AbilityManagerService KillProcessBySelf - * EnvConditions: NA - * CaseDescription: Verify the normal process of KillProcessBySelf - */ -HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_KillProcessBySelf_001, TestSize.Level1) -{ - EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) - .Times(1) - .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); - auto res = proxy_->KillProcessBySelf(); - EXPECT_EQ(IAbilityManager::KILL_PROCESS_SELF, mock_->code_); - EXPECT_EQ(res, NO_ERROR); -} - #ifdef ABILITY_COMMAND_FOR_TEST /* * Feature: AbilityManagerService diff --git a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h index b687465bcf3..ae846c95dad 100644 --- a/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -164,11 +164,6 @@ public: return 0; } - virtual int KillProcessBySelf() - { - return 0; - } - virtual int UninstallApp(const std::string& bundleName, int32_t uid) { return 0; diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 0888b433c56..3297c4c602c 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -197,11 +197,6 @@ public: return 0; } - virtual int KillProcessBySelf() - { - return 0; - } - virtual int UninstallApp(const std::string& bundleName, int32_t uid) { return 0; diff --git a/test/unittest/ability_manager_test/ability_manager_stub_mock.h b/test/unittest/ability_manager_test/ability_manager_stub_mock.h index 8da04bcdcdb..5a5bd4dc2d8 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -58,7 +58,6 @@ public: MOCK_METHOD2(TerminateAbilityResult, int(const sptr&, int)); MOCK_METHOD1(StopServiceAbility, int(const Want&)); MOCK_METHOD1(KillProcess, int(const std::string&)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index bea3ce9f0ce..1e3eb470f69 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -63,7 +63,6 @@ public: MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); - MOCK_METHOD0(KillProcessBySelf, int()); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); MOCK_METHOD2( -- Gitee From 9484e9e124f56e82ecf58b292060143ffdd5bf08 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 09:09:21 +0000 Subject: [PATCH 33/66] test Signed-off-by: gongyuechen --- .../include/ability_manager_interface.h | 3 --- .../src/ability_manager_service.cpp | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index cd8054b4c45..31ff2cfef9e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -871,9 +871,6 @@ public: // stop extension ability (61) STOP_EXTENSION_ABILITY, - - // kill process itself (62) - KILL_PROCESS_SELF, SET_COMPONENT_INTERCEPTION, diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index fd73138259a..19cd379b782 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3399,6 +3399,31 @@ void AbilityManagerService::GetMaxRestartNum(int &max) } } +int AbilityManagerService::KillProcess(const std::string &bundleName) +{ + HILOG_DEBUG("Kill process, bundleName: %{public}s", bundleName.c_str()); + auto bms = GetBundleManager(); + CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); + int32_t userId = GetUserId(); + AppExecFwk::BundleInfo bundleInfo; + if (!IN_PROCESS_CALL( + bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo, userId))) { + HILOG_ERROR("Failed to get bundle info when kill process."); + return GET_BUNDLE_INFO_FAILED; + } + + if (bundleInfo.isKeepAlive) { + HILOG_ERROR("Can not kill keep alive process."); + return KILL_PROCESS_KEEP_ALIVE; + } + + int ret = DelayedSingleton::GetInstance()->KillApplication(bundleName); + if (ret != ERR_OK) { + return KILL_PROCESS_FAILED; + } + return ERR_OK; +} + int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) { HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); -- Gitee From 79dd1c5a809cfce6224005863abd3974df029f1e Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 19 Dec 2022 11:03:05 +0000 Subject: [PATCH 34/66] test Signed-off-by: gongyuechen --- .../include/mock_ability_manager_service.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h index c6bad07e2ff..47dd3e50b3b 100644 --- a/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_ability_manager_service.h @@ -150,8 +150,6 @@ public: int KillProcess(const std::string& bundleName) override; - int KillProcessBySelf() override; - int UninstallApp(const std::string& bundleName, int32_t uid) override; int TerminateAbilityByCaller(const sptr& callerToken, int requestCode) override -- Gitee From aa6a2537e2d13b3a133c90fab951deaba3b11da5 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Tue, 20 Dec 2022 12:23:10 +0000 Subject: [PATCH 35/66] test Signed-off-by: gongyuechen --- .../context/application_context.cpp | 5 ++ .../ability_runtime/context/context_impl.cpp | 8 +++ .../context/js_application_context_utils.cpp | 49 ++++++++++++++++++- .../include/ability_manager_interface.h | 2 +- .../include/appmgr/app_mgr_client.h | 9 ++++ .../include/appmgr/app_mgr_interface.h | 9 ++++ .../include/appmgr/app_mgr_proxy.h | 9 ++++ .../app_manager/include/appmgr/app_mgr_stub.h | 1 + .../app_manager/src/appmgr/app_mgr_client.cpp | 16 ++++++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 26 ++++++++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 19 +++++++ .../context/application_context.h | 1 + .../ability_runtime/context/context_impl.h | 7 +++ services/appmgr/include/app_mgr_service.h | 10 ++++ .../appmgr/include/app_mgr_service_inner.h | 9 ++++ services/appmgr/src/app_mgr_service.cpp | 8 +++ services/appmgr/src/app_mgr_service_inner.cpp | 12 +++++ 17 files changed, 197 insertions(+), 3 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 83d8f134822..bd822546833 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -301,6 +301,11 @@ void ApplicationContext::KillProcessBySelf() } } +ErrCode ApplicationContext::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) +{ + return (contextImpl_ != nullptr) ? contextImpl_->GetProcessRunningInformation(info) : nullptr; +} + bool ApplicationContext::IsUpdatingConfigurations() { return (contextImpl_ != nullptr) ? contextImpl_->IsUpdatingConfigurations() : false; diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index c0f6cd78c2f..acbeb173c0d 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -557,6 +557,14 @@ void ContextImpl::KillProcessBySelf() return; } +void ContextImpl::GetProcessRunningInformation(const AppExecFwk::RunningProcessInfo &info) +{ + HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); + std::unique_ptr appMgrClient; + appMgrClient->GetProcessRunningInformation(info); + return; +} + std::shared_ptr ContextImpl::GetConfiguration() const { return config_; diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 7398830b646..f0cbcc1b05d 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -79,6 +79,7 @@ public: NativeValue* OnGetPreferencesDir(NativeEngine &engine, NativeCallbackInfo &info); NativeValue* OnGetBundleCodeDir(NativeEngine &engine, NativeCallbackInfo &info); NativeValue* OnKillProcessBySelf(NativeEngine &engine, NativeCallbackInfo &info); + NativeValue* OnGetProcessRunningInformation(NativeEngine &engine, NativeCallbackInfo &info); static NativeValue* GetCacheDir(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue* GetTempDir(NativeEngine *engine, NativeCallbackInfo *info); @@ -89,6 +90,7 @@ public: static NativeValue* GetBundleCodeDir(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue* GetApplicationContext(NativeEngine *engine, NativeCallbackInfo *info); static NativeValue* KillProcessBySelf(NativeEngine *engine, NativeCallbackInfo *info); + static NativeValue* GetProcessRunningInformation(NativeEngine *engine, NativeCallbackInfo *info); void KeepApplicationContext(std::shared_ptr applicationContext) { @@ -467,13 +469,54 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine } applicationContext->KillProcessBySelf(); }; - - NativeValue* result = nullptr; AsyncTask::Schedule("JSAppManager::OnkillProcessBySelf", engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); return engine.CreateUndefined(); } +NativeValue *JsApplicationContextUtils::GetProcessRunningInformation(NativeEngine *engine, NativeCallbackInfo *info) +{ + HILOG_INFO("JsApplicationContextUtils::GetProcessRunningInformation is called"); + JsApplicationContextUtils *me = + CheckParamsAndGetThis(engine, info, APPLICATION_CONTEXT_NAME); + return me != nullptr ? me->OnGetProcessRunningInformation(*engine, *info) : nullptr; +} + +NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEngine &engine, NativeCallbackInfo &info) +{ + HILOG_INFO("%{public}s is called", __FUNCTION__); + int32_t errCode = 0; + + // only support 0 or 1 params + if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { + HILOG_ERROR("Not enough params"); + errCode = -1; + } + auto applicationContext = applicationContext_.lock(); + HILOG_INFO("Get Process Info"); + AsyncTask::CompleteCallback complete = + [applicationContext, errCode](NativeEngine& engine, AsyncTask& task, + int32_t status) { + if (errCode != 0) { + task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); + return; + } + AAFwk::AbilityRunningInfo info; + auto ret = applicationContext->GetProcessRunningInformation(&info); + if (ret == 0) { + task.Resolve(engine, CreateJsProcessRunningInfoArray(engine, infos)); + } else { + task.Reject(engine, CreateJsError(engine, ret, "Get mission infos failed.")); + } + }; + + NativeValue* lastParam = (info.argc == ARGC_ONE) ? info.argv[INDEX_ZERO] : nullptr; + NativeValue* result = nullptr; + AsyncTask::Schedule("JSAppManager::OnGetProcessRunningInformation", + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; +} + void JsApplicationContextUtils::Finalizer(NativeEngine *engine, void *data, void *hint) { HILOG_INFO("JsApplicationContextUtils::Finalizer is called"); @@ -950,6 +993,8 @@ NativeValue *CreateJsApplicationContext(NativeEngine &engine, std::shared_ptr &info, int32_t userId); + /** + * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. + * Obtains information about current application processes which is running on the device. + * + * @param info, app name in Application record. + * @return ERR_OK ,return back success,others fail. + */ + virtual AppMgrResultCode GetProcessRunningInformation(RunningProcessInfo &info); + /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. * Notify abilities background the current memory level. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index 08b5a161861..d7d17b26bcd 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -126,6 +126,15 @@ public: */ virtual int GetProcessRunningInfosByUserId(std::vector &info, int32_t userId) = 0; + /** + * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. + * Obtains information about current application process which is running on the device. + * + * @param info, app name in Application record. + * @return ERR_OK ,return back success,others fail. + */ + virtual int GetProcessRunningInformation(RunningProcessInfo &info) = 0; + /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. * Notify abilities background the current memory level. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index d15993ccbf3..4a61bd1e4ea 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -116,6 +116,15 @@ public: */ virtual int32_t GetProcessRunningInfosByUserId(std::vector &info, int32_t userId) override; + /** + * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. + * Obtains information about current application process which is running on the device. + * + * @param info, app name in Application record. + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; + /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. * Notify abilities background the current memory level. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h index b2848afed92..98081fdc07c 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_stub.h @@ -66,6 +66,7 @@ private: int32_t HandleClearUpApplicationData(MessageParcel &data, MessageParcel &reply); int32_t HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply); int32_t HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply); + int32_t HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply); int32_t HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyMemoryLevel(MessageParcel &data, MessageParcel &reply); int32_t HandleStartupResidentProcess(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 3f2d088651f..2575f6863cd 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -320,6 +320,22 @@ AppMgrResultCode AppMgrClient::GetProcessRunningInfosByUserId(std::vector service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service != nullptr) { + int32_t result = service->GetProcessRunningInformation(info); + if (result == ERR_OK) { + return AppMgrResultCode::RESULT_OK; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_READY; + } + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; +} + AppMgrResultCode AppMgrClient::NotifyMemoryLevel(MemoryLevel level) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 8b0b8ea36fe..ecc054326ef 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -268,6 +268,32 @@ int32_t AppMgrProxy::GetProcessRunningInfosByUserId(std::vector remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote() is NULL"); + return ERR_NULL_OBJECT; + } + if (!SendTransactCmd(IAppMgr::Message::APP_GET_PROCESS_RUNNING_INFORMATION, data, reply)) { + return ERR_NULL_OBJECT; + } + auto error = GetParcelableInfos(reply, info); + if (error != NO_ERROR) { + HILOG_ERROR("GetParcelableInfos fail, error: %{public}d", error); + return error; + } + int result = reply.ReadInt32(); + return result; +} + int32_t AppMgrProxy::NotifyMemoryLevel(int32_t level) { MessageParcel data; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 5dbad7ae036..a879eb3df45 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -55,6 +55,8 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleNotifyMemoryLevel; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_RUNNING_PROCESSES_BY_USER_ID)] = &AppMgrStub::HandleGetProcessRunningInfosByUserId; + memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_PROCESS_RUNNING_INFORMATION)] = + &AppMgrStub::HandleGetProcessRunningInformation; memberFuncMap_[static_cast(IAppMgr::Message::APP_ADD_ABILITY_STAGE_INFO_DONE)] = &AppMgrStub::HandleAddAbilityStageDone; memberFuncMap_[static_cast(IAppMgr::Message::STARTUP_RESIDENT_PROCESS)] = @@ -241,6 +243,23 @@ int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, Me return NO_ERROR; } +int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply) +{ + HITRACE_METER(HITRACE_TAG_APP); + std::vector info; + auto result = GetProcessRunningInformation(&info); + reply.WriteInt32(info.size()); + for (auto &it : info) { + if (!reply.WriteParcelable(&it)) { + return ERR_INVALID_VALUE; + } + } + if (!reply.WriteInt32(result)) { + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply) { int32_t recordId = data.ReadInt32(); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index aea4375e7d9..04d8909bb4e 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -75,6 +75,7 @@ public: std::string GetBaseDir() const override; Global::Resource::DeviceType GetDeviceType() const override; void KillProcessBySelf(); + ErrCode GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) void InitApplicationContext(); void AttachContextImpl(const std::shared_ptr &contextImpl); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 79dd063892d..2d506a1762e 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -246,6 +246,13 @@ public: */ void KillProcessBySelf(); + /** + * @brief Get running informationfor cuirrent process + * + * @return error code + */ + void GetProcessRunningInformation(const AppExecFwk::RunningProcessInfo &info); + /** * @brief Get the token witch the app launched. * diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index d1420c47a68..e5041f8009b 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -134,6 +134,16 @@ public: */ virtual int32_t GetProcessRunningInfosByUserId(std::vector &info, int32_t userId) override; + /** + * GetProcessRunningInformation, call GetProcessRunningInformation() through proxy project. + * Obtains information about current application process which is running on the device. + * + * @param info, app name in Application record. + * + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; + /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. * Notify applications background the current memory level. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 7fc75d31e22..84c91da037c 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -256,6 +256,15 @@ public: */ virtual int32_t GetProcessRunningInfosByUserId(std::vector &info, int32_t userId); + /** + * GetProcessRunningInfosByUserId, Obtains information about current application process which is running on the device. + * + * @param info, app name in Application record. + * + * @return ERR_OK ,return back success,others fail. + */ + virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info); + /** * NotifyMemoryLevel, Notify applications background the current memory level. * diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index b8c444e1044..ebde6cc5b74 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -302,6 +302,14 @@ int32_t AppMgrService::GetProcessRunningInfosByUserId(std::vectorGetProcessRunningInfosByUserId(info, userId); } +int32_t AppMgrService::GetProcessRunningInformation(std::vector &info) +{ + if (!IsReady()) { + return ERR_INVALID_OPERATION; + } + return appMgrServiceInner_->GetProcessRunningInformation(info); +} + int32_t AppMgrService::NotifyMemoryLevel(int32_t level) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 76f8290ccdd..d533203db31 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -736,6 +736,18 @@ int32_t AppMgrServiceInner::GetProcessRunningInfosByUserId(std::vector Date: Tue, 20 Dec 2022 12:40:58 +0000 Subject: [PATCH 36/66] test Signed-off-by: gongyuechen --- .../appkit/ability_runtime/context/application_context.h | 3 ++- .../kits/native/appkit/ability_runtime/context/context_impl.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index 04d8909bb4e..4fe71831be6 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -23,6 +23,7 @@ #include "context.h" #include "context_impl.h" #include "environment_callback.h" +#include "running_process_info.h" namespace OHOS { namespace AbilityRuntime { @@ -75,7 +76,7 @@ public: std::string GetBaseDir() const override; Global::Resource::DeviceType GetDeviceType() const override; void KillProcessBySelf(); - ErrCode GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) + ErrCode GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info); void InitApplicationContext(); void AttachContextImpl(const std::shared_ptr &contextImpl); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 2d506a1762e..8d3b965a1e8 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -20,6 +20,7 @@ #include "configuration.h" #include "bundle_mgr_interface.h" +#include "running_process_info.h" namespace OHOS { namespace AbilityRuntime { -- Gitee From 39abca2e472ad22a9be8c046088aa773bb8a7f58 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 01:17:56 +0000 Subject: [PATCH 37/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 84b814c31e5..7060952b9ab 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -175,6 +175,7 @@ ohos_shared_library("app_context") { "${ability_base_kits_path}/extractortool/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${ability_runtime_services_path}/appmgr/include", ] configs = [ ":appkit_config" ] -- Gitee From 705869bb3ff20bc5f631c1d37ce8a8fd39159037 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 01:41:11 +0000 Subject: [PATCH 38/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 7060952b9ab..6dedaaa8aca 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -175,7 +175,6 @@ ohos_shared_library("app_context") { "${ability_base_kits_path}/extractortool/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/app", - "${ability_runtime_services_path}/appmgr/include", ] configs = [ ":appkit_config" ] @@ -227,6 +226,7 @@ ohos_shared_library("app_context_utils") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", + "${ability_runtime_services_path}/appmgr/include", ] configs = [ ":appkit_config" ] -- Gitee From 68397673bb8cb9da2d650fa4b43d486503e97839 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 01:52:44 +0000 Subject: [PATCH 39/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 6dedaaa8aca..e38f1b8f7df 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -175,6 +175,7 @@ ohos_shared_library("app_context") { "${ability_base_kits_path}/extractortool/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${ability_runtime_services_path}/appmgr/include", ] configs = [ ":appkit_config" ] -- Gitee From b45c583ca41f1c0daa0b006dc18be682673d8d3f Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 02:20:28 +0000 Subject: [PATCH 40/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index e38f1b8f7df..eb41964487c 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -188,6 +188,7 @@ ohos_shared_library("app_context") { "${ability_runtime_native_path}/appkit/ability_runtime/context/context_impl.cpp", "${ability_runtime_native_path}/appkit/ability_runtime/context/environment_callback.cpp", "${ability_runtime_native_path}/appkit/app/sys_mgr_client.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", ] cflags = [] if (target_cpu == "arm") { @@ -235,6 +236,7 @@ ohos_shared_library("app_context_utils") { public_configs = [ ":appkit_public_config" ] sources = [ + "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", "ability_runtime/context/js_application_context_utils.cpp", "ability_runtime/context/js_context_utils.cpp", "ability_runtime/context/js_hap_module_info_utils.cpp", -- Gitee From 8640c079b6405a75a4b079e48d12bc4c1588f89d Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 02:45:22 +0000 Subject: [PATCH 41/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index eb41964487c..745e6286193 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -173,6 +173,7 @@ ohos_shared_library("appkit_native") { ohos_shared_library("app_context") { include_dirs = [ "${ability_base_kits_path}/extractortool/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native/", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_services_path}/appmgr/include", @@ -188,7 +189,6 @@ ohos_shared_library("app_context") { "${ability_runtime_native_path}/appkit/ability_runtime/context/context_impl.cpp", "${ability_runtime_native_path}/appkit/ability_runtime/context/environment_callback.cpp", "${ability_runtime_native_path}/appkit/app/sys_mgr_client.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", ] cflags = [] if (target_cpu == "arm") { @@ -201,6 +201,7 @@ ohos_shared_library("app_context") { external_deps = [ "ability_base:configuration", + "ability_base:zuri", "ability_runtime:ability_deps_wrapper", "ability_runtime:app_manager", "ability_runtime:runtime", @@ -236,7 +237,6 @@ ohos_shared_library("app_context_utils") { public_configs = [ ":appkit_public_config" ] sources = [ - "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", "ability_runtime/context/js_application_context_utils.cpp", "ability_runtime/context/js_context_utils.cpp", "ability_runtime/context/js_hap_module_info_utils.cpp", -- Gitee From bdf40acf1475e127c7306a0cddcef5c4acce8865 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 03:20:53 +0000 Subject: [PATCH 42/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 745e6286193..3c547c305e8 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -194,7 +194,9 @@ ohos_shared_library("app_context") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [] + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + ] public_deps = [ "${global_path}/resource_management/frameworks/resmgr:global_resmgr" ] @@ -229,7 +231,6 @@ ohos_shared_library("app_context_utils") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", - "${ability_runtime_services_path}/appmgr/include", ] configs = [ ":appkit_config" ] -- Gitee From 66a2799ce00b1380a777fffa20f8745d9475e253 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 21 Dec 2022 06:58:11 +0000 Subject: [PATCH 43/66] test Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 3c547c305e8..84b814c31e5 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -173,10 +173,8 @@ ohos_shared_library("appkit_native") { ohos_shared_library("app_context") { include_dirs = [ "${ability_base_kits_path}/extractortool/include", - "${ability_runtime_path}/interfaces/kits/native/ability/native/", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", "${ability_runtime_path}/interfaces/kits/native/appkit/app", - "${ability_runtime_services_path}/appmgr/include", ] configs = [ ":appkit_config" ] @@ -194,16 +192,13 @@ ohos_shared_library("app_context") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ - "${ability_runtime_innerkits_path}/app_manager:app_manager", - ] + deps = [] public_deps = [ "${global_path}/resource_management/frameworks/resmgr:global_resmgr" ] external_deps = [ "ability_base:configuration", - "ability_base:zuri", "ability_runtime:ability_deps_wrapper", "ability_runtime:app_manager", "ability_runtime:runtime", -- Gitee From e7566cc1d8937f4f9587fa3e1d203e7026b3b115 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 22 Dec 2022 03:02:03 +0000 Subject: [PATCH 44/66] test Signed-off-by: gongyuechen --- .../native/appkit/ability_runtime/context/context_impl.cpp | 4 ++-- .../inner_api/app_manager/include/appmgr/app_mgr_interface.h | 1 + .../inner_api/app_manager/src/appmgr/app_mgr_client.cpp | 2 +- interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp | 2 +- interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp | 2 +- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- .../include/mock_app_mgr_service.h | 1 + test/mock/services_appmgr_test/include/mock_app_mgr_service.h | 1 + 8 files changed, 9 insertions(+), 6 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index acbeb173c0d..7dc791e508c 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -552,7 +552,7 @@ void ContextImpl::SetConfiguration(const std::shared_ptr appMgrClient; + auto appMgrClient = DelayedSingleton::GetInstance(); appMgrClient->KillApplicationSelf(); return; } @@ -560,7 +560,7 @@ void ContextImpl::KillProcessBySelf() void ContextImpl::GetProcessRunningInformation(const AppExecFwk::RunningProcessInfo &info) { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - std::unique_ptr appMgrClient; + auto appMgrClient = DelayedSingleton::GetInstance(); appMgrClient->GetProcessRunningInformation(info); return; } diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index d7d17b26bcd..c6174361d94 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -319,6 +319,7 @@ public: APP_GET_MGR_INSTANCE, APP_CLEAR_UP_APPLICATION_DATA, APP_GET_ALL_RUNNING_PROCESSES, + APP_GET_PROCESS_RUNNING_INFORMATION, APP_GET_RUNNING_PROCESSES_BY_USER_ID, APP_ADD_ABILITY_STAGE_INFO_DONE, STARTUP_RESIDENT_PROCESS, diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 2575f6863cd..e95f5571b05 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -323,7 +323,7 @@ AppMgrResultCode AppMgrClient::GetProcessRunningInfosByUserId(std::vector service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index ecc054326ef..b77e834ec65 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -268,7 +268,7 @@ int32_t AppMgrProxy::GetProcessRunningInfosByUserId(std::vector &info) { MessageParcel data; MessageParcel reply; diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index a879eb3df45..bae27de02ba 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -247,7 +247,7 @@ int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, Mess { HITRACE_METER(HITRACE_TAG_APP); std::vector info; - auto result = GetProcessRunningInformation(&info); + auto result = GetProcessRunningInformation(info); reply.WriteInt32(info.size()); for (auto &it : info) { if (!reply.WriteParcelable(&it)) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index d533203db31..1606098288d 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -736,7 +736,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInfosByUserId(std::vector &info) { if (!appRunningManager_) { HILOG_ERROR("appRunningManager_ is nullptr"); diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 29c796d17d8..c56b090f004 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -39,6 +39,7 @@ public: MOCK_METHOD1(StartupResidentProcess, void(const std::vector& bundleInfos)); MOCK_METHOD1(NotifyMemoryLevel, int(int32_t level)); MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector& info, int32_t userId)); + MOCK_METHOD1(GetProcessRunningInformation, int(std::vector& info)); MOCK_METHOD4(StartUserTestProcess, int(const AAFwk::Want& want, const sptr& observer, const BundleInfo& bundleInfo, int32_t userId)); MOCK_METHOD3(FinishUserTest, int(const std::string& msg, const int64_t& resultCode, diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 841db5cc142..7b94e605eb4 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -42,6 +42,7 @@ public: MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string& bundleName)); MOCK_METHOD1(GetAllRunningProcesses, int(std::vector& info)); MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector& info, int32_t userId)); + MOCK_METHOD1(GetProcessRunningInformation, int(std::vector& info)); MOCK_METHOD0(GetAmsMgr, sptr()); MOCK_METHOD1(GetAppFreezingTime, void(int& time)); MOCK_METHOD1(SetAppFreezingTime, void(int time)); -- Gitee From 8bf2f9c56fcc3489cd8351aa7c9a864dfbed6f6d Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 22 Dec 2022 06:15:17 +0000 Subject: [PATCH 45/66] test Signed-off-by: gongyuechen --- .../inner_api/app_manager/include/appmgr/app_mgr_interface.h | 1 + interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h | 2 +- interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index c6174361d94..b1a2bbb87d0 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -31,6 +31,7 @@ #include "iapplication_state_observer.h" #include "iconfiguration_observer.h" #include "iquick_fix_callback.h" +#include "running_process_info.h" namespace OHOS { namespace AppExecFwk { diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 4a61bd1e4ea..4a856426663 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -123,7 +123,7 @@ public: * @param info, app name in Application record. * @return ERR_OK ,return back success,others fail. */ - virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; + virtual int32_t GetProcessRunningInformation(std::vector &info) override; /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index e95f5571b05..57fabad8580 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -323,7 +323,7 @@ AppMgrResultCode AppMgrClient::GetProcessRunningInfosByUserId(std::vector service = iface_cast(mgrHolder_->GetRemoteObject()); if (service != nullptr) { -- Gitee From 40e6a03ee51b1413b520230c6d269f2627ff6454 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 23 Dec 2022 06:38:29 +0000 Subject: [PATCH 46/66] update frameworks/native/appkit/BUILD.gn. Signed-off-by: gongyuechen --- frameworks/native/appkit/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 84b814c31e5..7042e98dd09 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -249,6 +249,7 @@ ohos_shared_library("app_context_utils") { external_deps = [ "ability_runtime:ability_runtime_error_util", + "ability_runtime:app_manager", "ability_runtime:runtime", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", -- Gitee From 05b003eb97db56019159b2765699e6fc9b2f886c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 23 Dec 2022 06:57:55 +0000 Subject: [PATCH 47/66] update frameworks/native/appkit/ability_runtime/context/context_impl.cpp. Signed-off-by: gongyuechen --- .../native/appkit/ability_runtime/context/context_impl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 0c8d2f60cbf..17db71b31fe 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -34,6 +34,7 @@ #include "system_ability_definition.h" #include "bundle_mgr_proxy.h" #include "configuration_convertor.h" +#include "running_process_info.h" namespace OHOS { namespace AbilityRuntime { -- Gitee From a9b381c6a066d001ee5ec19c4b88512380871b04 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 23 Dec 2022 07:00:55 +0000 Subject: [PATCH 48/66] update interfaces/kits/native/appkit/ability_runtime/context/context_impl.h. Signed-off-by: gongyuechen --- .../kits/native/appkit/ability_runtime/context/context_impl.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 8d3b965a1e8..7ea6a289208 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -20,9 +20,11 @@ #include "configuration.h" #include "bundle_mgr_interface.h" -#include "running_process_info.h" namespace OHOS { +namespace AppExecFwk { +struct RunningProcessInfo; +} namespace AbilityRuntime { class ContextImpl : public Context, public std::enable_shared_from_this { public: -- Gitee From f00bbfb180bdd22bdfbd58c157fb2f351ab05b4d Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 23 Dec 2022 07:46:34 +0000 Subject: [PATCH 49/66] update interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h. Signed-off-by: gongyuechen --- .../inner_api/app_manager/include/appmgr/app_mgr_interface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index b1a2bbb87d0..afb7fa01c10 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -134,7 +134,7 @@ public: * @param info, app name in Application record. * @return ERR_OK ,return back success,others fail. */ - virtual int GetProcessRunningInformation(RunningProcessInfo &info) = 0; + virtual int GetProcessRunningInformation(std::vector &info) = 0; /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. -- Gitee From 18d6cdc7c453fb908e7c431e8172cb14e9d0dfe3 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 23 Dec 2022 07:59:13 +0000 Subject: [PATCH 50/66] update frameworks/native/appkit/ability_runtime/context/application_context.cpp. Signed-off-by: gongyuechen --- .../appkit/ability_runtime/context/application_context.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index bd822546833..5aec89471ed 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -18,6 +18,7 @@ #include #include "hilog_wrapper.h" +#include "running_process_info.h" namespace OHOS { namespace AbilityRuntime { -- Gitee From 3b7a0ab526f1aa1ff2b404b490982ce2341fc9b3 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 23 Dec 2022 08:13:54 +0000 Subject: [PATCH 51/66] update interfaces/kits/native/appkit/ability_runtime/context/application_context.h. Signed-off-by: gongyuechen --- .../native/appkit/ability_runtime/context/application_context.h | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index 4fe71831be6..571edc3d115 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -23,7 +23,6 @@ #include "context.h" #include "context_impl.h" #include "environment_callback.h" -#include "running_process_info.h" namespace OHOS { namespace AbilityRuntime { -- Gitee From bfdf09a81b90dcf9c4bc26534f60bdd712ab21eb Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 11:11:59 +0800 Subject: [PATCH 52/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../context/application_context.cpp | 4 +- .../ability_runtime/context/context_impl.cpp | 11 +-- .../context/js_application_context_utils.cpp | 71 +++++++++++++------ .../include/appmgr/app_mgr_interface.h | 2 +- .../include/appmgr/app_mgr_proxy.h | 2 +- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 2 +- .../context/application_context.h | 2 +- .../ability_runtime/context/context_impl.h | 2 +- .../appmgr/include/app_mgr_service_inner.h | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 47 +++++------- 10 files changed, 78 insertions(+), 66 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index 5aec89471ed..b461aa66598 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -302,9 +302,9 @@ void ApplicationContext::KillProcessBySelf() } } -ErrCode ApplicationContext::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) +int32_t ApplicationContext::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) { - return (contextImpl_ != nullptr) ? contextImpl_->GetProcessRunningInformation(info) : nullptr; + return (contextImpl_ != nullptr) ? contextImpl_->GetProcessRunningInformation(info) : -1; } bool ApplicationContext::IsUpdatingConfigurations() diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 17db71b31fe..06a951a8ed8 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -553,17 +553,18 @@ void ContextImpl::SetConfiguration(const std::shared_ptr::GetInstance(); + auto appMgrClient = std::make_unique(); appMgrClient->KillApplicationSelf(); return; } -void ContextImpl::GetProcessRunningInformation(const AppExecFwk::RunningProcessInfo &info) +int32_t ContextImpl::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) { HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); - auto appMgrClient = DelayedSingleton::GetInstance(); - appMgrClient->GetProcessRunningInformation(info); - return; + auto appMgrClient = std::make_unique(); + auto result = appMgrClient->GetProcessRunningInformation(info); + HILOG_INFO("result is %{public}d.", result); + return result; } std::shared_ptr ContextImpl::GetConfiguration() const diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index f0cbcc1b05d..92e76d347c2 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -25,6 +25,7 @@ #include "js_hap_module_info_utils.h" #include "js_resource_manager_utils.h" #include "js_runtime_utils.h" +#include "running_process_info.h" namespace OHOS { namespace AbilityRuntime { @@ -106,6 +107,8 @@ private: NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, + const AppExecFwk::RunningProcessInfo &info); std::shared_ptr keepApplicationContext_; std::shared_ptr callback_; std::shared_ptr envCallback_; @@ -451,26 +454,29 @@ NativeValue *JsApplicationContextUtils::KillProcessBySelf(NativeEngine *engine, NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine, NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); - int32_t errCode = 0; + auto applicationContext = applicationContext_.lock(); + if(!applicationContext){ + HILOG_WARN("applicationContext if already released"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST); + return engine.CreateUndefined(); + } // only support 0 or 1 params if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { HILOG_ERROR("Not enough params"); - errCode = -1; + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + return engine.CreateUndefined; } - auto applicationContext = applicationContext_.lock(); HILOG_INFO("kill self process"); AsyncTask::CompleteCallback complete = - [applicationContext, errCode](NativeEngine& engine, AsyncTask& task, - int32_t status) { - if (errCode != 0) { - task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); - return; - } - applicationContext->KillProcessBySelf(); + [applicationContext](NativeEngine& engine, AsyncTask& task,int32_t status) { + applicationContext->KillProcessBySelf(); + task.Resolve(engine, engine.CreateUndefined()); }; + NativeValue* lastParam = (info.argc = ARGC_ONE) ? info.argv[INDEX_ZERO] : nullptr; + NativeValue* result = nullptr; AsyncTask::Schedule("JSAppManager::OnkillProcessBySelf", - engine, CreateAsyncTaskWithLastParam(engine, nullptr, nullptr, std::move(complete), &result)); + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); return engine.CreateUndefined(); } @@ -485,28 +491,30 @@ NativeValue *JsApplicationContextUtils::GetProcessRunningInformation(NativeEngin NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEngine &engine, NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); - int32_t errCode = 0; + auto applicationContext = applicationContext_.lock(); + if(!applicationContext){ + HILOG_WARN("applicationContext if already released"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST); + return engine.CreateUndefined(); + } // only support 0 or 1 params if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { HILOG_ERROR("Not enough params"); - errCode = -1; + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + return engine.CreateUndefined; } - auto applicationContext = applicationContext_.lock(); HILOG_INFO("Get Process Info"); AsyncTask::CompleteCallback complete = - [applicationContext, errCode](NativeEngine& engine, AsyncTask& task, + [applicationContext, this](NativeEngine& engine, AsyncTask& task, int32_t status) { - if (errCode != 0) { - task.Reject(engine, CreateJsError(engine, errCode, "Invalidate params.")); - return; - } - AAFwk::AbilityRunningInfo info; - auto ret = applicationContext->GetProcessRunningInformation(&info); + AppExecFwk::RunningProcessInfo processInfo; + auto ret = applicationContext->GetProcessRunningInformation(processInfo); if (ret == 0) { - task.Resolve(engine, CreateJsProcessRunningInfoArray(engine, infos)); + task.Resolve(engine, CreateJsProcessRunningInfo(engine, processInfo)); } else { - task.Reject(engine, CreateJsError(engine, ret, "Get mission infos failed.")); + task.Reject(engine, CreateJsError(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR, + "Get mission infos failed.")); } }; @@ -517,6 +525,23 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng return result; } +NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, + const AppExecFwk::RunningProcessInfo &info) +{ + NativeValue* objValue = engine.CreateObject(); + NativeObject* object = ConvertNativeValueTo(objValue); + + object->SetProperty("processName", CreateJsValue(engine, info.processName_)); + object->SetProperty("pid", CreateJsValue(engine, info.pid_)); + object->SetProperty("uid", CreateJsValue(engine, info.uid_)); + object->SetProperty("bundleNames", CreateJsValue(engine, info.state_)); + object->SetProperty("state", CreateJsValue(engine, info.state_)); + object->SetProperty("isContinuousTask", CreateJsValue(engine, info.isContinuousTask_)); + object->SetProperty("isKeepAlive", CreateJsValue(engine, info.isKeepAlive_)); + object->SetProperty("isFocused", CreateJsValue(engine, info.isFocused_)); + return objValue; +} + void JsApplicationContextUtils::Finalizer(NativeEngine *engine, void *data, void *hint) { HILOG_INFO("JsApplicationContextUtils::Finalizer is called"); diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index afb7fa01c10..b1a2bbb87d0 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -134,7 +134,7 @@ public: * @param info, app name in Application record. * @return ERR_OK ,return back success,others fail. */ - virtual int GetProcessRunningInformation(std::vector &info) = 0; + virtual int GetProcessRunningInformation(RunningProcessInfo &info) = 0; /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h index 4a856426663..4a61bd1e4ea 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_proxy.h @@ -123,7 +123,7 @@ public: * @param info, app name in Application record. * @return ERR_OK ,return back success,others fail. */ - virtual int32_t GetProcessRunningInformation(std::vector &info) override; + virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) override; /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index b77e834ec65..ecc054326ef 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -268,7 +268,7 @@ int32_t AppMgrProxy::GetProcessRunningInfosByUserId(std::vector &info) +int32_t AppMgrProxy::GetProcessRunningInformation(RunningProcessInfo &info) { MessageParcel data; MessageParcel reply; diff --git a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h index 571edc3d115..b790f24aa5c 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -75,7 +75,7 @@ public: std::string GetBaseDir() const override; Global::Resource::DeviceType GetDeviceType() const override; void KillProcessBySelf(); - ErrCode GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info); + int32_t GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info); void InitApplicationContext(); void AttachContextImpl(const std::shared_ptr &contextImpl); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h index 7ea6a289208..1ace51b6ae4 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -254,7 +254,7 @@ public: * * @return error code */ - void GetProcessRunningInformation(const AppExecFwk::RunningProcessInfo &info); + int32_t GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info); /** * @brief Get the token witch the app launched. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 84c91da037c..08efb0442e6 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -741,6 +741,7 @@ private: void InitGlobalConfiguration(); void GetRunningProcesses(const std::shared_ptr &appRecord, std::vector &info); + void GetRunningProcess(const std::shared_ptr &appRecord, RunningProcessInfo &info); int StartRenderProcessImpl(const std::shared_ptr &renderRecord, const std::shared_ptr appRecord, pid_t &renderPid); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 36264140e76..22fad5aaeb5 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -477,28 +477,7 @@ int32_t AppMgrServiceInner::KillApplication(const std::string &bundleName) return errCode; } - int result = ERR_OK; - int64_t startTime = SystemTimeMillisecond(); - std::list pids; - - if (!appRunningManager_->ProcessExitByBundleName(bundleName, pids)) { - HILOG_INFO("The process corresponding to the package name did not start"); - return result; - } - if (WaitForRemoteProcessExit(pids, startTime)) { - HILOG_INFO("The remote process exited successfully "); - NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); - return result; - } - for (auto iter = pids.begin(); iter != pids.end(); ++iter) { - result = KillProcessByPid(*iter); - if (result < 0) { - HILOG_ERROR("KillApplication failed for bundleName:%{public}s pid:%{public}d", bundleName.c_str(), *iter); - return result; - } - } - NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); - return result; + return KillApplicationByBundleName(bundleName); } int32_t AppMgrServiceInner::KillApplicationByUid(const std::string &bundleName, const int uid) @@ -774,18 +753,24 @@ void AppMgrServiceInner::GetRunningProcesses(const std::shared_ptr &info) { RunningProcessInfo runningProcessInfo; - runningProcessInfo.processName_ = appRecord->GetProcessName(); - runningProcessInfo.pid_ = appRecord->GetPriorityObject()->GetPid(); - runningProcessInfo.uid_ = appRecord->GetUid(); - runningProcessInfo.state_ = static_cast(appRecord->GetState()); - runningProcessInfo.isContinuousTask = appRecord->IsContinuousTask(); - runningProcessInfo.isKeepAlive = appRecord->IsKeepAliveApp(); - runningProcessInfo.isFocused = appRecord->GetFocusFlag(); - runningProcessInfo.startTimeMillis_ = appRecord->GetAppStartTime(); - appRecord->GetBundleNames(runningProcessInfo.bundleNames); + GetRunningProcess(appRecord, RunningProcessInfo); info.emplace_back(runningProcessInfo); } +void AppMgrServiceInner::GetRunningProcess(const std::shared_ptr &appRecord, + RunningProcessInfo &info) +{ + info.processName_ = appRecord->GetProcessName(); + info.pid_ = appRecord->GetPriorityObject()->GetPid(); + info.uid_ = appRecord->GetUid(); + info.state_ = static_cast(appRecord->GetState()); + info.isContinuousTask = appRecord->IsContinuousTask(); + info.isKeepAlive = appRecord->IsKeepAliveApp(); + info.isFocused = appRecord->GetFocusFlag(); + info.startTimeMillis_ = appRecord->GetAppStartTime(); + appRecord->GetBundleNames(runningProcessInfo.bundleNames); +} + int32_t AppMgrServiceInner::KillProcessByPid(const pid_t pid) const { int32_t ret = -1; -- Gitee From 0d7826ccfacfd1957d101db53a40f7528b7a8a1f Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 04:06:56 +0000 Subject: [PATCH 53/66] update services/appmgr/src/app_mgr_service.cpp. Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index ebde6cc5b74..d1d46cb3ce5 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -302,7 +302,7 @@ int32_t AppMgrService::GetProcessRunningInfosByUserId(std::vectorGetProcessRunningInfosByUserId(info, userId); } -int32_t AppMgrService::GetProcessRunningInformation(std::vector &info) +int32_t AppMgrService::GetProcessRunningInformation(RunningProcessInfo &info) { if (!IsReady()) { return ERR_INVALID_OPERATION; -- Gitee From f5d946aea77b25b13d36779b184ba74322eadd7c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 12:18:49 +0800 Subject: [PATCH 54/66] Signecription:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../inner_api/app_manager/src/appmgr/app_mgr_stub.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index bae27de02ba..5d46d2d8bbe 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -246,13 +246,10 @@ int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, Me int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply) { HITRACE_METER(HITRACE_TAG_APP); - std::vector info; + RunningProcessInfo info; auto result = GetProcessRunningInformation(info); - reply.WriteInt32(info.size()); - for (auto &it : info) { - if (!reply.WriteParcelable(&it)) { - return ERR_INVALID_VALUE; - } + if (!reply.WriteParcelable(&info)) { + return ERR_INVALID_VALUE; } if (!reply.WriteInt32(result)) { return ERR_INVALID_VALUE; -- Gitee From b73875e343ed8046efe021f28780fc44c2aec27a Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 12:32:51 +0800 Subject: [PATCH 55/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../include/mock_app_mgr_service.h | 5 ++++- .../mock/services_appmgr_test/include/mock_app_mgr_service.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index c56b090f004..715f2263cbe 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -39,7 +39,6 @@ public: MOCK_METHOD1(StartupResidentProcess, void(const std::vector& bundleInfos)); MOCK_METHOD1(NotifyMemoryLevel, int(int32_t level)); MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector& info, int32_t userId)); - MOCK_METHOD1(GetProcessRunningInformation, int(std::vector& info)); MOCK_METHOD4(StartUserTestProcess, int(const AAFwk::Want& want, const sptr& observer, const BundleInfo& bundleInfo, int32_t userId)); MOCK_METHOD3(FinishUserTest, int(const std::string& msg, const int64_t& resultCode, @@ -115,6 +114,10 @@ public: return 0; } + virtual int GetProcessRunningInformation(RunningProcessInfo &info){ + return 0; + } + int IsBackgroundRunningRestricted(const std::string& appName) { return 0; diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 7b94e605eb4..17be25823fb 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -42,7 +42,6 @@ public: MOCK_METHOD1(IsBackgroundRunningRestricted, int(const std::string& bundleName)); MOCK_METHOD1(GetAllRunningProcesses, int(std::vector& info)); MOCK_METHOD2(GetProcessRunningInfosByUserId, int(std::vector& info, int32_t userId)); - MOCK_METHOD1(GetProcessRunningInformation, int(std::vector& info)); MOCK_METHOD0(GetAmsMgr, sptr()); MOCK_METHOD1(GetAppFreezingTime, void(int& time)); MOCK_METHOD1(SetAppFreezingTime, void(int time)); @@ -84,6 +83,10 @@ public: return 0; } + virtual int GetProcessRunningInformation(RunningProcessInfo &info){ + return 0; + } + virtual void RegisterAppStateCallback(const sptr& callback) { callback_ = callback; -- Gitee From 8efdc837ef1f5d3b95f0048e24f0734589a8a214 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 14:01:26 +0800 Subject: [PATCH 56/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/include/app_mgr_service_inner.h | 2 ++ services/appmgr/src/app_mgr_service_inner.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 08efb0442e6..c411f81060d 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -775,6 +775,8 @@ private: bool CheckGetRunningInfoPermission() const; + int32_t KillApplicationByBundleName(const std::string &bundleName); + private: /** * Notify application status. diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 22fad5aaeb5..b0b133a1a99 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -531,6 +531,23 @@ int32_t AppMgrServiceInner::KillApplicationSelf() return ERR_NO_INIT; } + auto callerPid = IPCSkeleton::GetCallingPid(); + auto appRecord = GetAppRunningRecordByPid(callerPid); + auto bundleName = appRecord->GetBundleName(); + return KillApplicationByBundleName(bundleName); +} + +int32_t AppMgrServiceInner::KillApplicationByBundleName(const std::string &bundleName) +{ + int result = ERR_OK; + int64_t startTime = SystemTimeMillisecond(); + std::list pids; + + if (!appRunningManager_->ProcessExitByBundleName(bundleName, pids)) { + HILOG_ERROR("The process corresponding to the package name did not start"); + return result; + } + auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); auto bundleName = appRecord->GetBundleName(); -- Gitee From 5a4e43be40bd1e33b961046eeb1254df7f8a2bbf Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 14:14:25 +0800 Subject: [PATCH 57/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index b0b133a1a99..3b346d35969 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -547,18 +547,6 @@ int32_t AppMgrServiceInner::KillApplicationByBundleName(const std::string &bundl HILOG_ERROR("The process corresponding to the package name did not start"); return result; } - - auto callerPid = IPCSkeleton::GetCallingPid(); - auto appRecord = GetAppRunningRecordByPid(callerPid); - auto bundleName = appRecord->GetBundleName(); - int result = ERR_OK; - int64_t startTime = SystemTimeMillisecond(); - std::list pids; - - if (!appRunningManager_->ProcessExitByBundleName(bundleName, pids)) { - HILOG_INFO("The process corresponding to the package name did not start"); - return result; - } if (WaitForRemoteProcessExit(pids, startTime)) { HILOG_INFO("The remote process exited successfully "); NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); @@ -785,7 +773,7 @@ void AppMgrServiceInner::GetRunningProcess(const std::shared_ptrIsKeepAliveApp(); info.isFocused = appRecord->GetFocusFlag(); info.startTimeMillis_ = appRecord->GetAppStartTime(); - appRecord->GetBundleNames(runningProcessInfo.bundleNames); + appRecord->GetBundleNames(info.bundleNames); } int32_t AppMgrServiceInner::KillProcessByPid(const pid_t pid) const -- Gitee From c45223d2409656db1346bb2b60dad686f1e4cc8c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 14:35:53 +0800 Subject: [PATCH 58/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- services/appmgr/src/app_mgr_service_inner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 3b346d35969..4f241f5e150 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -555,7 +555,7 @@ int32_t AppMgrServiceInner::KillApplicationByBundleName(const std::string &bundl for (auto iter = pids.begin(); iter != pids.end(); ++iter) { result = KillProcessByPid(*iter); if (result < 0) { - HILOG_ERROR("KillApplicationSelf is fail, pid:%{public}d", callerPid); + HILOG_ERROR("KillApplicationSelf is failed for bundleName:%{public}d, pid: %{public}d", bundleName.c_str(), *iter); return result; } } @@ -719,7 +719,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInfosByUserId(std::vector &info) +int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &info) { if (!appRunningManager_) { HILOG_ERROR("appRunningManager_ is nullptr"); @@ -758,7 +758,7 @@ void AppMgrServiceInner::GetRunningProcesses(const std::shared_ptr &info) { RunningProcessInfo runningProcessInfo; - GetRunningProcess(appRecord, RunningProcessInfo); + GetRunningProcess(appRecord, runningProcessInfo); info.emplace_back(runningProcessInfo); } -- Gitee From e871ced2b01b20397bb5cc6e63a258e21887179c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 14:43:04 +0800 Subject: [PATCH 59/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index ecc054326ef..7b2a323e8d6 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -272,24 +272,15 @@ int32_t AppMgrProxy::GetProcessRunningInformation(RunningProcessInfo &info) { MessageParcel data; MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - sptr remote = Remote(); - if (remote == nullptr) { - HILOG_ERROR("Remote() is NULL"); - return ERR_NULL_OBJECT; - } if (!SendTransactCmd(IAppMgr::Message::APP_GET_PROCESS_RUNNING_INFORMATION, data, reply)) { return ERR_NULL_OBJECT; } - auto error = GetParcelableInfos(reply, info); - if (error != NO_ERROR) { - HILOG_ERROR("GetParcelableInfos fail, error: %{public}d", error); - return error; - } + std::unique_ptr infoReply(reply.ReadParcelable()); + info = *infoReply; int result = reply.ReadInt32(); return result; } -- Gitee From 06f9423a57049cfdf93424ec04ba721b334ec8b9 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 07:21:59 +0000 Subject: [PATCH 60/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../context/js_application_context_utils.cpp | 15 +++++++-------- services/appmgr/src/app_mgr_service_inner.cpp | 4 ++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 92e76d347c2..3fa5362cf59 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -107,8 +107,7 @@ private: NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info); - NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, - const AppExecFwk::RunningProcessInfo &info); + NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, const AppExecFwk::RunningProcessInfo &info); std::shared_ptr keepApplicationContext_; std::shared_ptr callback_; std::shared_ptr envCallback_; @@ -465,7 +464,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { HILOG_ERROR("Not enough params"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); - return engine.CreateUndefined; + return engine.CreateUndefined(); } HILOG_INFO("kill self process"); AsyncTask::CompleteCallback complete = @@ -502,7 +501,7 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng if (info.argc != ARGC_ZERO && info.argc != ARGC_ONE) { HILOG_ERROR("Not enough params"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); - return engine.CreateUndefined; + return engine.CreateUndefined(); } HILOG_INFO("Get Process Info"); AsyncTask::CompleteCallback complete = @@ -534,11 +533,11 @@ NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, object->SetProperty("processName", CreateJsValue(engine, info.processName_)); object->SetProperty("pid", CreateJsValue(engine, info.pid_)); object->SetProperty("uid", CreateJsValue(engine, info.uid_)); - object->SetProperty("bundleNames", CreateJsValue(engine, info.state_)); + object->SetProperty("bundleNames", CreateNativeArray(engine, info.bundleNames)); object->SetProperty("state", CreateJsValue(engine, info.state_)); - object->SetProperty("isContinuousTask", CreateJsValue(engine, info.isContinuousTask_)); - object->SetProperty("isKeepAlive", CreateJsValue(engine, info.isKeepAlive_)); - object->SetProperty("isFocused", CreateJsValue(engine, info.isFocused_)); + object->SetProperty("isContinuousTask", CreateJsValue(engine, info.isContinuousTask)); + object->SetProperty("isKeepAlive", CreateJsValue(engine, info.isKeepAlive)); + object->SetProperty("isFocused", CreateJsValue(engine, info.isFocused)); return objValue; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 4f241f5e150..b46907a465f 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -555,7 +555,7 @@ int32_t AppMgrServiceInner::KillApplicationByBundleName(const std::string &bundl for (auto iter = pids.begin(); iter != pids.end(); ++iter) { result = KillProcessByPid(*iter); if (result < 0) { - HILOG_ERROR("KillApplicationSelf is failed for bundleName:%{public}d, pid: %{public}d", bundleName.c_str(), *iter); + HILOG_ERROR("KillApplicationSelf is failed for bundleName:%{public}s, pid: %{public}d", bundleName.c_str(), *iter); return result; } } @@ -727,7 +727,7 @@ int32_t AppMgrServiceInner::GetProcessRunningInformation(RunningProcessInfo &inf } auto callerPid = IPCSkeleton::GetCallingPid(); auto appRecord = GetAppRunningRecordByPid(callerPid); - GetRunningProcesses(appRecord, info); + GetRunningProcess(appRecord, info); return ERR_OK; } -- Gitee From ef6e0071cca2eed4965533540964a2d22f45e526 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 07:27:19 +0000 Subject: [PATCH 61/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_runtime/context/js_application_context_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 3fa5362cf59..553c6fcf9e6 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -510,7 +510,7 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng AppExecFwk::RunningProcessInfo processInfo; auto ret = applicationContext->GetProcessRunningInformation(processInfo); if (ret == 0) { - task.Resolve(engine, CreateJsProcessRunningInfo(engine, processInfo)); + task.Resolve(engine, this->CreateJsProcessRunningInfo(engine, processInfo)); } else { task.Reject(engine, CreateJsError(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR, "Get mission infos failed.")); -- Gitee From 6319cb454b700d0e8458cb83aafc7bf5637742dc Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 07:33:57 +0000 Subject: [PATCH 62/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_runtime/context/js_application_context_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 553c6fcf9e6..d7f5127337d 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -107,7 +107,7 @@ private: NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info); - NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, const AppExecFwk::RunningProcessInfo &info); + NativeValue* CreateJsProcessRunningInfo(NativeEngine &engine, const AppExecFwk::RunningProcessInfo &info); std::shared_ptr keepApplicationContext_; std::shared_ptr callback_; std::shared_ptr envCallback_; -- Gitee From f9c08f7cd1402815bd4e94440bb31aa49fe8978d Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 07:45:16 +0000 Subject: [PATCH 63/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../ability_runtime/context/js_application_context_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index d7f5127337d..3f62843a2f3 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -504,7 +504,7 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng return engine.CreateUndefined(); } HILOG_INFO("Get Process Info"); - AsyncTask::CompleteCallback complete = + auto complete = [applicationContext, this](NativeEngine& engine, AsyncTask& task, int32_t status) { AppExecFwk::RunningProcessInfo processInfo; @@ -524,7 +524,7 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng return result; } -NativeValue* CreateJsProcessRunningInfo(NativeEngine& engine, +NativeValue* JsApplicationContextUtils::CreateJsProcessRunningInfo(NativeEngine &engine, const AppExecFwk::RunningProcessInfo &info) { NativeValue* objValue = engine.CreateObject(); -- Gitee From dededd3f2bba5defb37494ab44cd3341034f673a Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 09:47:11 +0000 Subject: [PATCH 64/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../appkit/ability_runtime/context/context_impl.cpp | 5 +---- .../context/js_application_context_utils.cpp | 12 ++++-------- .../app_manager/include/appmgr/app_mgr_interface.h | 2 +- .../app_manager/src/appmgr/app_mgr_proxy.cpp | 3 +-- services/appmgr/src/app_mgr_service_inner.cpp | 2 +- 5 files changed, 8 insertions(+), 16 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 06a951a8ed8..247d3056192 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -552,18 +552,15 @@ void ContextImpl::SetConfiguration(const std::shared_ptr(); appMgrClient->KillApplicationSelf(); - return; } int32_t ContextImpl::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) { - HILOG_INFO("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); auto appMgrClient = std::make_unique(); auto result = appMgrClient->GetProcessRunningInformation(info); - HILOG_INFO("result is %{public}d.", result); + HILOG_DEBUG("result is %{public}d.", result); return result; } diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 3f62843a2f3..65f02289bc8 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -444,7 +444,6 @@ NativeValue *JsApplicationContextUtils::OnGetBundleCodeDir(NativeEngine &engine, NativeValue *JsApplicationContextUtils::KillProcessBySelf(NativeEngine *engine, NativeCallbackInfo *info) { - HILOG_INFO("JsApplicationContextUtils::KillProcessBySelf is called"); JsApplicationContextUtils *me = CheckParamsAndGetThis(engine, info, APPLICATION_CONTEXT_NAME); return me != nullptr ? me->OnKillProcessBySelf(*engine, *info) : nullptr; @@ -452,8 +451,7 @@ NativeValue *JsApplicationContextUtils::KillProcessBySelf(NativeEngine *engine, NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine, NativeCallbackInfo &info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); - auto applicationContext = applicationContext_.lock(); + auto applicationContext = appli cationContext_.lock(); if(!applicationContext){ HILOG_WARN("applicationContext if already released"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST); @@ -466,7 +464,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); return engine.CreateUndefined(); } - HILOG_INFO("kill self process"); + HILOG_DEBUG("kill self process"); AsyncTask::CompleteCallback complete = [applicationContext](NativeEngine& engine, AsyncTask& task,int32_t status) { applicationContext->KillProcessBySelf(); @@ -481,7 +479,6 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine NativeValue *JsApplicationContextUtils::GetProcessRunningInformation(NativeEngine *engine, NativeCallbackInfo *info) { - HILOG_INFO("JsApplicationContextUtils::GetProcessRunningInformation is called"); JsApplicationContextUtils *me = CheckParamsAndGetThis(engine, info, APPLICATION_CONTEXT_NAME); return me != nullptr ? me->OnGetProcessRunningInformation(*engine, *info) : nullptr; @@ -489,7 +486,6 @@ NativeValue *JsApplicationContextUtils::GetProcessRunningInformation(NativeEngin NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEngine &engine, NativeCallbackInfo &info) { - HILOG_INFO("%{public}s is called", __FUNCTION__); auto applicationContext = applicationContext_.lock(); if(!applicationContext){ HILOG_WARN("applicationContext if already released"); @@ -503,7 +499,7 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); return engine.CreateUndefined(); } - HILOG_INFO("Get Process Info"); + HILOG_DEBUG("Get Process Info"); auto complete = [applicationContext, this](NativeEngine& engine, AsyncTask& task, int32_t status) { @@ -513,7 +509,7 @@ NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEng task.Resolve(engine, this->CreateJsProcessRunningInfo(engine, processInfo)); } else { task.Reject(engine, CreateJsError(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INTERNAL_ERROR, - "Get mission infos failed.")); + "Get process infos failed.")); } }; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index b1a2bbb87d0..ef4f96c30f7 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -134,7 +134,7 @@ public: * @param info, app name in Application record. * @return ERR_OK ,return back success,others fail. */ - virtual int GetProcessRunningInformation(RunningProcessInfo &info) = 0; + virtual int32_t GetProcessRunningInformation(RunningProcessInfo &info) = 0; /** * NotifyMemoryLevel, call NotifyMemoryLevel() through proxy project. diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp index 7b2a323e8d6..5ece7a00290 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_proxy.cpp @@ -281,8 +281,7 @@ int32_t AppMgrProxy::GetProcessRunningInformation(RunningProcessInfo &info) } std::unique_ptr infoReply(reply.ReadParcelable()); info = *infoReply; - int result = reply.ReadInt32(); - return result; + return reply.ReadInt32(); } int32_t AppMgrProxy::NotifyMemoryLevel(int32_t level) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index b46907a465f..3a2f4a11945 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -548,7 +548,7 @@ int32_t AppMgrServiceInner::KillApplicationByBundleName(const std::string &bundl return result; } if (WaitForRemoteProcessExit(pids, startTime)) { - HILOG_INFO("The remote process exited successfully "); + HILOG_DEBUG("The remote process exited successfully "); NotifyAppStatus(bundleName, EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_RESTARTED); return result; } -- Gitee From d249bf1fe749cfce22d38d8149e58ce4b15248a2 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 24 Dec 2022 17:57:40 +0800 Subject: [PATCH 65/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../context/js_application_context_utils.cpp | 8 ++++---- .../inner_api/app_manager/src/appmgr/app_mgr_client.cpp | 3 --- services/appmgr/include/app_mgr_service_inner.h | 4 ++-- services/appmgr/src/app_mgr_service_inner.cpp | 3 ++- .../include/mock_app_mgr_service.h | 3 ++- .../services_appmgr_test/include/mock_app_mgr_service.h | 3 ++- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 65f02289bc8..3aca6df6058 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -451,8 +451,8 @@ NativeValue *JsApplicationContextUtils::KillProcessBySelf(NativeEngine *engine, NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine, NativeCallbackInfo &info) { - auto applicationContext = appli cationContext_.lock(); - if(!applicationContext){ + auto applicationContext = applicationContext_.lock(); + if (!applicationContext) { HILOG_WARN("applicationContext if already released"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST); return engine.CreateUndefined(); @@ -466,7 +466,7 @@ NativeValue *JsApplicationContextUtils::OnKillProcessBySelf(NativeEngine &engine } HILOG_DEBUG("kill self process"); AsyncTask::CompleteCallback complete = - [applicationContext](NativeEngine& engine, AsyncTask& task,int32_t status) { + [applicationContext](NativeEngine& engine, AsyncTask& task, int32_t status) { applicationContext->KillProcessBySelf(); task.Resolve(engine, engine.CreateUndefined()); }; @@ -487,7 +487,7 @@ NativeValue *JsApplicationContextUtils::GetProcessRunningInformation(NativeEngin NativeValue *JsApplicationContextUtils::OnGetProcessRunningInformation(NativeEngine &engine, NativeCallbackInfo &info) { auto applicationContext = applicationContext_.lock(); - if(!applicationContext){ + if (!applicationContext) { HILOG_WARN("applicationContext if already released"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_CONTEXT_NOT_EXIST); return engine.CreateUndefined(); diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp index 57fabad8580..71695760ec3 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_client.cpp @@ -320,9 +320,6 @@ AppMgrResultCode AppMgrClient::GetProcessRunningInfosByUserId(std::vector service = iface_cast(mgrHolder_->GetRemoteObject()); diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index c411f81060d..e6434ce48d6 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -257,8 +257,8 @@ public: virtual int32_t GetProcessRunningInfosByUserId(std::vector &info, int32_t userId); /** - * GetProcessRunningInfosByUserId, Obtains information about current application process which is running on the device. - * + * GetProcessRunningInformation, Obtains information about current application process + * which is running on the device. * @param info, app name in Application record. * * @return ERR_OK ,return back success,others fail. diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 3a2f4a11945..7085425ab60 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -555,7 +555,8 @@ int32_t AppMgrServiceInner::KillApplicationByBundleName(const std::string &bundl for (auto iter = pids.begin(); iter != pids.end(); ++iter) { result = KillProcessByPid(*iter); if (result < 0) { - HILOG_ERROR("KillApplicationSelf is failed for bundleName:%{public}s, pid: %{public}d", bundleName.c_str(), *iter); + HILOG_ERROR("KillApplicationSelf is failed for bundleName:%{public}s, pid: %{public}d", + bundleName.c_str(), *iter); return result; } } diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index 715f2263cbe..357784320d3 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -114,7 +114,8 @@ public: return 0; } - virtual int GetProcessRunningInformation(RunningProcessInfo &info){ + virtual int GetProcessRunningInformation(RunningProcessInfo &info) + { return 0; } diff --git a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h index 17be25823fb..165937e635b 100644 --- a/test/mock/services_appmgr_test/include/mock_app_mgr_service.h +++ b/test/mock/services_appmgr_test/include/mock_app_mgr_service.h @@ -83,7 +83,8 @@ public: return 0; } - virtual int GetProcessRunningInformation(RunningProcessInfo &info){ + virtual int GetProcessRunningInformation(RunningProcessInfo &info) + { return 0; } -- Gitee From 07699cef098a476be88b309794aac00005ba511c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Tue, 27 Dec 2022 12:58:03 +0000 Subject: [PATCH 66/66] Description:add KillProcessSelf Sig:SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: gongyuechen --- .../native/appkit/ability_runtime/context/context_impl.cpp | 4 ++-- .../inner_api/app_manager/include/appmgr/app_mgr_interface.h | 2 +- interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 247d3056192..089149a5fec 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -552,13 +552,13 @@ void ContextImpl::SetConfiguration(const std::shared_ptr(); + auto appMgrClient = DelayedSingleton::GetInstance(); appMgrClient->KillApplicationSelf(); } int32_t ContextImpl::GetProcessRunningInformation(AppExecFwk::RunningProcessInfo &info) { - auto appMgrClient = std::make_unique(); + auto appMgrClient = DelayedSingleton::GetInstance(); auto result = appMgrClient->GetProcessRunningInformation(info); HILOG_DEBUG("result is %{public}d.", result); return result; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h index ef4f96c30f7..e75bf3e0fcc 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_interface.h @@ -320,7 +320,6 @@ public: APP_GET_MGR_INSTANCE, APP_CLEAR_UP_APPLICATION_DATA, APP_GET_ALL_RUNNING_PROCESSES, - APP_GET_PROCESS_RUNNING_INFORMATION, APP_GET_RUNNING_PROCESSES_BY_USER_ID, APP_ADD_ABILITY_STAGE_INFO_DONE, STARTUP_RESIDENT_PROCESS, @@ -346,6 +345,7 @@ public: SET_CONTINUOUSTASK_PROCESS, NOTIFY_UNLOAD_REPAIR_PATCH, PRE_START_NWEBSPAWN_PROCESS, + APP_GET_PROCESS_RUNNING_INFORMATION, }; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp index 5d46d2d8bbe..68db2791906 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/app_mgr_stub.cpp @@ -55,8 +55,6 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleNotifyMemoryLevel; memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_RUNNING_PROCESSES_BY_USER_ID)] = &AppMgrStub::HandleGetProcessRunningInfosByUserId; - memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_PROCESS_RUNNING_INFORMATION)] = - &AppMgrStub::HandleGetProcessRunningInformation; memberFuncMap_[static_cast(IAppMgr::Message::APP_ADD_ABILITY_STAGE_INFO_DONE)] = &AppMgrStub::HandleAddAbilityStageDone; memberFuncMap_[static_cast(IAppMgr::Message::STARTUP_RESIDENT_PROCESS)] = @@ -91,6 +89,8 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleRegisterConfigurationObserver; memberFuncMap_[static_cast(IAppMgr::Message::UNREGISTER_CONFIGURATION_OBSERVER)] = &AppMgrStub::HandleUnregisterConfigurationObserver; + memberFuncMap_[static_cast(IAppMgr::Message::APP_GET_PROCESS_RUNNING_INFORMATION)] = + &AppMgrStub::HandleGetProcessRunningInformation; #ifdef ABILITY_COMMAND_FOR_TEST memberFuncMap_[static_cast(IAppMgr::Message::BLOCK_APP_SERVICE)] = &AppMgrStub::HandleBlockAppServiceDone; -- Gitee