From a873f55607cdcb0796a9e5db89584ff5d6c6abc7 Mon Sep 17 00:00:00 2001 From: wylyw78 Date: Fri, 14 Jun 2024 16:20:58 +0800 Subject: [PATCH 001/148] =?UTF-8?q?=E9=80=82=E9=85=8DLinux=20arm=20host=20?= =?UTF-8?q?openharmony=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wylyw78 --- frameworks/native/ability/native/BUILD.gn | 8 ++++++-- interfaces/inner_api/ability_manager/BUILD.gn | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 46f847c720..d6f32fc9a1 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -279,10 +279,12 @@ ohos_shared_library("abilitykit_native") { "json:nlohmann_json_static", "napi:ace_napi", "node:node_header_notice", - "relational_store:native_rdb", "resource_management:global_resmgr", "samgr:samgr_proxy", ] + if (!(is_linux && host_cpu == "arm64")) { + external_deps += [ "relational_store:native_rdb" ] + } public_external_deps = [ "accessibility:accessibility_common", @@ -879,10 +881,12 @@ ohos_shared_library("data_ability_helper") { "hitrace:hitrace_meter", "json:nlohmann_json_static", "relational_store:native_dataability", - "relational_store:native_rdb", "relational_store:rdb_data_ability_adapter", "window_manager:libwm", ] + if (!(is_linux && host_cpu == "arm64")) { + external_deps += [ "relational_store:native_rdb" ] + } innerapi_tags = [ "platformsdk" ] subsystem_name = "ability" diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index c066d6a600..7b71858e57 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -243,9 +243,11 @@ ohos_shared_library("ability_manager") { "hitrace:hitrace_meter", "ipc:ipc_core", "relational_store:native_dataability", - "relational_store:native_rdb", "samgr:samgr_proxy", ] + if (!(is_linux && host_cpu == "arm64")) { + external_deps += [ "relational_store:native_rdb" ] + } public_external_deps = [ "ability_base:configuration", From c3253d81993d11d93bb529e3065199ce0eddc719 Mon Sep 17 00:00:00 2001 From: wenyu Date: Tue, 18 Jun 2024 02:58:31 +0000 Subject: [PATCH 002/148] update frameworks/native/ability/native/BUILD.gn. Signed-off-by: wenyu --- frameworks/native/ability/native/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index d6f32fc9a1..5104ea482f 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -282,7 +282,7 @@ ohos_shared_library("abilitykit_native") { "resource_management:global_resmgr", "samgr:samgr_proxy", ] - if (!(is_linux && host_cpu == "arm64")) { + if (host_cpu != "arm64") { external_deps += [ "relational_store:native_rdb" ] } @@ -884,7 +884,7 @@ ohos_shared_library("data_ability_helper") { "relational_store:rdb_data_ability_adapter", "window_manager:libwm", ] - if (!(is_linux && host_cpu == "arm64")) { + if (host_cpu != "arm64") { external_deps += [ "relational_store:native_rdb" ] } From d02c109324d4c1f1298f772104c26bd6aeefda09 Mon Sep 17 00:00:00 2001 From: wenyu Date: Tue, 18 Jun 2024 02:59:07 +0000 Subject: [PATCH 003/148] update interfaces/inner_api/ability_manager/BUILD.gn. Signed-off-by: wenyu --- interfaces/inner_api/ability_manager/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 7b71858e57..ef53ed3bea 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -245,7 +245,7 @@ ohos_shared_library("ability_manager") { "relational_store:native_dataability", "samgr:samgr_proxy", ] - if (!(is_linux && host_cpu == "arm64")) { + if (host_cpu != "arm64") { external_deps += [ "relational_store:native_rdb" ] } From 29819beff5162339919c88b7e671ed5e5fdef645 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 04:06:06 +0000 Subject: [PATCH 004/148] update interfaces/inner_api/runtime/include/js_runtime_utils.h. Signed-off-by: wanglai.yao --- interfaces/inner_api/runtime/include/js_runtime_utils.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interfaces/inner_api/runtime/include/js_runtime_utils.h b/interfaces/inner_api/runtime/include/js_runtime_utils.h index e586f1bff0..47ab469ad6 100644 --- a/interfaces/inner_api/runtime/include/js_runtime_utils.h +++ b/interfaces/inner_api/runtime/include/js_runtime_utils.h @@ -302,6 +302,8 @@ std::unique_ptr CreateAsyncTaskWithLastParam(napi_env env, napi_v std::unique_ptr CreateAsyncTaskWithLastParam(napi_env env, napi_value lastParam, std::nullptr_t, std::nullptr_t, napi_value* result); + +std::unique_ptr CreateEmptyAsyncTask(napi_env env, napi_value lastParam, napi_value* result); } // namespace AbilityRuntime } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_JS_RUNTIME_UTILS_H From ee7c1339624cdec1b3925231a974806affd7038c Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 04:08:17 +0000 Subject: [PATCH 005/148] update frameworks/native/runtime/js_runtime_utils.cpp. Signed-off-by: wanglai.yao --- frameworks/native/runtime/js_runtime_utils.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frameworks/native/runtime/js_runtime_utils.cpp b/frameworks/native/runtime/js_runtime_utils.cpp index 40b74fb676..a60e4d8e11 100644 --- a/frameworks/native/runtime/js_runtime_utils.cpp +++ b/frameworks/native/runtime/js_runtime_utils.cpp @@ -451,5 +451,23 @@ std::unique_ptr CreateAsyncTaskWithLastParam(napi_env env, napi_v return CreateAsyncTaskWithLastParam(env, lastParam, std::unique_ptr(), std::unique_ptr(), result); } + +std::unique_ptr CreateEmptyAsyncTask(napi_env env, napi_value lastParam, napi_value* result) +{ + napi_valuetype type = napi_undefined; + napi_typeof(env, lastParam, &type); + if (lastParam == nullptr || type != napi_function) { + napi_deferred nativeDeferred = nullptr; + napi_create_promise(env, &nativeDeferred, result); + return std::make_unique(nativeDeferred, std::unique_ptr(), + std::unique_ptr()); + } else { + napi_get_undefined(env, result); + napi_ref callbackRef = nullptr; + napi_create_reference(env, lastParam, 1, &callbackRef); + return std::make_unique(callbackRef, std::unique_ptr(), + std::unique_ptr()); + } +} } // namespace AbilityRuntime } // namespace OHOS From d99e80a15201f2c7f3a1b6f00c44ec3b6edab854 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 04:09:58 +0000 Subject: [PATCH 006/148] update frameworks/simulator/ability_simulator/src/js_runtime_utils.cpp. Signed-off-by: wanglai.yao --- .../ability_simulator/src/js_runtime_utils.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frameworks/simulator/ability_simulator/src/js_runtime_utils.cpp b/frameworks/simulator/ability_simulator/src/js_runtime_utils.cpp index df9e345c84..975b9fe541 100644 --- a/frameworks/simulator/ability_simulator/src/js_runtime_utils.cpp +++ b/frameworks/simulator/ability_simulator/src/js_runtime_utils.cpp @@ -319,6 +319,24 @@ std::unique_ptr CreateAsyncTaskWithLastParam(napi_env env, napi_v std::unique_ptr(), result); } +std::unique_ptr CreateEmptyAsyncTask(napi_env env, napi_value lastParam, napi_value* result) +{ + napi_valuetype type = napi_undefined; + napi_typeof(env, lastParam, &type); + if (lastParam == nullptr || type != napi_function) { + napi_deferred nativeDeferred = nullptr; + napi_create_promise(env, &nativeDeferred, result); + return std::make_unique(nativeDeferred, std::unique_ptr(), + std::unique_ptr()); + } else { + napi_get_undefined(env, result); + napi_ref callbackRef = nullptr; + napi_create_reference(env, lastParam, 1, &callbackRef); + return std::make_unique(callbackRef, std::unique_ptr(), + std::unique_ptr()); + } +} + std::unique_ptr JsRuntime::LoadSystemModuleByEngine(napi_env env, const std::string &moduleName, napi_value const *argv, size_t argc) { From 105d1a5dc8027f71bf70035fc43409772c01bfc8 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 04:23:55 +0000 Subject: [PATCH 007/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../napi/app/app_manager/js_app_manager.cpp | 226 ++++++++++-------- 1 file changed, 120 insertions(+), 106 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 aa8f550645..2b11eb1ea4 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -179,32 +179,34 @@ private: } } - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, observer = observer_, observerId, errCode]( - napi_env env, NapiAsyncTask& task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - if (observer == nullptr || appManager == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr")); - return; - } - int32_t ret = appManager->UnregisterApplicationStateObserver(observer); - if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { - task.Resolve(env, CreateJsUndefined(env)); - TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize()); - } else { - TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); - task.Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed")); - } - }; - napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnUnregisterApplicationStateObserver", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, observer = observer_, observerId, errCode, + env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + if (observer == nullptr || appManager == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr")); + return; + } + int32_t ret = appManager->UnregisterApplicationStateObserver(observer); + if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { + task->Resolve(env, CreateJsUndefined(env)); + TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize()); + } else { + TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); + task->Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed")); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -218,32 +220,35 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "Not enough params"); errCode = ERR_NOT_OK; } - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - if (appManager == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr")); - return; - } - std::vector list; - int32_t ret = appManager->GetForegroundApplications(list); - if (ret == 0) { - TAG_LOGD(AAFwkTag::APPMGR, "success."); - task.Resolve(env, CreateJsAppStateDataArray(env, list)); - } else { - TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); - task.Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed")); - } - }; napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnGetForegroundApplications", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + if (appManager == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr")); + return; + } + std::vector list; + int32_t ret = appManager->GetForegroundApplications(list); + if (ret == 0) { + TAG_LOGD(AAFwkTag::APPMGR, "success."); + task->Resolve(env, CreateJsAppStateDataArray(env, list)); + } else { + TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); + task->Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed")); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -257,25 +262,28 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "Not enough params"); errCode = ERR_NOT_OK; } - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, errCode](napi_env env, NapiAsyncTask &task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - std::vector infos; - auto ret = appManager->GetAllRunningProcesses(infos); - if (ret == 0) { - task.Resolve(env, CreateJsProcessRunningInfoArray(env, infos)); - } else { - task.Reject(env, CreateJsError(env, ret, "Get mission infos failed.")); - } - }; napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnGetProcessRunningInfos", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + std::vector infos; + auto ret = appManager->GetAllRunningProcesses(infos); + if (ret == 0) { + task->Resolve(env, CreateJsProcessRunningInfoArray(env, infos)); + } else { + task->Reject(env, CreateJsError(env, ret, "Get mission infos failed.")); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -289,26 +297,29 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "Not enough arguments"); errCode = ERR_NOT_OK; } - NapiAsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); - return; - } - bool ret = abilityManager->IsRunningInStabilityTest(); - TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); - task.Resolve(env, CreateJsValue(env, ret)); - }; napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnIsRunningInStabilityTest", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + return; + } + bool ret = abilityManager->IsRunningInStabilityTest(); + TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); + task->Resolve(env, CreateJsValue(env, ret)); + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -340,29 +351,31 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]", bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex); - NapiAsyncTask::CompleteCallback complete = - [bundleName, clearPageStack, abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, - int32_t status) { + napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr; + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [bundleName, abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); return; } if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); return; } - auto ret = abilityManager->KillProcess(bundleName, clearPageStack); + auto ret = abilityManager->KillProcess(bundleName); if (ret == 0) { - task.Resolve(env, CreateJsValue(env, ret)); + task->Resolve(env, CreateJsValue(env, ret)); } else { - task.Reject(env, CreateJsError(env, ret, "kill process failed.")); + task->Reject(env, CreateJsError(env, ret, "kill process failed.")); } }; - napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr; - napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessByBundleName", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -385,30 +398,31 @@ private: } } - NapiAsyncTask::CompleteCallback complete = - [bundleName, appManager = appManager_, errCode](napi_env env, NapiAsyncTask& task, - int32_t status) { + napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [bundleName, abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); return; } - if (appManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr")); + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); return; } - auto ret = appManager->ClearUpApplicationData(bundleName, 0); + auto ret = abilityManager->ClearUpApplicationData(bundleName); if (ret == 0) { - task.Resolve(env, CreateJsValue(env, ret)); + task->Resolve(env, CreateJsValue(env, ret)); } else { - task.Reject(env, CreateJsError(env, ret, "clear up application failed.")); + task->Reject(env, CreateJsError(env, ret, "clear up application failed.")); } }; - napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; - napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnClearUpApplicationData", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } From b2f7ad484a5d57c1ca4102c3d9bfe4e1e1d13a58 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 06:32:21 +0000 Subject: [PATCH 008/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../napi/app/app_manager/js_app_manager.cpp | 116 ++++++++++-------- 1 file changed, 62 insertions(+), 54 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 2b11eb1ea4..3b915cd473 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -459,27 +459,29 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]", bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex); - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, bundleName, accountId, clearPageStack, errCode]( - napi_env env, NapiAsyncTask &task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack); - if (ret == 0) { - task.Resolve(env, CreateJsUndefined(env)); - } else { - TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret); - task.Reject(env, CreateJsError(env, ret, "Kill processes failed.")); - } - }; - napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; - napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessWithAccount", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); - return result; + napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, bundleName, accountId, errCode, env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId); + if (ret == 0) { + task->Resolve(env, CreateJsUndefined(env)); + } else { + TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret); + task->Reject(env, CreateJsError(env, ret, "Kill processes failed.")); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); TAG_LOGD(AAFwkTag::APPMGR, "end"); + return result; } napi_value OnGetAppMemorySize(napi_env env, const size_t argc, napi_value* argv) @@ -491,26 +493,29 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "Insufficient params"); errCode = ERR_NOT_OK; } - NapiAsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); - return; - } - int32_t memorySize = abilityManager->GetAppMemorySize(); - TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); - task.Resolve(env, CreateJsValue(env, memorySize)); - }; napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetAppMemorySize", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + return; + } + int32_t memorySize = abilityManager->GetAppMemorySize(); + TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); + task->Resolve(env, CreateJsValue(env, memorySize)); + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -523,26 +528,29 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "Not enough parameters"); errCode = ERR_NOT_OK; } - NapiAsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_, errCode](napi_env env, NapiAsyncTask& task, int32_t status) { - if (errCode != 0) { - task.Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); - return; - } - bool ret = abilityManager->IsRamConstrainedDevice(); - TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); - task.Resolve(env, CreateJsValue(env, ret)); - }; napi_value lastParam = (argc == ARGC_ONE) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsRamConstrainedDevice", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + return; + } + bool ret = abilityManager->IsRamConstrainedDevice(); + TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); + task->Resolve(env, CreateJsValue(env, ret)); + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } }; From ddf40b41ede1c539f81964aa44d3a950ea89cb0b Mon Sep 17 00:00:00 2001 From: wenyu Date: Thu, 20 Jun 2024 07:08:49 +0000 Subject: [PATCH 009/148] update frameworks/native/ability/native/BUILD.gn. Signed-off-by: wenyu --- frameworks/native/ability/native/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 5104ea482f..93baad4730 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -282,7 +282,7 @@ ohos_shared_library("abilitykit_native") { "resource_management:global_resmgr", "samgr:samgr_proxy", ] - if (host_cpu != "arm64") { + if (!(host_os == "linux" && host_cpu == "arm64")) { external_deps += [ "relational_store:native_rdb" ] } @@ -884,7 +884,7 @@ ohos_shared_library("data_ability_helper") { "relational_store:rdb_data_ability_adapter", "window_manager:libwm", ] - if (host_cpu != "arm64") { + if (!(host_os == "linux" && host_cpu == "arm64")) { external_deps += [ "relational_store:native_rdb" ] } From 8eff1b6745835e0677a4de30825e48d33844d282 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 07:15:40 +0000 Subject: [PATCH 010/148] update frameworks/js/napi/app/js_app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../app/js_app_manager/js_app_manager.cpp | 428 ++++++++++-------- 1 file changed, 237 insertions(+), 191 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 2f19d98cf3..2999f32b17 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -511,29 +511,30 @@ private: } TAG_LOGD(AAFwkTag::APPMGR, "find observer exist observer:%{public}d", static_cast(observerId)); - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, observer = observer_, observerId]( - napi_env env, NapiAsyncTask& task, int32_t status) { - if (observer == nullptr || appManager == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - int32_t ret = appManager->UnregisterApplicationStateObserver(observer); - if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { - task.ResolveWithNoError(env, CreateJsUndefined(env)); - TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", - observer->GetJsObserverMapSize()); - } else { - TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); - task.Reject(env, CreateJsErrorByNativeErr(env, ret)); - } - }; - napi_value lastParam = (argc > ARGC_TWO) ? argv[INDEX_TWO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnUnregisterApplicationStateObserver", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, observer = observer_, observerId, env, task = napiAsyncTask.get()]() { + if (observer == nullptr || appManager == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + int32_t ret = appManager->UnregisterApplicationStateObserver(observer); + if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { + task->ResolveWithNoError(env, CreateJsUndefined(env)); + TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", + observer->GetJsObserverMapSize()); + } else { + TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); + task->Reject(env, CreateJsErrorByNativeErr(env, ret)); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -611,54 +612,60 @@ private: napi_value OnGetForegroundApplications(napi_env env, size_t argc, napi_value *argv) { TAG_LOGD(AAFwkTag::APPMGR, "called"); - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) { - if (appManager == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - std::vector list; - int32_t ret = appManager->GetForegroundApplications(list); - if (ret == 0) { - TAG_LOGD(AAFwkTag::APPMGR, "success."); - task.ResolveWithNoError(env, CreateJsAppStateDataArray(env, list)); - } else { - TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); - task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); - } - }; napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnGetForegroundApplications", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, env, task = napiAsyncTask.get()]() { + if (appManager == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + std::vector list; + int32_t ret = appManager->GetForegroundApplications(list); + if (ret == 0) { + TAG_LOGD(AAFwkTag::APPMGR, "success."); + task->ResolveWithNoError(env, CreateJsAppStateDataArray(env, list)); + } else { + TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); + task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } napi_value OnGetRunningProcessInformation(napi_env env, size_t argc, napi_value* argv) { TAG_LOGD(AAFwkTag::APPMGR, "called"); - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) { - if (appManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - std::vector infos; - auto ret = appManager->GetAllRunningProcesses(infos); - if (ret == 0) { - task.ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); - } else { - task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); - } - }; napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnGetRunningProcessInformation", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, env, task = napiAsyncTask.get()]() { + if (appManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + std::vector infos; + auto ret = appManager->GetAllRunningProcesses(infos); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); + } else { + task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -729,49 +736,54 @@ private: ThrowInvalidParamError(env, "Parse param bundleType failed, must not be less then zero."); return CreateJsUndefined(env); } - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, bundleType](napi_env env, NapiAsyncTask &task, int32_t status) { - if (appManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - std::vector infos; - auto ret = appManager->GetRunningProcessesByBundleType( - static_cast(bundleType), infos); - if (ret == 0) { - task.ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); - } else { - task.Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); - } - }; napi_value lastParam = (argc > ARGC_ONE) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnGetRunningProcessInformationByBundleType", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, bundleType, env, task = napiAsyncTask.get()]() { + if (appManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + std::vector infos; + auto ret = appManager->GetRunningProcessesByBundleType( + static_cast(bundleType), infos); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); + } else { + task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } napi_value OnIsRunningInStabilityTest(napi_env env, size_t argc, napi_value* argv) { TAG_LOGD(AAFwkTag::APPMGR, "called"); - NapiAsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) { - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - bool ret = abilityManager->IsRunningInStabilityTest(); - TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret); - task.ResolveWithNoError(env, CreateJsValue(env, ret)); - }; - napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnIsRunningInStabilityTest", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + bool ret = abilityManager->IsRunningInStabilityTest(); + TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret); + task->ResolveWithNoError(env, CreateJsValue(env, ret)); + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -803,25 +815,27 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]", bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex); - NapiAsyncTask::CompleteCallback complete = - [bundleName, clearPageStack, abilityManager = abilityManager_]( - napi_env env, NapiAsyncTask& task, int32_t status) { - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - auto ret = abilityManager->KillProcess(bundleName, clearPageStack); - if (ret == 0) { - task.ResolveWithNoError(env, CreateJsUndefined(env)); - } else { - task.Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed.")); - } - }; napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessesByBundleName", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [bundleName, abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + auto ret = abilityManager->KillProcess(bundleName); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsUndefined(env)); + } else { + task->Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed.")); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -841,25 +855,27 @@ private: return CreateJsUndefined(env); } - NapiAsyncTask::CompleteCallback complete = - [bundleName, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) { - if (appManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [bundleName, abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); return; } - auto ret = appManager->ClearUpApplicationData(bundleName, 0); + auto ret = abilityManager->ClearUpApplicationData(bundleName); if (ret == 0) { - task.ResolveWithNoError(env, CreateJsUndefined(env)); + task->ResolveWithNoError(env, CreateJsUndefined(env)); } else { - task.Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); + task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); } }; - napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; - napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnClearUpApplicationData", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -885,24 +901,26 @@ private: return CreateJsUndefined(env); } - NapiAsyncTask::CompleteCallback complete = - [bundleName, appCloneIndex, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) { + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, nullptr, &result); + auto asyncTask = [bundleName, appCloneIndex, appManager = appManager_, env, task = napiAsyncTask.get()]() { if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); return; } auto ret = appManager->ClearUpApplicationData(bundleName, appCloneIndex); if (ret == 0) { - task.ResolveWithNoError(env, CreateJsUndefined(env)); + task->ResolveWithNoError(env, CreateJsUndefined(env)); } else { - task.Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); + task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); } }; - napi_value result = nullptr; - NapiAsyncTask::Schedule("JSAppManager::OnClearUpAppData", - env, CreateAsyncTaskWithLastParam(env, nullptr, nullptr, std::move(complete), &result)); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -929,22 +947,24 @@ private: return CreateJsUndefined(env); } - NapiAsyncTask::CompleteCallback complete = - [bundleName, versionCode, appManager = appManager_](napi_env env, NapiAsyncTask& task, int32_t status) { + napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [bundleName, versionCode, appManager = appManager_, env, task = napiAsyncTask.get()]() { if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); return; } bool ret = appManager->IsSharedBundleRunning(bundleName, versionCode); TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); - task.ResolveWithNoError(env, CreateJsValue(env, ret)); + task->ResolveWithNoError(env, CreateJsValue(env, ret)); }; - napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; - napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsSharedBundleRunning", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -998,50 +1018,72 @@ private: }; napi_value lastParam = (argc == ARGC_THREE && !hasClearPageStack) ? argv[INDEX_TWO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnKillProcessWithAccount", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [appManager = appManager_, bundleName, accountId, clearPageStack, + env, task = napiAsyncTask.get()]() { + if (appManager == nullptr || appManager->GetAmsMgr() == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr or amsMgr is nullptr."); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsUndefined(env)); + } else { + task->Reject(env, CreateJsErrorByNativeErr(env, ret, "Kill processes failed.")); + } + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } napi_value OnGetAppMemorySize(napi_env env, size_t argc, napi_value* argv) { - NapiAsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) { - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - int32_t memorySize = abilityManager->GetAppMemorySize(); - TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); - task.ResolveWithNoError(env, CreateJsValue(env, memorySize)); - }; - napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetAppMemorySize", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + int32_t memorySize = abilityManager->GetAppMemorySize(); + TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); + task->ResolveWithNoError(env, CreateJsValue(env, memorySize)); + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } napi_value OnIsRamConstrainedDevice(napi_env env, size_t argc, napi_value* argv) { - NapiAsyncTask::CompleteCallback complete = - [abilityManager = abilityManager_](napi_env env, NapiAsyncTask& task, int32_t status) { - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - bool ret = abilityManager->IsRamConstrainedDevice(); - TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); - task.ResolveWithNoError(env, CreateJsValue(env, ret)); - }; - napi_value lastParam = (argc > ARGC_ZERO) ? argv[INDEX_ZERO] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnIsRamConstrainedDevice", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + bool ret = abilityManager->IsRamConstrainedDevice(); + TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); + task->ResolveWithNoError(env, CreateJsValue(env, ret)); + }; + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -1061,26 +1103,27 @@ private: return CreateJsUndefined(env); } - NapiAsyncTask::CompleteCallback complete = - [pid, appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) { - if (appManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - int32_t memSize = 0; - int32_t ret = appManager->GetProcessMemoryByPid(pid, memSize); - if (ret == 0) { - task.ResolveWithNoError(env, CreateJsValue(env, memSize)); - } else { - task.Reject(env, CreateJsErrorByNativeErr(env, ret)); - } - }; - napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetProcessMemoryByPid", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [pid, appManager = appManager_, env, task = napiAsyncTask.get()]() { + if (appManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + int32_t memSize = 0; + int32_t ret = appManager->GetProcessMemoryByPid(pid, memSize); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsValue(env, memSize)); + } else { + task->Reject(env, CreateJsErrorByNativeErr(env, ret)); + } + }; + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } @@ -1116,24 +1159,27 @@ private: return CreateJsUndefined(env); } - NapiAsyncTask::CompleteCallback complete = - [bundleName, userId, appManager = appManager_](napi_env env, NapiAsyncTask &task, int32_t status) { + napi_value lastParam = isPromiseType ? nullptr : argv[argc - 1]; + napi_value result = nullptr; + std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); + auto asyncTask = [bundleName, userId, appManager = appManager_, env, task = napiAsyncTask.get()]() { if (appManager == nullptr) { - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); return; } std::vector infos; int32_t ret = appManager->GetRunningProcessInformation(bundleName, userId, infos); if (ret == 0) { - task.ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); + task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); } else { - task.Reject(env, CreateJsErrorByNativeErr(env, ret)); + task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } }; - napi_value lastParam = isPromiseType ? nullptr : argv[argc - 1]; - napi_value result = nullptr; - NapiAsyncTask::ScheduleHighQos("JSAppManager::OnGetRunningProcessInfoByBundleName", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + } + napiAsyncTask.release(); return result; } From 6e1176ba742a26ea8c86cf007658f7c072d2cb07 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 07:55:15 +0000 Subject: [PATCH 011/148] update frameworks/js/napi/app/js_app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../app/js_app_manager/js_app_manager.cpp | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 2999f32b17..0be2cf1258 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -514,7 +514,8 @@ private: napi_value lastParam = (argc > ARGC_TWO) ? argv[INDEX_TWO] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [appManager = appManager_, observer = observer_, observerId, env, task = napiAsyncTask.get()]() { + auto asyncTask = [appManager = appManager_, observer = observer_, observerId, + env, task = napiAsyncTask.get()]() { if (observer == nullptr || appManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); @@ -818,13 +819,14 @@ private: napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [bundleName, abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { + auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, + env, task = napiAsyncTask.get()]() { if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); return; } - auto ret = abilityManager->KillProcess(bundleName); + auto ret = abilityManager->KillProcess(bundleName, clearPageStack); if (ret == 0) { task->ResolveWithNoError(env, CreateJsUndefined(env)); } else { @@ -858,13 +860,13 @@ private: napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [bundleName, abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + auto asyncTask = [bundleName, appManager = appManager_, env, task = napiAsyncTask.get()]() { + if (appManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); return; } - auto ret = abilityManager->ClearUpApplicationData(bundleName); + auto ret = appManager->ClearUpApplicationData(bundleName, 0); if (ret == 0) { task->ResolveWithNoError(env, CreateJsUndefined(env)); } else { @@ -1001,21 +1003,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]", bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex); - NapiAsyncTask::CompleteCallback complete = - [appManager = appManager_, bundleName, accountId, clearPageStack]( - napi_env env, NapiAsyncTask &task, int32_t status) { - if (appManager == nullptr || appManager->GetAmsMgr() == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr or amsMgr is nullptr."); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack); - if (ret == 0) { - task.ResolveWithNoError(env, CreateJsUndefined(env)); - } else { - task.Reject(env, CreateJsErrorByNativeErr(env, ret, "Kill processes failed.")); - } - }; napi_value lastParam = (argc == ARGC_THREE && !hasClearPageStack) ? argv[INDEX_TWO] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); From 4236eb7eb16cc262dd0bbcb472cb5ff5304bb3cf Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 08:13:24 +0000 Subject: [PATCH 012/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../napi/app/app_manager/js_app_manager.cpp | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 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 3b915cd473..ddc7e4d8c5 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -354,7 +354,8 @@ private: napi_value lastParam = (argc == ARGC_TWO && !hasClearPageStack) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [bundleName, abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { + auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, errCode, + env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); return; @@ -364,7 +365,7 @@ private: task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); return; } - auto ret = abilityManager->KillProcess(bundleName); + auto ret = abilityManager->KillProcess(bundleName, clearPageStack); if (ret == 0) { task->Resolve(env, CreateJsValue(env, ret)); } else { @@ -401,17 +402,17 @@ private: napi_value lastParam = (argc == ARGC_TWO) ? argv[INDEX_ONE] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [bundleName, abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { + auto asyncTask = [bundleName, appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); return; } - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + if (appManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr")); return; } - auto ret = abilityManager->ClearUpApplicationData(bundleName); + auto ret = appManager->ClearUpApplicationData(bundleName, 0); if (ret == 0) { task->Resolve(env, CreateJsValue(env, ret)); } else { @@ -462,12 +463,13 @@ private: napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); - auto asyncTask = [appManager = appManager_, bundleName, accountId, errCode, env, task = napiAsyncTask.get()]() { + auto asyncTask = [appManager = appManager_, bundleName, accountId, clearPageStack, errCode, + env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); return; } - auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId); + auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack); if (ret == 0) { task->Resolve(env, CreateJsUndefined(env)); } else { From 65f4e7fe5c5b5b1ce317b0d68b13c605bbfc728b Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 08:18:06 +0000 Subject: [PATCH 013/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- frameworks/js/napi/app/app_manager/js_app_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 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 ddc7e4d8c5..e73a6fffbd 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -460,8 +460,8 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "kill [%{public}s], hasClearPageStack [%{public}d], clearPageStack [%{public}d],appIndex [%{public}d]", bundleName.c_str(), hasClearPageStack, clearPageStack, appIndex); - napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; - napi_value result = nullptr; + napi_value lastParam = (argc == ARGC_THREE) ? argv[INDEX_TWO] : nullptr; + napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [appManager = appManager_, bundleName, accountId, clearPageStack, errCode, env, task = napiAsyncTask.get()]() { From 525ac265f772eb3b8269b48a70f76daa4f8be629 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 09:14:05 +0000 Subject: [PATCH 014/148] update frameworks/js/napi/app/js_app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../app/js_app_manager/js_app_manager.cpp | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 0be2cf1258..c93b5efb67 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -524,14 +524,12 @@ private: int32_t ret = appManager->UnregisterApplicationStateObserver(observer); if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { task->ResolveWithNoError(env, CreateJsUndefined(env)); - TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", - observer->GetJsObserverMapSize()); + TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize()); } else { TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -633,7 +631,6 @@ private: task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -662,7 +659,6 @@ private: task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -756,7 +752,6 @@ private: task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -780,7 +775,6 @@ private: TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret); task->ResolveWithNoError(env, CreateJsValue(env, ret)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -833,7 +827,6 @@ private: task->Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -873,7 +866,6 @@ private: task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -918,7 +910,6 @@ private: task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -962,7 +953,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->ResolveWithNoError(env, CreateJsValue(env, ret)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -1020,7 +1010,6 @@ private: task->Reject(env, CreateJsErrorByNativeErr(env, ret, "Kill processes failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -1043,7 +1032,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); task->ResolveWithNoError(env, CreateJsValue(env, memorySize)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -1066,7 +1054,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->ResolveWithNoError(env, CreateJsValue(env, ret)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -1162,10 +1149,7 @@ private: task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } }; - - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); - } + napi_send_event(env, asyncTask, napi_eprio_immediate); napiAsyncTask.release(); return result; } From 353645338db65973486accf2f279339fcdd56aec Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 09:20:36 +0000 Subject: [PATCH 015/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../js/napi/app/app_manager/js_app_manager.cpp | 12 +----------- 1 file changed, 1 insertion(+), 11 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 e73a6fffbd..9a63adefed 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -202,7 +202,6 @@ private: task->Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -244,7 +243,6 @@ private: task->Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -279,7 +277,6 @@ private: task->Reject(env, CreateJsError(env, ret, "Get mission infos failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -315,7 +312,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->Resolve(env, CreateJsValue(env, ret)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -372,10 +368,8 @@ private: task->Reject(env, CreateJsError(env, ret, "kill process failed.")); } }; - - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); - } napiAsyncTask.release(); return result; } @@ -419,7 +413,6 @@ private: task->Reject(env, CreateJsError(env, ret, "clear up application failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -477,7 +470,6 @@ private: task->Reject(env, CreateJsError(env, ret, "Kill processes failed.")); } }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -513,7 +505,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); task->Resolve(env, CreateJsValue(env, memorySize)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } @@ -548,7 +539,6 @@ private: TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->Resolve(env, CreateJsValue(env, ret)); }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); } From 16c435b213951ac8f6b16b7283514dc512533f73 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Thu, 20 Jun 2024 09:21:42 +0000 Subject: [PATCH 016/148] update frameworks/js/napi/app/js_app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- frameworks/js/napi/app/js_app_manager/js_app_manager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index c93b5efb67..31dd6dff40 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -1149,7 +1149,8 @@ private: task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } }; - napi_send_event(env, asyncTask, napi_eprio_immediate); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) + TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); napiAsyncTask.release(); return result; } From 8d7a9b8af3131dd7c82da8f7a208722e6b22c196 Mon Sep 17 00:00:00 2001 From: zhu-bingwei123 Date: Thu, 20 Jun 2024 18:53:39 +0800 Subject: [PATCH 017/148] =?UTF-8?q?[=E5=85=83=E8=83=BD=E5=8A=9B]=E8=A7=A3?= =?UTF-8?q?=E5=86=B3TDD=20crash=E9=97=AE=E9=A2=98(connection=5Frecord=5Fte?= =?UTF-8?q?st,=20mission=5Flistener=5Ftest=E7=AD=89)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhu-bingwei123 --- test/unittest/ability_scheduler_proxy_test/BUILD.gn | 7 ++++++- test/unittest/connection_record_test/BUILD.gn | 7 ++++++- test/unittest/connection_state_item_test/BUILD.gn | 7 ++++++- test/unittest/connection_state_manager_test/BUILD.gn | 7 ++++++- test/unittest/data_ability_record_test/BUILD.gn | 7 ++++++- test/unittest/implicit_start_processor_test/BUILD.gn | 7 ++++++- test/unittest/mission_list_manager_ut_test/BUILD.gn | 7 ++++++- test/unittest/mission_listener_proxy_test/BUILD.gn | 7 ++++++- test/unittest/mission_listener_test/BUILD.gn | 7 ++++++- test/unittest/pending_want_record_test/BUILD.gn | 7 ++++++- test/unittest/remote_mission_listener_proxy_test/BUILD.gn | 7 ++++++- test/unittest/want_receiver_proxy_test/BUILD.gn | 7 ++++++- test/unittest/want_sender_proxy_test/BUILD.gn | 7 ++++++- test/unittest/want_sender_stub_test/BUILD.gn | 7 ++++++- 14 files changed, 84 insertions(+), 14 deletions(-) diff --git a/test/unittest/ability_scheduler_proxy_test/BUILD.gn b/test/unittest/ability_scheduler_proxy_test/BUILD.gn index 94012bc23a..32b8e84667 100644 --- a/test/unittest/ability_scheduler_proxy_test/BUILD.gn +++ b/test/unittest/ability_scheduler_proxy_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_scheduler_proxy_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/connection_record_test/BUILD.gn b/test/unittest/connection_record_test/BUILD.gn index fb97ed0533..28436f5122 100644 --- a/test/unittest/connection_record_test/BUILD.gn +++ b/test/unittest/connection_record_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("connection_record_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/connection_state_item_test/BUILD.gn b/test/unittest/connection_state_item_test/BUILD.gn index 7d77735f25..bc458b9384 100755 --- a/test/unittest/connection_state_item_test/BUILD.gn +++ b/test/unittest/connection_state_item_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("connection_state_item_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/connection_state_manager_test/BUILD.gn b/test/unittest/connection_state_manager_test/BUILD.gn index f27228ff04..7f8c8e2973 100755 --- a/test/unittest/connection_state_manager_test/BUILD.gn +++ b/test/unittest/connection_state_manager_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("connection_state_manager_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/data_ability_record_test/BUILD.gn b/test/unittest/data_ability_record_test/BUILD.gn index fbb5d2e1e0..b0e7a34721 100644 --- a/test/unittest/data_ability_record_test/BUILD.gn +++ b/test/unittest/data_ability_record_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("data_ability_record_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/ability_scheduler_mock", diff --git a/test/unittest/implicit_start_processor_test/BUILD.gn b/test/unittest/implicit_start_processor_test/BUILD.gn index 6b137d8243..36a75fd373 100755 --- a/test/unittest/implicit_start_processor_test/BUILD.gn +++ b/test/unittest/implicit_start_processor_test/BUILD.gn @@ -20,7 +20,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("implicit_start_processor_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/mission_list_manager_ut_test/BUILD.gn b/test/unittest/mission_list_manager_ut_test/BUILD.gn index f96461b545..56e79bce5b 100644 --- a/test/unittest/mission_list_manager_ut_test/BUILD.gn +++ b/test/unittest/mission_list_manager_ut_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("mission_list_manager_ut_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/mission_listener_proxy_test/BUILD.gn b/test/unittest/mission_listener_proxy_test/BUILD.gn index 56f2ef0983..586d23d39b 100755 --- a/test/unittest/mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/mission_listener_proxy_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("mission_listener_proxy_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/mission_listener_test/BUILD.gn b/test/unittest/mission_listener_test/BUILD.gn index 53ae6f859c..84807a8561 100644 --- a/test/unittest/mission_listener_test/BUILD.gn +++ b/test/unittest/mission_listener_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("mission_listener_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core", diff --git a/test/unittest/pending_want_record_test/BUILD.gn b/test/unittest/pending_want_record_test/BUILD.gn index 81def2a390..fd639818d6 100644 --- a/test/unittest/pending_want_record_test/BUILD.gn +++ b/test/unittest/pending_want_record_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("pending_want_record_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn index 9be3156731..fc84df01e6 100755 --- a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("remote_mission_listener_proxy_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/want_receiver_proxy_test/BUILD.gn b/test/unittest/want_receiver_proxy_test/BUILD.gn index dfc727d91d..a5aef87d5b 100644 --- a/test/unittest/want_receiver_proxy_test/BUILD.gn +++ b/test/unittest/want_receiver_proxy_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("want_receiver_proxy_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/want_sender_proxy_test/BUILD.gn b/test/unittest/want_sender_proxy_test/BUILD.gn index a9c48baba8..02a82d91e4 100644 --- a/test/unittest/want_sender_proxy_test/BUILD.gn +++ b/test/unittest/want_sender_proxy_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("want_sender_proxy_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", diff --git a/test/unittest/want_sender_stub_test/BUILD.gn b/test/unittest/want_sender_stub_test/BUILD.gn index 96fdb67b2d..02b0ea3f07 100644 --- a/test/unittest/want_sender_stub_test/BUILD.gn +++ b/test/unittest/want_sender_stub_test/BUILD.gn @@ -18,7 +18,12 @@ module_output_path = "ability_runtime/abilitymgr" ohos_unittest("want_sender_stub_test") { module_out_path = module_output_path - + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" include_dirs = [ "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", From 9c008c910db59b3b8a4e087ab27f6fa3147e8495 Mon Sep 17 00:00:00 2001 From: xia Date: Thu, 20 Jun 2024 15:29:35 +0800 Subject: [PATCH 018/148] StartHighestPriorityAbility Signed-off-by: xia --- .../include/ability_manager_service.h | 2 +- .../interceptor/disposed_rule_interceptor.h | 1 + .../src/ability_manager_service.cpp | 8 ++--- .../interceptor/ability_jump_interceptor.cpp | 10 +++--- .../src/interceptor/control_interceptor.cpp | 10 +++--- .../interceptor/crowd_test_interceptor.cpp | 2 +- .../interceptor/disposed_rule_interceptor.cpp | 32 +++++++++++++++++-- .../ecological_rule_interceptor.cpp | 4 +-- .../interceptor/screen_unlock_interceptor.cpp | 2 +- .../start_other_app_interceptor.cpp | 6 ++-- .../ams_system_dialog/AppScope/app.json | 4 +-- .../JumpInterceptorServiceExtAbility.ts | 18 +++++++---- .../SelectorServiceExtAbility.ts | 17 +++++----- .../TipsServiceExtAbility.ts | 7 ++-- .../AssertFaultShareExtAbility.ts | 16 ++++++---- 15 files changed, 85 insertions(+), 54 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 6166b5626f..16b1d90c7a 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1768,7 +1768,7 @@ private: * start highest priority ability. * */ - void StartHighestPriorityAbility(int32_t userId, bool isBoot, sptr callback); + void StartHighestPriorityAbility(int32_t userId, bool isBoot); /** * connet bms. * diff --git a/services/abilitymgr/include/interceptor/disposed_rule_interceptor.h b/services/abilitymgr/include/interceptor/disposed_rule_interceptor.h index a82ffd9992..a75fd45f44 100644 --- a/services/abilitymgr/include/interceptor/disposed_rule_interceptor.h +++ b/services/abilitymgr/include/interceptor/disposed_rule_interceptor.h @@ -44,6 +44,7 @@ private: ErrCode StartNonBlockRule(const Want &want, AppExecFwk::DisposedRule &disposedRule); sptr GetAppMgr(); ErrCode CreateModalUIExtension(const Want &want, const sptr &callerToken); + void SetInterceptInfo(const Want &want, AppExecFwk::DisposedRule &disposedRule); private: std::shared_ptr taskHandler_; std::map> disposedObserverMap_; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f6d19d10a3..caa8adac39 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -5632,7 +5632,7 @@ int32_t AbilityManagerService::GetUserId() const return U0_USER_ID; } -void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBoot, sptr callback) +void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isBoot) { TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s", __func__); auto bms = GetBundleManager(); @@ -5651,7 +5651,6 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB ++attemptNums; if (!isBoot && attemptNums > SWITCH_ACCOUNT_TRY) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Query highest priority ability failed."); - callback->OnStartUserDone(userId, ERR_QUERY_HIGHEST_PRIORITY_ABILITY); return; } AbilityRequest abilityRequest; @@ -5660,10 +5659,8 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB if (abilityInfo.name.empty() && extensionAbilityInfo.name.empty()) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Query highest priority ability failed"); - callback->OnStartUserDone(userId, ERR_QUERY_HIGHEST_PRIORITY_ABILITY); return; } - callback->OnStartUserDone(userId, ERR_OK); Want abilityWant; // donot use 'want' here, because the entity of 'want' is not empty if (!abilityInfo.name.empty()) { @@ -7393,8 +7390,9 @@ void AbilityManagerService::SwitchToUser(int32_t oldUserId, int32_t userId, sptr ConnectBmsService(); StartUserApps(); } + callback->OnStartUserDone(userId, ERR_OK); bool isBoot = oldUserId == U0_USER_ID ? true : false; - StartHighestPriorityAbility(userId, isBoot, callback); + StartHighestPriorityAbility(userId, isBoot); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled() && AmsConfigurationParameter::GetInstance().MultiUserType() != 0) { TAG_LOGI(AAFwkTag::ABILITYMGR, "no need to terminate old scb."); diff --git a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp index d6479d3fe8..6de7371132 100644 --- a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp @@ -30,11 +30,11 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string JUMP_DIALOG_CALLER_BUNDLE_NAME = "interceptor_callerBundleName"; -const std::string JUMP_DIALOG_CALLER_MODULE_NAME = "interceptor_callerModuleName"; -const std::string JUMP_DIALOG_CALLER_LABEL_ID = "interceptor_callerLabelId"; -const std::string JUMP_DIALOG_TARGET_MODULE_NAME = "interceptor_targetModuleName"; -const std::string JUMP_DIALOG_TARGET_LABEL_ID = "interceptor_targetLabelId"; +constexpr const char* JUMP_DIALOG_CALLER_BUNDLE_NAME = "interceptor_callerBundleName"; +constexpr const char* JUMP_DIALOG_CALLER_MODULE_NAME = "interceptor_callerModuleName"; +constexpr const char* JUMP_DIALOG_CALLER_LABEL_ID = "interceptor_callerLabelId"; +constexpr const char* JUMP_DIALOG_TARGET_MODULE_NAME = "interceptor_targetModuleName"; +constexpr const char* JUMP_DIALOG_TARGET_LABEL_ID = "interceptor_targetLabelId"; } ErrCode AbilityJumpInterceptor::DoProcess(AbilityInterceptorParam param) { diff --git a/services/abilitymgr/src/interceptor/control_interceptor.cpp b/services/abilitymgr/src/interceptor/control_interceptor.cpp index a25da3855e..2641a04fdd 100644 --- a/services/abilitymgr/src/interceptor/control_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/control_interceptor.cpp @@ -26,11 +26,11 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string INTERCEPT_PARAMETERS = "intercept_parammeters"; -const std::string INTERCEPT_BUNDLE_NAME = "intercept_bundleName"; -const std::string INTERCEPT_ABILITY_NAME = "intercept_abilityName"; -const std::string INTERCEPT_MODULE_NAME = "intercept_moduleName"; -const std::string IS_FROM_PARENTCONTROL = "ohos.ability.isFromParentControl"; +constexpr const char* INTERCEPT_PARAMETERS = "intercept_parammeters"; +constexpr const char* INTERCEPT_BUNDLE_NAME = "intercept_bundleName"; +constexpr const char* INTERCEPT_ABILITY_NAME = "intercept_abilityName"; +constexpr const char* INTERCEPT_MODULE_NAME = "intercept_moduleName"; +constexpr const char* IS_FROM_PARENTCONTROL = "ohos.ability.isFromParentControl"; } ErrCode ControlInterceptor::DoProcess(AbilityInterceptorParam param) diff --git a/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp b/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp index e78cd48ae7..e874f343c3 100644 --- a/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string ACTION_MARKET_CROWDTEST = "ohos.want.action.marketCrowdTest"; +constexpr const char* ACTION_MARKET_CROWDTEST = "ohos.want.action.marketCrowdTest"; } ErrCode CrowdTestInterceptor::DoProcess(AbilityInterceptorParam param) { diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index 4366dfe785..9987e46bfe 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -28,10 +28,15 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string UNREGISTER_EVENT_TASK = "unregister event task"; -const std::string UNREGISTER_TIMEOUT_OBSERVER_TASK = "unregister timeout observer task"; +constexpr const char* UNREGISTER_EVENT_TASK = "unregister event task"; +constexpr const char* UNREGISTER_TIMEOUT_OBSERVER_TASK = "unregister timeout observer task"; constexpr int UNREGISTER_OBSERVER_MICRO_SECONDS = 5000; -const std::string UIEXTENSION_MODAL_TYPE = "ability.want.params.modalType"; +constexpr const char* UIEXTENSION_MODAL_TYPE = "ability.want.params.modalType"; +constexpr const char* INTERCEPT_PARAMETERS = "intercept_parammeters"; +constexpr const char* INTERCEPT_BUNDLE_NAME = "intercept_bundleName"; +constexpr const char* INTERCEPT_ABILITY_NAME = "intercept_abilityName"; +constexpr const char* INTERCEPT_MODULE_NAME = "intercept_moduleName"; +constexpr const char* IS_FROM_PARENTCONTROL = "ohos.ability.isFromParentControl"; } ErrCode DisposedRuleInterceptor::DoProcess(AbilityInterceptorParam param) @@ -53,6 +58,7 @@ ErrCode DisposedRuleInterceptor::DoProcess(AbilityInterceptorParam param) TAG_LOGE(AAFwkTag::ABILITYMGR, "Can not start disposed want with same bundleName"); return AbilityUtil::EdmErrorType(disposedRule.isEdm); } + SetInterceptInfo(param.want, disposedRule); if (disposedRule.componentType == AppExecFwk::ComponentType::UI_ABILITY) { int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*disposedRule.want, param.requestCode, param.userId)); @@ -159,6 +165,7 @@ ErrCode DisposedRuleInterceptor::StartNonBlockRule(const Want &want, AppExecFwk: TAG_LOGE(AAFwkTag::ABILITYMGR, "Can not start disposed app with same bundleName"); return ERR_OK; } + SetInterceptInfo(param.want, disposedRule); std::string bundleName = want.GetBundle(); { std::lock_guard guard(observerLock_); @@ -249,5 +256,24 @@ ErrCode DisposedRuleInterceptor::CreateModalUIExtension(const Want &want, const return abilityRecord->CreateModalUIExtension(want); } } + +void DisposedRuleInterceptor::SetInterceptInfo(const Want &want, AppExecFwk::DisposedRule &disposedRule) +{ + if (disposedRule.want == nullptr) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "disposedWant is nullptr"); + return; + } + if (disposedRule.want->GetBoolParam(IS_FROM_PARENTCONTROL, false)) { + auto disposedParam = disposedRule.want->GetParams(); + sptr interceptParam = WantParamWrapper::Box(want.GetParams()); + if (interceptParam != nullptr) { + disposedParam.SetParam(INTERCEPT_PARAMETERS, interceptParam); + } + disposedRule.want->SetParams(disposedParam); + disposedRule.want->SetParam(INTERCEPT_BUNDLE_NAME, want.GetElement().GetBundleName()); + disposedRule.want->SetParam(INTERCEPT_ABILITY_NAME, want.GetElement().GetAbilityName()); + disposedRule.want->SetParam(INTERCEPT_MODULE_NAME, want.GetElement().GetModuleName()); + } +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp index 10b9bd0271..01af889c91 100644 --- a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp @@ -29,8 +29,8 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE = "persist.sys.abilityms.support.ecologicalrulemgrservice"; -const std::string BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; +constexpr const char* ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE = "persist.sys.abilityms.support.ecologicalrulemgrservice"; +constexpr const char* BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; } ErrCode EcologicalRuleInterceptor::DoProcess(AbilityInterceptorParam param) { diff --git a/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp b/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp index 7c9472fd19..cd0b080d06 100644 --- a/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/screen_unlock_interceptor.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string SUPPORT_SCREEN_UNLOCK_STARTUP = "persist.sys.ability.support.screen_unlock_startup"; +constexpr const char* SUPPORT_SCREEN_UNLOCK_STARTUP = "persist.sys.ability.support.screen_unlock_startup"; } ErrCode ScreenUnlockInterceptor::DoProcess(AbilityInterceptorParam param) { diff --git a/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp b/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp index ef080dbe79..b82137aef6 100644 --- a/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/start_other_app_interceptor.cpp @@ -30,9 +30,9 @@ namespace AAFwk { namespace { const uint32_t API_VERSION_MOD = 100; const uint32_t API_SINCE_VISION = 12; -const std::string ABILITY_SUPPORT_START_OTHER_APP = "persist.sys.abilityms.support.start_other_app"; -const std::string IS_DELEGATOR_CALL = "isDelegatorCall"; -const std::string OPEN_LINK_SCENE_IDENTIFICATION = "appLinkingOnly"; +constexpr const char* ABILITY_SUPPORT_START_OTHER_APP = "persist.sys.abilityms.support.start_other_app"; +constexpr const char* IS_DELEGATOR_CALL = "isDelegatorCall"; +constexpr const char* OPEN_LINK_SCENE_IDENTIFICATION = "appLinkingOnly"; } ErrCode StartOtherAppInterceptor::DoProcess(AbilityInterceptorParam param) diff --git a/services/dialog_ui/ams_system_dialog/AppScope/app.json b/services/dialog_ui/ams_system_dialog/AppScope/app.json index 1a0d7f436c..eb0725a887 100644 --- a/services/dialog_ui/ams_system_dialog/AppScope/app.json +++ b/services/dialog_ui/ams_system_dialog/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.amsdialog", "vendor": "example", - "versionCode": 1000003, - "versionName": "1.0.0", + "versionCode": 1000005, + "versionName": "1.2.0", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true, diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/JumpInterceptorServiceExtAbility.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/JumpInterceptorServiceExtAbility.ts index aeafe0cac1..87aad86331 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/JumpInterceptorServiceExtAbility.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/JumpInterceptorServiceExtAbility.ts @@ -31,13 +31,17 @@ export default class JumpInterceptorServiceExtAbility extends extension { async onRequest(want, startId) { globalThis.abilityWant = want; - globalThis.params = JSON.parse(want.parameters.params); - globalThis.position = JSON.parse(want.parameters.position); - globalThis.interceptor_callerBundleName = want.parameters.interceptor_callerBundleName; - globalThis.interceptor_callerModuleName = want.parameters.interceptor_callerModuleName; - globalThis.interceptor_callerLabelId = want.parameters.interceptor_callerLabelId; - globalThis.interceptor_targetModuleName = want.parameters.interceptor_targetModuleName; - globalThis.interceptor_targetLabelId = want.parameters.interceptor_targetLabelId; + try { + globalThis.params = JSON.parse(want.parameters.params); + globalThis.position = JSON.parse(want.parameters.position); + globalThis.interceptor_callerBundleName = want.parameters.interceptor_callerBundleName; + globalThis.interceptor_callerModuleName = want.parameters.interceptor_callerModuleName; + globalThis.interceptor_callerLabelId = want.parameters.interceptor_callerLabelId; + globalThis.interceptor_targetModuleName = want.parameters.interceptor_targetModuleName; + globalThis.interceptor_targetLabelId = want.parameters.interceptor_targetLabelId; + } catch (error) { + console.error(TAG, `getMediaBase64 error:${JSON.stringify(error)}`); + } await this.getHapResource(); display.getDefaultDisplay().then(dis => { let navigationBarRect = { diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts index 981182fb84..c08a6464ab 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts @@ -142,14 +142,14 @@ export default class SelectorServiceExtensionAbility extends extension { async onRequest(want, startId) { console.debug(TAG, 'onRequest, want: ' + JSON.stringify(want)); globalThis.abilityWant = want; - globalThis.params = JSON.parse(want.parameters.params); - let displayClass = display.getDefaultDisplaySync(); - let lineNums = 0; - if (globalThis.params && globalThis.params.hapList && globalThis.params.hapList.length) { - lineNums = globalThis.params.hapList.length; - } - globalThis.position = PositionUtils.getSelectorDialogPosition(lineNums); try { + globalThis.params = JSON.parse(want.parameters.params); + globalThis.callerToken = want.parameters.callerToken; + let lineNums = 0; + if (globalThis.params && globalThis.params.hapList && globalThis.params.hapList.length) { + lineNums = globalThis.params.hapList.length; + } + globalThis.position = PositionUtils.getSelectorDialogPosition(lineNums); display.on('change', (data: number) => { let position = PositionUtils.getSelectorDialogPosition(lineNums); if (position.offsetX !== globalThis.position.offsetX || position.offsetY !== globalThis.position.offsetY) { @@ -163,11 +163,10 @@ export default class SelectorServiceExtensionAbility extends extension { } catch (exception) { console.error('Failed to register callback. Code: ' + JSON.stringify(exception)); } - + let displayClass = display.getDefaultDisplaySync(); console.debug(TAG, 'onRequest display is' + JSON.stringify(displayClass)); console.debug(TAG, 'onRequest, want: ' + JSON.stringify(want)); console.debug(TAG, 'onRequest, params: ' + JSON.stringify(globalThis.params)); - globalThis.callerToken = want.parameters.callerToken; console.debug(TAG, 'onRequest, position: ' + JSON.stringify(globalThis.position)); if (!globalThis.params.isDefaultSelector) { globalThis.modelFlag = Boolean(globalThis.params.modelFlag); diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts index 26124ae7f5..8ac87a0d16 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts @@ -33,11 +33,10 @@ export default class TipsServiceExtensionAbility extends extension { onRequest(want, startId) { console.debug(TAG, 'onRequest, want: ' + JSON.stringify(want)); globalThis.abilityWant = want; - globalThis.params = JSON.parse(want.parameters.params); - globalThis.position = PositionUtils.getTipsDialogPosition(); - globalThis.callerToken = want.parameters.callerToken; - try { + globalThis.params = JSON.parse(want.parameters.params); + globalThis.position = PositionUtils.getTipsDialogPosition(); + globalThis.callerToken = want.parameters.callerToken; display.on('change', (data: number) => { let position = PositionUtils.getTipsDialogPosition(); if (position.offsetX !== globalThis.position.offsetX || position.offsetY !== globalThis.position.offsetY) { diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ShareExtAbility/AssertFaultShareExtAbility.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ShareExtAbility/AssertFaultShareExtAbility.ts index 4e9a66694e..eaceab85c4 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ShareExtAbility/AssertFaultShareExtAbility.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ShareExtAbility/AssertFaultShareExtAbility.ts @@ -41,12 +41,16 @@ export default class UiExtAbility extends UIExtensionAbility { } onSessionCreate(want: Want, session: UIExtensionContentSession): void { - this.sessionId = want.parameters[wantConstant.Params.ASSERT_FAULT_SESSION_ID] as string, - this.storage = new LocalStorage( - { - 'session': session, - 'textDetail' : want.parameters[TEXT_DETAIL] - }); + try { + this.sessionId = want.parameters[wantConstant.Params.ASSERT_FAULT_SESSION_ID] as string, + this.storage = new LocalStorage( + { + 'session': session, + 'textDetail' : want.parameters[TEXT_DETAIL] + }); + } catch (exception) { + console.error('Failed to register callback. Code: ' + JSON.stringify(exception)); + } session.loadContent('pages/assertFaultDialog', this.storage); session.setWindowBackgroundColor('#00000000'); } From 8a32d31cf7fe07ad19598d3968164ab552c59416 Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Tue, 18 Jun 2024 19:44:10 +0800 Subject: [PATCH 019/148] refactor: cfi Signed-off-by: yangxuguang-huawei --- .../dialog_request_callback_stub.cpp | 10 +- .../native/free_install_observer_stub.cpp | 17 +- .../include/ability_manager_errors.h | 5 + .../dialog_request_callback_stub.h | 3 - .../native/free_install_observer_stub.h | 2 - .../include/ability_manager_service.h | 9 - .../abilitymgr/include/ability_manager_stub.h | 52 +- .../include/ability_scheduler_stub.h | 10 +- .../src/ability_manager_service.cpp | 91 +- .../abilitymgr/src/ability_manager_stub.cpp | 1176 +++++++++++------ .../abilitymgr/src/ability_scheduler_stub.cpp | 165 ++- .../src/resident_process_manager.cpp | 5 +- services/appmgr/include/app_mgr_service.h | 9 - services/appmgr/src/ams_mgr_scheduler.cpp | 63 +- services/appmgr/src/app_death_recipient.cpp | 7 +- services/appmgr/src/app_mgr_service.cpp | 184 ++- services/appmgr/src/app_mgr_service_inner.cpp | 12 +- .../abilitymanagerservicesecond_fuzzer.cpp | 2 - .../ability_manager_service_dump_test.cpp | 13 - tools/aa/src/ability_command.cpp | 34 +- tools/aa/src/ability_tool_command.cpp | 10 +- 21 files changed, 1170 insertions(+), 709 deletions(-) diff --git a/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp b/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp index b020836115..519f851adb 100755 --- a/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp +++ b/frameworks/native/ability/native/dialog_request_callback/dialog_request_callback_stub.cpp @@ -23,10 +23,7 @@ namespace OHOS { namespace AbilityRuntime { DialogRequestCallbackStub::DialogRequestCallbackStub() -{ - vecMemberFunc_.resize(IDialogRequestCallback::CODE_MAX); - vecMemberFunc_[CODE_SEND_RESULT] = &DialogRequestCallbackStub::SendResultInner; -} +{} int DialogRequestCallbackStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -38,9 +35,8 @@ int DialogRequestCallbackStub::OnRemoteRequest( return ERR_INVALID_STATE; } - if (code < IDialogRequestCallback::CODE_MAX) { - auto memberFunc = vecMemberFunc_[code]; - return (this->*memberFunc)(data, reply); + if (code == CODE_SEND_RESULT) { + return SendResultInner(data, reply); } return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/frameworks/native/ability/native/free_install_observer_stub.cpp b/frameworks/native/ability/native/free_install_observer_stub.cpp index dbcc61039d..68a4d08c19 100644 --- a/frameworks/native/ability/native/free_install_observer_stub.cpp +++ b/frameworks/native/ability/native/free_install_observer_stub.cpp @@ -23,15 +23,10 @@ namespace OHOS { namespace AbilityRuntime { FreeInstallObserverStub::FreeInstallObserverStub() -{ - memberFuncMap_[IFreeInstallObserver::ON_INSTALL_FINISHED] = - &FreeInstallObserverStub::OnInstallFinishedInner; -} +{} FreeInstallObserverStub::~FreeInstallObserverStub() -{ - memberFuncMap_.clear(); -} +{} int FreeInstallObserverStub::OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply) { @@ -54,12 +49,8 @@ int FreeInstallObserverStub::OnRemoteRequest( return ERR_INVALID_STATE; } - auto itFunc = memberFuncMap_.find(code); - if (itFunc != memberFuncMap_.end()) { - auto memberFunc = itFunc->second; - if (memberFunc != nullptr) { - return (this->*memberFunc)(data, reply); - } + if (code == IFreeInstallObserver::ON_INSTALL_FINISHED) { + return OnInstallFinishedInner(data, reply); } return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 3eacb1691d..531e2a7c6b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -549,6 +549,11 @@ enum { * Native error(2097258) for target bundle not exist. */ ERR_BUNDLE_NOT_EXIST, + + /** + * Native error(3000000) for target bundle not exist. + */ + ERR_CODE_NOT_EXIST = 3000000, }; enum { diff --git a/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h b/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h index 68bec89043..e421e8bacf 100755 --- a/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h +++ b/interfaces/kits/native/ability/native/dialog_request_callback/dialog_request_callback_stub.h @@ -41,9 +41,6 @@ private: DISALLOW_COPY_AND_MOVE(DialogRequestCallbackStub); int SendResultInner(MessageParcel &data, MessageParcel &reply); - - using StubFunc = int (DialogRequestCallbackStub::*)(MessageParcel &data, MessageParcel &reply); - std::vector vecMemberFunc_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/interfaces/kits/native/ability/native/free_install_observer_stub.h b/interfaces/kits/native/ability/native/free_install_observer_stub.h index fb8d4887f9..d1a4c6701a 100644 --- a/interfaces/kits/native/ability/native/free_install_observer_stub.h +++ b/interfaces/kits/native/ability/native/free_install_observer_stub.h @@ -35,8 +35,6 @@ public: private: DISALLOW_COPY_AND_MOVE(FreeInstallObserverStub); int OnInstallFinishedInner(MessageParcel &data, MessageParcel &reply); - using FreeInstallObserverFunc = int32_t (FreeInstallObserverStub::*)(MessageParcel &data, MessageParcel &reply); - std::map memberFuncMap_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index a844d821db..bffc6220fb 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1837,14 +1837,12 @@ private: void DataDumpStateInner(const std::string &args, std::vector &info); void DumpMissionListInner(const std::string &args, std::vector &info); void DumpMissionInfosInner(const std::string &args, std::vector &info); - void DumpFuncInit(); bool JudgeMultiUserConcurrency(const int32_t userId); /** * dumpsys info * */ - void DumpSysFuncInit(); void DumpSysInner( const std::string &args, std::vector &info, bool isClient, bool isUserID, int userId); void DumpSysMissionListInner( @@ -1920,13 +1918,6 @@ private: int VerifyAccountPermission(int32_t userId); - using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector &info); - std::map dumpFuncMap_; - - using DumpSysFuncType = void (AbilityManagerService::*)( - const std::string& args, std::vector& state, bool isClient, bool isUserID, int UserID); - std::map dumpsysFuncMap_; - int CheckStaticCfgPermissionForAbility(const AppExecFwk::AbilityInfo &abilityInfo, uint32_t tokenId); int CheckStaticCfgPermissionForSkill(const AppExecFwk::AbilityRequest &abilityRequest, uint32_t tokenId); diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 3389fe8ba6..b2e56e3768 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -66,11 +66,6 @@ public: virtual int GetConnectionData(std::vector &connectionData); private: - void FirstStepInit(); - void SecondStepInit(); - void ThirdStepInit(); - void FourthStepInit(); - void FifthStepInit(); int TerminateAbilityInner(MessageParcel &data, MessageParcel &reply); int TerminateUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply); int CloseUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply); @@ -218,9 +213,6 @@ private: int FreeInstallAbilityFromRemoteInner(MessageParcel &data, MessageParcel &reply); int AddFreeInstallObserverInner(MessageParcel &data, MessageParcel &reply); - using RequestFuncType = int (AbilityManagerStub::*)(MessageParcel &data, MessageParcel &reply); - std::map requestFuncMap_; - #ifdef ABILITY_COMMAND_FOR_TEST int BlockAmsServiceInner(MessageParcel &data, MessageParcel &reply); int BlockAbilityInner(MessageParcel &data, MessageParcel &reply); @@ -302,6 +294,50 @@ private: int32_t GetAbilityStateByPersistentIdInner(MessageParcel &data, MessageParcel &reply); int32_t TransferAbilityResultForExtensionInner(MessageParcel &data, MessageParcel &reply); int32_t NotifyFrozenProcessByRSSInner(MessageParcel &data, MessageParcel &reply); + int OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerFifth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerSixth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerEighth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerNinth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerTenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerEleventh(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInner(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerTwelveth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerThirteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerFourteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerFifteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerSixteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerSeventeenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerEighteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerNineteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int HandleOnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); + int HandleOnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_scheduler_stub.h b/services/abilitymgr/include/ability_scheduler_stub.h index 40291b9e25..50e26ca37b 100644 --- a/services/abilitymgr/include/ability_scheduler_stub.h +++ b/services/abilitymgr/include/ability_scheduler_stub.h @@ -75,8 +75,14 @@ private: int ShareDataInner(MessageParcel &data, MessageParcel &reply); int CreateModalUIExtensionInner(MessageParcel &data, MessageParcel &reply); int UpdateSessionTokenInner(MessageParcel &data, MessageParcel &reply); - using RequestFuncType = int (AbilitySchedulerStub::*)(MessageParcel &data, MessageParcel &reply); - std::map requestFuncMap_; + int OnRemoteRequestInner( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerFirst( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerSecond( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); + int OnRemoteRequestInnerThird( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); }; /** diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a1456145e0..fb9f1815f6 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -340,10 +340,7 @@ AbilityManagerService::AbilityManagerService() : SystemAbility(ABILITY_MGR_SERVICE_ID, true), state_(ServiceRunningState::STATE_NOT_START), bundleMgrHelper_(nullptr) -{ - DumpFuncInit(); - DumpSysFuncInit(); -} +{} AbilityManagerService::~AbilityManagerService() {} @@ -4788,29 +4785,6 @@ int AbilityManagerService::AttachAbilityThread( } } -void AbilityManagerService::DumpFuncInit() -{ - dumpFuncMap_[KEY_DUMP_SERVICE] = &AbilityManagerService::DumpStateInner; - dumpFuncMap_[KEY_DUMP_DATA] = &AbilityManagerService::DataDumpStateInner; - - dumpFuncMap_[KEY_DUMP_ALL] = &AbilityManagerService::DumpInner; - dumpFuncMap_[KEY_DUMP_MISSION] = &AbilityManagerService::DumpMissionInner; - dumpFuncMap_[KEY_DUMP_MISSION_LIST] = &AbilityManagerService::DumpMissionListInner; - dumpFuncMap_[KEY_DUMP_MISSION_INFOS] = &AbilityManagerService::DumpMissionInfosInner; -} - -void AbilityManagerService::DumpSysFuncInit() -{ - dumpsysFuncMap_[KEY_DUMPSYS_ALL] = &AbilityManagerService::DumpSysInner; - dumpsysFuncMap_[KEY_DUMPSYS_SERVICE] = &AbilityManagerService::DumpSysStateInner; - dumpsysFuncMap_[KEY_DUMPSYS_PENDING] = &AbilityManagerService::DumpSysPendingInner; - dumpsysFuncMap_[KEY_DUMPSYS_PROCESS] = &AbilityManagerService::DumpSysProcess; - dumpsysFuncMap_[KEY_DUMPSYS_DATA] = &AbilityManagerService::DataDumpSysStateInner; - - dumpsysFuncMap_[KEY_DUMPSYS_MISSION_LIST] = &AbilityManagerService::DumpSysMissionListInner; - dumpsysFuncMap_[KEY_DUMPSYS_ABILITY] = &AbilityManagerService::DumpSysAbilityInner; -} - void AbilityManagerService::DumpSysInner( const std::string& args, std::vector& info, bool isClient, bool isUserID, int userId) { @@ -5283,15 +5257,29 @@ void AbilityManagerService::DumpState(const std::string &args, std::vectorsecond; - auto itFunc = dumpFuncMap_.find(key); - if (itFunc != dumpFuncMap_.end()) { - auto dumpFunc = itFunc->second; - if (dumpFunc != nullptr) { - (this->*dumpFunc)(args, info); - return; - } + switch (key) { + case KEY_DUMP_SERVICE: + DumpStateInner(args, info); + break; + case KEY_DUMP_DATA: + DataDumpStateInner(args, info); + break; + case KEY_DUMP_ALL: + DumpInner(args, info); + break; + case KEY_DUMP_MISSION: + DumpMissionInner(args, info); + break; + case KEY_DUMP_MISSION_LIST: + DumpMissionListInner(args, info); + break; + case KEY_DUMP_MISSION_INFOS: + DumpMissionInfosInner(args, info); + break; + default: + info.push_back("error: invalid argument, please see 'ability dump -h'."); + break; } - info.push_back("error: invalid argument, please see 'ability dump -h'."); } void AbilityManagerService::DumpSysState( @@ -5314,15 +5302,32 @@ void AbilityManagerService::DumpSysState( return; } DumpsysKey key = it->second; - auto itFunc = dumpsysFuncMap_.find(key); - if (itFunc != dumpsysFuncMap_.end()) { - auto dumpsysFunc = itFunc->second; - if (dumpsysFunc != nullptr) { - (this->*dumpsysFunc)(args, info, isClient, isUserID, userId); - return; - } + switch (key) { + case KEY_DUMPSYS_ALL: + DumpSysInner(args, info, isClient, isUserID, userId); + break; + case KEY_DUMPSYS_SERVICE: + DumpSysStateInner(args, info, isClient, isUserID, userId); + break; + case KEY_DUMPSYS_PENDING: + DumpSysPendingInner(args, info, isClient, isUserID, userId); + break; + case KEY_DUMPSYS_PROCESS: + DumpSysProcess(args, info, isClient, isUserID, userId); + break; + case KEY_DUMPSYS_DATA: + DataDumpSysStateInner(args, info, isClient, isUserID, userId); + break; + case KEY_DUMPSYS_MISSION_LIST: + DumpSysMissionListInner(args, info, isClient, isUserID, userId); + break; + case KEY_DUMPSYS_ABILITY: + DumpSysAbilityInner(args, info, isClient, isUserID, userId); + break; + default: + info.push_back("error: invalid argument, please see 'ability dump -h'."); + break; } - info.push_back("error: invalid argument, please see 'ability dump -h'."); } int AbilityManagerService::AbilityTransitionDone(const sptr &token, int state, const PacMap &saveData) diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index ebd09d89d8..ad1bb836bf 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -41,414 +41,812 @@ constexpr int32_t CYCLE_LIMIT = 1000; constexpr int32_t MAX_KILL_PROCESS_PID_COUNT = 100; } // namespace AbilityManagerStub::AbilityManagerStub() -{ - FirstStepInit(); - SecondStepInit(); - ThirdStepInit(); - FourthStepInit(); - FifthStepInit(); -} +{} AbilityManagerStub::~AbilityManagerStub() +{} + +int AbilityManagerStub::OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { - requestFuncMap_.clear(); + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::TERMINATE_ABILITY) { + return TerminateAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MINIMIZE_ABILITY) { + return MinimizeAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD) { + return AttachAbilityThreadInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE) { + return AbilityTransitionDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONNECT_ABILITY_DONE) { + return ScheduleConnectAbilityDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DISCONNECT_ABILITY_DONE) { + return ScheduleDisconnectAbilityDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::COMMAND_ABILITY_DONE) { + return ScheduleCommandAbilityDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::COMMAND_ABILITY_WINDOW_DONE) { + return ScheduleCommandAbilityWindowDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ACQUIRE_DATA_ABILITY) { + return AcquireDataAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::RELEASE_DATA_ABILITY) { + return ReleaseDataAbilityInner(data, reply); + } + return ERR_CODE_NOT_EXIST; } -void AbilityManagerStub::FirstStepInit() +int AbilityManagerStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::TERMINATE_ABILITY)] = - &AbilityManagerStub::TerminateAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MINIMIZE_ABILITY)] = - &AbilityManagerStub::MinimizeAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD)] = - &AbilityManagerStub::AttachAbilityThreadInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE)] = - &AbilityManagerStub::AbilityTransitionDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONNECT_ABILITY_DONE)] = - &AbilityManagerStub::ScheduleConnectAbilityDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DISCONNECT_ABILITY_DONE)] = - &AbilityManagerStub::ScheduleDisconnectAbilityDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::COMMAND_ABILITY_DONE)] = - &AbilityManagerStub::ScheduleCommandAbilityDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::COMMAND_ABILITY_WINDOW_DONE)] = - &AbilityManagerStub::ScheduleCommandAbilityWindowDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ACQUIRE_DATA_ABILITY)] = - &AbilityManagerStub::AcquireDataAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::RELEASE_DATA_ABILITY)] = - &AbilityManagerStub::ReleaseDataAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::KILL_PROCESS)] = - &AbilityManagerStub::KillProcessInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNINSTALL_APP)] = - &AbilityManagerStub::UninstallAppInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UPGRADE_APP)] = - &AbilityManagerStub::UpgradeAppInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY)] = - &AbilityManagerStub::StartAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_ADD_CALLER)] = - &AbilityManagerStub::StartAbilityAddCallerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_WITH_SPECIFY_TOKENID)] = - &AbilityManagerStub::StartAbilityInnerSpecifyTokenId; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN)] = - &AbilityManagerStub::StartAbilityAsCallerByTokenInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_FOR_OPTIONS)] = - &AbilityManagerStub::StartAbilityAsCallerForOptionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_ADD_CALLER)] = - &AbilityManagerStub::StartAbilityByUIContentSessionAddCallerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS)] = - &AbilityManagerStub::StartAbilityByUIContentSessionForOptionsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT)] = - &AbilityManagerStub::StartAbilityByInsightIntentInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONNECT_ABILITY)] = - &AbilityManagerStub::ConnectAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DISCONNECT_ABILITY)] = - &AbilityManagerStub::DisconnectAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::STOP_SERVICE_ABILITY)] = - &AbilityManagerStub::StopServiceAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DUMP_STATE)] = - &AbilityManagerStub::DumpStateInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DUMPSYS_STATE)] = - &AbilityManagerStub::DumpSysStateInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_FOR_SETTINGS)] = - &AbilityManagerStub::StartAbilityForSettingsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONTINUE_MISSION)] = - &AbilityManagerStub::ContinueMissionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME)] = - &AbilityManagerStub::ContinueMissionOfBundleNameInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONTINUE_ABILITY)] = - &AbilityManagerStub::ContinueAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_CONTINUATION)] = - &AbilityManagerStub::StartContinuationInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::NOTIFY_COMPLETE_CONTINUATION)] = - &AbilityManagerStub::NotifyCompleteContinuationInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::NOTIFY_CONTINUATION_RESULT)] = - &AbilityManagerStub::NotifyContinuationResultInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SEND_RESULT_TO_ABILITY)] = - &AbilityManagerStub::SendResultToAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_REMOTE_MISSION_LISTENER)] = - &AbilityManagerStub::RegisterRemoteMissionListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_REMOTE_ON_LISTENER)] = - &AbilityManagerStub::RegisterRemoteOnListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_REMOTE_OFF_LISTENER)] = - &AbilityManagerStub::RegisterRemoteOffListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_REMOTE_MISSION_LISTENER)] = - &AbilityManagerStub::UnRegisterRemoteMissionListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_FOR_OPTIONS)] = - &AbilityManagerStub::StartAbilityForOptionsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_SYNC_MISSIONS)] = - &AbilityManagerStub::StartSyncRemoteMissionsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::STOP_SYNC_MISSIONS)] = - &AbilityManagerStub::StopSyncRemoteMissionsInner; + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::KILL_PROCESS) { + return KillProcessInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNINSTALL_APP) { + return UninstallAppInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UPGRADE_APP) { + return UpgradeAppInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY) { + return StartAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_ADD_CALLER) { + return StartAbilityAddCallerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_WITH_SPECIFY_TOKENID) { + return StartAbilityInnerSpecifyTokenId(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN) { + return StartAbilityAsCallerByTokenInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_FOR_OPTIONS) { + return StartAbilityAsCallerForOptionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_ADD_CALLER) { + return StartAbilityByUIContentSessionAddCallerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS) { + return StartAbilityByUIContentSessionForOptionsInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT) { + return StartAbilityByInsightIntentInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONNECT_ABILITY) { + return ConnectAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DISCONNECT_ABILITY) { + return DisconnectAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::STOP_SERVICE_ABILITY) { + return StopServiceAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DUMP_STATE) { + return DumpStateInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DUMPSYS_STATE) { + return DumpSysStateInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_FOR_SETTINGS) { + return StartAbilityForSettingsInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONTINUE_MISSION) { + return ContinueMissionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME) { + return ContinueMissionOfBundleNameInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONTINUE_ABILITY) { + return ContinueAbilityInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::START_CONTINUATION) { + return StartContinuationInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_COMPLETE_CONTINUATION) { + return NotifyCompleteContinuationInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_CONTINUATION_RESULT) { + return NotifyContinuationResultInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SEND_RESULT_TO_ABILITY) { + return SendResultToAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_REMOTE_MISSION_LISTENER) { + return RegisterRemoteMissionListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_REMOTE_ON_LISTENER) { + return RegisterRemoteOnListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_REMOTE_OFF_LISTENER) { + return RegisterRemoteOffListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_REMOTE_MISSION_LISTENER) { + return UnRegisterRemoteMissionListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_FOR_OPTIONS) { + return StartAbilityForOptionsInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_SYNC_MISSIONS) { + return StartSyncRemoteMissionsInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerFifth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::STOP_SYNC_MISSIONS) { + return StopSyncRemoteMissionsInner(data, reply); + } #ifdef ABILITY_COMMAND_FOR_TEST - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::FORCE_TIMEOUT)] = - &AbilityManagerStub::ForceTimeoutForTestInner; + if (interfaceCode == AbilityManagerInterfaceCode::FORCE_TIMEOUT) { + return ForceTimeoutForTestInner(data, reply); + } #endif - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::FREE_INSTALL_ABILITY_FROM_REMOTE)] = - &AbilityManagerStub::FreeInstallAbilityFromRemoteInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ADD_FREE_INSTALL_OBSERVER)] = - &AbilityManagerStub::AddFreeInstallObserverInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONNECT_ABILITY_WITH_TYPE)] = - &AbilityManagerStub::ConnectAbilityWithTypeInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ABILITY_RECOVERY)] = - &AbilityManagerStub::ScheduleRecoverAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ABILITY_RECOVERY_ENABLE)] = - &AbilityManagerStub::EnableRecoverAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CLEAR_RECOVERY_PAGE_STACK)] = - &AbilityManagerStub::ScheduleClearRecoveryPageStackInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MINIMIZE_UI_ABILITY_BY_SCB)] = - &AbilityManagerStub::MinimizeUIAbilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CLOSE_UI_ABILITY_BY_SCB)] = - &AbilityManagerStub::CloseUIAbilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_COLLABORATOR)] = - &AbilityManagerStub::RegisterIAbilityManagerCollaboratorInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_COLLABORATOR)] = - &AbilityManagerStub::UnregisterIAbilityManagerCollaboratorInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_APP_DEBUG_LISTENER)] = - &AbilityManagerStub::RegisterAppDebugListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_APP_DEBUG_LISTENER)] = - &AbilityManagerStub::UnregisterAppDebugListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ATTACH_APP_DEBUG)] = - &AbilityManagerStub::AttachAppDebugInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DETACH_APP_DEBUG)] = - &AbilityManagerStub::DetachAppDebugInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::IS_ABILITY_CONTROLLER_START)] = - &AbilityManagerStub::IsAbilityControllerStartInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::EXECUTE_INTENT)] = - &AbilityManagerStub::ExecuteIntentInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::EXECUTE_INSIGHT_INTENT_DONE)] = - &AbilityManagerStub::ExecuteInsightIntentDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::OPEN_FILE)] = - &AbilityManagerStub::OpenFileInner; + if (interfaceCode == AbilityManagerInterfaceCode::FREE_INSTALL_ABILITY_FROM_REMOTE) { + return FreeInstallAbilityFromRemoteInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ADD_FREE_INSTALL_OBSERVER) { + return AddFreeInstallObserverInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONNECT_ABILITY_WITH_TYPE) { + return ConnectAbilityWithTypeInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ABILITY_RECOVERY) { + return ScheduleRecoverAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ABILITY_RECOVERY_ENABLE) { + return EnableRecoverAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CLEAR_RECOVERY_PAGE_STACK) { + return ScheduleClearRecoveryPageStackInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MINIMIZE_UI_ABILITY_BY_SCB) { + return MinimizeUIAbilityBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CLOSE_UI_ABILITY_BY_SCB) { + return CloseUIAbilityBySCBInner(data, reply); + } + return ERR_CODE_NOT_EXIST; } -void AbilityManagerStub::SecondStepInit() +int AbilityManagerStub::OnRemoteRequestInnerSixth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER)] = - &AbilityManagerStub::GetWantSenderInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SEND_PENDING_WANT_SENDER)] = - &AbilityManagerStub::SendWantSenderInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CANCEL_PENDING_WANT_SENDER)] = - &AbilityManagerStub::CancelWantSenderInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_UID)] = - &AbilityManagerStub::GetPendingWantUidInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_USERID)] = - &AbilityManagerStub::GetPendingWantUserIdInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_BUNDLENAME)] = - &AbilityManagerStub::GetPendingWantBundleNameInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_CODE)] = - &AbilityManagerStub::GetPendingWantCodeInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE)] = - &AbilityManagerStub::GetPendingWantTypeInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_CANCEL_LISTENER)] = - &AbilityManagerStub::RegisterCancelListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_CANCEL_LISTENER)] = - &AbilityManagerStub::UnregisterCancelListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_REQUEST_WANT)] = - &AbilityManagerStub::GetPendingRequestWantInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER_INFO)] = - &AbilityManagerStub::GetWantSenderInfoInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_APP_MEMORY_SIZE)] = - &AbilityManagerStub::GetAppMemorySizeInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::IS_RAM_CONSTRAINED_DEVICE)] = - &AbilityManagerStub::IsRamConstrainedDeviceInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::LOCK_MISSION_FOR_CLEANUP)] = - &AbilityManagerStub::LockMissionForCleanupInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNLOCK_MISSION_FOR_CLEANUP)] = - &AbilityManagerStub::UnlockMissionForCleanupInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_SESSION_LOCKED_STATE)] = - &AbilityManagerStub::SetLockedStateInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_MISSION_LISTENER)] = - &AbilityManagerStub::RegisterMissionListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_MISSION_LISTENER)] = - &AbilityManagerStub::UnRegisterMissionListenerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_MISSION_INFOS)] = - &AbilityManagerStub::GetMissionInfosInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_MISSION_INFO_BY_ID)] = - &AbilityManagerStub::GetMissionInfoInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CLEAN_MISSION)] = - &AbilityManagerStub::CleanMissionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CLEAN_ALL_MISSIONS)] = - &AbilityManagerStub::CleanAllMissionsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT)] = - &AbilityManagerStub::MoveMissionToFrontInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT_BY_OPTIONS)] = - &AbilityManagerStub::MoveMissionToFrontByOptionsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_FOREGROUND)] = - &AbilityManagerStub::MoveMissionsToForegroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_BACKGROUND)] = - &AbilityManagerStub::MoveMissionsToBackgroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_CALL_ABILITY)] = - &AbilityManagerStub::StartAbilityByCallInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CALL_REQUEST_DONE)] = - &AbilityManagerStub::CallRequestDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::RELEASE_CALL_ABILITY)] = - &AbilityManagerStub::ReleaseCallInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_USER)] = - &AbilityManagerStub::StartUserInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::STOP_USER)] = - &AbilityManagerStub::StopUserInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::LOGOUT_USER)] = - &AbilityManagerStub::LogoutUserInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_ABILITY_RUNNING_INFO)] = - &AbilityManagerStub::GetAbilityRunningInfosInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_EXTENSION_RUNNING_INFO)] = - &AbilityManagerStub::GetExtensionRunningInfosInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_PROCESS_RUNNING_INFO)] = - &AbilityManagerStub::GetProcessRunningInfosInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_ABILITY_CONTROLLER)] = - &AbilityManagerStub::SetAbilityControllerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_MISSION_SNAPSHOT_INFO)] = - &AbilityManagerStub::GetMissionSnapshotInfoInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::IS_USER_A_STABILITY_TEST)] = - &AbilityManagerStub::IsRunningInStabilityTestInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::ACQUIRE_SHARE_DATA)] = - &AbilityManagerStub::AcquireShareDataInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SHARE_DATA_DONE)] = - &AbilityManagerStub::ShareDataDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_ABILITY_TOKEN)] = - &AbilityManagerStub::GetAbilityTokenByCalleeObjInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::FORCE_EXIT_APP)] = - &AbilityManagerStub::ForceExitAppInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::RECORD_APP_EXIT_REASON)] = - &AbilityManagerStub::RecordAppExitReasonInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::RECORD_PROCESS_EXIT_REASON)] = - &AbilityManagerStub::RecordProcessExitReasonInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER)] = - &AbilityManagerStub::RegisterSessionHandlerInner; + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_COLLABORATOR) { + return RegisterIAbilityManagerCollaboratorInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_COLLABORATOR) { + return UnregisterIAbilityManagerCollaboratorInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_APP_DEBUG_LISTENER) { + return RegisterAppDebugListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_APP_DEBUG_LISTENER) { + return UnregisterAppDebugListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::ATTACH_APP_DEBUG) { + return AttachAppDebugInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DETACH_APP_DEBUG) { + return DetachAppDebugInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::IS_ABILITY_CONTROLLER_START) { + return IsAbilityControllerStartInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::EXECUTE_INTENT) { + return ExecuteIntentInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::EXECUTE_INSIGHT_INTENT_DONE) { + return ExecuteInsightIntentDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::OPEN_FILE) { + return OpenFileInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER) { + return GetWantSenderInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SEND_PENDING_WANT_SENDER) { + return SendWantSenderInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CANCEL_PENDING_WANT_SENDER) { + return CancelWantSenderInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_UID) { + return GetPendingWantUidInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_USERID) { + return GetPendingWantUserIdInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_BUNDLENAME) { + return GetPendingWantBundleNameInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_CODE) { + return GetPendingWantCodeInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE) { + return GetPendingWantTypeInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_CANCEL_LISTENER) { + return RegisterCancelListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_CANCEL_LISTENER) { + return UnregisterCancelListenerInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerEighth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_REQUEST_WANT) { + return GetPendingRequestWantInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER_INFO) { + return GetWantSenderInfoInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_APP_MEMORY_SIZE) { + return GetAppMemorySizeInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::IS_RAM_CONSTRAINED_DEVICE) { + return IsRamConstrainedDeviceInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::LOCK_MISSION_FOR_CLEANUP) { + return LockMissionForCleanupInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNLOCK_MISSION_FOR_CLEANUP) { + return UnlockMissionForCleanupInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_SESSION_LOCKED_STATE) { + return SetLockedStateInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_MISSION_LISTENER) { + return RegisterMissionListenerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_MISSION_LISTENER) { + return UnRegisterMissionListenerInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerNinth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::GET_MISSION_INFOS) { + return GetMissionInfosInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_MISSION_INFO_BY_ID) { + return GetMissionInfoInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CLEAN_MISSION) { + return CleanMissionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CLEAN_ALL_MISSIONS) { + return CleanAllMissionsInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT) { + return MoveMissionToFrontInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT_BY_OPTIONS) { + return MoveMissionToFrontByOptionsInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_FOREGROUND) { + return MoveMissionsToForegroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_BACKGROUND) { + return MoveMissionsToBackgroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_CALL_ABILITY) { + return StartAbilityByCallInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CALL_REQUEST_DONE) { + return CallRequestDoneInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerTenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::RELEASE_CALL_ABILITY) { + return ReleaseCallInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_USER) { + return StartUserInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::STOP_USER) { + return StopUserInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::LOGOUT_USER) { + return LogoutUserInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_ABILITY_RUNNING_INFO) { + return GetAbilityRunningInfosInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_EXTENSION_RUNNING_INFO) { + return GetExtensionRunningInfosInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_PROCESS_RUNNING_INFO) { + return GetProcessRunningInfosInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_ABILITY_CONTROLLER) { + return SetAbilityControllerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_MISSION_SNAPSHOT_INFO) { + return GetMissionSnapshotInfoInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::IS_USER_A_STABILITY_TEST) { + return IsRunningInStabilityTestInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerEleventh(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::ACQUIRE_SHARE_DATA) { + return AcquireShareDataInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SHARE_DATA_DONE) { + return ShareDataDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_ABILITY_TOKEN) { + return GetAbilityTokenByCalleeObjInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::FORCE_EXIT_APP) { + return ForceExitAppInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::RECORD_APP_EXIT_REASON) { + return RecordAppExitReasonInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::RECORD_PROCESS_EXIT_REASON) { + return RecordProcessExitReasonInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER) { + return RegisterSessionHandlerInner(data, reply); + } #ifdef ABILITY_COMMAND_FOR_TEST - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::BLOCK_ABILITY)] = - &AbilityManagerStub::BlockAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE)] = - &AbilityManagerStub::BlockAmsServiceInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::BLOCK_APP_SERVICE)] = - &AbilityManagerStub::BlockAppServiceInner; + if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_ABILITY) { + return BlockAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_AMS_SERVICE) { + return BlockAmsServiceInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::BLOCK_APP_SERVICE) { + return BlockAppServiceInner(data, reply); + } #endif + return ERR_CODE_NOT_EXIST; } -void AbilityManagerStub::ThirdStepInit() +int AbilityManagerStub::OnRemoteRequestInnerTwelveth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_USER_TEST)] = - &AbilityManagerStub::StartUserTestInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::FINISH_USER_TEST)] = - &AbilityManagerStub::FinishUserTestInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_TOP_ABILITY_TOKEN)] = - &AbilityManagerStub::GetTopAbilityTokenInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CHECK_UI_EXTENSION_IS_FOCUSED)] = - &AbilityManagerStub::CheckUIExtensionIsFocusedInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_FOREGROUND)] = - &AbilityManagerStub::DelegatorDoAbilityForegroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_BACKGROUND)] = - &AbilityManagerStub::DelegatorDoAbilityBackgroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DO_ABILITY_FOREGROUND)] = - &AbilityManagerStub::DoAbilityForegroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DO_ABILITY_BACKGROUND)] = - &AbilityManagerStub::DoAbilityBackgroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_MISSION_ID_BY_ABILITY_TOKEN)] = - &AbilityManagerStub::GetMissionIdByTokenInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_TOP_ABILITY)] = - &AbilityManagerStub::GetTopAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_ELEMENT_NAME_BY_TOKEN)] = - &AbilityManagerStub::GetElementNameByTokenInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::DUMP_ABILITY_INFO_DONE)] = - &AbilityManagerStub::DumpAbilityInfoDoneInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_EXTENSION_ABILITY)] = - &AbilityManagerStub::StartExtensionAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::STOP_EXTENSION_ABILITY)] = - &AbilityManagerStub::StopExtensionAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UPDATE_MISSION_SNAPSHOT_FROM_WMS)] = - &AbilityManagerStub::UpdateMissionSnapShotFromWMSInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_CONNECTION_OBSERVER)] = - &AbilityManagerStub::RegisterConnectionObserverInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_CONNECTION_OBSERVER)] = - &AbilityManagerStub::UnregisterConnectionObserverInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_DLP_CONNECTION_INFOS)] = - &AbilityManagerStub::GetDlpConnectionInfosInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MOVE_ABILITY_TO_BACKGROUND)] = - &AbilityManagerStub::MoveAbilityToBackgroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MOVE_UI_ABILITY_TO_BACKGROUND)] = - &AbilityManagerStub::MoveUIAbilityToBackgroundInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_MISSION_CONTINUE_STATE)] = - &AbilityManagerStub::SetMissionContinueStateInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_BY_SCB)] = - &AbilityManagerStub::PrepareTerminateAbilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REQUESET_MODAL_UIEXTENSION)] = - &AbilityManagerStub::RequestModalUIExtensionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_UI_EXTENSION_ROOT_HOST_INFO)] = - &AbilityManagerStub::GetUIExtensionRootHostInfoInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::PRELOAD_UIEXTENSION_ABILITY)] = - &AbilityManagerStub::PreloadUIExtensionAbilityInner; + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::START_USER_TEST) { + return StartUserTestInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::FINISH_USER_TEST) { + return FinishUserTestInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_TOP_ABILITY_TOKEN) { + return GetTopAbilityTokenInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CHECK_UI_EXTENSION_IS_FOCUSED) { + return CheckUIExtensionIsFocusedInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_FOREGROUND) { + return DelegatorDoAbilityForegroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_BACKGROUND) { + return DelegatorDoAbilityBackgroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DO_ABILITY_FOREGROUND) { + return DoAbilityForegroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DO_ABILITY_BACKGROUND) { + return DoAbilityBackgroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_MISSION_ID_BY_ABILITY_TOKEN) { + return GetMissionIdByTokenInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_TOP_ABILITY) { + return GetTopAbilityInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerThirteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::GET_ELEMENT_NAME_BY_TOKEN) { + return GetElementNameByTokenInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::DUMP_ABILITY_INFO_DONE) { + return DumpAbilityInfoDoneInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_EXTENSION_ABILITY) { + return StartExtensionAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::STOP_EXTENSION_ABILITY) { + return StopExtensionAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UPDATE_MISSION_SNAPSHOT_FROM_WMS) { + return UpdateMissionSnapShotFromWMSInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_CONNECTION_OBSERVER) { + return RegisterConnectionObserverInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_CONNECTION_OBSERVER) { + return UnregisterConnectionObserverInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_DLP_CONNECTION_INFOS) { + return GetDlpConnectionInfosInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MOVE_ABILITY_TO_BACKGROUND) { + return MoveAbilityToBackgroundInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MOVE_UI_ABILITY_TO_BACKGROUND) { + return MoveUIAbilityToBackgroundInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerFourteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::SET_MISSION_CONTINUE_STATE) { + return SetMissionContinueStateInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_BY_SCB) { + return PrepareTerminateAbilityBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REQUESET_MODAL_UIEXTENSION) { + return RequestModalUIExtensionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_UI_EXTENSION_ROOT_HOST_INFO) { + return GetUIExtensionRootHostInfoInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::PRELOAD_UIEXTENSION_ABILITY) { + return PreloadUIExtensionAbilityInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerFifteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); #ifdef SUPPORT_GRAPHICS - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_MISSION_LABEL)] = - &AbilityManagerStub::SetMissionLabelInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_MISSION_ICON)] = - &AbilityManagerStub::SetMissionIconInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_WMS_HANDLER)] = - &AbilityManagerStub::RegisterWindowManagerServiceHandlerInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::COMPLETEFIRSTFRAMEDRAWING)] = - &AbilityManagerStub::CompleteFirstFrameDrawingInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY)] = - &AbilityManagerStub::StartUIExtensionAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::MINIMIZE_UI_EXTENSION_ABILITY)] = - &AbilityManagerStub::MinimizeUIExtensionAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::TERMINATE_UI_EXTENSION_ABILITY)] = - &AbilityManagerStub::TerminateUIExtensionAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CONNECT_UI_EXTENSION_ABILITY)] = - &AbilityManagerStub::ConnectUIExtensionAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY)] = - &AbilityManagerStub::PrepareTerminateAbilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_DIALOG_SESSION_INFO)] = - &AbilityManagerStub::GetDialogSessionInfoInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SEND_DIALOG_RESULT)] = - &AbilityManagerStub::SendDialogResultInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER)] = - &AbilityManagerStub::RegisterAbilityFirstFrameStateObserverInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER)] - = &AbilityManagerStub::UnregisterAbilityFirstFrameStateObserverInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::COMPLETE_FIRST_FRAME_DRAWING_BY_SCB)] = - &AbilityManagerStub::CompleteFirstFrameDrawingBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_NON_MODAL)] = - &AbilityManagerStub::StartUIExtensionAbilityNonModalInner; + if (interfaceCode == AbilityManagerInterfaceCode::SET_MISSION_LABEL) { + return SetMissionLabelInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_MISSION_ICON) { + return SetMissionIconInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_WMS_HANDLER) { + return RegisterWindowManagerServiceHandlerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::COMPLETEFIRSTFRAMEDRAWING) { + return CompleteFirstFrameDrawingInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY) { + return StartUIExtensionAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::MINIMIZE_UI_EXTENSION_ABILITY) { + return MinimizeUIExtensionAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::TERMINATE_UI_EXTENSION_ABILITY) { + return TerminateUIExtensionAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CONNECT_UI_EXTENSION_ABILITY) { + return ConnectUIExtensionAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY) { + return PrepareTerminateAbilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_DIALOG_SESSION_INFO) { + return GetDialogSessionInfoInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SEND_DIALOG_RESULT) { + return SendDialogResultInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER) { + return RegisterAbilityFirstFrameStateObserverInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER) { + return UnregisterAbilityFirstFrameStateObserverInner(data, reply); + } #endif - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REQUEST_DIALOG_SERVICE)] = - &AbilityManagerStub::HandleRequestDialogService; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REPORT_DRAWN_COMPLETED)] = - &AbilityManagerStub::HandleReportDrawnCompleted; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::QUERY_MISSION_VAILD)] = - &AbilityManagerStub::IsValidMissionIdsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::VERIFY_PERMISSION)] = - &AbilityManagerStub::VerifyPermissionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_UI_ABILITY_BY_SCB)] = - &AbilityManagerStub::StartUIAbilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_ROOT_SCENE_SESSION)] = - &AbilityManagerStub::SetRootSceneSessionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CALL_ABILITY_BY_SCB)] = - &AbilityManagerStub::CallUIAbilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_SPECIFIED_ABILITY_BY_SCB)] = - &AbilityManagerStub::StartSpecifiedAbilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::NOTIFY_SAVE_AS_RESULT)] = - &AbilityManagerStub::NotifySaveAsResultInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_SESSIONMANAGERSERVICE)] = - &AbilityManagerStub::SetSessionManagerServiceInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UPDATE_SESSION_INFO)] = - &AbilityManagerStub::UpdateSessionInfoBySCBInner; + return ERR_CODE_NOT_EXIST; } -void AbilityManagerStub::FourthStepInit() +int AbilityManagerStub::OnRemoteRequestInnerSixteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_STATUS_BAR_DELEGATE)] = - &AbilityManagerStub::RegisterStatusBarDelegateInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::KILL_PROCESS_WITH_PREPARE_TERMINATE)] = - &AbilityManagerStub::KillProcessWithPrepareTerminateInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REGISTER_AUTO_STARTUP_SYSTEM_CALLBACK)] = - &AbilityManagerStub::RegisterAutoStartupSystemCallbackInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::UNREGISTER_AUTO_STARTUP_SYSTEM_CALLBACK)] = - &AbilityManagerStub::UnregisterAutoStartupSystemCallbackInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP)] = - &AbilityManagerStub::SetApplicationAutoStartupInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP)] = - &AbilityManagerStub::CancelApplicationAutoStartupInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::QUERY_ALL_AUTO_STARTUP_APPLICATION)] = - &AbilityManagerStub::QueryAllAutoStartupApplicationsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_CONNECTION_DATA)] = - &AbilityManagerStub::GetConnectionDataInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP_BY_EDM)] = - &AbilityManagerStub::SetApplicationAutoStartupByEDMInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP_BY_EDM)] = - &AbilityManagerStub::CancelApplicationAutoStartupByEDMInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER)] = - &AbilityManagerStub::StartAbilityForResultAsCallerInner; - requestFuncMap_[static_cast( - AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER_FOR_OPTIONS)] = - &AbilityManagerStub::StartAbilityForResultAsCallerForOptionsInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_FOREGROUND_UI_ABILITIES)] = - &AbilityManagerStub::GetForegroundUIAbilitiesInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::RESTART_APP)] = - &AbilityManagerStub::RestartAppInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::OPEN_ATOMIC_SERVICE)] = - &AbilityManagerStub::OpenAtomicServiceInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::IS_EMBEDDED_OPEN_ALLOWED)] = - &AbilityManagerStub::IsEmbeddedOpenAllowedInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::REQUEST_ASSERT_FAULT_DIALOG)] = - &AbilityManagerStub::RequestAssertFaultDialogInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::NOTIFY_DEBUG_ASSERT_RESULT)] = - &AbilityManagerStub::NotifyDebugAssertResultInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CHANGE_ABILITY_VISIBILITY)] = - &AbilityManagerStub::ChangeAbilityVisibilityInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::CHANGE_UI_ABILITY_VISIBILITY_BY_SCB)] = - &AbilityManagerStub::ChangeUIAbilityVisibilityBySCBInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::START_SHORTCUT)] = - &AbilityManagerStub::StartShortcutInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::SET_RESIDENT_PROCESS_ENABLE)] = - &AbilityManagerStub::SetResidentProcessEnableInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::GET_ABILITY_STATE_BY_PERSISTENT_ID)] = - &AbilityManagerStub::GetAbilityStateByPersistentIdInner; + AbilityManagerInterfaceCode interfaceCode = static_cast(code); +#ifdef SUPPORT_GRAPHICS + if (interfaceCode == AbilityManagerInterfaceCode::COMPLETE_FIRST_FRAME_DRAWING_BY_SCB) { + return CompleteFirstFrameDrawingBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_NON_MODAL) { + return StartUIExtensionAbilityNonModalInner(data, reply); + } +#endif + if (interfaceCode == AbilityManagerInterfaceCode::REQUEST_DIALOG_SERVICE) { + return HandleRequestDialogService(data, reply); + }; + if (interfaceCode == AbilityManagerInterfaceCode::REPORT_DRAWN_COMPLETED) { + return HandleReportDrawnCompleted(data, reply); + }; + if (interfaceCode == AbilityManagerInterfaceCode::QUERY_MISSION_VAILD) { + return IsValidMissionIdsInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::VERIFY_PERMISSION) { + return VerifyPermissionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_ABILITY_BY_SCB) { + return StartUIAbilityBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_ROOT_SCENE_SESSION) { + return SetRootSceneSessionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CALL_ABILITY_BY_SCB) { + return CallUIAbilityBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_SPECIFIED_ABILITY_BY_SCB) { + return StartSpecifiedAbilityBySCBInner(data, reply); + } + return ERR_CODE_NOT_EXIST; } -void AbilityManagerStub::FifthStepInit() +int AbilityManagerStub::OnRemoteRequestInnerSeventeenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::TRANSFER_ABILITY_RESULT)] = - &AbilityManagerStub::TransferAbilityResultForExtensionInner; - requestFuncMap_[static_cast(AbilityManagerInterfaceCode::NOTIFY_FROZEN_PROCESS_BY_RSS)] = - &AbilityManagerStub::NotifyFrozenProcessByRSSInner; + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_SAVE_AS_RESULT) { + return NotifySaveAsResultInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_SESSIONMANAGERSERVICE) { + return SetSessionManagerServiceInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UPDATE_SESSION_INFO) { + return UpdateSessionInfoBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_STATUS_BAR_DELEGATE) { + return RegisterStatusBarDelegateInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::KILL_PROCESS_WITH_PREPARE_TERMINATE) { + return KillProcessWithPrepareTerminateInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REGISTER_AUTO_STARTUP_SYSTEM_CALLBACK) { + return RegisterAutoStartupSystemCallbackInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::UNREGISTER_AUTO_STARTUP_SYSTEM_CALLBACK) { + return UnregisterAutoStartupSystemCallbackInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP) { + return SetApplicationAutoStartupInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP) { + return CancelApplicationAutoStartupInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::QUERY_ALL_AUTO_STARTUP_APPLICATION) { + return QueryAllAutoStartupApplicationsInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInnerEighteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::GET_CONNECTION_DATA) { + return GetConnectionDataInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP_BY_EDM) { + return SetApplicationAutoStartupByEDMInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP_BY_EDM) { + return CancelApplicationAutoStartupByEDMInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER) { + return StartAbilityForResultAsCallerInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER_FOR_OPTIONS) { + return StartAbilityForResultAsCallerForOptionsInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_FOREGROUND_UI_ABILITIES) { + return GetForegroundUIAbilitiesInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::RESTART_APP) { + return RestartAppInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::OPEN_ATOMIC_SERVICE) { + return OpenAtomicServiceInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::IS_EMBEDDED_OPEN_ALLOWED) { + return IsEmbeddedOpenAllowedInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::REQUEST_ASSERT_FAULT_DIALOG) { + return RequestAssertFaultDialogInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + + +int AbilityManagerStub::OnRemoteRequestInnerNineteenth(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + AbilityManagerInterfaceCode interfaceCode = static_cast(code); + if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_DEBUG_ASSERT_RESULT) { + return NotifyDebugAssertResultInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CHANGE_ABILITY_VISIBILITY) { + return ChangeAbilityVisibilityInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::CHANGE_UI_ABILITY_VISIBILITY_BY_SCB) { + return ChangeUIAbilityVisibilityBySCBInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_SHORTCUT) { + return StartShortcutInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::SET_RESIDENT_PROCESS_ENABLE) { + return SetResidentProcessEnableInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::GET_ABILITY_STATE_BY_PERSISTENT_ID) { + return GetAbilityStateByPersistentIdInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::TRANSFER_ABILITY_RESULT) { + return TransferAbilityResultForExtensionInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_FROZEN_PROCESS_BY_RSS) { + return NotifyFrozenProcessByRSSInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::OnRemoteRequestInner(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + int retCode = ERR_OK; + retCode = HandleOnRemoteRequestInnerFirst(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = HandleOnRemoteRequestInnerSecond(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + TAG_LOGW(AAFwkTag::ABILITYMGR, "default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int AbilityManagerStub::HandleOnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + int retCode = ERR_OK; + retCode = OnRemoteRequestInnerFirst(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerSecond(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerThird(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerFourth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerFifth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerSixth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerSeventh(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerEighth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerNinth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerTenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + return ERR_CODE_NOT_EXIST; +} + +int AbilityManagerStub::HandleOnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + int retCode = ERR_OK; + retCode = OnRemoteRequestInnerEleventh(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerTwelveth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerThirteenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerFourteenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerFifteenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerSixteenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerSeventeenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerEighteenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerNineteenth(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + return ERR_CODE_NOT_EXIST; } int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -461,15 +859,7 @@ int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Mess return ERR_INVALID_STATE; } - auto itFunc = requestFuncMap_.find(code); - if (itFunc != requestFuncMap_.end()) { - auto requestFunc = itFunc->second; - if (requestFunc != nullptr) { - return (this->*requestFunc)(data, reply); - } - } - TAG_LOGW(AAFwkTag::ABILITYMGR, "default case, need check."); - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return OnRemoteRequestInner(code, data, reply, option); } int AbilityManagerStub::GetTopAbilityInner(MessageParcel &data, MessageParcel &reply) diff --git a/services/abilitymgr/src/ability_scheduler_stub.cpp b/services/abilitymgr/src/ability_scheduler_stub.cpp index 4dd6600a28..17d45bbdfa 100644 --- a/services/abilitymgr/src/ability_scheduler_stub.cpp +++ b/services/abilitymgr/src/ability_scheduler_stub.cpp @@ -15,6 +15,7 @@ #include "ability_scheduler_stub.h" +#include "ability_manager_errors.h" #include "abs_shared_result_set.h" #include "data_ability_observer_interface.h" #include "data_ability_operation.h" @@ -33,51 +34,10 @@ namespace OHOS { namespace AAFwk { constexpr int CYCLE_LIMIT = 2000; AbilitySchedulerStub::AbilitySchedulerStub() -{ - requestFuncMap_[SCHEDULE_ABILITY_TRANSACTION] = &AbilitySchedulerStub::AbilityTransactionInner; - requestFuncMap_[SEND_RESULT] = &AbilitySchedulerStub::SendResultInner; - requestFuncMap_[SCHEDULE_ABILITY_CONNECT] = &AbilitySchedulerStub::ConnectAbilityInner; - requestFuncMap_[SCHEDULE_ABILITY_DISCONNECT] = &AbilitySchedulerStub::DisconnectAbilityInner; - requestFuncMap_[SCHEDULE_ABILITY_COMMAND] = &AbilitySchedulerStub::CommandAbilityInner; - requestFuncMap_[SCHEDULE_ABILITY_PREPARE_TERMINATE] = &AbilitySchedulerStub::PrepareTerminateAbilityInner; - requestFuncMap_[SCHEDULE_ABILITY_COMMAND_WINDOW] = &AbilitySchedulerStub::CommandAbilityWindowInner; - requestFuncMap_[SCHEDULE_SAVE_ABILITY_STATE] = &AbilitySchedulerStub::SaveAbilityStateInner; - requestFuncMap_[SCHEDULE_RESTORE_ABILITY_STATE] = &AbilitySchedulerStub::RestoreAbilityStateInner; - requestFuncMap_[SCHEDULE_GETFILETYPES] = &AbilitySchedulerStub::GetFileTypesInner; - requestFuncMap_[SCHEDULE_OPENFILE] = &AbilitySchedulerStub::OpenFileInner; - requestFuncMap_[SCHEDULE_OPENRAWFILE] = &AbilitySchedulerStub::OpenRawFileInner; - requestFuncMap_[SCHEDULE_INSERT] = &AbilitySchedulerStub::InsertInner; - requestFuncMap_[SCHEDULE_UPDATE] = &AbilitySchedulerStub::UpdatetInner; - requestFuncMap_[SCHEDULE_DELETE] = &AbilitySchedulerStub::DeleteInner; - requestFuncMap_[SCHEDULE_QUERY] = &AbilitySchedulerStub::QueryInner; - requestFuncMap_[SCHEDULE_CALL] = &AbilitySchedulerStub::CallInner; - requestFuncMap_[SCHEDULE_GETTYPE] = &AbilitySchedulerStub::GetTypeInner; - requestFuncMap_[SCHEDULE_RELOAD] = &AbilitySchedulerStub::ReloadInner; - requestFuncMap_[SCHEDULE_BATCHINSERT] = &AbilitySchedulerStub::BatchInsertInner; - requestFuncMap_[SCHEDULE_REGISTEROBSERVER] = &AbilitySchedulerStub::RegisterObserverInner; - requestFuncMap_[SCHEDULE_UNREGISTEROBSERVER] = &AbilitySchedulerStub::UnregisterObserverInner; - requestFuncMap_[SCHEDULE_NOTIFYCHANGE] = &AbilitySchedulerStub::NotifyChangeInner; - requestFuncMap_[SCHEDULE_NORMALIZEURI] = &AbilitySchedulerStub::NormalizeUriInner; - requestFuncMap_[SCHEDULE_DENORMALIZEURI] = &AbilitySchedulerStub::DenormalizeUriInner; - requestFuncMap_[SCHEDULE_EXECUTEBATCH] = &AbilitySchedulerStub::ExecuteBatchInner; - requestFuncMap_[NOTIFY_CONTINUATION_RESULT] = &AbilitySchedulerStub::NotifyContinuationResultInner; - requestFuncMap_[REQUEST_CALL_REMOTE] = &AbilitySchedulerStub::CallRequestInner; - requestFuncMap_[CONTINUE_ABILITY] = &AbilitySchedulerStub::ContinueAbilityInner; - requestFuncMap_[DUMP_ABILITY_RUNNER_INNER] = &AbilitySchedulerStub::DumpAbilityInfoInner; - requestFuncMap_[SCHEDULE_SHARE_DATA] = &AbilitySchedulerStub::ShareDataInner; - requestFuncMap_[SCHEDULE_ONEXECUTE_INTENT] = &AbilitySchedulerStub::OnExecuteIntentInner; - requestFuncMap_[CREATE_MODAL_UI_EXTENSION] = &AbilitySchedulerStub::CreateModalUIExtensionInner; - requestFuncMap_[UPDATE_SESSION_TOKEN] = &AbilitySchedulerStub::UpdateSessionTokenInner; - -#ifdef ABILITY_COMMAND_FOR_TEST - requestFuncMap_[BLOCK_ABILITY_INNER] = &AbilitySchedulerStub::BlockAbilityInner; -#endif -} +{} AbilitySchedulerStub::~AbilitySchedulerStub() -{ - requestFuncMap_.clear(); -} +{} int AbilitySchedulerStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -88,18 +48,125 @@ int AbilitySchedulerStub::OnRemoteRequest( TAG_LOGE(AAFwkTag::ABILITYMGR, "local descriptor is not equal to remote"); return ERR_INVALID_STATE; } + return OnRemoteRequestInner(code, data, reply, option); +} - auto itFunc = requestFuncMap_.find(code); - if (itFunc != requestFuncMap_.end()) { - auto requestFunc = itFunc->second; - if (requestFunc != nullptr) { - return (this->*requestFunc)(data, reply); - } +int AbilitySchedulerStub::OnRemoteRequestInner( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + int retCode = ERR_OK; + retCode = OnRemoteRequestInnerFirst(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerSecond(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; + } + retCode = OnRemoteRequestInnerThird(code, data, reply, option); + if (retCode != ERR_CODE_NOT_EXIST) { + return retCode; } TAG_LOGW(AAFwkTag::ABILITYMGR, "AbilitySchedulerStub::OnRemoteRequest, default case, need check."); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } +int AbilitySchedulerStub::OnRemoteRequestInnerFirst( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case SCHEDULE_ABILITY_TRANSACTION: + return AbilityTransactionInner(data, reply); + case SEND_RESULT: + return SendResultInner(data, reply); + case SCHEDULE_ABILITY_CONNECT: + return ConnectAbilityInner(data, reply); + case SCHEDULE_ABILITY_DISCONNECT: + return DisconnectAbilityInner(data, reply); + case SCHEDULE_ABILITY_COMMAND: + return CommandAbilityInner(data, reply); + case SCHEDULE_ABILITY_PREPARE_TERMINATE: + return PrepareTerminateAbilityInner(data, reply); + case SCHEDULE_ABILITY_COMMAND_WINDOW: + return CommandAbilityWindowInner(data, reply); + case SCHEDULE_SAVE_ABILITY_STATE: + return SaveAbilityStateInner(data, reply); + case SCHEDULE_RESTORE_ABILITY_STATE: + return RestoreAbilityStateInner(data, reply); + case SCHEDULE_GETFILETYPES: + return GetFileTypesInner(data, reply); + case SCHEDULE_OPENFILE: + return OpenFileInner(data, reply); + case SCHEDULE_OPENRAWFILE: + return OpenRawFileInner(data, reply); + case SCHEDULE_INSERT: + return InsertInner(data, reply); + case SCHEDULE_UPDATE: + return UpdatetInner(data, reply); + case SCHEDULE_DELETE: + return DeleteInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilitySchedulerStub::OnRemoteRequestInnerSecond( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case SCHEDULE_QUERY: + return QueryInner(data, reply); + case SCHEDULE_CALL: + return CallInner(data, reply); + case SCHEDULE_GETTYPE: + return GetTypeInner(data, reply); + case SCHEDULE_RELOAD: + return ReloadInner(data, reply); + case SCHEDULE_BATCHINSERT: + return BatchInsertInner(data, reply); + case SCHEDULE_REGISTEROBSERVER: + return RegisterObserverInner(data, reply); + case SCHEDULE_UNREGISTEROBSERVER: + return UnregisterObserverInner(data, reply); + case SCHEDULE_NOTIFYCHANGE: + return NotifyChangeInner(data, reply); + case SCHEDULE_NORMALIZEURI: + return NormalizeUriInner(data, reply); + case SCHEDULE_DENORMALIZEURI: + return DenormalizeUriInner(data, reply); + case SCHEDULE_EXECUTEBATCH: + return ExecuteBatchInner(data, reply); + case NOTIFY_CONTINUATION_RESULT: + return NotifyContinuationResultInner(data, reply); + case REQUEST_CALL_REMOTE: + return CallRequestInner(data, reply); + case CONTINUE_ABILITY: + return ContinueAbilityInner(data, reply); + case DUMP_ABILITY_RUNNER_INNER: + return DumpAbilityInfoInner(data, reply); + } + return ERR_CODE_NOT_EXIST; +} + +int AbilitySchedulerStub::OnRemoteRequestInnerThird( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + switch (code) { + case SCHEDULE_SHARE_DATA: + return ShareDataInner(data, reply); + case SCHEDULE_ONEXECUTE_INTENT: + return OnExecuteIntentInner(data, reply); + case CREATE_MODAL_UI_EXTENSION: + return CreateModalUIExtensionInner(data, reply); + case UPDATE_SESSION_TOKEN: + return UpdateSessionTokenInner(data, reply); +#ifdef ABILITY_COMMAND_FOR_TEST + case BLOCK_ABILITY_INNER: + return BlockAbilityInner(data, reply); +#endif + } + return ERR_CODE_NOT_EXIST; +} + int AbilitySchedulerStub::AbilityTransactionInner(MessageParcel &data, MessageParcel &reply) { std::shared_ptr want(data.ReadParcelable()); diff --git a/services/abilitymgr/src/resident_process_manager.cpp b/services/abilitymgr/src/resident_process_manager.cpp index 3f6b3211c5..e1a039038b 100644 --- a/services/abilitymgr/src/resident_process_manager.cpp +++ b/services/abilitymgr/src/resident_process_manager.cpp @@ -180,8 +180,9 @@ int32_t ResidentProcessManager::SetResidentProcessEnabled( IN_PROCESS_CALL_WITHOUT_RET(appMgrClient->SetKeepAliveEnableState(bundleName, updateEnable)); } - ffrt::submit(std::bind(&ResidentProcessManager::UpdateResidentProcessesStatus, shared_from_this(), bundleName, - localEnable, updateEnable)); + ffrt::submit([self = shared_from_this(), bundleName, localEnable, updateEnable]() { + self->UpdateResidentProcessesStatus(bundleName, localEnable, updateEnable); + }); return ERR_OK; } diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 1aed994043..b4bdd7eae5 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -698,15 +698,6 @@ private: bool GetDumpIpcKeyByOption(const std::string &option, DumpIpcKey &key); - using DumpFuncType = int (AppMgrService::*)(const std::vector& args, std::string& result); - bool GetDumpFunc(const std::string &optionKey, DumpFuncType &func); - - using DumpIpcAllFuncType = int (AppMgrService::*)(std::string& result); - DumpIpcAllFuncType GetDumpIpcAllFuncByKey(uint32_t key); - - using DumpIpcFuncType = int (AppMgrService::*)(const int32_t pid, std::string& result); - DumpIpcFuncType GetDumpIpcFuncByKey(uint32_t key); - DISALLOW_COPY_AND_MOVE(AppMgrService); }; } // namespace AppExecFwk diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 2efca95aa5..853c366255 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -81,9 +81,10 @@ void AmsMgrScheduler::LoadAbility(const sptr &token, const sptrbundleName.c_str(), abilityInfo->name.c_str()); - std::function loadAbilityFunc = - std::bind(&AppMgrServiceInner::LoadAbility, amsMgrServiceInner_, token, preToken, abilityInfo, - appInfo, want, abilityRecordId); + std::function loadAbilityFunc = [amsMgrServiceInner = amsMgrServiceInner_, token, preToken, + abilityInfo, appInfo, want, abilityRecordId]() { + amsMgrServiceInner->LoadAbility(token, preToken, abilityInfo, appInfo, want, abilityRecordId); + }; // cache other application load ability task before scene board attach if (!amsMgrServiceInner_->GetSceneBoardAttachFlag() && abilityInfo->bundleName != SCENE_BOARD_BUNDLE_NAME) { @@ -116,8 +117,9 @@ void AmsMgrScheduler::UpdateAbilityState(const sptr &token, const TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return; } - std::function updateAbilityStateFunc = - std::bind(&AppMgrServiceInner::UpdateAbilityState, amsMgrServiceInner_, token, state); + std::function updateAbilityStateFunc = [amsMgrServiceInner = amsMgrServiceInner_, token, state] () { + amsMgrServiceInner->UpdateAbilityState(token, state); + }; amsHandler_->SubmitTask(updateAbilityStateFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_UPDATE_ABILITY_STATE, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -134,8 +136,9 @@ void AmsMgrScheduler::UpdateExtensionState(const sptr &token, con TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return; } - std::function updateExtensionStateFunc = - std::bind(&AppMgrServiceInner::UpdateExtensionState, amsMgrServiceInner_, token, state); + std::function updateExtensionStateFunc = [amsMgrServiceInner = amsMgrServiceInner_, token, state]() { + amsMgrServiceInner->UpdateExtensionState(token, state); + }; amsHandler_->SubmitTask(updateExtensionStateFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_UPDATE_EXTENSION_STATE, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -152,8 +155,9 @@ void AmsMgrScheduler::TerminateAbility(const sptr &token, bool cl TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return; } - std::function terminateAbilityFunc = - std::bind(&AppMgrServiceInner::TerminateAbility, amsMgrServiceInner_, token, clearMissionFlag); + std::function terminateAbilityFunc = [amsMgrServiceInner = amsMgrServiceInner_, token, clearMissionFlag]() { + amsMgrServiceInner->TerminateAbility(token, clearMissionFlag); + }; amsHandler_->SubmitTask(terminateAbilityFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_TERMINATE_ABILITY, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -165,8 +169,9 @@ void AmsMgrScheduler::RegisterAppStateCallback(const sptr &ca if (!IsReady()) { return; } - std::function registerAppStateCallbackFunc = - std::bind(&AppMgrServiceInner::RegisterAppStateCallback, amsMgrServiceInner_, callback); + std::function registerAppStateCallbackFunc = [amsMgrServiceInner = amsMgrServiceInner_, callback]() { + amsMgrServiceInner->RegisterAppStateCallback(callback); + }; amsHandler_->SubmitTask(registerAppStateCallbackFunc, TASK_REGISTER_APP_STATE_CALLBACK); } @@ -181,8 +186,11 @@ void AmsMgrScheduler::AbilityBehaviorAnalysis(const sptr &token, TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return; } - std::function abilityBehaviorAnalysisFunc = std::bind(&AppMgrServiceInner::AbilityBehaviorAnalysis, - amsMgrServiceInner_, token, preToken, visibility, perceptibility, connectionState); + std::function abilityBehaviorAnalysisFunc = [amsMgrServiceInner = amsMgrServiceInner_, token, preToken, + visibility, perceptibility, connectionState]() { + amsMgrServiceInner->AbilityBehaviorAnalysis(token, preToken, + visibility, perceptibility, connectionState); + }; amsHandler_->SubmitTask(abilityBehaviorAnalysisFunc, TASK_ABILITY_BEHAVIOR_ANALYSIS); } @@ -197,8 +205,9 @@ void AmsMgrScheduler::KillProcessByAbilityToken(const sptr &token return; } - std::function killProcessByAbilityTokenFunc = - std::bind(&AppMgrServiceInner::KillProcessByAbilityToken, amsMgrServiceInner_, token); + std::function killProcessByAbilityTokenFunc = [amsMgrServiceInner = amsMgrServiceInner_, token]() { + amsMgrServiceInner->KillProcessByAbilityToken(token); + }; amsHandler_->SubmitTask(killProcessByAbilityTokenFunc, TASK_KILL_PROCESS_BY_ABILITY_TOKEN); } @@ -222,8 +231,9 @@ void AmsMgrScheduler::KillProcessesByUserId(int32_t userId) return; } - std::function killProcessesByUserIdFunc = - std::bind(&AppMgrServiceInner::KillProcessesByUserId, amsMgrServiceInner_, userId); + std::function killProcessesByUserIdFunc = [amsMgrServiceInner = amsMgrServiceInner_, userId]() { + amsMgrServiceInner->KillProcessesByUserId(userId); + }; amsHandler_->SubmitTask(killProcessesByUserIdFunc, TASK_KILL_PROCESSES_BY_USERID); } @@ -240,8 +250,9 @@ void AmsMgrScheduler::KillProcessesByPids(std::vector &pids) return; } - std::function killProcessesByPidsFunc = - std::bind(&AppMgrServiceInner::KillProcessesByPids, amsMgrServiceInner_, pids); + std::function killProcessesByPidsFunc = [amsMgrServiceInner = amsMgrServiceInner_, &pids]() { + amsMgrServiceInner->KillProcessesByPids(pids); + }; amsHandler_->SubmitTask(killProcessesByPidsFunc, TASK_KILL_PROCESSES_BY_PIDS); } @@ -258,8 +269,9 @@ void AmsMgrScheduler::AttachPidToParent(const sptr &token, const return; } - std::function attachPidToParentFunc = - std::bind(&AppMgrServiceInner::AttachPidToParent, amsMgrServiceInner_, token, callerToken); + std::function attachPidToParentFunc = [amsMgrServiceInner = amsMgrServiceInner_, token, callerToken]() { + amsMgrServiceInner->AttachPidToParent(token, callerToken); + }; amsHandler_->SubmitTask(attachPidToParentFunc, TASK_ATTACH_PID_TO_PARENT); } @@ -285,7 +297,9 @@ void AmsMgrScheduler::AbilityAttachTimeOut(const sptr &token) TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return; } - auto task = [=]() { amsMgrServiceInner_->HandleAbilityAttachTimeOut(token); }; + auto task = [amsMgrServiceInner = amsMgrServiceInner_, token]() { + amsMgrServiceInner->HandleAbilityAttachTimeOut(token); + }; amsHandler_->SubmitTask(task); } @@ -566,8 +580,9 @@ void AmsMgrScheduler::ClearProcessByToken(sptr token) return; } - std::function clearProcessByTokenFunc = - std::bind(&AppMgrServiceInner::ClearProcessByToken, amsMgrServiceInner_, token); + std::function clearProcessByTokenFunc = [amsMgrServiceInner = amsMgrServiceInner_, token]() { + amsMgrServiceInner->ClearProcessByToken(token); + }; amsHandler_->SubmitTask(clearProcessByTokenFunc, TASK_CLEAR_PROCESS_BY_ABILITY_TOKEN); } diff --git a/services/appmgr/src/app_death_recipient.cpp b/services/appmgr/src/app_death_recipient.cpp index 6ec85d22be..30d389961e 100644 --- a/services/appmgr/src/app_death_recipient.cpp +++ b/services/appmgr/src/app_death_recipient.cpp @@ -41,8 +41,11 @@ void AppDeathRecipient::OnRemoteDied(const wptr &remote) return; } - auto onRemoteDiedFunc = std::bind(&AppMgrServiceInner::OnRemoteDied, serviceInner, remote, isRenderProcess_, - isChildProcess_); + auto onRemoteDiedFunc = [serviceInner, remote, + isRenderProcess = isRenderProcess_, + isChildProcess = isChildProcess_]() { + serviceInner->OnRemoteDied(remote, isRenderProcess, isChildProcess); + }; handler->SubmitTask(onRemoteDiedFunc, TASK_ON_REMOTE_DIED); } diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index bff60162d5..1153dcc654 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -154,8 +154,9 @@ ErrCode AppMgrService::Init() appMgrServiceInner_->SetTaskHandler(taskHandler_); appMgrServiceInner_->SetEventHandler(eventHandler_); DelayedSingleton::GetInstance()->SetAppMgr(appMgrServiceInner_); - std::function initAppMgrServiceInnerTask = - std::bind(&AppMgrServiceInner::Init, appMgrServiceInner_); + std::function initAppMgrServiceInnerTask = [appMgrServiceInner = appMgrServiceInner_]() { + appMgrServiceInner->Init(); + }; taskHandler_->SubmitTask(initAppMgrServiceInnerTask, TASK_INIT_APPMGRSERVICEINNER); ErrCode openErr = appMgrServiceInner_->OpenAppSpawnConnection(); @@ -184,8 +185,9 @@ void AppMgrService::AttachApplication(const sptr &app) } pid_t pid = IPCSkeleton::GetCallingPid(); - std::function attachApplicationFunc = - std::bind(&AppMgrServiceInner::AttachApplication, appMgrServiceInner_, pid, iface_cast(app)); + std::function attachApplicationFunc = [appMgrServiceInner = appMgrServiceInner_, pid, app]() { + appMgrServiceInner->AttachApplication(pid, iface_cast(app)); + }; taskHandler_->SubmitTask(attachApplicationFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_ATTACH_APPLICATION, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -211,8 +213,9 @@ void AppMgrService::ApplicationForegrounded(const int32_t recordId) if (!JudgeAppSelfCalled(recordId)) { return; } - std::function applicationForegroundedFunc = - std::bind(&AppMgrServiceInner::ApplicationForegrounded, appMgrServiceInner_, recordId); + std::function applicationForegroundedFunc = [appMgrServiceInner = appMgrServiceInner_, recordId]() { + appMgrServiceInner->ApplicationForegrounded(recordId); + }; taskHandler_->SubmitTask(applicationForegroundedFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_APPLICATION_FOREGROUNDED, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -228,8 +231,9 @@ void AppMgrService::ApplicationBackgrounded(const int32_t recordId) return; } taskHandler_->CancelTask("appbackground_" + std::to_string(recordId)); - std::function applicationBackgroundedFunc = - std::bind(&AppMgrServiceInner::ApplicationBackgrounded, appMgrServiceInner_, recordId); + std::function applicationBackgroundedFunc = [appMgrServiceInner = appMgrServiceInner_, recordId]() { + appMgrServiceInner->ApplicationBackgrounded(recordId); + }; taskHandler_->SubmitTask(applicationBackgroundedFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_APPLICATION_BACKGROUNDED, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -244,8 +248,9 @@ void AppMgrService::ApplicationTerminated(const int32_t recordId) if (!JudgeAppSelfCalled(recordId)) { return; } - std::function applicationTerminatedFunc = - std::bind(&AppMgrServiceInner::ApplicationTerminated, appMgrServiceInner_, recordId); + std::function applicationTerminatedFunc = [appMgrServiceInner = appMgrServiceInner_, recordId]() { + appMgrServiceInner->ApplicationTerminated(recordId); + }; taskHandler_->SubmitTask(applicationTerminatedFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_APPLICATION_TERMINATED, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -265,8 +270,9 @@ void AppMgrService::AbilityCleaned(const sptr &token) return; } - std::function abilityCleanedFunc = - std::bind(&AppMgrServiceInner::AbilityTerminated, appMgrServiceInner_, token); + std::function abilityCleanedFunc = [appMgrServiceInner = appMgrServiceInner_, token]() { + appMgrServiceInner->AbilityTerminated(token); + }; taskHandler_->SubmitTask(abilityCleanedFunc, AAFwk::TaskAttribute{ .taskName_ = TASK_ABILITY_CLEANED, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -295,8 +301,9 @@ void AppMgrService::StartupResidentProcess(const std::vector startupResidentProcess = - std::bind(&AppMgrServiceInner::LoadResidentProcess, appMgrServiceInner_, bundleInfos); + std::function startupResidentProcess = [appMgrServiceInner = appMgrServiceInner_, bundleInfos]() { + appMgrServiceInner->LoadResidentProcess(bundleInfos); + }; taskHandler_->SubmitTask(startupResidentProcess, AAFwk::TaskAttribute{ .taskName_ = TASK_STARTUP_RESIDENT_PROCESS, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -482,8 +489,9 @@ void AppMgrService::AddAbilityStageDone(const int32_t recordId) if (!JudgeAppSelfCalled(recordId)) { return; } - std::function addAbilityStageDone = - std::bind(&AppMgrServiceInner::AddAbilityStageDone, appMgrServiceInner_, recordId); + std::function addAbilityStageDone = [appMgrServiceInner = appMgrServiceInner_, recordId]() { + appMgrServiceInner->AddAbilityStageDone(recordId); + }; taskHandler_->SubmitTask(addAbilityStageDone, AAFwk::TaskAttribute{ .taskName_ = TASK_ADD_ABILITY_STAGE_DONE, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -553,8 +561,10 @@ int AppMgrService::StartUserTestProcess(const AAFwk::Want &want, const sptr startUserTestProcessFunc = - std::bind(&AppMgrServiceInner::StartUserTestProcess, appMgrServiceInner_, want, observer, bundleInfo, userId); + std::function startUserTestProcessFunc = [appMgrServiceInner = appMgrServiceInner_, + want, observer, bundleInfo, userId]() { + appMgrServiceInner->StartUserTestProcess(want, observer, bundleInfo, userId); + }; taskHandler_->SubmitTask(startUserTestProcessFunc, TASK_START_USER_TEST_PROCESS); return ERR_OK; } @@ -589,8 +599,10 @@ int AppMgrService::FinishUserTest(const std::string &msg, const int64_t &resultC return ERR_INVALID_OPERATION; } pid_t callingPid = IPCSkeleton::GetCallingPid(); - std::function finishUserTestProcessFunc = - std::bind(&AppMgrServiceInner::FinishUserTest, appMgrServiceInner_, msg, resultCode, bundleName, callingPid); + std::function finishUserTestProcessFunc = [appMgrServiceInner = appMgrServiceInner_, msg, + resultCode, bundleName, callingPid]() { + appMgrServiceInner->FinishUserTest(msg, resultCode, bundleName, callingPid); + }; taskHandler_->SubmitTask(finishUserTestProcessFunc, TASK_FINISH_USER_TEST); return ERR_OK; } @@ -613,23 +625,6 @@ int AppMgrService::Dump(int fd, const std::vector& args) return errCode; } -bool AppMgrService::GetDumpFunc(const std::string &optionKey, DumpFuncType &func) -{ - if (optionKey == OPTION_KEY_HELP) { - func = &AppMgrService::ShowHelp; - return true; - } - if (optionKey == OPTION_KEY_DUMP_IPC) { - func = &AppMgrService::DumpIpc; - return true; - } - if (optionKey == OPTION_KEY_DUMP_FFRT) { - func = &AppMgrService::DumpFfrt; - return true; - } - return false; -} - int AppMgrService::Dump(const std::vector& args, std::string& result) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); @@ -639,19 +634,18 @@ int AppMgrService::Dump(const std::vector& args, std::string& re } std::string optionKey = Str16ToStr8(args[0]); - DumpFuncType dumpFunc; - if (!GetDumpFunc(optionKey, dumpFunc)) { - result.append("error: unkown option.\n"); - TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}s does not exist", optionKey.c_str()); - return DumpErrorCode::ERR_UNKNOWN_OPTION_ERROR; + if (optionKey == OPTION_KEY_HELP) { + return ShowHelp(args, result); } - if (dumpFunc == nullptr) { - result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) - .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); - TAG_LOGE(AAFwkTag::APPMGR, "dump ffrt function does not exist"); - return DumpErrorCode::ERR_INTERNAL_ERROR; + if (optionKey == OPTION_KEY_DUMP_IPC) { + return DumpIpc(args, result); } - return (this->*dumpFunc)(args, result); + if (optionKey == OPTION_KEY_DUMP_FFRT) { + return DumpFfrt(args, result); + } + result.append("error: unkown option.\n"); + TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}s does not exist", optionKey.c_str()); + return DumpErrorCode::ERR_UNKNOWN_OPTION_ERROR; } int AppMgrService::ShowHelp(const std::vector& args, std::string& result) @@ -665,47 +659,23 @@ int AppMgrService::ShowHelp(const std::vector& args, std::string return ERR_OK; } -AppMgrService::DumpIpcAllFuncType AppMgrService::GetDumpIpcAllFuncByKey(uint32_t key) -{ - if (key == KEY_DUMP_IPC_START) { - return &AppMgrService::DumpIpcAllStart; - } - if (key == KEY_DUMP_IPC_STOP) { - return &AppMgrService::DumpIpcAllStop; - } - if (key == KEY_DUMP_IPC_STAT) { - return &AppMgrService::DumpIpcAllStat; - } - TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); - return nullptr; -} - int AppMgrService::DumpIpcAllInner(const AppMgrService::DumpIpcKey key, std::string& result) { TAG_LOGI(AAFwkTag::APPMGR, "Called."); - auto dumpFunc = GetDumpIpcAllFuncByKey(key); - if (dumpFunc == nullptr) { - result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) - .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); - TAG_LOGE(AAFwkTag::APPMGR, "dump ipc all function does not exist"); - return DumpErrorCode::ERR_INTERNAL_ERROR; + switch (key) { + case KEY_DUMP_IPC_START: + return DumpIpcAllStart(result); + case KEY_DUMP_IPC_STOP: + return DumpIpcAllStop(result); + case KEY_DUMP_IPC_STAT: + return DumpIpcAllStat(result); + default: { + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "dump ipc all function does not exist"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } } - return (this->*dumpFunc)(result); -} - -AppMgrService::DumpIpcFuncType AppMgrService::GetDumpIpcFuncByKey(uint32_t key) -{ - if (key == KEY_DUMP_IPC_START) { - return &AppMgrService::DumpIpcStart; - } - if (key == KEY_DUMP_IPC_STOP) { - return &AppMgrService::DumpIpcStop; - } - if (key == KEY_DUMP_IPC_STAT) { - return &AppMgrService::DumpIpcStat; - } - TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); - return nullptr; } int AppMgrService::DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, @@ -728,14 +698,21 @@ int AppMgrService::DumpIpcWithPidInner(const AppMgrService::DumpIpcKey key, return DumpErrorCode::ERR_INVALID_PID_ERROR; } - auto dumpFunc = GetDumpIpcFuncByKey(key); - if (dumpFunc == nullptr) { - result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) - .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); - TAG_LOGE(AAFwkTag::APPMGR, "dump ipc function does not exist"); - return DumpErrorCode::ERR_INTERNAL_ERROR; + switch (key) { + case KEY_DUMP_IPC_START: + return DumpIpcStart(pid, result); + case KEY_DUMP_IPC_STOP: + return DumpIpcStop(pid, result); + case KEY_DUMP_IPC_STAT: + return DumpIpcStat(pid, result); + default: { + TAG_LOGE(AAFwkTag::APPMGR, "option key %{public}d does not exist", key); + result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL)) + .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL)); + TAG_LOGE(AAFwkTag::APPMGR, "dump ipc function does not exist"); + return DumpErrorCode::ERR_INTERNAL_ERROR; + } } - return (this->*dumpFunc)(pid, result); } int AppMgrService::DumpFfrtInner(const std::string& pidsRaw, std::string& result) @@ -895,7 +872,9 @@ void AppMgrService::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk:: if (!JudgeAppSelfCalled(recordId)) { return; } - auto task = [=]() { appMgrServiceInner_->ScheduleAcceptWantDone(recordId, want, flag); }; + auto task = [appMgrServiceInner = appMgrServiceInner_, recordId, want, flag]() { + appMgrServiceInner->ScheduleAcceptWantDone(recordId, want, flag); + }; taskHandler_->SubmitTask(task); } @@ -909,7 +888,9 @@ void AppMgrService::ScheduleNewProcessRequestDone(const int32_t recordId, const if (!JudgeAppSelfCalled(recordId)) { return; } - auto task = [=]() { appMgrServiceInner_->ScheduleNewProcessRequestDone(recordId, want, flag); }; + auto task = [appMgrServiceInner = appMgrServiceInner_, recordId, want, flag]() { + appMgrServiceInner->ScheduleNewProcessRequestDone(recordId, want, flag); + }; taskHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE); } @@ -959,8 +940,9 @@ void AppMgrService::AttachRenderProcess(const sptr &scheduler) } auto pid = IPCSkeleton::GetCallingPid(); - auto fun = std::bind(&AppMgrServiceInner::AttachRenderProcess, - appMgrServiceInner_, pid, iface_cast(scheduler)); + auto fun = [appMgrServiceInner = appMgrServiceInner_, pid, scheduler]() { + appMgrServiceInner->AttachRenderProcess(pid, iface_cast(scheduler)); + }; taskHandler_->SubmitTask(fun, AAFwk::TaskAttribute{ .taskName_ = TASK_ATTACH_RENDER_PROCESS, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -1370,8 +1352,9 @@ void AppMgrService::AttachChildProcess(const sptr &childScheduler return; } pid_t pid = IPCSkeleton::GetCallingPid(); - std::function task = std::bind(&AppMgrServiceInner::AttachChildProcess, - appMgrServiceInner_, pid, iface_cast(childScheduler)); + std::function task = [appMgrServiceInner = appMgrServiceInner_, pid, childScheduler]() { + appMgrServiceInner->AttachChildProcess(pid, iface_cast(childScheduler)); + }; taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{ .taskName_ = TASK_ATTACH_CHILD_PROCESS, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE @@ -1389,8 +1372,9 @@ void AppMgrService::ExitChildProcessSafely() return; } pid_t pid = IPCSkeleton::GetCallingPid(); - std::function task = std::bind(&AppMgrServiceInner::ExitChildProcessSafelyByChildPid, - appMgrServiceInner_, pid); + std::function task = [appMgrServiceInner = appMgrServiceInner_, pid]() { + appMgrServiceInner->ExitChildProcessSafelyByChildPid(pid); + }; taskHandler_->SubmitTask(task, AAFwk::TaskAttribute{ .taskName_ = TASK_EXIT_CHILD_PROCESS_SAFELY, .taskQos_ = AAFwk::TaskQoS::USER_INTERACTIVE diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 65fcc7c239..a1055197ef 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5291,19 +5291,19 @@ int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData if (!AppExecFwk::AppfreezeManager::GetInstance()->IsHandleAppfreeze(bundleName) || record->IsDebugging()) { return ERR_OK; } - auto timeoutNotifyApp = std::bind(&AppMgrServiceInner::TimeoutNotifyApp, this, - pid, uid, bundleName, transformedFaultData); + auto timeoutNotifyApp = [this, pid, uid, bundleName, transformedFaultData]() { + this->TimeoutNotifyApp(pid, uid, bundleName, transformedFaultData); + }; taskHandler_->SubmitTask(timeoutNotifyApp, transformedFaultData.timeoutMarkers, timeout); } record->NotifyAppFault(transformedFaultData); TAG_LOGW(AAFwkTag::APPMGR, "FaultDataBySA is: name: %{public}s, faultType: %{public}s, uid: %{public}d," "pid: %{public}d, bundleName: %{public}s", faultData.errorObject.name.c_str(), FaultTypeToString(faultData.faultType).c_str(), uid, pid, bundleName.c_str()); - } else { - TAG_LOGD(AAFwkTag::APPMGR, "this is not called by SA."); - return AAFwk::CHECK_PERMISSION_FAILED; + return ERR_OK; } - return ERR_OK; + TAG_LOGD(AAFwkTag::APPMGR, "this is not called by SA."); + return AAFwk::CHECK_PERMISSION_FAILED; } FaultData AppMgrServiceInner::ConvertDataTypes(const AppFaultDataBySA &faultData) diff --git a/test/fuzztest/abilitymanagerservicesecond_fuzzer/abilitymanagerservicesecond_fuzzer.cpp b/test/fuzztest/abilitymanagerservicesecond_fuzzer/abilitymanagerservicesecond_fuzzer.cpp index 813ae23e27..a5d978d454 100755 --- a/test/fuzztest/abilitymanagerservicesecond_fuzzer/abilitymanagerservicesecond_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicesecond_fuzzer/abilitymanagerservicesecond_fuzzer.cpp @@ -115,8 +115,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) sptr dataAbilityScheduler; abilityms->ReleaseDataAbility(dataAbilityScheduler, token); abilityms->AttachAbilityThread(dataAbilityScheduler, token); - abilityms->DumpFuncInit(); - abilityms->DumpSysFuncInit(); std::vector info; abilityms->DumpSysInner(stringParam, info, boolParam, boolParam, intParam); abilityms->DumpSysMissionListInner(stringParam, info, boolParam, boolParam, intParam); diff --git a/test/moduletest/ability_manager_service_dump_test/ability_manager_service_dump_test.cpp b/test/moduletest/ability_manager_service_dump_test/ability_manager_service_dump_test.cpp index a036b86cdf..0a40f909e4 100644 --- a/test/moduletest/ability_manager_service_dump_test/ability_manager_service_dump_test.cpp +++ b/test/moduletest/ability_manager_service_dump_test/ability_manager_service_dump_test.cpp @@ -69,19 +69,6 @@ HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_GetProcessRunningI EXPECT_EQ(result, AppMgrResultCode::RESULT_OK); } -/** - * @tc.name: AbilityManagerService_DumpSysFuncInit_0100 - * @tc.desc: DumpSysFuncInit - * @tc.type: FUNC - * @tc.require: SR000GH1GO - */ -HWTEST_F(AbilityManagerServiceDumpTest, AbilityManagerService_DumpSysFuncInit_0100, TestSize.Level1) -{ - auto abilityMs_ = std::make_shared(); - abilityMs_->DumpSysFuncInit(); - EXPECT_GT(abilityMs_->dumpsysFuncMap_.size(), SIZE_ZERO); -} - /** * @tc.name: AbilityManagerService_DumpSysInner_0100 * @tc.desc: DumpSysInner diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 7ad1a42aff..53bdff6eb4 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -157,26 +157,26 @@ AbilityManagerShellCommand::AbilityManagerShellCommand(int argc, char* argv[]) : ErrCode AbilityManagerShellCommand::CreateCommandMap() { commandMap_ = { - {"help", std::bind(&AbilityManagerShellCommand::RunAsHelpCommand, this)}, - {"screen", std::bind(&AbilityManagerShellCommand::RunAsScreenCommand, this)}, - {"start", std::bind(&AbilityManagerShellCommand::RunAsStartAbility, this)}, - {"stop-service", std::bind(&AbilityManagerShellCommand::RunAsStopService, this)}, - {"dump", std::bind(&AbilityManagerShellCommand::RunAsDumpsysCommand, this)}, - {"force-stop", std::bind(&AbilityManagerShellCommand::RunAsForceStop, this)}, - {"test", std::bind(&AbilityManagerShellCommand::RunAsTestCommand, this)}, - {"process", std::bind(&AbilityManagerShellCommand::RunAsProcessCommand, this)}, - {"attach", std::bind(&AbilityManagerShellCommand::RunAsAttachDebugCommand, this)}, - {"detach", std::bind(&AbilityManagerShellCommand::RunAsDetachDebugCommand, this)}, - {"appdebug", std::bind(&AbilityManagerShellCommand::RunAsAppDebugDebugCommand, this)}, + {"help", [this]() { return this->RunAsHelpCommand(); }}, + {"screen", [this]() { return this->RunAsScreenCommand(); }}, + {"start", [this]() { return this->RunAsStartAbility(); }}, + {"stop-service", [this]() { return this->RunAsStopService(); }}, + {"dump", [this]() { return this->RunAsDumpsysCommand(); }}, + {"force-stop", [this]() { return this->RunAsForceStop(); }}, + {"test", [this]() { return this->RunAsTestCommand(); }}, + {"process", [this]() { return this->RunAsProcessCommand(); }}, + {"attach", [this]() { return this->RunAsAttachDebugCommand(); }}, + {"detach", [this]() { return this->RunAsDetachDebugCommand(); }}, + {"appdebug", [this]() { return this->RunAsAppDebugDebugCommand(); }}, #ifdef ABILITY_COMMAND_FOR_TEST - {"force-timeout", std::bind(&AbilityManagerShellCommand::RunForceTimeoutForTest, this)}, - {"block-ability", std::bind(&AbilityManagerShellCommand::RunAsBlockAbilityCommand, this)}, - {"block-ams-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAmsServiceCommand, this)}, - {"block-app-service", std::bind(&AbilityManagerShellCommand::RunAsBlockAppServiceCommand, this)}, + {"force-timeout", [this]() { return this->RunForceTimeoutForTest(); }}, + {"block-ability", [this]() { return this->RunAsBlockAbilityCommand(); }}, + {"block-ams-service", [this]() { return this->RunAsBlockAmsServiceCommand(); }}, + {"block-app-service", [this]() { return this->RunAsBlockAppServiceCommand(); }}, #endif #ifdef ABILITY_FAULT_AND_EXIT_TEST - {"forceexitapp", std::bind(&AbilityManagerShellCommand::RunAsForceExitAppCommand, this)}, - {"notifyappfault", std::bind(&AbilityManagerShellCommand::RunAsNotifyAppFaultCommand, this)}, + {"forceexitapp", [this]() { return this->RunAsForceExitAppCommand(); }}, + {"notifyappfault", [this]() { return this->RunAsNotifyAppFaultCommand(); }}, #endif }; diff --git a/tools/aa/src/ability_tool_command.cpp b/tools/aa/src/ability_tool_command.cpp index 521d24ffd5..3b8191cc63 100644 --- a/tools/aa/src/ability_tool_command.cpp +++ b/tools/aa/src/ability_tool_command.cpp @@ -116,11 +116,11 @@ AbilityToolCommand::AbilityToolCommand(int argc, char* argv[]) : ShellCommand(ar ErrCode AbilityToolCommand::CreateCommandMap() { commandMap_ = { - {"help", std::bind(&AbilityToolCommand::RunAsHelpCommand, this)}, - {"start", std::bind(&AbilityToolCommand::RunAsStartAbility, this)}, - {"stop-service", std::bind(&AbilityToolCommand::RunAsStopService, this)}, - {"force-stop", std::bind(&AbilityToolCommand::RunAsForceStop, this)}, - {"test", std::bind(&AbilityToolCommand::RunAsTestCommand, this)}, + {"help", [this]() { return this->RunAsHelpCommand(); }}, + {"start", [this]() { return this->RunAsStartAbility(); }}, + {"stop-service", [this]() { return this->RunAsStopService(); }}, + {"force-stop", [this]() { return this->RunAsForceStop(); }}, + {"test", [this]() { return this->RunAsTestCommand(); }}, }; return OHOS::ERR_OK; From 97c80f9e399783794e14e8b13c6f93f2f3211bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Fri, 21 Jun 2024 03:35:25 +0000 Subject: [PATCH 020/148] update services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../abilitymgr/src/interceptor/ecological_rule_interceptor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp index cdbf98a8c6..594f9f2349 100644 --- a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp @@ -29,7 +29,8 @@ namespace OHOS { namespace AAFwk { namespace { -constexpr const char* ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE = "persist.sys.abilityms.support.ecologicalrulemgrservice"; +constexpr const char* ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE = + "persist.sys.abilityms.support.ecologicalrulemgrservice"; constexpr const char* BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; } ErrCode EcologicalRuleInterceptor::DoProcess(AbilityInterceptorParam param) From 69324c6ad1a2ec61070b3fe7fa58f33b3ea00723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Fri, 21 Jun 2024 03:36:37 +0000 Subject: [PATCH 021/148] update services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../abilitymgr/src/interceptor/disposed_rule_interceptor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index e8ac9c158c..b586a07bec 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -165,7 +165,7 @@ ErrCode DisposedRuleInterceptor::StartNonBlockRule(const Want &want, AppExecFwk: TAG_LOGE(AAFwkTag::ABILITYMGR, "Can not start disposed app with same bundleName"); return ERR_OK; } - SetInterceptInfo(param.want, disposedRule); + SetInterceptInfo(want, disposedRule); std::string bundleName = want.GetBundle(); { std::lock_guard guard(observerLock_); From e3c9c65cf51bac0b1ea9738b31bf9c685219747b Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Mon, 17 Jun 2024 10:53:56 +0800 Subject: [PATCH 022/148] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/IA5VY3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 独立编译整改 Signed-off-by: jiangzhijun8 --- test/unittest/frameworks_kits_ability_native_test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index 5b45bcd532..bdfd558403 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -2432,6 +2432,7 @@ ohos_unittest("form_extension_module_loader_test") { external_deps = [ "ability_base:configuration", "ability_base:session_info", + "ability_runtime:extensionkit_native", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", From 3adda25fdaba16b9c16167597d8061e2a0c35333 Mon Sep 17 00:00:00 2001 From: jsjzju Date: Fri, 21 Jun 2024 16:11:16 +0800 Subject: [PATCH 023/148] =?UTF-8?q?UIExtensionNode=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=90=8E=E5=86=8D=E8=AE=BE=E7=BD=AEIsModalCovered=E6=A0=87?= =?UTF-8?q?=E5=BF=97=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: Ia02a705c4712e0a6730f77b2210957aa25464004 --- .../inner_api/auto_fill_manager/include/auto_fill_manager.h | 1 + interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h b/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h index e6eab20570..67cf518d5d 100644 --- a/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h +++ b/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h @@ -51,6 +51,7 @@ struct AutoFillRequest { AutoFillCommand autoFillCommand = AutoFillCommand::NONE; AbilityBase::ViewData viewData; AutoFillCustomConfig config; + std::function doAfterAsyncModalBinding; }; /** diff --git a/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp b/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp index 3f46888869..070e5f48f9 100644 --- a/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp +++ b/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp @@ -308,6 +308,7 @@ int32_t AutoFillManager::CreateAutoFillExtension(Ace::UIContent *uiContent, want.SetParam(WANT_PARAMS_AUTO_FILL_POPUP_WINDOW_KEY, false); Ace::ModalUIExtensionConfig config; config.isAsyncModalBinding = true; + config.doAfterAsyncModalBinding = std::move(request.doAfterAsyncModalBinding); sessionId = uiContent->CreateModalUIExtension(want, callback, config); } return sessionId; From 03599c06d1ecafe8e5c5d198ae83897c99d8d408 Mon Sep 17 00:00:00 2001 From: zhuhan Date: Fri, 21 Jun 2024 16:17:56 +0800 Subject: [PATCH 024/148] fix mem Signed-off-by: zhuhan Change-Id: I0795e024bc0f1b397d364850b871dff4f340bad2 --- .../ability_runtime/context/js_application_context_utils.cpp | 1 + .../native/appkit/ability_runtime/context/js_context_utils.cpp | 2 ++ 2 files changed, 3 insertions(+) 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 c05554c8e1..7625adeb80 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 @@ -1422,6 +1422,7 @@ napi_value JsApplicationContextUtils::OnGetApplicationContext(napi_env env, Napi [](napi_env, void *data, void *) { TAG_LOGD(AAFwkTag::APPKIT, "Finalizer for weak_ptr application context is called"); delete static_cast *>(data); + data = nullptr; }, nullptr, nullptr); } diff --git a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp index 521bfaebfe..20acd7c2ed 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp @@ -621,6 +621,7 @@ napi_value JsBaseContext::OnGetApplicationContext(napi_env env, NapiCallbackInfo [](napi_env, void *data, void *) { TAG_LOGD(AAFwkTag::APPKIT, "Finalizer for weak_ptr application context is called"); delete static_cast *>(data); + data = nullptr; }, nullptr, nullptr); napi_ref ref = nullptr; @@ -706,6 +707,7 @@ napi_value AttachApplicationContext(napi_env env, void* value, void* hint) [](napi_env, void *data, void *) { TAG_LOGD(AAFwkTag::APPKIT, "Finalizer for weak_ptr application context is called"); delete static_cast *>(data); + data = nullptr; }, nullptr, nullptr); return contextObj; From 2da346e511f59c1a84f8e7d7fc4da2b4233e21fd Mon Sep 17 00:00:00 2001 From: xlw Date: Wed, 19 Jun 2024 11:15:06 +0800 Subject: [PATCH 025/148] =?UTF-8?q?=E6=9E=81=E7=AB=AF=E5=86=85=E5=AD=98?= =?UTF-8?q?=E5=B8=B8=E9=A9=BB=E8=BF=9B=E7=A8=8B=E9=85=8D=E7=BD=AEccm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlw Change-Id: I1895c1aa768990f397abb5d3ae6462a9f6e855da --- .../include/ability_connect_manager.h | 1 - .../src/ability_connect_manager.cpp | 16 +-- services/appmgr/src/app_mgr_service_inner.cpp | 4 +- services/common/BUILD.gn | 7 +- services/common/include/app_utils.h | 6 +- services/common/include/json_utils.h | 45 ++++++++ services/common/src/app_utils.cpp | 108 +++++++++++++----- services/common/src/json_utils.cpp | 96 ++++++++++++++++ 8 files changed, 234 insertions(+), 49 deletions(-) create mode 100644 services/common/include/json_utils.h create mode 100644 services/common/src/json_utils.cpp diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index df3ce56277..9e17c68c55 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -560,7 +560,6 @@ private: std::shared_ptr GetExtensionByIdFromServiceMap(int32_t abilityRecordId); int TerminateAbilityInner(const sptr &token); bool IsLauncher(std::shared_ptr serviceExtension) const; - bool IsSampleManagement(std::shared_ptr serviceExtension) const; void KillProcessesByUserId() const; void SetLastExitReason(const AbilityRequest &abilityRequest, std::shared_ptr &targetService); inline bool IsUIExtensionAbility(const std::shared_ptr &abilityRecord); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 8e6f1ce971..d1cf5b094d 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -75,8 +75,6 @@ const std::unordered_set FROZEN_WHITE_LIST { }; constexpr char BUNDLE_NAME_DIALOG[] = "com.ohos.amsdialog"; constexpr char ABILITY_NAME_ASSERT_FAULT_DIALOG[] = "AssertFaultDialog"; -constexpr char BUNDLE_NAME_SAMPLE_MANAGEMENT[] = "com.huawei.hmsapp.samplemanagement"; -constexpr char ABILITY_NAME_SAMPLE_MANAGEMENT[] = "MspesService"; bool IsSpecialAbility(const AppExecFwk::AbilityInfo &abilityInfo) { @@ -2026,6 +2024,7 @@ void AbilityConnectManager::HandleAbilityDiedTask( } isRemove = true; } + auto abilityInfo = abilityRecord->GetAbilityInfo(); if (IsAbilityNeedKeepAlive(abilityRecord)) { TAG_LOGI(AAFwkTag::ABILITYMGR, "restart ability: %{public}s", abilityRecord->GetAbilityInfo().name.c_str()); @@ -2039,7 +2038,8 @@ void AbilityConnectManager::HandleAbilityDiedTask( return; } if (DelayedSingleton::GetInstance()->IsMemorySizeSufficent() || - IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard() || IsSampleManagement(abilityRecord)) { + IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard() || + AppUtils::GetInstance().IsAllowResidentInExtremeMemory(abilityInfo.bundleName, abilityInfo.name)) { RestartAbility(abilityRecord, currentUserId); } } else { @@ -2368,16 +2368,6 @@ bool AbilityConnectManager::IsLauncher(std::shared_ptr serviceExt serviceExtension->GetAbilityInfo().bundleName == AbilityConfig::LAUNCHER_BUNDLE_NAME; } -bool AbilityConnectManager::IsSampleManagement(std::shared_ptr serviceExtension) const -{ - if (serviceExtension == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "param is nullptr"); - return false; - } - return serviceExtension->GetAbilityInfo().name == ABILITY_NAME_SAMPLE_MANAGEMENT && - serviceExtension->GetAbilityInfo().bundleName == BUNDLE_NAME_SAMPLE_MANAGEMENT; -} - void AbilityConnectManager::KillProcessesByUserId() const { auto appScheduler = DelayedSingleton::GetInstance(); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index a4d55f11d2..cf132a6cc4 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -188,8 +188,6 @@ constexpr const char* EVENT_KEY_MESSAGE = "MSG"; constexpr const char* DEVELOPER_MODE_STATE = "const.security.developermode.state"; constexpr const char* PRODUCT_ASSERT_FAULT_DIALOG_ENABLED = "persisit.sys.abilityms.support_assert_fault_dialog"; -constexpr char BUNDLE_NAME_SAMPLE_MANAGEMENT[] = "com.huawei.hmsapp.samplemanagement"; - // Msg length is less than 48 characters constexpr const char* EVENT_MESSAGE_TERMINATE_ABILITY_TIMEOUT = "Terminate Ability TimeOut!"; constexpr const char* EVENT_MESSAGE_TERMINATE_APPLICATION_TIMEOUT = "Terminate Application TimeOut!"; @@ -5992,7 +5990,7 @@ void AppMgrServiceInner::ClearAppRunningDataForKeepAlive(const std::shared_ptrIsKeepAliveApp()) { - if (appRecord->GetBundleName() != BUNDLE_NAME_SAMPLE_MANAGEMENT && + if (!AAFwk::AppUtils::GetInstance().IsAllowResidentInExtremeMemory(appRecord->GetBundleName()) && ExitResidentProcessManager::GetInstance().RecordExitResidentBundleName(appRecord->GetBundleName())) { TAG_LOGI(AAFwkTag::APPMGR, "memory size is insufficent, record exit resident process info"); return; diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index f0aaa3ae9f..21eae80af8 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -113,14 +113,19 @@ ohos_shared_library("task_handler_wrap") { ohos_shared_library("app_util") { public_configs = [ ":common_config" ] - include_dirs = [ "include" ] + include_dirs = [ + "include", + "//third_party/json/include", + ] sources = [ "src/ability_manager_radar.cpp", "src/app_utils.cpp", + "src/configuation_utils.cpp", ] external_deps = [ + "config_policy:configpolicy_util", "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", diff --git a/services/common/include/app_utils.h b/services/common/include/app_utils.h index 509ab97bbf..b5d8e3bbc6 100644 --- a/services/common/include/app_utils.h +++ b/services/common/include/app_utils.h @@ -32,6 +32,7 @@ public: class AppUtils { public: static AppUtils &GetInstance(); + ~AppUtils(); bool IsLauncher(const std::string &bundleName) const; bool IsLauncherAbility(const std::string &abilityName) const; bool IsInheritWindowSplitScreenMode(); @@ -48,10 +49,11 @@ public: bool EnableMoveUIAbilityToBackgroundApi(); bool IsLaunchEmbededUIAbility(); bool IsSupportNativeChildProcess(); + bool IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName = ""); private: + void LoadResidentProcessInExtremeMemory(); AppUtils(); - ~AppUtils(); volatile bool isSceneBoard_ = false; volatile DeviceConfiguration isInheritWindowSplitScreenMode_ = {false, true}; volatile DeviceConfiguration isSupportAncoApp_ = {false, false}; @@ -67,6 +69,8 @@ private: volatile DeviceConfiguration enableMoveUIAbilityToBackgroundApi_ = {false, true}; volatile DeviceConfiguration isLaunchEmbededUIAbility_ = {false, false}; volatile DeviceConfiguration isSupportNativeChildProcess_ = {false, false}; + DeviceConfiguration>> + residentProcessInExtremeMemory_ = {false, {}}; DISALLOW_COPY_AND_MOVE(AppUtils); }; } // namespace AAFwk diff --git a/services/common/include/json_utils.h b/services/common/include/json_utils.h new file mode 100644 index 0000000000..67c0c6c280 --- /dev/null +++ b/services/common/include/json_utils.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_JSON_UTILS_H +#define OHOS_ABILITY_RUNTIME_JSON_UTILS_H + +#include +#include + +#include "nlohmann/json.hpp" +#include "singleton.h" + +namespace OHOS { +namespace AAFwk { +class JsonUtils { +public: + static JsonUtils &GetInstance() + { + static JsonUtils instance; + return instance; + } + ~JsonUtils() = default; + bool LoadConfiguration(const std::string& path, nlohmann::json& jsonBuf, const std::string& defaultPath = ""); + +private: + std::string GetConfigPath(const std::string& path, const std::string& defaultPath); + bool ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf); + JsonUtils() = default; + DISALLOW_COPY_AND_MOVE(JsonUtils); +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JSON_UTILS_H \ No newline at end of file diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index 9a83fb5fe4..7d3e0a7a46 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -14,9 +14,10 @@ */ #include "app_utils.h" - +#include "configuation_utils.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" +#include "nlohmann/json.hpp" #include "parameters.h" #ifdef SUPPORT_GRAPHICS #include "scene_board_judgement.h" @@ -26,25 +27,29 @@ namespace OHOS { namespace AAFwk { namespace { -const std::string BUNDLE_NAME_LAUNCHER = "com.ohos.launcher"; -const std::string BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; -const std::string LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility"; -const std::string SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; -const std::string INHERIT_WINDOW_SPLIT_SCREEN_MODE = "persist.sys.abilityms.inherit_window_split_screen_mode"; -const std::string SUPPORT_ANCO_APP = "persist.sys.abilityms.support_anco_app"; -const std::string TIMEOUT_UNIT_TIME_RATIO = "persist.sys.abilityms.timeout_unit_time_ratio"; -const std::string SELECTOR_DIALOG_POSSION = "persist.sys.abilityms.selector_dialog_possion"; -const std::string START_SPECIFIED_PROCESS = "persist.sys.abilityms.start_specified_process"; -const std::string USE_MULTI_RENDER_PROCESS = "persist.sys.abilityms.use_multi_render_process"; -const std::string LIMIT_MAXIMUM_OF_RENDER_PROCESS = "persist.sys.abilityms.limit_maximum_of_render_process"; -const std::string GRANT_PERSIST_URI_PERMISSION = "persist.sys.abilityms.grant_persist_uri_permission"; -const std::string START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation"; -const std::string MULTI_PROCESS_MODEL = "persist.sys.abilityms.multi_process_model"; -const std::string START_OPTIONS_WITH_PROCESS_OPTION = "persist.sys.abilityms.start_options_with_process_option"; -const std::string MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE = +constexpr const char* BUNDLE_NAME_LAUNCHER = "com.ohos.launcher"; +constexpr const char* BUNDLE_NAME_SCENEBOARD = "com.ohos.sceneboard"; +constexpr const char* LAUNCHER_ABILITY_NAME = "com.ohos.launcher.MainAbility"; +constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility"; +constexpr const char* INHERIT_WINDOW_SPLIT_SCREEN_MODE = "persist.sys.abilityms.inherit_window_split_screen_mode"; +constexpr const char* SUPPORT_ANCO_APP = "persist.sys.abilityms.support_anco_app"; +constexpr const char* TIMEOUT_UNIT_TIME_RATIO = "persist.sys.abilityms.timeout_unit_time_ratio"; +constexpr const char* SELECTOR_DIALOG_POSSION = "persist.sys.abilityms.selector_dialog_possion"; +constexpr const char* START_SPECIFIED_PROCESS = "persist.sys.abilityms.start_specified_process"; +constexpr const char* USE_MULTI_RENDER_PROCESS = "persist.sys.abilityms.use_multi_render_process"; +constexpr const char* LIMIT_MAXIMUM_OF_RENDER_PROCESS = "persist.sys.abilityms.limit_maximum_of_render_process"; +constexpr const char* GRANT_PERSIST_URI_PERMISSION = "persist.sys.abilityms.grant_persist_uri_permission"; +constexpr const char* START_OPTIONS_WITH_ANIMATION = "persist.sys.abilityms.start_options_with_animation"; +constexpr const char* MULTI_PROCESS_MODEL = "persist.sys.abilityms.multi_process_model"; +constexpr const char* START_OPTIONS_WITH_PROCESS_OPTION = "persist.sys.abilityms.start_options_with_process_option"; +constexpr const char* MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE = "persist.sys.abilityms.move_ui_ability_to_background_api_enable"; -const std::string LAUNCH_EMBEDED_UI_ABILITY = "const.abilityms.launch_embeded_ui_ability"; -const std::string SUPPROT_NATIVE_CHILD_PROCESS = "persist.sys.abilityms.start_native_child_process"; +constexpr const char* LAUNCH_EMBEDED_UI_ABILITY = "const.abilityms.launch_embeded_ui_ability"; +constexpr const char* SUPPROT_NATIVE_CHILD_PROCESS = "persist.sys.abilityms.start_native_child_process"; +constexpr const char* CONFIG_PATH = "/etc/ability_runtime/resident_process_in_extreme_memory.json"; +constexpr const char* RESIDENT_PROCESS_IN_EXTREME_MEMORY = "residentProcessInExtremeMemory"; +constexpr const char* BUNDLE_NAME = "bundleName"; +constexpr const char* ABILITY_NAME = "abilityName"; } AppUtils::~AppUtils() {} @@ -98,7 +103,7 @@ bool AppUtils::IsSupportAncoApp() isSupportAncoApp_.value = system::GetBoolParameter(SUPPORT_ANCO_APP, false); isSupportAncoApp_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isSupportAncoApp is %{public}d", isSupportAncoApp_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isSupportAncoApp is %{public}d", isSupportAncoApp_.value); return isSupportAncoApp_.value; } @@ -118,7 +123,7 @@ bool AppUtils::IsSelectorDialogDefaultPossion() isSelectorDialogDefaultPossion_.value = system::GetBoolParameter(SELECTOR_DIALOG_POSSION, true); isSelectorDialogDefaultPossion_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isSelectorDialogDefaultPossion is %{public}d", isSelectorDialogDefaultPossion_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isSelectorDialogDefaultPossion is %{public}d", isSelectorDialogDefaultPossion_.value); return isSelectorDialogDefaultPossion_.value; } @@ -128,7 +133,7 @@ bool AppUtils::IsStartSpecifiedProcess() isStartSpecifiedProcess_.value = system::GetBoolParameter(START_SPECIFIED_PROCESS, false); isStartSpecifiedProcess_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isStartSpecifiedProcess is %{public}d", isStartSpecifiedProcess_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isStartSpecifiedProcess is %{public}d", isStartSpecifiedProcess_.value); return isStartSpecifiedProcess_.value; } @@ -138,7 +143,7 @@ bool AppUtils::IsUseMultiRenderProcess() isUseMultiRenderProcess_.value = system::GetBoolParameter(USE_MULTI_RENDER_PROCESS, true); isUseMultiRenderProcess_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isUseMultiRenderProcess is %{public}d", isUseMultiRenderProcess_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isUseMultiRenderProcess is %{public}d", isUseMultiRenderProcess_.value); return isUseMultiRenderProcess_.value; } @@ -148,7 +153,7 @@ bool AppUtils::IsLimitMaximumOfRenderProcess() isLimitMaximumOfRenderProcess_.value = system::GetBoolParameter(LIMIT_MAXIMUM_OF_RENDER_PROCESS, true); isLimitMaximumOfRenderProcess_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isLimitMaximumOfRenderProcess_ is %{public}d", isLimitMaximumOfRenderProcess_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isLimitMaximumOfRenderProcess_ is %{public}d", isLimitMaximumOfRenderProcess_.value); return isLimitMaximumOfRenderProcess_.value; } @@ -158,7 +163,7 @@ bool AppUtils::IsGrantPersistUriPermission() isGrantPersistUriPermission_.value = system::GetBoolParameter(GRANT_PERSIST_URI_PERMISSION, false); isGrantPersistUriPermission_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isGrantPersistUriPermission_ is %{public}d", isGrantPersistUriPermission_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isGrantPersistUriPermission_ is %{public}d", isGrantPersistUriPermission_.value); return isGrantPersistUriPermission_.value; } @@ -168,7 +173,7 @@ bool AppUtils::IsStartOptionsWithAnimation() isStartOptionsWithAnimation_.value = system::GetBoolParameter(START_OPTIONS_WITH_ANIMATION, false); isStartOptionsWithAnimation_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isStartOptionsWithAnimation_ is %{public}d", isStartOptionsWithAnimation_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isStartOptionsWithAnimation_ is %{public}d", isStartOptionsWithAnimation_.value); return isStartOptionsWithAnimation_.value; } @@ -188,7 +193,7 @@ bool AppUtils::IsStartOptionsWithProcessOptions() isStartOptionsWithProcessOptions_.value = system::GetBoolParameter(START_OPTIONS_WITH_PROCESS_OPTION, false); isStartOptionsWithProcessOptions_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, + TAG_LOGD(AAFwkTag::DEFAULT, "isStartOptionsWithProcessOptions_ is %{public}d", isStartOptionsWithProcessOptions_.value); return isStartOptionsWithProcessOptions_.value; } @@ -200,7 +205,7 @@ bool AppUtils::EnableMoveUIAbilityToBackgroundApi() system::GetBoolParameter(MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE, true); enableMoveUIAbilityToBackgroundApi_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, + TAG_LOGD(AAFwkTag::DEFAULT, "enableMoveUIAbilityToBackgroundApi_ is %{public}d", enableMoveUIAbilityToBackgroundApi_.value); return enableMoveUIAbilityToBackgroundApi_.value; } @@ -211,7 +216,7 @@ bool AppUtils::IsLaunchEmbededUIAbility() isLaunchEmbededUIAbility_.value = system::GetBoolParameter(LAUNCH_EMBEDED_UI_ABILITY, false); isLaunchEmbededUIAbility_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isLaunchEmbededUIAbility_ is %{public}d", isLaunchEmbededUIAbility_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isLaunchEmbededUIAbility_ is %{public}d", isLaunchEmbededUIAbility_.value); return isLaunchEmbededUIAbility_.value; } @@ -221,9 +226,52 @@ bool AppUtils::IsSupportNativeChildProcess() isSupportNativeChildProcess_.value = system::GetBoolParameter(SUPPROT_NATIVE_CHILD_PROCESS, false); isSupportNativeChildProcess_.isLoaded = true; } - TAG_LOGI(AAFwkTag::DEFAULT, "isSupportNativeChildProcess_ is %{public}d", isSupportNativeChildProcess_.value); + TAG_LOGD(AAFwkTag::DEFAULT, "isSupportNativeChildProcess_ is %{public}d", isSupportNativeChildProcess_.value); return isSupportNativeChildProcess_.value; } +bool AppUtils::IsAllowResidentInExtremeMemory(const std::string& bundleName, const std::string& abilityName) +{ + if (!residentProcessInExtremeMemory_.isLoaded) { + LoadResidentProcessInExtremeMemory(); + residentProcessInExtremeMemory_.isLoaded = true; + } + TAG_LOGD(AAFwkTag::DEFAULT, "isSupportNativeChildProcess_ is %{public}d", isSupportNativeChildProcess_.value); + for(auto &element : residentProcessInExtremeMemory_.value) { + if (bundleName == element.first && + (abilityName == "" || abilityName == element.second)) { + return true; + } + } + return false; +} + +void AppUtils::LoadResidentProcessInExtremeMemory() +{ + nlohmann::json object; + if (!JsonUtils::GetInstance().LoadConfiguration(CONFIG_PATH, object)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "load resident process in extreme memory failed."); + return; + } + if (!object.contains(RESIDENT_PROCESS_IN_EXTREME_MEMORY)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "resident process in extreme memory config not existed."); + return; + } + + for (auto &item : object.at(RESIDENT_PROCESS_IN_EXTREME_MEMORY).items()) { + const nlohmann::json& jsonObject = item.value(); + if (!jsonObject.contains(BUNDLE_NAME) || !jsonObject.at(BUNDLE_NAME).is_string()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to load bundleName."); + return; + } + if (!jsonObject.contains(ABILITY_NAME) || !jsonObject.at(ABILITY_NAME).is_string()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to load abilityName."); + return; + } + std::string bundleName = jsonObject.at(BUNDLE_NAME).get(); + std::string abilityName = jsonObject.at(ABILITY_NAME).get(); + residentProcessInExtremeMemory_.value.emplace_back(std::make_pair(bundleName, abilityName)); + } +} } // namespace AAFwk } // namespace OHOS diff --git a/services/common/src/json_utils.cpp b/services/common/src/json_utils.cpp new file mode 100644 index 0000000000..de7bcc936f --- /dev/null +++ b/services/common/src/json_utils.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "json_utils.h" +#include +#include +#include +#include + +#include "config_policy_utils.h" +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +bool JsonUtils::LoadConfiguration(const std::string& path, nlohmann::json& jsonBuf, + const std::string& defaultPath) +{ + std::string configPath = GetConfigPath(path, defaultPath); + TAG_LOGD(AAFwkTag::ABILITYMGR, "config path is: %{public}s", configPath.c_str()); + if (!ReadFileInfoJson(configPath, jsonBuf)) { + return false; + } + return true; +} + +std::string JsonUtils::GetConfigPath(const std::string& path, const std::string& defaultPath) +{ + char buf[MAX_PATH_LEN] = { 0 }; + char *configPath = GetOneCfgFile(path.c_str(), buf, MAX_PATH_LEN); + if (configPath == nullptr || configPath[0] == '\0' || strlen(configPath) > MAX_PATH_LEN) { + return defaultPath; + } + return configPath; +} + +bool JsonUtils::ReadFileInfoJson(const std::string &filePath, nlohmann::json &jsonBuf) +{ + if (access(filePath.c_str(), F_OK) != 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Deeplink reserve config not exist."); + return false; + } + + if (filePath.empty()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "File path is empty."); + return false; + } + + char path[PATH_MAX] = {0}; + if (realpath(filePath.c_str(), path) == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "realpath error, errno is %{public}d.", errno); + return false; + } + + std::fstream in; + char errBuf[256]; + errBuf[0] = '\0'; + in.open(path, std::ios_base::in); + if (!in.is_open()) { + strerror_r(errno, errBuf, sizeof(errBuf)); + TAG_LOGE(AAFwkTag::ABILITYMGR, "the file cannot be open due to %{public}s", errBuf); + return false; + } + + in.seekg(0, std::ios::end); + int64_t size = in.tellg(); + if (size <= 0) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "the file is an empty file"); + in.close(); + return false; + } + + in.seekg(0, std::ios::beg); + jsonBuf = nlohmann::json::parse(in, nullptr, false); + in.close(); + if (jsonBuf.is_discarded()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "bad profile file"); + return false; + } + + return true; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file From d5c8aedbedd677c7f50e10402ea63d856dcbb35b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Fri, 21 Jun 2024 09:06:54 +0000 Subject: [PATCH 026/148] update services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../src/interceptor/disposed_rule_interceptor.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index b586a07bec..63122088e1 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -264,12 +264,6 @@ void DisposedRuleInterceptor::SetInterceptInfo(const Want &want, AppExecFwk::Dis return; } if (disposedRule.want->GetBoolParam(IS_FROM_PARENTCONTROL, false)) { - auto disposedParam = disposedRule.want->GetParams(); - sptr interceptParam = WantParamWrapper::Box(want.GetParams()); - if (interceptParam != nullptr) { - disposedParam.SetParam(INTERCEPT_PARAMETERS, interceptParam); - } - disposedRule.want->SetParams(disposedParam); disposedRule.want->SetParam(INTERCEPT_BUNDLE_NAME, want.GetElement().GetBundleName()); disposedRule.want->SetParam(INTERCEPT_ABILITY_NAME, want.GetElement().GetAbilityName()); disposedRule.want->SetParam(INTERCEPT_MODULE_NAME, want.GetElement().GetModuleName()); From c8094b74e98f7c59a2b1399129ac81ba5d6e43f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Fri, 21 Jun 2024 09:11:37 +0000 Subject: [PATCH 027/148] update services/common/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- services/common/BUILD.gn | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 6d4bfb79c4..2576dfcd08 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -113,10 +113,7 @@ ohos_shared_library("task_handler_wrap") { ohos_shared_library("app_util") { public_configs = [ ":common_config" ] - include_dirs = [ - "include", - "//third_party/json/include", - ] + include_dirs = [ "include" ] sources = [ "src/ability_manager_radar.cpp", @@ -129,6 +126,7 @@ ohos_shared_library("app_util") { "hilog:libhilog", "hisysevent:libhisysevent", "init:libbegetutil", + "json:nlohmann_json_static", ] if (ability_runtime_graphics) { From 2839187ba977a4a3cee6f1cee144da9f4ec95dca Mon Sep 17 00:00:00 2001 From: sunxuhui Date: Fri, 21 Jun 2024 17:27:06 +0800 Subject: [PATCH 028/148] update Signed-off-by: sunxuhui --- services/abilitymgr/src/ability_manager_stub.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index ebd09d89d8..48b3d40188 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -3457,6 +3457,10 @@ int32_t AbilityManagerStub::TransferAbilityResultForExtensionInner(MessageParcel sptr callerToken = data.ReadRemoteObject(); int32_t resultCode = data.ReadInt32(); sptr want = data.ReadParcelable(); + if (want == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "want is nullptr"); + return ERR_INVALID_VALUE; + } int32_t result = TransferAbilityResultForExtension(callerToken, resultCode, *want); reply.WriteInt32(result); return NO_ERROR; From 8f771d58cb137fb70b6346a013cbb1aa34da1107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Fri, 21 Jun 2024 09:31:02 +0000 Subject: [PATCH 029/148] update services/common/BUILD.gn. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- services/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 2576dfcd08..d5aca12037 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -118,7 +118,7 @@ ohos_shared_library("app_util") { sources = [ "src/ability_manager_radar.cpp", "src/app_utils.cpp", - "src/configuation_utils.cpp", + "src/json_utils.cpp", ] external_deps = [ From c0561a52a734998308e070e8ad28c549fe0a149d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Fri, 21 Jun 2024 10:05:49 +0000 Subject: [PATCH 030/148] update services/common/src/app_utils.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- services/common/src/app_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index 08e29162ad..84726d89c7 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -14,7 +14,7 @@ */ #include "app_utils.h" -#include "configuation_utils.h" +#include "json_utils.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "nlohmann/json.hpp" From f46e5bc44f3e7141ba31b334f0f3ceb299a664d8 Mon Sep 17 00:00:00 2001 From: liangzhao Date: Fri, 21 Jun 2024 10:15:32 +0000 Subject: [PATCH 031/148] modify config item name Signed-off-by: liangzhao --- services/abilitymgr/etc/appfwk.para | 6 +++--- services/abilitymgr/etc/appfwk.para.dac | 6 +++--- services/common/src/app_utils.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/services/abilitymgr/etc/appfwk.para b/services/abilitymgr/etc/appfwk.para index 7e0fca3c58..115ca8d88e 100644 --- a/services/abilitymgr/etc/appfwk.para +++ b/services/abilitymgr/etc/appfwk.para @@ -34,6 +34,6 @@ persist.sys.abilityms.start_options_with_process_option = false persist.sys.abilityms.move_ui_ability_to_background_api_enable = true persist.sys.abilityms.prevent_startability = true const.abilityms.launch_embeded_ui_ability = false -persist.sys.abilityms.limit_maximum_extensions_of_per_process = 10 -persist.sys.abilityms.limit_maximum_extensions_of_per_device = 100 -persist.sys.abilityms.cache_extension = 3;5;17 \ No newline at end of file +const.sys.abilityms.limit_maximum_extensions_of_per_process = 10 +const.sys.abilityms.limit_maximum_extensions_of_per_device = 100 +const.sys.abilityms.cache_extension = 3;5;17;260 \ No newline at end of file diff --git a/services/abilitymgr/etc/appfwk.para.dac b/services/abilitymgr/etc/appfwk.para.dac index 9ca134de7f..2d31be0f30 100644 --- a/services/abilitymgr/etc/appfwk.para.dac +++ b/services/abilitymgr/etc/appfwk.para.dac @@ -34,6 +34,6 @@ persist.sys.abilityms.start_options_with_process_option = foundation:foundation: persist.sys.abilityms.move_ui_ability_to_background_api_enable = foundation:foundation:0755 persist.sys.abilityms.prevent_startability = foundation:foundation:0755 const.abilityms.launch_embeded_ui_ability = foundation:foundation:0755 -persist.sys.abilityms.limit_maximum_extensions_of_per_process = foundation:foundation:0755 -persist.sys.abilityms.limit_maximum_extensions_of_per_device = foundation:foundation:0755 -persist.sys.abilityms.cache_extension = foundation:foundation:0755 \ No newline at end of file +const.sys.abilityms.limit_maximum_extensions_of_per_process = foundation:foundation:0755 +const.sys.abilityms.limit_maximum_extensions_of_per_device = foundation:foundation:0755 +const.sys.abilityms.cache_extension = foundation:foundation:0755 \ No newline at end of file diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index 696e70f2df..585c8cf7cf 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -46,10 +46,10 @@ const std::string MOVE_UI_ABILITY_TO_BACKGROUND_API_ENABLE = const std::string LAUNCH_EMBEDED_UI_ABILITY = "const.abilityms.launch_embeded_ui_ability"; const std::string SUPPROT_NATIVE_CHILD_PROCESS = "persist.sys.abilityms.start_native_child_process"; const std::string LIMIT_MAXIMUM_EXTENSIONS_OF_PER_PROCESS = - "persist.sys.abilityms.limit_maximum_extensions_of_per_process"; + "const.sys.abilityms.limit_maximum_extensions_of_per_process"; const std::string LIMIT_MAXIMUM_EXTENSIONS_OF_PER_DEVICE = - "persist.sys.abilityms.limit_maximum_extensions_of_per_device"; -const std::string CACHE_EXTENSION_TYPES = "persist.sys.abilityms.cache_extension"; + "const.sys.abilityms.limit_maximum_extensions_of_per_device"; +const std::string CACHE_EXTENSION_TYPES = "const.sys.abilityms.cache_extension"; } AppUtils::~AppUtils() {} @@ -255,7 +255,7 @@ int32_t AppUtils::GetLimitMaximumExtensionsPerDevice() std::string AppUtils::GetCacheExtensionTypeList() { - std::string cacheExtAbilityTypeList = system::GetParameter(CACHE_EXTENSION_TYPES, "3;5;17"); + std::string cacheExtAbilityTypeList = system::GetParameter(CACHE_EXTENSION_TYPES, "3;5;17;260"); TAG_LOGD(AAFwkTag::DEFAULT, "cacheExtAbilityTypeList is %{public}s", cacheExtAbilityTypeList.c_str()); return cacheExtAbilityTypeList; } From bcaa4001093691b0cf9199c1371ec3cf07c34b92 Mon Sep 17 00:00:00 2001 From: hhl Date: Fri, 21 Jun 2024 18:29:42 +0800 Subject: [PATCH 032/148] add setAppfreezeFilter interface Signed-off-by: hhl --- .../include/appmgr/app_mgr_client.h | 8 ++ .../include/appmgr/app_mgr_interface.h | 8 ++ .../appmgr/app_mgr_ipc_interface_code.h | 1 + .../include/appmgr/app_mgr_proxy.h | 8 ++ .../app_manager/include/appmgr/app_mgr_stub.h | 1 + .../app_manager/src/appmgr/app_mgr_client.cpp | 9 ++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 23 ++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 13 +++ services/appdfr/include/appfreeze_manager.h | 11 ++ services/appdfr/src/appfreeze_manager.cpp | 106 ++++++++++++++++-- services/appmgr/include/app_mgr_service.h | 8 ++ .../appmgr/include/app_mgr_service_inner.h | 8 ++ services/appmgr/src/app_mgr_service.cpp | 14 +++ services/appmgr/src/app_mgr_service_inner.cpp | 17 ++- .../include/mock_app_mgr_service.h | 5 + .../app_mgr_proxy_test/app_mgr_proxy_test.cpp | 15 +++ .../app_mgr_stub_test/app_mgr_stub_test.cpp | 17 +++ 17 files changed, 262 insertions(+), 10 deletions(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index cee2046040..1a47253997 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -516,6 +516,14 @@ public: */ int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData); + /** + * Set Appfreeze Detect Filter + * + * @param pid the process pid. + * @return Returns true on success, others on failure. + */ + bool SetAppFreezeFilter(int32_t pid); + /** * Set AbilityForegroundingFlag of an app-record to true. * 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 bb6e2616b4..8b25487054 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 @@ -431,6 +431,14 @@ public: */ virtual int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) = 0; + /** + * Set Appfreeze Detect Filter + * + * @param pid the process pid. + * @return Returns true on success, others on failure. + */ + virtual bool SetAppFreezeFilter(int32_t pid) = 0; + #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE /** * @brief Set whether the process is continuousTask. diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index 0ba1e69925..7b0b2b877a 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -106,6 +106,7 @@ enum class AppMgrInterfaceCode { GET_RUNNING_PROCESS_INFO_BY_PID = 80, IS_APP_RUNNING = 81, CHECK_CALLING_IS_USER_TEST_MODE = 82, + SET_APPFREEZE_FILTER = 83, }; } // AppExecFwk } // OHOS 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 63851b235c..8d4f61319a 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 @@ -358,6 +358,14 @@ public: */ virtual int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override; + /** + * Set Appfreeze Detect Filter + * + * @param pid the process pid. + * @return Returns true on success, others on failure. + */ + virtual bool SetAppFreezeFilter(int32_t pid) override; + #ifdef ABILITY_COMMAND_FOR_TEST /** * Block app service. 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 52c2e319a6..e5e5eb4ba4 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 @@ -110,6 +110,7 @@ private: int32_t HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyFault(MessageParcel &data, MessageParcel &reply); int32_t HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &reply); + int32_t HandleSetAppFreezeFilter(MessageParcel &data, MessageParcel &reply); int32_t HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply); int32_t HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply); int32_t HandleGetRunningProcessInfoByPid(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 597fa9e294..61beba12c4 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 @@ -854,6 +854,15 @@ int32_t AppMgrClient::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) return service->NotifyAppFaultBySA(faultData); } +bool AppMgrClient::SetAppFreezeFilter(int32_t pid) +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + return service->SetAppFreezeFilter(pid); +} + int32_t AppMgrClient::ChangeAppGcState(pid_t pid, int32_t state) { if (mgrHolder_ == 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 d485e4899a..cb03c801c8 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 @@ -1433,6 +1433,29 @@ int32_t AppMgrProxy::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) return reply.ReadInt32(); } +bool AppMgrProxy::SetAppFreezeFilter(int32_t pid) +{ + TAG_LOGD(AAFwkTag::APPMGR, "called."); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return false; + } + if (!data.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::APPMGR, "write pid failed."); + return false; + } + auto ret = SendRequest(AppMgrInterfaceCode::SET_APPFREEZE_FILTER, + data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret); + return false; + } + return reply.ReadBool(); +} + int32_t AppMgrProxy::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) { TAG_LOGD(AAFwkTag::APPMGR, "GetProcessMemoryByPid start"); 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 b6dedf7e42..c65d40d24b 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 @@ -131,6 +131,8 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleNotifyFaultBySA; memberFuncMap_[static_cast(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID)] = &AppMgrStub::HandleJudgeSandboxByPid; + memberFuncMap_[static_cast(AppMgrInterfaceCode::SET_APPFREEZE_FILTER)] = + &AppMgrStub::HandleSetAppFreezeFilter; memberFuncMap_[static_cast(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID)] = &AppMgrStub::HandleGetBundleNameByPid; memberFuncMap_[static_cast(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_PID)] = @@ -1010,6 +1012,17 @@ int32_t AppMgrStub::HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &re return NO_ERROR; } +int32_t AppMgrStub::HandleSetAppFreezeFilter(MessageParcel &data, MessageParcel &reply) +{ + int32_t pid = data.ReadInt32(); + bool result = SetAppFreezeFilter(pid); + if (!reply.WriteBool(result)) { + TAG_LOGE(AAFwkTag::APPMGR, "reply write failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int32_t AppMgrStub::HandleGetProcessMemoryByPid(MessageParcel &data, MessageParcel &reply) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/services/appdfr/include/appfreeze_manager.h b/services/appdfr/include/appfreeze_manager.h index 60b85fca99..4b1319b0cb 100644 --- a/services/appdfr/include/appfreeze_manager.h +++ b/services/appdfr/include/appfreeze_manager.h @@ -50,6 +50,8 @@ public: enum AppFreezeState { APPFREEZE_STATE_IDLE = 0, APPFREEZE_STATE_FREEZE = 1, + APPFREEZE_STATE_CANCELING = 2, + APPFREEZE_STATE_CANCELED = 3, }; struct AppFreezeInfo { @@ -79,6 +81,10 @@ public: bool IsProcessDebug(int32_t pid, std::string processName); bool IsNeedIgnoreFreezeEvent(int32_t pid); void DeleteStack(int pid); + bool CancelAppFreezeDetect(int32_t pid); + void RemoveDeathProcess(std::string processName); + void ResetAppfreezeState(int32_t pid); + bool IsValidFreezeFilter(int32_t pid); private: AppfreezeManager& operator=(const AppfreezeManager&) = delete; @@ -97,6 +103,9 @@ private: int GetFreezeState(int32_t pid); int64_t GetFreezeTime(int32_t pid); void ClearOldInfo(); + std::string FormatCmdLine(const std::string& cmdLine); + std::string GetProcessName(int32_t pid); + std::string GetBundleName(int32_t pid); static const inline std::string LOGGER_DEBUG_PROC_PATH = "/proc/transaction_proc"; std::string name_; @@ -106,6 +115,8 @@ private: std::map appfreezeInfo_; static ffrt::mutex catchStackMutex_; static std::map catchStackMap_; + static ffrt::mutex freezeFilterMutex_; + std::map appfreezeFilterMap_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 3faa55f0e1..cfaa565bba 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -59,6 +59,7 @@ ffrt::mutex AppfreezeManager::singletonMutex_; ffrt::mutex AppfreezeManager::freezeMutex_; ffrt::mutex AppfreezeManager::catchStackMutex_; std::map AppfreezeManager::catchStackMap_; +ffrt::mutex AppfreezeManager::freezeFilterMutex_; AppfreezeManager::AppfreezeManager() { @@ -437,17 +438,19 @@ std::string AppfreezeManager::CatcherStacktrace(int pid) const bool AppfreezeManager::IsProcessDebug(int32_t pid, std::string processName) { - const int buffSize = 128; - char param[buffSize] = {0}; - std::string filter = "hiviewdfx.freeze.filter." + processName; - GetParameter(filter.c_str(), "", param, buffSize - 1); - int32_t debugPid = atoi(param); - if (debugPid == pid) { - TAG_LOGI(AAFwkTag::APPDFR, "appfreeze filtration %{public}s_%{public}d don't exit.", - processName.c_str(), debugPid); - return true; + std::lock_guard lock(freezeFilterMutex_); + auto it = appfreezeFilterMap_.find(processName); + if (it != appfreezeFilterMap_.end() && it->second.pid == pid) { + if (it->second.state == AppFreezeState::APPFREEZE_STATE_CANCELED) { + TAG_LOGI(AAFwkTag::APPDFR, "appfreeze filtration only once in a lifecycle."); + return false; + } else { + TAG_LOGI(AAFwkTag::APPDFR, "appfreeze filtration %{public}s", processName.c_str()); + return true; + } } + const int buffSize = 128; char paramBundle[buffSize] = {0}; GetParameter("hiviewdfx.appfreeze.filter_bundle_name", "", paramBundle, buffSize - 1); std::string debugBundle(paramBundle); @@ -544,5 +547,90 @@ bool AppfreezeManager::IsNeedIgnoreFreezeEvent(int32_t pid) return false; } } + +std::string AppfreezeManager::FormatCmdLine(const std::string& cmdLine) +{ + std::string::size_type startPos = 0; + std::string::size_type endPos = cmdLine.size(); + for (std::string::size_type i = 0; i < cmdLine.size(); i++) { + if (cmdLine[i] == '/') { + startPos = i + 1; + } else if (cmdLine[i] == '\0') { + endPos = i; + break; + } + } + return cmdLine.substr(startPos, endPos - startPos); +} + +std::string AppfreezeManager::GetProcessName(int32_t pid) +{ + std::ifstream cmdLineFile("/proc/" + std::to_string(pid) + "/cmdline"); + std::string processName; + if (cmdLineFile) { + std::getline(cmdLineFile, processName); + cmdLineFile.close(); + processName = FormatCmdLine(processName); + return processName; + } else { + TAG_LOGI(AAFwkTag::APPDFR, "GetProcessName failed, pid: %{public}d", pid); + return ""; + } +} + +std::string AppfreezeManager::GetBundleName(int32_t pid) +{ + std::string processName = GetProcessName(pid); + if (processName.find(":") != std::string::npos) { + return processName.substr(0, processName.find(":")); + } + return processName; +} + +bool AppfreezeManager::CancelAppFreezeDetect(int32_t pid) +{ + std::string processName = GetBundleName(pid); + if (processName.empty()) { + return false; + } + std::lock_guard lock(freezeFilterMutex_); + AppFreezeInfo info; + info.pid = pid; + info.state = AppFreezeState::APPFREEZE_STATE_CANCELING; + appfreezeFilterMap_.emplace(processName, info); + return true; +} + +void AppfreezeManager::RemoveDeathProcess(std::string processName) +{ + std::lock_guard lock(freezeFilterMutex_); + auto it = appfreezeFilterMap_.find(processName); + if (it != appfreezeFilterMap_.end()) { + TAG_LOGD(AAFwkTag::APPDFR, "RemoveDeathProcess processName: %{public}s", + processName.c_str()); + appfreezeFilterMap_.erase(it); + } +} + +void AppfreezeManager::ResetAppfreezeState(int32_t pid) +{ + std::string processName = GetBundleName(pid); + std::lock_guard lock(freezeFilterMutex_); + if (appfreezeFilterMap_.find(processName) != appfreezeFilterMap_.end()) { + TAG_LOGD(AAFwkTag::APPDFR, "ResetAppfreezeState processName: %{public}s", + processName.c_str()); + appfreezeFilterMap_[processName].state = AppFreezeState::APPFREEZE_STATE_CANCELED; + } +} + +bool AppfreezeManager::IsValidFreezeFilter(int32_t pid) +{ + std::lock_guard lock(freezeFilterMutex_); + std::string processName = GetBundleName(pid); + if (appfreezeFilterMap_.find(processName) != appfreezeFilterMap_.end()) { + return false; + } + return true; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 1aed994043..51d4538e31 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -405,6 +405,14 @@ public: */ int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData) override; + /** + * Set Appfreeze Detect Filter + * + * @param pid the process pid. + * @return Returns true on success, others on failure. + */ + bool SetAppFreezeFilter(int32_t pid) override; + /** * get memorySize by pid. * diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 796dd813c7..9865d51cfb 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -819,6 +819,14 @@ public: */ int32_t NotifyAppFaultBySA(const AppFaultDataBySA &faultData); + /** + * Set Appfreeze Detect Filter + * + * @param pid the process pid. + * @return Returns true on success, others on failure. + */ + bool SetAppFreezeFilter(int32_t pid); + /** * get memorySize by pid. * diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index bff60162d5..c646b0c583 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1189,6 +1189,20 @@ int32_t AppMgrService::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) return ret; } +bool AppMgrService::SetAppFreezeFilter(int32_t pid) +{ + if (!IsReady()) { + TAG_LOGE(AAFwkTag::APPMGR, "AppMgrService is not ready."); + return ERR_INVALID_OPERATION; + } + + auto ret = appMgrServiceInner_->SetAppFreezeFilter(pid); + if (!ret) { + TAG_LOGE(AAFwkTag::APPMGR, "SetAppFreezeFilter fail."); + } + return ret; +} + int32_t AppMgrService::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySize) { if (!IsReady()) { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index aa781a9abf..39ea3f9775 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -3091,7 +3091,7 @@ void AppMgrServiceInner::OnRemoteDied(const wptr &remote, bool is TAG_LOGI(AAFwkTag::APPMGR, "app record is not exist."); return; } - + AppExecFwk::AppfreezeManager::GetInstance()->RemoveDeathProcess(appRecord->GetBundleName()); std::vector> abilityTokens; for (const auto &token : appRecord->GetAbilities()) { abilityTokens.emplace_back(token.first); @@ -5306,6 +5306,21 @@ int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData return ERR_OK; } +bool AppMgrServiceInner::SetAppFreezeFilter(int32_t pid) +{ + int32_t callingPid = IPCSkeleton::GetCallingPid(); + if (callingPid == pid && AppExecFwk::AppfreezeManager::GetInstance()->IsValidFreezeFilter(pid)) { + bool cancelResult = AppExecFwk::AppfreezeManager::GetInstance()->CancelAppFreezeDetect(pid); + auto resetAppfreezeTask = [pid, innerService = shared_from_this()]() { + AppExecFwk::AppfreezeManager::GetInstance()->ResetAppfreezeState(pid); + }; + constexpr int32_t waitTime = 120000; // wait 2min + taskHandler_->SubmitTask(resetAppfreezeTask, "resetAppfreezeTask", waitTime); + return cancelResult; + } + return false; +} + FaultData AppMgrServiceInner::ConvertDataTypes(const AppFaultDataBySA &faultData) { FaultData newfaultData; 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 cd2fe2f138..f97a6ebdf2 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 @@ -226,6 +226,11 @@ public: int code_; + virtual bool SetAppFreezeFilter(int32_t pid) + { + return false; + } + virtual int32_t ChangeAppGcState(pid_t pid, int32_t state) { return 0; diff --git a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp index 82682e1ec8..d88434a2f8 100644 --- a/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp +++ b/test/unittest/app_mgr_proxy_test/app_mgr_proxy_test.cpp @@ -333,6 +333,21 @@ HWTEST_F(AppMgrProxyTest, NotifyAppFaultBySA_001, TestSize.Level1) EXPECT_EQ(mockAppMgrService_->code_, static_cast(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA)); } +/** + * @tc.name: SetAppFreezeFilter_001 + * @tc.desc: Set appfreeze filter. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrProxyTest, SetAppFreezeFilter_001, TestSize.Level1) +{ + EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest)); + int32_t pid = 0; // test value + appMgrProxy_->SetAppFreezeFilter(pid); + EXPECT_EQ(mockAppMgrService_->code_, static_cast(AppMgrInterfaceCode::SET_APPFREEZE_FILTER)); +} + /** * @tc.name: ChangeAppGcState_001 * @tc.desc: Change app Gc state. diff --git a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp index 79ec2bf9b8..7e1c3f6e21 100644 --- a/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp +++ b/test/unittest/app_mgr_stub_test/app_mgr_stub_test.cpp @@ -335,6 +335,23 @@ HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level1) EXPECT_EQ(result, NO_ERROR); } +/** + * @tc.name: HandleSetAppFreezeFilter_001 + * @tc.desc: Handle Set AppFreeze Filter. + * @tc.type: FUNC + */ +HWTEST_F(AppMgrStubTest, HandleSetAppFreezeFilter_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + WriteInterfaceToken(data); + data.WriteInt32(0); + auto result = mockAppMgrService_->OnRemoteRequest( + static_cast(AppMgrInterfaceCode::SET_APPFREEZE_FILTER), data, reply, option); + EXPECT_EQ(result, NO_ERROR); +} + /** * @tc.name: HandleChangeAppGcState_001 * @tc.desc: Handle change app Gc state. From 74ae8078ea21ea7efa00ac32f7735a6340de7ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Fri, 21 Jun 2024 11:28:51 +0000 Subject: [PATCH 033/148] update services/abilitymgr/src/ability_manager_service.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- services/abilitymgr/src/ability_manager_service.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 9a447f9ee4..d2cd074bf3 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -7928,12 +7928,17 @@ int AbilityManagerService::CheckStaticCfgPermissionForSkill(const AppExecFwk::Ab if (abilityInfo.skills.empty()) { return AppExecFwk::Constants::PERMISSION_GRANTED; } + int32_t result = AppExecFwk::Constants::PERMISSION_GRANTED; for (auto skill : abilityInfo.skills) { - if (skill.Match(abilityRequest.want) && CheckOneSkillPermission(skill, tokenId)) { - return AppExecFwk::Constants::PERMISSION_GRANTED; + if (skill.Match(abilityRequest.want)) { + if (CheckOneSkillPermission(skill, tokenId)) { + return AppExecFwk::Constants::PERMISSION_GRANTED; + } else { + result = AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + } } } - return AppExecFwk::Constants::PERMISSION_NOT_GRANTED; + return result; } int AbilityManagerService::CheckStaticCfgPermission(const AppExecFwk::AbilityRequest &abilityRequest, From 3ef28db9f6fb10a1af1fd5137da2128f95c2dd76 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 21 Jun 2024 20:18:29 +0800 Subject: [PATCH 034/148] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/IA7D9Y MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 删除冗余依赖 Signed-off-by: jiangzhijun8 --- frameworks/js/napi/inner/napi_ability_common/BUILD.gn | 1 - frameworks/js/napi/inner/napi_common/BUILD.gn | 1 - interfaces/inner_api/ability_manager/BUILD.gn | 2 -- interfaces/inner_api/app_manager/BUILD.gn | 1 - interfaces/inner_api/wantagent/BUILD.gn | 1 - services/abilitymgr/BUILD.gn | 1 - services/appmgr/BUILD.gn | 1 - 7 files changed, 8 deletions(-) diff --git a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn index be85ea95e4..3b2f2d4a61 100644 --- a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn @@ -47,7 +47,6 @@ ohos_shared_library("napi_ability_common") { external_deps = [ "ability_base:base", - "ability_base:configuration", "ability_base:want", "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index e02e55fb26..7c916655dc 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -46,7 +46,6 @@ ohos_shared_library("napi_common") { external_deps = [ "ability_base:base", - "ability_base:configuration", "ability_base:session_info", "ability_base:want", "access_token:libtokenid_sdk", diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index c066d6a600..150d9f058f 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -233,7 +233,6 @@ ohos_shared_library("ability_manager") { external_deps = [ "ability_base:base", "ability_base:session_info", - "bundle_framework:appexecfwk_base", "bundle_framework:libappexecfwk_common", "c_utils:utils", "common_event_service:cesfwk_innerkits", @@ -264,7 +263,6 @@ ohos_shared_library("ability_manager") { deps += [] external_deps += [ "ability_base:session_info", - "graphic_2d:color_manager", "image_framework:image_native", "window_manager:libwsutils", "window_manager:session_manager_lite", diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 9f75523c6a..9bc66c3e86 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -122,7 +122,6 @@ ohos_shared_library("app_manager") { deps = [ "${ability_runtime_path}/utils/global/freeze:freeze_util" ] external_deps = [ - "ability_base:configuration", "c_utils:utils", "faultloggerd:libdfx_dumpcatcher", "faultloggerd:libfaultloggerd", diff --git a/interfaces/inner_api/wantagent/BUILD.gn b/interfaces/inner_api/wantagent/BUILD.gn index c1ccfcf73f..7e8e73fd8e 100644 --- a/interfaces/inner_api/wantagent/BUILD.gn +++ b/interfaces/inner_api/wantagent/BUILD.gn @@ -75,7 +75,6 @@ ohos_shared_library("wantagent_innerkits") { external_deps = [ "ability_base:session_info", "ability_base:want", - "bundle_framework:appexecfwk_core", "c_utils:utils", "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 34dfdda01c..34df94b82c 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -136,7 +136,6 @@ ohos_shared_library("abilityms") { "ability_base:zuri", "access_token:libaccesstoken_sdk", "access_token:libtokenid_sdk", - "background_task_mgr:bgtaskmgr_innerkits", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "bundle_framework:libappexecfwk_common", diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index 844e5ce311..e7c41e0785 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -129,7 +129,6 @@ ohos_shared_library("libappms") { "ipc:ipc_core", "json:nlohmann_json_static", "kv_store:distributeddata_inner", - "kv_store:distributeddata_mgr", "memmgr:memmgrclient", "memory_utils:libmeminfo", "os_account:libaccountkits", From b95fa17bddf7a1684f89bb59bf9923fa9675dbf9 Mon Sep 17 00:00:00 2001 From: donglin Date: Fri, 21 Jun 2024 12:30:15 +0000 Subject: [PATCH 035/148] fix caller's info error when restart Signed-off-by: donglin Change-Id: Ib154a711bf74072eec84aa7d404df7b310862dc9 --- services/abilitymgr/src/ability_connect_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index c24c994d03..b705e6e663 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -2152,6 +2152,7 @@ void AbilityConnectManager::RestartAbility(const std::shared_ptr requestInfo.appInfo = abilityRecord->GetApplicationInfo(); requestInfo.restartTime = abilityRecord->GetRestartTime(); requestInfo.restart = true; + requestInfo.uid = abilityRecord->GetUid(); abilityRecord->SetRestarting(true); if (AppUtils::GetInstance().IsLauncherAbility(abilityRecord->GetAbilityInfo().name)) { From 0caea647ac71e08f930d97450cb679441579487c Mon Sep 17 00:00:00 2001 From: wangdengze Date: Sat, 22 Jun 2024 11:40:57 +0800 Subject: [PATCH 036/148] modify safe issue Signed-off-by: wangdengze --- services/dataobsmgr/include/concurrent_map.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/services/dataobsmgr/include/concurrent_map.h b/services/dataobsmgr/include/concurrent_map.h index cc603d37c0..c8ee212047 100644 --- a/services/dataobsmgr/include/concurrent_map.h +++ b/services/dataobsmgr/include/concurrent_map.h @@ -181,12 +181,6 @@ public: return count; } - mapped_type &operator[](const key_type &key) noexcept - { - std::lock_guard lock(mutex_); - return entries_[key]; - } - void ForEach(const std::function &action) { if (action == nullptr) { From e7dc2a01ac6051cdd7380d917a496c0994fdbf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Sat, 22 Jun 2024 12:29:29 +0800 Subject: [PATCH 037/148] =?UTF-8?q?description:=E4=BF=AE=E5=A4=8DActsServi?= =?UTF-8?q?ceAbilityClientTest=E7=94=A8=E4=BE=8B=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../napi_ability_common/js_napi_common.cpp | 348 ++++++++++++++++++ .../js_napi_common_ability.h | 100 +++++ .../napi_common_ability.cpp | 343 ----------------- .../napi_ability_common/napi_common_ability.h | 102 ----- 4 files changed, 448 insertions(+), 445 deletions(-) diff --git a/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp b/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp index d0317b2f1e..6fa4a8d0f0 100644 --- a/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/js_napi_common.cpp @@ -24,11 +24,16 @@ #include "napi_common_ability_wrap_utils.h" #include "napi_common_util.h" #include "napi_context.h" +#include "napi_remote_object.h" using namespace OHOS::AbilityRuntime; namespace OHOS { namespace AppExecFwk { +static std::map, key_compare> connects_; +static std::mutex g_connectionsLock_; +static int64_t serialNumber_ = 0; + JsNapiCommon::JsNapiCommon() : ability_(nullptr) {} @@ -1430,5 +1435,348 @@ void JsNapiCommon::AddFreeInstallObserver(napi_env env, const AAFwk::Want &want, freeInstallObserver_->AddJsObserverObject(bundleName, abilityName, startTime, callback, result); } } + +void ClearCallbackWork(uv_work_t* req, int) +{ + std::unique_ptr work(req); + if (!req) { + TAG_LOGE(AAFwkTag::JSNAPI, "work null"); + return; + } + std::unique_ptr callback(reinterpret_cast(req->data)); + if (!callback) { + TAG_LOGE(AAFwkTag::JSNAPI, "data null"); + return; + } + callback->Reset(); +} + +void ConnectionCallback::Reset() +{ + auto engine = reinterpret_cast(env); + if (engine == nullptr) { + removeKey = nullptr; + return; + } + if (pthread_self() == engine->GetTid()) { + TAG_LOGD(AAFwkTag::JSNAPI, "in-js-thread"); + if (connectCallbackRef) { + napi_delete_reference(env, connectCallbackRef); + connectCallbackRef = nullptr; + } + if (disconnectCallbackRef) { + napi_delete_reference(env, disconnectCallbackRef); + disconnectCallbackRef = nullptr; + } + if (failedCallbackRef) { + napi_delete_reference(env, failedCallbackRef); + failedCallbackRef = nullptr; + } + env = nullptr; + removeKey = nullptr; + return; + } + TAG_LOGI(AAFwkTag::JSNAPI, "not in-js-thread"); + auto loop = engine->GetUVLoop(); + if (loop == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__); + env = nullptr; + removeKey = nullptr; + return; + } + uv_work_t *work = new(std::nothrow) uv_work_t; + if (work == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr."); + return; + } + ConnectionCallback *data = new(std::nothrow) ConnectionCallback(std::move(*this)); + work->data = data; + auto ret = uv_queue_work(loop, work, [](uv_work_t*) {}, ClearCallbackWork); + if (ret != 0) { + TAG_LOGE(AAFwkTag::JSNAPI, "uv_queue_work failed: %{public}d", ret); + data->env = nullptr; + data->removeKey = nullptr; + delete data; + delete work; + } +} + +void NAPIAbilityConnection::AddConnectionCallback(std::shared_ptr callback) +{ + std::lock_guard guard(lock_); + callbacks_.emplace_back(callback); +} + +int NAPIAbilityConnection::GetConnectionState() const +{ + std::lock_guard guard(lock_); + return connectionState_; +} + +void NAPIAbilityConnection::SetConnectionState(int connectionState) +{ + std::lock_guard guard(lock_); + connectionState_ = connectionState; +} + +size_t NAPIAbilityConnection::GetCallbackSize() +{ + std::lock_guard guard(lock_); + return callbacks_.size(); +} + +size_t NAPIAbilityConnection::RemoveAllCallbacks(ConnectRemoveKeyType key) +{ + size_t result = 0; + std::lock_guard guard(lock_); + for (auto it = callbacks_.begin(); it != callbacks_.end();) { + auto callback = *it; + if (callback && callback->removeKey == key) { + it = callbacks_.erase(it); + result++; + } else { + ++it; + } + } + TAG_LOGI(AAFwkTag::JSNAPI, "RemoveAllCallbacks removed size:%{public}zu, left size:%{public}zu", result, + callbacks_.size()); + return result; +} + +void UvWorkOnAbilityConnectDone(uv_work_t *work, int status) +{ + TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work"); + std::unique_ptr managedWork(work); + if (work == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, work is null"); + return; + } + // JS Thread + std::unique_ptr connectAbilityCB(static_cast(work->data)); + if (connectAbilityCB == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, connectAbilityCB is null"); + return; + } + CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo; + napi_handle_scope scope = nullptr; + napi_open_handle_scope(cbInfo.env, &scope); + if (scope == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed"); + return; + } + + napi_value globalValue; + napi_get_global(cbInfo.env, &globalValue); + napi_value func; + napi_get_named_property(cbInfo.env, globalValue, "requireNapi", &func); + + napi_value rpcInfo; + napi_create_string_utf8(cbInfo.env, "rpc", NAPI_AUTO_LENGTH, &rpcInfo); + napi_value funcArgv[1] = { rpcInfo }; + napi_value returnValue; + napi_call_function(cbInfo.env, globalValue, func, 1, funcArgv, &returnValue); + + napi_value result[ARGS_TWO] = {nullptr}; + result[PARAM0] = + WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName); + napi_value jsRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject( + cbInfo.env, connectAbilityCB->abilityConnectionCB.connection); + result[PARAM1] = jsRemoteObject; + + napi_value callback = nullptr; + napi_value undefined = nullptr; + napi_get_undefined(cbInfo.env, &undefined); + napi_value callResult = nullptr; + napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback); + + napi_call_function( + cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); + if (cbInfo.callback != nullptr) { + napi_delete_reference(cbInfo.env, cbInfo.callback); + } + napi_close_handle_scope(cbInfo.env, scope); + TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work end"); +} + +void NAPIAbilityConnection::HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode) +{ + TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(callback.env, &loop); + if (loop == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == null.", __func__); + return; + } + + uv_work_t *work = new(std::nothrow) uv_work_t; + if (work == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, work == null.", __func__); + return; + } + + ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB; + if (connectAbilityCB == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == null.", __func__); + if (work != nullptr) { + delete work; + work = nullptr; + } + return; + } + connectAbilityCB->cbBase.cbInfo.env = callback.env; + connectAbilityCB->cbBase.cbInfo.callback = callback.connectCallbackRef; + callback.connectCallbackRef = nullptr; + connectAbilityCB->abilityConnectionCB.elementName = element_; + connectAbilityCB->abilityConnectionCB.resultCode = resultCode; + connectAbilityCB->abilityConnectionCB.connection = serviceRemoteObject_; + work->data = static_cast(connectAbilityCB); + + int rev = uv_queue_work_with_qos( + loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityConnectDone, uv_qos_user_initiated); + if (rev != 0) { + if (connectAbilityCB != nullptr) { + delete connectAbilityCB; + connectAbilityCB = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; + } + } +} + +void NAPIAbilityConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d", + __func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode); + if (remoteObject == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, remoteObject == nullptr.", __func__); + return; + } + std::lock_guard guard(lock_); + element_ = element; + serviceRemoteObject_ = remoteObject; + for (const auto &callback : callbacks_) { + HandleOnAbilityConnectDone(*callback, resultCode); + } + connectionState_ = CONNECTION_STATE_CONNECTED; + TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__); +} + +void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status) +{ + TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work"); + std::unique_ptr managedWork(work); + if (work == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, work is null"); + return; + } + // JS Thread + std::unique_ptr connectAbilityCB(static_cast(work->data)); + if (connectAbilityCB == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, connectAbilityCB is null"); + return; + } + CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo; + napi_handle_scope scope = nullptr; + napi_open_handle_scope(cbInfo.env, &scope); + if (scope == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed"); + return; + } + napi_value result = WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName); + if (cbInfo.callback != nullptr) { + napi_value callback = nullptr; + napi_value callResult = nullptr; + napi_value undefined = nullptr; + napi_get_undefined(cbInfo.env, &undefined); + napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback); + napi_call_function(cbInfo.env, undefined, callback, ARGS_ONE, &result, &callResult); + napi_delete_reference(cbInfo.env, cbInfo.callback); + cbInfo.callback = nullptr; + } + napi_close_handle_scope(cbInfo.env, scope); + + // release connect + std::lock_guard lock(g_connectionsLock_); + TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone connects_.size:%{public}zu", connects_.size()); + std::string deviceId = connectAbilityCB->abilityConnectionCB.elementName.GetDeviceID(); + std::string bundleName = connectAbilityCB->abilityConnectionCB.elementName.GetBundleName(); + std::string abilityName = connectAbilityCB->abilityConnectionCB.elementName.GetAbilityName(); + auto item = std::find_if(connects_.begin(), connects_.end(), + [deviceId, bundleName, abilityName](const std::map>::value_type &obj) { + return (deviceId == obj.first.want.GetDeviceId()) && + (bundleName == obj.first.want.GetBundle()) && + (abilityName == obj.first.want.GetElement().GetAbilityName()); + }); + if (item != connects_.end()) { + // match deviceid & bundlename && abilityname + connects_.erase(item); + TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone erase connects_.size:%{public}zu", connects_.size()); + } + TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work end"); +} + +void NAPIAbilityConnection::HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode) +{ + TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(callback.env, &loop); + if (loop == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__); + return; + } + + uv_work_t *work = new(std::nothrow) uv_work_t; + if (work == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr."); + return; + } + + ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB; + if (connectAbilityCB == nullptr) { + TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == nullptr.", __func__); + if (work != nullptr) { + delete work; + work = nullptr; + } + return; + } + + connectAbilityCB->cbBase.cbInfo.env = callback.env; + connectAbilityCB->cbBase.cbInfo.callback = callback.disconnectCallbackRef; + callback.disconnectCallbackRef = nullptr; + connectAbilityCB->abilityConnectionCB.elementName = element_; + connectAbilityCB->abilityConnectionCB.resultCode = resultCode; + work->data = static_cast(connectAbilityCB); + + int rev = uv_queue_work( + loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityDisconnectDone); + if (rev != 0) { + if (connectAbilityCB != nullptr) { + delete connectAbilityCB; + connectAbilityCB = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; + } + } +} + +void NAPIAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) +{ + TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d", + __func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode); + std::lock_guard guard(lock_); + element_ = element; + for (const auto &callback : callbacks_) { + HandleOnAbilityDisconnectDone(*callback, resultCode); + } + connectionState_ = CONNECTION_STATE_DISCONNECTED; + TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h b/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h index 3d9b5dd890..016b7f06e7 100644 --- a/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h +++ b/frameworks/js/napi/inner/napi_ability_common/js_napi_common_ability.h @@ -15,6 +15,8 @@ #ifndef OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H #define OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H + +#include "ability_connect_callback_stub.h" #include "ability_info.h" #include "ability_manager_errors.h" #include "application_info.h" @@ -143,6 +145,104 @@ public: Ability *ability_; sptr freeInstallObserver_ = nullptr; }; + +enum { + CONNECTION_STATE_DISCONNECTED = -1, + + CONNECTION_STATE_CONNECTED = 0, + + CONNECTION_STATE_CONNECTING = 1 +}; + +using ConnectRemoveKeyType = JsNapiCommon*; +struct ConnectionCallback { + ConnectionCallback(napi_env env, napi_value cbInfo, ConnectRemoveKeyType key) + { + this->env = env; + napi_value jsMethod = nullptr; + napi_get_named_property(env, cbInfo, "onConnect", &jsMethod); + napi_create_reference(env, jsMethod, 1, &connectCallbackRef); + napi_get_named_property(env, cbInfo, "onDisconnect", &jsMethod); + napi_create_reference(env, jsMethod, 1, &disconnectCallbackRef); + napi_get_named_property(env, cbInfo, "onFailed", &jsMethod); + napi_create_reference(env, jsMethod, 1, &failedCallbackRef); + removeKey = key; + } + ConnectionCallback(ConnectionCallback &) = delete; + ConnectionCallback(ConnectionCallback &&other) + : env(other.env), connectCallbackRef(other.connectCallbackRef), + disconnectCallbackRef(other.disconnectCallbackRef), failedCallbackRef(other.failedCallbackRef), + removeKey(other.removeKey) + { + other.env = nullptr; + other.connectCallbackRef = nullptr; + other.disconnectCallbackRef = nullptr; + other.failedCallbackRef = nullptr; + other.removeKey = nullptr; + } + const ConnectionCallback &operator=(ConnectionCallback &) = delete; + const ConnectionCallback &operator=(ConnectionCallback &&other) + { + Reset(); + env = other.env; + connectCallbackRef = other.connectCallbackRef; + disconnectCallbackRef = other.disconnectCallbackRef; + failedCallbackRef = other.failedCallbackRef; + other.env = nullptr; + other.connectCallbackRef = nullptr; + other.disconnectCallbackRef = nullptr; + other.failedCallbackRef = nullptr; + other.removeKey = nullptr; + return *this; + } + ~ConnectionCallback() + { + Reset(); + } + void Reset(); + + napi_env env = nullptr; + napi_ref connectCallbackRef = nullptr; + napi_ref disconnectCallbackRef = nullptr; + napi_ref failedCallbackRef = nullptr; + ConnectRemoveKeyType removeKey = nullptr; +}; + +class NAPIAbilityConnection : public AAFwk::AbilityConnectionStub { +public: + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + void AddConnectionCallback(std::shared_ptr callback); + void HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode); + void HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode); + int GetConnectionState() const; + void SetConnectionState(int connectionState); + size_t GetCallbackSize(); + size_t RemoveAllCallbacks(ConnectRemoveKeyType key); + +private: + std::list> callbacks_; + AppExecFwk::ElementName element_; + sptr serviceRemoteObject_ = nullptr; + int connectionState_ = CONNECTION_STATE_DISCONNECTED; + mutable std::mutex lock_; +}; + +struct ConnectionKey { + Want want; + int64_t id; +}; + +struct key_compare { + bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const + { + if (key1.id < key2.id) { + return true; + } + return false; + } +}; } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H diff --git a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp index 59eddfe129..dc188d8af5 100644 --- a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp @@ -1016,349 +1016,6 @@ napi_value NAPI_StopAbilityCommon(napi_env env, napi_callback_info info, Ability return ret; } -void ClearCallbackWork(uv_work_t* req, int) -{ - std::unique_ptr work(req); - if (!req) { - TAG_LOGE(AAFwkTag::JSNAPI, "work null"); - return; - } - std::unique_ptr callback(reinterpret_cast(req->data)); - if (!callback) { - TAG_LOGE(AAFwkTag::JSNAPI, "data null"); - return; - } - callback->Reset(); -} - -void ConnectionCallback::Reset() -{ - auto engine = reinterpret_cast(env); - if (engine == nullptr) { - removeKey = nullptr; - return; - } - if (pthread_self() == engine->GetTid()) { - TAG_LOGD(AAFwkTag::JSNAPI, "in-js-thread"); - if (connectCallbackRef) { - napi_delete_reference(env, connectCallbackRef); - connectCallbackRef = nullptr; - } - if (disconnectCallbackRef) { - napi_delete_reference(env, disconnectCallbackRef); - disconnectCallbackRef = nullptr; - } - if (failedCallbackRef) { - napi_delete_reference(env, failedCallbackRef); - failedCallbackRef = nullptr; - } - env = nullptr; - removeKey = nullptr; - return; - } - TAG_LOGI(AAFwkTag::JSNAPI, "not in-js-thread"); - auto loop = engine->GetUVLoop(); - if (loop == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__); - env = nullptr; - removeKey = nullptr; - return; - } - uv_work_t *work = new(std::nothrow) uv_work_t; - if (work == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr."); - return; - } - ConnectionCallback *data = new(std::nothrow) ConnectionCallback(std::move(*this)); - work->data = data; - auto ret = uv_queue_work(loop, work, [](uv_work_t*) {}, ClearCallbackWork); - if (ret != 0) { - TAG_LOGE(AAFwkTag::JSNAPI, "uv_queue_work failed: %{public}d", ret); - data->env = nullptr; - data->removeKey = nullptr; - delete data; - delete work; - } -} - -void NAPIAbilityConnection::AddConnectionCallback(std::shared_ptr callback) -{ - std::lock_guard guard(lock_); - callbacks_.emplace_back(callback); -} - -int NAPIAbilityConnection::GetConnectionState() const -{ - std::lock_guard guard(lock_); - return connectionState_; -} - -void NAPIAbilityConnection::SetConnectionState(int connectionState) -{ - std::lock_guard guard(lock_); - connectionState_ = connectionState; -} - -size_t NAPIAbilityConnection::GetCallbackSize() -{ - std::lock_guard guard(lock_); - return callbacks_.size(); -} - -size_t NAPIAbilityConnection::RemoveAllCallbacks(ConnectRemoveKeyType key) -{ - size_t result = 0; - std::lock_guard guard(lock_); - for (auto it = callbacks_.begin(); it != callbacks_.end();) { - auto callback = *it; - if (callback && callback->removeKey == key) { - it = callbacks_.erase(it); - result++; - } else { - ++it; - } - } - TAG_LOGI(AAFwkTag::JSNAPI, "RemoveAllCallbacks removed size:%{public}zu, left size:%{public}zu", result, - callbacks_.size()); - return result; -} - -void UvWorkOnAbilityConnectDone(uv_work_t *work, int status) -{ - TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work"); - std::unique_ptr managedWork(work); - if (work == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, work is null"); - return; - } - // JS Thread - std::unique_ptr connectAbilityCB(static_cast(work->data)); - if (connectAbilityCB == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, connectAbilityCB is null"); - return; - } - CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo; - napi_handle_scope scope = nullptr; - napi_open_handle_scope(cbInfo.env, &scope); - if (scope == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed"); - return; - } - - napi_value globalValue; - napi_get_global(cbInfo.env, &globalValue); - napi_value func; - napi_get_named_property(cbInfo.env, globalValue, "requireNapi", &func); - - napi_value rpcInfo; - napi_create_string_utf8(cbInfo.env, "rpc", NAPI_AUTO_LENGTH, &rpcInfo); - napi_value funcArgv[1] = { rpcInfo }; - napi_value returnValue; - napi_call_function(cbInfo.env, globalValue, func, 1, funcArgv, &returnValue); - - napi_value result[ARGS_TWO] = {nullptr}; - result[PARAM0] = - WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName); - napi_value jsRemoteObject = NAPI_ohos_rpc_CreateJsRemoteObject( - cbInfo.env, connectAbilityCB->abilityConnectionCB.connection); - result[PARAM1] = jsRemoteObject; - - napi_value callback = nullptr; - napi_value undefined = nullptr; - napi_get_undefined(cbInfo.env, &undefined); - napi_value callResult = nullptr; - napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback); - - napi_call_function( - cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); - if (cbInfo.callback != nullptr) { - napi_delete_reference(cbInfo.env, cbInfo.callback); - } - napi_close_handle_scope(cbInfo.env, scope); - TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityConnectDone, uv_queue_work end"); -} - -void NAPIAbilityConnection::HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode) -{ - TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(callback.env, &loop); - if (loop == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == null.", __func__); - return; - } - - uv_work_t *work = new(std::nothrow) uv_work_t; - if (work == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, work == null.", __func__); - return; - } - - ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB; - if (connectAbilityCB == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == null.", __func__); - if (work != nullptr) { - delete work; - work = nullptr; - } - return; - } - connectAbilityCB->cbBase.cbInfo.env = callback.env; - connectAbilityCB->cbBase.cbInfo.callback = callback.connectCallbackRef; - callback.connectCallbackRef = nullptr; - connectAbilityCB->abilityConnectionCB.elementName = element_; - connectAbilityCB->abilityConnectionCB.resultCode = resultCode; - connectAbilityCB->abilityConnectionCB.connection = serviceRemoteObject_; - work->data = static_cast(connectAbilityCB); - - int rev = uv_queue_work_with_qos( - loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityConnectDone, uv_qos_user_initiated); - if (rev != 0) { - if (connectAbilityCB != nullptr) { - delete connectAbilityCB; - connectAbilityCB = nullptr; - } - if (work != nullptr) { - delete work; - work = nullptr; - } - } -} - -void NAPIAbilityConnection::OnAbilityConnectDone( - const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) -{ - TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d", - __func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode); - if (remoteObject == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, remoteObject == nullptr.", __func__); - return; - } - std::lock_guard guard(lock_); - element_ = element; - serviceRemoteObject_ = remoteObject; - for (const auto &callback : callbacks_) { - HandleOnAbilityConnectDone(*callback, resultCode); - } - connectionState_ = CONNECTION_STATE_CONNECTED; - TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__); -} - -void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status) -{ - TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work"); - std::unique_ptr managedWork(work); - if (work == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, work is null"); - return; - } - // JS Thread - std::unique_ptr connectAbilityCB(static_cast(work->data)); - if (connectAbilityCB == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, connectAbilityCB is null"); - return; - } - CallbackInfo &cbInfo = connectAbilityCB->cbBase.cbInfo; - napi_handle_scope scope = nullptr; - napi_open_handle_scope(cbInfo.env, &scope); - if (scope == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "napi_open_handle_scope failed"); - return; - } - napi_value result = WrapElementName(cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName); - if (cbInfo.callback != nullptr) { - napi_value callback = nullptr; - napi_value callResult = nullptr; - napi_value undefined = nullptr; - napi_get_undefined(cbInfo.env, &undefined); - napi_get_reference_value(cbInfo.env, cbInfo.callback, &callback); - napi_call_function(cbInfo.env, undefined, callback, ARGS_ONE, &result, &callResult); - napi_delete_reference(cbInfo.env, cbInfo.callback); - cbInfo.callback = nullptr; - } - napi_close_handle_scope(cbInfo.env, scope); - - // release connect - std::lock_guard lock(g_connectionsLock_); - TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone connects_.size:%{public}zu", connects_.size()); - std::string deviceId = connectAbilityCB->abilityConnectionCB.elementName.GetDeviceID(); - std::string bundleName = connectAbilityCB->abilityConnectionCB.elementName.GetBundleName(); - std::string abilityName = connectAbilityCB->abilityConnectionCB.elementName.GetAbilityName(); - auto item = std::find_if(connects_.begin(), connects_.end(), - [deviceId, bundleName, abilityName](const std::map>::value_type &obj) { - return (deviceId == obj.first.want.GetDeviceId()) && - (bundleName == obj.first.want.GetBundle()) && - (abilityName == obj.first.want.GetElement().GetAbilityName()); - }); - if (item != connects_.end()) { - // match deviceid & bundlename && abilityname - connects_.erase(item); - TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone erase connects_.size:%{public}zu", connects_.size()); - } - TAG_LOGI(AAFwkTag::JSNAPI, "UvWorkOnAbilityDisconnectDone, uv_queue_work end"); -} - -void NAPIAbilityConnection::HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode) -{ - TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s called.", __func__); - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(callback.env, &loop); - if (loop == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, loop == nullptr.", __func__); - return; - } - - uv_work_t *work = new(std::nothrow) uv_work_t; - if (work == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "work == nullptr."); - return; - } - - ConnectAbilityCB *connectAbilityCB = new (std::nothrow) ConnectAbilityCB; - if (connectAbilityCB == nullptr) { - TAG_LOGE(AAFwkTag::JSNAPI, "%{public}s, connectAbilityCB == nullptr.", __func__); - if (work != nullptr) { - delete work; - work = nullptr; - } - return; - } - - connectAbilityCB->cbBase.cbInfo.env = callback.env; - connectAbilityCB->cbBase.cbInfo.callback = callback.disconnectCallbackRef; - callback.disconnectCallbackRef = nullptr; - connectAbilityCB->abilityConnectionCB.elementName = element_; - connectAbilityCB->abilityConnectionCB.resultCode = resultCode; - work->data = static_cast(connectAbilityCB); - - int rev = uv_queue_work( - loop, work, [](uv_work_t *work) {}, UvWorkOnAbilityDisconnectDone); - if (rev != 0) { - if (connectAbilityCB != nullptr) { - delete connectAbilityCB; - connectAbilityCB = nullptr; - } - if (work != nullptr) { - delete work; - work = nullptr; - } - } -} - -void NAPIAbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) -{ - TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s bundleName:%{public}s abilityName:%{public}s, resultCode:%{public}d", - __func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str(), resultCode); - std::lock_guard guard(lock_); - element_ = element; - for (const auto &callback : callbacks_) { - HandleOnAbilityDisconnectDone(*callback, resultCode); - } - connectionState_ = CONNECTION_STATE_DISCONNECTED; - TAG_LOGI(AAFwkTag::JSNAPI, "%{public}s, end.", __func__); -} - /** * @brief AcquireDataAbilityHelper. * diff --git a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.h b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.h index 575aa293d3..3414e119c4 100644 --- a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.h +++ b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.h @@ -20,7 +20,6 @@ #include #include -#include "ability_connect_callback_stub.h" #include "ability_info.h" #include "ability_manager_errors.h" #include "application_info.h" @@ -167,90 +166,6 @@ napi_value NAPI_GetAbilityNameCommon(napi_env env, napi_callback_info info, Abil */ napi_value NAPI_StopAbilityCommon(napi_env env, napi_callback_info info, AbilityType abilityType); -enum { - CONNECTION_STATE_DISCONNECTED = -1, - - CONNECTION_STATE_CONNECTED = 0, - - CONNECTION_STATE_CONNECTING = 1 -}; - -class JsNapiCommon; -using ConnectRemoveKeyType = JsNapiCommon*; -struct ConnectionCallback { - ConnectionCallback(napi_env env, napi_value cbInfo, ConnectRemoveKeyType key) - { - this->env = env; - napi_value jsMethod = nullptr; - napi_get_named_property(env, cbInfo, "onConnect", &jsMethod); - napi_create_reference(env, jsMethod, 1, &connectCallbackRef); - napi_get_named_property(env, cbInfo, "onDisconnect", &jsMethod); - napi_create_reference(env, jsMethod, 1, &disconnectCallbackRef); - napi_get_named_property(env, cbInfo, "onFailed", &jsMethod); - napi_create_reference(env, jsMethod, 1, &failedCallbackRef); - removeKey = key; - } - ConnectionCallback(ConnectionCallback &) = delete; - ConnectionCallback(ConnectionCallback &&other) - : env(other.env), connectCallbackRef(other.connectCallbackRef), - disconnectCallbackRef(other.disconnectCallbackRef), failedCallbackRef(other.failedCallbackRef), - removeKey(other.removeKey) - { - other.env = nullptr; - other.connectCallbackRef = nullptr; - other.disconnectCallbackRef = nullptr; - other.failedCallbackRef = nullptr; - other.removeKey = nullptr; - } - const ConnectionCallback &operator=(ConnectionCallback &) = delete; - const ConnectionCallback &operator=(ConnectionCallback &&other) - { - Reset(); - env = other.env; - connectCallbackRef = other.connectCallbackRef; - disconnectCallbackRef = other.disconnectCallbackRef; - failedCallbackRef = other.failedCallbackRef; - other.env = nullptr; - other.connectCallbackRef = nullptr; - other.disconnectCallbackRef = nullptr; - other.failedCallbackRef = nullptr; - other.removeKey = nullptr; - return *this; - } - ~ConnectionCallback() - { - Reset(); - } - void Reset(); - - napi_env env = nullptr; - napi_ref connectCallbackRef = nullptr; - napi_ref disconnectCallbackRef = nullptr; - napi_ref failedCallbackRef = nullptr; - ConnectRemoveKeyType removeKey = nullptr; -}; - -class NAPIAbilityConnection : public AAFwk::AbilityConnectionStub { -public: - void OnAbilityConnectDone( - const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; - void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; - void AddConnectionCallback(std::shared_ptr callback); - void HandleOnAbilityConnectDone(ConnectionCallback &callback, int resultCode); - void HandleOnAbilityDisconnectDone(ConnectionCallback &callback, int resultCode); - int GetConnectionState() const; - void SetConnectionState(int connectionState); - size_t GetCallbackSize(); - size_t RemoveAllCallbacks(ConnectRemoveKeyType key); - -private: - std::list> callbacks_; - AppExecFwk::ElementName element_; - sptr serviceRemoteObject_ = nullptr; - int connectionState_ = CONNECTION_STATE_DISCONNECTED; - mutable std::mutex lock_; -}; - /** * @brief acquireDataAbilityHelper processing function. * @@ -294,23 +209,6 @@ napi_value NAPI_StartBackgroundRunningCommon(napi_env env, napi_callback_info in */ napi_value NAPI_CancelBackgroundRunningCommon(napi_env env, napi_callback_info info); -struct ConnectionKey { - Want want; - int64_t id; -}; - -struct key_compare { - bool operator()(const ConnectionKey &key1, const ConnectionKey &key2) const - { - if (key1.id < key2.id) { - return true; - } - return false; - } -}; -static std::map, key_compare> connects_; -static std::mutex g_connectionsLock_; -static int64_t serialNumber_ = 0; enum ErrorCode { NO_ERROR = 0, INVALID_PARAMETER = -1, From 50eebadc1b22755ed436897189ecbb7aa5a12165 Mon Sep 17 00:00:00 2001 From: liweifeng Date: Sat, 22 Jun 2024 15:11:09 +0800 Subject: [PATCH 038/148] =?UTF-8?q?uiextension=E6=89=A9=E5=B1=95=E4=B8=BA?= =?UTF-8?q?=E4=B8=89=E7=A7=8D=E7=94=A8=E9=80=94=EF=BC=8CMODAL=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E5=BA=94=E7=94=A8=E5=8F=AF=E4=BD=BF=E7=94=A8=EF=BC=8C?= =?UTF-8?q?EMBEDDED=E7=B3=BB=E7=BB=9F=E5=BA=94=E7=94=A8=E5=8F=AF=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=EF=BC=8CCONSTRAINED=5FEMBEDDED=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=8F=AF=E4=BD=BF=E7=94=A8=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liweifeng Change-Id: Id53629e598aa4f70f59f78478d8fa81d87464ff7 --- .../ability_manager_ipc_interface_code.h | 7 ++-- .../include/ability_manager_service.h | 3 ++ .../abilitymgr/include/ability_manager_stub.h | 3 +- .../abilitymgr/src/ability_manager_proxy.cpp | 8 +++-- .../src/ability_manager_service.cpp | 23 ++++++++++-- .../abilitymgr/src/ability_manager_stub.cpp | 35 ++++++++++++++++--- services/common/include/ui_extension_utils.h | 15 ++++++-- .../ability_manager_stub_test.cpp | 32 +++++++++++++++++ 8 files changed, 109 insertions(+), 17 deletions(-) diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index ac9f5fd75b..b1df9a4286 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -395,8 +395,11 @@ enum class AbilityManagerInterfaceCode { // ipc id for preload UIExtension ability by want PRELOAD_UIEXTENSION_ABILITY = 1062, - // ipc id for start UIExtension ability non—modal - START_UI_EXTENSION_ABILITY_NON_MODAL = 1063, + // ipc id for start UIExtension ability embedded + START_UI_EXTENSION_ABILITY_EMBEDDED = 1063, + + // ipc id for start UIExtension ability constrained embedded + START_UI_EXTENSION_CONSTRAINED_EMBEDDED = 1064, // ipc id for continue ability(1101) START_CONTINUATION = 1101, diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index b5fb6e0399..9e93570c25 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2152,6 +2152,9 @@ private: void GetRunningMultiAppIndex(const std::string &bundleName, int32_t uid, int32_t &appIndex); + int CheckUIExtensionUsage(AppExecFwk::UIExtensionUsage uiExtensionUsage, + AppExecFwk::ExtensionAbilityType extensionType); + constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index b2e56e3768..e0f2423669 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -93,7 +93,8 @@ private: int StartAbilityAsCallerForOptionInner(MessageParcel &data, MessageParcel &reply); int StartExtensionAbilityInner(MessageParcel &data, MessageParcel &reply); int StartUIExtensionAbilityInner(MessageParcel &data, MessageParcel &reply); - int StartUIExtensionAbilityNonModalInner(MessageParcel &data, MessageParcel &reply); + int StartUIExtensionAbilityEmbeddedInner(MessageParcel &data, MessageParcel &reply); + int StartUIExtensionConstrainedEmbeddedInner(MessageParcel &data, MessageParcel &reply); int StartUIAbilityBySCBInner(MessageParcel &data, MessageParcel &reply); int StopExtensionAbilityInner(MessageParcel& data, MessageParcel& reply); int StartAbilityAddCallerInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 2043acb848..a6a564f639 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -750,10 +750,12 @@ int AbilityManagerProxy::StartUIExtensionAbility(const sptr &extens return INNER_ERR; } - if (!extensionSessionInfo->isModal) { - error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_NON_MODAL, data, reply, option); - } else { + if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::EMBEDDED) { + error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_EMBEDDED, data, reply, option); + } else if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::MODAL) { error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY, data, reply, option); + } else { + error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_CONSTRAINED_EMBEDDED, data, reply, option); } if (error != NO_ERROR) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index ef821fcb45..5f98ac5b62 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2716,6 +2716,22 @@ void AbilityManagerService::SetAutoFillElementName(const sptr &exte extensionSessionInfo->want.SetModuleName(argList[INDEX_ONE]); } +int AbilityManagerService::CheckUIExtensionUsage(AppExecFwk::UIExtensionUsage uiExtensionUsage, + AppExecFwk::ExtensionAbilityType extensionType) +{ + if (uiExtensionUsage == UIExtensionUsage::EMBEDDED && + !AAFwk::UIExtensionUtils::IsPublicForEmbedded(extensionType)) { + CHECK_CALLER_IS_SYSTEM_APP; + } + + if (uiExtensionUsage == UIExtensionUsage::CONSTRAINED_EMBEDDED && + !AAFwk::UIExtensionUtils::IsPublicForConstrainedEmbedded(extensionType)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "error extension type %u for SecureConstrainedEmbedded.", extensionType); + return ERR_INVALID_VALUE; + } + return ERR_OK; +} + int AbilityManagerService::StartUIExtensionAbility(const sptr &extensionSessionInfo, int32_t userId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -2757,9 +2773,10 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte EventInfo eventInfo = BuildEventInfo(extensionSessionInfo->want, userId); eventInfo.extensionType = static_cast(extensionType); - // non-modal uiextension can only be used by system applications. - if (!extensionSessionInfo->isModal && !AAFwk::UIExtensionUtils::IsPublicCallerForNonModal(extensionType)) { - CHECK_CALLER_IS_SYSTEM_APP; + auto ret = CheckUIExtensionUsage(extensionSessionInfo->uiExtensionUsage, extensionType); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "check usage failed."); + return ret; } if (InsightIntentExecuteParam::IsInsightIntentExecute(extensionSessionInfo->want)) { diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 7bce7122c0..5528dbaaa0 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -606,8 +606,11 @@ int AbilityManagerStub::OnRemoteRequestInnerSixteenth(uint32_t code, MessageParc if (interfaceCode == AbilityManagerInterfaceCode::COMPLETE_FIRST_FRAME_DRAWING_BY_SCB) { return CompleteFirstFrameDrawingBySCBInner(data, reply); } - if (interfaceCode == AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_NON_MODAL) { - return StartUIExtensionAbilityNonModalInner(data, reply); + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_EMBEDDED) { + return StartUIExtensionAbilityEmbeddedInner(data, reply); + } + if (interfaceCode == AbilityManagerInterfaceCode::START_UI_EXTENSION_CONSTRAINED_EMBEDDED) { + return StartUIExtensionConstrainedEmbeddedInner(data, reply); } #endif if (interfaceCode == AbilityManagerInterfaceCode::REQUEST_DIALOG_SERVICE) { @@ -1330,7 +1333,8 @@ int AbilityManagerStub::StartUIExtensionAbilityInner(MessageParcel &data, Messag TAG_LOGE(AAFwkTag::ABILITYMGR, "read extensionSessionInfo failed."); return ERR_NULL_OBJECT; } - extensionSessionInfo->isModal = true; // To ensure security, this attribute must be rewritten. + // To ensure security, this attribute must be rewritten. + extensionSessionInfo->uiExtensionUsage = UIExtensionUsage::MODAL; } int32_t userId = data.ReadInt32(); @@ -1340,7 +1344,7 @@ int AbilityManagerStub::StartUIExtensionAbilityInner(MessageParcel &data, Messag return NO_ERROR; } -int AbilityManagerStub::StartUIExtensionAbilityNonModalInner(MessageParcel &data, MessageParcel &reply) +int AbilityManagerStub::StartUIExtensionAbilityEmbeddedInner(MessageParcel &data, MessageParcel &reply) { sptr extensionSessionInfo = nullptr; if (data.ReadBool()) { @@ -1349,7 +1353,28 @@ int AbilityManagerStub::StartUIExtensionAbilityNonModalInner(MessageParcel &data TAG_LOGE(AAFwkTag::ABILITYMGR, "read extensionSessionInfo failed."); return ERR_NULL_OBJECT; } - extensionSessionInfo->isModal = false; // To ensure security, this attribute must be rewritten. + // To ensure security, this attribute must be rewritten. + extensionSessionInfo->uiExtensionUsage = UIExtensionUsage::EMBEDDED; + } + + int32_t userId = data.ReadInt32(); + + int32_t result = StartUIExtensionAbility(extensionSessionInfo, userId); + reply.WriteInt32(result); + return NO_ERROR; +} + +int AbilityManagerStub::StartUIExtensionConstrainedEmbeddedInner(MessageParcel &data, MessageParcel &reply) +{ + sptr extensionSessionInfo = nullptr; + if (data.ReadBool()) { + extensionSessionInfo = data.ReadParcelable(); + if (extensionSessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "read extensionSessionInfo failed."); + return ERR_NULL_OBJECT; + } + // To ensure security, this attribute must be rewritten. + extensionSessionInfo->uiExtensionUsage = UIExtensionUsage::CONSTRAINED_EMBEDDED; } int32_t userId = data.ReadInt32(); diff --git a/services/common/include/ui_extension_utils.h b/services/common/include/ui_extension_utils.h index 074aee322e..cce0630672 100755 --- a/services/common/include/ui_extension_utils.h +++ b/services/common/include/ui_extension_utils.h @@ -120,14 +120,23 @@ inline bool IsSystemCallerNeeded(const AppExecFwk::ExtensionAbilityType type) } // In this collection, extension can be embedded by public app, which requires vertical businesses to ensure security. -inline bool IsPublicCallerForNonModal(const AppExecFwk::ExtensionAbilityType type) +inline bool IsPublicForEmbedded(const AppExecFwk::ExtensionAbilityType type) { - const std::unordered_set callerPublicForNonModalSet = { + const std::unordered_set publicForEmbeddedSet = { AppExecFwk::ExtensionAbilityType::EMBEDDED_UI, // EMBEDDED_UI usage within the app AppExecFwk::ExtensionAbilityType::ADS, AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER }; - return callerPublicForNonModalSet.find(type) != callerPublicForNonModalSet.end(); + return publicForEmbeddedSet.find(type) != publicForEmbeddedSet.end(); +} + +// In this collection, extension can be embedded by public app, which some UX effects are constrained +inline bool IsPublicForConstrainedEmbedded(const AppExecFwk::ExtensionAbilityType type) +{ + const std::unordered_set publicForConstrainedEmbeddedSet = { + AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER + }; + return publicForConstrainedEmbeddedSet.find(type) != publicForConstrainedEmbeddedSet.end(); } inline bool IsEnterpriseAdmin(const AppExecFwk::ExtensionAbilityType type) diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp index bd799c1388..6c22c87842 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp @@ -978,6 +978,38 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartUIExtensionAbilityInner EXPECT_EQ(res, NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: StartUIExtensionAbilityEmbeddedInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIExtensionAbilityEmbeddedInner + * EnvConditions: NA + * CaseDescription: Verify the function StartUIExtensionAbilityEmbeddedInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartUIExtensionAbilityEmbeddedInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->StartUIExtensionAbilityEmbeddedInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + +/* + * Feature: AbilityManagerService + * Function: StartUIExtensionConstrainedEmbeddedInner + * SubFunction: NA + * FunctionPoints: AbilityManagerService StartUIExtensionConstrainedEmbeddedInner + * EnvConditions: NA + * CaseDescription: Verify the function StartUIExtensionConstrainedEmbeddedInner is normal flow. + */ +HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_StartUIExtensionConstrainedEmbeddedInner_001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + auto res = stub_->StartUIExtensionConstrainedEmbeddedInner(data, reply); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: StopExtensionAbilityInner From ba977ee5cd4889832f0483dc7afcbe9ff5c08d09 Mon Sep 17 00:00:00 2001 From: fangting Date: Tue, 18 Jun 2024 20:29:56 +0800 Subject: [PATCH 039/148] fix arkts no data Signed-off-by: fangting --- .../native/runtime/connect_server_manager.cpp | 108 ++++++------------ .../native/runtime/connect_server_manager.h | 2 + frameworks/native/runtime/js_runtime.cpp | 8 +- .../js_environment/src/js_environment.cpp | 15 +-- .../interfaces/inner_api/js_environment.h | 2 +- .../js_environment_test.cpp | 4 +- 6 files changed, 45 insertions(+), 94 deletions(-) diff --git a/frameworks/native/runtime/connect_server_manager.cpp b/frameworks/native/runtime/connect_server_manager.cpp index 696c52bd92..300c5e0d3a 100644 --- a/frameworks/native/runtime/connect_server_manager.cpp +++ b/frameworks/native/runtime/connect_server_manager.cpp @@ -173,17 +173,13 @@ void ConnectServerManager::SendDebuggerInfo(bool needBreakPoint, bool isDebugApp panda::EcmaVM* vm = reinterpret_cast(g_debuggerInfo[tid].first); std::lock_guard lock(g_debuggerMutex); - const auto &debuggerPoskTask = g_debuggerInfo[tid].second; - if (!debuggerPoskTask) { + const auto &debuggerPostTask = g_debuggerInfo[tid].second; + if (!debuggerPostTask) { continue; } ConnectServerManager::Get().SendInstanceMessage(tid, instanceId, instanceName); - auto storeDebugInfoTask = [needBreakPoint, isDebugApp, instanceId, vm, debuggerPoskTask, instanceName]() { - panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, isDebugApp ? needBreakPoint : false}; - panda::JSNApi::StoreDebugInfo(getproctid(), vm, debugOption, debuggerPoskTask, isDebugApp); - }; - - debuggerPoskTask(storeDebugInfoTask); + panda::JSNApi::DebugOption debugOption = {ARK_DEBUGGER_LIB_PATH, isDebugApp ? needBreakPoint : false}; + panda::JSNApi::StoreDebugInfo(tid, vm, debugOption, debuggerPostTask, isDebugApp); } } @@ -204,33 +200,15 @@ void ConnectServerManager::SetConnectedCallback() }); } -bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId, const std::string& instanceName) +void ConnectServerManager::SetSwitchCallback(int32_t instanceId) { - TAG_LOGI(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage Add instance to connect server"); LoadConnectServerDebuggerSo(); - auto setSwitchCallBack = reinterpret_cast( - dlsym(handlerConnectServerSo_, "SetSwitchCallBack")); + dlsym(handlerConnectServerSo_, "SetSwitchCallBack")); if (setSwitchCallBack == nullptr) { - TAG_LOGI( - AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'setSwitchCallBack'"); - return false; + TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::AddInstance failed to find symbol 'setSwitchCallBack'"); + return; } - - auto storeMessage = reinterpret_cast(dlsym(handlerConnectServerSo_, "StoreMessage")); - if (storeMessage == nullptr) { - TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'StoreMessage'"); - return false; - } - - auto setProfilerCallback = reinterpret_cast( - dlsym(handlerConnectServerSo_, "SetProfilerCallback")); - if (setProfilerCallback == nullptr) { - TAG_LOGI(AAFwkTag::JSRUNTIME, - "ConnectServerManager::SendInstanceMessage failed to find symbol 'setProfilerCallback'"); - return false; - } - setSwitchCallBack( [this](bool status) { if (setStatus_ != nullptr) { @@ -246,7 +224,18 @@ bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId, TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::createLayoutInfo_ is nullptr"); } }, instanceId); - +} + +void ConnectServerManager::SetProfilerCallBack() +{ + LoadConnectServerDebuggerSo(); + auto setProfilerCallback = reinterpret_cast( + dlsym(handlerConnectServerSo_, "SetProfilerCallback")); + if (setProfilerCallback == nullptr) { + TAG_LOGE(AAFwkTag::JSRUNTIME, + "ConnectServerManager::AddInstance failed to find symbol 'setProfilerCallback'"); + return; + } setProfilerCallback([this](bool status) { if (setArkUIStateProfilerStatus_ != nullptr) { setArkUIStateProfilerStatus_(status); @@ -254,14 +243,25 @@ bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId, TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::setArkUIStateProfilerStatus_ is nullptr"); } }); +} +bool ConnectServerManager::SendInstanceMessage(int32_t tid, int32_t instanceId, const std::string& instanceName) +{ + TAG_LOGI(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage Add instance to connect server"); + ConnectServerManager::Get().SetSwitchCallback(instanceId); + ConnectServerManager::Get().SetProfilerCallBack(); std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName, tid); + LoadConnectServerDebuggerSo(); + auto storeMessage = reinterpret_cast(dlsym(handlerConnectServerSo_, "StoreMessage")); + if (storeMessage == nullptr) { + TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::SendInstanceMessage failed to find symbol 'StoreMessage'"); + return false; + } storeMessage(instanceId, message); - return true; } - + bool ConnectServerManager::AddInstance(int32_t tid, int32_t instanceId, const std::string& instanceName) { { @@ -280,46 +280,10 @@ bool ConnectServerManager::AddInstance(int32_t tid, int32_t instanceId, const st } TAG_LOGD(AAFwkTag::JSRUNTIME, "ConnectServerManager::AddInstance Add instance to connect server"); + + ConnectServerManager::Get().SetSwitchCallback(instanceId); + ConnectServerManager::Get().SetProfilerCallBack(); LoadConnectServerDebuggerSo(); - - auto setSwitchCallBack = reinterpret_cast( - dlsym(handlerConnectServerSo_, "SetSwitchCallBack")); - if (setSwitchCallBack == nullptr) { - TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::AddInstance failed to find symbol 'setSwitchCallBack'"); - return false; - } - setSwitchCallBack( - [this](bool status) { - if (setStatus_ != nullptr) { - setStatus_(status); - } else { - TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::setStatus_ is nullptr"); - } - }, - [this](int32_t containerId) { - if (createLayoutInfo_ != nullptr) { - createLayoutInfo_(containerId); - } else { - TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::createLayoutInfo_ is nullptr"); - } - }, instanceId); - - auto setProfilerCallback = reinterpret_cast( - dlsym(handlerConnectServerSo_, "SetProfilerCallback")); - if (setProfilerCallback == nullptr) { - TAG_LOGE(AAFwkTag::JSRUNTIME, - "ConnectServerManager::AddInstance failed to find symbol 'setProfilerCallback'"); - return false; - } - - setProfilerCallback([this](bool status) { - if (setArkUIStateProfilerStatus_ != nullptr) { - setArkUIStateProfilerStatus_(status); - } else { - TAG_LOGE(AAFwkTag::JSRUNTIME, "ConnectServerManager::setArkUIStateProfilerStatus_ is nullptr"); - } - }); - // Get the message including information of new instance, which will be send to IDE. std::string message = GetInstanceMapMessage("addInstance", instanceId, instanceName, tid); diff --git a/frameworks/native/runtime/connect_server_manager.h b/frameworks/native/runtime/connect_server_manager.h index a4dd6a9a4d..0601c4b125 100644 --- a/frameworks/native/runtime/connect_server_manager.h +++ b/frameworks/native/runtime/connect_server_manager.h @@ -53,6 +53,8 @@ public: void SendDebuggerInfo(bool needBreakPoint, bool isDebugApp); void LoadConnectServerDebuggerSo(); DebuggerPostTask GetDebuggerPostTask(int32_t tid); + void SetSwitchCallback(int32_t instanceId); + void SetProfilerCallBack(); private: ConnectServerManager() = default; diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 0c9bd45850..9e190d33f4 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -283,9 +283,7 @@ void JsRuntime::StartDebugMode(const DebugOption dOption) if (isDebugApp) { weak->StopDebugger(option); } - int32_t tid = weak->ParseHdcRegisterOption(option); - const auto &debuggerPostTask = ConnectServerManager::Get().GetDebuggerPostTask(tid); - weak->StartDebugger(option, socketFd, isDebugApp, debuggerPostTask); + weak->StartDebugger(option, socketFd, isDebugApp); } }); if (isDebugApp) { @@ -411,9 +409,7 @@ void JsRuntime::StartProfiler(const DebugOption dOption) if (isDebugApp) { weak->StopDebugger(option); } - int32_t tid = weak->ParseHdcRegisterOption(option); - const auto &debuggerPostTask = ConnectServerManager::Get().GetDebuggerPostTask(tid); - weak->StartDebugger(option, socketFd, isDebugApp, debuggerPostTask); + weak->StartDebugger(option, socketFd, isDebugApp); } }); if (isDebugApp) { diff --git a/js_environment/frameworks/js_environment/src/js_environment.cpp b/js_environment/frameworks/js_environment/src/js_environment.cpp index 6c4f1a90cf..0b8062168b 100644 --- a/js_environment/frameworks/js_environment/src/js_environment.cpp +++ b/js_environment/frameworks/js_environment/src/js_environment.cpp @@ -182,7 +182,7 @@ bool JsEnvironment::LoadScript(const std::string& path, std::vector* bu } bool JsEnvironment::StartDebugger( - std::string& option, uint32_t socketFd, bool isDebugApp, const DebuggerPostTask &debuggerPostTask) + std::string& option, uint32_t socketFd, bool isDebugApp) { TAG_LOGD(AAFwkTag::JSENV, "call."); if (vm_ == nullptr) { @@ -194,18 +194,7 @@ bool JsEnvironment::StartDebugger( TAG_LOGE(AAFwkTag::JSENV, "Abnormal parsing of tid results."); return false; } - if (isDebugApp) { - debugMode_ = panda::JSNApi::StartDebuggerForSocketPair(identifierId, socketFd); - } else { - if (debuggerPostTask == nullptr) { - TAG_LOGE(AAFwkTag::JSENV, "debuggerPostTask is nullptr."); - return false; - } - auto startDebuggerForSocketPairTask = [identifierId, socketFd, this]() { - debugMode_ = panda::JSNApi::StartDebuggerForSocketPair(identifierId, socketFd); - }; - debuggerPostTask(startDebuggerForSocketPairTask); - } + debugMode_ = panda::JSNApi::StartDebuggerForSocketPair(identifierId, socketFd); return debugMode_; } diff --git a/js_environment/interfaces/inner_api/js_environment.h b/js_environment/interfaces/inner_api/js_environment.h index d5b8eb9a9c..b71140e4f9 100644 --- a/js_environment/interfaces/inner_api/js_environment.h +++ b/js_environment/interfaces/inner_api/js_environment.h @@ -77,7 +77,7 @@ public: bool LoadScript(const std::string& path, std::vector* buffer = nullptr, bool isBundle = false); bool StartDebugger( - std::string& option, uint32_t socketFd, bool isDebugApp, const DebuggerPostTask &debuggerPostTask); + std::string& option, uint32_t socketFd, bool isDebugApp); void StopDebugger(); diff --git a/js_environment/test/unittest/js_environment_test/js_environment_test.cpp b/js_environment/test/unittest/js_environment_test/js_environment_test.cpp index 9e2611e4a8..5e74cb5656 100644 --- a/js_environment/test/unittest/js_environment_test/js_environment_test.cpp +++ b/js_environment/test/unittest/js_environment_test/js_environment_test.cpp @@ -235,7 +235,7 @@ HWTEST_F(JsEnvironmentTest, StartDebugger_0100, TestSize.Level0) std::string option = "ark:1234@Debugger"; uint32_t socketFd = 10; bool isDebugApp = true; - bool result = jsEnv->StartDebugger(option, socketFd, isDebugApp, jsEnv->GetDebuggerPostTask()); + bool result = jsEnv->StartDebugger(option, socketFd, isDebugApp); ASSERT_EQ(result, false); } @@ -256,7 +256,7 @@ HWTEST_F(JsEnvironmentTest, StartDebugger_0200, TestSize.Level0) std::string option = "ark:1234@Debugger"; uint32_t socketFd = 10; bool isDebugApp = true; - bool result = jsEnv->StartDebugger(option, socketFd, isDebugApp, jsEnv->GetDebuggerPostTask()); + bool result = jsEnv->StartDebugger(option, socketFd, isDebugApp); ASSERT_EQ(result, false); } From 5f958803d6f5c42b0e267967e1b69d55812123b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Sat, 22 Jun 2024 08:06:10 +0000 Subject: [PATCH 040/148] update services/abilitymgr/src/ability_connect_manager.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- services/abilitymgr/src/ability_connect_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 548a91ae96..6c4fee5e62 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -2050,7 +2050,8 @@ void AbilityConnectManager::KeepAbilityAlive(const std::shared_ptrGetAbilityInfo(); - TAG_LOGI(AAFwkTag::ABILITYMGR, "restart ability: %{public}s", abilityInfo.name.c_str()); + TAG_LOGI(AAFwkTag::ABILITYMGR, "restart ability, bundleName: %{public}s, abilityName: %{public}s", + abilityInfo.bundleName.c_str(), abilityInfo.name.c_str()); auto token = abilityRecord->GetToken(); if ((IsLauncher(abilityRecord) || abilityRecord->IsSceneBoard()) && token != nullptr) { IN_PROCESS_CALL_WITHOUT_RET(DelayedSingleton::GetInstance()->ClearProcessByToken( @@ -2107,7 +2108,6 @@ void AbilityConnectManager::HandleAbilityDiedTask( } isRemove = true; } - auto abilityInfo = abilityRecord->GetAbilityInfo(); if (IsAbilityNeedKeepAlive(abilityRecord)) { KeepAbilityAlive(abilityRecord, currentUserId); From 52b4dd3e4a2517b99611440d8215cbda7c3c8103 Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Mon, 17 Jun 2024 19:59:14 +0800 Subject: [PATCH 041/148] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- .../ability_manager_client_test.cpp | 4 +- .../ability_manager_stub_test/BUILD.gn | 3 +- .../ability_manager_stub_test.cpp | 2 +- test/unittest/ability_record_test/BUILD.gn | 2 + .../app_mgr_service_inner_test.cpp | 22 ++++++- .../ui_ability_impl_test.cpp | 12 ++-- .../BUILD.gn | 61 ++++++++++++++++++- .../context_impl_test.cpp | 4 +- 8 files changed, 94 insertions(+), 16 deletions(-) diff --git a/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp b/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp index 2ec3226b9b..a7ea92de48 100644 --- a/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp +++ b/test/moduletest/ability_manager_client_test/ability_manager_client_test.cpp @@ -101,7 +101,7 @@ HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_RecordAppExitReason_0100 TAG_LOGI(AAFwkTag::TEST, "AbilityManagerClient_RecordAppExitReason_0100 start"); ExitReason exitReason = { REASON_JS_ERROR, "Js Error." }; auto result = AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason); - EXPECT_EQ(result, GET_BUNDLE_INFO_FAILED); + EXPECT_EQ(result, ERR_NAME_NOT_FOUND); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerClient_RecordAppExitReason_0100 end"); } @@ -115,7 +115,7 @@ HWTEST_F(AbilityManagerClientTest, AbilityManagerClient_RecordProcessExitReason_ TAG_LOGI(AAFwkTag::TEST, "AbilityManagerClient_RecordProcessExitReason_0100 start"); ExitReason exitReason = { REASON_JS_ERROR, "Js Error." }; auto result = AbilityManagerClient::GetInstance()->RecordAppExitReason(exitReason); - EXPECT_EQ(result, GET_BUNDLE_INFO_FAILED); + EXPECT_EQ(result, ERR_NAME_NOT_FOUND); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerClient_RecordProcessExitReason_0100 end"); } } // namespace AAFwk diff --git a/test/unittest/ability_manager_stub_test/BUILD.gn b/test/unittest/ability_manager_stub_test/BUILD.gn index d19dc278c6..ac50cdd9bc 100644 --- a/test/unittest/ability_manager_stub_test/BUILD.gn +++ b/test/unittest/ability_manager_stub_test/BUILD.gn @@ -17,13 +17,14 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/abilitymgr" ohos_unittest("ability_manager_stub_test") { - module_out_path = module_output_path sanitize = { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" + module_out_path = module_output_path include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp index bd799c1388..b2dc0c69be 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp @@ -3353,7 +3353,7 @@ HWTEST_F(AbilityManagerStubTest, AbilityManagerStub_TransferAbilityResultForExte MessageParcel data; MessageParcel reply; auto res = stub_->TransferAbilityResultForExtensionInner(data, reply); - EXPECT_EQ(res, NO_ERROR); + EXPECT_EQ(res, ERR_INVALID_VALUE); } /** diff --git a/test/unittest/ability_record_test/BUILD.gn b/test/unittest/ability_record_test/BUILD.gn index 4e675d6866..82d5a3ea44 100644 --- a/test/unittest/ability_record_test/BUILD.gn +++ b/test/unittest/ability_record_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("ability_record_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ @@ -104,6 +105,7 @@ ohos_unittest("ability_record_test_call") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index abd7d678fc..d57cd8865b 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -4359,13 +4359,33 @@ HWTEST_F(AppMgrServiceInnerTest, GetRunningMultiAppInfoByBundleName_001, TestSiz int32_t ret = appMgrServiceInner->GetRunningMultiAppInfoByBundleName(bundleName, info); EXPECT_NE(ret, ERR_OK); - appMgrServiceInner->appRunningManager_ = nullptr; + appMgrServiceInner->remoteClientManager_ = nullptr; ret = appMgrServiceInner->GetRunningMultiAppInfoByBundleName(bundleName, info); EXPECT_EQ(ret, ERR_INVALID_VALUE); TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_001 end"); } +/** + * @tc.name: GetRunningMultiAppInfoByBundleName_002 + * @tc.desc: Get multiApp information list by bundleName. + * @tc.type: FUNC + * @tc.require: issueI9HMAO + */ +HWTEST_F(AppMgrServiceInnerTest, GetRunningMultiAppInfoByBundleName_002, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_002 start"); + auto appMgrServiceInner = std::make_shared(); + EXPECT_NE(appMgrServiceInner, nullptr); + + std::string bundleName = ""; + RunningMultiAppInfo info; + int32_t ret = appMgrServiceInner->GetRunningMultiAppInfoByBundleName(bundleName, info); + EXPECT_EQ(ret, AAFwk::INVALID_PARAMETERS_ERR); + + TAG_LOGI(AAFwkTag::TEST, "GetRunningMultiAppInfoByBundleName_002 end"); +} + /** * @tc.name: SendCreateAtomicServiceProcessEvent_001 * @tc.desc: Report event of create atomic service process. diff --git a/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp index 04f087b76c..c32667afc3 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ui_ability_impl_test.cpp @@ -106,7 +106,7 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_001, Test EXPECT_EQ(testNotify1, 0); mockUIAbilityimpl->ScheduleUpdateConfiguration(config); auto testNotify2 = pMocKUIAbility->OnConfigurationUpdated_; - EXPECT_EQ(testNotify2, 0); + EXPECT_EQ(testNotify2, 1); } } GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_001 end"; @@ -154,14 +154,14 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_002, Test Configuration config; mockUIAbilityimpl->ScheduleUpdateConfiguration(config); auto testNotify2 = pMocKUIAbility->OnConfigurationUpdated_; - EXPECT_EQ(testNotify2, 0); + EXPECT_EQ(testNotify2, 1); auto language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage(); GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_002 : " << language; config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, language); mockUIAbilityimpl->SetlifecycleState(AAFwk::ABILITY_STATE_ACTIVE); mockUIAbilityimpl->ScheduleUpdateConfiguration(config); auto testNotify3 = pMocKUIAbility->OnConfigurationUpdated_; - EXPECT_EQ(testNotify3, 1); + EXPECT_EQ(testNotify3, 2); } } GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_002 end"; @@ -212,17 +212,17 @@ HWTEST_F(UIAbilityImplTest, AbilityRuntime_ScheduleUpdateConfiguration_003, Test EXPECT_EQ(testNotify1, 0); mockUIAbilityimpl->ScheduleUpdateConfiguration(config); auto testNotify2 = pMocKUIAbility->OnConfigurationUpdated_; - EXPECT_EQ(testNotify2, 0); + EXPECT_EQ(testNotify2, 1); auto language = OHOS::Global::I18n::LocaleConfig::GetSystemLanguage(); GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_003 : " << language; config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, language); mockUIAbilityimpl->SetlifecycleState(AAFwk::ABILITY_STATE_ACTIVE); mockUIAbilityimpl->ScheduleUpdateConfiguration(config); auto testNotify3 = pMocKUIAbility->OnConfigurationUpdated_; - EXPECT_EQ(testNotify3, 1); + EXPECT_EQ(testNotify3, 2); mockUIAbilityimpl->ScheduleUpdateConfiguration(config); auto testNotify4 = pMocKUIAbility->OnConfigurationUpdated_; - EXPECT_EQ(testNotify4, 2); + EXPECT_EQ(testNotify4, 3); } } GTEST_LOG_(INFO) << "AbilityRuntime_ScheduleUpdateConfiguration_003 end"; diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 1765794194..1390e342cd 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -104,10 +104,65 @@ ohos_unittest("application_test") { "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_bundle_manager.cpp", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_overlay_manager.cpp", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/sys_mgr_client_mock.cpp", - "ability_stage_test.cpp", - "application_cleaner_test.cpp", - "application_data_manager_test.cpp", "application_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", + "${ability_runtime_native_path}/ability/native:ability_thread", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:uiabilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_native_path}/appkit:appkit_native", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:extractortool", + "ability_base:want", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "napi:ace_napi", + "resource_management:global_resmgr", + ] + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +ohos_unittest("context_impl_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_services_path}/common/include", + "${ability_runtime_test_path}/mock/common/include", + "${resource_management_path}/frameworks/resmgr/include", + ] + + sources = [ + "${ability_runtime_native_path}/appkit/app/app_context.cpp", + "${ability_runtime_native_path}/appkit/app/app_loader.cpp", + "${ability_runtime_native_path}/appkit/app/application_cleaner.cpp", + "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_bundle_manager.cpp", "context_impl_test.cpp", ] diff --git a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp index 6e553396b8..812818cf04 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp @@ -653,7 +653,7 @@ HWTEST_F(ContextImplTest, AppExecFwk_ContextImpl_GetApplicationInfo_001, Functio HWTEST_F(ContextImplTest, AppExecFwk_ContextImpl_GetApplicationContext_001, Function | MediumTest | Level1) { GTEST_LOG_(INFO) << "AppExecFwk_ContextImpl_GetApplicationContext_001 start"; - EXPECT_FALSE(contextImpl_->GetApplicationContext() == nullptr); + EXPECT_TRUE(contextImpl_->GetApplicationContext() == nullptr); auto contextImpl = std::make_shared(); EXPECT_NE(contextImpl, nullptr); @@ -678,7 +678,7 @@ HWTEST_F(ContextImplTest, AppExecFwk_ContextImpl_SetParentContext_001, Function GTEST_LOG_(INFO) << "AppExecFwk_ContextImpl_SetParentContext_001 start"; std::shared_ptr contextImpl_ = std::make_shared(); contextImpl_->SetParentContext(contextImpl_); - EXPECT_FALSE(contextImpl_->GetApplicationContext() == nullptr); + EXPECT_TRUE(contextImpl_->GetApplicationContext() == nullptr); GTEST_LOG_(INFO) << "AppExecFwk_ContextImpl_SetParentContext_001 end"; } From 586b86eeffb4c6d5567e40c2275a30060538b0b2 Mon Sep 17 00:00:00 2001 From: donglin Date: Sat, 22 Jun 2024 13:40:10 +0000 Subject: [PATCH 042/148] =?UTF-8?q?action=E6=97=A5=E8=90=BD=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: donglin Change-Id: Iab6133f53268bc3fc404afbb5445f1c4ab85d5e6 --- .../bundle_mgr_helper.cpp | 3 +- .../bundle_mgr_helper.h | 3 +- .../include/implicit_start_processor.h | 4 +- .../src/implicit_start_processor.cpp | 53 +++++++++++++------ .../bundle_mgr_helper_test.cpp | 4 +- 5 files changed, 46 insertions(+), 21 deletions(-) diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index ac21209083..bc79ee9e88 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -668,7 +668,7 @@ void BundleMgrHelper::UpgradeAtomicService(const Want &want, int32_t userId) } bool BundleMgrHelper::ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault, - std::vector &abilityInfos, std::vector &extensionInfos) + std::vector &abilityInfos, std::vector &extensionInfos, bool &findDefaultApp) { TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called."); auto bundleMgr = Connect(); @@ -680,7 +680,6 @@ bool BundleMgrHelper::ImplicitQueryInfos(const Want &want, int32_t flags, int32_ AAFwk::Want newWant = want; newWant.RemoveAllFd(); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - bool findDefaultApp = false; bool ret = bundleMgr->ImplicitQueryInfos(newWant, flags, userId, withDefault, abilityInfos, extensionInfos, findDefaultApp); TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "findDefaultApp is %{public}d.", findDefaultApp); diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index fe8029909e..8ea8710ed1 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -79,7 +79,8 @@ public: int32_t flags, int32_t userId, AbilityInfo &abilityInfo, const sptr &callBack); void UpgradeAtomicService(const Want &want, int32_t userId); bool ImplicitQueryInfos(const Want &want, int32_t flags, int32_t userId, bool withDefault, - std::vector &abilityInfos, std::vector &extensionInfos); + std::vector &abilityInfos, std::vector &extensionInfos, + bool &findDefaultApp); bool CleanBundleDataFiles(const std::string &bundleName, int32_t userId, int32_t appCloneIndex); bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::vector &infos); bool GetBundleGidsByUid(const std::string &bundleName, const int32_t &uid, std::vector &gids); diff --git a/services/abilitymgr/include/implicit_start_processor.h b/services/abilitymgr/include/implicit_start_processor.h index b61ecf71b7..b5c17e31d2 100644 --- a/services/abilitymgr/include/implicit_start_processor.h +++ b/services/abilitymgr/include/implicit_start_processor.h @@ -71,7 +71,7 @@ public: private: int GenerateAbilityRequestByAction(int32_t userId, AbilityRequest &request, - std::vector &dialogAppInfos, bool isMoreHapList); + std::vector &dialogAppInfos, bool isMoreHapList, bool &findDefaultApp); std::string MatchTypeAndUri(const AAFwk::Want &want); std::shared_ptr GetBundleManagerHelper(); std::vector SplitStr(const std::string& str, char delimiter); @@ -105,6 +105,8 @@ private: void OnlyKeepReserveApp(std::vector &abilityInfos, std::vector &extensionInfos); + bool IsActionImplicitStart(const Want &want, bool findDeafultApp); + private: const static std::vector blackList; const static std::unordered_set extensionWhiteList; diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 7c517a12fd..3386399c7c 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -30,6 +30,7 @@ #include "in_process_call_wrapper.h" #include "parameters.h" #include "scene_board_judgement.h" +#include "start_ability_utils.h" #include "want.h" namespace OHOS { @@ -95,7 +96,8 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ std::vector dialogAppInfos; request.want.RemoveParam(APP_CLONE_INDEX); - auto ret = GenerateAbilityRequestByAction(userId, request, dialogAppInfos, false); + bool findDefaultApp = false; + auto ret = GenerateAbilityRequestByAction(userId, request, dialogAppInfos, false, findDefaultApp); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request by action failed."); return ret; @@ -157,7 +159,7 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ } std::vector dialogAllAppInfos; bool isMoreHapList = true; - ret = GenerateAbilityRequestByAction(userId, request, dialogAllAppInfos, isMoreHapList); + ret = GenerateAbilityRequestByAction(userId, request, dialogAllAppInfos, isMoreHapList, findDefaultApp); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "generate ability request by action failed."); return ret; @@ -188,9 +190,12 @@ int ImplicitStartProcessor::ImplicitStartAbility(AbilityRequest &request, int32_ defaultPicker = request.want.GetBoolParam(SHOW_DEFAULT_PICKER_FLAG, defaultPicker); if (dialogAppInfos.size() == 1 && (!defaultPicker || AppUtils::GetInstance().IsSelectorDialogDefaultPossion())) { auto info = dialogAppInfos.front(); - TAG_LOGI( - AAFwkTag::ABILITYMGR, "ImplicitQueryInfos success, target ability: %{public}s", info.abilityName.data()); - return IN_PROCESS_CALL(startAbilityTask(info.bundleName, info.abilityName)); + // Compatible with the action's sunset scene + if (!IsActionImplicitStart(request.want, findDefaultApp)) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "ImplicitQueryInfos success, target ability: %{public}s", + info.abilityName.data()); + return IN_PROCESS_CALL(startAbilityTask(info.bundleName, info.abilityName)); + } } if (AppUtils::GetInstance().IsSelectorDialogDefaultPossion()) { @@ -327,7 +332,7 @@ void ImplicitStartProcessor::OnlyKeepReserveApp(std::vector &dialogAppInfos, bool isMoreHapList) + AbilityRequest &request, std::vector &dialogAppInfos, bool isMoreHapList, bool &findDefaultApp) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s.", __func__); @@ -349,7 +354,7 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, if (IPCSkeleton::GetCallingUid() == NFC_CALLER_UID && !request.want.GetStringArrayParam(PARAM_ABILITY_APPINFOS).empty()) { TAG_LOGI(AAFwkTag::ABILITYMGR, "The NFCNeed caller source is NFC."); - ImplicitStartProcessor::QueryBmsAppInfos(request, userId, dialogAppInfos); + QueryBmsAppInfos(request, userId, dialogAppInfos); } if (!IsCallFromAncoShellOrBroker(request.callerToken)) { @@ -367,7 +372,7 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, } IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->ImplicitQueryInfos( - request.want, abilityInfoFlag, userId, withDefault, abilityInfos, extensionInfos)); + request.want, abilityInfoFlag, userId, withDefault, abilityInfos, extensionInfos, findDefaultApp)); OnlyKeepReserveApp(abilityInfos, extensionInfos); if (isOpenLink && extensionInfos.size() > 0) { @@ -407,7 +412,7 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, std::vector infoNames; if (!AppUtils::GetInstance().IsSelectorDialogDefaultPossion()) { IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->ImplicitQueryInfos(implicitwant, abilityInfoFlag, userId, - withDefault, implicitAbilityInfos, implicitExtensionInfos)); + withDefault, implicitAbilityInfos, implicitExtensionInfos, findDefaultApp)); if (implicitAbilityInfos.size() != 0 && typeName != TYPE_ONLY_MATCH_WILDCARD) { for (auto implicitAbilityInfo : implicitAbilityInfos) { infoNames.emplace_back(implicitAbilityInfo.bundleName + "#" + @@ -761,13 +766,9 @@ bool ImplicitStartProcessor::IsCallFromAncoShellOrBroker(const sptrGetAbilityInfo().bundleName; - if (callerBundleName == SHELL_ASSISTANT_BUNDLENAME) { - return true; + AppExecFwk::AbilityInfo callerAbilityInfo; + if (StartAbilityUtils::GetCallerAbilityInfo(token, callerAbilityInfo)) { + return callerAbilityInfo.bundleName == SHELL_ASSISTANT_BUNDLENAME; } return false; } @@ -792,5 +793,25 @@ void ImplicitStartProcessor::SetTargetLinkInfo(const std::vector abilityInfos; std::vector extensionInfos; - auto ret = bundleMgrHelper->ImplicitQueryInfos(want, flags, userId, withDefault, abilityInfos, extensionInfos); + bool findDefaultApp = false; + auto ret = bundleMgrHelper->ImplicitQueryInfos(want, flags, userId, withDefault, abilityInfos, extensionInfos, + findDefaultApp); EXPECT_EQ(ret, false); } From ff05482dfada11251f8cc204d364c2bcf7b9be5b Mon Sep 17 00:00:00 2001 From: dijun Date: Sun, 23 Jun 2024 21:27:59 +0800 Subject: [PATCH 043/148] static Signed-off-by: dijun Change-Id: I9964282c30dfa1a34735730f5dc379807a858946 --- .../photo_editor_extension_context.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/photo_editor_extension_context/photo_editor_extension_context.js b/frameworks/js/napi/photo_editor_extension_context/photo_editor_extension_context.js index 081a1bb4a4..b2e7e12e0a 100755 --- a/frameworks/js/napi/photo_editor_extension_context/photo_editor_extension_context.js +++ b/frameworks/js/napi/photo_editor_extension_context/photo_editor_extension_context.js @@ -21,12 +21,12 @@ export class PhotoEditorExtensionContext extends UIExtensionContext { } saveEditedContentWithUri(uri, asyncCallback) { - console.log("saveEditedContent with uri: " + uri); + console.log('saveEditedContent with uri: ' + uri); return this.__context_impl__.saveEditedContentWithUri(uri, asyncCallback); } saveEditedContentWithImage(image, option, asyncCallback) { - console.log("saveEditedContent with image pixmap."); + console.log('saveEditedContent with image pixmap.'); return this.__context_impl__.saveEditedContentWithImage(image, option, asyncCallback); } } \ No newline at end of file From 619124cd56be5fdb3e1b10200a44019aac09cea0 Mon Sep 17 00:00:00 2001 From: zhangduanyang Date: Mon, 24 Jun 2024 13:42:04 +0800 Subject: [PATCH 044/148] TicketNo:AR20240403329372 Description:add application no responding dialog Team:gitee Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No Signed-off-by: zhangduanyang --- .../modal_system_app_freeze_uiextension.h | 6 +++++- services/appmgr/src/app_mgr_service_inner.cpp | 8 +++----- .../modal_system_app_freeze_uiextension.cpp | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/services/appmgr/include/modal_system_app_freeze_uiextension.h b/services/appmgr/include/modal_system_app_freeze_uiextension.h index e9067cdcc8..882834dba2 100644 --- a/services/appmgr/include/modal_system_app_freeze_uiextension.h +++ b/services/appmgr/include/modal_system_app_freeze_uiextension.h @@ -20,10 +20,12 @@ #include #include +#include #include "ability_connect_callback_stub.h" #include "ability_manager_client.h" #include "ability_state.h" +#include "fault_data.h" #include "iremote_stub.h" #include "task_handler_wrap.h" #include "want.h" @@ -37,9 +39,11 @@ public: ModalSystemAppFreezeUIExtension() = default; virtual ~ModalSystemAppFreezeUIExtension(); - bool CreateModalUIExtension(std::string pid, std::string bundleName); + void ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid, std::string bundleName, + std::function callback); private: + bool CreateModalUIExtension(std::string pid, std::string bundleName); AAFwk::Want CreateSystemDialogWant(std::string pid, std::string bundleName); private: diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 2640d13514..3fce61e4cb 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5193,11 +5193,9 @@ int32_t AppMgrServiceInner::NotifyAppFault(const FaultData &faultData) #ifdef APP_NO_RESPONSE_DIALOG // A dialog box is displayed when the PC appfreeze - if (appRecord->GetFocusFlag() && (faultData.errorObject.name == AppFreezeType::THREAD_BLOCK_6S || - faultData.errorObject.name == AppFreezeType::APP_INPUT_BLOCK)) { - auto &connection = ModalSystemAppFreezeUIExtension::GetInstance(); - connection.CreateModalUIExtension(std::to_string(pid), bundleName); - } + auto killFaultApp = std::bind(&AppMgrServiceInner::KillFaultApp, this, pid, bundleName, faultData); + ModalSystemAppFreezeUIExtension::GetInstance().ProcessAppFreeze(appRecord->GetFocusFlag(), faultData, + std::to_string(pid), bundleName, killFaultApp); #else KillFaultApp(pid, bundleName, faultData); #endif diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index c87ce0122f..931e4d2f75 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -56,6 +56,25 @@ sptr ModalSystemAppF return dialogConnectionCallback_; } +void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid, + std::string bundleName, std::function callback) +{ + const std::string SCENE_BAOARD_NAME = "com.ohos.sceneboard"; + if (bundleName == SCENE_BAOARD_NAME && callback) { + callback(); + return; + } + FaultDataType faultType = faultData.faultType; + std::string name = faultData.errorObject.name; + bool isAppFreezeDialog = name == AppFreezeType::THREAD_BLOCK_6S || name == AppFreezeType::APP_INPUT_BLOCK || + name == AppFreezeType::LIFECYCLE_TIMEOUT; + if (focusFlag && isAppFreezeDialog) { + CreateModalUIExtension(pid, bundleName); + } else if (callback && faultType != FaultDataType::APP_FREEZE) { + callback(); + } +} + bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, std::string bundleName) { TAG_LOGI(AAFwkTag::ABILITYMGR, "CreateModalUIExtension Called."); From c4e59aab7dbbc19d78a711482a09b49f8de57976 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Mon, 24 Jun 2024 14:33:27 +0800 Subject: [PATCH 045/148] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/IA7OTU MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 消除弱耦合 Signed-off-by: jiangzhijun8 --- frameworks/js/napi/inner/napi_ability_common/BUILD.gn | 3 ++- frameworks/js/napi/inner/napi_common/BUILD.gn | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn index be85ea95e4..2eb72fb995 100644 --- a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn @@ -62,7 +62,6 @@ ohos_shared_library("napi_ability_common") { public_external_deps = [ "ability_base:configuration", "bundle_framework:appexecfwk_core", - "window_manager:libwm_lite", ] if (ability_runtime_graphics) { @@ -70,6 +69,8 @@ ohos_shared_library("napi_ability_common") { "SUPPORT_GRAPHICS", "SUPPORT_SCREEN", ] + + public_external_deps += [ "window_manager:libwm_lite" ] } innerapi_tags = [ "platformsdk" ] diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index e02e55fb26..9a380d45ca 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -63,7 +63,6 @@ ohos_shared_library("napi_common") { public_external_deps = [ "ability_base:configuration", "bundle_framework:appexecfwk_core", - "window_manager:libwm_lite", ] if (ability_runtime_graphics) { @@ -71,6 +70,8 @@ ohos_shared_library("napi_common") { "SUPPORT_GRAPHICS", "SUPPORT_SCREEN", ] + + public_external_deps += [ "window_manager:libwm_lite" ] } innerapi_tags = [ "platformsdk" ] From 48b6fc4ba5697b95d00c74c0b3f52b8bdbca9c28 Mon Sep 17 00:00:00 2001 From: sodanotgreen Date: Mon, 24 Jun 2024 17:18:41 +0800 Subject: [PATCH 046/148] cfi Signed-off-by: sodanotgreen --- interfaces/inner_api/session_handler/BUILD.gn | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/interfaces/inner_api/session_handler/BUILD.gn b/interfaces/inner_api/session_handler/BUILD.gn index 6a950db1f7..c40fe59d36 100644 --- a/interfaces/inner_api/session_handler/BUILD.gn +++ b/interfaces/inner_api/session_handler/BUILD.gn @@ -32,6 +32,15 @@ config("session_handler_config") { } ohos_shared_library("session_handler") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } sources = [ "src/session_handler_proxy.cpp", "src/session_handler_stub.cpp", From cfe55adab772e4b8d7415b581382622fada430d4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 24 Jun 2024 17:23:35 +0800 Subject: [PATCH 047/148] add log Signed-off-by: unknown --- services/appmgr/src/app_mgr_service_inner.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 65fcc7c239..54d755afc1 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -442,7 +442,8 @@ void AppMgrServiceInner::LoadAbility(sptr token, sptr want, int32_t abilityRecordId) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::APPMGR, "name:%{public}s.", abilityInfo->name.c_str()); + TAG_LOGI(AAFwkTag::APPMGR, "name:%{public}s-%{public}s.", + abilityInfo->bundleName.c_str(), abilityInfo->name.c_str()); if (!CheckLoadAbilityConditions(token, abilityInfo, appInfo)) { TAG_LOGE(AAFwkTag::APPMGR, "CheckLoadAbilityConditions failed"); return; @@ -2241,7 +2242,8 @@ void AppMgrServiceInner::StartAbility(sptr token, sptr want, int32_t abilityRecordId) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); - TAG_LOGD(AAFwkTag::APPMGR, "start ability"); + TAG_LOGI(AAFwkTag::APPMGR, "start ability, ability %{public}s-%{public}s", + abilityInfo->bundleName.c_str(), abilityInfo->name.c_str()); if (!appRecord) { TAG_LOGE(AAFwkTag::APPMGR, "appRecord is null"); return; From c96c5573bc2a2cd387bcc1a5f6f051c19a330d02 Mon Sep 17 00:00:00 2001 From: xufu Date: Mon, 24 Jun 2024 14:25:22 +0800 Subject: [PATCH 048/148] =?UTF-8?q?=E9=80=9A=E7=9F=A5rss=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0callerpid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xufu --- .../include/ability_manager_service.h | 2 +- .../src/ability_manager_service.cpp | 42 ++++++++++++------- services/common/include/res_sched_util.h | 3 +- services/common/src/res_sched_util.cpp | 4 +- .../abilitymanagerservicefirst_fuzzer.cpp | 2 +- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index b5fb6e0399..ce2521ea75 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1947,7 +1947,7 @@ private: void ReportAbilitAssociatedStartInfoToRSS(const AppExecFwk::AbilityInfo &abilityInfo, int64_t type, const sptr &callerToken); - void ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo); + void ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo, sptr callerToken); void ReportAppRecoverResult(const int32_t appId, const AppExecFwk::ApplicationInfo &appInfo, const std::string& abilityName, const std::string& result); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index ef821fcb45..91b217f798 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -1179,7 +1179,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(want)); return connectManager->StartAbility(abilityRequest); } @@ -1198,7 +1198,7 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrStartAbility(abilityRequest); } @@ -1897,7 +1897,7 @@ int32_t AbilityManagerService::RequestDialogServiceInner(const Want &want, const } TAG_LOGD(AAFwkTag::ABILITYMGR, "request dialog service, start service extension,name is %{public}s.", abilityInfo.name.c_str()); - ReportEventToRSS(abilityInfo); + ReportEventToRSS(abilityInfo, callerToken); return connectManager->StartAbility(abilityRequest); } @@ -2368,15 +2368,27 @@ void AbilityManagerService::ReportAbilitAssociatedStartInfoToRSS( ResSchedUtil::GetInstance().ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerUid, callerPid); } -void AbilityManagerService::ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo) +void AbilityManagerService::ReportEventToRSS(const AppExecFwk::AbilityInfo &abilityInfo, + sptr callerToken) { CHECK_POINTER_LOG(taskHandler_, "taskhandler null"); - std::string reason = (abilityInfo.type == AppExecFwk::AbilityType::PAGE) ? - "THAW_BY_START_PAGE_ABILITY" : "THAW_BY_START_NOT_PAGE_ABILITY"; + std::string reason; + if (abilityInfo.type == AppExecFwk::AbilityType::PAGE) { + reason = "THAW_BY_START_PAGE_ABILITY"; + } else if (abilityInfo.type == AppExecFwk::AbilityType::EXTENSION && + abilityInfo.extensionAbilityType == AppExecFwk::ExtensionAbilityType::SERVICE) { + reason = "THAW_BY_START_SERVICE_EXTENSION"; + } else { + reason = "THAW_BY_START_NOT_PAGE_ABILITY"; + } const auto uid = abilityInfo.applicationInfo.uid; const auto bundleName = abilityInfo.applicationInfo.bundleName; - taskHandler_->SubmitTask([reason, uid, bundleName]() { - ResSchedUtil::GetInstance().ReportEventToRSS(uid, bundleName, reason); + auto callerAbility = Token::GetAbilityRecordByToken(callerToken); + const int32_t callerPid = (callerAbility != nullptr) ? callerAbility->GetPid() : IPCSkeleton::GetCallingPid(); + TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}d_%{public}s reason=%{public}s callerPid=%{public}d", uid, + bundleName.c_str(), reason.c_str(), callerPid); + taskHandler_->SubmitTask([reason, uid, bundleName, callerPid]() { + ResSchedUtil::GetInstance().ReportEventToRSS(uid, bundleName, reason, callerPid); }); } @@ -3818,7 +3830,7 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u return ERR_INVALID_VALUE; } - ReportEventToRSS(abilityInfo); + ReportEventToRSS(abilityInfo, callerToken); return connectManager->ConnectAbilityLocked(abilityRequest, connect, callerToken, sessionInfo, connectInfo); } @@ -4691,7 +4703,7 @@ sptr AbilityManagerService::AcquireDataAbility( std::shared_ptr dataAbilityManager = GetDataAbilityManagerByUserId(userId); CHECK_POINTER_AND_RETURN(dataAbilityManager, nullptr); - ReportEventToRSS(abilityRequest.abilityInfo); + ReportEventToRSS(abilityRequest.abilityInfo, callerToken); bool isNotHap = isSaCall || isShellCall; UpdateCallerInfo(abilityRequest.want, callerToken); return dataAbilityManager->Acquire(abilityRequest, tryBind, callerToken, isNotHap); @@ -6740,7 +6752,7 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptrDoProcess(afterCheckParam); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - ReportEventToRSS(abilityRequest.abilityInfo); + ReportEventToRSS(abilityRequest.abilityInfo, callerToken); abilityRequest.want.SetParam(IS_CALL_BY_SCB, false); auto uiAbilityManager = GetUIAbilityManagerByUserId(oriValidUserId); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); @@ -6752,7 +6764,7 @@ int AbilityManagerService::StartAbilityByCall(const Want &want, const sptrResolveLocked(abilityRequest); @@ -6779,7 +6791,7 @@ int AbilityManagerService::StartAbilityJust(AbilityRequest &abilityRequest, int3 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionListMgr is Null. Designated User Id=%{public}d", validUserId); return ERR_INVALID_VALUE; } - ReportEventToRSS(abilityRequest.abilityInfo); + ReportEventToRSS(abilityRequest.abilityInfo, abilityRequest.callerToken); return missionListMgr->ResolveLocked(abilityRequest); } diff --git a/services/common/include/res_sched_util.h b/services/common/include/res_sched_util.h index 918a10f65d..8639366731 100644 --- a/services/common/include/res_sched_util.h +++ b/services/common/include/res_sched_util.h @@ -35,7 +35,8 @@ public: void ReportAbilitStartInfoToRSS(const AbilityInfo &abilityInfo, int32_t pid, bool isColdStart); void ReportAbilitAssociatedStartInfoToRSS( const AbilityInfo &abilityInfo, int64_t resSchedType, int32_t callerUid, int32_t callerPid); - void ReportEventToRSS(int32_t uid, std::string bundleName, std::string name); + void ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason, + const int32_t callerPid = -1); void GetAllFrozenPidsFromRSS(std::unordered_set &frozenPids); private: ResSchedUtil() = default; diff --git a/services/common/src/res_sched_util.cpp b/services/common/src/res_sched_util.cpp index 861b90b403..1d1a5704cc 100644 --- a/services/common/src/res_sched_util.cpp +++ b/services/common/src/res_sched_util.cpp @@ -83,7 +83,8 @@ void ResSchedUtil::ReportAbilitAssociatedStartInfoToRSS( #endif } -void ResSchedUtil::ReportEventToRSS(int32_t uid, std::string bundleName, std::string reason) +void ResSchedUtil::ReportEventToRSS(const int32_t uid, const std::string &bundleName, const std::string &reason, + const int32_t callerPid) { #ifdef RESOURCE_SCHEDULE_SERVICE_ENABLE uint32_t resType = ResourceSchedule::ResType::SYNC_RES_TYPE_THAW_ONE_APP; @@ -92,6 +93,7 @@ void ResSchedUtil::ReportEventToRSS(int32_t uid, std::string bundleName, std::st payload.emplace("pid", -1); payload.emplace("bundleName", bundleName); payload.emplace("reason", reason); + payload.emplace("callerPid", callerPid); nlohmann::json reply; TAG_LOGD(AAFwkTag::DEFAULT, "call"); ResourceSchedule::ResSchedClient::GetInstance().ReportSyncEvent(resType, 0, payload, reply); diff --git a/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp b/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp index 296d59c318..b3120b5832 100755 --- a/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp +++ b/test/fuzztest/abilitymanagerservicefirst_fuzzer/abilitymanagerservicefirst_fuzzer.cpp @@ -96,7 +96,7 @@ void DoSomethingInterestingWithMyAPI1(AbilityManagerService &abilityms, Want& wa abilityms.CheckOptExtensionAbility(want, abilityRequest, int32Param, extensionType); AppExecFwk::AbilityInfo abilityInfo; abilityms.ReportAbilitStartInfoToRSS(abilityInfo); - abilityms.ReportEventToRSS(abilityInfo); + abilityms.ReportEventToRSS(abilityInfo, token); abilityms.StartExtensionAbility(want, token, int32Param, extensionType); abilityms.StopExtensionAbility(want, token, int32Param, extensionType); abilityms.TerminateAbility(token, intParam, &want); From 4ed83dbe8a5b31ddec0bedd935de10408e2b4362 Mon Sep 17 00:00:00 2001 From: zhangyuhang72 Date: Mon, 24 Jun 2024 22:15:15 +0800 Subject: [PATCH 049/148] =?UTF-8?q?=E9=80=80=E5=87=BA=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BA=94=E7=94=A8=E5=88=86=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyuhang72 Change-Id: Ic2641d8480fe9203dfd30eb455ee0eabb4304551 --- .../include/ability_manager_interface.h | 22 +++- .../include/ability_manager_proxy.h | 14 ++- .../include/ability_manager_service.h | 16 ++- .../include/app_exit_reason_data_manager.h | 4 +- .../include/app_exit_reason_helper.h | 10 +- services/abilitymgr/include/mission_list.h | 3 +- .../abilitymgr/include/mission_list_manager.h | 3 +- .../ui_ability_lifecycle_manager.h | 3 +- .../abilitymgr/src/ability_manager_proxy.cpp | 13 ++- .../src/ability_manager_service.cpp | 51 +++++---- .../abilitymgr/src/ability_manager_stub.cpp | 6 +- .../src/app_exit_reason_data_manager.cpp | 16 ++- .../abilitymgr/src/app_exit_reason_helper.cpp | 104 ++++++++++-------- services/abilitymgr/src/mission_list.cpp | 5 +- .../abilitymgr/src/mission_list_manager.cpp | 17 +-- .../ui_ability_lifecycle_manager.cpp | 5 +- .../AMS/mock_serviceability_manager_service.h | 1 + .../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_manager_proxy.h | 1 + .../mock/include/mock_ability_mgr_service.h | 1 + .../ability_manager_proxy_test.cpp | 24 +++- .../ability_manager_stub_mock.h | 3 +- .../ability_manager_service_first_test.cpp | 3 +- .../mock_ability_manager_service.h | 1 + .../ui_ability_lifecycle_manager_test.cpp | 8 +- tools/test/mock/mock_ability_manager_stub.h | 1 + 29 files changed, 224 insertions(+), 116 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 9f8c65e778..cbd89b0fe0 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -723,7 +723,23 @@ public: * @param uid uid of bundle. * @return Returns ERR_OK on success, others on failure. */ - virtual int UninstallApp(const std::string &bundleName, int32_t uid) = 0; + virtual int UninstallApp(const std::string &bundleName, int32_t uid) + { + return 0; + } + + /** + * Uninstall app + * + * @param bundleName bundle name of uninstalling app. + * @param uid uid of bundle. + * @param appIndex the app index of app clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex) + { + return 0; + } /** * Upgrade app, record exit reason and kill application @@ -731,9 +747,11 @@ public: * @param bundleName bundle name of upgrading app. * @param uid uid of bundle. * @param exitMsg the exit reason message. + * @param appIndex the app index of app clone. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg) + virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg, + int32_t appIndex = 0) { return 0; } diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 2cd94095fc..77717b3947 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -579,15 +579,27 @@ public: */ virtual int UninstallApp(const std::string &bundleName, int32_t uid) override; + /** + * Uninstall app + * + * @param bundleName bundle name of uninstalling app. + * @param uid uid of bundle. + * @param appIndex the app index of app clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex) override; + /** * Upgrade app, record exit reason and kill application * * @param bundleName bundle name of upgrading app. * @param uid uid of bundle. * @param exitMsg the exit reason message. + * @param appIndex the app index of app clone. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg) override; + virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg, + int32_t appIndex = 0) override; virtual sptr GetWantSender( const WantSenderInfo &wantSenderInfo, const sptr &callerToken) override; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 9853c68f6a..7b751c3287 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -791,15 +791,27 @@ public: */ virtual int UninstallApp(const std::string &bundleName, int32_t uid) override; + /** + * Uninstall app + * + * @param bundleName bundle name of uninstalling app. + * @param uid uid of bundle. + * @param appIndex the app index of app clone. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex) override; + /** * Upgrade app, record exit reason and kill application * * @param bundleName bundle name of upgrading app. * @param uid uid of bundle. * @param exitMsg the exit reason message. + * @param appIndex the app index of app clone. * @return Returns ERR_OK on success, others on failure. */ - virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg) override; + virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg, + int32_t appIndex = 0) override; virtual sptr GetWantSender( const WantSenderInfo &wantSenderInfo, const sptr &callerToken) override; @@ -2139,7 +2151,7 @@ private: bool CheckSenderWantInfo(int32_t callerUid, const WantSenderInfo &wantSenderInfo); - int32_t UninstallAppInner(const std::string &bundleName, const int32_t uid, const bool isUpgrade, + int32_t UninstallAppInner(const std::string &bundleName, const int32_t uid, int32_t appIndex, const bool isUpgrade, const std::string &exitMsg); int32_t GetMissionIdByAbilityTokenInner(const sptr &token); diff --git a/services/abilitymgr/include/app_exit_reason_data_manager.h b/services/abilitymgr/include/app_exit_reason_data_manager.h index d0fb0c43a6..79c3dafa9b 100644 --- a/services/abilitymgr/include/app_exit_reason_data_manager.h +++ b/services/abilitymgr/include/app_exit_reason_data_manager.h @@ -39,7 +39,9 @@ public: int32_t GetAppExitReason(const std::string &bundleName, uint32_t accessTokenId, const std::string &abilityName, bool &isSetReason, AAFwk::ExitReason &exitReason); - int32_t DeleteAppExitReason(const std::string &bundleName, int32_t uid); + int32_t DeleteAppExitReason(const std::string &bundleName, int32_t uid, int32_t appIndex); + + int32_t DeleteAppExitReason(const std::string &bundleName, uint32_t accessTokenId); int32_t AddAbilityRecoverInfo(uint32_t accessTokenId, const std::string &moduleName, const std::string &abilityName, const int &sessionId); diff --git a/services/abilitymgr/include/app_exit_reason_helper.h b/services/abilitymgr/include/app_exit_reason_helper.h index 6cb25d8f16..91c87ef0fa 100644 --- a/services/abilitymgr/include/app_exit_reason_helper.h +++ b/services/abilitymgr/include/app_exit_reason_helper.h @@ -31,20 +31,18 @@ public: ~AppExitReasonHelper() = default; int32_t RecordAppExitReason(const ExitReason &exitReason); + int32_t RecordAppExitReason(const std::string &bundleName, int32_t uid, int32_t appIndex, + const ExitReason &exitReason); int32_t RecordProcessExtensionExitReason( const int32_t pid, const std::string &bundleName, const ExitReason &exitReason); int32_t RecordProcessExitReason(const int32_t pid, const ExitReason &exitReason); - int32_t RecordProcessExitReason(const std::string &bundleName, int32_t uid, const ExitReason &exitReason); private: int32_t RecordProcessExitReason(const int32_t pid, const std::string bundleName, const int32_t uid, const uint32_t accessTokenId, const ExitReason &exitReason); - void GetActiveAbilityListByU0(const std::string bundleName, std::vector &abilityLists, + void GetActiveAbilityList(int32_t uid, std::vector &abilityLists, const int32_t pid); + void GetActiveAbilityListFromUIAbilityManager(int32_t uid, std::vector &abilityLists, const int32_t pid); - void GetActiveAbilityListByUser(const std::string bundleName, std::vector &abilityLists, - const int32_t targetUserId, const int32_t pid); - void GetActiveAbilityListFromUIAabilityManager(const std::string bundleName, - std::vector &abilityLists, const int32_t targetUserId, const int32_t pid); bool IsExitReasonValid(const ExitReason &exitReason); std::shared_ptr subManagersHelper_; diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission_list.h index 4b06464289..f38731267b 100644 --- a/services/abilitymgr/include/mission_list.h +++ b/services/abilitymgr/include/mission_list.h @@ -223,8 +223,7 @@ public: int32_t GetMissionCountByUid(int32_t targetUid) const; void FindEarliestMission(std::shared_ptr& targetMission) const; int32_t GetMissionCount() const; - void GetActiveAbilityList(const std::string &bundleName, std::vector &abilityList, - int32_t pid = NO_PID); + void GetActiveAbilityList(int32_t uid, std::vector &abilityList, int32_t pid = NO_PID); void SignRestartAppFlag(const std::string &bundleName); diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 4b493995be..e79e78bf8f 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -348,8 +348,7 @@ public: int DoAbilityForeground(std::shared_ptr &abilityRecord, uint32_t flag); - void GetActiveAbilityList(const std::string &bundleName, std::vector &abilityList, - int32_t pid = NO_PID); + void GetActiveAbilityList(int32_t uid, std::vector &abilityList, int32_t pid = NO_PID); void CallRequestDone(const std::shared_ptr &abilityRecord, const sptr &callStub); diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 2420f0e2a0..eafc34b6c8 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -253,8 +253,7 @@ public: */ int32_t GetSessionIdByAbilityToken(const sptr &token); - void GetActiveAbilityList(const std::string &bundleName, std::vector &abilityList, - int32_t pid = NO_PID); + void GetActiveAbilityList(int32_t uid, std::vector &abilityList, int32_t pid = NO_PID); bool PrepareTerminateAbility(const std::shared_ptr &abilityRecord); void SetSessionHandler(const sptr &handler); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 2043acb848..201dd700de 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1786,6 +1786,11 @@ int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, con #endif int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid) +{ + return UninstallApp(bundleName, uid, 0); +} + +int32_t AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex) { MessageParcel data; MessageParcel reply; @@ -1802,6 +1807,10 @@ int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write failed."); return ERR_INVALID_VALUE; } + if (!data.WriteInt32(appIndex)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "appIndex write failed."); + return ERR_INVALID_VALUE; + } int error = SendRequest(AbilityManagerInterfaceCode::UNINSTALL_APP, data, reply, option); if (error != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error); @@ -1810,7 +1819,8 @@ int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid return reply.ReadInt32(); } -int32_t AbilityManagerProxy::UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg) +int32_t AbilityManagerProxy::UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg, + int32_t appIndex) { MessageParcel data; MessageParcel reply; @@ -1822,6 +1832,7 @@ int32_t AbilityManagerProxy::UpgradeApp(const std::string &bundleName, const int PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(bundleName)); PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, uid); PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(exitMsg)); + PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, appIndex); int error = SendRequest(AbilityManagerInterfaceCode::UPGRADE_APP, data, reply, option); if (error != NO_ERROR) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a5895e98a4..7d7a2a102e 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2151,16 +2151,21 @@ int32_t AbilityManagerService::ForceExitApp(const int32_t pid, const ExitReason return ERR_PERMISSION_DENIED; } - std::string bundleName; - int32_t uid; - DelayedSingleton::GetInstance()->GetBundleNameByPid(pid, bundleName, uid); - if (bundleName.empty()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Get bundle name by pid failed."); - return ERR_INVALID_VALUE; + AppExecFwk::ApplicationInfo application; + bool debug = false; + auto ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->GetApplicationInfoByProcessID(pid, + application, debug)); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "GetApplicationInfoByProcessID failed."); + return ret; } + std::string bundleName = application.bundleName; + int32_t uid = application.uid; + int32_t appIndex = application.appIndex; + CHECK_POINTER_AND_RETURN(appExitReasonHelper_, ERR_NULL_OBJECT); - appExitReasonHelper_->RecordProcessExitReason(bundleName, uid, exitReason); + appExitReasonHelper_->RecordAppExitReason(bundleName, uid, appIndex, exitReason); return DelayedSingleton::GetInstance()->KillApplication(bundleName); } @@ -5938,20 +5943,27 @@ int AbilityManagerService::KillProcess(const std::string &bundleName, const bool int AbilityManagerService::UninstallApp(const std::string &bundleName, int32_t uid) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "Uninstall app, bundleName: %{public}s, uid=%{public}d", bundleName.c_str(), uid); - return UninstallAppInner(bundleName, uid, false, ""); + return UninstallApp(bundleName, uid, 0); } -int32_t AbilityManagerService::UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg) +int32_t AbilityManagerService::UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex) { - TAG_LOGD(AAFwkTag::ABILITYMGR, - "UpgradeApp app, bundleName: %{public}s, uid=%{public}d, exitMsg: %{public}s,", bundleName.c_str(), - uid, exitMsg.c_str()); - return UninstallAppInner(bundleName, uid, true, exitMsg); + TAG_LOGI(AAFwkTag::ABILITYMGR, "Uninstall app, bundleName: %{public}s, uid=%{public}d, appIndex:%{public}d", + bundleName.c_str(), uid, appIndex); + return UninstallAppInner(bundleName, uid, appIndex, false, ""); } -int32_t AbilityManagerService::UninstallAppInner(const std::string &bundleName, const int32_t uid, const bool isUpgrade, - const std::string &exitMsg) +int32_t AbilityManagerService::UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg, + int32_t appIndex) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, + "UpgradeApp app, bundleName: %{public}s, uid=%{public}d, exitMsg: %{public}s, appIndex:%{public}d", + bundleName.c_str(), uid, exitMsg.c_str(), appIndex); + return UninstallAppInner(bundleName, uid, appIndex, true, exitMsg); +} + +int32_t AbilityManagerService::UninstallAppInner(const std::string &bundleName, const int32_t uid, int32_t appIndex, + const bool isUpgrade, const std::string &exitMsg) { pid_t callingPid = IPCSkeleton::GetCallingPid(); pid_t pid = getprocpid(); @@ -5963,7 +5975,7 @@ int32_t AbilityManagerService::UninstallAppInner(const std::string &bundleName, if (isUpgrade) { CHECK_POINTER_AND_RETURN(appExitReasonHelper_, ERR_NULL_OBJECT); AAFwk::ExitReason exitReason = { REASON_UPGRADE, exitMsg }; - appExitReasonHelper_->RecordProcessExitReason(bundleName, uid, exitReason); + appExitReasonHelper_->RecordAppExitReason(bundleName, uid, appIndex, exitReason); } CHECK_POINTER_AND_RETURN(subManagersHelper_, ERR_NULL_OBJECT); @@ -5973,7 +5985,8 @@ int32_t AbilityManagerService::UninstallAppInner(const std::string &bundleName, return UNINSTALL_APP_FAILED; } if (!isUpgrade) { - DelayedSingleton::GetInstance()->DeleteAppExitReason(bundleName, uid); + DelayedSingleton::GetInstance()->DeleteAppExitReason(bundleName, uid, + appIndex); } return ERR_OK; } @@ -7139,7 +7152,7 @@ void AbilityManagerService::ScheduleClearRecoveryPageStack() "ScheduleClearRecoveryPageStack bundleName = %{public}s, callerUid = %{public}d, tokenId = %{public}d", bundleName.c_str(), callerUid, tokenId); (void)DelayedSingleton::GetInstance()-> - DeleteAppExitReason(bundleName, callerUid); + DeleteAppExitReason(bundleName, tokenId); (void)DelayedSingleton::GetInstance()-> DeleteAllRecoverInfoByTokenId(tokenId); } diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index ebd09d89d8..9362a0811d 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -727,7 +727,8 @@ int AbilityManagerStub::UninstallAppInner(MessageParcel &data, MessageParcel &re { std::string bundleName = Str16ToStr8(data.ReadString16()); int32_t uid = data.ReadInt32(); - int result = UninstallApp(bundleName, uid); + int32_t appIndex = data.ReadInt32(); + int32_t result = UninstallApp(bundleName, uid, appIndex); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "remove stack error"); return ERR_INVALID_VALUE; @@ -740,7 +741,8 @@ int32_t AbilityManagerStub::UpgradeAppInner(MessageParcel &data, MessageParcel & std::string bundleName = Str16ToStr8(data.ReadString16()); int32_t uid = data.ReadInt32(); std::string exitMsg = Str16ToStr8(data.ReadString16()); - int result = UpgradeApp(bundleName, uid, exitMsg); + int32_t appIndex = data.ReadInt32(); + int32_t result = UpgradeApp(bundleName, uid, exitMsg, appIndex); if (!reply.WriteInt32(result)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "UpgradeAppInner error"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/app_exit_reason_data_manager.cpp b/services/abilitymgr/src/app_exit_reason_data_manager.cpp index 6c24d6ba23..2bf9de65c8 100644 --- a/services/abilitymgr/src/app_exit_reason_data_manager.cpp +++ b/services/abilitymgr/src/app_exit_reason_data_manager.cpp @@ -95,7 +95,7 @@ int32_t AppExitReasonDataManager::SetAppExitReason(const std::string &bundleName const std::vector &abilityList, const AAFwk::ExitReason &exitReason) { auto accessTokenIdStr = std::to_string(accessTokenId); - if (bundleName.empty() || accessTokenIdStr.empty()) { + if (bundleName.empty() || accessTokenId == Security::AccessToken::INVALID_TOKENID) { TAG_LOGW(AAFwkTag::ABILITYMGR, "invalid value"); return ERR_INVALID_VALUE; } @@ -124,7 +124,8 @@ int32_t AppExitReasonDataManager::SetAppExitReason(const std::string &bundleName return ERR_OK; } -int32_t AppExitReasonDataManager::DeleteAppExitReason(const std::string &bundleName, int32_t uid) + +int32_t AppExitReasonDataManager::DeleteAppExitReason(const std::string &bundleName, int32_t uid, int32_t appIndex) { int32_t userId; if (DelayedSingleton::GetInstance()-> @@ -132,9 +133,14 @@ int32_t AppExitReasonDataManager::DeleteAppExitReason(const std::string &bundleN TAG_LOGE(AAFwkTag::ABILITYMGR, "Get GetOsAccountLocalIdFromUid failed."); return ERR_INVALID_VALUE; } - uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, 0); + uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, appIndex); + return DeleteAppExitReason(bundleName, accessTokenId); +} + +int32_t AppExitReasonDataManager::DeleteAppExitReason(const std::string &bundleName, uint32_t accessTokenId) +{ auto accessTokenIdStr = std::to_string(accessTokenId); - if (bundleName.empty() || accessTokenIdStr.empty()) { + if (bundleName.empty() || accessTokenId == Security::AccessToken::INVALID_TOKENID) { TAG_LOGW(AAFwkTag::ABILITYMGR, "invalid value."); return ERR_INVALID_VALUE; } @@ -178,7 +184,7 @@ int32_t AppExitReasonDataManager::GetAppExitReason(const std::string &bundleName const std::string &abilityName, bool &isSetReason, AAFwk::ExitReason &exitReason) { auto accessTokenIdStr = std::to_string(accessTokenId); - if (bundleName.empty() || accessTokenIdStr.empty()) { + if (bundleName.empty() || accessTokenId == Security::AccessToken::INVALID_TOKENID) { TAG_LOGW(AAFwkTag::ABILITYMGR, "invalid value!"); return ERR_INVALID_VALUE; } diff --git a/services/abilitymgr/src/app_exit_reason_helper.cpp b/services/abilitymgr/src/app_exit_reason_helper.cpp index b5608752fe..1f11ab24bd 100644 --- a/services/abilitymgr/src/app_exit_reason_helper.cpp +++ b/services/abilitymgr/src/app_exit_reason_helper.cpp @@ -66,14 +66,15 @@ int32_t AppExitReasonHelper::RecordAppExitReason(const ExitReason &exitReason) CHECK_POINTER_AND_RETURN(subManagersHelper_, ERR_NULL_OBJECT); std::vector abilityList; + auto uid = IPCSkeleton::GetCallingUid(); if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - auto uiAbilityManager = subManagersHelper_->GetUIAbilityManagerByUid(IPCSkeleton::GetCallingUid()); + auto uiAbilityManager = subManagersHelper_->GetUIAbilityManagerByUid(uid); CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_NULL_OBJECT); - uiAbilityManager->GetActiveAbilityList(bundleName, abilityList); + uiAbilityManager->GetActiveAbilityList(uid, abilityList); } else { - auto missionListManager = subManagersHelper_->GetMissionListManagerByUid(IPCSkeleton::GetCallingUid()); + auto missionListManager = subManagersHelper_->GetMissionListManagerByUid(uid); CHECK_POINTER_AND_RETURN(missionListManager, ERR_NULL_OBJECT); - missionListManager->GetActiveAbilityList(bundleName, abilityList); + missionListManager->GetActiveAbilityList(uid, abilityList); } ret = DelayedSingleton::GetInstance()->NotifyAppMgrRecordExitReason(pid, exitReason.reason, @@ -109,7 +110,7 @@ int32_t AppExitReasonHelper::RecordProcessExitReason(const int32_t pid, const Ex return RecordProcessExitReason(pid, bundleName, application.uid, application.accessTokenId, exitReason); } -int32_t AppExitReasonHelper::RecordProcessExitReason(const std::string &bundleName, int32_t uid, +int32_t AppExitReasonHelper::RecordAppExitReason(const std::string &bundleName, int32_t uid, int32_t appIndex, const ExitReason &exitReason) { int32_t userId; @@ -118,7 +119,7 @@ int32_t AppExitReasonHelper::RecordProcessExitReason(const std::string &bundleNa TAG_LOGE(AAFwkTag::ABILITYMGR, "Get GetOsAccountLocalIdFromUid failed."); return ERR_INVALID_VALUE; } - uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, 0); + uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, appIndex); return RecordProcessExitReason(NO_PID, bundleName, uid, accessTokenId, exitReason); } @@ -138,11 +139,9 @@ int32_t AppExitReasonHelper::RecordProcessExitReason(const int32_t pid, const st } std::vector abilityLists; if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { - GetActiveAbilityListFromUIAabilityManager(bundleName, abilityLists, targetUserId, pid); - } else if (targetUserId == U0_USER_ID) { - GetActiveAbilityListByU0(bundleName, abilityLists, pid); - } else { - GetActiveAbilityListByUser(bundleName, abilityLists, targetUserId, pid); + GetActiveAbilityListFromUIAbilityManager(uid, abilityLists, pid); + } else { + GetActiveAbilityList(uid, abilityLists, pid); } auto ret = DelayedSingleton::GetInstance()->NotifyAppMgrRecordExitReason(pid, exitReason.reason, @@ -192,31 +191,60 @@ int32_t AppExitReasonHelper::RecordProcessExtensionExitReason( return appExitReasonDataMgr->SetUIExtensionAbilityExitReason(bundleName, extensionList, exitReason); } -void AppExitReasonHelper::GetActiveAbilityListByU0(const std::string bundleName, - std::vector &abilityLists, const int32_t pid) +void AppExitReasonHelper::GetActiveAbilityList(int32_t uid, std::vector &abilityLists, + const int32_t pid) { - CHECK_POINTER(subManagersHelper_); - auto missionListManagers = subManagersHelper_->GetMissionListManagers(); - for (auto& item: missionListManagers) { - if (!item.second) { - continue; - } - std::vector abilityList; - item.second->GetActiveAbilityList(bundleName, abilityList, pid); - if (!abilityList.empty()) { - abilityLists.insert(abilityLists.end(), abilityList.begin(), abilityList.end()); - } + int32_t targetUserId; + if (DelayedSingleton::GetInstance()-> + GetOsAccountLocalIdFromUid(uid, targetUserId) != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get GetOsAccountLocalIdFromUid failed."); + return; } + CHECK_POINTER(subManagersHelper_); + if (targetUserId == U0_USER_ID) { + auto missionListManagers = subManagersHelper_->GetMissionListManagers(); + for (auto& item: missionListManagers) { + CHECK_POINTER_CONTINUE(item.second); + std::vector abilityList; + item.second->GetActiveAbilityList(uid, abilityList, pid); + if (!abilityList.empty()) { + abilityLists.insert(abilityLists.end(), abilityList.begin(), abilityList.end()); + } + } + return; + } + + auto listManager = subManagersHelper_->GetMissionListManagerByUserId(targetUserId); + CHECK_POINTER(listManager); + listManager->GetActiveAbilityList(uid, abilityLists, pid); } -void AppExitReasonHelper::GetActiveAbilityListByUser(const std::string bundleName, - std::vector &abilityLists, const int32_t targetUserId, const int32_t pid) +void AppExitReasonHelper::GetActiveAbilityListFromUIAbilityManager(int32_t uid, std::vector &abilityLists, + const int32_t pid) { CHECK_POINTER(subManagersHelper_); - auto listManager = subManagersHelper_->GetMissionListManagerByUserId(targetUserId); - if (listManager) { - listManager->GetActiveAbilityList(bundleName, abilityLists, pid); + int32_t targetUserId; + if (DelayedSingleton::GetInstance()-> + GetOsAccountLocalIdFromUid(uid, targetUserId) != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get GetOsAccountLocalIdFromUid failed."); + return; } + if (targetUserId == U0_USER_ID) { + auto uiAbilityManagers = subManagersHelper_->GetUIAbilityManagers(); + for (auto& item: uiAbilityManagers) { + CHECK_POINTER_CONTINUE(item.second); + std::vector abilityList; + item.second->GetActiveAbilityList(uid, abilityList, pid); + if (!abilityList.empty()) { + abilityLists.insert(abilityLists.end(), abilityList.begin(), abilityList.end()); + } + } + return; + } + + auto uiAbilityManager = subManagersHelper_->GetUIAbilityManagerByUserId(targetUserId); + CHECK_POINTER(uiAbilityManager); + uiAbilityManager->GetActiveAbilityList(uid, abilityLists, pid); } bool AppExitReasonHelper::IsExitReasonValid(const ExitReason &exitReason) @@ -224,23 +252,5 @@ bool AppExitReasonHelper::IsExitReasonValid(const ExitReason &exitReason) const Reason reason = exitReason.reason; return reason >= REASON_MIN || reason <= REASON_MAX; } - -void AppExitReasonHelper::GetActiveAbilityListFromUIAabilityManager(const std::string bundleName, - std::vector &abilityLists, const int32_t targetUserId, const int32_t pid) -{ - CHECK_POINTER(subManagersHelper_); - if (targetUserId == U0_USER_ID) { - auto uiAbilityManagers = subManagersHelper_->GetUIAbilityManagers(); - for (auto& item: uiAbilityManagers) { - if (item.second) { - item.second->GetActiveAbilityList(bundleName, abilityLists, pid); - } - } - } else { - auto uiAbilityManager = subManagersHelper_->GetUIAbilityManagerByUserId(targetUserId); - CHECK_POINTER(uiAbilityManager); - uiAbilityManager->GetActiveAbilityList(bundleName, abilityLists, pid); - } -} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index ecb7d609b8..815b523b67 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -464,8 +464,7 @@ int32_t MissionList::GetMissionCount() const return static_cast(missions_.size()); } -void MissionList::GetActiveAbilityList(const std::string &bundleName, std::vector &abilityList, - int32_t pid) +void MissionList::GetActiveAbilityList(int32_t uid, std::vector &abilityList, int32_t pid) { for (auto mission : missions_) { if (!mission) { @@ -482,7 +481,7 @@ void MissionList::GetActiveAbilityList(const std::string &bundleName, std::vecto } const AppExecFwk::AbilityInfo &abilityInfo = abilityRecord->GetAbilityInfo(); - if (abilityInfo.bundleName == bundleName && !abilityInfo.name.empty()) { + if (abilityInfo.applicationInfo.uid == uid && !abilityInfo.name.empty()) { TAG_LOGD(AAFwkTag::ABILITYMGR, "find ability name is %{public}s", abilityInfo.name.c_str()); abilityList.push_back(abilityInfo.name); } diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index d8b1bf0be3..ca5e4d07b3 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -4027,14 +4027,13 @@ int MissionListManager::DoAbilityForeground(std::shared_ptr &abil return ERR_OK; } -void MissionListManager::GetActiveAbilityList(const std::string &bundleName, std::vector &abilityList, - int32_t pid) +void MissionListManager::GetActiveAbilityList(int32_t uid, std::vector &abilityList, int32_t pid) { std::lock_guard guard(managerLock_); for (auto missionList : currentMissionLists_) { if (missionList != nullptr) { std::vector currentActiveAbilities; - missionList->GetActiveAbilityList(bundleName, currentActiveAbilities, pid); + missionList->GetActiveAbilityList(uid, currentActiveAbilities, pid); if (!currentActiveAbilities.empty()) { abilityList.insert(abilityList.end(), currentActiveAbilities.begin(), currentActiveAbilities.end()); } @@ -4043,7 +4042,7 @@ void MissionListManager::GetActiveAbilityList(const std::string &bundleName, std if (defaultStandardList_ != nullptr) { std::vector defaultActiveStandardList; - defaultStandardList_->GetActiveAbilityList(bundleName, defaultActiveStandardList, pid); + defaultStandardList_->GetActiveAbilityList(uid, defaultActiveStandardList, pid); if (!defaultActiveStandardList.empty()) { abilityList.insert(abilityList.end(), defaultActiveStandardList.begin(), defaultActiveStandardList.end()); } @@ -4051,7 +4050,7 @@ void MissionListManager::GetActiveAbilityList(const std::string &bundleName, std if (defaultSingleList_ != nullptr) { std::vector defaultActiveSingleList; - defaultSingleList_->GetActiveAbilityList(bundleName, defaultActiveSingleList, pid); + defaultSingleList_->GetActiveAbilityList(uid, defaultActiveSingleList, pid); if (!defaultActiveSingleList.empty()) { abilityList.insert(abilityList.end(), defaultActiveSingleList.begin(), defaultActiveSingleList.end()); } @@ -4094,16 +4093,12 @@ bool MissionListManager::IsAppLastAbility(const std::shared_ptr & return false; } - std::string bundleName = abilityRecord->GetAbilityInfo().bundleName; - if (bundleName.empty()) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName is empty."); - return false; - } + auto uid = abilityRecord->GetAbilityInfo().applicationInfo.uid; std::vector abilityList; for (auto missionList : currentMissionLists_) { if (missionList != nullptr) { - missionList->GetActiveAbilityList(bundleName, abilityList); + missionList->GetActiveAbilityList(uid, abilityList); } } diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 076ffceb93..451ae057d0 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -1903,8 +1903,7 @@ std::shared_ptr UIAbilityLifecycleManager::GetAbilityRecordsById( return search->second; } -void UIAbilityLifecycleManager::GetActiveAbilityList(const std::string &bundleName, - std::vector &abilityList, int32_t pid) +void UIAbilityLifecycleManager::GetActiveAbilityList(int32_t uid, std::vector &abilityList, int32_t pid) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); std::lock_guard guard(sessionLock_); @@ -1918,7 +1917,7 @@ void UIAbilityLifecycleManager::GetActiveAbilityList(const std::string &bundleNa continue; } const auto &abilityInfo = abilityRecord->GetAbilityInfo(); - if (abilityInfo.bundleName == bundleName && !abilityInfo.name.empty()) { + if (abilityInfo.applicationInfo.uid == uid && !abilityInfo.name.empty()) { std::string abilityName = abilityInfo.name; if (abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD && abilityRecord->GetSessionInfo() != nullptr) { 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 b7f3e3be1d..bfd571ef16 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 @@ -119,6 +119,7 @@ public: MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); MOCK_METHOD2(SendWantSender, int(sptr target, const SenderInfo& senderInfo)); 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 95e6b82909..69f9b1ccdf 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 @@ -72,6 +72,7 @@ public: MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); MOCK_METHOD4(CompelVerifyPermission, int(const std::string& permission, int pid, int uid, std::string& message)); @@ -252,6 +253,7 @@ public: MOCK_METHOD1(RemoveStack, int(int id)); MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2(MoveMissionToEnd, int(const sptr& token, const bool nonFirst)); MOCK_METHOD1(IsFirstInMission, bool(const sptr& token)); MOCK_METHOD4(CompelVerifyPermission, int(const std::string& permission, int pid, int uid, std::string& message)); 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 eea499963f..f4fc557896 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 @@ -67,6 +67,7 @@ public: MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD1(TerminateAbilityByRecordId, int(const int64_t recordId)); MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId)); 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 1a83ee69d9..a179c60339 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 @@ -111,6 +111,7 @@ public: MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); MOCK_METHOD2(SendWantSender, int(sptr target, const SenderInfo& senderInfo)); 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 1dad4bd71a..825569be06 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 @@ -112,6 +112,7 @@ public: MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); MOCK_METHOD2(SendWantSender, int(sptr target, const SenderInfo& senderInfo)); diff --git a/test/moduletest/mock/include/mock_ability_manager_proxy.h b/test/moduletest/mock/include/mock_ability_manager_proxy.h index 989ddbb47b..3bd86053c7 100644 --- a/test/moduletest/mock/include/mock_ability_manager_proxy.h +++ b/test/moduletest/mock/include/mock_ability_manager_proxy.h @@ -57,6 +57,7 @@ public: MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); MOCK_METHOD2(KillProcess, int(const std::string&, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string&, int32_t, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD3(StartAbility, int(const Want& want, const sptr& callerToken, int requestCode)); MOCK_METHOD2( diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index e57037032f..3c503b9025 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -65,6 +65,7 @@ public: MOCK_METHOD2(GetAbilityTokenByCalleeObj, void(const sptr &callStub, sptr &token)); MOCK_METHOD2(KillProcess, int(const std::string&, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string&, int32_t)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string&, int32_t, int32_t)); MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); 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 6b3de757c1..610866b1cf 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 @@ -1052,6 +1052,27 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UninstallApp_001, TestSize EXPECT_EQ(res, NO_ERROR); } +/* + * Feature: AbilityManagerService + * Function: UninstallApp + * SubFunction: NA + * FunctionPoints: AbilityManagerService UninstallApp + * EnvConditions: NA + * CaseDescription: Verify the normal process of UninstallApp + */ +HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UninstallApp_002, TestSize.Level1) +{ + EXPECT_CALL(*mock_, SendRequest(_, _, _, _)) + .Times(1) + .WillOnce(Invoke(mock_.GetRefPtr(), &AbilityManagerStubMock::InvokeSendRequest)); + std::string bundleName = ""; + int32_t uid = 1; + int32_t appIndex = 0; + auto res = proxy_->UninstallApp(bundleName, uid, appIndex); + EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::UNINSTALL_APP), mock_->code_); + EXPECT_EQ(res, NO_ERROR); +} + /* * Feature: AbilityManagerService * Function: UpgradeApp @@ -1068,7 +1089,8 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_UpgradeApp_001, TestSize.L std::string bundleName = ""; int32_t uid = 1; std::string exitMsg = "App upgrade."; - auto res = proxy_->UpgradeApp(bundleName, uid, exitMsg); + int32_t appIndex = 0; + auto res = proxy_->UpgradeApp(bundleName, uid, exitMsg, appIndex); EXPECT_EQ(static_cast(AbilityManagerInterfaceCode::UPGRADE_APP), mock_->code_); EXPECT_EQ(res, NO_ERROR); } 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 437e9cee9d..060125e209 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 @@ -220,7 +220,8 @@ public: return 0; } - virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg) + virtual int32_t UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg, + int32_t appIndex) { return 0; } diff --git a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp index dc1fa5528e..d0d0e5c7a3 100644 --- a/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp +++ b/test/unittest/ability_manager_service_first_test/ability_manager_service_first_test.cpp @@ -1132,7 +1132,8 @@ HWTEST_F(AbilityManagerServiceFirstTest, UpgradeApp_001, TestSize.Level1) std::string bundleName = ""; int32_t uid = 1; std::string exitMsg = "App upgrade."; - EXPECT_EQ(abilityMs_->UpgradeApp(bundleName, uid, exitMsg), ERR_NULL_OBJECT); + int32_t appIndex = 0; + EXPECT_EQ(abilityMs_->UpgradeApp(bundleName, uid, exitMsg, appIndex), ERR_NULL_OBJECT); TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceFirstTest UpgradeApp_001 end"); } diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index 6019d0afd3..5f2edd67cc 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -91,6 +91,7 @@ public: MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); MOCK_METHOD2(SendWantSender, int(sptr target, const SenderInfo& senderInfo)); diff --git a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp index 8c139a582e..a397d682a7 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp +++ b/test/unittest/ui_ability_lifecycle_manager_test/ui_ability_lifecycle_manager_test.cpp @@ -39,6 +39,7 @@ namespace OHOS { namespace AAFwk { namespace { const std::string DLP_INDEX = "ohos.dlp.params.index"; +constexpr int32_t TEST_UID = 20010001; }; class UIAbilityLifecycleManagerTest : public testing::Test { public: @@ -2854,10 +2855,9 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetActiveAbilityList_001, TestSize.Level AbilityRequest abilityRequest; auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord); - std::string bundleName = "com.example.unittest"; std::vector abilityList; int32_t pid = 100; - uiAbilityLifecycleManager->GetActiveAbilityList(bundleName, abilityList, pid); + uiAbilityLifecycleManager->GetActiveAbilityList(TEST_UID, abilityList, pid); uiAbilityLifecycleManager.reset(); } @@ -2875,13 +2875,13 @@ HWTEST_F(UIAbilityLifecycleManagerTest, GetActiveAbilityList_002, TestSize.Level abilityRequest.abilityInfo.name = "testAbility"; abilityRequest.abilityInfo.moduleName = "testModule"; abilityRequest.abilityInfo.bundleName = "com.example.unittest"; + abilityRequest.abilityInfo.applicationInfo.uid = TEST_UID; auto abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); abilityRecord->SetOwnerMissionUserId(DelayedSingleton::GetInstance()->GetUserId()); uiAbilityLifecycleManager->sessionAbilityMap_.emplace(1, abilityRecord); - std::string bundleName = "com.example.unittest"; std::vector abilityList; int32_t pid = 100; - uiAbilityLifecycleManager->GetActiveAbilityList(bundleName, abilityList, pid); + uiAbilityLifecycleManager->GetActiveAbilityList(TEST_UID, abilityList, pid); uiAbilityLifecycleManager.reset(); } diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 9bd184342a..4c2a0bc296 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -72,6 +72,7 @@ public: MOCK_METHOD2(KillProcess, int(const std::string& bundleName, const bool clearPageStack)); MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD3(UninstallApp, int32_t(const std::string& bundleName, int32_t uid, int32_t appIndex)); MOCK_METHOD2( GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); From 1eed275b5c7c36b530f1ed71b64025d39bfd7581 Mon Sep 17 00:00:00 2001 From: xia Date: Tue, 25 Jun 2024 10:30:41 +0800 Subject: [PATCH 050/148] =?UTF-8?q?=E4=BF=AE=E5=A4=8Damsdialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xia --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 3a3097785b..47cf1c9592 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -207,6 +207,7 @@ struct SelectorPhoneDialog { .rowsGap(12) .margin({ top: 30 }) .height(210) + .align(Alignment.Center) }, item => item) } .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 }) From c876b14a1014c5b34c268ea48769e8a6faceab68 Mon Sep 17 00:00:00 2001 From: wentao Date: Thu, 20 Jun 2024 22:05:56 +0800 Subject: [PATCH 051/148] fix cj abilityStageContext Signed-off-by: wentao Change-Id: Ia1d5409ba5f1a5494f817657ee7086cc4fb76206 Signed-off-by: wentao --- .../ability_runtime/app/cj_ability_stage.cpp | 29 +++++++++++++------ .../app/cj_ability_stage_object.cpp | 9 ++++++ frameworks/native/runtime/cj_runtime.cpp | 2 +- .../ability_runtime/app/cj_ability_stage.h | 2 ++ .../app/cj_ability_stage_object.h | 2 ++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/app/cj_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/cj_ability_stage.cpp index d5b269c86f..78605a1c37 100644 --- a/frameworks/native/appkit/ability_runtime/app/cj_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/cj_ability_stage.cpp @@ -80,34 +80,45 @@ std::shared_ptr CJAbilityStage::Create( const std::unique_ptr& runtime, const AppExecFwk::HapModuleInfo& hapModuleInfo) { if (!runtime) { - HILOG_ERROR("Runtime does not exist."); + TAG_LOGE(AAFwkTag::APPKIT, "Runtime does not exist."); return nullptr; } auto& cjRuntime = static_cast(*runtime); // Load cj app library. if (!cjRuntime.IsAppLibLoaded()) { - HILOG_ERROR("Failed to create CJAbilityStage, applib not loaded."); + TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage, applib not loaded."); return nullptr; } auto cjAbilityStageObject = CJAbilityStageObject::LoadModule(hapModuleInfo.moduleName); if (cjAbilityStageObject == nullptr) { cjRuntime.UnLoadCJAppLibrary(); - HILOG_ERROR("Failed to create CJAbilityStage."); + TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage."); return nullptr; } return std::make_shared(cjAbilityStageObject); } +void CJAbilityStage::Init(const std::shared_ptr &context, + const std::weak_ptr application) +{ + AbilityStage::Init(context, application); + if (!cjAbilityStageObject_) { + TAG_LOGE(AAFwkTag::APPKIT, "Failed to create CJAbilityStage."); + return; + } + cjAbilityStageObject_->Init(this); +} + void CJAbilityStage::OnCreate(const AAFwk::Want& want) const { AbilityStage::OnCreate(want); if (!cjAbilityStageObject_) { - HILOG_ERROR("CJAbilityStage is not loaded."); + TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded."); return; } - HILOG_DEBUG("CJAbilityStage::OnCreate"); + TAG_LOGD(AAFwkTag::APPKIT, "CJAbilityStage::OnCreate"); cjAbilityStageObject_->OnCreate(); } @@ -115,7 +126,7 @@ std::string CJAbilityStage::OnAcceptWant(const AAFwk::Want& want) { AbilityStage::OnAcceptWant(want); if (!cjAbilityStageObject_) { - HILOG_ERROR("CJAbilityStage is not loaded."); + TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded."); return ""; } return cjAbilityStageObject_->OnAcceptWant(want); @@ -126,12 +137,12 @@ void CJAbilityStage::OnConfigurationUpdated(const AppExecFwk::Configuration& con AbilityStage::OnConfigurationUpdated(configuration); auto fullConfig = GetContext()->GetConfiguration(); if (!fullConfig) { - HILOG_ERROR("configuration is nullptr."); + TAG_LOGE(AAFwkTag::APPKIT, "configuration is nullptr."); return; } if (!cjAbilityStageObject_) { - HILOG_ERROR("CJAbilityStage is not loaded."); + TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded."); return; } cjAbilityStageObject_->OnConfigurationUpdated(fullConfig); @@ -141,7 +152,7 @@ void CJAbilityStage::OnMemoryLevel(int level) { AbilityStage::OnMemoryLevel(level); if (!cjAbilityStageObject_) { - HILOG_ERROR("CJAbilityStage is not loaded."); + TAG_LOGE(AAFwkTag::APPKIT, "CJAbilityStage is not loaded."); return; } cjAbilityStageObject_->OnMemoryLevel(level); diff --git a/frameworks/native/appkit/ability_runtime/app/cj_ability_stage_object.cpp b/frameworks/native/appkit/ability_runtime/app/cj_ability_stage_object.cpp index 3eb0669d0d..841dba3dc8 100644 --- a/frameworks/native/appkit/ability_runtime/app/cj_ability_stage_object.cpp +++ b/frameworks/native/appkit/ability_runtime/app/cj_ability_stage_object.cpp @@ -67,6 +67,15 @@ CJAbilityStageObject::~CJAbilityStageObject() id_ = 0; } +void CJAbilityStageObject::Init(AbilityStageHandle abilityStage) const +{ + if (g_cjAbilityStageFuncs == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "cj functions for CJAbilityStage are not registered"); + return; + } + g_cjAbilityStageFuncs->AbilityStageInit(id_, abilityStage); +} + void CJAbilityStageObject::OnCreate() const { if (g_cjAbilityStageFuncs == nullptr) { diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index 200b04d214..059f004345 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -87,7 +87,7 @@ bool CJRuntime::Initialize(const Options& options) void CJRuntime::RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo) { - HILOG_INFO("RegisterUncaughtExceptionHandler not support yet"); + OHOS::CJEnvironment::GetInstance()->RegisterCJUncaughtExceptionHandler(uncaughtExceptionInfo); } bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) diff --git a/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage.h b/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage.h index 4cd03a8a37..aeb4194f0c 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage.h @@ -57,6 +57,8 @@ public: std::shared_ptr cjStage) : cjAbilityStageObject_(std::move(cjStage)) {} ~CJAbilityStage() override = default; + void Init(const std::shared_ptr &context, + const std::weak_ptr application) override; void OnCreate(const AAFwk::Want& want) const override; std::string OnAcceptWant(const AAFwk::Want& want) override; void OnConfigurationUpdated(const AppExecFwk::Configuration& configuration) override; diff --git a/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage_object.h b/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage_object.h index dd512f1e07..44a7ff7005 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage_object.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/cj_ability_stage_object.h @@ -46,6 +46,7 @@ struct CJAbilityStageFuncs { char* (*AbilityStageOnAcceptWant)(int64_t handle, OHOS::AAFwk::Want* want); void (*AbilityStageOnConfigurationUpdated)(int64_t id, CJConfiguration configuration); void (*AbilityStageOnMemoryLevel)(int64_t id, int32_t level); + void (*AbilityStageInit)(int64_t id, void* abilityStage); }; CJ_EXPORT void RegisterCJAbilityStageFuncs(void (*registerFunc)(CJAbilityStageFuncs* result)); @@ -60,6 +61,7 @@ public: explicit CJAbilityStageObject(int64_t id) : id_(id) {} ~CJAbilityStageObject(); + void Init(AbilityStageHandle abilityStage) const; void OnCreate() const; std::string OnAcceptWant(const AAFwk::Want& want) const; void OnConfigurationUpdated(const std::shared_ptr& configuration) const; From 7474ff12a7a5039897b40dea9302bc35bbcf3c34 Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Tue, 25 Jun 2024 10:48:50 +0800 Subject: [PATCH 052/148] fix: do not use reference in task Signed-off-by: yangxuguang-huawei Change-Id: If9401b1e6dc97c0294dcf6bd81ff8f5107191a9b --- services/appmgr/src/ams_mgr_scheduler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 709bfa1f4c..26e4fb0ed4 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -251,7 +251,7 @@ void AmsMgrScheduler::KillProcessesByPids(std::vector &pids) return; } - std::function killProcessesByPidsFunc = [amsMgrServiceInner = amsMgrServiceInner_, &pids]() { + std::function killProcessesByPidsFunc = [amsMgrServiceInner = amsMgrServiceInner_, pids]() mutable { amsMgrServiceInner->KillProcessesByPids(pids); }; amsHandler_->SubmitTask(killProcessesByPidsFunc, TASK_KILL_PROCESSES_BY_PIDS); From fb1ebe8dfe16c14b1ff6434e7cb95405973d8305 Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Tue, 25 Jun 2024 11:29:00 +0800 Subject: [PATCH 053/148] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E6=95=8F=E6=84=9F=E4=BF=A1=E6=81=AF=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- .../ability/native/ability_runtime/js_ability_context.cpp | 3 +-- .../native/ability/native/js_service_extension_context.cpp | 3 +-- .../native/ui_extension_ability/js_ui_extension_context.cpp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index 645ca75aec..8e627cb01f 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -532,7 +532,7 @@ napi_value JsAbilityContext::OnOpenLink(napi_env env, NapiCallbackInfo& info) { StartAsyncTrace(HITRACE_TAG_ABILITY_MANAGER, TRACE_ATOMIC_SERVICE, TRACE_ATOMIC_SERVICE_ID); HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::CONTEXT, "OnOpenLink"); + TAG_LOGD(AAFwkTag::CONTEXT, "OnOpenLink"); std::string linkValue(""); AAFwk::OpenLinkOptions openLinkOptions; @@ -547,7 +547,6 @@ napi_value JsAbilityContext::OnOpenLink(napi_env env, NapiCallbackInfo& info) return CreateJsUndefined(env); } - TAG_LOGI(AAFwkTag::CONTEXT, "open link:%{public}s.", linkValue.c_str()); want.SetUri(linkValue); int requestCode = -1; if (CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_function)) { diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 1b4feb27f6..649e9cdb57 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -301,7 +301,7 @@ private: napi_value OnOpenLink(napi_env env, NapiCallbackInfo& info) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::SERVICE_EXT, "OnOpenLink"); + TAG_LOGD(AAFwkTag::SERVICE_EXT, "OnOpenLink"); std::string linkValue(""); AAFwk::OpenLinkOptions openLinkOptions; @@ -315,7 +315,6 @@ private: return CreateJsUndefined(env); } - TAG_LOGI(AAFwkTag::SERVICE_EXT, "open link:%{public}s.", linkValue.c_str()); want.SetUri(linkValue); auto innerErrorCode = std::make_shared(ERR_OK); diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp index 1182fabbee..80a3458fba 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_context.cpp @@ -289,7 +289,7 @@ static bool ParseOpenLinkParams(const napi_env &env, const NapiCallbackInfo &inf napi_value JsUIExtensionContext::OnOpenLink(napi_env env, NapiCallbackInfo& info) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - TAG_LOGI(AAFwkTag::UI_EXT, "OnOpenLink"); + TAG_LOGD(AAFwkTag::UI_EXT, "OnOpenLink"); std::string linkValue(""); AAFwk::OpenLinkOptions openLinkOptions; @@ -304,7 +304,6 @@ napi_value JsUIExtensionContext::OnOpenLink(napi_env env, NapiCallbackInfo& info return CreateJsUndefined(env); } - TAG_LOGI(AAFwkTag::UI_EXT, "open link:%{public}s.", linkValue.c_str()); want.SetUri(linkValue); int requestCode = -1; if (CheckTypeForNapiValue(env, info.argv[INDEX_TWO], napi_function)) { From 5c3b67c5f9e5bd02b809127d477f434b33fe12ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Tue, 25 Jun 2024 07:15:47 +0000 Subject: [PATCH 054/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 1 + 1 file changed, 1 insertion(+) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 47cf1c9592..ddad988c87 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -199,6 +199,7 @@ struct SelectorPhoneDialog { }) } .margin({ top: 85 }) + .align(Alignment.Center) }, item => item) } .columnsTemplate(this.selector.swiper.gridColumns) From 5419f3e1b2072a80a4bc8f49fb9946eef221f0e6 Mon Sep 17 00:00:00 2001 From: XKK Date: Sat, 22 Jun 2024 14:03:24 +0800 Subject: [PATCH 055/148] test wantAgent Signed-off-by: XKK --- frameworks/js/napi/wantagent/napi_want_agent.cpp | 8 +++++--- frameworks/js/napi/wantagent/napi_want_agent.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frameworks/js/napi/wantagent/napi_want_agent.cpp b/frameworks/js/napi/wantagent/napi_want_agent.cpp index 243b73d9f8..5238fc0762 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.cpp +++ b/frameworks/js/napi/wantagent/napi_want_agent.cpp @@ -75,7 +75,7 @@ void TriggerCompleteCallBack::SetCallbackInfo(napi_env env, NativeReference* ref triggerCompleteInfo_.nativeRef.reset(ref); } -void TriggerCompleteCallBack::SetWantAgentInstance(WantAgent* wantAgent) +void TriggerCompleteCallBack::SetWantAgentInstance(std::shared_ptr wantAgent) { triggerCompleteInfo_.wantAgent = wantAgent; } @@ -222,7 +222,9 @@ void TriggerCompleteCallBack::OnSendFinished( dataWorker->resultExtras = resultExtras; dataWorker->env = triggerCompleteInfo_.env; dataWorker->nativeRef = std::move(triggerCompleteInfo_.nativeRef); - dataWorker->wantAgent = triggerCompleteInfo_.wantAgent; + if (triggerCompleteInfo_.wantAgent != nullptr) { + dataWorker->wantAgent = new WantAgent(triggerCompleteInfo_.wantAgent->GetPendingWant()); + } work->data = static_cast(dataWorker); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, OnSendFinishedUvAfterWorkCallback); if (ret != 0) { @@ -745,7 +747,7 @@ int32_t JsWantAgent::UnWrapTriggerInfoParam(napi_env env, napi_callback_info inf napi_ref ref = nullptr; napi_create_reference(env, argv[ARGC_TWO], 1, &ref); triggerObj->SetCallbackInfo(env, reinterpret_cast(ref)); - triggerObj->SetWantAgentInstance(pWantAgent); + triggerObj->SetWantAgentInstance(std::make_shared(pWantAgent->GetPendingWant())); return BUSINESS_ERROR_CODE_OK; } diff --git a/frameworks/js/napi/wantagent/napi_want_agent.h b/frameworks/js/napi/wantagent/napi_want_agent.h index 763266ce3a..ed3b5c527a 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.h +++ b/frameworks/js/napi/wantagent/napi_want_agent.h @@ -51,7 +51,7 @@ const uint8_t NUMBER_OF_PARAMETERS_NINE = 9; class TriggerCompleteCallBack; struct CallbackInfo { - WantAgent* wantAgent = nullptr; + std::shared_ptr wantAgent; napi_env env = nullptr; std::unique_ptr nativeRef = nullptr; }; @@ -123,7 +123,7 @@ public: void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData, const AAFwk::WantParams &resultExtras) override; void SetCallbackInfo(napi_env env, NativeReference* ref); - void SetWantAgentInstance(WantAgent* wantAgent); + void SetWantAgentInstance(std::shared_ptr wantAgent); private: CallbackInfo triggerCompleteInfo_; From c63fd65db886f439ec7da3a023944264bb6e710b Mon Sep 17 00:00:00 2001 From: m30043719 Date: Tue, 25 Jun 2024 17:01:42 +0800 Subject: [PATCH 056/148] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=9C=AA=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: m30043719 --- .../distributed_mission_manager.cpp | 1 - .../ability_manager_client_branch_test.cpp | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp index 9906b0b7fa..72c650645d 100644 --- a/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp +++ b/frameworks/js/napi/mission_manager/distributed_mission_manager.cpp @@ -840,7 +840,6 @@ void OffExecuteCB(napi_env env, OnCB *onCB) onCB->onRegistration->DelOnCallbackCBRef(env, onCB->onCallbackCB.napiCallback); if (!onCB->onRegistration->GetOnCallbackCBRef().empty()) { TAG_LOGI(AAFwkTag::MISSION, "There are still other remaining callback"); - return; } DmsSaClient::GetInstance().DelListener(onCB->type, onCB->onRegistration); if (onCB->result == NO_ERROR) { diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp index e18967d846..346b1cff88 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_client_branch_test.cpp @@ -1639,6 +1639,20 @@ HWTEST_F(AbilityManagerClientBranchTest, RegisterOffListener_0100, TestSize.Leve EXPECT_EQ(result, ERR_OK); } +/** + * @tc.name: AbilityManagerClient_RegisterOffListener_0200 + * @tc.desc: RegisterOffListener + * @tc.type: FUNC + * @tc.require: issue + */ +HWTEST_F(AbilityManagerClientBranchTest, RegisterOffListener_0200, TestSize.Level1) +{ + std::string type = "continueStateChange"; + sptr listener = nullptr; + auto result = client_->RegisterOffListener(type, listener); + EXPECT_EQ(result, ERR_OK); +} + /** * @tc.name: AbilityManagerClient_RequestDialogService_0100 * @tc.desc: RequestDialogService From 99dc75784232ba21f41b419f1b18d074faddc3b4 Mon Sep 17 00:00:00 2001 From: zhaoleyi Date: Tue, 25 Jun 2024 11:16:30 +0800 Subject: [PATCH 057/148] =?UTF-8?q?=E4=BF=AE=E6=94=B9requestModalUIExtensi?= =?UTF-8?q?on=E5=BC=82=E6=AD=A5=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaoleyi Change-Id: I93f7433aa6ced285204473e19e62c0967535512d --- .../ability_runtime/js_ability_context.cpp | 39 +++++++++---------- .../native/js_service_extension_context.cpp | 23 ++++++----- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index 645ca75aec..079bada0e8 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -2047,39 +2047,38 @@ napi_value JsAbilityContext::OnStartAbilityByType(napi_env env, NapiCallbackInfo napi_value JsAbilityContext::OnRequestModalUIExtension(napi_env env, NapiCallbackInfo& info) { TAG_LOGD(AAFwkTag::CONTEXT, "called"); - if (info.argc < ARGC_ONE) { ThrowTooFewParametersError(env); return CreateJsUndefined(env); } - AAFwk::Want want; if (!AppExecFwk::UnwrapWant(env, info.argv[0], want)) { TAG_LOGE(AAFwkTag::CONTEXT, "Failed to parse want!"); ThrowInvalidParamError(env, "Parse param want failed, want must be Want."); return CreateJsUndefined(env); } - - NapiAsyncTask::CompleteCallback complete = - [weak = context_, want](napi_env env, NapiAsyncTask& task, int32_t status) { - auto context = weak.lock(); - if (!context) { - TAG_LOGW(AAFwkTag::CONTEXT, "context is released"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - return; - } - auto errcode = context->RequestModalUIExtension(want); - if (errcode == 0) { - task.Resolve(env, CreateJsUndefined(env)); - } else { - task.Reject(env, CreateJsErrorByNativeErr(env, errcode)); - } - }; - + auto innerErrCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = [abilityContext = context_, want, innerErrCode]() { + auto context = abilityContext.lock(); + if (!context) { + TAG_LOGE(AAFwkTag::APPKIT, "context is released"); + *innerErrCode = static_cast(AbilityErrorCode::ERROR_CODE_INNER); + return; + } + *innerErrCode = AAFwk::AbilityManagerClient::GetInstance()->RequestModalUIExtension(want); + }; + NapiAsyncTask::CompleteCallback complete = [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) { + if (*innerErrCode == ERR_OK) { + task.Resolve(env, CreateJsUndefined(env)); + } else { + TAG_LOGE(AAFwkTag::APPKIT, "OnRequestModalUIExtension is failed %{public}d", *innerErrCode); + task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode)); + } + }; napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JsAbilityContext::OnRequestModalUIExtension", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result)); return result; } diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 1b4feb27f6..e5acc32b30 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -1017,27 +1017,30 @@ private: ThrowInvalidParamError(env, "Parse param want failed, must be a Want."); return CreateJsUndefined(env); } - - NapiAsyncTask::CompleteCallback complete = - [weak = context_, want](napi_env env, NapiAsyncTask& task, int32_t status) { - auto context = weak.lock(); + + auto innerErrCode = std::make_shared(ERR_OK); + NapiAsyncTask::ExecuteCallback execute = [serviceContext = context_, want, innerErrCode]() { + auto context = serviceContext.lock(); if (!context) { - TAG_LOGW(AAFwkTag::SERVICE_EXT, "context is released"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + TAG_LOGE(AAFwkTag::APPKIT, "context is released"); + *innerErrCode = static_cast(AbilityErrorCode::ERROR_CODE_INNER); return; } - auto errcode = context->RequestModalUIExtension(want); - if (errcode == 0) { + *innerErrCode = AAFwk::AbilityManagerClient::GetInstance()->RequestModalUIExtension(want); + }; + NapiAsyncTask::CompleteCallback complete = [innerErrCode](napi_env env, NapiAsyncTask& task, int32_t status) { + if (*innerErrCode == ERR_OK) { task.Resolve(env, CreateJsUndefined(env)); } else { - task.Reject(env, CreateJsErrorByNativeErr(env, errcode)); + TAG_LOGE(AAFwkTag::APPKIT, "OnRequestModalUIExtension is failed %{public}d", *innerErrCode); + task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrCode)); } }; napi_value lastParam = (info.argc > ARGC_ONE) ? info.argv[ARGC_ONE] : nullptr; napi_value result = nullptr; NapiAsyncTask::ScheduleHighQos("JSServiceExtensionContext::OnRequestModalUIExtension", - env, CreateAsyncTaskWithLastParam(env, lastParam, nullptr, std::move(complete), &result)); + env, CreateAsyncTaskWithLastParam(env, lastParam, std::move(execute), std::move(complete), &result)); return result; } From c250107017e8fc6e03fe4b486cdc61bd4635433a Mon Sep 17 00:00:00 2001 From: jsjzju Date: Mon, 24 Jun 2024 00:26:11 +0800 Subject: [PATCH 058/148] =?UTF-8?q?autofill=E4=BB=A3=E7=A0=81=E9=87=8D?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jsjzju Change-Id: I1898b23f75aa20787c1a305f7c738117a61f486c --- .../js_auto_fill_manager.cpp | 3 +- .../include/auto_fill_extension_callback.h | 31 +- .../include/auto_fill_manager.h | 71 ++--- .../src/auto_fill_extension_callback.cpp | 284 ++++++++++++------ .../src/auto_fill_manager.cpp | 217 ++++--------- .../auto_fill_manager_test.cpp | 122 +------- 6 files changed, 305 insertions(+), 423 deletions(-) diff --git a/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.cpp b/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.cpp index 8e3e109202..bbd3ede5db 100644 --- a/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.cpp +++ b/frameworks/js/napi/auto_fill_manager/js_auto_fill_manager.cpp @@ -107,7 +107,8 @@ void JsAutoFillManager::OnRequestAutoSaveInner(napi_env env, int32_t instanceId, AutoFill::AutoFillRequest request; uiContent->DumpViewData(request.viewData, request.autoFillType); request.autoFillCommand = AutoFill::AutoFillCommand::SAVE; - auto ret = AutoFillManager::GetInstance().RequestAutoSave(uiContent, request, saveRequestCallback); + AbilityRuntime::AutoFill::AutoFillResult result; + auto ret = AutoFillManager::GetInstance().RequestAutoSave(uiContent, request, saveRequestCallback, result); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Request auto save error[%{public}d].", ret); ThrowError(env, GetJsErrorCodeByNativeError(ret)); diff --git a/interfaces/inner_api/auto_fill_manager/include/auto_fill_extension_callback.h b/interfaces/inner_api/auto_fill_manager/include/auto_fill_extension_callback.h index 84b1028214..6a228a8f86 100644 --- a/interfaces/inner_api/auto_fill_manager/include/auto_fill_extension_callback.h +++ b/interfaces/inner_api/auto_fill_manager/include/auto_fill_extension_callback.h @@ -32,50 +32,54 @@ enum AutoFillWindowType { POPUP_WINDOW }; } +#ifdef SUPPORT_GRAPHICS class AutoFillExtensionCallback : public std::enable_shared_from_this { public: - AutoFillExtensionCallback() = default; + AutoFillExtensionCallback(); ~AutoFillExtensionCallback() = default; void OnResult(int32_t errCode, const AAFwk::Want &want); void OnRelease(int32_t errCode); void OnError(int32_t errCode, const std::string &name, const std::string &message); void OnReceive(const AAFwk::WantParams &wantParams); -#ifdef SUPPORT_GRAPHICS void onRemoteReady(const std::shared_ptr &modalUIExtensionProxy); -#endif // SUPPORT_GRAPHICS void onDestroy(); void SetFillRequestCallback(const std::shared_ptr &callback); void SetSaveRequestCallback(const std::shared_ptr &callback); void SetSessionId(int32_t sessionId); -#ifdef SUPPORT_GRAPHICS void SetInstanceId(int32_t instanceId); int32_t GetInstanceId(); -#endif // SUPPORT_GRAPHICS - void SetEventId(uint32_t eventId); void SetWindowType(const AutoFill::AutoFillWindowType &autoFillWindowType); + AutoFill::AutoFillWindowType GetWindowType() const; void SetExtensionType(bool isSmartAutoFill); void SetAutoFillType(const AbilityBase::AutoFillType &autoFillType); void SetViewData(const AbilityBase::ViewData &viewData); void SetAutoFillRequestConfig(const AutoFill::AutoFillCustomConfig &config); - AbilityBase::ViewData GetViewData(); + uint32_t GetCallbackId() const; void HandleTimeOut(); + void UpdateCustomPopupUIExtension(const AbilityBase::ViewData &viewData); private: - void SendAutoFillSucess(const AAFwk::Want &want); + void SendAutoFillSuccess(const AAFwk::Want &want); void SendAutoFillFailed(int32_t errCode, const AAFwk::Want &want = AAFwk::Want()); - void CloseModalUIExtension(); + void CloseUIExtension(); void HandleReloadInModal(const AAFwk::WantParams &wantParams); + int32_t ReloadInModal(const AAFwk::WantParams &wantParams); + void UpdateCustomPopupConfig(const AAFwk::WantParams &wantParams); + void SetModalUIExtensionProxy(const std::shared_ptr& proxy); + std::shared_ptr GetModalUIExtensionProxy(); + std::shared_ptr GetFillRequestCallback(); + std::shared_ptr GetSaveRequestCallback(); + uint32_t GenerateCallbackId(); + std::mutex requestCallbackMutex_; std::shared_ptr fillCallback_; std::shared_ptr saveCallback_; int32_t sessionId_; -#ifdef SUPPORT_GRAPHICS int32_t instanceId_ = -1; -#endif // SUPPORT_GRAPHICS - uint32_t eventId_ = 0; + uint32_t callbackId_ = 0; AutoFill::AutoFillWindowType autoFillWindowType_ = AutoFill::AutoFillWindowType::MODAL_WINDOW; AbilityBase::ViewData viewData_; AutoFill::AutoFillCustomConfig autoFillCustomConfig_; @@ -85,7 +89,10 @@ private: AAFwk::Want want_; int32_t errCode_ = 0; AbilityBase::AutoFillType autoFillType_ = AbilityBase::AutoFillType::UNSPECIFIED; + std::mutex proxyMutex_; + std::shared_ptr modalUIExtensionProxy_; }; +#endif // SUPPORT_GRAPHICS } // AbilityRuntime } // OHOS #endif // OHOS_ABILITY_RUNTIME_AUTO_FILL_EXTENSION_CALLBACK_H diff --git a/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h b/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h index e6eab20570..c486882d4c 100644 --- a/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h +++ b/interfaces/inner_api/auto_fill_manager/include/auto_fill_manager.h @@ -22,6 +22,7 @@ #include "auto_fill_event_handler.h" #include "auto_fill_extension_callback.h" #include "fill_request_callback_interface.h" +#include "nocopyable.h" #include "save_request_callback_interface.h" #include "task_handler_wrap.h" #ifdef SUPPORT_GRAPHICS @@ -53,77 +54,59 @@ struct AutoFillRequest { AutoFillCustomConfig config; }; -/** - * @struct ReloadInModalRequest - * ReloadInModalRequest is used to define the reload in modal request parameter structure. - */ -#ifdef SUPPORT_GRAPHICS -struct ReloadInModalRequest { - int32_t instanceId = -1; - bool isSmartAutoFill = false; - int32_t nodeId; - std::string customData; - AutoFillWindowType autoFillWindowType; - AbilityBase::AutoFillType autoFillType = AbilityBase::AutoFillType::UNSPECIFIED; - std::shared_ptr extensionCallback; +struct AutoFillResult { + bool isPopup = false; + uint32_t autoFillSessionId = 0; }; - } +#ifdef SUPPORT_GRAPHICS class AutoFillManager { public: - AutoFillManager() = default; - ~AutoFillManager(); - static AutoFillManager &GetInstance(); - int32_t RequestAutoFill( - Ace::UIContent *uiContent, - const AutoFill::AutoFillRequest &request, - const std::shared_ptr &fillCallback, bool &isPopup); + int32_t RequestAutoFill(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, + const std::shared_ptr &fillCallback, AutoFill::AutoFillResult &result); - int32_t RequestAutoSave( - Ace::UIContent *uiContent, - const AutoFill::AutoFillRequest &request, - const std::shared_ptr &saveCallback); - void UpdateCustomPopupUIExtension(Ace::UIContent *uiContent, const AbilityBase::ViewData &viewData); - int32_t UpdateCustomPopupConfig(int32_t instanceId, const Ace::CustomPopupUIExtensionConfig &popupConfig); - void SetAutoFillExtensionProxy(int32_t instanceId, - const std::shared_ptr &modalUIExtensionProxy); - void RemoveAutoFillExtensionProxy(int32_t instanceId); - int32_t ReloadInModal(const AutoFill::ReloadInModalRequest &request); + int32_t RequestAutoSave(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, + const std::shared_ptr &saveCallback, AutoFill::AutoFillResult &result); + + void UpdateCustomPopupUIExtension(uint32_t autoFillSessionId, const AbilityBase::ViewData &viewData); void HandleTimeOut(uint32_t eventId); + void SetTimeOutEvent(uint32_t eventId); void RemoveEvent(uint32_t eventId); -private: - int32_t HandleRequestExecuteInner( - Ace::UIContent *uiContent, - const AutoFill::AutoFillRequest &request, + void BindModalUIExtensionCallback(const std::shared_ptr &extensionCallback, + Ace::ModalUIExtensionCallbacks &callback); + void RemoveAutoFillExtensionCallback(uint32_t callbackId); +private: + AutoFillManager(); + ~AutoFillManager(); + DISALLOW_COPY_AND_MOVE(AutoFillManager); + + int32_t HandleRequestExecuteInner(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, const std::shared_ptr &fillCallback, - const std::shared_ptr &saveCallback, bool &isPopup); + const std::shared_ptr &saveCallback, + AutoFill::AutoFillResult &result); + int32_t CreateAutoFillExtension(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, const Ace::ModalUIExtensionCallbacks &callback, const AutoFill::AutoFillWindowType &autoFillWindowType, bool isSmartAutoFill); - void BindModalUIExtensionCallback( - const std::shared_ptr &extensionCallback, Ace::ModalUIExtensionCallbacks &callback); - void SetTimeOutEvent(uint32_t eventId); bool ConvertAutoFillWindowType(const AutoFill::AutoFillRequest &request, bool &isSmartAutoFill, AutoFill::AutoFillWindowType &autoFillWindowType); + std::shared_ptr GetAutoFillExtensionCallback(uint32_t callbackId); bool IsPreviousRequestFinished(Ace::UIContent *uiContent); bool IsNeed2SaveRequest(const AbilityBase::ViewData &viewData, bool &isSmartAutoFill); std::mutex extensionCallbacksMutex_; - std::mutex modalProxyMapMutex_; - std::map> extensionCallbacks_; + std::map> extensionCallbacks_; - std::map> modalUIExtensionProxyMap_; - uint32_t eventId_ = 0; std::shared_ptr eventHandler_; -#endif // SUPPORT_GRAPHICS }; +#endif // SUPPORT_GRAPHICS } // AbilityRuntime } // OHOS #endif // OHOS_ABILITY_RUNTIME_AUTO_FILL_MANAGER_H \ No newline at end of file diff --git a/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp b/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp index c1eaf02065..6f8f7e1736 100644 --- a/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp +++ b/interfaces/inner_api/auto_fill_manager/src/auto_fill_extension_callback.cpp @@ -14,34 +14,48 @@ */ #include "auto_fill_extension_callback.h" +#include + #include "auto_fill_error.h" #include "auto_fill_manager.h" #include "auto_fill_manager_util.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" +#include "int_wrapper.h" +#include "string_wrapper.h" #include "view_data.h" namespace OHOS { namespace AbilityRuntime { namespace { -constexpr static char WANT_PARAMS_VIEW_DATA_KEY[] = "ohos.ability.params.viewData"; #ifdef SUPPORT_GRAPHICS -constexpr static char WANT_PARAMS_CUSTOM_DATA_KEY[] = "ohos.ability.params.customData"; -constexpr static char WANT_PARAMS_AUTO_FILL_EVENT_KEY[] = "ability.want.params.AutoFillEvent"; -constexpr static char WANT_PARAMS_AUTO_FILL_CMD_KEY[] = "ohos.ability.params.autoFillCmd"; -constexpr static char WANT_PARAMS_UPDATE_POPUP_WIDTH[] = "ohos.ability.params.popupWidth"; -constexpr static char WANT_PARAMS_UPDATE_POPUP_HEIGHT[] = "ohos.ability.params.popupHeight"; -constexpr static char WANT_PARAMS_UPDATE_POPUP_PLACEMENT[] = "ohos.ability.params.popupPlacement"; +constexpr const char* WANT_PARAMS_VIEW_DATA_KEY = "ohos.ability.params.viewData"; +constexpr const char* WANT_PARAMS_AUTO_FILL_CMD_KEY = "ohos.ability.params.autoFillCmd"; +constexpr const char* WANT_PARAMS_FILL_CONTENT = "ohos.ability.params.fillContent"; +constexpr const char* WANT_PARAMS_CUSTOM_DATA_KEY = "ohos.ability.params.customData"; +constexpr const char* WANT_PARAMS_AUTO_FILL_EVENT_KEY = "ability.want.params.AutoFillEvent"; +constexpr const char* WANT_PARAMS_UPDATE_POPUP_WIDTH = "ohos.ability.params.popupWidth"; +constexpr const char* WANT_PARAMS_UPDATE_POPUP_HEIGHT = "ohos.ability.params.popupHeight"; +constexpr const char* WANT_PARAMS_UPDATE_POPUP_PLACEMENT = "ohos.ability.params.popupPlacement"; +constexpr const char* WANT_PARAMS_EXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; +constexpr const char* WANT_PARAMS_EXTENSION_TYPE = "autoFill/password"; +constexpr const char* WANT_PARAMS_SMART_EXTENSION_TYPE = "autoFill/smart"; +constexpr const char* WANT_PARAMS_AUTO_FILL_TYPE_KEY = "ability.want.params.AutoFillType"; +constexpr const char* WANT_PARAMS_AUTO_FILL_POPUP_WINDOW_KEY = "ohos.ability.params.popupWindow"; #endif // SUPPORT_GRAPHICS -constexpr static char WANT_PARAMS_FILL_CONTENT[] = "ohos.ability.params.fillContent"; } // namespace + +#ifdef SUPPORT_GRAPHICS +AutoFillExtensionCallback::AutoFillExtensionCallback() +{ + callbackId_ = GenerateCallbackId(); +} + void AutoFillExtensionCallback::OnResult(int32_t errCode, const AAFwk::Want &want) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called, result code is %{public}d.", errCode); -#ifdef SUPPORT_GRAPHICS - AutoFillManager::GetInstance().RemoveEvent(eventId_); - CloseModalUIExtension(); -#endif // SUPPORT_GRAPHICS + AutoFillManager::GetInstance().RemoveEvent(callbackId_); + CloseUIExtension(); if (autoFillWindowType_ == AutoFill::AutoFillWindowType::POPUP_WINDOW) { isOnResult_ = true; want_ = want; @@ -50,7 +64,7 @@ void AutoFillExtensionCallback::OnResult(int32_t errCode, const AAFwk::Want &wan } if (errCode == AutoFill::AUTO_FILL_SUCCESS) { - SendAutoFillSucess(want); + SendAutoFillSuccess(want); } else { auto resultCode = (errCode == AutoFill::AUTO_FILL_CANCEL) ? AutoFill::AUTO_FILL_CANCEL : AutoFill::AUTO_FILL_FAILED; @@ -61,10 +75,8 @@ void AutoFillExtensionCallback::OnResult(int32_t errCode, const AAFwk::Want &wan void AutoFillExtensionCallback::OnRelease(int32_t errCode) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called, result code is %{public}d.", errCode); -#ifdef SUPPORT_GRAPHICS - AutoFillManager::GetInstance().RemoveEvent(eventId_); - CloseModalUIExtension(); -#endif // SUPPORT_GRAPHICS + AutoFillManager::GetInstance().RemoveEvent(callbackId_); + CloseUIExtension(); if (errCode != 0) { SendAutoFillFailed(AutoFill::AUTO_FILL_RELEASE_FAILED); } @@ -74,31 +86,22 @@ void AutoFillExtensionCallback::OnError(int32_t errCode, const std::string &name { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called, errcode is %{public}d, name is %{public}s, message is %{public}s", errCode, name.c_str(), message.c_str()); -#ifdef SUPPORT_GRAPHICS - AutoFillManager::GetInstance().RemoveEvent(eventId_); - CloseModalUIExtension(); -#endif // SUPPORT_GRAPHICS + AutoFillManager::GetInstance().RemoveEvent(callbackId_); + CloseUIExtension(); if (errCode != 0) { SendAutoFillFailed(AutoFill::AUTO_FILL_ON_ERROR); } } -#ifdef SUPPORT_GRAPHICS + void AutoFillExtensionCallback::HandleReloadInModal(const AAFwk::WantParams &wantParams) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); isReloadInModal_ = true; - AutoFillManager::GetInstance().RemoveAutoFillExtensionProxy(instanceId_); - auto customDataString(wantParams.GetStringParam(WANT_PARAMS_CUSTOM_DATA_KEY)); - AutoFill::ReloadInModalRequest request = { - .instanceId = instanceId_, - .isSmartAutoFill = isSmartAutoFill_, - .nodeId = sessionId_, - .customData = customDataString, - .autoFillWindowType = autoFillWindowType_, - .autoFillType = autoFillType_, - .extensionCallback = shared_from_this(), - }; - int32_t resultCode = AutoFillManager::GetInstance().ReloadInModal(request); + SetModalUIExtensionProxy(nullptr); + + auto oldWindowType = autoFillWindowType_; + auto oldSessionId = sessionId_; + int32_t resultCode = ReloadInModal(wantParams); if (resultCode != AutoFill::AUTO_FILL_SUCCESS) { SendAutoFillFailed(resultCode); } @@ -109,13 +112,47 @@ void AutoFillExtensionCallback::HandleReloadInModal(const AAFwk::WantParams &wan return; } - if (request.autoFillWindowType == AutoFill::AutoFillWindowType::POPUP_WINDOW) { - uiContent->DestroyCustomPopupUIExtension(request.nodeId); + if (oldWindowType == AutoFill::AutoFillWindowType::POPUP_WINDOW) { + uiContent->DestroyCustomPopupUIExtension(oldSessionId); } else { TAG_LOGW(AAFwkTag::AUTOFILLMGR, "Window type is not popup, the window can not be destroyed."); } } +int32_t AutoFillExtensionCallback::ReloadInModal(const AAFwk::WantParams &wantParams) +{ + TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); + auto uiContent = Ace::UIContent::GetUIContent(instanceId_); + if (uiContent == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Content is nullptr."); + return AutoFill::AUTO_FILL_OBJECT_IS_NULL; + } + + AutoFillManager::GetInstance().SetTimeOutEvent(callbackId_); + AAFwk::Want want; + want.SetParam(WANT_PARAMS_AUTO_FILL_CMD_KEY, static_cast(AutoFill::AutoFillCommand::RELOAD_IN_MODAL)); + want.SetParam(WANT_PARAMS_CUSTOM_DATA_KEY, wantParams.GetStringParam(WANT_PARAMS_CUSTOM_DATA_KEY)); + isSmartAutoFill_ ? want.SetParam(WANT_PARAMS_EXTENSION_TYPE_KEY, std::string(WANT_PARAMS_SMART_EXTENSION_TYPE)) : + want.SetParam(WANT_PARAMS_EXTENSION_TYPE_KEY, std::string(WANT_PARAMS_EXTENSION_TYPE)); + want.SetParam(WANT_PARAMS_AUTO_FILL_TYPE_KEY, static_cast(autoFillType_)); + want.SetParam(WANT_PARAMS_VIEW_DATA_KEY, viewData_.ToJsonString()); + want.SetParam(WANT_PARAMS_AUTO_FILL_POPUP_WINDOW_KEY, false); + Ace::ModalUIExtensionCallbacks callback; + AutoFillManager::GetInstance().BindModalUIExtensionCallback(shared_from_this(), callback); + Ace::ModalUIExtensionConfig config; + config.isAsyncModalBinding = true; + int32_t sessionId = 0; + sessionId = uiContent->CreateModalUIExtension(want, callback, config); + if (sessionId == 0) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Create ui extension is failed."); + AutoFillManager::GetInstance().RemoveEvent(callbackId_); + return AutoFill::AUTO_FILL_CREATE_MODULE_UI_EXTENSION_FAILED; + } + SetSessionId(sessionId); + SetWindowType(AutoFill::AutoFillWindowType::MODAL_WINDOW); + return AutoFill::AUTO_FILL_SUCCESS; +} + void AutoFillExtensionCallback::OnReceive(const AAFwk::WantParams &wantParams) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); @@ -124,34 +161,42 @@ void AutoFillExtensionCallback::OnReceive(const AAFwk::WantParams &wantParams) HandleReloadInModal(wantParams); return; } else if (cmdValue == static_cast(AutoFill::AutoFillCommand::RESIZE)) { - Ace::CustomPopupUIExtensionConfig popupConfig; - if (wantParams.HasParam(WANT_PARAMS_UPDATE_POPUP_WIDTH) && - wantParams.HasParam(WANT_PARAMS_UPDATE_POPUP_HEIGHT)) { - Ace::PopupSize popupSize; - popupSize.width = wantParams.GetIntParam(WANT_PARAMS_UPDATE_POPUP_WIDTH, 0); - popupSize.height = wantParams.GetIntParam(WANT_PARAMS_UPDATE_POPUP_HEIGHT, 0); - popupConfig.targetSize = popupSize; - } - if (wantParams.HasParam(WANT_PARAMS_UPDATE_POPUP_PLACEMENT)) { - popupConfig.placement = - static_cast(wantParams.GetIntParam(WANT_PARAMS_UPDATE_POPUP_PLACEMENT, 0)); - } - Ace::CustomPopupUIExtensionConfig popupConfigToConvert; - AutoFillManagerUtil::ConvertToPopupUIExtensionConfig(autoFillCustomConfig_, popupConfigToConvert); - popupConfig.nodeId = sessionId_; - popupConfig.isFocusable = popupConfigToConvert.isFocusable; - popupConfig.isShowInSubWindow = popupConfigToConvert.isShowInSubWindow; - popupConfig.isEnableArrow = popupConfigToConvert.isEnableArrow; - auto updateResult = AutoFillManager::GetInstance().UpdateCustomPopupConfig(instanceId_, popupConfig); - if (updateResult != AutoFill::AUTO_FILL_SUCCESS) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Update custom popup config failed."); - } + UpdateCustomPopupConfig(wantParams); } if (wantParams.GetIntParam(WANT_PARAMS_AUTO_FILL_EVENT_KEY, 0) == AutoFill::AUTO_FILL_CANCEL_TIME_OUT) { - AutoFillManager::GetInstance().RemoveEvent(eventId_); + AutoFillManager::GetInstance().RemoveEvent(callbackId_); } } +void AutoFillExtensionCallback::UpdateCustomPopupConfig(const AAFwk::WantParams &wantParams) +{ + TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); + Ace::CustomPopupUIExtensionConfig popupConfig; + if (wantParams.HasParam(WANT_PARAMS_UPDATE_POPUP_WIDTH) && + wantParams.HasParam(WANT_PARAMS_UPDATE_POPUP_HEIGHT)) { + Ace::PopupSize popupSize; + popupSize.width = wantParams.GetIntParam(WANT_PARAMS_UPDATE_POPUP_WIDTH, 0); + popupSize.height = wantParams.GetIntParam(WANT_PARAMS_UPDATE_POPUP_HEIGHT, 0); + popupConfig.targetSize = popupSize; + } + if (wantParams.HasParam(WANT_PARAMS_UPDATE_POPUP_PLACEMENT)) { + popupConfig.placement = + static_cast(wantParams.GetIntParam(WANT_PARAMS_UPDATE_POPUP_PLACEMENT, 0)); + } + Ace::CustomPopupUIExtensionConfig popupConfigToConvert; + AutoFillManagerUtil::ConvertToPopupUIExtensionConfig(autoFillCustomConfig_, popupConfigToConvert); + popupConfig.nodeId = sessionId_; + popupConfig.isFocusable = popupConfigToConvert.isFocusable; + popupConfig.isShowInSubWindow = popupConfigToConvert.isShowInSubWindow; + popupConfig.isEnableArrow = popupConfigToConvert.isEnableArrow; + auto uiContent = Ace::UIContent::GetUIContent(instanceId_); + if (uiContent == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UIContent is nullptr."); + return; + } + uiContent->UpdateCustomPopupUIExtension(popupConfig); +} + void AutoFillExtensionCallback::onRemoteReady(const std::shared_ptr &modalUIExtensionProxy) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); @@ -159,9 +204,9 @@ void AutoFillExtensionCallback::onRemoteReady(const std::shared_ptr &callback) { + std::lock_guard lock(requestCallbackMutex_); fillCallback_ = callback; } +std::shared_ptr AutoFillExtensionCallback::GetFillRequestCallback() +{ + std::lock_guard lock(requestCallbackMutex_); + return fillCallback_; +} + void AutoFillExtensionCallback::SetSaveRequestCallback(const std::shared_ptr &callback) { + std::lock_guard lock(requestCallbackMutex_); saveCallback_ = callback; } +std::shared_ptr AutoFillExtensionCallback::GetSaveRequestCallback() +{ + std::lock_guard lock(requestCallbackMutex_); + return saveCallback_; +} + void AutoFillExtensionCallback::SetSessionId(int32_t sessionId) { sessionId_= sessionId; } -#ifdef SUPPORT_GRAPHICS + void AutoFillExtensionCallback::SetInstanceId(int32_t instanceId) { instanceId_ = instanceId; @@ -210,17 +267,17 @@ int32_t AutoFillExtensionCallback::GetInstanceId() { return instanceId_; } -#endif // SUPPORT_GRAPHICS -void AutoFillExtensionCallback::SetEventId(uint32_t eventId) -{ - eventId_ = eventId; -} void AutoFillExtensionCallback::SetWindowType(const AutoFill::AutoFillWindowType &autoFillWindowType) { autoFillWindowType_ = autoFillWindowType; } +AutoFill::AutoFillWindowType AutoFillExtensionCallback::GetWindowType() const +{ + return autoFillWindowType_; +} + void AutoFillExtensionCallback::SetViewData(const AbilityBase::ViewData &viewData) { viewData_ = viewData; @@ -241,53 +298,90 @@ void AutoFillExtensionCallback::SetAutoFillType(const AbilityBase::AutoFillType autoFillType_ = autoFillType; } -AbilityBase::ViewData AutoFillExtensionCallback::GetViewData() -{ - return viewData_; -} - void AutoFillExtensionCallback::HandleTimeOut() { -#ifdef SUPPORT_GRAPHICS - CloseModalUIExtension(); -#endif + CloseUIExtension(); SendAutoFillFailed(AutoFill::AUTO_FILL_REQUEST_TIME_OUT); } -void AutoFillExtensionCallback::SendAutoFillSucess(const AAFwk::Want &want) +uint32_t AutoFillExtensionCallback::GenerateCallbackId() +{ + static std::atomic callbackId(0); + ++callbackId; + return callbackId.load(); +} + +uint32_t AutoFillExtensionCallback::GetCallbackId() const +{ + return callbackId_; +} + +void AutoFillExtensionCallback::SetModalUIExtensionProxy(const std::shared_ptr& proxy) +{ + std::lock_guard lock(proxyMutex_); + modalUIExtensionProxy_ = proxy; +} + +std::shared_ptr AutoFillExtensionCallback::GetModalUIExtensionProxy() +{ + std::lock_guard lock(proxyMutex_); + return modalUIExtensionProxy_; +} + +void AutoFillExtensionCallback::UpdateCustomPopupUIExtension(const AbilityBase::ViewData &viewData) +{ + auto modalUIExtensionProxy = GetModalUIExtensionProxy(); + if (modalUIExtensionProxy == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UIExtensionProxy is nullptr."); + return; + } + AAFwk::WantParams wantParams; + wantParams.SetParam(WANT_PARAMS_AUTO_FILL_CMD_KEY, + AAFwk::Integer::Box(static_cast(AutoFill::AutoFillCommand::UPDATE))); + wantParams.SetParam(WANT_PARAMS_VIEW_DATA_KEY, AAFwk::String::Box(viewData.ToJsonString())); + modalUIExtensionProxy->SendData(wantParams); +} + +void AutoFillExtensionCallback::SendAutoFillSuccess(const AAFwk::Want &want) { TAG_LOGI(AAFwkTag::AUTOFILLMGR, "Called."); - if (fillCallback_ != nullptr) { + auto fillCallback = GetFillRequestCallback(); + if (fillCallback != nullptr) { std::string dataStr = want.GetStringParam(WANT_PARAMS_VIEW_DATA_KEY); AbilityBase::ViewData viewData; viewData.FromJsonString(dataStr.c_str()); - fillCallback_->OnFillRequestSuccess(viewData); - fillCallback_ = nullptr; + fillCallback->OnFillRequestSuccess(viewData); + SetFillRequestCallback(nullptr); } - if (saveCallback_ != nullptr) { - saveCallback_->OnSaveRequestSuccess(); - saveCallback_ = nullptr; + auto saveCallback = GetSaveRequestCallback(); + if (saveCallback != nullptr) { + saveCallback->OnSaveRequestSuccess(); + SetSaveRequestCallback(nullptr); } + AutoFillManager::GetInstance().RemoveAutoFillExtensionCallback(callbackId_); } void AutoFillExtensionCallback::SendAutoFillFailed(int32_t errCode, const AAFwk::Want &want) { TAG_LOGI(AAFwkTag::AUTOFILLMGR, "Called."); - if (fillCallback_ != nullptr) { + auto fillCallback = GetFillRequestCallback(); + if (fillCallback != nullptr) { std::string fillContent = want.GetStringParam(WANT_PARAMS_FILL_CONTENT); bool isPopup = (autoFillWindowType_ == AutoFill::AutoFillWindowType::POPUP_WINDOW); - fillCallback_->OnFillRequestFailed(errCode, fillContent, isPopup); - fillCallback_ = nullptr; + fillCallback->OnFillRequestFailed(errCode, fillContent, isPopup); + SetFillRequestCallback(nullptr); } - if (saveCallback_ != nullptr) { - saveCallback_->OnSaveRequestFailed(); - saveCallback_ = nullptr; + auto saveCallback = GetSaveRequestCallback(); + if (saveCallback != nullptr) { + saveCallback->OnSaveRequestFailed(); + SetSaveRequestCallback(nullptr); } + AutoFillManager::GetInstance().RemoveAutoFillExtensionCallback(callbackId_); } -#ifdef SUPPORT_GRAPHICS -void AutoFillExtensionCallback::CloseModalUIExtension() + +void AutoFillExtensionCallback::CloseUIExtension() { auto uiContent = Ace::UIContent::GetUIContent(instanceId_); if (uiContent == nullptr) { @@ -300,7 +394,7 @@ void AutoFillExtensionCallback::CloseModalUIExtension() } else if (autoFillWindowType_ == AutoFill::AutoFillWindowType::MODAL_WINDOW) { uiContent->CloseModalUIExtension(sessionId_); } - AutoFillManager::GetInstance().RemoveAutoFillExtensionProxy(instanceId_); + SetModalUIExtensionProxy(nullptr); instanceId_ = -1; } #endif // SUPPORT_GRAPHICS diff --git a/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp b/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp index 3f46888869..c025441179 100644 --- a/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp +++ b/interfaces/inner_api/auto_fill_manager/src/auto_fill_manager.cpp @@ -20,19 +20,16 @@ #include "extension_ability_info.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" -#include "int_wrapper.h" #include "parameters.h" -#include "string_wrapper.h" namespace OHOS { namespace AbilityRuntime { namespace { +#ifdef SUPPORT_GRAPHICS const std::string WANT_PARAMS_EXTENSION_TYPE = "autoFill/password"; const std::string WANT_PARAMS_SMART_EXTENSION_TYPE = "autoFill/smart"; const std::string AUTO_FILL_START_POPUP_WINDOW = "persist.sys.abilityms.autofill.is_passwd_popup_window"; -#ifdef SUPPORT_GRAPHICS constexpr static char WANT_PARAMS_VIEW_DATA_KEY[] = "ohos.ability.params.viewData"; -constexpr static char WANT_PARAMS_CUSTOM_DATA_KEY[] = "ohos.ability.params.customData"; constexpr static char WANT_PARAMS_AUTO_FILL_CMD_KEY[] = "ohos.ability.params.autoFillCmd"; constexpr static char WANT_PARAMS_AUTO_FILL_POPUP_WINDOW_KEY[] = "ohos.ability.params.popupWindow"; constexpr static char WANT_PARAMS_EXTENSION_TYPE_KEY[] = "ability.want.params.uiExtensionType"; @@ -49,18 +46,19 @@ AutoFillManager &AutoFillManager::GetInstance() return instance; } +AutoFillManager::AutoFillManager() +{ + auto runner = AppExecFwk::EventRunner::Create(AUTO_FILL_MANAGER_THREAD); + eventHandler_ = std::make_shared(runner); +} + AutoFillManager::~AutoFillManager() { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - if (eventHandler_ != nullptr) { - eventHandler_.reset(); - } } -int32_t AutoFillManager::RequestAutoFill( - Ace::UIContent *uiContent, - const AutoFill::AutoFillRequest &request, - const std::shared_ptr &fillCallback, bool &isPopup) +int32_t AutoFillManager::RequestAutoFill(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, + const std::shared_ptr &fillCallback, AutoFill::AutoFillResult &result) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); if (uiContent == nullptr || fillCallback == nullptr) { @@ -72,28 +70,24 @@ int32_t AutoFillManager::RequestAutoFill( TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Auto fill type is invalid."); return AutoFill::AUTO_FILL_TYPE_INVALID; } - return HandleRequestExecuteInner(uiContent, request, fillCallback, nullptr, isPopup); + return HandleRequestExecuteInner(uiContent, request, fillCallback, nullptr, result); } -int32_t AutoFillManager::RequestAutoSave( - Ace::UIContent *uiContent, - const AutoFill::AutoFillRequest &request, - const std::shared_ptr &saveCallback) +int32_t AutoFillManager::RequestAutoSave(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, + const std::shared_ptr &saveCallback, AutoFill::AutoFillResult &result) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); if (uiContent == nullptr || saveCallback == nullptr) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UIContent or save callback is nullptr."); return AutoFill::AUTO_FILL_OBJECT_IS_NULL; } - bool isPopup = false; - return HandleRequestExecuteInner(uiContent, request, nullptr, saveCallback, isPopup); + return HandleRequestExecuteInner(uiContent, request, nullptr, saveCallback, result); } -int32_t AutoFillManager::HandleRequestExecuteInner( - Ace::UIContent *uiContent, - const AutoFill::AutoFillRequest &request, +int32_t AutoFillManager::HandleRequestExecuteInner(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, const std::shared_ptr &fillCallback, - const std::shared_ptr &saveCallback, bool &isPopup) + const std::shared_ptr &saveCallback, + AutoFill::AutoFillResult &result) { if (uiContent == nullptr || (fillCallback == nullptr && saveCallback == nullptr)) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UIContent or fillCallback&saveCallback is nullptr."); @@ -103,10 +97,6 @@ int32_t AutoFillManager::HandleRequestExecuteInner( TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Previous request is not finished."); return AutoFill::AUTO_FILL_PREVIOUS_REQUEST_NOT_FINISHED; } - { - std::lock_guard lock(extensionCallbacksMutex_); - SetTimeOutEvent(++eventId_); - } auto extensionCallback = std::make_shared(); if (fillCallback != nullptr) { @@ -121,96 +111,41 @@ int32_t AutoFillManager::HandleRequestExecuteInner( AutoFill::AutoFillWindowType autoFillWindowType = AutoFill::AutoFillWindowType::MODAL_WINDOW; if (!ConvertAutoFillWindowType(request, isSmartAutoFill, autoFillWindowType)) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Convert auto fill type failed."); - RemoveEvent(eventId_); return AutoFill::AUTO_FILL_CREATE_MODULE_UI_EXTENSION_FAILED; } - isPopup = autoFillWindowType == AutoFill::AutoFillWindowType::POPUP_WINDOW ? true : false; + auto callbackId = extensionCallback->GetCallbackId(); + SetTimeOutEvent(callbackId); + result.isPopup = autoFillWindowType == AutoFill::AutoFillWindowType::POPUP_WINDOW ? true : false; auto sessionId = CreateAutoFillExtension(uiContent, request, callback, autoFillWindowType, isSmartAutoFill); if (sessionId == AUTO_FILL_UI_EXTENSION_SESSION_ID_INVALID) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Create ui extension is failed."); - RemoveEvent(eventId_); + RemoveEvent(callbackId); return AutoFill::AUTO_FILL_CREATE_MODULE_UI_EXTENSION_FAILED; } + result.autoFillSessionId = callbackId; extensionCallback->SetInstanceId(uiContent->GetInstanceId()); extensionCallback->SetSessionId(sessionId); - extensionCallback->SetEventId(eventId_); extensionCallback->SetViewData(request.viewData); extensionCallback->SetWindowType(autoFillWindowType); extensionCallback->SetExtensionType(isSmartAutoFill); extensionCallback->SetAutoFillType(request.autoFillType); extensionCallback->SetAutoFillRequestConfig(request.config); + TAG_LOGI(AAFwkTag::AUTOFILLMGR, "callbackId: %{public}u.", callbackId); std::lock_guard lock(extensionCallbacksMutex_); - extensionCallbacks_.emplace(eventId_, extensionCallback); + extensionCallbacks_.emplace(callbackId, extensionCallback); return AutoFill::AUTO_FILL_SUCCESS; } -void AutoFillManager::UpdateCustomPopupUIExtension(Ace::UIContent *uiContent, const AbilityBase::ViewData &viewData) +void AutoFillManager::UpdateCustomPopupUIExtension(uint32_t autoFillSessionId, const AbilityBase::ViewData &viewData) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - if (uiContent == nullptr) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UIContent is nullptr."); + auto extensionCallback = GetAutoFillExtensionCallback(autoFillSessionId); + if (extensionCallback == nullptr) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Extension callback is nullptr."); return; } - - std::shared_ptr modalUIExtensionProxy; - { - std::lock_guard lock(modalProxyMapMutex_); - auto it = modalUIExtensionProxyMap_.find(uiContent->GetInstanceId()); - if (it == modalUIExtensionProxyMap_.end()) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Content is not in map."); - return; - } - modalUIExtensionProxy = it->second; - } - - if (modalUIExtensionProxy != nullptr) { - AAFwk::WantParams wantParams; - wantParams.SetParam(WANT_PARAMS_AUTO_FILL_CMD_KEY, - AAFwk::Integer::Box(static_cast(AutoFill::AutoFillCommand::UPDATE))); - wantParams.SetParam(WANT_PARAMS_VIEW_DATA_KEY, AAFwk::String::Box(viewData.ToJsonString())); - modalUIExtensionProxy->SendData(wantParams); - } -} - -int32_t AutoFillManager::UpdateCustomPopupConfig(int32_t instanceId, - const Ace::CustomPopupUIExtensionConfig &popupConfig) -{ - TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - auto uiContent = Ace::UIContent::GetUIContent(instanceId); - if (uiContent == nullptr) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "UIContent is nullptr."); - return AutoFill::AUTO_FILL_OBJECT_IS_NULL; - } - uiContent->UpdateCustomPopupUIExtension(popupConfig); - return AutoFill::AUTO_FILL_SUCCESS; -} - -void AutoFillManager::SetAutoFillExtensionProxy(int32_t instanceId, - const std::shared_ptr &modalUIExtensionProxy) -{ - TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - if (modalUIExtensionProxy == nullptr) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "proxy is nullptr."); - return; - } - - std::lock_guard lock(modalProxyMapMutex_); - auto it = modalUIExtensionProxyMap_.find(instanceId); - if (it != modalUIExtensionProxyMap_.end()) { - modalUIExtensionProxyMap_.erase(it); - } - modalUIExtensionProxyMap_.emplace(instanceId, modalUIExtensionProxy); -} - -void AutoFillManager::RemoveAutoFillExtensionProxy(int32_t instanceId) -{ - TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - std::lock_guard lock(modalProxyMapMutex_); - auto it = modalUIExtensionProxyMap_.find(instanceId); - if (it != modalUIExtensionProxyMap_.end()) { - modalUIExtensionProxyMap_.erase(it); - } + extensionCallback->UpdateCustomPopupUIExtension(viewData); } void AutoFillManager::BindModalUIExtensionCallback( @@ -229,57 +164,6 @@ void AutoFillManager::BindModalUIExtensionCallback( callback.onDestroy = std::bind(&AutoFillExtensionCallback::onDestroy, extensionCallback); } -int32_t AutoFillManager::ReloadInModal(const AutoFill::ReloadInModalRequest &request) -{ - TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - auto uiContent = Ace::UIContent::GetUIContent(request.instanceId); - if (uiContent == nullptr) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Content is nullptr."); - return AutoFill::AUTO_FILL_OBJECT_IS_NULL; - } - - if (request.extensionCallback == nullptr) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Extension callback is nullptr."); - return AutoFill::AUTO_FILL_OBJECT_IS_NULL; - } - - if (request.autoFillType == AbilityBase::AutoFillType::UNSPECIFIED) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Auto fill type is invalid."); - return AutoFill::AUTO_FILL_TYPE_INVALID; - } - - { - std::lock_guard lock(extensionCallbacksMutex_); - SetTimeOutEvent(++eventId_); - } - - AAFwk::Want want; - want.SetParam(WANT_PARAMS_AUTO_FILL_CMD_KEY, static_cast(AutoFill::AutoFillCommand::RELOAD_IN_MODAL)); - want.SetParam(WANT_PARAMS_CUSTOM_DATA_KEY, request.customData); - request.isSmartAutoFill ? want.SetParam(WANT_PARAMS_EXTENSION_TYPE_KEY, WANT_PARAMS_SMART_EXTENSION_TYPE) : - want.SetParam(WANT_PARAMS_EXTENSION_TYPE_KEY, WANT_PARAMS_EXTENSION_TYPE); - want.SetParam(WANT_PARAMS_AUTO_FILL_TYPE_KEY, static_cast(request.autoFillType)); - want.SetParam(WANT_PARAMS_VIEW_DATA_KEY, request.extensionCallback->GetViewData().ToJsonString()); - want.SetParam(WANT_PARAMS_AUTO_FILL_POPUP_WINDOW_KEY, false); - Ace::ModalUIExtensionCallbacks callback; - BindModalUIExtensionCallback(request.extensionCallback, callback); - Ace::ModalUIExtensionConfig config; - config.isAsyncModalBinding = true; - int32_t sessionId = AUTO_FILL_UI_EXTENSION_SESSION_ID_INVALID; - sessionId = uiContent->CreateModalUIExtension(want, callback, config); - if (sessionId == AUTO_FILL_UI_EXTENSION_SESSION_ID_INVALID) { - TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Create ui extension is failed."); - RemoveEvent(eventId_); - return AutoFill::AUTO_FILL_CREATE_MODULE_UI_EXTENSION_FAILED; - } - request.extensionCallback->SetSessionId(sessionId); - request.extensionCallback->SetEventId(eventId_); - request.extensionCallback->SetWindowType(AutoFill::AutoFillWindowType::MODAL_WINDOW); - std::lock_guard lock(extensionCallbacksMutex_); - extensionCallbacks_.emplace(eventId_, request.extensionCallback); - return AutoFill::AUTO_FILL_SUCCESS; -} - int32_t AutoFillManager::CreateAutoFillExtension(Ace::UIContent *uiContent, const AutoFill::AutoFillRequest &request, const Ace::ModalUIExtensionCallbacks &callback, @@ -365,10 +249,9 @@ bool AutoFillManager::ConvertAutoFillWindowType(const AutoFill::AutoFillRequest void AutoFillManager::SetTimeOutEvent(uint32_t eventId) { TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Called."); - auto runner = AppExecFwk::EventRunner::Create(AUTO_FILL_MANAGER_THREAD); if (eventHandler_ == nullptr) { - TAG_LOGD(AAFwkTag::AUTOFILLMGR, "Eventhandler is nullptr."); - eventHandler_ = std::make_shared(runner); + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Eventhandler is nullptr."); + return; } eventHandler_->SendEvent(eventId, AUTO_FILL_REQUEST_TIME_OUT_VALUE); } @@ -381,30 +264,35 @@ void AutoFillManager::RemoveEvent(uint32_t eventId) return; } eventHandler_->RemoveEvent(eventId); - - std::lock_guard lock(extensionCallbacksMutex_); - auto ret = extensionCallbacks_.find(eventId); - if (ret != extensionCallbacks_.end()) { - extensionCallbacks_.erase(ret); - } } void AutoFillManager::HandleTimeOut(uint32_t eventId) { TAG_LOGI(AAFwkTag::AUTOFILLMGR, "Called."); - std::lock_guard lock(extensionCallbacksMutex_); - auto ret = extensionCallbacks_.find(eventId); - if (ret == extensionCallbacks_.end()) { - TAG_LOGW(AAFwkTag::AUTOFILLMGR, "Event id is not find."); - return; - } - auto extensionCallback = ret->second.lock(); + auto extensionCallback = GetAutoFillExtensionCallback(eventId); if (extensionCallback == nullptr) { TAG_LOGE(AAFwkTag::AUTOFILLMGR, "Extension callback is nullptr."); return; } extensionCallback->HandleTimeOut(); - extensionCallbacks_.erase(ret); +} + +std::shared_ptr AutoFillManager::GetAutoFillExtensionCallback(uint32_t callbackId) +{ + std::lock_guard lock(extensionCallbacksMutex_); + auto iter = extensionCallbacks_.find(callbackId); + if (iter == extensionCallbacks_.end()) { + TAG_LOGE(AAFwkTag::AUTOFILLMGR, "callback is not find. callbackId: %{public}u", callbackId); + return nullptr; + } + return iter->second; +} + +void AutoFillManager::RemoveAutoFillExtensionCallback(uint32_t callbackId) +{ + TAG_LOGI(AAFwkTag::AUTOFILLMGR, "callbackId: %{public}u", callbackId); + std::lock_guard lock(extensionCallbacksMutex_); + extensionCallbacks_.erase(callbackId); } bool AutoFillManager::IsPreviousRequestFinished(Ace::UIContent *uiContent) @@ -413,12 +301,13 @@ bool AutoFillManager::IsPreviousRequestFinished(Ace::UIContent *uiContent) return false; } std::lock_guard lock(extensionCallbacksMutex_); - for (auto& item: extensionCallbacks_) { - auto extensionCallback = item.second.lock(); + for (const auto& item: extensionCallbacks_) { + auto extensionCallback = item.second; if (extensionCallback == nullptr) { continue; } - if (extensionCallback->GetInstanceId() == uiContent->GetInstanceId()) { + if (extensionCallback->GetWindowType() == AutoFill::AutoFillWindowType::MODAL_WINDOW && + extensionCallback->GetInstanceId() == uiContent->GetInstanceId()) { return false; } } diff --git a/test/unittest/auto_fill_manager_test/auto_fill_manager_test.cpp b/test/unittest/auto_fill_manager_test/auto_fill_manager_test.cpp index 026ea6ead2..9d3503a881 100644 --- a/test/unittest/auto_fill_manager_test/auto_fill_manager_test.cpp +++ b/test/unittest/auto_fill_manager_test/auto_fill_manager_test.cpp @@ -42,9 +42,6 @@ public: { return nullptr; } - - std::shared_ptr autoFillManager_ = - std::make_shared(); }; class MockModalUIExtensionProxy : public Ace::ModalUIExtensionProxy { @@ -64,19 +61,6 @@ void AutoFillManagerTest::SetUp() void AutoFillManagerTest::TearDown() {} -/** - * @tc.name: ReloadInModal_0100 - * @tc.desc: Js auto fill extension ReloadInModal. - * @tc.type: FUNC - */ -HWTEST_F(AutoFillManagerTest, ReloadInModal_0100, TestSize.Level1) -{ - AbilityRuntime::AutoFill::ReloadInModalRequest request; - ASSERT_NE(autoFillManager_, nullptr); - auto ret = autoFillManager_->ReloadInModal(request); - EXPECT_EQ(ret, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); -} - /* * Feature: AutoFillManager * Function: RequestAutoFill @@ -91,9 +75,9 @@ HWTEST_F(AutoFillManagerTest, RequestAutoFill_0100, TestSize.Level1) auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); const AbilityRuntime::AutoFill::AutoFillRequest autoFillRequest; const std::shared_ptr fillCallback = nullptr; - bool isPopup = false; - int32_t result = manager.RequestAutoFill(GetUIContent(), autoFillRequest, fillCallback, isPopup); - EXPECT_EQ(result, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); + AbilityRuntime::AutoFill::AutoFillResult result; + int32_t ret = manager.RequestAutoFill(GetUIContent(), autoFillRequest, fillCallback, result); + EXPECT_EQ(ret, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); } /* @@ -110,8 +94,9 @@ HWTEST_F(AutoFillManagerTest, RequestAutoSave_0100, TestSize.Level1) auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); const AbilityRuntime::AutoFill::AutoFillRequest autoFillRequest; const std::shared_ptr saveCallback = nullptr; - int32_t result = manager.RequestAutoSave(GetUIContent(), autoFillRequest, saveCallback); - EXPECT_EQ(result, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); + AbilityRuntime::AutoFill::AutoFillResult result; + int32_t ret = manager.RequestAutoSave(GetUIContent(), autoFillRequest, saveCallback, result); + EXPECT_EQ(ret, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); } /* @@ -130,10 +115,10 @@ HWTEST_F(AutoFillManagerTest, HandleRequestExecuteInner_0100, TestSize.Level1) const AbilityRuntime::AutoFill::AutoFillRequest autoFillRequest; const std::shared_ptr fillCallback = nullptr; const std::shared_ptr saveCallback = nullptr; - bool isPopup = false; - int32_t result = - manager.HandleRequestExecuteInner(GetUIContent(), autoFillRequest, fillCallback, saveCallback, isPopup); - EXPECT_EQ(result, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); + AbilityRuntime::AutoFill::AutoFillResult result; + int32_t ret = + manager.HandleRequestExecuteInner(GetUIContent(), autoFillRequest, fillCallback, saveCallback, result); + EXPECT_EQ(ret, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); } /* @@ -148,12 +133,8 @@ HWTEST_F(AutoFillManagerTest, SetTimeOutEvent_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AutoFillManagerTest, SetTimeOutEvent_0100, TestSize.Level1"; auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - EXPECT_EQ(manager.eventHandler_, nullptr); manager.SetTimeOutEvent(EVENT_ID); EXPECT_NE(manager.eventHandler_, nullptr); - if (manager.eventHandler_ != nullptr) { - manager.eventHandler_.reset(); - } } /* @@ -168,14 +149,10 @@ HWTEST_F(AutoFillManagerTest, RemoveEvent_0100, TestSize.Level1) { GTEST_LOG_(INFO) << "AutoFillManagerTest, SetTimeOutEvent_0100, TestSize.Level1"; auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - EXPECT_EQ(manager.eventHandler_, nullptr); manager.SetTimeOutEvent(EVENT_ID); EXPECT_NE(manager.eventHandler_, nullptr); manager.RemoveEvent(EVENT_ID); EXPECT_NE(manager.eventHandler_, nullptr); - if (manager.eventHandler_ != nullptr) { - manager.eventHandler_.reset(); - } } /* @@ -190,9 +167,8 @@ HWTEST_F(AutoFillManagerTest, RemoveEvent_0200, TestSize.Level1) { GTEST_LOG_(INFO) << "AutoFillManagerTest, RemoveEvent_0200, TestSize.Level1"; auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - EXPECT_EQ(manager.eventHandler_, nullptr); manager.RemoveEvent(EVENT_ID); - EXPECT_EQ(manager.eventHandler_, nullptr); + EXPECT_NE(manager.eventHandler_, nullptr); } /* @@ -207,76 +183,9 @@ HWTEST_F(AutoFillManagerTest, UpdateCustomPopupUIExtension_0100, TestSize.Level1 { GTEST_LOG_(INFO) << "AutoFillManagerTest, UpdateCustomPopupUIExtension_0100, TestSize.Level1"; auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - EXPECT_EQ(manager.modalUIExtensionProxyMap_.size(), 0); - auto modalUIExtensionProxy = std::make_shared(); - auto uiContent = Ace::UIContent::Create(nullptr, nullptr); - manager.modalUIExtensionProxyMap_.emplace(uiContent->GetInstanceId(), modalUIExtensionProxy); + EXPECT_EQ(manager.extensionCallbacks_.size(), 0); const AbilityBase::ViewData viewdata; - EXPECT_CALL(*modalUIExtensionProxy, SendData(_)).Times(1); - manager.UpdateCustomPopupUIExtension(uiContent.get(), viewdata); - manager.modalUIExtensionProxyMap_.clear(); -} - -/* - * Feature: AutoFillManager - * Function: UpdateCustomPopupConfig - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Verify if the UpdateCustomPopupConfig is valid. - */ -HWTEST_F(AutoFillManagerTest, UpdateCustomPopupConfig_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AutoFillManagerTest, UpdateCustomPopupConfig_0100, TestSize.Level1"; - auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - Ace::CustomPopupUIExtensionConfig customPopupUIExtensionConfig; - int32_t result = manager.UpdateCustomPopupConfig(-1, customPopupUIExtensionConfig); - EXPECT_EQ(result, AbilityRuntime::AutoFill::AUTO_FILL_OBJECT_IS_NULL); - - auto uiContent = Ace::UIContent::Create(nullptr, nullptr); - result = manager.UpdateCustomPopupConfig(uiContent->GetInstanceId(), customPopupUIExtensionConfig); - EXPECT_EQ(result, AbilityRuntime::AutoFill::AUTO_FILL_SUCCESS); -} - -/* - * Feature: AutoFillManager - * Function: SetAutoFillExtensionProxy - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Verify if the SetAutoFillExtensionProxy is valid. - */ -HWTEST_F(AutoFillManagerTest, SetAutoFillExtensionProxy_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AutoFillManagerTest, SetAutoFillExtensionProxy_0100, TestSize.Level1"; - auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - EXPECT_EQ(manager.modalUIExtensionProxyMap_.size(), 0); - auto modalUIExtensionProxy = std::make_shared(); - auto uiContent = Ace::UIContent::Create(nullptr, nullptr); - manager.SetAutoFillExtensionProxy(uiContent->GetInstanceId(), modalUIExtensionProxy); - EXPECT_EQ(manager.modalUIExtensionProxyMap_.size(), 1); - manager.modalUIExtensionProxyMap_.clear(); -} - -/* - * Feature: AutoFillManager - * Function: RemoveAutoFillExtensionProxy - * SubFunction: NA - * FunctionPoints: NA - * EnvConditions: NA - * CaseDescription: Verify if the RemoveAutoFillExtensionProxy is valid. - */ -HWTEST_F(AutoFillManagerTest, RemoveAutoFillExtensionProxy_0100, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "AutoFillManagerTest, RemoveAutoFillExtensionProxy_0100, TestSize.Level1"; - auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); - EXPECT_EQ(manager.modalUIExtensionProxyMap_.size(), 0); - auto modalUIExtensionProxy = std::make_shared(); - auto uiContent = Ace::UIContent::Create(nullptr, nullptr); - manager.modalUIExtensionProxyMap_.emplace(uiContent->GetInstanceId(), modalUIExtensionProxy); - manager.RemoveAutoFillExtensionProxy(uiContent->GetInstanceId()); - EXPECT_EQ(manager.modalUIExtensionProxyMap_.size(), 0); - manager.modalUIExtensionProxyMap_.clear(); + manager.UpdateCustomPopupUIExtension(1, viewdata); } /* @@ -293,9 +202,8 @@ HWTEST_F(AutoFillManagerTest, HandleTimeOut_0100, TestSize.Level1) auto &manager = AbilityRuntime::AutoFillManager::GetInstance(); EXPECT_EQ(manager.extensionCallbacks_.size(), 0); auto extensionCallback = std::make_shared(); - uint32_t eventId = 0; - manager.extensionCallbacks_.emplace(eventId, extensionCallback); - manager.HandleTimeOut(eventId); + manager.extensionCallbacks_.emplace(extensionCallback->GetCallbackId(), extensionCallback); + manager.HandleTimeOut(extensionCallback->GetCallbackId()); EXPECT_EQ(manager.extensionCallbacks_.size(), 0); manager.extensionCallbacks_.clear(); } From 7053dfea82b323ea8a1df6a47995d4c11399abe6 Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Tue, 25 Jun 2024 18:59:10 +0800 Subject: [PATCH 059/148] xiaoyi Signed-off-by: savior-xzh Change-Id: Ia124f6af1a6597dfd4943bb5996adfddb6e860a8 --- .../app_manager/include/appmgr/ams_mgr_interface.h | 2 +- .../app_manager/include/appmgr/ams_mgr_proxy.h | 2 +- .../app_manager/include/appmgr/app_mgr_client.h | 3 ++- .../inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp | 6 +++++- .../inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp | 3 ++- .../app_manager/src/appmgr/app_mgr_client.cpp | 4 ++-- services/abilitymgr/include/app_scheduler.h | 2 +- services/abilitymgr/src/app_scheduler.cpp | 4 ++-- .../src/scene_board/ui_ability_lifecycle_manager.cpp | 2 +- services/appmgr/include/ams_mgr_scheduler.h | 2 +- services/appmgr/include/app_mgr_service_inner.h | 2 +- services/appmgr/include/app_running_manager.h | 2 +- services/appmgr/include/app_running_record.h | 2 +- services/appmgr/src/ams_mgr_scheduler.cpp | 4 ++-- services/appmgr/src/app_mgr_service_inner.cpp | 4 ++-- services/appmgr/src/app_running_manager.cpp | 9 ++++++--- services/appmgr/src/app_running_record.cpp | 10 +++------- .../appexecfwk_core/include/appmgr/app_mgr_client.h | 2 +- .../libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp | 2 +- .../appexecfwk_core/src/appmgr/mock_app_scheduler.cpp | 2 +- .../include/mock_ams_mgr_scheduler.h | 2 +- 21 files changed, 38 insertions(+), 33 deletions(-) diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h index 701efbfee4..95d26ce919 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_interface.h @@ -168,7 +168,7 @@ public: virtual void AbilityAttachTimeOut(const sptr &token) = 0; - virtual void PrepareTerminate(const sptr &token) = 0; + virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false) = 0; virtual void GetRunningProcessInfoByToken( const sptr &token, OHOS::AppExecFwk::RunningProcessInfo &info) = 0; diff --git a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h index 0aae81ce59..d15f4ea418 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h +++ b/interfaces/inner_api/app_manager/include/appmgr/ams_mgr_proxy.h @@ -158,7 +158,7 @@ public: virtual void AbilityAttachTimeOut(const sptr &token) override; - virtual void PrepareTerminate(const sptr &token) override; + virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false) override; void GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info) override; diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index cee2046040..84cbe9d500 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -292,8 +292,9 @@ public: * Prepare terminate. * * @param token Ability identify. + * @param clearMissionFlag Clear mission flag. */ - virtual void PrepareTerminate(const sptr &token); + virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); /** * Get running process information by ability token. diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp index dc09428b71..1ae4b54443 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_proxy.cpp @@ -501,7 +501,7 @@ void AmsMgrProxy::AbilityAttachTimeOut(const sptr &token) TAG_LOGD(AAFwkTag::APPMGR, "end"); } -void AmsMgrProxy::PrepareTerminate(const sptr &token) +void AmsMgrProxy::PrepareTerminate(const sptr &token, bool clearMissionFlag) { TAG_LOGD(AAFwkTag::APPMGR, "start"); MessageParcel data; @@ -514,6 +514,10 @@ void AmsMgrProxy::PrepareTerminate(const sptr &token) TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token"); return; } + if (!data.WriteBool(clearMissionFlag)) { + TAG_LOGE(AAFwkTag::APPMGR, "Failed to write clearMissionFlag"); + return; + } int32_t ret = SendTransactCmd(static_cast(IAmsMgr::Message::PREPARE_TERMINATE_ABILITY), data, reply, option); diff --git a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp index 94c73dcac7..6bc21df8ac 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/ams_mgr_stub.cpp @@ -351,7 +351,8 @@ int32_t AmsMgrStub::HandleAbilityAttachTimeOut(MessageParcel &data, MessageParce int32_t AmsMgrStub::HandlePrepareTerminate(MessageParcel &data, MessageParcel &reply) { sptr token = data.ReadRemoteObject(); - PrepareTerminate(token); + bool clearMissionFlag = data.ReadBool(); + PrepareTerminate(token, clearMissionFlag); return NO_ERROR; } 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 597fa9e294..3e15cf4339 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 @@ -495,7 +495,7 @@ void AppMgrClient::AbilityAttachTimeOut(const sptr &token) amsService->AbilityAttachTimeOut(token); } -void AppMgrClient::PrepareTerminate(const sptr &token) +void AppMgrClient::PrepareTerminate(const sptr &token, bool clearMissionFlag) { sptr service = iface_cast(mgrHolder_->GetRemoteObject()); if (service == nullptr) { @@ -505,7 +505,7 @@ void AppMgrClient::PrepareTerminate(const sptr &token) if (amsService == nullptr) { return; } - amsService->PrepareTerminate(token); + amsService->PrepareTerminate(token, clearMissionFlag); } void AppMgrClient::GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info) diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 0503b782e2..650fd973b0 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -252,7 +252,7 @@ public: void AttachTimeOut(const sptr &token); - void PrepareTerminate(const sptr &token); + void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); void GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info); diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 9238942850..2d9c8ab11c 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -278,10 +278,10 @@ void AppScheduler::AttachTimeOut(const sptr &token) IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->AbilityAttachTimeOut(token)); } -void AppScheduler::PrepareTerminate(const sptr &token) +void AppScheduler::PrepareTerminate(const sptr &token, bool clearMissionFlag) { CHECK_POINTER(appMgrClient_); - IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->PrepareTerminate(token)); + IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->PrepareTerminate(token, clearMissionFlag)); } void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index 076ffceb93..b805eeba3f 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -1114,7 +1114,7 @@ int UIAbilityLifecycleManager::CloseUIAbilityInner(std::shared_ptr::GetInstance()->PrepareTerminate(abilityRecord->GetToken()); + DelayedSingleton::GetInstance()->PrepareTerminate(abilityRecord->GetToken(), isClearSession); abilityRecord->SetTerminatingState(); abilityRecord->SetClearMissionFlag(isClearSession); // save result to caller AbilityRecord diff --git a/services/appmgr/include/ams_mgr_scheduler.h b/services/appmgr/include/ams_mgr_scheduler.h index 38aaeca589..239cfcea42 100644 --- a/services/appmgr/include/ams_mgr_scheduler.h +++ b/services/appmgr/include/ams_mgr_scheduler.h @@ -170,7 +170,7 @@ public: virtual void AbilityAttachTimeOut(const sptr &token) override; - virtual void PrepareTerminate(const sptr &token) override; + virtual void PrepareTerminate(const sptr &token, bool clearMissionFlag = false) override; virtual void GetRunningProcessInfoByToken( const sptr &token, AppExecFwk::RunningProcessInfo &info) override; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 796dd813c7..a16ed0184a 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -592,7 +592,7 @@ public: void HandleAbilityAttachTimeOut(const sptr &token); - void PrepareTerminate(const sptr &token); + void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); void OnAppStateChanged(const std::shared_ptr &appRecord, const ApplicationState state, bool needNotifyApp, bool isFromWindowFocusChanged); diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index 305ca53f84..569cdba930 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -235,7 +235,7 @@ public: const std::string &bundleName, const int uid, std::list &pids, const bool clearPageStack = true); bool GetPidsByUserId(int32_t userId, std::list &pids); - void PrepareTerminate(const sptr &token); + void PrepareTerminate(const sptr &token, bool clearMissionFlag = false); std::shared_ptr GetTerminatingAppRunningRecord(const sptr &abilityToken); diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 7e8c361d76..5c0350f95f 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -541,7 +541,7 @@ public: bool IsLastPageAbilityRecord(const sptr &token); - bool ExtensionAbilityRecordExists(const sptr &token); + bool ExtensionAbilityRecordExists(); void SetTerminating(); diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index 576b10aeed..77e31f1a08 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -290,7 +290,7 @@ void AmsMgrScheduler::AbilityAttachTimeOut(const sptr &token) amsHandler_->SubmitTask(task); } -void AmsMgrScheduler::PrepareTerminate(const sptr &token) +void AmsMgrScheduler::PrepareTerminate(const sptr &token, bool clearMissionFlag) { TAG_LOGD(AAFwkTag::APPMGR, "Notify AppMgrService to prepare to terminate the ability."); if (!IsReady()) { @@ -301,7 +301,7 @@ void AmsMgrScheduler::PrepareTerminate(const sptr &token) TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return; } - auto task = [=]() { amsMgrServiceInner_->PrepareTerminate(token); }; + auto task = [=]() { amsMgrServiceInner_->PrepareTerminate(token, clearMissionFlag); }; amsHandler_->SubmitTask(task, AAFwk::TaskQoS::USER_INTERACTIVE); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index aa781a9abf..04dd658dcf 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -3224,14 +3224,14 @@ void AppMgrServiceInner::HandleAbilityAttachTimeOut(const sptr &t appRunningManager_->HandleAbilityAttachTimeOut(token); } -void AppMgrServiceInner::PrepareTerminate(const sptr &token) +void AppMgrServiceInner::PrepareTerminate(const sptr &token, bool clearMissionFlag) { TAG_LOGD(AAFwkTag::APPMGR, "called"); if (!appRunningManager_) { TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr"); return; } - appRunningManager_->PrepareTerminate(token); + appRunningManager_->PrepareTerminate(token, clearMissionFlag); } void AppMgrServiceInner::HandleTerminateApplicationTimeOut(const int64_t eventId) diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index b11ee0a2bc..059474d0a3 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -488,7 +488,7 @@ void AppRunningManager::HandleAbilityAttachTimeOut(const sptr &to appRecord->PostTask("DELAY_KILL_ABILITY", AMSEventHandler::KILL_PROCESS_TIMEOUT, timeoutTask); } -void AppRunningManager::PrepareTerminate(const sptr &token) +void AppRunningManager::PrepareTerminate(const sptr &token, bool clearMissionFlag) { if (token == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "token is nullptr."); @@ -506,7 +506,10 @@ void AppRunningManager::PrepareTerminate(const sptr &token) abilityRecord->SetTerminating(); } - if (appRecord->IsLastAbilityRecord(token) && (!appRecord->IsKeepAliveApp() || + // set app record terminating when close last page ability + auto isLastAbility = + clearMissionFlag ? appRecord->IsLastPageAbilityRecord(token) : appRecord->IsLastAbilityRecord(token); + if (isLastAbility && (!appRecord->IsKeepAliveApp() || !ExitResidentProcessManager::GetInstance().IsMemorySizeSufficent())) { auto cacheProcMgr = DelayedSingleton::GetInstance(); cacheProcMgr->UpdateTypeByAbility(abilityRecord, appRecord); @@ -581,7 +584,7 @@ void AppRunningManager::TerminateAbility(const sptr &token, bool TAG_LOGD(AAFwkTag::APPMGR, "The ability is the last in the app:%{public}s.", appRecord->GetName().c_str()); appRecord->SetTerminating(); if (clearMissionFlag && appMgrServiceInner != nullptr) { - auto delayTime = appRecord->ExtensionAbilityRecordExists(token) ? + auto delayTime = appRecord->ExtensionAbilityRecordExists() ? AMSEventHandler::DELAY_KILL_EXTENSION_PROCESS_TIMEOUT : AMSEventHandler::DELAY_KILL_PROCESS_TIMEOUT; appRecord->PostTask("DELAY_KILL_PROCESS", delayTime, killProcess); } diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 723744509f..09b0c7b773 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -1354,19 +1354,15 @@ bool AppRunningRecord::IsLastAbilityRecord(const sptr &token) return false; } -bool AppRunningRecord::ExtensionAbilityRecordExists(const sptr &token) +bool AppRunningRecord::ExtensionAbilityRecordExists() { - auto moduleRecord = GetModuleRunningRecordByToken(token); - if (!moduleRecord) { - TAG_LOGE(AAFwkTag::APPMGR, "can not find module record"); - return false; - } auto moduleRecordList = GetAllModuleRecord(); for (auto moduleRecord : moduleRecordList) { if (moduleRecord && moduleRecord->ExtensionAbilityRecordExists()) { return true; + } } - } + TAG_LOGD(AAFwkTag::APPMGR, "can not find extension record"); return false; } diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index e9b08c88d5..092fc3f569 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -171,7 +171,7 @@ public: virtual AppMgrResultCode GetAppFreezingTime(int& time); virtual void AbilityAttachTimeOut(const sptr& token); - virtual void PrepareTerminate(const sptr& token); + virtual void PrepareTerminate(const sptr& token, bool clearMissionFlag = false); void GetRunningProcessInfoByToken(const sptr& token, AppExecFwk::RunningProcessInfo& info); diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index 8023501fd6..f6ff62b1d3 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -109,7 +109,7 @@ AppMgrResultCode AppMgrClient::ConnectAppMgrService() void AppMgrClient::AbilityAttachTimeOut(const sptr& token) {} -void AppMgrClient::PrepareTerminate(const sptr& token) +void AppMgrClient::PrepareTerminate(const sptr& token, bool clearMissionFlag) {} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index c003a2dac8..32a8573f19 100644 --- a/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/test/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -121,7 +121,7 @@ void AppScheduler::AttachTimeOut(const sptr& token) TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::AttachTimeOut()"); } -void AppScheduler::PrepareTerminate(const sptr& token) +void AppScheduler::PrepareTerminate(const sptr& token, bool clearMissionFlag) { TAG_LOGI(AAFwkTag::TEST, "Test AppScheduler::PrepareTerminate()"); } diff --git a/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h b/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h index 5b88e69774..605df5f62a 100644 --- a/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h +++ b/test/mock/services_appmgr_test/include/mock_ams_mgr_scheduler.h @@ -41,7 +41,7 @@ public: MOCK_METHOD2(KillApplicationByUid, int(const std::string&, const int uid)); MOCK_METHOD0(IsReady, bool()); MOCK_METHOD1(AbilityAttachTimeOut, void(const sptr& token)); - MOCK_METHOD1(PrepareTerminate, void(const sptr& token)); + MOCK_METHOD2(PrepareTerminate, void(const sptr& token, bool clearMissionFlag)); MOCK_METHOD2(GetRunningProcessInfoByToken, void(const sptr& token, OHOS::AppExecFwk::RunningProcessInfo& info)); MOCK_METHOD1(SetAbilityForegroundingFlagToAppRecord, void(const pid_t pid)); From 849aef0884a4aa920d83cc0d3e66b4e552c089b5 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Tue, 25 Jun 2024 14:05:47 +0000 Subject: [PATCH 060/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../napi/app/app_manager/js_app_manager.cpp | 73 ++++++++++++++----- 1 file changed, 54 insertions(+), 19 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 9a63adefed..7d0ce29f78 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -186,11 +186,13 @@ private: env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (observer == nullptr || appManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "observer or appManager nullptr")); + delete task; return; } int32_t ret = appManager->UnregisterApplicationStateObserver(observer); @@ -201,11 +203,13 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); task->Reject(env, CreateJsError(env, ret, "UnregisterApplicationStateObserver failed")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -226,11 +230,13 @@ private: auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (appManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr")); + delete task; return; } std::vector list; @@ -242,11 +248,13 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); task->Reject(env, CreateJsError(env, ret, "OnGetForegroundApplications failed")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -267,6 +275,7 @@ private: auto asyncTask = [appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } std::vector infos; @@ -276,11 +285,13 @@ private: } else { task->Reject(env, CreateJsError(env, ret, "Get mission infos failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -301,21 +312,25 @@ private: auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + delete task; return; } bool ret = abilityManager->IsRunningInStabilityTest(); TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->Resolve(env, CreateJsValue(env, ret)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -354,11 +369,13 @@ private: env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + delete task; return; } auto ret = abilityManager->KillProcess(bundleName, clearPageStack); @@ -367,10 +384,13 @@ private: } else { task->Reject(env, CreateJsError(env, ret, "kill process failed.")); } + delete task; }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); - napiAsyncTask.release(); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); + } return result; } @@ -399,11 +419,13 @@ private: auto asyncTask = [bundleName, appManager = appManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "appManager nullptr")); + delete task; return; } auto ret = appManager->ClearUpApplicationData(bundleName, 0); @@ -412,11 +434,13 @@ private: } else { task->Reject(env, CreateJsError(env, ret, "clear up application failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -460,6 +484,7 @@ private: env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack); @@ -469,11 +494,13 @@ private: TAG_LOGD(AAFwkTag::APPMGR, "failed error:%{public}d", ret); task->Reject(env, CreateJsError(env, ret, "Kill processes failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); TAG_LOGD(AAFwkTag::APPMGR, "end"); return result; } @@ -494,21 +521,25 @@ private: auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + delete task; return; } int32_t memorySize = abilityManager->GetAppMemorySize(); TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); task->Resolve(env, CreateJsValue(env, memorySize)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -528,21 +559,25 @@ private: auto asyncTask = [abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { if (errCode != 0) { task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + delete task; return; } if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + delete task; return; } bool ret = abilityManager->IsRamConstrainedDevice(); TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->Resolve(env, CreateJsValue(env, ret)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } }; From e148b0b267d7a91b9916c2d5cdd050879b859440 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Tue, 25 Jun 2024 14:23:09 +0000 Subject: [PATCH 061/148] update frameworks/js/napi/app/js_app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../app/js_app_manager/js_app_manager.cpp | 115 +++++++++++++----- 1 file changed, 86 insertions(+), 29 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 31dd6dff40..86741f8d9f 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -519,6 +519,7 @@ private: if (observer == nullptr || appManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } int32_t ret = appManager->UnregisterApplicationStateObserver(observer); @@ -529,11 +530,14 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -619,6 +623,7 @@ private: if (appManager == nullptr) { TAG_LOGE(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } std::vector list; @@ -630,11 +635,14 @@ private: TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -649,6 +657,7 @@ private: if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } std::vector infos; @@ -658,11 +667,14 @@ private: } else { task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -741,6 +753,7 @@ private: if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } std::vector infos; @@ -751,11 +764,14 @@ private: } else { task->Reject(env, CreateJsError(env, GetJsErrorCodeByNativeError(ret))); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -769,16 +785,20 @@ private: if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } bool ret = abilityManager->IsRunningInStabilityTest(); TAG_LOGD(AAFwkTag::APPMGR, "result:%{public}d", ret); task->ResolveWithNoError(env, CreateJsValue(env, ret)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -818,6 +838,7 @@ private: if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } auto ret = abilityManager->KillProcess(bundleName, clearPageStack); @@ -826,11 +847,14 @@ private: } else { task->Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -857,6 +881,7 @@ private: if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } auto ret = appManager->ClearUpApplicationData(bundleName, 0); @@ -865,11 +890,14 @@ private: } else { task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -901,6 +929,7 @@ private: if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } auto ret = appManager->ClearUpApplicationData(bundleName, appCloneIndex); @@ -909,11 +938,14 @@ private: } else { task->Reject(env, CreateJsErrorByNativeErr(env, ret, "clear up application failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -947,16 +979,20 @@ private: if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } bool ret = appManager->IsSharedBundleRunning(bundleName, versionCode); TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->ResolveWithNoError(env, CreateJsValue(env, ret)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -1001,6 +1037,7 @@ private: if (appManager == nullptr || appManager->GetAmsMgr() == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr or amsMgr is nullptr."); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } auto ret = appManager->GetAmsMgr()->KillProcessWithAccount(bundleName, accountId, clearPageStack); @@ -1009,11 +1046,14 @@ private: } else { task->Reject(env, CreateJsErrorByNativeErr(env, ret, "Kill processes failed.")); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -1026,16 +1066,20 @@ private: if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } int32_t memorySize = abilityManager->GetAppMemorySize(); TAG_LOGI(AAFwkTag::APPMGR, "memorySize:%{public}d", memorySize); task->ResolveWithNoError(env, CreateJsValue(env, memorySize)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -1048,16 +1092,20 @@ private: if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } bool ret = abilityManager->IsRamConstrainedDevice(); TAG_LOGI(AAFwkTag::APPMGR, "result:%{public}d", ret); task->ResolveWithNoError(env, CreateJsValue(env, ret)); + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -1084,6 +1132,7 @@ private: if (appManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "appManager is nullptr"); task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } int32_t memSize = 0; @@ -1093,11 +1142,14 @@ private: } else { task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } + delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); } - napiAsyncTask.release(); return result; } @@ -1139,6 +1191,7 @@ private: auto asyncTask = [bundleName, userId, appManager = appManager_, env, task = napiAsyncTask.get()]() { if (appManager == nullptr) { task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + delete task; return; } std::vector infos; @@ -1148,10 +1201,14 @@ private: } else { task->Reject(env, CreateJsErrorByNativeErr(env, ret)); } + delete task; }; - if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) - TAG_LOGE(AAFwkTag::APPMGR, "%{public}s send event failed!", __func__); - napiAsyncTask.release(); + if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { + napiAsyncTask->Reject(env, + CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + } else { + napiAsyncTask.release(); + } return result; } From 0d24367e5ee5a6168cd46e49b80fc464cdbf6b2e Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Wed, 26 Jun 2024 02:15:10 +0000 Subject: [PATCH 062/148] update frameworks/js/napi/app/js_app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../app/js_app_manager/js_app_manager.cpp | 145 ++++++++++-------- 1 file changed, 79 insertions(+), 66 deletions(-) diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index 86741f8d9f..d7ccc2d0c0 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -482,6 +482,23 @@ private: return CreateJsUndefined(env); } #endif + static void OnOffOldInner(sptr appManager, sptr observer, + int64_t observerId, napi_env env, NapiAsyncTask *task) + { + if (observer == nullptr || appManager == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + int32_t ret = appManager->UnregisterApplicationStateObserver(observer); + if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { + task->ResolveWithNoError(env, CreateJsUndefined(env)); + TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize()); + } else { + TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); + task->Reject(env, CreateJsErrorByNativeErr(env, ret)); + } + } napi_value OnOffOld(napi_env env, size_t argc, napi_value* argv) { @@ -516,25 +533,12 @@ private: std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [appManager = appManager_, observer = observer_, observerId, env, task = napiAsyncTask.get()]() { - if (observer == nullptr || appManager == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "observer or appManager nullptr"); - task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - delete task; - return; - } - int32_t ret = appManager->UnregisterApplicationStateObserver(observer); - if (ret == 0 && observer->RemoveJsObserverObject(observerId)) { - task->ResolveWithNoError(env, CreateJsUndefined(env)); - TAG_LOGD(AAFwkTag::APPMGR, "success size:%{public}zu", observer->GetJsObserverMapSize()); - } else { - TAG_LOGE(AAFwkTag::APPMGR, "failed error:%{public}d", ret); - task->Reject(env, CreateJsErrorByNativeErr(env, ret)); - } + OnOffOldInner(appManager, observer, observerId, env, task); delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -638,8 +642,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -670,8 +674,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -767,8 +771,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -794,14 +798,29 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } return result; } + static void OnKillProcessesByBundleNameInner(std::string bundleName, bool clearPageStack, + sptr abilityManager, napi_env env, NapiAsyncTask *task) + { + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + auto ret = abilityManager->KillProcess(bundleName, clearPageStack); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsUndefined(env)); + } else { + task->Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed.")); + } + } napi_value OnKillProcessesByBundleName(napi_env env, size_t argc, napi_value* argv) { TAG_LOGD(AAFwkTag::APPMGR, "OnKillProcessesByBundleName called"); @@ -835,23 +854,12 @@ private: std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, env, task = napiAsyncTask.get()]() { - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager nullptr"); - task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - delete task; - return; - } - auto ret = abilityManager->KillProcess(bundleName, clearPageStack); - if (ret == 0) { - task->ResolveWithNoError(env, CreateJsUndefined(env)); - } else { - task->Reject(env, CreateJsErrorByNativeErr(env, ret, "kill process failed.")); - } + OnKillProcessesByBundleNameInner(bundleName, clearPageStack, abilityManager, env, task); delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -893,8 +901,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -941,8 +949,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_high)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -988,8 +996,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -1049,8 +1057,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -1075,8 +1083,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -1101,8 +1109,8 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } @@ -1145,14 +1153,30 @@ private: delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } return result; } + static void OnGetRunningProcessInfoByBundleNameInner(std::string bundleName, int userId, + sptr appManager, napi_env env, NapiAsyncTask *task) + { + if (appManager == nullptr) { + task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + std::vector infos; + int32_t ret = appManager->GetRunningProcessInformation(bundleName, userId, infos); + if (ret == 0) { + task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); + } else { + task->Reject(env, CreateJsErrorByNativeErr(env, ret)); + } + } + napi_value OnGetRunningProcessInfoByBundleName(napi_env env, size_t argc, napi_value* argv) { if (argc < ARGC_ONE) { @@ -1189,23 +1213,12 @@ private: napi_value result = nullptr; std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [bundleName, userId, appManager = appManager_, env, task = napiAsyncTask.get()]() { - if (appManager == nullptr) { - task->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); - delete task; - return; - } - std::vector infos; - int32_t ret = appManager->GetRunningProcessInformation(bundleName, userId, infos); - if (ret == 0) { - task->ResolveWithNoError(env, CreateJsRunningProcessInfoArray(env, infos)); - } else { - task->Reject(env, CreateJsErrorByNativeErr(env, ret)); - } + OnGetRunningProcessInfoByBundleNameInner(bundleName, userId, appManager, env, task); delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { - napiAsyncTask->Reject(env, - CreateJsErrorByNativeErr(env, AbilityErrorCode::ERROR_CODE_INNER, "send event failed")); + napiAsyncTask->Reject(env, CreateJsErrorByNativeErr(env, + static_cast(AbilityErrorCode::ERROR_CODE_INNER), "send event failed!")); } else { napiAsyncTask.release(); } From 17e10444e65da5a61e6207bd2749753c090ecfef Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Wed, 26 Jun 2024 02:21:55 +0000 Subject: [PATCH 063/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../napi/app/app_manager/js_app_manager.cpp | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 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 7d0ce29f78..4dbba879c1 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -334,6 +334,26 @@ private: return result; } + static void OnKillProcessByBundleNameInner(std::string bundleName, bool clearPageStack, + sptr abilityManager, int32_t errCode, napi_env env, NapiAsyncTask *task) + { + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + return; + } + if (abilityManager == nullptr) { + TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null"); + task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); + return; + } + auto ret = abilityManager->KillProcess(bundleName, clearPageStack); + if (ret == 0) { + task->Resolve(env, CreateJsValue(env, ret)); + } else { + task->Reject(env, CreateJsError(env, ret, "kill process failed.")); + } + } + napi_value OnKillProcessByBundleName(napi_env env, size_t argc, napi_value* argv) { TAG_LOGD(AAFwkTag::APPMGR, "called"); @@ -367,23 +387,7 @@ private: std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { - if (errCode != 0) { - task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - delete task; - return; - } - if (abilityManager == nullptr) { - TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null"); - task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); - delete task; - return; - } - auto ret = abilityManager->KillProcess(bundleName, clearPageStack); - if (ret == 0) { - task->Resolve(env, CreateJsValue(env, ret)); - } else { - task->Reject(env, CreateJsError(env, ret, "kill process failed.")); - } + OnKillProcessByBundleNameInner(bundleName, clearPageStack, abilityManager, errCode, env, task); delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { From 3f0f17aec2807c012ddfbe5759a59b81b27f76ed Mon Sep 17 00:00:00 2001 From: wangzhen Date: Fri, 14 Jun 2024 16:23:38 +0800 Subject: [PATCH 064/148] Correct mistakes in recent pr Signed-off-by: wangzhen Change-Id: I3a215ab41fa351df136ed6213af172627b2c8705 --- frameworks/native/ability/native/BUILD.gn | 62 ++++++++++++++++++- .../native/free_install_observer_proxy.cpp | 5 ++ interfaces/inner_api/ability_manager/BUILD.gn | 1 + .../include/free_install_observer_interface.h | 2 + services/abilitymgr/BUILD.gn | 1 + .../abilitymgr/include/ability_service_util.h | 2 +- .../abilitymgr/src/ability_manager_stub.cpp | 2 +- .../interceptor/ability_jump_interceptor.cpp | 2 +- .../src/interceptor/control_interceptor.cpp | 2 +- .../interceptor/disposed_rule_interceptor.cpp | 2 +- .../src/system_dialog_scheduler.cpp | 4 +- 11 files changed, 75 insertions(+), 10 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index a07657ec94..7d7b8984aa 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -191,6 +191,61 @@ ohos_shared_library("abilitykit_utils") { part_name = "ability_runtime" } +ohos_shared_library("free_install_observer") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_services_path}/common/include", + ] + + defines = [] + if (ability_runtime_graphics) { + defines += [ + "SUPPORT_GRAPHICS", + "SUPPORT_SCREEN", + ] + } + + if (target_cpu == "arm64") { + defines += [ "APP_USE_ARM64" ] + } else if (target_cpu == "arm") { + defines += [ "APP_USE_ARM" ] + } else if (target_cpu == "x86_64") { + defines += [ "APP_USE_X86_64" ] + } + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + sources = [ + "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", + "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + ] + + innerapi_tags = [ "platformsdk" ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + ohos_shared_library("abilitykit_native") { include_dirs = [ "${ability_runtime_path}/utils/global/time/include" ] @@ -214,8 +269,6 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/data_ability_helper_impl.cpp", "${ability_runtime_native_path}/ability/native/data_ability_impl.cpp", "${ability_runtime_native_path}/ability/native/data_uri_utils.cpp", - "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", - "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", "${ability_runtime_native_path}/ability/native/insight_intent_host_client.cpp", "${ability_runtime_native_path}/ability/native/js_free_install_observer.cpp", "${ability_runtime_native_path}/ability/native/new_ability_impl.cpp", @@ -236,6 +289,7 @@ ohos_shared_library("abilitykit_native") { deps = [ ":continuation_ipc", ":extension_blocklist_config", + ":free_install_observer", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", @@ -1250,7 +1304,9 @@ ohos_shared_library("auto_startup_callback") { "${ability_runtime_native_path}/ability/native/auto_startup_callback_stub.cpp", ] - deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager" ] + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_base", + ] configs = [ "${ability_runtime_services_path}/common:common_config" ] diff --git a/frameworks/native/ability/native/free_install_observer_proxy.cpp b/frameworks/native/ability/native/free_install_observer_proxy.cpp index 097e807698..0639e07700 100644 --- a/frameworks/native/ability/native/free_install_observer_proxy.cpp +++ b/frameworks/native/ability/native/free_install_observer_proxy.cpp @@ -63,5 +63,10 @@ void FreeInstallObserverProxy::OnInstallFinished(const std::string &bundleName, return; } } + +sptr BuildFreeInstallObserver(sptr remoteObject) +{ + return iface_cast(remoteObject); +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index c066d6a600..ee522993ff 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -172,6 +172,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_native_path}/ability/native/task_handler_client.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_client.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_client.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_manager_collaborator_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", diff --git a/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h b/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h index 33de6df6b0..004fe99d22 100644 --- a/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h +++ b/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h @@ -40,6 +40,8 @@ public: ON_INSTALL_FINISHED = 1, }; }; + +sptr BuildFreeInstallObserver(sptr remoteObject); } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 34dfdda01c..1a0c763897 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -117,6 +117,7 @@ ohos_shared_library("abilityms") { "${ability_runtime_innerkits_path}/session_handler:session_handler", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:auto_startup_callback", + "${ability_runtime_native_path}/ability/native:free_install_observer", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_path}/utils/server/startup:startup_util", diff --git a/services/abilitymgr/include/ability_service_util.h b/services/abilitymgr/include/ability_service_util.h index 9e946a4e50..6bf23591e4 100644 --- a/services/abilitymgr/include/ability_service_util.h +++ b/services/abilitymgr/include/ability_service_util.h @@ -42,7 +42,7 @@ constexpr const char* MARKET_CROWD_TEST_BUNDLE_PARAM = "crowd_test_bundle_name"; want.SetElementName(appGalleryBundleName, ""); want.SetAction(action); want.SetParam(MARKET_CROWD_TEST_BUNDLE_PARAM, bundleName); - return DelayedSingleton::GetInstance()->StartAbility(want, requestCode, userId); + return DelayedSingleton::GetInstance()->StartAbility(want, userId, requestCode); } } // namespace AbilityUtil } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index ebd09d89d8..ea39054852 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -2281,7 +2281,7 @@ int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, M int AbilityManagerStub::AddFreeInstallObserverInner(MessageParcel &data, MessageParcel &reply) { sptr observer = - iface_cast(data.ReadRemoteObject()); + AbilityRuntime::BuildFreeInstallObserver(data.ReadRemoteObject()); if (observer == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "observer is nullptr"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp index 927cd54f84..2a0e46084b 100644 --- a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp @@ -76,7 +76,7 @@ ErrCode AbilityJumpInterceptor::DoProcess(AbilityInterceptorParam param) AbilityUtil::ParseJumpInterceptorWant(dialogWant, controlRule.callerPkg); LoadAppLabelInfo(dialogWant, controlRule, param.userId); int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility(dialogWant, - param.requestCode, param.userId)); + param.userId, param.requestCode)); if (ret != ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "appInterceptor Dialog StartAbility error, ret:%{public}d", ret); return ret; diff --git a/services/abilitymgr/src/interceptor/control_interceptor.cpp b/services/abilitymgr/src/interceptor/control_interceptor.cpp index 8b84b46345..ee20f68e33 100644 --- a/services/abilitymgr/src/interceptor/control_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/control_interceptor.cpp @@ -58,7 +58,7 @@ ErrCode ControlInterceptor::DoProcess(AbilityInterceptorParam param) controlRule.controlWant = controlWant; } int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *controlRule.controlWant, param.requestCode, param.userId)); + *controlRule.controlWant, param.userId, param.requestCode)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Control implicit start appgallery failed."); return ret; diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index 301220e01f..aebb0b02b0 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -55,7 +55,7 @@ ErrCode DisposedRuleInterceptor::DoProcess(AbilityInterceptorParam param) } if (disposedRule.componentType == AppExecFwk::ComponentType::UI_ABILITY) { int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *disposedRule.want, param.requestCode, param.userId)); + *disposedRule.want, param.userId, param.requestCode)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "DisposedRuleInterceptor start ability failed."); return ret; diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index 9adc899c15..e0b3b50cdb 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -441,7 +441,7 @@ int SystemDialogScheduler::GetSelectorDialogWantCommon(const std::vector Date: Wed, 26 Jun 2024 12:00:06 +0800 Subject: [PATCH 065/148] atomic terminate Signed-off-by: zhuhan Change-Id: Ic0840db660f9048e1f01058c598965aea85f1aba --- .../native/ability/ability_runtime/ability_context_impl.cpp | 6 +++--- .../native/ability/ability_runtime/ability_context_impl.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index 14cfad71c2..b73496fa1b 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -301,7 +301,7 @@ ErrCode AbilityContextImpl::StopServiceExtensionAbility(const AAFwk::Want& want, ErrCode AbilityContextImpl::TerminateAbilityWithResult(const AAFwk::Want& want, int resultCode) { TAG_LOGI(AAFwkTag::CONTEXT, "TerminateAbilityWithResult"); - isTerminating_ = true; + isTerminating_.store(true); #ifdef SUPPORT_SCREEN if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { auto sessionToken = GetSessionToken(); @@ -539,7 +539,7 @@ ErrCode AbilityContextImpl::MoveUIAbilityToBackground() ErrCode AbilityContextImpl::TerminateSelf() { TAG_LOGI(AAFwkTag::CONTEXT, "TerminateSelf"); - isTerminating_ = true; + isTerminating_.store(true); auto sessionToken = GetSessionToken(); if (sessionToken == nullptr) { TAG_LOGW(AAFwkTag::CONTEXT, "sessionToken is null"); @@ -576,7 +576,7 @@ ErrCode AbilityContextImpl::CloseAbility() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::CONTEXT, "CloseAbility"); - isTerminating_ = true; + isTerminating_.store(true); AAFwk::Want resultWant; ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->CloseAbility(token_, -1, &resultWant); if (err != ERR_OK) { diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h index 4046a9e512..da37141fa5 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h @@ -186,7 +186,7 @@ public: bool IsTerminating() override { - return isTerminating_; + return isTerminating_.load(); } void SetWeakSessionToken(const wptr& sessionToken) override; @@ -195,7 +195,7 @@ public: void SetTerminating(bool state) override { - isTerminating_ = state; + isTerminating_.store(state); } ErrCode RequestDialogService(napi_env env, AAFwk::Want &want, RequestDialogResultTask &&task) override; @@ -292,7 +292,7 @@ private: std::shared_ptr config_ = nullptr; std::shared_ptr localCallContainer_ = nullptr; std::weak_ptr abilityCallback_; - bool isTerminating_ = false; + std::atomic isTerminating_ = false; int32_t missionId_ = -1; int32_t abilityRecordId_ = 0; std::mutex sessionTokenMutex_; From d2d3271a47c8688f69f428d193174f22b7bc366a Mon Sep 17 00:00:00 2001 From: liuyics15 <1179805842@qq.com> Date: Tue, 18 Jun 2024 16:08:16 +0800 Subject: [PATCH 066/148] move ark_interop_helper to ability_runtime Signed-off-by: liuyics15 <1179805842@qq.com> --- .../cj_environment/src/cj_environment.cpp | 43 ++++++ .../interfaces/inner_api/cj_environment.h | 1 + frameworks/cj/BUILD.gn | 1 + frameworks/cj/ffi/ark_interop_helper/BUILD.gn | 54 +++++++ .../ark_interop_helper/ark_interop_helper.cpp | 146 ++++++++++++++++++ .../ark_interop_helper/ark_interop_helper.h | 38 +++++ .../cj/ffi/ark_interop_helper/custom_scope.h | 33 ++++ frameworks/cj/ffi/ark_interop_helper/utils.h | 31 ++++ 8 files changed, 347 insertions(+) create mode 100644 frameworks/cj/ffi/ark_interop_helper/BUILD.gn create mode 100644 frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.cpp create mode 100644 frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.h create mode 100644 frameworks/cj/ffi/ark_interop_helper/custom_scope.h create mode 100644 frameworks/cj/ffi/ark_interop_helper/utils.h diff --git a/cj_environment/frameworks/cj_environment/src/cj_environment.cpp b/cj_environment/frameworks/cj_environment/src/cj_environment.cpp index 434b456286..c2ba4f6fb2 100644 --- a/cj_environment/frameworks/cj_environment/src/cj_environment.cpp +++ b/cj_environment/frameworks/cj_environment/src/cj_environment.cpp @@ -473,4 +473,47 @@ bool IsCJAbility(const std::string& info) std::string pattern = "^([a-zA-Z0-9_]+\\.)+[a-zA-Z0-9_]+$"; return std::regex_match(info, std::regex(pattern)); } + +struct CJEnvMethods { + void (*initCJAppNS)(const std::string& path) = nullptr; + void (*initCJSDKNS)(const std::string& path) = nullptr; + void (*initCJSysNS)(const std::string& path) = nullptr; + void (*initCJChipSDKNS)(const std::string& path) = nullptr; + bool (*startRuntime)() = nullptr; + bool (*startUIScheduler)() = nullptr; + void* (*loadCJModule)(const char* dllName) = nullptr; + void* (*loadLibrary)(uint32_t kind, const char* dllName) = nullptr; + void* (*getSymbol)(void* handle, const char* symbol) = nullptr; +}; + +CJ_EXPORT extern "C" CJEnvMethods* OHOS_GetCJEnvInstance() +{ + static CJEnvMethods gCJEnvMethods { + .initCJAppNS = [](const std::string& path) { + CJEnvironment::GetInstance()->InitCJAppNS(path); + }, + .initCJSDKNS = [](const std::string& path) { + CJEnvironment::GetInstance()->InitCJSDKNS(path); + }, + .initCJSysNS = [](const std::string& path) { + CJEnvironment::GetInstance()->InitCJSysNS(path); + }, + .initCJChipSDKNS = [](const std::string& path) { + CJEnvironment::GetInstance()->InitCJChipSDKNS(path); + }, + .startRuntime = [] { + return CJEnvironment::GetInstance()->StartRuntime(); + }, + .startUIScheduler = [] { + return CJEnvironment::GetInstance()->StartUIScheduler(); + }, + .loadCJModule = [](const char* dllName) { + return CJEnvironment::GetInstance()->LoadCJLibrary(dllName); + }, + .getSymbol = [](void* handle, const char* dllName) { + return CJEnvironment::GetInstance()->GetSymbol(handle, dllName); + } + }; + return &gCJEnvMethods; +} } diff --git a/cj_environment/interfaces/inner_api/cj_environment.h b/cj_environment/interfaces/inner_api/cj_environment.h index 2df6085c0e..def32d4e48 100644 --- a/cj_environment/interfaces/inner_api/cj_environment.h +++ b/cj_environment/interfaces/inner_api/cj_environment.h @@ -16,6 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H #define OHOS_ABILITY_RUNTIME_CJ_ENVIRONMENT_H +#include #include #ifdef WINDOWS_PLATFORM diff --git a/frameworks/cj/BUILD.gn b/frameworks/cj/BUILD.gn index b4830fb179..e406ddb028 100755 --- a/frameworks/cj/BUILD.gn +++ b/frameworks/cj/BUILD.gn @@ -18,5 +18,6 @@ group("cj_ability_packages") { deps = [ "${ability_runtime_path}/frameworks/cj/ffi:cj_ability_ffi", "${ability_runtime_path}/frameworks/cj/ffi/app/errormanager:cj_errormanager_ffi", + "${ability_runtime_path}/frameworks/cj/ffi/ark_interop_helper:ark_interop_helper_ffi", ] } diff --git a/frameworks/cj/ffi/ark_interop_helper/BUILD.gn b/frameworks/cj/ffi/ark_interop_helper/BUILD.gn new file mode 100644 index 0000000000..bf0cc02472 --- /dev/null +++ b/frameworks/cj/ffi/ark_interop_helper/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (C) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("ark_interop_helper_ffi") { + defines = [] + + sources = [ "ark_interop_helper.cpp" ] + + external_deps = [ + "ets_runtime:libark_jsruntime", + "hilog:libhilog", + "napi:ace_napi", + "napi:ark_interop", + ] + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } + + deps = [] + + if (build_ohos_sdk) { + defines += [ "PREVIEW" ] + } else { + deps += [ + "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_native", + ] + external_deps += [ "ace_engine:ace_container_scope" ] + } + + if (current_os == "mingw") { + defines += [ "__WINDOWS__" ] + } + + innerapi_tags = [ "platformsdk" ] + part_name = "ability_runtime" + subsystem_name = "ability" +} diff --git a/frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.cpp b/frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.cpp new file mode 100644 index 0000000000..74fa04bb91 --- /dev/null +++ b/frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ark_interop_helper.h" +#include "ark_native_engine.h" +#include "inner_api/cjffi/ark_interop/ark_interop_internal.h" +#include "inner_api/cjffi/ark_interop/ark_interop_log.h" +#ifndef PREVIEW +#include "core/common/container_scope.h" +#include "custom_scope.h" +#include "napi_base_context.h" +#include "ability.h" +#endif + +using namespace panda::ecmascript; + +extern "C" { +napi_value ArkTsValuetoNapiValue(napi_env env, ARKTS_Value arkValue) +{ + LOGI("ArkTsValuetoNapiValue start"); + if (env == nullptr) { + LOGE("FfiOHOSArkTsValuetoNapiValue Error: env is null!"); + return nullptr; + } + Local js_value_ref = ARKTS_ToHandle(arkValue); + auto ark_native_obj = ArkNativeEngine::ArkValueToNapiValue(env, js_value_ref); + return ark_native_obj; +}; + +ARKTS_Value NapiValueToArkTsValue(napi_value value) +{ + auto ref = BIT_CAST(value, Local); + return ARKTS_FromHandle(ref); +} + +bool IsStageMode(napi_env env, napi_value context) +{ +#ifndef PREVIEW + LOGI("IsStageMode start"); + bool isStageMode = false; + napi_status status = OHOS::AbilityRuntime::IsStageContext(env, context, isStageMode); + if (status != napi_ok || !isStageMode) { + LOGI("IsStageMode false"); + return false; + } else { + LOGI("IsStageMode true"); + return true; + } +#else + return false; +#endif +} + +void* GetContextStageMode(napi_env env, napi_value context) +{ +#ifndef PREVIEW + LOGI("GetContextStageMode start"); + if (!env || !context) { + LOGE("argument invalid"); + return nullptr; + } + napi_valuetype type; + if (napi_typeof(env, context, &type) != napi_ok) { + LOGE("invalid napi value"); + return nullptr; + } + if (type != napi_object) { + LOGE("not a object"); + return nullptr; + } + void* data; + if (napi_unwrap(env, context, &data) != napi_ok) { + LOGE("no bind native object"); + return nullptr; + } + if (!data) { + LOGE("native object is null"); + return nullptr; + } + auto ability = OHOS::AbilityRuntime::GetStageModeContext(env, context); + if (ability == nullptr) { + LOGE("Failed to get native ability instance"); + return nullptr; + } + LOGI("GetContextStageMode success"); + return ability.get(); +#else + return nullptr; +#endif +} +#ifndef PREVIEW +void CustomScope::Enter() +{ + last_ = OHOS::Ace::ContainerScope::CurrentId(); + OHOS::Ace::ContainerScope::UpdateCurrent(id_); +} + +void CustomScope::Exit() const +{ + OHOS::Ace::ContainerScope::UpdateCurrent(last_); +} + +int32_t ARKTS_GetCurrentContainerId() +{ + return OHOS::Ace::ContainerScope::CurrentId(); +} + +ContainerScope ARKTS_CreateContainerScope(int32_t id) +{ + return new CustomScope(id); +} + +void ARKTS_DestroyContainerScope(ContainerScope scope) +{ + delete scope; +} + +void ARKTS_EnterContainerScope(ContainerScope scope) +{ + scope->Enter(); +} + +void ARKTS_ExitContainerScope(ContainerScope scope) +{ + scope->Exit(); +} +#else +int32_t ARKTS_GetCurrentContainerId() { return 0; } +ContainerScope ARKTS_CreateContainerScope(int32_t id) { return nullptr; } +void ARKTS_DestroyContainerScope(ContainerScope scope) {} +void ARKTS_EnterContainerScope(ContainerScope scope) {} +void ARKTS_ExitContainerScope(ContainerScope scope) {} +#endif +} \ No newline at end of file diff --git a/frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.h b/frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.h new file mode 100644 index 0000000000..fec91a5b1c --- /dev/null +++ b/frameworks/cj/ffi/ark_interop_helper/ark_interop_helper.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NAPI_ARK_INTEROP_HELPER_H +#define NAPI_ARK_INTEROP_HELPER_H + +#include "inner_api/cjffi/ark_interop/ark_interop_napi.h" +#include "napi/native_api.h" + +#include + +using ContainerScope = class CustomScope*; + +extern "C" { +EXPORT napi_value ArkTsValuetoNapiValue(napi_env env, ARKTS_Value arkValue); +EXPORT ARKTS_Value NapiValueToArkTsValue(napi_value value); +EXPORT bool IsStageMode(napi_env env, napi_value context); +EXPORT void* GetContextStageMode(napi_env env, napi_value context); +EXPORT int32_t ARKTS_GetCurrentContainerId(); +EXPORT ContainerScope ARKTS_CreateContainerScope(int32_t); +EXPORT void ARKTS_DestroyContainerScope(ContainerScope scope); +EXPORT void ARKTS_EnterContainerScope(ContainerScope scope); +EXPORT void ARKTS_ExitContainerScope(ContainerScope scope); +} + +#endif // NAPI_ARK_INTEROP_HELPER_H \ No newline at end of file diff --git a/frameworks/cj/ffi/ark_interop_helper/custom_scope.h b/frameworks/cj/ffi/ark_interop_helper/custom_scope.h new file mode 100644 index 0000000000..2a17b6e775 --- /dev/null +++ b/frameworks/cj/ffi/ark_interop_helper/custom_scope.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NAPI_CUSTOM_SCOPE_H +#define NAPI_CUSTOM_SCOPE_H + +#include + +class CustomScope { +public: + explicit CustomScope(int32_t id): id_(id), last_(0) {} + + void Enter(); + void Exit() const; + +private: + int32_t id_ = 0; + int32_t last_ = 0; +}; + +#endif // NAPI_CUSTOM_SCOPE_H diff --git a/frameworks/cj/ffi/ark_interop_helper/utils.h b/frameworks/cj/ffi/ark_interop_helper/utils.h new file mode 100644 index 0000000000..587d7c9999 --- /dev/null +++ b/frameworks/cj/ffi/ark_interop_helper/utils.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ARK_INTEROP_HELPER_UTILS_H +#define ARK_INTEROP_HELPER_UTILS_H + +#include +#include +#include + +#ifndef EXPORT +#ifdef __WINDOWS__ +#define EXPORT __declspec(dllexport) +#else +#define EXPORT __attribute__((visibility("default"))) +#endif +#endif + +#endif // ARK_INTEROP_HELPER_UTILS_H \ No newline at end of file From e8e467851666ed2470d7e84db96087c4170be737 Mon Sep 17 00:00:00 2001 From: "wanglai.yao" Date: Wed, 26 Jun 2024 06:30:10 +0000 Subject: [PATCH 067/148] update frameworks/js/napi/app/app_manager/js_app_manager.cpp. Signed-off-by: wanglai.yao --- .../js/napi/app/app_manager/js_app_manager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 4dbba879c1..b7a4cde957 100644 --- a/frameworks/js/napi/app/app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/app_manager/js_app_manager.cpp @@ -335,12 +335,8 @@ private: } static void OnKillProcessByBundleNameInner(std::string bundleName, bool clearPageStack, - sptr abilityManager, int32_t errCode, napi_env env, NapiAsyncTask *task) + sptr abilityManager, napi_env env, NapiAsyncTask *task) { - if (errCode != 0) { - task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); - return; - } if (abilityManager == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "abilityManager null"); task->Reject(env, CreateJsError(env, ERROR_CODE_ONE, "abilityManager nullptr")); @@ -387,7 +383,11 @@ private: std::unique_ptr napiAsyncTask = CreateEmptyAsyncTask(env, lastParam, &result); auto asyncTask = [bundleName, clearPageStack, abilityManager = abilityManager_, errCode, env, task = napiAsyncTask.get()]() { - OnKillProcessByBundleNameInner(bundleName, clearPageStack, abilityManager, errCode, env, task); + if (errCode != 0) { + task->Reject(env, CreateJsError(env, errCode, "Invalidate params.")); + } else { + OnKillProcessByBundleNameInner(bundleName, clearPageStack, abilityManager, env, task); + } delete task; }; if (napi_status::napi_ok != napi_send_event(env, asyncTask, napi_eprio_immediate)) { From fd43b91ca33849a4c00a78138bc3c299be5d7d51 Mon Sep 17 00:00:00 2001 From: zhubingwei Date: Mon, 24 Jun 2024 13:57:06 +0800 Subject: [PATCH 068/148] =?UTF-8?q?[BUG]=20TDD=E5=A2=9E=E5=BC=BAability=5F?= =?UTF-8?q?manager=5Fservice=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhubingwei --- .../ability_manager_service_third_test.cpp | 113 +++++++++++++++++- .../mock_ability_interceptor_executer.h | 2 +- .../src/mock_ability_interceptor_executer.cpp | 2 +- 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp index be7505f9ce..ad80d843ba 100644 --- a/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp +++ b/test/unittest/ability_manager_service_third_test/ability_manager_service_third_test.cpp @@ -20,7 +20,7 @@ #include "mock_ipc_skeleton.h" #include "mock_permission_verification.h" #include "mock_my_flag.h" -#include "mock_permission_verification.h" + #include "ability_manager_service.h" #include "ability_start_setting.h" #include "recovery_param.h" @@ -54,6 +54,8 @@ class AbilityManagerServiceThirdTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); + std::shared_ptr MockAbilityRecord(AbilityType); + sptr MockToken(AbilityType); void SetUp(); void TearDown(); @@ -69,6 +71,23 @@ void AbilityManagerServiceThirdTest::TearDownTestCase() {} void AbilityManagerServiceThirdTest::SetUp() {} void AbilityManagerServiceThirdTest::TearDown() {} +std::shared_ptr AbilityManagerServiceThirdTest::MockAbilityRecord(AbilityType abilityType) +{ + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.test.demo"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = abilityType; + return AbilityRecord::CreateAbilityRecord(abilityRequest); +} + +sptr AbilityManagerServiceThirdTest::MockToken(AbilityType abilityType) +{ + std::shared_ptr abilityRecord = MockAbilityRecord(abilityType); + if (!abilityRecord) { + return nullptr; + } + return abilityRecord->GetToken(); +} /* * Feature: AbilityManagerService @@ -1984,6 +2003,7 @@ HWTEST_F(AbilityManagerServiceThirdTest, RequestDialogService_002, TestSize.Leve */ HWTEST_F(AbilityManagerServiceThirdTest, RequestDialogServiceInner_001, TestSize.Level1) { + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest RequestDialogServiceInner_001 start"); auto abilityMs = std::make_shared(); Want want; const sptr callerToken; @@ -1991,6 +2011,15 @@ HWTEST_F(AbilityManagerServiceThirdTest, RequestDialogServiceInner_001, TestSize int32_t userId = 0; auto result = abilityMs->RequestDialogServiceInner(want, callerToken, requestCode, userId); EXPECT_EQ(result, ERR_INVALID_CALLER); + + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + abilityMs->subManagersHelper_->currentUIAbilityManager_ = std::make_shared(); + std::shared_ptr abilityRecord = MockAbilityRecord(AbilityType::PAGE); + sptr callerToken2 = abilityRecord->GetToken(); + + result = abilityMs->RequestDialogServiceInner(want, callerToken2, requestCode, userId); + EXPECT_EQ(result, ERR_INVALID_CALLER); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest RequestDialogServiceInner_001 end"); } /* @@ -2107,6 +2136,23 @@ HWTEST_F(AbilityManagerServiceThirdTest, AppUpgradeCompleted_002, TestSize.Level EXPECT_TRUE(abilityMs != nullptr); } +/* + * Feature: AbilityManagerService + * Function: GetConfiguration + * SubFunction: NA + * FunctionPoints: AbilityManagerService GetConfiguration + */ +HWTEST_F(AbilityManagerServiceThirdTest, GetConfiguration_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest GetConfiguration_001 start"); + auto abilityMs_ = std::make_shared(); + AppExecFwk::Configuration config; + abilityMs_->SubscribeBackgroundTask(); + EXPECT_EQ(abilityMs_->GetConfiguration(config), 0); + abilityMs_->UnSubscribeBackgroundTask(); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest GetConfiguration_001 end"); +} + /* * Feature: AbilityManagerService * Function: GetAppMgr @@ -2119,6 +2165,42 @@ HWTEST_F(AbilityManagerServiceThirdTest, GetAppMgr_001, TestSize.Level1) EXPECT_NE(result, nullptr); } +/* + * Feature: AbilityManagerService + * Function: ReportAbilitStartInfoToRSS + * FunctionPoints: AbilityManagerService ReportAbilitStartInfoToRSS + */ +HWTEST_F(AbilityManagerServiceThirdTest, ReportAbilitStartInfoToRSS_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest ReportAbilitStartInfoToRSS start"); + auto abilityMs = std::make_shared(); + AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityMs->ReportAbilitStartInfoToRSS(abilityInfo); + EXPECT_EQ(abilityInfo.type, AppExecFwk::AbilityType::PAGE); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest ReportAbilitStartInfoToRSS end"); +} + +/* + * Feature: AbilityManagerService + * Function: ReportAbilitAssociatedStartInfoToRSS + * FunctionPoints: AbilityManagerService ReportAbilitAssociatedStartInfoToRSS + */ +HWTEST_F(AbilityManagerServiceThirdTest, ReportAbilitAssociatedStartInfoToRSS_001, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest ReportAbilitAssociatedStartInfoToRSS start"); + auto abilityMs = std::make_shared(); + AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.type = AppExecFwk::AbilityType::PAGE; + sptr callerToken = nullptr; + int64_t type = 0; + abilityMs->ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerToken); + callerToken = MockToken(AbilityType::PAGE); + abilityMs->ReportAbilitAssociatedStartInfoToRSS(abilityInfo, type, callerToken); + EXPECT_EQ(abilityInfo.type, AppExecFwk::AbilityType::PAGE); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest ReportAbilitAssociatedStartInfoToRSS end"); +} + /* * Feature: AbilityManagerService * Function: OnAddSystemAbility @@ -2401,6 +2483,35 @@ HWTEST_F(AbilityManagerServiceThirdTest, StartExtensionAbilityInner_003, TestSiz EXPECT_EQ(result, ERR_INVALID_CALLER); } +/* + * Feature: AbilityManagerService + * Function: StartExtensionAbilityInner + * FunctionPoints: AbilityManagerService StartExtensionAbilityInner + */ +HWTEST_F(AbilityManagerServiceThirdTest, StartExtensionAbilityInner_004, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest StartExtensionAbilityInner_004 start"); + auto abilityMs = std::make_shared(); + Want want; + sptr callerToken = nullptr; + int32_t userId = 0; + AppExecFwk::ExtensionAbilityType extensionType = AppExecFwk::ExtensionAbilityType::VPN; + bool checkSystemCaller = true; + bool isImplicit = true; + bool isDlp = true; + abilityMs->interceptorExecuter_ = std::make_shared(); + abilityMs->subManagersHelper_ = std::make_shared(nullptr, nullptr); + auto result = abilityMs->StartExtensionAbilityInner(want, callerToken, userId, extensionType, checkSystemCaller, + isImplicit, isDlp); + EXPECT_EQ(result, ERR_IMPLICIT_START_ABILITY_FAIL); + + abilityMs-> implicitStartProcessor_ = std::make_shared(); + result = abilityMs->StartExtensionAbilityInner(want, callerToken, userId, extensionType, checkSystemCaller, + isImplicit, isDlp); + EXPECT_EQ(result, ERR_IMPLICIT_START_ABILITY_FAIL); + TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest StartExtensionAbilityInner_004 end"); +} + /* * Feature: AbilityManagerService * Function: MoveAbilityToBackground diff --git a/test/unittest/ability_manager_service_third_test/mock/include/mock_ability_interceptor_executer.h b/test/unittest/ability_manager_service_third_test/mock/include/mock_ability_interceptor_executer.h index 60374db238..5b2569f566 100644 --- a/test/unittest/ability_manager_service_third_test/mock/include/mock_ability_interceptor_executer.h +++ b/test/unittest/ability_manager_service_third_test/mock/include/mock_ability_interceptor_executer.h @@ -27,7 +27,7 @@ using InterceptorMap = std::unordered_map Date: Wed, 26 Jun 2024 08:29:27 +0000 Subject: [PATCH 069/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 142ab4f947..70c8c1cce8 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -213,6 +213,7 @@ struct SelectorPhoneDialog { } .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 }) .align(Alignment.Center) + .margin({ top: 20 }) .width('90%') .indicator(this.phoneShowData.totalCount() > 1) } @@ -232,8 +233,7 @@ struct SelectorPhoneDialog { globalThis.selectExtensionContext.terminateSelf(); }) } - .borderRadius(24) - .borderWidth(1) + .borderRadius(24) .borderColor('#e9e9e9') .backgroundColor('#ffffff') .width('100%') From 8463712d503099bf99c817a108bce8acb90b9784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E9=B8=BF?= Date: Wed, 26 Jun 2024 16:55:41 +0800 Subject: [PATCH 070/148] =?UTF-8?q?IssueNo:=20#IA8HZZ=20Description:=20cod?= =?UTF-8?q?echeck=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 吴鸿 --- .../photo_editor_extension_ability.js | 2 +- .../photo_editor_extension_context.cpp | 12 +++++++++--- .../photo_editor_extension_context.h | 8 ++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/frameworks/js/napi/photo_editor_extension_ability/photo_editor_extension_ability.js b/frameworks/js/napi/photo_editor_extension_ability/photo_editor_extension_ability.js index ed321878ec..fa526e5088 100644 --- a/frameworks/js/napi/photo_editor_extension_ability/photo_editor_extension_ability.js +++ b/frameworks/js/napi/photo_editor_extension_ability/photo_editor_extension_ability.js @@ -18,6 +18,6 @@ let UIExtensionAbility = requireNapi('app.ability.UIExtensionAbility'); export default class PhotoEditorExtensionAbility extends UIExtensionAbility { onStartContentEditing(uri, want, session) { - console.log("onStartContentEditing: " + uri); + console.log('onStartContentEditing: ' + uri); } } \ No newline at end of file diff --git a/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp b/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp index d7dc659220..0b14f0ee41 100644 --- a/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp +++ b/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp @@ -14,6 +14,7 @@ */ #include "photo_editor_extension_context.h" +#include #include #include "media_errors.h" #include "hilog_tag_wrapper.h" @@ -114,8 +115,14 @@ PhotoEditorErrorCode PhotoEditorExtensionContext::CopyImageToPanel(const std::st TAG_LOGD(AAFwkTag::UI_EXT, "ImageUri: %{public}s, panelPhysicalPath: %{public}s.", imageUri.c_str(), panelPhysicalPath.c_str()); + char imagePath[PATH_MAX] = {0}; + if(realpath(imageUri.c_str(), imagePath) == nullptr) { + TAG_LOGE(AAFwkTag::UI_EXT, "Realpath error, errno is %{public}d.", errno); + return PhotoEditorErrorCode::ERROR_CODE_IMAGE_INPUT_ERROR; + } + std::ifstream sourceFile; - sourceFile.open(imageUri, std::ios::binary); + sourceFile.open(imagePath, std::ios::binary); if (!sourceFile.is_open()) { TAG_LOGE(AAFwkTag::UI_EXT, "Can not open source file."); sourceFile.close(); @@ -143,8 +150,7 @@ PhotoEditorErrorCode PhotoEditorExtensionContext::CopyImageToPanel(const std::st while (sourceFile.read(buffer, sizeof(buffer))) { panelFile.write(buffer, sizeof(buffer)); } - size_t remainingBytes = sourceFile.gcount(); - panelFile.write(buffer, remainingBytes); + panelFile.write(buffer, sourceFile.gcount()); sourceFile.close(); panelFile.close(); diff --git a/interfaces/kits/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.h b/interfaces/kits/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.h index a419223802..ef680eb18c 100644 --- a/interfaces/kits/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.h +++ b/interfaces/kits/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.h @@ -28,16 +28,16 @@ enum class PhotoEditorErrorCode { ERROR_OK = 0, // param error - ERROR_CODE_PARAM_ERROR = 1500000001, + ERROR_CODE_PARAM_ERROR = 401, // internal error - ERROR_CODE_INTERNAL_ERROR = 1500000002, + ERROR_CODE_INTERNAL_ERROR = 29600001, // image input error - ERROR_CODE_IMAGE_INPUT_ERROR = 1500000003, + ERROR_CODE_IMAGE_INPUT_ERROR = 29600002, // image too big - ERROR_CODE_IMAGE_TOO_BIG_ERROR = 1500000004 + ERROR_CODE_IMAGE_TOO_BIG_ERROR = 29600003 }; class PhotoEditorExtensionContext : public UIExtensionContext { From 60680aa33c168e25d049eab20f4a7ab06581d3b6 Mon Sep 17 00:00:00 2001 From: cheng Date: Tue, 25 Jun 2024 21:05:22 +0800 Subject: [PATCH 071/148] add mediacontrol uiextension type to non modal set Signed-off-by: cheng --- .../native/ability/native/extension_ability_thread.cpp | 6 ------ services/abilitymgr/resource/uiextension_picker_config.json | 4 ++++ services/common/include/ui_extension_utils.h | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/frameworks/native/ability/native/extension_ability_thread.cpp b/frameworks/native/ability/native/extension_ability_thread.cpp index dee2d4eff8..64d4daa428 100644 --- a/frameworks/native/ability/native/extension_ability_thread.cpp +++ b/frameworks/native/ability/native/extension_ability_thread.cpp @@ -32,7 +32,6 @@ namespace { constexpr static char FORM_EXTENSION[] = "FormExtension"; constexpr static char UI_EXTENSION[] = "UIExtensionAbility"; constexpr static char CUSTOM_EXTENSION[] = "ExtensionAbility"; -constexpr static char MEDIA_CONTROL_EXTENSION[] = "MediaControlExtensionAbility"; constexpr static char USER_AUTH_EXTENSION[] = "UserAuthExtensionAbility"; constexpr static char ACTION_EXTENSION[] = "ActionExtensionAbility"; constexpr static char SHARE_EXTENSION[] = "ShareExtensionAbility"; @@ -151,11 +150,6 @@ void ExtensionAbilityThread::CreateExtensionAbilityName( if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::INPUTMETHOD) { abilityName = INPUTMETHOD_EXTENSION; } -#ifdef SUPPORT_GRAPHICS - if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL) { - abilityName = MEDIA_CONTROL_EXTENSION; - } -#endif // SUPPORT_GRAPHICS if (abilityInfo->extensionAbilityType == AppExecFwk::ExtensionAbilityType::APP_ACCOUNT_AUTHORIZATION) { abilityName = APP_ACCOUNT_AUTHORIZATION_EXTENSION; } diff --git a/services/abilitymgr/resource/uiextension_picker_config.json b/services/abilitymgr/resource/uiextension_picker_config.json index 2b8b187f5e..f51de049c0 100644 --- a/services/abilitymgr/resource/uiextension_picker_config.json +++ b/services/abilitymgr/resource/uiextension_picker_config.json @@ -27,6 +27,10 @@ { "type": "audioPicker", "typePicker": "sysPicker/audioPicker" + }, + { + "type": "mediaControl", + "typePicker": "sysPicker/mediaControl" } ] } \ No newline at end of file diff --git a/services/common/include/ui_extension_utils.h b/services/common/include/ui_extension_utils.h index cce0630672..87b42fc8fd 100755 --- a/services/common/include/ui_extension_utils.h +++ b/services/common/include/ui_extension_utils.h @@ -125,7 +125,8 @@ inline bool IsPublicForEmbedded(const AppExecFwk::ExtensionAbilityType type) const std::unordered_set publicForEmbeddedSet = { AppExecFwk::ExtensionAbilityType::EMBEDDED_UI, // EMBEDDED_UI usage within the app AppExecFwk::ExtensionAbilityType::ADS, - AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER + AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER, + AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL }; return publicForEmbeddedSet.find(type) != publicForEmbeddedSet.end(); } From ce5b74721b1480b626e4e00d99aae6145d844f3a Mon Sep 17 00:00:00 2001 From: mars10577020 <8651080+mars10577020@user.noreply.gitee.com> Date: Wed, 26 Jun 2024 09:32:59 +0000 Subject: [PATCH 072/148] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mars10577020 <8651080+mars10577020@user.noreply.gitee.com> --- .../photo_editor_extension_context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp b/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp index 0b14f0ee41..1cdc3ba569 100644 --- a/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp +++ b/frameworks/native/ability/native/photo_editor_extension_ability/photo_editor_extension_context.cpp @@ -116,10 +116,10 @@ PhotoEditorErrorCode PhotoEditorExtensionContext::CopyImageToPanel(const std::st panelPhysicalPath.c_str()); char imagePath[PATH_MAX] = {0}; - if(realpath(imageUri.c_str(), imagePath) == nullptr) { + if (realpath(imageUri.c_str(), imagePath) == nullptr) { TAG_LOGE(AAFwkTag::UI_EXT, "Realpath error, errno is %{public}d.", errno); return PhotoEditorErrorCode::ERROR_CODE_IMAGE_INPUT_ERROR; - } + } std::ifstream sourceFile; sourceFile.open(imagePath, std::ios::binary); From 9b4ed887653a11687240a17eb99b4d01bf5c9348 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Wed, 26 Jun 2024 16:52:04 +0800 Subject: [PATCH 073/148] fixed lock Signed-off-by: yuwenze Change-Id: I03714327fc95fc1bffe13b1b787bbbda1501a0af --- .../inner_api/ability_manager/include/ability_manager_client.h | 1 + services/abilitymgr/src/ability_manager_client.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 cf2205b207..5056cb4ab5 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1510,6 +1510,7 @@ private: static std::once_flag singletonFlag_; std::recursive_mutex mutex_; + std::mutex topAbilityMutex_; static std::shared_ptr instance_; sptr proxy_; sptr deathRecipient_; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 9e52ff248f..9b268200d1 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1468,7 +1468,7 @@ AppExecFwk::ElementName AbilityManagerClient::GetTopAbility(bool isNeedLocalDevi { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); { - std::lock_guard lock_l(mutex_); + std::lock_guard lock_l(topAbilityMutex_); #ifdef SUPPORT_SCREEN if (Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { AppExecFwk::ElementName elementName = {}; From 6a879e6628a54724f64037b542153a35fd1cd3e5 Mon Sep 17 00:00:00 2001 From: liuzongze Date: Wed, 26 Jun 2024 17:55:32 +0800 Subject: [PATCH 074/148] =?UTF-8?q?taskPool=20=E5=85=BC=E5=AE=B9=E6=80=A7f?= =?UTF-8?q?ix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuzongze Change-Id: I0cf74bc8343b64e8de07d365eb659dea2c51a270 --- .../appkit/ability_runtime/app/js_ability_stage.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp index f9b4fb504a..dfa9b9d7be 100644 --- a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp @@ -48,8 +48,8 @@ constexpr const char* EXCLUDE_FROM_AUTO_START = "excludeFromAutoStart"; constexpr const char* RUN_ON_THREAD = "runOnThread"; constexpr const char* WAIT_ON_MAIN_THREAD = "waitOnMainThread"; constexpr const char* CONFIG_ENTRY = "configEntry"; -constexpr const char *MAIN_THREAD = "mainThread"; constexpr const char *TASKPOOL = "taskPool"; +constexpr const char *TASKPOOL_LOWER = "taskpool"; napi_value AttachAbilityStageContext(napi_env env, void *value, void *) { @@ -544,12 +544,10 @@ void JsAbilityStage::SetOptionalParameters( if (module.contains(RUN_ON_THREAD) && module[RUN_ON_THREAD].is_string()) { std::string profileName = module.at(RUN_ON_THREAD).get(); - if (profileName == MAIN_THREAD) { - jsStartupTask.SetCallCreateOnMainThread(true); - } else if (profileName == TASKPOOL) { + if (profileName == TASKPOOL || profileName == TASKPOOL_LOWER) { jsStartupTask.SetCallCreateOnMainThread(false); } else { - TAG_LOGW(AAFwkTag::APPKIT, "RunOnThread configuration is invalid."); + jsStartupTask.SetCallCreateOnMainThread(true); } } From fdd04d7ac3ad89cce3511e50910d2448b78b2bbe Mon Sep 17 00:00:00 2001 From: liangzhao Date: Wed, 26 Jun 2024 08:11:33 +0000 Subject: [PATCH 075/148] fix AbilityCache residue Signed-off-by: liangzhao --- .../include/ability_cache_manager.h | 2 - .../abilitymgr/src/ability_cache_manager.cpp | 18 +++--- .../src/ability_connect_manager.cpp | 58 +++++++++++-------- .../common/include/cache_extension_utils.h | 5 +- .../ability_cache_manager_test.cpp | 57 ++++++++++++++++-- 5 files changed, 100 insertions(+), 40 deletions(-) diff --git a/services/abilitymgr/include/ability_cache_manager.h b/services/abilitymgr/include/ability_cache_manager.h index df8aadfe34..fb23674f35 100644 --- a/services/abilitymgr/include/ability_cache_manager.h +++ b/services/abilitymgr/include/ability_cache_manager.h @@ -19,8 +19,6 @@ #include #include #include -#include -#include #include #include "ability_record.h" diff --git a/services/abilitymgr/src/ability_cache_manager.cpp b/services/abilitymgr/src/ability_cache_manager.cpp index 3309a73708..e2271b2a56 100644 --- a/services/abilitymgr/src/ability_cache_manager.cpp +++ b/services/abilitymgr/src/ability_cache_manager.cpp @@ -40,13 +40,10 @@ void AbilityCacheManager::Init(uint32_t devCapacity, uint32_t procCapacity) void AbilityCacheManager::RemoveAbilityRecInDevList(std::shared_ptr abilityRecord) { - AbilityInfo abilityInfo = abilityRecord->GetAbilityInfo(); auto it = devRecLru_.begin(); uint32_t accessTokenId = abilityRecord->GetApplicationInfo().accessTokenId; while (it != devRecLru_.end()) { - if ((*it)->GetAbilityInfo().bundleName == abilityInfo.bundleName && - (*it)->GetAbilityInfo().moduleName == abilityInfo.moduleName && - (*it)->GetApplicationInfo().accessTokenId == accessTokenId) { + if ((*it)->GetRecordId() == abilityRecord->GetRecordId()) { devRecLru_.erase(it); devLruCnt_--; return; @@ -58,7 +55,6 @@ void AbilityCacheManager::RemoveAbilityRecInDevList(std::shared_ptr abilityRecord) { - AbilityInfo abilityInfo = abilityRecord->GetAbilityInfo(); const Want want = abilityRecord->GetWant(); uint32_t accessTokenId = abilityRecord->GetApplicationInfo().accessTokenId; auto findProcInfo = procLruMap_.find(accessTokenId); @@ -69,8 +65,7 @@ void AbilityCacheManager::RemoveAbilityRecInProcList(std::shared_ptrsecond.recList.begin(); while (it != findProcInfo->second.recList.end()) { - if ((*it)->GetAbilityInfo().moduleName == abilityInfo.moduleName && - (*it)->GetWant().GetElement().GetAbilityName() == want.GetElement().GetAbilityName()) { + if ((*it)->GetRecordId() == abilityRecord->GetRecordId()) { findProcInfo->second.recList.erase(it); findProcInfo->second.cnt--; if (findProcInfo->second.cnt == 0) { @@ -130,6 +125,8 @@ std::shared_ptr AbilityCacheManager::Put(std::shared_ptrGetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); std::lock_guard lock(mutex_); std::shared_ptr rec = AddToProcLru(abilityRecord); return AddToDevLru(abilityRecord, rec); @@ -141,6 +138,8 @@ void AbilityCacheManager::Remove(std::shared_ptr abilityRecord) TAG_LOGE(AAFwkTag::ABILITYMGR, "The param abilityRecord is nullptr for Remove operation."); return; } + TAG_LOGD(AAFwkTag::ABILITYMGR, "Remove the ability from lru, service:%{public}s, extension type %{public}d", + abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); std::lock_guard lock(mutex_); RemoveAbilityRecInProcList(abilityRecord); RemoveAbilityRecInDevList(abilityRecord); @@ -177,9 +176,12 @@ std::shared_ptr AbilityCacheManager::GetAbilityRecInProcList(cons std::shared_ptr AbilityCacheManager::Get(const AbilityRequest& abilityRequest) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Get the ability from lru, service:%{public}s, extension type %{public}d", + abilityRequest.abilityInfo.uri.c_str(), abilityRequest.abilityInfo.extensionAbilityType); std::lock_guard lock(mutex_); std::shared_ptr abilityRecord = GetAbilityRecInProcList(abilityRequest); if (abilityRecord == nullptr) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Can't found the abilityRecord for get."); return nullptr; } RemoveAbilityRecInDevList(abilityRecord); @@ -197,6 +199,8 @@ std::shared_ptr AbilityCacheManager::FindRecordByToken(const sptr sptr srcToken = (*it)->GetToken(); if (srcToken == token) { std::shared_ptr &abilityRecord = *it; + TAG_LOGD(AAFwkTag::ABILITYMGR, "Find the ability from lru, service:%{public}s, extension type %{public}d", + abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); return abilityRecord; } else { it++; diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index dd87850175..2c9af82570 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -1023,6 +1023,7 @@ int AbilityConnectManager::ScheduleConnectAbilityDoneLocked( void AbilityConnectManager::ProcessEliminateAbilityRecord(std::shared_ptr eliminateRecord) { + CHECK_POINTER(eliminateRecord); std::string eliminateKey = eliminateRecord->GetURI(); if (FRS_BUNDLE_NAME == eliminateRecord->GetAbilityInfo().bundleName) { eliminateKey = eliminateKey + @@ -1035,28 +1036,35 @@ void AbilityConnectManager::ProcessEliminateAbilityRecord(std::shared_ptr abilityRecord) { RemoveUIExtensionAbilityRecord(abilityRecord); - if (!abilityRecord->IsSceneBoard()) { - if (IsCacheExtensionAbilityType(abilityRecord)) { - std::string serviceKey = abilityRecord->GetURI(); - auto abilityInfo = abilityRecord->GetAbilityInfo(); - if (FRS_BUNDLE_NAME == abilityInfo.bundleName) { - AppExecFwk::ElementName elementName(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name, - abilityInfo.moduleName); - serviceKey = elementName.GetURI() + - std::to_string(abilityRecord->GetWant().GetIntParam(FRS_APP_INDEX, 0)); - } - { - std::lock_guard lock(serviceMapMutex_); - serviceMap_.erase(serviceKey); - } - auto eliminateRecord = AbilityCacheManager::GetInstance().Put(abilityRecord); - if (eliminateRecord != nullptr) { - ProcessEliminateAbilityRecord(eliminateRecord); - } - } else { - TerminateRecord(abilityRecord); - } + if (abilityRecord->IsSceneBoard()) { + return; } + if (IsCacheExtensionAbilityType(abilityRecord)) { + std::string serviceKey = abilityRecord->GetURI(); + auto abilityInfo = abilityRecord->GetAbilityInfo(); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Cache the ability, service:%{public}s, extension type %{public}d", + serviceKey.c_str(), abilityInfo.extensionAbilityType); + if (FRS_BUNDLE_NAME == abilityInfo.bundleName) { + AppExecFwk::ElementName elementName(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name, + abilityInfo.moduleName); + serviceKey = elementName.GetURI() + + std::to_string(abilityRecord->GetWant().GetIntParam(FRS_APP_INDEX, 0)); + } + { + std::lock_guard lock(serviceMapMutex_); + serviceMap_.erase(serviceKey); + } + auto eliminateRecord = AbilityCacheManager::GetInstance().Put(abilityRecord); + if (eliminateRecord != nullptr) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate the eliminated ability, service:%{public}s.", + eliminateRecord->GetURI().c_str()); + ProcessEliminateAbilityRecord(eliminateRecord); + } + return; + } + TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate the ability, service:%{public}s, extension type %{public}d", + abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); + TerminateRecord(abilityRecord); } int AbilityConnectManager::ScheduleDisconnectAbilityDoneLocked(const sptr &token) @@ -2634,14 +2642,14 @@ void AbilityConnectManager::MoveToTerminatingMap(const std::shared_ptrGetAbilityInfo(); std::lock_guard lock(serviceMapMutex_); terminatingExtensionMap_.emplace(abilityRecord->GetURI(), abilityRecord); + std::string serviceKey = abilityRecord->GetURI(); if (FRS_BUNDLE_NAME == abilityInfo.bundleName) { AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name, abilityInfo.moduleName); - serviceMap_.erase( - element.GetURI() + std::to_string(abilityRecord->GetWant().GetIntParam(FRS_APP_INDEX, 0))); - } else { - serviceMap_.erase(abilityRecord->GetURI()); + serviceKey = element.GetURI() + std::to_string(abilityRecord->GetWant().GetIntParam(FRS_APP_INDEX, 0)); } + serviceMap_.erase(serviceKey); + AbilityCacheManager::GetInstance().Remove(abilityRecord); if (IsSpecialAbility(abilityRecord->GetAbilityInfo())) { TAG_LOGI(AAFwkTag::ABILITYMGR, "Moving ability: %{public}s", abilityRecord->GetURI().c_str()); } diff --git a/services/common/include/cache_extension_utils.h b/services/common/include/cache_extension_utils.h index c8300224cd..bb4d44344b 100755 --- a/services/common/include/cache_extension_utils.h +++ b/services/common/include/cache_extension_utils.h @@ -24,6 +24,8 @@ namespace OHOS { namespace AAFwk { namespace CacheExtensionUtils { +constexpr const int32_t BASE_TEN = 10; + // cache extension type list std::unordered_set GetCacheExtensionTypeList() { @@ -35,7 +37,8 @@ std::unordered_set GetCacheExtensionTypeList() std::vector cacheExtTypeListVec; SplitStr(cacheExtTypeListStr, ";", cacheExtTypeListVec); for (auto it = cacheExtTypeListVec.begin(); it != cacheExtTypeListVec.end(); it++) { - cacheExtTypeList.insert(static_cast(std::stoi(*it))); + cacheExtTypeList.insert( + static_cast(std::strtol((*it).c_str(), nullptr, BASE_TEN))); } return cacheExtTypeList; } diff --git a/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp b/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp index 13621d931c..e164f9f3be 100644 --- a/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp +++ b/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp @@ -78,6 +78,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutAndGetTest_001, TestSize abilityRecord_->Init(); std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); EXPECT_EQ(rec, nullptr); + int recId = abilityRecord_->GetRecordId(); AbilityRequest abilityRequest; abilityRequest.abilityInfo = abilityInfo; abilityRequest.appInfo = applicationInfo; @@ -99,6 +100,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutAndGetTest_001, TestSize EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo.bundleName); EXPECT_EQ(rec->GetWant().GetElement().GetAbilityName(), "ability"); + EXPECT_EQ(rec->GetRecordId(), recId); rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); EXPECT_EQ(rec, nullptr); } @@ -123,6 +125,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerRemoveTest_001, TestSize.Le auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); abilityRecord_->Init(); std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + int recId = abilityRecord_->GetRecordId(); EXPECT_EQ(rec, nullptr); applicationInfo.accessTokenId = 0; auto removeRec = std::make_shared(want, abilityInfo, applicationInfo); @@ -137,6 +140,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerRemoveTest_001, TestSize.Le EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo.bundleName); EXPECT_EQ(rec->GetWant().GetElement().GetAbilityName(), "ability"); + EXPECT_EQ(rec->GetRecordId(), recId); rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); EXPECT_EQ(rec, nullptr); } @@ -161,6 +165,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerRemoveTest_002, TestSize.Le auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); abilityRecord_->Init(); std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + int recId = abilityRecord_->GetRecordId(); EXPECT_EQ(rec, nullptr); abilityInfo.moduleName = "WrongModuleName"; auto removeRec = std::make_shared(want, abilityInfo, applicationInfo); @@ -175,6 +180,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerRemoveTest_002, TestSize.Le EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo.bundleName); EXPECT_EQ(rec->GetWant().GetElement().GetAbilityName(), "ability"); + EXPECT_EQ(rec->GetRecordId(), recId); rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); EXPECT_EQ(rec, nullptr); } @@ -199,6 +205,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerRemoveTest_003, TestSize.Le auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); abilityRecord_->Init(); std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + int recId = abilityRecord_->GetRecordId(); EXPECT_EQ(rec, nullptr); ElementName wrongeElement("", "", "wrongAbility", ""); want.SetElement(wrongeElement); @@ -213,6 +220,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerRemoveTest_003, TestSize.Le EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo.bundleName); EXPECT_EQ(rec->GetWant().GetElement().GetAbilityName(), "ability"); + EXPECT_EQ(rec->GetRecordId(), recId); rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); EXPECT_EQ(rec, nullptr); } @@ -237,7 +245,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_001, TestSize.Level abilityRecord1->Init(); std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord1); EXPECT_EQ(rec, nullptr); - + int recId1 = abilityRecord1->GetRecordId(); OHOS::AppExecFwk::AbilityInfo abilityInfo2; abilityInfo2.moduleName = "TestModuleName2"; abilityInfo2.bundleName = "TestBundleName2"; @@ -260,7 +268,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_001, TestSize.Level EXPECT_EQ(rec->GetApplicationInfo().accessTokenId, applicationInfo1.accessTokenId); EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo1.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo1.bundleName); - + EXPECT_EQ(rec->GetRecordId(), recId1); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord2); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord3); } @@ -294,7 +302,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_002, TestSize.Level abilityRecord2->Init(); rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord2); EXPECT_EQ(rec, nullptr); - + int recId2 = abilityRecord2->GetRecordId(); OHOS::AppExecFwk::AbilityInfo abilityInfo3; abilityInfo3.moduleName = "TestModuleName3"; abilityInfo3.bundleName = "TestBundleName3"; @@ -307,6 +315,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_002, TestSize.Level EXPECT_EQ(rec->GetApplicationInfo().accessTokenId, applicationInfo2.accessTokenId); EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo2.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo2.bundleName); + EXPECT_EQ(rec->GetRecordId(), recId2); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord1); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord3); } @@ -348,9 +357,9 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_003, TestSize.Level abilityInfo3.bundleName = "TestBundleName3"; OHOS::AppExecFwk::ApplicationInfo applicationInfo3; applicationInfo3.accessTokenId = 3; - auto abilityRecord3 = std::make_shared(want, abilityInfo3, applicationInfo3); abilityRecord3->Init(); + int recId3 = abilityRecord3->GetRecordId(); rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord3); EXPECT_EQ(rec, nullptr); @@ -366,6 +375,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_003, TestSize.Level EXPECT_EQ(rec->GetApplicationInfo().accessTokenId, applicationInfo3.accessTokenId); EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo3.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo3.bundleName); + EXPECT_EQ(rec->GetRecordId(), recId3); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord1); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord2); @@ -391,7 +401,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_004, TestSize.Level abilityRecord1->Init(); std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord1); EXPECT_EQ(rec, nullptr); - + int recId1 = abilityRecord1->GetRecordId(); OHOS::AppExecFwk::AbilityInfo abilityInfo2; abilityInfo2.moduleName = "TestModuleName2"; abilityInfo2.bundleName = "TestBundleName2"; @@ -414,6 +424,7 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutTest_004, TestSize.Level EXPECT_EQ(rec->GetApplicationInfo().accessTokenId, applicationInfo1.accessTokenId); EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo1.moduleName); EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo1.bundleName); + EXPECT_EQ(rec->GetRecordId(), recId1); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord2); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord3); @@ -453,5 +464,41 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerPutAndRemoveTest_001, TestS abilityRecord1->Init(); OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord1); } + +/** + * @tc.name: AbilityCacheManagerFindByToken_001 + * @tc.desc: Put a single ability record into cache and find it, find will not remove cache + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindByToken_001, TestSize.Level0) +{ + OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.moduleName = "TestModuleName"; + abilityInfo.bundleName = "TestBundleName"; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + applicationInfo.accessTokenId = 0; + Want want; + auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord_->Init(); + int recId = abilityRecord_->GetRecordId(); + std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + EXPECT_EQ(rec, nullptr); + auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().FindRecordByToken(abilityRecord_->GetToken()); + EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recordFind->GetRecordId(), recId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo = abilityInfo; + abilityRequest.appInfo = applicationInfo; + auto recGet = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); + EXPECT_EQ(recGet->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recGet->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recGet->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recGet->GetRecordId(), recId); +} + } // namespace AAFwk } // namespace OHOS From 16bd81023f3af4d2d5623d8c4aa0661e3cf62e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Wed, 26 Jun 2024 10:41:52 +0000 Subject: [PATCH 076/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 70c8c1cce8..6b6a8888b0 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -233,7 +233,9 @@ struct SelectorPhoneDialog { globalThis.selectExtensionContext.terminateSelf(); }) } - .borderRadius(24) + .borderRadius(24) + .borderWidth(1) + .align(Alignment.Center) .borderColor('#e9e9e9') .backgroundColor('#ffffff') .width('100%') From 7f0c28819ff80fa35f95d9317dd34eeb9a6ee50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Wed, 26 Jun 2024 10:44:47 +0000 Subject: [PATCH 077/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 6b6a8888b0..fb1cb1ae36 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -206,14 +206,13 @@ struct SelectorPhoneDialog { .rowsTemplate(this.selector.swiper.gridRows) .columnsGap(12) .rowsGap(12) - .margin({ top: 30 }) + .margin({ top: 10 }) .height(210) .align(Alignment.Center) }, item => item) } .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 }) .align(Alignment.Center) - .margin({ top: 20 }) .width('90%') .indicator(this.phoneShowData.totalCount() > 1) } From d749bafe98674e549e2fb86d844a42dcce745a37 Mon Sep 17 00:00:00 2001 From: donglin Date: Sat, 15 Jun 2024 13:05:10 +0000 Subject: [PATCH 078/148] modify erms's code Signed-off-by: donglin Change-Id: I0c7ebd22be1ffa16347a6d029e63160c258af307 --- ...bility_ecological_rule_mgr_service_param.h | 2 + .../interceptor/ecological_rule_interceptor.h | 5 +- .../src/ability_manager_service.cpp | 9 +- ...lity_ecological_rule_mgr_service_param.cpp | 16 +++- .../interceptor/disposed_rule_interceptor.cpp | 1 + .../ecological_rule_interceptor.cpp | 83 ++++++++++--------- 6 files changed, 68 insertions(+), 48 deletions(-) diff --git a/services/abilitymgr/include/ecological_rule/ability_ecological_rule_mgr_service_param.h b/services/abilitymgr/include/ecological_rule/ability_ecological_rule_mgr_service_param.h index ea12333645..a49f530125 100644 --- a/services/abilitymgr/include/ecological_rule/ability_ecological_rule_mgr_service_param.h +++ b/services/abilitymgr/include/ecological_rule/ability_ecological_rule_mgr_service_param.h @@ -75,6 +75,8 @@ struct AbilityCallerInfo : public Parcelable { std::string callerAppProvisionType; std::string targetAppProvisionType; AppExecFwk::ExtensionAbilityType callerExtensionAbilityType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED; + AppExecFwk::AbilityType targetAbilityType = AppExecFwk::AbilityType::UNKNOWN; + AppExecFwk::ExtensionAbilityType targetExtensionAbilityType = AppExecFwk::ExtensionAbilityType::UNSPECIFIED; bool ReadFromParcel(Parcel &parcel); diff --git a/services/abilitymgr/include/interceptor/ecological_rule_interceptor.h b/services/abilitymgr/include/interceptor/ecological_rule_interceptor.h index 9f9bd8aecf..09bfd762fc 100644 --- a/services/abilitymgr/include/interceptor/ecological_rule_interceptor.h +++ b/services/abilitymgr/include/interceptor/ecological_rule_interceptor.h @@ -40,9 +40,12 @@ public: }; private: + void GetEcologicalTargetInfo(const Want &want, ErmsCallerInfo &callerInfo); void GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId, const sptr &callerToken = nullptr); - void InitErmsCallerInfo(Want &want, ErmsCallerInfo &callerInfo) const; + void InitErmsCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId, + const sptr &callerToken = nullptr); + static int32_t GetAppTypeByBundleType(int32_t bundleType); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index e29b7114a2..f652dd66d7 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2927,7 +2927,7 @@ int AbilityManagerService::StartUIExtensionAbility(const sptr &exte } AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(abilityRequest.want, 0, GetUserId(), - false, callerToken, std::make_shared(abilityInfo)); + true, callerToken, std::make_shared(abilityInfo)); result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : afterCheckExecuter_->DoProcess(afterCheckParam); if (result != ERR_OK) { @@ -5757,10 +5757,6 @@ int AbilityManagerService::GenerateAbilityRequest(const Want &want, int requestC request.appInfo.name.c_str(), request.abilityInfo.moduleName.c_str(), request.uid); request.want.SetModuleName(request.abilityInfo.moduleName); - request.want.SetParam("send_to_erms_targetBundleType", - static_cast(request.abilityInfo.applicationInfo.bundleType)); - request.want.SetParam("send_to_erms_targetAppProvisionType", request.abilityInfo.applicationInfo.appProvisionType); - request.want.SetParam("send_to_erms_targetAppDistType", request.abilityInfo.applicationInfo.appDistributionType); if (want.GetBoolParam(Want::PARAM_RESV_START_RECENT, false) && AAFwk::PermissionVerification::GetInstance()->VerifyStartRecentAbilityPermission()) { @@ -5816,9 +5812,6 @@ int32_t AbilityManagerService::InitialAbilityRequest(AbilityRequest &request, TAG_LOGD(AAFwkTag::ABILITYMGR, "GenerateExtensionAbilityRequest end, app name: %{public}s, bundle name: %{public}s, uid: %{public}d.", request.appInfo.name.c_str(), request.appInfo.bundleName.c_str(), request.uid); - request.want.SetParam("send_to_erms_targetBundleType", - static_cast(request.abilityInfo.applicationInfo.bundleType)); - request.want.SetParam("send_to_erms_targetAppProvisionType", request.abilityInfo.applicationInfo.appProvisionType); TAG_LOGD(AAFwkTag::ABILITYMGR, "GenerateExtensionAbilityRequest, moduleName: %{public}s.", request.abilityInfo.moduleName.c_str()); diff --git a/services/abilitymgr/src/ecological_rule/ability_ecological_rule_mgr_service_param.cpp b/services/abilitymgr/src/ecological_rule/ability_ecological_rule_mgr_service_param.cpp index 704a24832a..4e740358c3 100644 --- a/services/abilitymgr/src/ecological_rule/ability_ecological_rule_mgr_service_param.cpp +++ b/services/abilitymgr/src/ecological_rule/ability_ecological_rule_mgr_service_param.cpp @@ -131,6 +131,8 @@ AbilityCallerInfo *AbilityCallerInfo::Unmarshalling(Parcel &in) info->callerAppProvisionType = in.ReadString(); info->targetAppProvisionType = in.ReadString(); info->callerExtensionAbilityType = static_cast(in.ReadInt32()); + info->targetAbilityType = static_cast(in.ReadInt32()); + info->targetExtensionAbilityType = static_cast(in.ReadInt32()); return info; } @@ -159,6 +161,16 @@ bool AbilityCallerInfo::Marshalling(Parcel &parcel) const TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write callerExtensionAbilityType failed"); return false; } + + if (!parcel.WriteInt32(static_cast(targetAbilityType))) { + TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetAbilityType failed"); + return false; + } + + if (!parcel.WriteInt32(static_cast(targetExtensionAbilityType))) { + TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "write targetExtensionAbilityType failed"); + return false; + } return true; } @@ -227,7 +239,9 @@ std::string AbilityCallerInfo::ToString() const std::to_string(static_cast(callerAbilityType)) + ",callerExtensionAbilityType:" + std::to_string(static_cast(callerExtensionAbilityType)) + ",embedded:" + std::to_string(embedded) + ",callerAppProvisionType:" + callerAppProvisionType + ",targetAppProvisionType:" + - targetAppProvisionType + "}"; + targetAppProvisionType + ",targetAbilityType:" + + std::to_string(static_cast(targetAbilityType)) + ",targetExtensionAbilityType:" + + std::to_string(static_cast(targetExtensionAbilityType)) + "}"; return str; } } // namespace EcologicalRuleMgrService diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index 4366dfe785..56a240522c 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -24,6 +24,7 @@ #include "iservice_registry.h" #include "modal_system_ui_extension.h" #include "task_utils_wrap.h" +#include "ui_extension_utils.h" namespace OHOS { namespace AAFwk { diff --git a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp index e18970b521..11b83352f5 100644 --- a/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ecological_rule_interceptor.cpp @@ -54,12 +54,7 @@ ErrCode EcologicalRuleInterceptor::DoProcess(AbilityInterceptorParam param) } AAFwk::Want newWant = param.want; newWant.RemoveAllFd(); - GetEcologicalCallerInfo(newWant, callerInfo, param.userId, param.callerToken); - std::string supportErms = OHOS::system::GetParameter(ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE, "true"); - if (supportErms == "false") { - TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "Abilityms not support Erms between applications."); - return ERR_OK; - } + InitErmsCallerInfo(newWant, callerInfo, param.userId, param.callerToken); int ret = IN_PROCESS_CALL(AbilityEcologicalRuleMgrServiceClient::GetInstance()->QueryStartExperience(newWant, callerInfo, rule)); @@ -72,6 +67,12 @@ ErrCode EcologicalRuleInterceptor::DoProcess(AbilityInterceptorParam param) TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "ecological rule is allow, keep going."); return ERR_OK; } + + std::string supportErms = OHOS::system::GetParameter(ABILITY_SUPPORT_ECOLOGICAL_RULEMGRSERVICE, "true"); + if (supportErms == "false") { + TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "Abilityms not support Erms between applications."); + return ERR_OK; + } #ifdef SUPPORT_GRAPHICS if (param.isWithUI && rule.replaceWant) { (const_cast(param.want)) = *rule.replaceWant; @@ -104,18 +105,17 @@ bool EcologicalRuleInterceptor::DoProcess(Want &want, int32_t userId) } want.SetElement(launchWant.GetElement()); - AppExecFwk::ApplicationInfo targetAppInfo; - bool getCallerResult = IN_PROCESS_CALL(bundleMgrHelper->GetApplicationInfo(want.GetBundle(), - AppExecFwk::ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, targetAppInfo)); - if (!getCallerResult) { + int32_t appIndex = 0; + StartAbilityUtils::startAbilityInfo = StartAbilityInfo::CreateStartAbilityInfo(want, + userId, appIndex); + if (StartAbilityUtils::startAbilityInfo->status != ERR_OK) { TAG_LOGE(AAFwkTag::ECOLOGICAL_RULE, "Get targetApplicationInfo failed."); return false; } - want.SetParam("send_to_erms_targetAppProvisionType", targetAppInfo.appProvisionType); - want.SetParam("send_to_erms_targetBundleType", static_cast(targetAppInfo.bundleType)); ErmsCallerInfo callerInfo; - GetEcologicalCallerInfo(want, callerInfo, userId); + InitErmsCallerInfo(want, callerInfo, userId); + ExperienceRule rule; AAFwk::Want newWant = want; newWant.RemoveAllFd(); @@ -128,11 +128,26 @@ bool EcologicalRuleInterceptor::DoProcess(Want &want, int32_t userId) return rule.isAllow; } +void EcologicalRuleInterceptor::GetEcologicalTargetInfo(const Want &want, ErmsCallerInfo &callerInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + callerInfo.targetLinkFeature = want.GetStringParam("send_to_erms_targetLinkFeature"); + callerInfo.targetLinkType = want.GetIntParam("send_to_erms_targetLinkType", 0); + if (StartAbilityUtils::startAbilityInfo) { + AppExecFwk::AbilityInfo targetAbilityInfo = StartAbilityUtils::startAbilityInfo->abilityInfo; + callerInfo.targetAppDistType = targetAbilityInfo.applicationInfo.appDistributionType; + callerInfo.targetAppProvisionType = targetAbilityInfo.applicationInfo.appProvisionType; + callerInfo.targetAppType = GetAppTypeByBundleType(static_cast( + targetAbilityInfo.applicationInfo.bundleType)); + callerInfo.targetAbilityType = targetAbilityInfo.type; + callerInfo.targetExtensionAbilityType = targetAbilityInfo.extensionAbilityType; + } +} + void EcologicalRuleInterceptor::GetEcologicalCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId, const sptr &callerToken) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - InitErmsCallerInfo(const_cast(want), callerInfo); AppExecFwk::ApplicationInfo callerAppInfo; AppExecFwk::AbilityInfo callerAbilityInfo; @@ -177,39 +192,31 @@ void EcologicalRuleInterceptor::GetEcologicalCallerInfo(const Want &want, ErmsCa } } -void EcologicalRuleInterceptor::InitErmsCallerInfo(Want &want, ErmsCallerInfo &callerInfo) const +void EcologicalRuleInterceptor::InitErmsCallerInfo(const Want &want, ErmsCallerInfo &callerInfo, int32_t userId, + const sptr &callerToken) { callerInfo.packageName = want.GetStringParam(Want::PARAM_RESV_CALLER_BUNDLE_NAME); callerInfo.uid = want.GetIntParam(Want::PARAM_RESV_CALLER_UID, IPCSkeleton::GetCallingUid()); callerInfo.pid = want.GetIntParam(Want::PARAM_RESV_CALLER_PID, IPCSkeleton::GetCallingPid()); - callerInfo.targetAppType = ErmsCallerInfo::TYPE_INVALID; - callerInfo.callerAppType = ErmsCallerInfo::TYPE_INVALID; - callerInfo.targetLinkFeature = want.GetStringParam("send_to_erms_targetLinkFeature"); - callerInfo.targetAppDistType = want.GetStringParam("send_to_erms_targetAppDistType"); - callerInfo.targetLinkType = want.GetIntParam("send_to_erms_targetLinkType", 0); - want.RemoveParam("send_to_erms_targetLinkFeature"); - want.RemoveParam("send_to_erms_targetAppDistType"); - want.RemoveParam("send_to_erms_targetLinkType"); - HILOG_INFO( - "get callerInfo targetLinkFeature is %{public}s, targetAppDistType is %{public}s, targetLinkType is %{public}d", - callerInfo.targetLinkFeature.c_str(), callerInfo.targetAppDistType.c_str(), callerInfo.targetLinkType); callerInfo.embedded = want.GetIntParam("send_to_erms_embedded", 0); - callerInfo.targetAppProvisionType = want.GetStringParam("send_to_erms_targetAppProvisionType"); + + GetEcologicalTargetInfo(want, callerInfo); + GetEcologicalCallerInfo(want, callerInfo, userId, callerToken); + TAG_LOGI(AAFwkTag::ECOLOGICAL_RULE, "The ERMS's %{public}s", callerInfo.ToString().c_str()); +} - auto targetBundleType = want.GetIntParam("send_to_erms_targetBundleType", -1); - want.RemoveParam("send_to_erms_targetBundleType"); - if (targetBundleType == static_cast(AppExecFwk::BundleType::ATOMIC_SERVICE)) { - TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "the target type is atomic service"); - callerInfo.targetAppType = ErmsCallerInfo::TYPE_ATOM_SERVICE; +int32_t EcologicalRuleInterceptor::GetAppTypeByBundleType(int32_t bundleType) +{ + if (bundleType == static_cast(AppExecFwk::BundleType::ATOMIC_SERVICE)) { + return ErmsCallerInfo::TYPE_ATOM_SERVICE; } - if (targetBundleType == static_cast(AppExecFwk::BundleType::APP)) { - TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "the target type is app"); - callerInfo.targetAppType = ErmsCallerInfo::TYPE_HARMONY_APP; + if (bundleType == static_cast(AppExecFwk::BundleType::APP)) { + return ErmsCallerInfo::TYPE_HARMONY_APP; } - if (targetBundleType == static_cast(AppExecFwk::BundleType::APP_SERVICE_FWK)) { - TAG_LOGD(AAFwkTag::ECOLOGICAL_RULE, "the target type is app service"); - callerInfo.targetAppType = ErmsCallerInfo::TYPE_APP_SERVICE; + if (bundleType == static_cast(AppExecFwk::BundleType::APP_SERVICE_FWK)) { + return ErmsCallerInfo::TYPE_APP_SERVICE; } + return ErmsCallerInfo::TYPE_INVALID; } } // namespace AAFwk } // namespace OHOS \ No newline at end of file From 69d6b623f4b5b600ca0d11c23ac82fc7a741a841 Mon Sep 17 00:00:00 2001 From: hhl Date: Tue, 25 Jun 2024 09:44:51 +0800 Subject: [PATCH 079/148] set appfreeze filter callback Signed-off-by: hhl --- frameworks/native/appkit/BUILD.gn | 2 + .../native/appkit/app/dump_runtime_helper.cpp | 54 +++++++++++++++++++ frameworks/native/appkit/app/main_thread.cpp | 4 ++ .../native/appkit/app/dump_runtime_helper.h | 34 ++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 frameworks/native/appkit/app/dump_runtime_helper.cpp create mode 100644 interfaces/kits/native/appkit/app/dump_runtime_helper.h diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 3e8fef309b..de113bb9cd 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -120,6 +120,7 @@ ohos_shared_library("appkit_native") { "${ability_runtime_native_path}/appkit/app/child_main_thread.cpp", "${ability_runtime_native_path}/appkit/app/dump_ffrt_helper.cpp", "${ability_runtime_native_path}/appkit/app/dump_ipc_helper.cpp", + "${ability_runtime_native_path}/appkit/app/dump_runtime_helper.cpp", "${ability_runtime_native_path}/appkit/app/extension_plugin_info.cpp", "${ability_runtime_native_path}/appkit/app/idle_time.cpp", "${ability_runtime_native_path}/appkit/app/main_thread.cpp", @@ -175,6 +176,7 @@ ohos_shared_library("appkit_native") { "bundle_framework:appexecfwk_core", "c_utils:utils", "common_event_service:cesfwk_innerkits", + "ets_runtime:libark_jsruntime", "eventhandler:libeventhandler", "faultloggerd:libbacktrace_local", "faultloggerd:libdfx_procinfo", diff --git a/frameworks/native/appkit/app/dump_runtime_helper.cpp b/frameworks/native/appkit/app/dump_runtime_helper.cpp new file mode 100644 index 0000000000..75054a0d60 --- /dev/null +++ b/frameworks/native/appkit/app/dump_runtime_helper.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dump_runtime_helper.h" + +#include "app_mgr_client.h" +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" +#include "js_runtime.h" +#include "singleton.h" +#include "dfx_jsnapi.h" + +namespace OHOS { +namespace AppExecFwk { +DumpRuntimeHelper::DumpRuntimeHelper(const std::shared_ptr &application) + : application_(application) +{} + +void DumpRuntimeHelper::SetAppFreezeFilterCallback() +{ + if (application_ == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "SetAppFreezeFilterCallback OHOSApplication is nullptr"); + return; + } + auto& runtime = application_->GetRuntime(); + if (runtime == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "SetAppFreezeFilterCallback GetRuntime is nullptr"); + return; + } + auto appfreezeFilterCallback = [] (const int32_t pid) -> bool { + auto client = DelayedSingleton::GetInstance(); + if (client == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "SetAppFreezeFilterCallback client is nullptr"); + return false; + } + return client->SetAppFreezeFilter(pid); + }; + auto vm = (static_cast(*runtime)).GetEcmaVm(); + panda::DFXJSNApi::SetAppFreezeFilterCallback(vm, appfreezeFilterCallback); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index a58c4c277f..118441082d 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -49,6 +49,7 @@ #include "context_impl.h" #include "dump_ffrt_helper.h" #include "dump_ipc_helper.h" +#include "dump_runtime_helper.h" #include "exit_reason.h" #include "extension_ability_info.h" #include "extension_module_loader.h" @@ -1661,6 +1662,9 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con IdleNotifyStatusCallback cb = idleTime_->GetIdleNotifyFunc(); jsEngine.NotifyIdleStatusControl(cb); + + auto helper = std::make_shared(application_); + helper->SetAppFreezeFilterCallback(); } #ifdef CJ_FRONTEND } diff --git a/interfaces/kits/native/appkit/app/dump_runtime_helper.h b/interfaces/kits/native/appkit/app/dump_runtime_helper.h new file mode 100644 index 0000000000..89f36960e4 --- /dev/null +++ b/interfaces/kits/native/appkit/app/dump_runtime_helper.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_DUMP_RUNTIME_HELPER_H +#define OHOS_ABILITY_RUNTIME_DUMP_RUNTIME_HELPER_H + +#include "ohos_application.h" + +namespace OHOS { +namespace AppExecFwk { +class DumpRuntimeHelper : public std::enable_shared_from_this { +public: + explicit DumpRuntimeHelper(const std::shared_ptr &application); + ~DumpRuntimeHelper() = default; + void SetAppFreezeFilterCallback(); +private: + std::shared_ptr application_ = nullptr; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_DUMP_RUNTIME_HELPER_H From aa456f092362dd8220fca5f53ee7721823257dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 02:26:38 +0000 Subject: [PATCH 080/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index fb1cb1ae36..f06d2769dd 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -139,7 +139,7 @@ struct SelectorPhoneDialog { } build() { - Flex({ direction: FlexDirection.Column }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Flex({ direction: FlexDirection.Column }) { Text($r('app.string.message_title_selector')) .fontSize(22) From e4ca64f606043e3246475095b8aa41e952a0c8aa Mon Sep 17 00:00:00 2001 From: sunxuhui Date: Thu, 27 Jun 2024 11:58:17 +0800 Subject: [PATCH 081/148] =?UTF-8?q?extensionContext=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunxuhui --- .../js_ui_extension_content_session.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp index e881135375..2ebfeae4d8 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp @@ -1081,10 +1081,11 @@ void JsUIExtensionContentSession::SetCallbackForTerminateWithResult(int32_t resu if (!extensionContext) { TAG_LOGE(AAFwkTag::UI_EXT, "extensionContext is nullptr"); task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); - return; + } else { + auto token = extensionContext->GetToken(); + AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want); } - auto token = extensionContext->GetToken(); - AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want); + if (uiWindow == nullptr) { TAG_LOGE(AAFwkTag::UI_EXT, "uiWindow is nullptr."); task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); From b1723980c92ca78447941f4caa169e0e40cf5d83 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Thu, 27 Jun 2024 12:49:03 +0800 Subject: [PATCH 082/148] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/IA8P0G MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 删除绝对路径 Signed-off-by: jiangzhijun8 --- frameworks/native/ability/native/BUILD.gn | 4 ++-- frameworks/native/runtime/js_worker.cpp | 16 ++++++++-------- .../ability/ability_runtime/ability_context.h | 3 +-- .../continuation_connector.h | 12 ++++++------ .../ability/native/data_ability_helper_impl.h | 4 ++-- .../native/ability/native/extension_base.inl | 4 ++-- .../appkit/ability_delegator/ability_delegator.h | 7 +++---- interfaces/kits/native/appkit/app/context_deal.h | 2 +- .../native/appkit/app/{context.h => contxt.h} | 8 ++++---- .../kits/native/appkit/app/ohos_application.h | 2 +- .../mock_ability_runtime_context.h | 2 +- 11 files changed, 31 insertions(+), 33 deletions(-) rename interfaces/kits/native/appkit/app/{context.h => contxt.h} (100%) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 5d3898ed6e..47385964b9 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -36,8 +36,6 @@ config("ability_config") { "${ability_runtime_innerkits_path}/uri/include", "${ability_runtime_services_path}/abilitymgr/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", - "${ability_runtime_path}/interfaces/kits/native/appkit/app", - "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_innerkits_path}/ability_manager/include/continuation", "${ability_runtime_path}/interfaces/kits/native/appkit/app/task", "${ability_runtime_napi_path}/inner/napi_common", @@ -1150,6 +1148,7 @@ ohos_shared_library("ui_extension_module") { deps = [ ":ui_extension", "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/appkit:appkit_native", ] external_deps = [ @@ -1584,6 +1583,7 @@ ohos_shared_library("auto_fill_extension_module") { deps = [ ":auto_fill_extension", "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_native_path}/appkit:appkit_native", ] external_deps = [ diff --git a/frameworks/native/runtime/js_worker.cpp b/frameworks/native/runtime/js_worker.cpp index fad54284f3..cf2d5a0f31 100644 --- a/frameworks/native/runtime/js_worker.cpp +++ b/frameworks/native/runtime/js_worker.cpp @@ -22,9 +22,11 @@ #include #include +#include "bundle_info.h" #include "bundle_mgr_helper.h" +#include "bundle_mgr_proxy.h" #include "connect_server_manager.h" -#include "commonlibrary/c_utils/base/include/refbase.h" +#include "console.h" #ifdef SUPPORT_SCREEN #include "core/common/container_scope.h" #include "declarative_module_preloader.h" @@ -32,18 +34,16 @@ #include "extractor.h" #include "file_mapper.h" -#include "foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_base/include/bundle_info.h" -#include "foundation/bundlemanager/bundle_framework/interfaces/inner_api/appexecfwk_core/include/bundlemgr/bundle_mgr_proxy.h" -#include "foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include/iservice_registry.h" -#include "foundation/communication/ipc/interfaces/innerkits/ipc_core/include/iremote_object.h" -#include "singleton.h" -#include "system_ability_definition.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" +#include "iremote_object.h" +#include "iservice_registry.h" #include "js_runtime_utils.h" #include "native_engine/impl/ark/ark_native_engine.h" -#include "commonlibrary/ets_utils/js_sys_module/console/console.h" +#include "refbase.h" +#include "singleton.h" #include "syscap_ts.h" +#include "system_ability_definition.h" #ifdef SUPPORT_SCREEN using OHOS::Ace::ContainerScope; #endif diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context.h b/interfaces/kits/native/ability/ability_runtime/ability_context.h index 4a05e9daab..7ea7e4ce22 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context.h @@ -16,13 +16,12 @@ #ifndef OHOS_ABILITY_RUNTIME_ABILITY_CONTEXT_H #define OHOS_ABILITY_RUNTIME_ABILITY_CONTEXT_H -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" - #include "ability_connect_callback.h" #include "ability_info.h" #include "ability_lifecycle_observer_interface.h" #include "caller_callback.h" #include "configuration.h" +#include "context.h" #include "iability_callback.h" #include "js_ui_extension_callback.h" #include "mission_info.h" diff --git a/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_connector.h b/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_connector.h index d0e41e34f0..4be06f4a03 100644 --- a/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_connector.h +++ b/interfaces/kits/native/ability/native/continuation/remote_register_service/continuation_connector.h @@ -22,15 +22,15 @@ #include #include -#include "iremote_broker.h" -#include "element_name.h" -#include "refbase.h" -#include "context.h" -#include "extra_params.h" -#include "continuation_request.h" #include "ability_connect_callback_stub.h" +#include "continuation_request.h" #include "continuation/kits/continuation_device_callback_interface.h" #include "continuation/remote_register_service_interface.h" +#include "contxt.h" +#include "element_name.h" +#include "extra_params.h" +#include "iremote_broker.h" +#include "refbase.h" namespace OHOS { namespace AppExecFwk { diff --git a/interfaces/kits/native/ability/native/data_ability_helper_impl.h b/interfaces/kits/native/ability/native/data_ability_helper_impl.h index 9dd6e50327..2ed30f492a 100644 --- a/interfaces/kits/native/ability/native/data_ability_helper_impl.h +++ b/interfaces/kits/native/ability/native/data_ability_helper_impl.h @@ -20,8 +20,8 @@ #include #include -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/app/context.h" -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" +#include "context.h" +#include "contxt.h" #include "uri.h" using Uri = OHOS::Uri; diff --git a/interfaces/kits/native/ability/native/extension_base.inl b/interfaces/kits/native/ability/native/extension_base.inl index 440300077b..c2a2d4320d 100644 --- a/interfaces/kits/native/ability/native/extension_base.inl +++ b/interfaces/kits/native/ability/native/extension_base.inl @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/application_context.h" +#include "application_context.h" +#include "context.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" diff --git a/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h b/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h index 1eab52f3c1..d891180b54 100644 --- a/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h +++ b/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h @@ -29,14 +29,13 @@ #endif #include "ability_delegator_infos.h" +#include "ability_lifecycle_executor.h" +#include "context.h" +#include "delegator_thread.h" #include "iability_monitor.h" #include "iability_stage_monitor.h" -#include "delegator_thread.h" #include "shell_cmd_result.h" #include "test_runner.h" - -#include "ability_lifecycle_executor.h" -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" #include "want.h" namespace OHOS { diff --git a/interfaces/kits/native/appkit/app/context_deal.h b/interfaces/kits/native/appkit/app/context_deal.h index 73cb8ca70e..3399eba4da 100644 --- a/interfaces/kits/native/appkit/app/context_deal.h +++ b/interfaces/kits/native/appkit/app/context_deal.h @@ -16,7 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_CONTEXT_DEAL_H #define OHOS_ABILITY_RUNTIME_CONTEXT_DEAL_H -#include "context.h" +#include "contxt.h" #include "lifecycle_state_info.h" namespace OHOS { diff --git a/interfaces/kits/native/appkit/app/context.h b/interfaces/kits/native/appkit/app/contxt.h similarity index 100% rename from interfaces/kits/native/appkit/app/context.h rename to interfaces/kits/native/appkit/app/contxt.h index 3a2b3a5f31..58408acea0 100644 --- a/interfaces/kits/native/appkit/app/context.h +++ b/interfaces/kits/native/appkit/app/contxt.h @@ -18,13 +18,13 @@ #include -#include "bundle_mgr_interface.h" -#include "ability_manager_interface.h" #include "ability_info.h" -#include "process_info.h" -#include "resource_manager.h" +#include "ability_manager_interface.h" +#include "bundle_mgr_interface.h" #include "dummy_hap_module_info.h" #include "hap_module_info.h" +#include "process_info.h" +#include "resource_manager.h" #include "task/task_priority.h" namespace OHOS { diff --git a/interfaces/kits/native/appkit/app/ohos_application.h b/interfaces/kits/native/appkit/app/ohos_application.h index f8a664ce28..ca9e9a3ca2 100644 --- a/interfaces/kits/native/appkit/app/ohos_application.h +++ b/interfaces/kits/native/appkit/app/ohos_application.h @@ -22,9 +22,9 @@ #include #include "ability_lifecycle_callbacks.h" -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" #include "ability_stage.h" #include "app_context.h" +#include "context.h" #include "element_callback.h" namespace OHOS { diff --git a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h index 9672c0fa13..be4fa4379c 100644 --- a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h +++ b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h @@ -20,7 +20,7 @@ #define private public #define protected public -#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" +#include "context.h" #undef private #undef protected From 32641130e4420d3b1f159004955c63abe6498b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=97=AD=E8=BE=89?= Date: Thu, 27 Jun 2024 06:22:06 +0000 Subject: [PATCH 083/148] update frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙旭辉 --- .../ui_extension_ability/js_ui_extension_content_session.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp index 2ebfeae4d8..bd1afa8c89 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_content_session.cpp @@ -1080,7 +1080,6 @@ void JsUIExtensionContentSession::SetCallbackForTerminateWithResult(int32_t resu auto extensionContext = AbilityRuntime::Context::ConvertTo(weak.lock()); if (!extensionContext) { TAG_LOGE(AAFwkTag::UI_EXT, "extensionContext is nullptr"); - task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INVALID_CONTEXT)); } else { auto token = extensionContext->GetToken(); AAFwk::AbilityManagerClient::GetInstance()->TransferAbilityResultForExtension(token, resultCode, want); From bb8bf713976cc3d584f1d040dcac8942669e2d5e Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Thu, 27 Jun 2024 14:28:05 +0800 Subject: [PATCH 084/148] =?UTF-8?q?proxy=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: savior-xzh Change-Id: I7c10d15ec6d8f62ba1e52faf2358e9f4a4d4a35a --- .../app_manager/include/appmgr/parcel_util.h | 57 ++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 640 +++++------------- 2 files changed, 210 insertions(+), 487 deletions(-) create mode 100644 interfaces/inner_api/app_manager/include/appmgr/parcel_util.h diff --git a/interfaces/inner_api/app_manager/include/appmgr/parcel_util.h b/interfaces/inner_api/app_manager/include/appmgr/parcel_util.h new file mode 100644 index 0000000000..d34e1aae9b --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/parcel_util.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H +#define OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +#define PARCEL_UTIL_WRITE_NORET(parcel, type, value) \ + do { \ + if (!(parcel).Write##type(value)) { \ + TAG_LOGE(AAFwkTag::APPMGR, "failed to write %{public}s", #value); \ + return; \ + } \ + } while (0) + +#define PARCEL_UTIL_WRITE_RET_INT(parcel, type, value) \ + do { \ + if (!(parcel).Write##type(value)) { \ + TAG_LOGE(AAFwkTag::APPMGR, "failed to write %{public}s", #value); \ + return IPC_PROXY_ERR; \ + } \ + } while (0) + +#define PARCEL_UTIL_SENDREQ_NORET(code, data, reply, option) \ + do { \ + int32_t ret = SendRequest(code, data, reply, option); \ + if (ret != NO_ERROR) { \ + TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); \ + } \ + } while (0) + +#define PARCEL_UTIL_SENDREQ_RET_INT(code, data, reply, option) \ + do { \ + int32_t ret = SendRequest(code, data, reply, option); \ + if (ret != NO_ERROR) { \ + TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); \ + return ret; \ + } \ + } while (0) +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_PARCEL_UTIL_H 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 cb03c801c8..b58d25c3db 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 @@ -21,19 +21,10 @@ #include "hitrace_meter.h" #include "ipc_types.h" #include "iremote_object.h" +#include "parcel_util.h" namespace OHOS { namespace AppExecFwk { -namespace { -#define PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(messageParcel, type, value) \ - do { \ - if (!(messageParcel).Write##type(value)) { \ - TAG_LOGE(AAFwkTag::APPMGR, \ - "failed to write %{public}s", #value); \ - return IPC_PROXY_ERR; \ - } \ - } while (0) -} constexpr int32_t CYCLE_LIMIT = 1000; AppMgrProxy::AppMgrProxy(const sptr &impl) : IRemoteProxy(impl) {} @@ -55,14 +46,9 @@ void AppMgrProxy::AttachApplication(const sptr &obj) if (!WriteInterfaceToken(data)) { return; } - if (!data.WriteRemoteObject(obj.GetRefPtr())) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write remote object"); - return; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_ATTACH_APPLICATION, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } + PARCEL_UTIL_WRITE_NORET(data, RemoteObject, obj.GetRefPtr()); + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_ATTACH_APPLICATION, data, reply, option); } int32_t AppMgrProxy::PreloadApplication(const std::string &bundleName, int32_t userId, @@ -72,21 +58,16 @@ int32_t AppMgrProxy::PreloadApplication(const std::string &bundleName, int32_t u MessageParcel data; MessageParcel reply; MessageOption option(MessageOption::TF_SYNC); - if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Write interface token failed."); return IPC_PROXY_ERR; } - PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(bundleName)); - PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId); - PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, static_cast(preloadMode)); - PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, appIndex); + PARCEL_UTIL_WRITE_RET_INT(data, String16, Str8ToStr16(bundleName)); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, static_cast(preloadMode)); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, appIndex); - int32_t error = SendRequest(AppMgrInterfaceCode::PRELOAD_APPLICATION, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "PreloadApplication Send request error: %{public}d.", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PRELOAD_APPLICATION, data, reply, option); return reply.ReadInt32(); } @@ -98,11 +79,9 @@ void AppMgrProxy::ApplicationForegrounded(const int32_t recordId) if (!WriteInterfaceToken(data)) { return; } - data.WriteInt32(recordId); - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } + PARCEL_UTIL_WRITE_NORET(data, Int32, recordId); + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED, data, reply, option); } void AppMgrProxy::ApplicationBackgrounded(const int32_t recordId) @@ -113,11 +92,9 @@ void AppMgrProxy::ApplicationBackgrounded(const int32_t recordId) if (!WriteInterfaceToken(data)) { return; } - data.WriteInt32(recordId); - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } + PARCEL_UTIL_WRITE_NORET(data, Int32, recordId); + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED, data, reply, option); } void AppMgrProxy::ApplicationTerminated(const int32_t recordId) @@ -128,11 +105,9 @@ void AppMgrProxy::ApplicationTerminated(const int32_t recordId) if (!WriteInterfaceToken(data)) { return; } - data.WriteInt32(recordId); - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_APPLICATION_TERMINATED, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } + PARCEL_UTIL_WRITE_NORET(data, Int32, recordId); + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_APPLICATION_TERMINATED, data, reply, option); } void AppMgrProxy::AbilityCleaned(const sptr &token) @@ -143,14 +118,9 @@ void AppMgrProxy::AbilityCleaned(const sptr &token) if (!WriteInterfaceToken(data)) { return; } - if (!data.WriteRemoteObject(token.GetRefPtr())) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token"); - return; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_ABILITY_CLEANED, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } + PARCEL_UTIL_WRITE_NORET(data, RemoteObject, token.GetRefPtr()); + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::APP_ABILITY_CLEANED, data, reply, option); } sptr AppMgrProxy::GetAmsMgr() @@ -180,23 +150,11 @@ int32_t AppMgrProxy::ClearUpApplicationData(const std::string &bundleName, int32 if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteString(bundleName)) { - TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteString failed"); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteInt32(appCloneIndex)) { - TAG_LOGE(AAFwkTag::APPMGR, "appCloneIndex write failed."); - return ERR_INVALID_VALUE; - } - if (!data.WriteInt32(userId)) { - TAG_LOGE(AAFwkTag::APPMGR, "userId write failed."); - return ERR_INVALID_VALUE; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, appCloneIndex); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA, data, reply, option); return reply.ReadInt32(); } @@ -208,15 +166,9 @@ int32_t AppMgrProxy::ClearUpApplicationDataBySelf(int32_t userId) if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteInt32(userId)) { - TAG_LOGE(AAFwkTag::APPMGR, "userId write failed."); - return ERR_INVALID_VALUE; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA_BY_SELF, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA_BY_SELF, data, reply, option); return reply.ReadInt32(); } @@ -250,15 +202,9 @@ int32_t AppMgrProxy::GetRunningMultiAppInfoByBundleName(const std::string &bundl if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteString(bundleName)) { - TAG_LOGE(AAFwkTag::APPMGR, "bundleName write failed."); - return ERR_INVALID_VALUE; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME, data, reply, option); std::unique_ptr infoReply(reply.ReadParcelable()); if (infoReply == nullptr) { TAG_LOGW(AAFwkTag::APPMGR, "reply ReadParcelable is nullptr"); @@ -278,10 +224,8 @@ int32_t AppMgrProxy::GetRunningProcessesByBundleType(const BundleType bundleType if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteInt32(static_cast(bundleType))) { - TAG_LOGE(AAFwkTag::APPMGR, "Bundle type write failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, Int32, static_cast(bundleType)); + if (!SendTransactCmd(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_BUNDLE_TYPE, data, reply)) { return ERR_NULL_OBJECT; } @@ -322,16 +266,9 @@ int32_t AppMgrProxy::JudgeSandboxByPid(pid_t pid, bool &isSandbox) if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteInt32(pid)) { - TAG_LOGE(AAFwkTag::APPMGR, "Pid write failed."); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID, data, reply, option); isSandbox = reply.ReadBool(); return reply.ReadInt32(); } @@ -345,7 +282,8 @@ int32_t AppMgrProxy::GetProcessRunningInfosByUserId(std::vector &procLevelMap) @@ -406,13 +341,10 @@ int32_t AppMgrProxy::NotifyProcMemoryLevel(const std::map &p return ERR_FLATTEN_OBJECT; } MemoryLevelInfo memoryLevelInfo(procLevelMap); - data.WriteParcelable(&memoryLevelInfo); - int32_t ret = SendRequest(AppMgrInterfaceCode::APP_NOTIFY_PROC_MEMORY_LEVEL, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - } - int result = reply.ReadInt32(); - return result; + PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &memoryLevelInfo); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::APP_NOTIFY_PROC_MEMORY_LEVEL, data, reply, option); + return reply.ReadInt32(); } int32_t AppMgrProxy::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo) @@ -423,7 +355,7 @@ int32_t AppMgrProxy::DumpHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocI if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - data.WriteInt32(pid); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid); MessageOption option(MessageOption::TF_SYNC); int32_t ret = SendRequest(AppMgrInterfaceCode::DUMP_HEAP_MEMORY_PROCESS, data, reply, option); @@ -446,22 +378,14 @@ int32_t AppMgrProxy::DumpJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info) TAG_LOGD(AAFwkTag::APPMGR, "AppMgrProxy::DumpJsHeapMemory."); MessageParcel data; MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } + PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &info); - if (!data.WriteParcelable(&info)) { - TAG_LOGE(AAFwkTag::APPMGR, "info write failed"); - return ERR_FLATTEN_OBJECT; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t ret = SendRequest(AppMgrInterfaceCode::DUMP_JSHEAP_MEMORY_PROCESS, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, - "AppMgrProxy SendRequest DUMP_JSHEAP_MEMORY_PROCESS is failed, error code: %{public}d", ret); - return ret; - } - return ret; + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::DUMP_JSHEAP_MEMORY_PROCESS, data, reply, option); + return reply.ReadInt32(); } bool AppMgrProxy::SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply) @@ -590,17 +514,9 @@ int AppMgrProxy::UnregisterApplicationStateObserver( if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteRemoteObject(observer->AsObject())) { - TAG_LOGE(AAFwkTag::APPMGR, "observer write failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer->AsObject()); - auto error = SendRequest(AppMgrInterfaceCode::UNREGISTER_APPLICATION_STATE_OBSERVER, - data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_APPLICATION_STATE_OBSERVER, data, reply, option); return reply.ReadInt32(); } @@ -617,17 +533,11 @@ int32_t AppMgrProxy::RegisterAbilityForegroundStateObserver(const sptrAsObject())) { - TAG_LOGE(AAFwkTag::APPMGR, "Observer write failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer->AsObject()); MessageParcel reply; MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER, data, reply, option); return reply.ReadInt32(); } @@ -643,17 +553,10 @@ int32_t AppMgrProxy::UnregisterAbilityForegroundStateObserver(const sptrAsObject())) { - TAG_LOGE(AAFwkTag::APPMGR, "Observer write failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer->AsObject()); MessageParcel reply; MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d.", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER, data, reply, option); return reply.ReadInt32(); } @@ -665,12 +568,7 @@ int AppMgrProxy::GetForegroundApplications(std::vector &list) if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - auto error = SendRequest(AppMgrInterfaceCode::GET_FOREGROUND_APPLICATIONS, - data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "GetForegroundApplications fail, error: %{public}d", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_FOREGROUND_APPLICATIONS, data, reply, option); int32_t infoSize = reply.ReadInt32(); if (infoSize > CYCLE_LIMIT) { TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large"); @@ -697,27 +595,12 @@ int AppMgrProxy::StartUserTestProcess( if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteParcelable(&want)) { - TAG_LOGE(AAFwkTag::APPMGR, "want write failed."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteRemoteObject(observer)) { - TAG_LOGE(AAFwkTag::APPMGR, "observer write failed."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteParcelable(&bundleInfo)) { - TAG_LOGE(AAFwkTag::APPMGR, "bundleInfo write failed."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteInt32(userId)) { - TAG_LOGE(AAFwkTag::APPMGR, "userId write failed."); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::START_USER_TEST_PROCESS, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &want); + PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, observer); + PARCEL_UTIL_WRITE_RET_INT(data, Parcelable, &bundleInfo); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, userId); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_USER_TEST_PROCESS, data, reply, option); return reply.ReadInt32(); } @@ -730,23 +613,12 @@ int AppMgrProxy::FinishUserTest(const std::string &msg, const int64_t &resultCod if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteString(msg)) { - TAG_LOGE(AAFwkTag::APPMGR, "msg write failed."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteInt64(resultCode)) { - TAG_LOGE(AAFwkTag::APPMGR, "resultCode:WriteInt32 fail."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteString(bundleName)) { - TAG_LOGE(AAFwkTag::APPMGR, "bundleName write failed."); - return ERR_FLATTEN_OBJECT; - } - int32_t ret = SendRequest(AppMgrInterfaceCode::FINISH_USER_TEST, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + + PARCEL_UTIL_WRITE_RET_INT(data, String, msg); + PARCEL_UTIL_WRITE_RET_INT(data, Int64, resultCode); + PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::FINISH_USER_TEST, data, reply, option); return reply.ReadInt32(); } @@ -827,19 +699,12 @@ int AppMgrProxy::PreStartNWebSpawnProcess() return ERR_FLATTEN_OBJECT; } - int32_t ret = SendRequest(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess failed, result: %{public}d", ret); - return ret; - } - + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS, data, reply, option); auto result = reply.ReadInt32(); if (result != 0) { - TAG_LOGW(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess failed, result: %{public}d", ret); - return ret; + TAG_LOGW(AAFwkTag::APPMGR, "PreStartNWebSpawnProcess failed, result: %{public}d", result); } - return 0; + return result; } int AppMgrProxy::StartRenderProcess(const std::string &renderParam, @@ -888,9 +753,8 @@ int AppMgrProxy::StartRenderProcess(const std::string &renderParam, renderPid = reply.ReadInt32(); if (result != 0) { TAG_LOGW(AAFwkTag::APPMGR, "StartRenderProcess failed, result: %{public}d", result); - return result; } - return 0; + return result; } void AppMgrProxy::AttachRenderProcess(const sptr &renderScheduler) @@ -1263,13 +1127,8 @@ int32_t AppMgrProxy::NotifyUnLoadRepairPatch(const std::string &bundleName, cons MessageParcel reply; MessageOption option; - auto ret = SendRequest(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH, - data, reply, option); - if (ret != 0) { - TAG_LOGW(AAFwkTag::APPMGR, "Notify unload patch, Send request failed with error code %{public}d.", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH, data, reply, option); return reply.ReadInt32(); } @@ -1313,13 +1172,8 @@ int32_t AppMgrProxy::StartNativeProcessForDebugger(const AAFwk::Want &want) MessageParcel reply; MessageOption option; - auto ret = SendRequest(AppMgrInterfaceCode::START_NATIVE_PROCESS_FOR_DEBUGGER, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_NATIVE_PROCESS_FOR_DEBUGGER, data, reply, option); return reply.ReadInt32(); } @@ -1339,11 +1193,7 @@ int32_t AppMgrProxy::GetBundleNameByPid(const int pid, std::string &bundleName, return ERR_INVALID_DATA; } - auto ret = SendRequest(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID, data, reply, option); bundleName = reply.ReadString(); uid = reply.ReadInt32(); return ERR_NONE; @@ -1364,11 +1214,7 @@ int32_t AppMgrProxy::GetRunningProcessInfoByPid(const pid_t pid, OHOS::AppExecFw return ERR_INVALID_DATA; } - auto ret = SendRequest(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_PID, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_PID, data, reply, option); std::unique_ptr processInfo(reply.ReadParcelable()); if (processInfo == nullptr) { @@ -1396,13 +1242,8 @@ int32_t AppMgrProxy::NotifyAppFault(const FaultData &faultData) MessageParcel reply; MessageOption option; - auto ret = SendRequest(AppMgrInterfaceCode::NOTIFY_APP_FAULT, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_APP_FAULT, data, reply, option); return reply.ReadInt32(); } @@ -1423,13 +1264,8 @@ int32_t AppMgrProxy::NotifyAppFaultBySA(const AppFaultDataBySA &faultData) MessageParcel reply; MessageOption option; - auto ret = SendRequest(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA, data, reply, option); return reply.ReadInt32(); } @@ -1472,12 +1308,7 @@ int32_t AppMgrProxy::GetProcessMemoryByPid(const int32_t pid, int32_t &memorySiz return ERR_INVALID_DATA; } - auto ret = SendRequest(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID, data, reply, option); memorySize = reply.ReadInt32(); auto result = reply.ReadInt32(); return result; @@ -1517,8 +1348,7 @@ int32_t AppMgrProxy::GetRunningProcessInformation( TAG_LOGE(AAFwkTag::APPMGR, "GetParcelableInfos fail, error: %{public}d", error); return error; } - int result = reply.ReadInt32(); - return result; + return reply.ReadInt32(); } int32_t AppMgrProxy::ChangeAppGcState(pid_t pid, int32_t state) @@ -1539,11 +1369,8 @@ int32_t AppMgrProxy::ChangeAppGcState(pid_t pid, int32_t state) TAG_LOGE(AAFwkTag::APPMGR, "State write failed."); return ERR_FLATTEN_OBJECT; } - int32_t ret = SendRequest(AppMgrInterfaceCode::CHANGE_APP_GC_STATE, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); - return ret; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::CHANGE_APP_GC_STATE, data, reply, option); return NO_ERROR; } @@ -1567,13 +1394,7 @@ int32_t AppMgrProxy::NotifyPageShow(const sptr &token, const Page return ERR_FLATTEN_OBJECT; } - auto error = SendRequest(AppMgrInterfaceCode::NOTIFY_PAGE_SHOW, - data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } - + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_PAGE_SHOW, data, reply, option); return NO_ERROR; } @@ -1597,13 +1418,7 @@ int32_t AppMgrProxy::NotifyPageHide(const sptr &token, const Page return ERR_FLATTEN_OBJECT; } - auto error = SendRequest(AppMgrInterfaceCode::NOTIFY_PAGE_HIDE, - data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } - + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_PAGE_HIDE, data, reply, option); return NO_ERROR; } @@ -1633,11 +1448,8 @@ int32_t AppMgrProxy::RegisterAppRunningStatusListener(const sptr MessageParcel reply; MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::REGISTER_APP_RUNNING_STATUS_LISTENER, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_APP_RUNNING_STATUS_LISTENER, data, reply, option); return reply.ReadInt32(); } @@ -1655,11 +1467,8 @@ int32_t AppMgrProxy::UnregisterAppRunningStatusListener(const sptr remote = Remote(); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr."); - return ERR_NULL_OBJECT; - } - auto error = remote->SendRequest( - static_cast(AppMgrInterfaceCode::REGISTER_APP_FOREGROUND_STATE_OBSERVER), data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d.", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_APP_FOREGROUND_STATE_OBSERVER, data, reply, option); return reply.ReadInt32(); } @@ -1704,17 +1503,7 @@ int32_t AppMgrProxy::UnregisterAppForegroundStateObserver(const sptr remote = Remote(); - if (remote == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr."); - return ERR_NULL_OBJECT; - } - auto error = remote->SendRequest( - static_cast(AppMgrInterfaceCode::UNREGISTER_APP_FOREGROUND_STATE_OBSERVER), data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::UNREGISTER_APP_FOREGROUND_STATE_OBSERVER, data, reply, option); return reply.ReadInt32(); } @@ -1724,24 +1513,15 @@ int32_t AppMgrProxy::IsApplicationRunning(const std::string &bundleName, bool &i TAG_LOGD(AAFwkTag::APPMGR, "Called."); isRunning = false; MessageParcel data; + MessageParcel reply; + MessageOption option; if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); return ERR_INVALID_DATA; } - if (!data.WriteString(bundleName)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write bundle name failed."); - return ERR_INVALID_DATA; - } - - MessageParcel reply; - MessageOption option; - auto ret = SendRequest(AppMgrInterfaceCode::IS_APPLICATION_RUNNING, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_APPLICATION_RUNNING, data, reply, option); isRunning = reply.ReadBool(); return reply.ReadInt32(); } @@ -1755,24 +1535,13 @@ int32_t AppMgrProxy::IsAppRunning(const std::string &bundleName, int32_t appClon TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); return ERR_INVALID_DATA; } - if (!data.WriteString(bundleName)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write bundle name failed."); - return ERR_INVALID_DATA; - } - if (!data.WriteInt32(appCloneIndex)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write appCloneIndex failed."); - return ERR_INVALID_DATA; - } + PARCEL_UTIL_WRITE_RET_INT(data, String, bundleName); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, appCloneIndex); MessageParcel reply; MessageOption option; - auto ret = SendRequest(AppMgrInterfaceCode::IS_APP_RUNNING, - data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request is failed, error code: %{public}d", ret); - return ret; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::IS_APP_RUNNING, data, reply, option); isRunning = reply.ReadBool(); return reply.ReadInt32(); } @@ -1790,26 +1559,14 @@ int32_t AppMgrProxy::StartChildProcess(const std::string &srcEntry, pid_t &child TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed"); return ERR_FLATTEN_OBJECT; } - if (!data.WriteString(srcEntry)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write param srcEntry failed."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteInt32(childProcessCount)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write param childProcessCount failed."); - return ERR_FLATTEN_OBJECT; - } - if (!data.WriteBool(isStartWithDebug)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write param isStartWithDebug failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, String, srcEntry); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, childProcessCount); + PARCEL_UTIL_WRITE_RET_INT(data, Bool, isStartWithDebug); MessageParcel reply; MessageOption option; - int32_t ret = SendRequest(AppMgrInterfaceCode::START_CHILD_PROCESS, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "StartChildProcess SendRequest is failed, error code: %{public}d", ret); - return ret; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_CHILD_PROCESS, data, reply, option); auto result = reply.ReadInt32(); if (result == ERR_OK) { childPid = reply.ReadInt32(); @@ -1821,17 +1578,14 @@ int32_t AppMgrProxy::GetChildProcessInfoForSelf(ChildProcessInfo &info) { TAG_LOGD(AAFwkTag::APPMGR, "called"); MessageParcel data; + MessageParcel reply; + MessageOption option; if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed"); return ERR_FLATTEN_OBJECT; } - MessageParcel reply; - MessageOption option; - int32_t ret = SendRequest(AppMgrInterfaceCode::GET_CHILD_PROCCESS_INFO_FOR_SELF, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "GetChildProcessInfoForSelf SendRequest is failed, error code: %{public}d", ret); - return ret; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_CHILD_PROCCESS_INFO_FOR_SELF, data, reply, option); auto result = reply.ReadInt32(); if (result == ERR_OK) { std::unique_ptr infoReply(reply.ReadParcelable()); @@ -1848,36 +1602,29 @@ void AppMgrProxy::AttachChildProcess(const sptr &childScheduler) return; } MessageParcel data; + MessageParcel reply; + MessageOption option; if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed"); return; } - if (!data.WriteRemoteObject(childScheduler.GetRefPtr())) { - TAG_LOGE(AAFwkTag::APPMGR, "Failed to write remote object"); - return; - } - MessageParcel reply; - MessageOption option; - int32_t ret = SendRequest(AppMgrInterfaceCode::ATTACH_CHILD_PROCESS, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "AttachChildProcess SendRequest is failed, error code: %{public}d", ret); - } + PARCEL_UTIL_WRITE_NORET(data, RemoteObject, childScheduler.GetRefPtr()); + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::ATTACH_CHILD_PROCESS, data, reply, option); } void AppMgrProxy::ExitChildProcessSafely() { TAG_LOGD(AAFwkTag::APPMGR, "called"); MessageParcel data; + MessageParcel reply; + MessageOption option; if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed"); return; } - MessageParcel reply; - MessageOption option; - int32_t ret = SendRequest(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "ExitChildProcessSafely SendRequest is failed, error code: %{public}d", ret); - } + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY, data, reply, option); } bool AppMgrProxy::IsFinalAppProcess() @@ -1917,11 +1664,7 @@ int32_t AppMgrProxy::RegisterRenderStateObserver(const sptr return ERR_INVALID_DATA; } - if (!data.WriteInt32(pid)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write pid failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid); MessageParcel reply; MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_ROOT_HOST_PID, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d.", error); - return error; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_ROOT_HOST_PID, data, reply, option); int32_t size = reply.ReadInt32(); if (size > CYCLE_LIMIT) { @@ -2068,19 +1779,12 @@ int32_t AppMgrProxy::GetAllUIExtensionProviderPid(pid_t hostPid, std::vector CYCLE_LIMIT) { @@ -2102,18 +1806,12 @@ int32_t AppMgrProxy::NotifyMemorySizeStateChanged(bool isMemorySizeSufficent) if (!WriteInterfaceToken(data)) { return ERR_INVALID_DATA; } - if (!data.WriteBool(isMemorySizeSufficent)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "write isMemorySizeSufficent fail."); - return ERR_INVALID_DATA; - } + PARCEL_UTIL_WRITE_RET_INT(data, Bool, isMemorySizeSufficent); MessageParcel reply; MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::NOTIFY_MEMORY_SIZE_STATE_CHANGED, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error); - return error; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_MEMORY_SIZE_STATE_CHANGED, data, reply, option); return reply.ReadInt32(); } @@ -2125,18 +1823,12 @@ int32_t AppMgrProxy::SetSupportedProcessCacheSelf(bool isSupport) TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); return ERR_INVALID_DATA; } - if (!data.WriteBool(isSupport)) { - TAG_LOGE(AAFwkTag::APPMGR, "isSupport write failed."); - return ERR_FLATTEN_OBJECT; - } + PARCEL_UTIL_WRITE_RET_INT(data, Bool, isSupport); MessageParcel reply; MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF, data, reply, option); return reply.ReadInt32(); } @@ -2144,22 +1836,15 @@ void AppMgrProxy::SetAppAssertionPauseState(bool flag) { TAG_LOGD(AAFwkTag::APPMGR, "Called."); MessageParcel data; + MessageParcel reply; + MessageOption option; if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); return; } - if (!data.WriteBool(flag)) { - TAG_LOGE(AAFwkTag::APPMGR, "flag write failed."); - return; - } + PARCEL_UTIL_WRITE_NORET(data, Bool, flag); - MessageParcel reply; - MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::SET_APP_ASSERT_PAUSE_STATE_SELF, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return; - } + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::SET_APP_ASSERT_PAUSE_STATE_SELF, data, reply, option); } int32_t AppMgrProxy::StartNativeChildProcess(const std::string &libName, int32_t childProcessCount, @@ -2172,33 +1857,17 @@ int32_t AppMgrProxy::StartNativeChildProcess(const std::string &libName, int32_t } MessageParcel data; + MessageParcel reply; + MessageOption option; if (!WriteInterfaceToken(data)) { TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); return IPC_PROXY_ERR; } + PARCEL_UTIL_WRITE_RET_INT(data, String, libName); + PARCEL_UTIL_WRITE_RET_INT(data, Int32, childProcessCount); + PARCEL_UTIL_WRITE_RET_INT(data, RemoteObject, callback); - if (!data.WriteString(libName)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write lib name failed."); - return IPC_PROXY_ERR; - } - - if (!data.WriteInt32(childProcessCount)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write param childProcessCount failed."); - return IPC_PROXY_ERR; - } - - if (!data.WriteRemoteObject(callback)) { - TAG_LOGE(AAFwkTag::APPMGR, "Write call back ipc object failed."); - return IPC_PROXY_ERR; - } - - MessageParcel reply; - MessageOption option; - auto error = SendRequest(AppMgrInterfaceCode::START_NATIVE_CHILD_PROCESS, data, reply, option); - if (error != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error); - return error; - } + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::START_NATIVE_CHILD_PROCESS, data, reply, option); return reply.ReadInt32(); } @@ -2210,10 +1879,7 @@ int32_t AppMgrProxy::CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTes if (!WriteInterfaceToken(data)) { return ERR_FLATTEN_OBJECT; } - if (!data.WriteInt32(pid)) { - TAG_LOGE(AAFwkTag::APPMGR, "pid write failed."); - return ERR_INVALID_VALUE; - } + PARCEL_UTIL_WRITE_RET_INT(data, Int32, pid); int32_t ret = SendRequest(AppMgrInterfaceCode::CHECK_CALLING_IS_USER_TEST_MODE, data, reply, option); if (ret != NO_ERROR) { TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret); From b770a93eba6a2c3651f50157398df6509dfcec26 Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Wed, 26 Jun 2024 01:38:46 +0000 Subject: [PATCH 085/148] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/IA7EZ9?from=project-issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 20个include的整改 Signed-off-by: jiangzhijun8 --- .../napi/inner/napi_ability_common/BUILD.gn | 9 ++- frameworks/js/napi/inner/napi_common/BUILD.gn | 8 ++- frameworks/native/ability/native/BUILD.gn | 70 ++++++++++++++----- 3 files changed, 67 insertions(+), 20 deletions(-) diff --git a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn index 2eb72fb995..fabcb43e14 100644 --- a/frameworks/js/napi/inner/napi_ability_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_ability_common/BUILD.gn @@ -69,8 +69,13 @@ ohos_shared_library("napi_ability_common") { "SUPPORT_GRAPHICS", "SUPPORT_SCREEN", ] - - public_external_deps += [ "window_manager:libwm_lite" ] + public_external_deps += [ + "form_fwk:fmskit_provider_client", + "form_fwk:form_manager", + "window_manager:libdm", + "window_manager:libdm_lite", + "window_manager:libwm_lite", + ] } innerapi_tags = [ "platformsdk" ] diff --git a/frameworks/js/napi/inner/napi_common/BUILD.gn b/frameworks/js/napi/inner/napi_common/BUILD.gn index 9a380d45ca..caa975b5c9 100644 --- a/frameworks/js/napi/inner/napi_common/BUILD.gn +++ b/frameworks/js/napi/inner/napi_common/BUILD.gn @@ -70,8 +70,12 @@ ohos_shared_library("napi_common") { "SUPPORT_GRAPHICS", "SUPPORT_SCREEN", ] - - public_external_deps += [ "window_manager:libwm_lite" ] + public_external_deps += [ + "form_fwk:form_manager", + "window_manager:libdm", + "window_manager:libdm_lite", + "window_manager:libwm_lite", + ] } innerapi_tags = [ "platformsdk" ] diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index ba5c121a73..6b00f2fd30 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -63,7 +63,6 @@ config("ability_config") { } if (ability_runtime_graphics) { - include_dirs += [ "${form_fwk_path}/interfaces/inner_api/include" ] defines += [ "SUPPORT_GRAPHICS", "SUPPORT_SCREEN", @@ -95,13 +94,7 @@ config("ability_public_config") { ] if (ability_runtime_graphics) { - include_dirs += [ - "${form_fwk_path}/interfaces/kits/native/include", - "${form_fwk_path}/interfaces/inner_api/include", - "${windowmanager_path}/interfaces/innerkits/dm", - "${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi", - "${windowmanager_path}/utils/include", - ] + include_dirs += [ "${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi" ] defines = [ "SUPPORT_GRAPHICS" ] } } @@ -332,17 +325,20 @@ ohos_shared_library("abilitykit_native") { external_deps += [ "ability_base:session_info", - "form_fwk:form_manager", "icu:shared_icuuc", "image_framework:image", - "image_framework:image", "image_framework:image_native", "input:libmmi-client", - "window_manager:libdm", "window_manager:libwm", "window_manager:libwsutils", "window_manager:windowstage_kit", ] + + public_external_deps += [ + "form_fwk:form_manager", + "window_manager:libdm", + "window_manager:libdm_lite", + ] } innerapi_tags = [ "platformsdk" ] @@ -730,6 +726,15 @@ ohos_shared_library("form_extension_module") { "window_manager:libwm", ] + if (ability_runtime_graphics) { + public_external_deps = [ + "form_fwk:fmskit_provider_client", + "form_fwk:form_manager", + "window_manager:libdm", + "window_manager:libdm_lite", + ] + } + relative_install_dir = "extensionability" subsystem_name = "ability" part_name = "ability_runtime" @@ -839,6 +844,14 @@ ohos_shared_library("continuation_ipc") { "libuv:uv", ] + if (ability_runtime_graphics) { + public_external_deps += [ + "form_fwk:form_manager", + "window_manager:libdm", + "window_manager:libdm_lite", + ] + } + defines = [] if (background_task_mgr_continuous_task_enable) { @@ -883,6 +896,15 @@ ohos_shared_library("data_ability_helper") { external_deps += [ "relational_store:native_rdb" ] } + if (ability_runtime_graphics) { + public_external_deps = [ + "form_fwk:fmskit_provider_client", + "form_fwk:form_manager", + "window_manager:libdm", + "window_manager:libdm_lite", + ] + } + innerapi_tags = [ "platformsdk" ] subsystem_name = "ability" part_name = "ability_runtime" @@ -913,9 +935,12 @@ ohos_shared_library("service_extension_module") { ] if (ability_runtime_graphics) { - external_deps += [ - "image_framework:image", + external_deps += [ "image_framework:image" ] + public_external_deps = [ + "form_fwk:fmskit_provider_client", + "form_fwk:form_manager", "window_manager:libdm", + "window_manager:libdm_lite", ] } @@ -1026,7 +1051,6 @@ config("ui_extension_public_config") { "${ability_runtime_path}/interfaces/kits/native/ability/native/ui_extension_ability", "${windowmanager_path}/interfaces/kits/napi/embeddable_window_stage", "${windowmanager_path}/interfaces/kits/napi/extension_window", - "${windowmanager_path}/wm/include", ] } @@ -1080,6 +1104,8 @@ ohos_shared_library("ui_extension") { "window_manager:libdm", "window_manager:libwm", ] + + public_external_deps = [ "window_manager:scene_session_manager" ] } subsystem_name = "ability" @@ -1107,6 +1133,9 @@ ohos_shared_library("ui_extension_module") { "napi:ace_napi", "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "form_fwk:form_manager" ] + } relative_install_dir = "extensionability/" subsystem_name = "ability" @@ -1238,7 +1267,10 @@ ohos_shared_library("share_extension_module") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "form_fwk:form_manager", + "window_manager:libwm", + ] } relative_install_dir = "extensionability/" @@ -1294,7 +1326,10 @@ ohos_shared_library("action_extension_module") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm" ] + external_deps += [ + "form_fwk:form_manager", + "window_manager:libwm", + ] } relative_install_dir = "extensionability/" @@ -1539,6 +1574,9 @@ ohos_shared_library("auto_fill_extension_module") { "napi:ace_napi", "window_manager:libwm", ] + if (ability_runtime_graphics) { + external_deps += [ "form_fwk:form_manager" ] + } relative_install_dir = "extensionability/" subsystem_name = "ability" From ac0f09e21b05e0309effc8a365cdba2ba10802d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 07:51:08 +0000 Subject: [PATCH 086/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../main/ets/pages/selectorPhoneDialog.ets | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index f06d2769dd..d841eb0cff 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -139,16 +139,15 @@ struct SelectorPhoneDialog { } build() { + Flex({ direction: FlexDirection.Column }) { + Text($r('app.string.message_title_selector')) + .fontSize(22) + .fontWeight(FontWeight.Medium) + .textAlign(TextAlign.Start) + .margin({ top: 25, left: 20 }) + } + .height(100) Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { - Flex({ direction: FlexDirection.Column }) { - Text($r('app.string.message_title_selector')) - .fontSize(22) - .fontWeight(FontWeight.Medium) - .textAlign(TextAlign.Start) - .margin({ top: 25, left: 20 }) - } - .height(100) - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Swiper() { LazyForEach(this.phoneShowData, (item: any) => { @@ -206,7 +205,7 @@ struct SelectorPhoneDialog { .rowsTemplate(this.selector.swiper.gridRows) .columnsGap(12) .rowsGap(12) - .margin({ top: 10 }) + .margin({ top: 10, bottom:20 }) .height(210) .align(Alignment.Center) }, item => item) From 6cec11816cf54467de44ef06fbdfb6630d48ed82 Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Thu, 27 Jun 2024 16:06:37 +0800 Subject: [PATCH 087/148] web Signed-off-by: savior-xzh Change-Id: I64c1b3114c273549ba79650d018cfd538fc85e7e --- .../include/appmgr/app_mgr_client.h | 4 ++ .../include/appmgr/app_mgr_interface.h | 24 +++++++++ .../appmgr/app_mgr_ipc_interface_code.h | 4 ++ .../include/appmgr/app_mgr_proxy.h | 5 ++ .../app_manager/include/appmgr/app_mgr_stub.h | 3 ++ .../app_manager/src/appmgr/app_mgr_client.cpp | 22 ++++++++ .../app_manager/src/appmgr/app_mgr_proxy.cpp | 40 ++++++++++++++ .../app_manager/src/appmgr/app_mgr_stub.cpp | 31 +++++++++++ .../include/ability_bundle_event_callback.h | 1 + .../include/ability_manager_service.h | 2 + .../src/ability_bundle_event_callback.cpp | 14 +++++ .../src/ability_manager_service.cpp | 7 +++ services/appmgr/include/app_mgr_service.h | 6 +++ .../appmgr/include/app_mgr_service_inner.h | 6 +++ services/appmgr/include/app_running_record.h | 11 ++++ .../include/exit_resident_process_manager.h | 4 ++ services/appmgr/src/app_mgr_service.cpp | 35 ++++++++++++ services/appmgr/src/app_mgr_service_inner.cpp | 54 +++++++++++++++++++ .../src/exit_resident_process_manager.cpp | 16 ++++++ 19 files changed, 289 insertions(+) diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h index 1a47253997..b3b4dd7f47 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_client.h @@ -763,6 +763,10 @@ public: * @return Returns RESULT_OK on success, others on failure. */ virtual AppMgrResultCode AttachedToStatusBar(const sptr &token); + + int32_t NotifyProcessDependedOnWeb(); + + void KillProcessDependedOnWeb(); private: void SetServiceManager(std::unique_ptr serviceMgr); /** 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 8b25487054..c0a7ca4169 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 @@ -727,6 +727,30 @@ public: { return 0; } + + /** + * Notify that the process depends on web by itself. + */ + virtual int32_t NotifyProcessDependedOnWeb() + { + return 0; + } + + /** + * Kill process depended on web by sa. + */ + virtual void KillProcessDependedOnWeb() + { + return; + } + + /** + * Restart resident process depended on web. + */ + virtual void RestartResidentProcessDependedOnWeb() + { + return; + } }; } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h index 7b0b2b877a..011190daa9 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_ipc_interface_code.h @@ -107,6 +107,10 @@ enum class AppMgrInterfaceCode { IS_APP_RUNNING = 81, CHECK_CALLING_IS_USER_TEST_MODE = 82, SET_APPFREEZE_FILTER = 83, + // ipc for process depended on arkweb + NOTIFY_PROCESS_DEPENDED_ON_WEB = 84, + KILL_PROCESS_DEPENDED_ON_WEB = 85, + RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB = 86, }; } // AppExecFwk } // OHOS 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 8d4f61319a..7f7f755939 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 @@ -637,6 +637,11 @@ public: */ int32_t CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest) override; + virtual int32_t NotifyProcessDependedOnWeb() override; + + virtual void KillProcessDependedOnWeb() override; + + virtual void RestartResidentProcessDependedOnWeb() override; private: bool SendTransactCmd(AppMgrInterfaceCode code, MessageParcel &data, MessageParcel &reply); bool WriteInterfaceToken(MessageParcel &data); 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 e5e5eb4ba4..5b0cbc8222 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 @@ -143,6 +143,9 @@ private: int32_t HandleStartNativeChildProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleSaveBrowserChannel(MessageParcel &data, MessageParcel &reply); int32_t HandleCheckCallingIsUserTestMode(MessageParcel &data, MessageParcel &reply); + int32_t HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply); + int32_t HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply); + int32_t HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply); using AppMgrFunc = int32_t (AppMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; 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 61beba12c4..e7ac024882 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 @@ -1216,5 +1216,27 @@ AppMgrResultCode AppMgrClient::AttachedToStatusBar(const sptr &to TAG_LOGE(AAFwkTag::APPMGR, "Service is not connected."); return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; } + +int32_t AppMgrClient::NotifyProcessDependedOnWeb() +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); + return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED; + } + TAG_LOGD(AAFwkTag::APPMGR, "call"); + return service->NotifyProcessDependedOnWeb(); +} + +void AppMgrClient::KillProcessDependedOnWeb() +{ + sptr service = iface_cast(mgrHolder_->GetRemoteObject()); + if (service == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Service is nullptr."); + return; + } + TAG_LOGD(AAFwkTag::APPMGR, "call"); + service->KillProcessDependedOnWeb(); +} } // namespace AppExecFwk } // namespace OHOS 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 cb03c801c8..63aadb998f 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 @@ -2223,5 +2223,45 @@ int32_t AppMgrProxy::CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTes isUserTest = reply.ReadBool(); return reply.ReadInt32(); } + +int32_t AppMgrProxy::NotifyProcessDependedOnWeb() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return IPC_PROXY_ERR; + } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::NOTIFY_PROCESS_DEPENDED_ON_WEB, data, reply, option); + return reply.ReadInt32(); +} + +void AppMgrProxy::KillProcessDependedOnWeb() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return; + } + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::KILL_PROCESS_DEPENDED_ON_WEB, data, reply, option); +} + +void AppMgrProxy::RestartResidentProcessDependedOnWeb() +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return; + } + + PARCEL_UTIL_SENDREQ_NORET(AppMgrInterfaceCode::RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB, data, reply, option); +} } // namespace AppExecFwk } // namespace OHOS 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 c65d40d24b..26f9490963 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 @@ -207,6 +207,12 @@ AppMgrStub::AppMgrStub() &AppMgrStub::HandleIsAppRunning; memberFuncMap_[static_cast(AppMgrInterfaceCode::CHECK_CALLING_IS_USER_TEST_MODE)] = &AppMgrStub::HandleCheckCallingIsUserTestMode; + memberFuncMap_[static_cast(AppMgrInterfaceCode::NOTIFY_PROCESS_DEPENDED_ON_WEB)] = + &AppMgrStub::HandleNotifyProcessDependedOnWeb; + memberFuncMap_[static_cast(AppMgrInterfaceCode::KILL_PROCESS_DEPENDED_ON_WEB)] = + &AppMgrStub::HandleKillProcessDependedOnWeb; + memberFuncMap_[static_cast(AppMgrInterfaceCode::RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB)] = + &AppMgrStub::HandleRestartResidentProcessDependedOnWeb; } AppMgrStub::~AppMgrStub() @@ -1438,5 +1444,30 @@ int32_t AppMgrStub::HandleCheckCallingIsUserTestMode(MessageParcel &data, Messag return NO_ERROR; } +int32_t AppMgrStub::HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + int32_t ret = NotifyProcessDependedOnWeb(); + if (!reply.WriteInt32(ret)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write ret error."); + return IPC_STUB_ERR; + } + + return NO_ERROR; +} + +int32_t AppMgrStub::HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + KillProcessDependedOnWeb(); + return NO_ERROR; +} + +int32_t AppMgrStub::HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + RestartResidentProcessDependedOnWeb(); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_bundle_event_callback.h b/services/abilitymgr/include/ability_bundle_event_callback.h index f8d8d99bf7..450beb9468 100644 --- a/services/abilitymgr/include/ability_bundle_event_callback.h +++ b/services/abilitymgr/include/ability_bundle_event_callback.h @@ -49,6 +49,7 @@ private: void HandleUpdatedModuleInfo(const std::string &bundleName, int32_t uid); void HandleAppUpgradeCompleted(const std::string &bundleName, int32_t uid); void HandleRemoveUriPermission(uint32_t tokenId); + void HandleRestartResidentProcessDependedOnWeb(); DISALLOW_COPY_AND_MOVE(AbilityBundleEventCallback); AbilityEventUtil abilityEventHelper_; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index bc4656dc90..26de891666 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1693,6 +1693,8 @@ public: */ virtual void NotifyFrozenProcessByRSS(const std::vector &pidList, int32_t uid) override; + void HandleRestartResidentProcessDependedOnWeb(); + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; diff --git a/services/abilitymgr/src/ability_bundle_event_callback.cpp b/services/abilitymgr/src/ability_bundle_event_callback.cpp index 768c670283..2f762c19ae 100644 --- a/services/abilitymgr/src/ability_bundle_event_callback.cpp +++ b/services/abilitymgr/src/ability_bundle_event_callback.cpp @@ -63,6 +63,7 @@ void AbilityBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData // install or uninstall module/bundle HandleUpdatedModuleInfo(bundleName, uid); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_CHANGED) { + HandleRestartResidentProcessDependedOnWeb(); HandleUpdatedModuleInfo(bundleName, uid); HandleAppUpgradeCompleted(bundleName, uid); if (abilityAutoStartupService_ == nullptr) { @@ -115,5 +116,18 @@ void AbilityBundleEventCallback::HandleAppUpgradeCompleted(const std::string &bu }; taskHandler_->SubmitTask(task); } + +void AbilityBundleEventCallback::HandleRestartResidentProcessDependedOnWeb() +{ + auto task = []() { + auto abilityMgr = DelayedSingleton::GetInstance(); + if (abilityMgr == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityMgr is nullptr."); + return; + } + abilityMgr->HandleRestartResidentProcessDependedOnWeb(); + }; + taskHandler_->SubmitTask(task); +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 9b96841d7b..8aae3fe1b3 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -10846,5 +10846,12 @@ void AbilityManagerService::NotifyFrozenProcessByRSS(const std::vector CHECK_POINTER_LOG(connectManager, "can not find user connect manager"); connectManager->HandleProcessFrozen(pidList, uid); } + +void AbilityManagerService::HandleRestartResidentProcessDependedOnWeb() +{ + auto appMgr = GetAppMgr(); + CHECK_POINTER_LOG(appMgr, "get appMgr fail"); + appMgr->RestartResidentProcessDependedOnWeb(); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index f68ef66d0f..d766628e9b 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -554,6 +554,12 @@ public: * @return Returns ERR_OK is test ability, others is not test ability. */ int32_t CheckCallingIsUserTestMode(const pid_t pid, bool &isUserTest) override; + + virtual int32_t NotifyProcessDependedOnWeb() override; + + virtual void KillProcessDependedOnWeb() override; + + virtual void RestartResidentProcessDependedOnWeb() override; private: /** * Init, Initialize application services. diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 9865d51cfb..ac5e9d1456 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -1136,6 +1136,12 @@ public: */ void AttachedToStatusBar(const sptr &token); void KillApplicationByRecord(const std::shared_ptr &appRecord); + + int32_t NotifyProcessDependedOnWeb(); + + void KillProcessDependedOnWeb(); + + void RestartResidentProcessDependedOnWeb(); private: std::string FaultTypeToString(FaultDataType type); diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 7e8c361d76..de2064f944 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -814,6 +814,16 @@ public: { return isStrictMode_; } + + inline void SetIsDependedOnArkWeb(bool isDepend) + { + isDependedOnArkWeb_ = isDepend; + } + + inline bool IsDependedOnArkWeb() + { + return isDependedOnArkWeb_; + } private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data. @@ -975,6 +985,7 @@ private: pid_t gpuPid_ = 0; bool isStrictMode_ = false; bool isAttachedToStatusBar = false; + bool isDependedOnArkWeb_ = false; }; } // namespace AppExecFwk diff --git a/services/appmgr/include/exit_resident_process_manager.h b/services/appmgr/include/exit_resident_process_manager.h index 570f5938cd..cbf62c37c4 100644 --- a/services/appmgr/include/exit_resident_process_manager.h +++ b/services/appmgr/include/exit_resident_process_manager.h @@ -38,8 +38,10 @@ public: ~ExitResidentProcessManager(); bool IsMemorySizeSufficent() const; bool RecordExitResidentBundleName(const std::string &bundleName); + bool RecordExitResidentBundleDependedOnWeb(const std::string &bundleName); int32_t HandleMemorySizeInSufficent(); int32_t HandleMemorySizeSufficent(std::vector& bundleNames); + void HandleExitResidentBundleDependedOnWeb(std::vector& bundleNames); void QueryExitBundleInfos(const std::vector& exitBundleNames, std::vector& exitBundleInfos); @@ -47,7 +49,9 @@ private: ExitResidentProcessManager(); MemorySizeState currentMemorySizeState_ = MemorySizeState::MEMORY_SIZE_SUFFICENT; std::vector exitResidentBundleNames_; + std::vector exitResidentBundlesDependedOnWeb_; mutable ffrt::mutex mutexLock_; + mutable ffrt::mutex webMutexLock_; DISALLOW_COPY_AND_MOVE(ExitResidentProcessManager); }; } // namespace AppExecFwk diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 7c84254ee9..6621a5d7a7 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1543,5 +1543,40 @@ int32_t AppMgrService::CheckCallingIsUserTestMode(const pid_t pid, bool &isUserT return appMgrServiceInner_->CheckCallingIsUserTestModeInner(pid, isUserTest); } +int32_t AppMgrService::NotifyProcessDependedOnWeb() +{ + TAG_LOGD(AAFwkTag::APPMGR, "called."); + if (!appMgrServiceInner_) { + TAG_LOGE(AAFwkTag::APPMGR, "Not ready."); + return ERR_INVALID_VALUE; + } + return appMgrServiceInner_->NotifyProcessDependedOnWeb(); +} + +void AppMgrService::KillProcessDependedOnWeb() +{ + TAG_LOGD(AAFwkTag::APPMGR, "called."); + if (!AAFwk::PermissionVerification::GetInstance()->IsSACall()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not SA."); + return; + } + if (!appMgrServiceInner_) { + return; + } + appMgrServiceInner_->KillProcessDependedOnWeb(); +} + +void AppMgrService::RestartResidentProcessDependedOnWeb() +{ + TAG_LOGD(AAFwkTag::APPMGR, "called."); + if (!AAFwk::PermissionVerification::GetInstance()->CheckSpecificSystemAbilityAccessPermission(FOUNDATION_PROCESS)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is not foundation."); + return; + } + if (!appMgrServiceInner_) { + return; + } + appMgrServiceInner_->RestartResidentProcessDependedOnWeb(); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index d5c6af132f..c971d4a810 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -7009,5 +7009,59 @@ void AppMgrServiceInner::AttachedToStatusBar(const sptr &token) } appRecord->SetAttachedToStatusBar(true); } + +int32_t AppMgrServiceInner::NotifyProcessDependedOnWeb() +{ + int32_t pid = IPCSkeleton::GetCallingPid(); + auto appRecord = GetAppRunningRecordByPid(pid); + if (appRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "no such appRecord"); + return ERR_INVALID_VALUE; + } + TAG_LOGD(AAFwkTag::APPMGR, "call"); + appRecord->SetIsDependedOnArkWeb(true); + return ERR_OK; +} + +void AppMgrServiceInner::KillProcessDependedOnWeb() +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + CHECK_POINTER_AND_RETURN_LOG(appRunningManager_, "appRunningManager_ is nullptr"); + for (const auto &item : appRunningManager_->GetAppRunningRecordMap()) { + const auto &appRecord = item.second; + if (!appRecord || !appRecord->GetSpawned() || !appRecord->GetPriorityObject()) { + continue; + } + + if (appRecord->IsDependedOnArkWeb()) { + std::string bundleName = appRecord->GetBundleName(); + pid_t pid = appRecord->GetPriorityObject()->GetPid(); + appRecord->IsKeepAliveApp() && + ExitResidentProcessManager::GetInstance().RecordExitResidentBundleDependedOnWeb(bundleName); + KillProcessByPid(pid, "KillProcessDependedOnWeb"); + } + } +} + +void AppMgrServiceInner::RestartResidentProcessDependedOnWeb() +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + std::vector bundleNames; + ExitResidentProcessManager::GetInstance().HandleExitResidentBundleDependedOnWeb(bundleNames); + if (bundleNames.empty()) { + TAG_LOGE(AAFwkTag::APPMGR, "exit resident bundle names is empty"); + return; + } + + auto RestartResidentProcessDependedOnWebTask = [bundleNames, innerServicerWeak = weak_from_this()]() { + auto innerServicer = innerServicerWeak.lock(); + CHECK_POINTER_AND_RETURN_LOG(innerServicer, "get AppMgrServiceInner failed"); + std::vector exitBundleInfos; + ExitResidentProcessManager::GetInstance().QueryExitBundleInfos(bundleNames, exitBundleInfos); + + innerServicer->NotifyStartResidentProcess(exitBundleInfos); + }; + taskHandler_->SubmitTask(RestartResidentProcessDependedOnWebTask, "RestartResidentProcessDependedOnWeb"); +} } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/src/exit_resident_process_manager.cpp b/services/appmgr/src/exit_resident_process_manager.cpp index d7a68f8b8b..1c1bd4486b 100644 --- a/services/appmgr/src/exit_resident_process_manager.cpp +++ b/services/appmgr/src/exit_resident_process_manager.cpp @@ -53,6 +53,14 @@ bool ExitResidentProcessManager::RecordExitResidentBundleName(const std::string return true; } +bool ExitResidentProcessManager::RecordExitResidentBundleDependedOnWeb(const std::string &bundleName) +{ + std::lock_guard lock(webMutexLock_); + TAG_LOGE(AAFwkTag::APPMGR, "call"); + exitResidentBundlesDependedOnWeb_.emplace_back(bundleName); + return true; +} + int32_t ExitResidentProcessManager::HandleMemorySizeInSufficent() { std::lock_guard lock(mutexLock_); @@ -77,6 +85,14 @@ int32_t ExitResidentProcessManager::HandleMemorySizeSufficent(std::vector& bundleNames) +{ + std::lock_guard lock(webMutexLock_); + TAG_LOGE(AAFwkTag::APPMGR, "call"); + bundleNames = exitResidentBundlesDependedOnWeb_; + exitResidentBundlesDependedOnWeb_.clear(); +} + void ExitResidentProcessManager::QueryExitBundleInfos(const std::vector& exitBundleNames, std::vector& exitBundleInfos) { From 16142958c47c30aeb434ef18d092748280784ecc Mon Sep 17 00:00:00 2001 From: xuzhihao Date: Thu, 27 Jun 2024 16:47:34 +0800 Subject: [PATCH 088/148] =?UTF-8?q?Bugfix:=20IntentContext=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=8E=B7=E5=8F=96want=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E6=95=B4=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xuzhihao --- .../insight_intent_context/js_insight_intent_context.cpp | 2 +- .../insight_intent_context/js_insight_intent_context.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/insight_intent/insight_intent_context/js_insight_intent_context.cpp b/frameworks/native/insight_intent/insight_intent_context/js_insight_intent_context.cpp index 2bcef8817b..73229f658f 100644 --- a/frameworks/native/insight_intent/insight_intent_context/js_insight_intent_context.cpp +++ b/frameworks/native/insight_intent/insight_intent_context/js_insight_intent_context.cpp @@ -118,7 +118,7 @@ napi_value CreateJsInsightIntentContext(napi_env env, const std::shared_ptr Date: Thu, 27 Jun 2024 17:28:33 +0800 Subject: [PATCH 089/148] add cangjie ansan version Signed-off-by: wentao Change-Id: I2ba249b8dba19665f0c245669cfd643f55d5c583 --- .../cj_environment/src/cj_environment.cpp | 11 ++++++++++- .../interfaces/inner_api/cj_environment.h | 11 +++++++++++ frameworks/native/appkit/app/main_thread.cpp | 5 +++++ frameworks/native/runtime/cj_runtime.cpp | 15 +++++++++++++++ interfaces/inner_api/runtime/include/cj_runtime.h | 3 +++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/cj_environment/frameworks/cj_environment/src/cj_environment.cpp b/cj_environment/frameworks/cj_environment/src/cj_environment.cpp index c2ba4f6fb2..f965ab93f5 100644 --- a/cj_environment/frameworks/cj_environment/src/cj_environment.cpp +++ b/cj_environment/frameworks/cj_environment/src/cj_environment.cpp @@ -177,7 +177,16 @@ bool CJEnvironment::LoadRuntimeApis() #ifdef __OHOS__ Dl_namespace ns; dlns_get(CJEnvironment::cjSDKNSName, &ns); - auto dso = DynamicLoadLibrary(&ns, RTLIB_NAME, 1); + std::string runtimeLibName = "libcangjie-runtime"; + if (sanitizerKind_ == SanitizerKind::ASAN) { + runtimeLibName += "_asan"; + } else if (sanitizerKind_ == SanitizerKind::TSAN) { + runtimeLibName += "_tsan"; + } else if (sanitizerKind_ == SanitizerKind::HWASAN) { + runtimeLibName += "_hwasan"; + } + runtimeLibName += ".so"; + auto dso = DynamicLoadLibrary(&ns, runtimeLibName.c_str(), 1); #else auto dso = DynamicLoadLibrary(RTLIB_NAME, 1); #endif diff --git a/cj_environment/interfaces/inner_api/cj_environment.h b/cj_environment/interfaces/inner_api/cj_environment.h index def32d4e48..d2ce016ce5 100644 --- a/cj_environment/interfaces/inner_api/cj_environment.h +++ b/cj_environment/interfaces/inner_api/cj_environment.h @@ -49,6 +49,16 @@ public: { return isRuntimeStarted_; } + enum SanitizerKind { + NONE, + ASAN, + TSAN, + HWASAN, + }; + void SetSanitizerKindRuntimeVersion(SanitizerKind kind) + { + sanitizerKind_ = kind; + } void InitCJAppNS(const std::string& path); void InitCJSDKNS(const std::string& path); void InitCJSysNS(const std::string& path); @@ -92,6 +102,7 @@ private: bool isRuntimeStarted_{false}; bool isUISchedulerStarted_{false}; void* uiScheduler_ {nullptr}; + SanitizerKind sanitizerKind_ {SanitizerKind::NONE}; }; CJ_EXPORT bool IsCJAbility(const std::string& info); diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 118441082d..4f1117de1b 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -1464,6 +1464,11 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con #ifdef CJ_FRONTEND if (isCJApp) { AbilityRuntime::CJRuntime::SetAppLibPath(appLibPaths); + if (appInfo.asanEnabled) { + AbilityRuntime::CJRuntime::SetAsanVersion(); + } else if (appInfo.tsanEnabled) { + AbilityRuntime::CJRuntime::SetTsanVersion(); + } } else { #endif AbilityRuntime::JsRuntime::SetAppLibPath(appLibPaths, isSystemApp); diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index 059f004345..6484de795d 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -112,6 +112,21 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) return true; } +void CJRuntime::SetAsanVersion() +{ + CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(CJEnvironment::SanitizerKind::ASAN); +} + +void CJRuntime::SetTsanVersion() +{ + CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(CJEnvironment::SanitizerKind::TSAN); +} + +void CJRuntime::SetHWAsanVersion() +{ + CJEnvironment::GetInstance()->SetSanitizerKindRuntimeVersion(CJEnvironment::SanitizerKind::HWASAN); +} + void CJRuntime::StartDebugMode(const DebugOption dOption) { if (debugModel_) { diff --git a/interfaces/inner_api/runtime/include/cj_runtime.h b/interfaces/inner_api/runtime/include/cj_runtime.h index cb68f2a087..a089949a47 100644 --- a/interfaces/inner_api/runtime/include/cj_runtime.h +++ b/interfaces/inner_api/runtime/include/cj_runtime.h @@ -33,6 +33,9 @@ class CJRuntime : public Runtime { public: static std::unique_ptr Create(const Options& options); static void SetAppLibPath(const AppLibPathMap& appLibPaths); + static void SetAsanVersion(); + static void SetTsanVersion(); + static void SetHWAsanVersion(); ~CJRuntime() override = default; Language GetLanguage() const override From 0a3a78b1f6b0e94191b1b7658e813052215c1141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 11:41:03 +0000 Subject: [PATCH 090/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index d841eb0cff..64ec2fdc6b 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -139,15 +139,15 @@ struct SelectorPhoneDialog { } build() { - Flex({ direction: FlexDirection.Column }) { - Text($r('app.string.message_title_selector')) + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { + Flex({ direction: FlexDirection.Column }) { + Text($r('app.string.message_title_selector')) .fontSize(22) .fontWeight(FontWeight.Medium) .textAlign(TextAlign.Start) .margin({ top: 25, left: 20 }) - } - .height(100) - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { + } + .height(100) Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Swiper() { LazyForEach(this.phoneShowData, (item: any) => { From e9ec803f5921b95a273a8eadf818f7a578464b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 11:52:05 +0000 Subject: [PATCH 091/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../src/main/ets/pages/selectorPhoneDialog.ets | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 64ec2fdc6b..1f01df1d4f 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -141,13 +141,14 @@ struct SelectorPhoneDialog { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Flex({ direction: FlexDirection.Column }) { - Text($r('app.string.message_title_selector')) - .fontSize(22) - .fontWeight(FontWeight.Medium) - .textAlign(TextAlign.Start) - .margin({ top: 25, left: 20 }) - } - .height(100) + Text($r('app.string.message_title_selector')) + .fontSize(22) + .fontWeight(FontWeight.Medium) + .textAlign(TextAlign.Start) + .margin({ top: 25, left: 20 }) + } + .height(100) + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Swiper() { LazyForEach(this.phoneShowData, (item: any) => { From 79765e3c92714c9becb185aadd3150c1f380d9f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 12:09:37 +0000 Subject: [PATCH 092/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 1f01df1d4f..f8011743fb 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -140,14 +140,14 @@ struct SelectorPhoneDialog { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { - Flex({ direction: FlexDirection.Column }) { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start }) { Text($r('app.string.message_title_selector')) .fontSize(22) .fontWeight(FontWeight.Medium) .textAlign(TextAlign.Start) .margin({ top: 25, left: 20 }) - } - .height(100) + } + .height(100) Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { Swiper() { From 15668790094a3633d7fad080971e0f77e495c157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 12:22:58 +0000 Subject: [PATCH 093/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index f8011743fb..af5aa7df50 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -206,12 +206,12 @@ struct SelectorPhoneDialog { .rowsTemplate(this.selector.swiper.gridRows) .columnsGap(12) .rowsGap(12) - .margin({ top: 10, bottom:20 }) + .margin({ top: 10}) .height(210) .align(Alignment.Center) }, item => item) } - .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 }) + .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 ,top: 10}) .align(Alignment.Center) .width('90%') .indicator(this.phoneShowData.totalCount() > 1) From cc1b59f7affcdb3da84cd51724c09a8140a78496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 12:24:12 +0000 Subject: [PATCH 094/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index af5aa7df50..59fb47931b 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -206,7 +206,7 @@ struct SelectorPhoneDialog { .rowsTemplate(this.selector.swiper.gridRows) .columnsGap(12) .rowsGap(12) - .margin({ top: 10}) + .margin({ top: 30}) .height(210) .align(Alignment.Center) }, item => item) From 03c0dcb07b5c1c60e9cc5093c85a7f3e7a8f3624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 12:25:26 +0000 Subject: [PATCH 095/148] update services/dialog_ui/ams_system_dialog/AppScope/app.json. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- services/dialog_ui/ams_system_dialog/AppScope/app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/AppScope/app.json b/services/dialog_ui/ams_system_dialog/AppScope/app.json index eb0725a887..aaef6134db 100644 --- a/services/dialog_ui/ams_system_dialog/AppScope/app.json +++ b/services/dialog_ui/ams_system_dialog/AppScope/app.json @@ -2,8 +2,8 @@ "app": { "bundleName": "com.ohos.amsdialog", "vendor": "example", - "versionCode": 1000005, - "versionName": "1.2.0", + "versionCode": 1000006, + "versionName": "1.3.0", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true, From 74a78cead9d72eff5df7aa5ce90303f1d60877c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Thu, 27 Jun 2024 12:26:00 +0000 Subject: [PATCH 096/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 59fb47931b..5e48109e3b 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -206,7 +206,7 @@ struct SelectorPhoneDialog { .rowsTemplate(this.selector.swiper.gridRows) .columnsGap(12) .rowsGap(12) - .margin({ top: 30}) + .margin({ top: 30 }) .height(210) .align(Alignment.Center) }, item => item) From c333bcaf30750b157098233cfff603bc65536dc2 Mon Sep 17 00:00:00 2001 From: yuwenze Date: Thu, 27 Jun 2024 21:18:07 +0800 Subject: [PATCH 097/148] check system app Signed-off-by: yuwenze Change-Id: Ic811f620abb99f657d044c619b65817713ee80cf --- services/appmgr/src/app_mgr_service.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index 7c84254ee9..a00d6a6c12 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -21,6 +21,7 @@ #include #include +#include "ability_manager_errors.h" #include "app_death_recipient.h" #include "app_mgr_constants.h" #include "datetime_ex.h" @@ -317,6 +318,10 @@ sptr AppMgrService::GetAmsMgr() int32_t AppMgrService::ClearUpApplicationData(const std::string &bundleName, int32_t appCloneIndex, int32_t userId) { + if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { + TAG_LOGE(AAFwkTag::APPMGR, "The caller is not system-app, can not use system-api"); + return AAFwk::ERR_NOT_SYSTEM_APP; + } if (!IsReady()) { return ERR_INVALID_OPERATION; } From b7077dc2e8f067bf99ef4370cb643da2cb4e156b Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Tue, 25 Jun 2024 02:00:44 +0000 Subject: [PATCH 098/148] Issue: https://gitee.com/openharmony/ability_ability_runtime/issues/IA80GX?from=project-issue Comment: third_part Signed-off-by: jiangzhijun8 --- frameworks/simulator/ability_simulator/BUILD.gn | 2 +- test/moduletest/ability_test/BUILD.gn | 7 ++++++- test/moduletest/common/ams/BUILD.gn | 7 +++---- test/unittest/BUILD.gn | 3 +-- test/unittest/ams_app_state_callback_test/BUILD.gn | 2 +- test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn | 2 +- test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn | 6 +++--- test/unittest/dfr_test/appfreeze_state_test/BUILD.gn | 2 +- test/unittest/dfr_test/watchdog_test/BUILD.gn | 2 +- test/unittest/js_auto_fill_extension_test/BUILD.gn | 2 +- test/unittest/js_service_extension_test/BUILD.gn | 2 +- 11 files changed, 20 insertions(+), 17 deletions(-) diff --git a/frameworks/simulator/ability_simulator/BUILD.gn b/frameworks/simulator/ability_simulator/BUILD.gn index 0671f9f18f..5d5f379eab 100644 --- a/frameworks/simulator/ability_simulator/BUILD.gn +++ b/frameworks/simulator/ability_simulator/BUILD.gn @@ -68,7 +68,6 @@ ohos_shared_library("ability_simulator_inner") { "${windowmanager_path}/interfaces/innerkits/wm", "${windowmanager_path}/interfaces/kits/napi/window_runtime/window_stage_napi", "include/bundle_parser", - "//third_party/json/include", ] sources = [ @@ -113,6 +112,7 @@ ohos_shared_library("ability_simulator_inner") { "ets_utils:console", "ets_utils:timer", "hilog:libhilog", + "json:nlohmann_json_static", "jsoncpp:jsoncpp_static", "napi:ace_napi", ] diff --git a/test/moduletest/ability_test/BUILD.gn b/test/moduletest/ability_test/BUILD.gn index 2b1cb7c2a5..18f014593a 100644 --- a/test/moduletest/ability_test/BUILD.gn +++ b/test/moduletest/ability_test/BUILD.gn @@ -24,7 +24,6 @@ config("module_private_config") { cflags += [ "-DBINDER_IPC_32BIT" ] } include_dirs = [ - "//third_party/json/include", "${ability_runtime_innerkits_path}/ability_manager/include", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", "${ability_runtime_services_path}/common/include", @@ -83,6 +82,7 @@ ohos_moduletest("ability_moduletest") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -142,6 +142,7 @@ ohos_moduletest("ability_conetxt_test") { "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -180,6 +181,7 @@ ohos_moduletest("ability_thread_call_request_module_test") { "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", "hilog:libhilog", + "json:nlohmann_json_static", "napi:ace_napi", ] } @@ -224,6 +226,7 @@ ohos_moduletest("data_ability_operation_moduletest") { "c_utils:utils", "hilog:libhilog", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -279,6 +282,7 @@ ohos_moduletest("data_ability_helper_module_test") { "eventhandler:libeventhandler", "hilog:libhilog", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", @@ -326,6 +330,7 @@ ohos_moduletest("ability_post_event_timeout_test") { "eventhandler:libeventhandler", "hilog:libhilog", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "relational_store:native_appdatafwk", "relational_store:native_dataability", diff --git a/test/moduletest/common/ams/BUILD.gn b/test/moduletest/common/ams/BUILD.gn index 7c2c4c6f93..1936399484 100644 --- a/test/moduletest/common/ams/BUILD.gn +++ b/test/moduletest/common/ams/BUILD.gn @@ -24,10 +24,8 @@ ohos_source_set("appmgr_mst_source") { defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ] - include_dirs = [ - "//third_party/json/include", - "${ability_runtime_test_path}/mock/services_appmgr_test/include", - ] + include_dirs = + [ "${ability_runtime_test_path}/mock/services_appmgr_test/include" ] public_configs = [ "${ability_runtime_test_path}/moduletest:services_module_test_config", @@ -80,6 +78,7 @@ ohos_source_set("appmgr_mst_source") { "init:libbeget_proxy", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", ] if (ability_runtime_graphics) { diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 6dd7482377..afc3662ad6 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -57,8 +57,6 @@ ohos_source_set("appmgr_test_source") { "${ability_runtime_innerkits_path}/app_manager/src/appmgr/running_process_info.cpp", ] - include_dirs = [ "//third_party/json/include" ] - public_configs = [ ":appmgr_test_config", "${c_utils_base_path}:utils_config", @@ -94,6 +92,7 @@ ohos_source_set("appmgr_test_source") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", + "json:nlohmann_json_static", "kv_store:distributeddata_mgr", ] diff --git a/test/unittest/ams_app_state_callback_test/BUILD.gn b/test/unittest/ams_app_state_callback_test/BUILD.gn index 29555e5242..96cf099b43 100644 --- a/test/unittest/ams_app_state_callback_test/BUILD.gn +++ b/test/unittest/ams_app_state_callback_test/BUILD.gn @@ -19,7 +19,6 @@ module_output_path = "ability_runtime/appmgrservice" ohos_unittest("AmsAppStateCallbackTest") { module_out_path = module_output_path cflags_cc = [] - include_dirs = [ "//third_party/json/include" ] sources = [ "${ability_runtime_innerkits_path}//app_manager/src/appmgr/app_process_data.cpp", @@ -49,6 +48,7 @@ ohos_unittest("AmsAppStateCallbackTest") { "hilog:libhilog", "hitrace:hitrace_meter", "ipc:ipc_core", + "json:nlohmann_json_static", ] } diff --git a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn index f9cc437dd8..d4818c5bbd 100644 --- a/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_inner_test/BUILD.gn @@ -50,7 +50,6 @@ ohos_unittest("appfreeze_inner_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/dfr", "${ability_runtime_path}/utils/global/time/include", - "//third_party/json/include", ] configs = [ @@ -104,6 +103,7 @@ ohos_unittest("appfreeze_inner_test") { "init:libbegetutil", "input:libmmi-client", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", "safwk:system_ability_fwk", diff --git a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn index e0452c3154..ca35c2db20 100644 --- a/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_manager_test/BUILD.gn @@ -9,7 +9,7 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. import("//build/ohos.gni") import("//build/test.gni") @@ -52,7 +52,6 @@ ohos_unittest("appfreeze_manager_test") { "${ability_runtime_services_path}/appdfr/include", "${ability_runtime_services_path}/appmgr/include", "${ability_runtime_services_path}/common/include", - "//third_party/json/include", ] configs = [ @@ -87,10 +86,11 @@ ohos_unittest("appfreeze_manager_test") { "hilog:libhilog", "init:libbeget_proxy", "ipc:ipc_core", + "json:nlohmann_json_static", ] } -############################################################################### +############################################################################### group("unittest") { testonly = true diff --git a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn index 57c1669ea6..422a69dcb9 100644 --- a/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn +++ b/test/unittest/dfr_test/appfreeze_state_test/BUILD.gn @@ -50,7 +50,6 @@ ohos_unittest("appfreeze_state_test") { include_dirs = [ "${ability_runtime_path}/interfaces/kits/native/appkit/dfr", "${ability_runtime_path}/utils/global/time/include", - "//third_party/json/include", ] configs = [ @@ -101,6 +100,7 @@ ohos_unittest("appfreeze_state_test") { "hitrace:hitrace_meter", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", ] } diff --git a/test/unittest/dfr_test/watchdog_test/BUILD.gn b/test/unittest/dfr_test/watchdog_test/BUILD.gn index 1825d44c40..0c9afbb19d 100644 --- a/test/unittest/dfr_test/watchdog_test/BUILD.gn +++ b/test/unittest/dfr_test/watchdog_test/BUILD.gn @@ -52,7 +52,6 @@ ohos_unittest("watchdog_test") { "${ability_runtime_path}/interfaces/kits/native/appkit/dfr", "${ability_runtime_test_path}/mock/frameworks_kits_appkit_test/include", "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", - "//third_party/json/include", ] configs = [ @@ -80,6 +79,7 @@ ohos_unittest("watchdog_test") { "hilog:libhilog", "image_framework:image_native", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", ] } diff --git a/test/unittest/js_auto_fill_extension_test/BUILD.gn b/test/unittest/js_auto_fill_extension_test/BUILD.gn index 11e750bfd5..6a919c7e81 100644 --- a/test/unittest/js_auto_fill_extension_test/BUILD.gn +++ b/test/unittest/js_auto_fill_extension_test/BUILD.gn @@ -28,7 +28,6 @@ ohos_unittest("js_auto_fill_extension_test") { "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", "//third_party/jsoncpp/include", - "//third_party/json/include", ] sources = [ "js_auto_fill_extension_test.cpp" ] @@ -62,6 +61,7 @@ ohos_unittest("js_auto_fill_extension_test") { "i18n:intl_util", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] diff --git a/test/unittest/js_service_extension_test/BUILD.gn b/test/unittest/js_service_extension_test/BUILD.gn index e69761f716..202ea65685 100644 --- a/test/unittest/js_service_extension_test/BUILD.gn +++ b/test/unittest/js_service_extension_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("js_service_extension_test") { "${ability_runtime_path}/interfaces/kits/native/appkit/app", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include", "//third_party/jsoncpp/include", - "//third_party/json/include", ] sources = [ @@ -63,6 +62,7 @@ ohos_unittest("js_service_extension_test") { "i18n:intl_util", "init:libbegetutil", "ipc:ipc_core", + "json:nlohmann_json_static", "napi:ace_napi", "resource_management:global_resmgr", ] From 9488969d6bf6096dad4a9266be49c54205193516 Mon Sep 17 00:00:00 2001 From: liangzhao Date: Fri, 28 Jun 2024 02:46:26 +0000 Subject: [PATCH 099/148] fix compatibility bug Signed-off-by: liangzhao --- services/abilitymgr/etc/appfwk.para | 2 +- services/common/src/app_utils.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/etc/appfwk.para b/services/abilitymgr/etc/appfwk.para index 115ca8d88e..744752292a 100644 --- a/services/abilitymgr/etc/appfwk.para +++ b/services/abilitymgr/etc/appfwk.para @@ -36,4 +36,4 @@ persist.sys.abilityms.prevent_startability = true const.abilityms.launch_embeded_ui_ability = false const.sys.abilityms.limit_maximum_extensions_of_per_process = 10 const.sys.abilityms.limit_maximum_extensions_of_per_device = 100 -const.sys.abilityms.cache_extension = 3;5;17;260 \ No newline at end of file +const.sys.abilityms.cache_extension = 260 \ No newline at end of file diff --git a/services/common/src/app_utils.cpp b/services/common/src/app_utils.cpp index 3bbdea412a..c1874e134e 100644 --- a/services/common/src/app_utils.cpp +++ b/services/common/src/app_utils.cpp @@ -304,7 +304,7 @@ int32_t AppUtils::GetLimitMaximumExtensionsPerDevice() std::string AppUtils::GetCacheExtensionTypeList() { - std::string cacheExtAbilityTypeList = system::GetParameter(CACHE_EXTENSION_TYPES, "3;5;17;260"); + std::string cacheExtAbilityTypeList = system::GetParameter(CACHE_EXTENSION_TYPES, "260"); TAG_LOGD(AAFwkTag::DEFAULT, "cacheExtAbilityTypeList is %{public}s", cacheExtAbilityTypeList.c_str()); return cacheExtAbilityTypeList; } From fcd33d726690b123efb9ac8cb4f7c457dab8c3b8 Mon Sep 17 00:00:00 2001 From: ZhangYan Date: Wed, 26 Jun 2024 16:16:43 +0800 Subject: [PATCH 100/148] WindowModeMap function memory optimization Signed-off-by: ZhangYan --- .../include/ability_manager_service.h | 1 - .../include/utils/window_options_utils.h | 2 ++ .../src/ability_manager_service.cpp | 21 +++++-------------- .../src/utils/window_options_utils.cpp | 20 ++++++++++++++++++ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 9853c68f6a..f8626e2981 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -2172,7 +2172,6 @@ private: sptr appMgr_ { nullptr }; const static std::map dumpMap; const static std::map dumpsysMap; - const static std::map windowModeMap; std::shared_ptr freeInstallManager_; diff --git a/services/abilitymgr/include/utils/window_options_utils.h b/services/abilitymgr/include/utils/window_options_utils.h index 60151a4da5..26363d61f5 100644 --- a/services/abilitymgr/include/utils/window_options_utils.h +++ b/services/abilitymgr/include/utils/window_options_utils.h @@ -16,6 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_WINDOW_OPTIONS_UTILS_H #define OHOS_ABILITY_RUNTIME_WINDOW_OPTIONS_UTILS_H +#include "ability_info.h" #include "iremote_object.h" #include "start_options.h" #include "want.h" @@ -26,6 +27,7 @@ class WindowOptionsUtils final { public: static void SetWindowPositionAndSize(Want& want, const sptr& callerToken, const StartOptions& startOptions); + static std::pair WindowModeMap(int32_t windowMode); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a5895e98a4..ebdc18e8e9 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -321,17 +321,6 @@ const std::map AbilityManagerSer std::map::value_type("-d", KEY_DUMPSYS_DATA), }; -const std::map AbilityManagerService::windowModeMap = { - std::map::value_type(MULTI_WINDOW_DISPLAY_FULLSCREEN, - AppExecFwk::SupportWindowMode::FULLSCREEN), - std::map::value_type(MULTI_WINDOW_DISPLAY_PRIMARY, - AppExecFwk::SupportWindowMode::SPLIT), - std::map::value_type(MULTI_WINDOW_DISPLAY_SECONDARY, - AppExecFwk::SupportWindowMode::SPLIT), - std::map::value_type(MULTI_WINDOW_DISPLAY_FLOATING, - AppExecFwk::SupportWindowMode::FLOATING), -}; - const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(DelayedSingleton::GetInstance().get()); sptr AbilityManagerService::instance_; @@ -8503,11 +8492,11 @@ bool AbilityManagerService::CheckWindowMode(int32_t windowMode, if (windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED) { return true; } - auto it = windowModeMap.find(windowMode); - if (it != windowModeMap.end()) { - auto bmsWindowMode = it->second; - for (auto mode : windowModes) { - if (mode == bmsWindowMode) { + + auto bmsWindowMode = WindowOptionsUtils::WindowModeMap(windowMode); + if (bmsWindowMode.first) { + for (const auto& mode : windowModes) { + if (mode == bmsWindowMode.second) { return true; } } diff --git a/services/abilitymgr/src/utils/window_options_utils.cpp b/services/abilitymgr/src/utils/window_options_utils.cpp index 205bd80eb4..d05c8e03ba 100644 --- a/services/abilitymgr/src/utils/window_options_utils.cpp +++ b/services/abilitymgr/src/utils/window_options_utils.cpp @@ -45,5 +45,25 @@ void WindowOptionsUtils::SetWindowPositionAndSize(Want& want, want.SetParam(Want::PARAM_RESV_WITH_ANIMATION, withAnimation); } } + +std::pair WindowOptionsUtils::WindowModeMap(int32_t windowMode) +{ + std::pair result(false, AppExecFwk::SupportWindowMode::FULLSCREEN); + + if (windowMode == MULTI_WINDOW_DISPLAY_FULLSCREEN) { + result.first = true; + result.second = AppExecFwk::SupportWindowMode::FULLSCREEN; + } else if (windowMode == MULTI_WINDOW_DISPLAY_PRIMARY) { + result.first = true; + result.second = AppExecFwk::SupportWindowMode::SPLIT; + } else if (windowMode == MULTI_WINDOW_DISPLAY_SECONDARY) { + result.first = true; + result.second = AppExecFwk::SupportWindowMode::SPLIT; + } else if (windowMode == MULTI_WINDOW_DISPLAY_FLOATING) { + result.first = true; + result.second = AppExecFwk::SupportWindowMode::FLOATING; + } + return result; +} } // namespace AAFwk } // namespace OHOS From b382d1c0e3bea942ca5e950f3365fd61568ed65b Mon Sep 17 00:00:00 2001 From: jiangzhijun8 Date: Fri, 28 Jun 2024 02:39:05 +0000 Subject: [PATCH 101/148] Issue: https://gitee.com/openharmony/account_os_account/issues/IA7CW5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comment: 删除不用的依赖 Signed-off-by: jiangzhijun8 --- test/unittest/uri_permission_impl_test/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/uri_permission_impl_test/BUILD.gn b/test/unittest/uri_permission_impl_test/BUILD.gn index 76433b40e9..b6008af331 100755 --- a/test/unittest/uri_permission_impl_test/BUILD.gn +++ b/test/unittest/uri_permission_impl_test/BUILD.gn @@ -59,6 +59,7 @@ ohos_unittest("uri_permission_impl_test") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "hilog:libhilog", "init:libbeget_proxy", "init:libbegetutil", "storage_service:storage_manager_sa_proxy", From 3464d8159e5e8c467360cfa3a615f8d8c464cc79 Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Thu, 6 Jun 2024 11:10:41 +0800 Subject: [PATCH 102/148] =?UTF-8?q?SA=E6=8B=89=E8=B5=B7permission=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- services/abilitymgr/abilitymgr.gni | 1 + .../utils/extension_permissions_util.h | 30 ++++++++ .../src/ability_manager_service.cpp | 7 ++ .../src/utils/extension_permissions_util.cpp | 76 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 services/abilitymgr/include/utils/extension_permissions_util.h create mode 100644 services/abilitymgr/src/utils/extension_permissions_util.cpp diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index be41b7ec36..c8fecb97fd 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -132,6 +132,7 @@ abilityms_files = [ #utils "src/utils/window_options_utils.cpp", + "src/utils/extension_permissions_util.cpp", ] if (ability_runtime_graphics) { diff --git a/services/abilitymgr/include/utils/extension_permissions_util.h b/services/abilitymgr/include/utils/extension_permissions_util.h new file mode 100644 index 0000000000..7b3a5e4196 --- /dev/null +++ b/services/abilitymgr/include/utils/extension_permissions_util.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_EXTENSION_PERMISSIONS_UTIL_H +#define OHOS_EXTENSION_PERMISSIONS_UTIL_H + +#include "extension_ability_info.h" + +namespace OHOS { +namespace AAFwk { +class ExtensionPermissionsUtil final { +public: + static bool CheckSAPermission(const AppExecFwk::ExtensionAbilityType &extensionType); +}; + +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_EXTENSION_PERMISSIONS_UTIL_H \ No newline at end of file diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index a85445e054..9a633bc216 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -113,6 +113,7 @@ #include "xcollie/watchdog.h" #include "config_policy_utils.h" #include "running_multi_info.h" +#include "utils/extension_permissions_util.h" #include "utils/window_options_utils.h" #ifdef SUPPORT_GRAPHICS #include "dialog_session_record.h" @@ -3838,6 +3839,12 @@ int AbilityManagerService::ConnectLocalAbility(const Want &want, const int32_t u TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s CheckCallServicePermission error.", __func__); return result; } + + if (!ExtensionPermissionsUtil::CheckSAPermission(targetExtensionType)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "The SA doesn't have permission for target extension."); + return CHECK_PERMISSION_FAILED; + } + result = PreLoadAppDataAbilities(abilityInfo.bundleName, validUserId); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ConnectAbility: App data ability preloading failed, '%{public}s', %{public}d", diff --git a/services/abilitymgr/src/utils/extension_permissions_util.cpp b/services/abilitymgr/src/utils/extension_permissions_util.cpp new file mode 100644 index 0000000000..7b8384cc89 --- /dev/null +++ b/services/abilitymgr/src/utils/extension_permissions_util.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "utils/extension_permissions_util.h" + +#include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" +#include "permission_verification.h" + +namespace OHOS { +namespace AAFwk { + +bool ExtensionPermissionsUtil::CheckSAPermission(const AppExecFwk::ExtensionAbilityType &extensionType) +{ + auto checkRet = false; + TAG_LOGD(AAFwkTag::ABILITYMGR, "CheckSAPermission, extensionType: %{public}d.", extensionType); + if (extensionType == AppExecFwk::ExtensionAbilityType::FORM) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_FORM_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::WORK_SCHEDULER) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_WORK_SCHEDULER_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::INPUTMETHOD) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_INPUT_METHOD_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::ACCESSIBILITY) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_ACCESSIBILITY_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::STATICSUBSCRIBER) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_STATIC_SUBSCRIBER_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::WALLPAPER) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_WALLPAPER_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::BACKUP) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_BACKUP_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::ENTERPRISE_ADMIN) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_ENTERPRISE_ADMIN_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::PRINT) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_PRINT_EXTENSION"); + } else if (extensionType == AppExecFwk::ExtensionAbilityType::VPN) { + checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( + "ohos.permission.CONNECT_VPN_EXTENSION"); + } else { + TAG_LOGI(AAFwkTag::ABILITYMGR, "No need connect permission for extension type %{public}d.", extensionType); + return true; + } + if (!checkRet) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "SA connect permission verification failed."); + return false; + } + + return true; +} + + +} // namespace AAFwk +} // namespace OHOS From 996bd29ad319950250b691bf1f04feb3ac5709dd Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Fri, 28 Jun 2024 06:08:54 +0000 Subject: [PATCH 103/148] =?UTF-8?q?=E5=8F=91=E7=94=9Ffreeze=EF=BC=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=B8=8A=E6=8A=A5=E4=BA=8B=E4=BB=B6id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mayunteng_1 Change-Id: I457f28731302300d0d74b3a6cdcf161c02214037 --- services/appdfr/include/application_anr_listener.h | 2 +- services/appdfr/src/application_anr_listener.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/services/appdfr/include/application_anr_listener.h b/services/appdfr/include/application_anr_listener.h index 73316584a2..791d2769aa 100644 --- a/services/appdfr/include/application_anr_listener.h +++ b/services/appdfr/include/application_anr_listener.h @@ -30,7 +30,7 @@ class ApplicationAnrListener : public MMI::IAnrObserver { public: ApplicationAnrListener(); virtual ~ApplicationAnrListener(); - void OnAnr(int32_t pid) const override; + void OnAnr(int32_t pid, int32_t eventId) const override; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/appdfr/src/application_anr_listener.cpp b/services/appdfr/src/application_anr_listener.cpp index 0f8d8c2303..d0d77bb502 100644 --- a/services/appdfr/src/application_anr_listener.cpp +++ b/services/appdfr/src/application_anr_listener.cpp @@ -29,7 +29,7 @@ ApplicationAnrListener::ApplicationAnrListener() {} ApplicationAnrListener::~ApplicationAnrListener() {} -void ApplicationAnrListener::OnAnr(int32_t pid) const +void ApplicationAnrListener::OnAnr(int32_t pid, int32_t eventId) const { AppExecFwk::AppFaultDataBySA faultData; faultData.faultType = AppExecFwk::FaultDataType::APP_FREEZE; @@ -43,4 +43,4 @@ void ApplicationAnrListener::OnAnr(int32_t pid) const DelayedSingleton::GetInstance()->NotifyAppFaultBySA(faultData); } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS From c2a4adfd686280f197ac34b19d70c3e113ef4b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E5=86=AC=E5=86=AC=E5=86=AC?= Date: Fri, 28 Jun 2024 16:22:42 +0800 Subject: [PATCH 104/148] =?UTF-8?q?Messsage:=E6=B3=A8=E5=86=8C=E5=A4=9A?= =?UTF-8?q?=E6=A8=A1anr=E4=BB=8Einit=E6=96=B9=E6=B3=95=E4=B8=AD=E7=A7=BB?= =?UTF-8?q?=E5=88=B0onAddSystemAbility=E6=96=B9=E6=B3=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 郑冬冬冬 --- .../abilitymgr/src/ability_manager_service.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 85e1afd27e..974f3c6fb2 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -364,6 +364,9 @@ void AbilityManagerService::OnStart() AddSystemAbilityListener(BACKGROUND_TASK_MANAGER_SERVICE_ID); AddSystemAbilityListener(DISTRIBUTED_SCHED_SA_ID); AddSystemAbilityListener(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); +#ifdef SUPPORT_SCREEN + AddSystemAbilityListener(MULTIMODAL_INPUT_SERVICE_ID); +#endif TAG_LOGI(AAFwkTag::ABILITYMGR, "Ability manager service start success."); } @@ -384,11 +387,6 @@ bool AbilityManagerService::Init() subManagersHelper_->InitSubManagers(MAIN_USER_ID, true); SwitchManagers(U0_USER_ID, false); #ifdef SUPPORT_SCREEN - auto anrListenerTask = []() { - auto anrListener = std::make_shared(); - MMI::InputManager::GetInstance()->SetAnrObserver(anrListener); - }; - taskHandler_->SubmitTask(anrListenerTask, "AnrListenerTask"); implicitStartProcessor_ = std::make_shared(); if (!Rosen::SceneBoardJudgement::IsSceneBoardEnabled()) { InitFocusListener(); @@ -2239,6 +2237,13 @@ void AbilityManagerService::OnAddSystemAbility(int32_t systemAbilityId, const st SubscribeBundleEventCallback(); break; } +#ifdef SUPPORT_SCREEN + case MULTIMODAL_INPUT_SERVICE_ID: { + auto anrListener = std::make_shared(); + MMI::InputManager::GetInstance()->SetAnrObserver(anrListener); + break; + } +#endif default: break; } From 0a87ef48eb7a5f72028630100335a986ea5090dc Mon Sep 17 00:00:00 2001 From: donglin Date: Fri, 28 Jun 2024 08:34:35 +0000 Subject: [PATCH 105/148] modify action start Signed-off-by: donglin Change-Id: I0dcb6155a6ac84d6ae4b6ca9c8ca886fd8f26f62 --- services/abilitymgr/src/implicit_start_processor.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 3386399c7c..319ab7d48d 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -53,6 +53,7 @@ const std::string OPEN_LINK_APP_LINKING_ONLY = "appLinkingOnly"; const std::string HTTP_SCHEME_NAME = "http"; const std::string HTTPS_SCHEME_NAME = "https"; const std::string APP_CLONE_INDEX = "ohos.extra.param.key.appCloneIndex"; +constexpr const char* SUPPORT_ACTION_START_SELECTOR = "persist.sys.ability.support.action_start_selector"; const std::vector ImplicitStartProcessor::blackList = { std::vector::value_type(BLACK_ACTION_SELECT_DATA), @@ -796,6 +797,11 @@ void ImplicitStartProcessor::SetTargetLinkInfo(const std::vector Date: Fri, 28 Jun 2024 20:24:39 +0800 Subject: [PATCH 106/148] TicketNo:AR20240403329372 Description:add application no responding dialog Team:EMUI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No Signed-off-by: zhangduanyang --- .../modal_system_app_freeze_uiextension.h | 2 ++ .../modal_system_app_freeze_uiextension.cpp | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/services/appmgr/include/modal_system_app_freeze_uiextension.h b/services/appmgr/include/modal_system_app_freeze_uiextension.h index 882834dba2..d84a1ca552 100644 --- a/services/appmgr/include/modal_system_app_freeze_uiextension.h +++ b/services/appmgr/include/modal_system_app_freeze_uiextension.h @@ -41,6 +41,7 @@ public: void ProcessAppFreeze(bool focusFlag, const FaultData &faultData, std::string pid, std::string bundleName, std::function callback); + void TryReduceReqeustCount(); private: bool CreateModalUIExtension(std::string pid, std::string bundleName); @@ -66,6 +67,7 @@ private: std::mutex appFreezeResultMutex_; std::mutex dialogConnectionMutex_; + int32_t reqeustCount_ = 0; sptr dialogConnectionCallback_; }; } // namespace AppExecFwk diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index 931e4d2f75..2bce512204 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -21,6 +21,7 @@ #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "in_process_call_wrapper.h" #include "scene_board_judgement.h" namespace OHOS { @@ -75,11 +76,24 @@ void ModalSystemAppFreezeUIExtension::ProcessAppFreeze(bool focusFlag, const Fau } } +void ModalSystemAppFreezeUIExtension::TryReduceReqeustCount() +{ + std::unique_lock lockAssertResult(appFreezeResultMutex_); + if (reqeustCount_ > 0) { + reqeustCount_--; + } +} + bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, std::string bundleName) { TAG_LOGI(AAFwkTag::ABILITYMGR, "CreateModalUIExtension Called."); AAFwk::Want want = CreateSystemDialogWant(pid, bundleName); std::unique_lock lockAssertResult(appFreezeResultMutex_); + if (reqeustCount_ > 0) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "CreateModalUIExtension reqeustCount is greater than 0."); + return false; + } + reqeustCount_++; auto callback = GetConnection(); if (callback == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "CreateModalUIExtension Callback is nullptr."); @@ -97,10 +111,11 @@ bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, st } else { systemUIWant.SetElementName("com.ohos.systemui", "com.ohos.systemui.dialog"); } - auto result = abilityManagerClient->ConnectAbility(systemUIWant, callback, INVALID_USERID); + auto result = IN_PROCESS_CALL(abilityManagerClient->ConnectAbility(systemUIWant, callback, INVALID_USERID)); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "CreateModalUIExtension ConnectSystemUi ConnectAbility dialog failed, result = %{public}d", result); + reqeustCount_--; return false; } TAG_LOGE(AAFwkTag::ABILITYMGR, @@ -156,6 +171,7 @@ void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::OnAbilityConnec TAG_LOGI(AAFwkTag::ABILITYMGR, "AppFreezeDialogConnection::OnAbilityConnectDone Show dialog"); auto ret = remote->SendRequest(code, data, reply, option); if (ret != ERR_OK) { + ModalSystemAppFreezeUIExtension::GetInstance().TryReduceReqeustCount(); TAG_LOGE(AAFwkTag::ABILITYMGR, "Show dialog is failed"); return; } @@ -165,6 +181,7 @@ void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::OnAbilityDiscon const AppExecFwk::ElementName &element, int resultCode) { TAG_LOGI(AAFwkTag::ABILITYMGR, "Called."); + ModalSystemAppFreezeUIExtension::GetInstance().TryReduceReqeustCount(); } } // namespace AppExecFwk } // namespace OHOS From 0fa47ae448039180fe64d3d0e80b3eedf7634048 Mon Sep 17 00:00:00 2001 From: zhangduanyang Date: Fri, 28 Jun 2024 20:42:42 +0800 Subject: [PATCH 107/148] TicketNo:AR20240403329372 Description:add application no responding dialog Team:EMUI Feature or Bugfix:Feature Binary Source:No PrivateCode(Yes/No):No Signed-off-by: zhangduanyang --- services/appmgr/src/modal_system_app_freeze_uiextension.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp index 2bce512204..3ad0bcce8e 100644 --- a/services/appmgr/src/modal_system_app_freeze_uiextension.cpp +++ b/services/appmgr/src/modal_system_app_freeze_uiextension.cpp @@ -93,7 +93,6 @@ bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, st TAG_LOGI(AAFwkTag::ABILITYMGR, "CreateModalUIExtension reqeustCount is greater than 0."); return false; } - reqeustCount_++; auto callback = GetConnection(); if (callback == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "CreateModalUIExtension Callback is nullptr."); @@ -115,11 +114,11 @@ bool ModalSystemAppFreezeUIExtension::CreateModalUIExtension(std::string pid, st if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "CreateModalUIExtension ConnectSystemUi ConnectAbility dialog failed, result = %{public}d", result); - reqeustCount_--; return false; } TAG_LOGE(AAFwkTag::ABILITYMGR, "CreateModalUIExtension ConnectSystemUi ConnectAbility dialog success, result = %{public}d", result); + reqeustCount_++; return true; } @@ -146,6 +145,7 @@ void ModalSystemAppFreezeUIExtension::AppFreezeDialogConnection::OnAbilityConnec { TAG_LOGD(AAFwkTag::ABILITYMGR, "Called."); if (remote == nullptr) { + ModalSystemAppFreezeUIExtension::GetInstance().TryReduceReqeustCount(); TAG_LOGE(AAFwkTag::ABILITYMGR, "Input remote object is nullptr."); return; } From fd420c24375160f679985af3eb1bf6c9285d7e34 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Sat, 29 Jun 2024 09:14:04 +0800 Subject: [PATCH 108/148] add param for wms to solve snapshot problemm Signed-off-by: gongyuechen --- .../ability_manager/include/ability_manager_client.h | 3 ++- .../include/ability_manager_interface.h | 6 +++++- services/abilitymgr/include/ability_manager_proxy.h | 3 ++- services/abilitymgr/include/ability_manager_service.h | 6 +++++- services/abilitymgr/include/mission_list_manager.h | 2 ++ services/abilitymgr/src/ability_manager_client.cpp | 5 +++-- services/abilitymgr/src/ability_manager_proxy.cpp | 7 ++++++- services/abilitymgr/src/ability_manager_service.cpp | 10 +++++++++- services/abilitymgr/src/ability_manager_stub.cpp | 3 ++- services/abilitymgr/src/mission_list_manager.cpp | 3 ++- .../AMS/mock_serviceability_manager_service.h | 3 ++- .../include/mock_ability_manager_service.h | 3 ++- .../ability_delegator/mock_ability_delegator_stub.cpp | 6 ++++-- .../ability_delegator/mock_ability_delegator_stub.h | 6 ++++-- .../AMS/mock_ability_manager_service.h | 3 ++- .../AMS/mock_serviceability_manager_service.h | 3 ++- .../moduletest/mock/include/mock_ability_mgr_service.h | 3 ++- .../ability_manager_stub_mock_test.h | 3 ++- .../ability_manager_proxy_test.cpp | 2 +- .../ability_manager_stub_mock.h | 3 ++- .../ability_manager_stub_impl_mock.h | 3 ++- .../ability_manager_test/ability_manager_stub_mock.h | 3 ++- .../ability_manager_stub_mock.h | 3 ++- .../sys_mgr_client_test/mock_ability_manager_service.h | 3 ++- tools/test/mock/mock_ability_manager_stub.h | 3 ++- 25 files changed, 71 insertions(+), 27 deletions(-) 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 cf2205b207..498d83bca8 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1017,7 +1017,8 @@ public: * @param handler Indidate handler of WindowManagerService. * @return ErrCode Returns ERR_OK on success, others on failure. */ - ErrCode RegisterWindowManagerServiceHandler(sptr handler); + ErrCode RegisterWindowManagerServiceHandler(sptr handler, + bool animationEnabled = true); /** * WindowManager notification AbilityManager after the first frame is drawn. 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 6f9998725f..dbe7864d6b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -893,7 +893,11 @@ public: * @param handler Indidate handler of WindowManagerService. * @return ErrCode Returns ERR_OK on success, others on failure. */ - virtual int RegisterWindowManagerServiceHandler(const sptr& handler) = 0; + virtual int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled) + { + return 0; + } /** * WindowManager notification AbilityManager after the first frame is drawn. diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index aaaeeb2ba1..cac766e733 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -718,7 +718,8 @@ public: virtual int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override; - virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override; + virtual int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled) override; virtual void CompleteFirstFrameDrawing(const sptr &abilityToken) override; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 3c4db1a412..efb2ec465c 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1107,7 +1107,8 @@ public: virtual int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override; - virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override; + virtual int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled) override; virtual void CompleteFirstFrameDrawing(const sptr &abilityToken) override; @@ -1137,6 +1138,8 @@ public: virtual int UnregisterAbilityFirstFrameStateObserver( const sptr &observer) override; + + bool GetAnimationFlag(); #endif @@ -2266,6 +2269,7 @@ private: std::shared_ptr implicitStartProcessor_; sptr wmsHandler_; std::shared_ptr dialogSessionRecord_; + bool isAnimationEnabled_ = true; //only use on mission list #endif std::shared_ptr interceptorExecuter_; std::shared_ptr afterCheckExecuter_; diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 154666e8c4..6595f66509 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -359,6 +359,8 @@ public: bool IsAbilityStarted(AbilityRequest &abilityRequest, std::shared_ptr &targetRecord); void SignRestartAppFlag(const std::string &bundleName); + + void SetAnimationFlag(bool IsAnimationEnabled); #ifdef SUPPORT_SCREEN public: /** diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 9e52ff248f..c0920f2c43 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1302,11 +1302,12 @@ ErrCode AbilityManagerClient::SetMissionIcon( return abms->SetMissionIcon(abilityToken, icon); } -ErrCode AbilityManagerClient::RegisterWindowManagerServiceHandler(sptr handler) +ErrCode AbilityManagerClient::RegisterWindowManagerServiceHandler(sptr handler, + bool animationEnabled) { auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->RegisterWindowManagerServiceHandler(handler); + return abms->RegisterWindowManagerServiceHandler(handler, animationEnabled); } void AbilityManagerClient::CompleteFirstFrameDrawing(sptr abilityToken) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index a5586cef0a..82f1a747bb 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -2957,7 +2957,8 @@ int AbilityManagerProxy::SetMissionIcon(const sptr &token, return reply.ReadInt32(); } -int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr& handler) +int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled) { if (!handler) { TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: handler is nullptr.", __func__); @@ -2972,6 +2973,10 @@ int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr &token, return missionListManager->SetMissionIcon(token, icon); } -int AbilityManagerService::RegisterWindowManagerServiceHandler(const sptr &handler) +int AbilityManagerService::RegisterWindowManagerServiceHandler(const sptr &handler, + bool animationEnabled) { auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); if (!isSaCall) { @@ -8476,6 +8477,7 @@ int AbilityManagerService::RegisterWindowManagerServiceHandler(const sptr::GetInstance()-> UnregisterAbilityFirstFrameStateObserver(observer); } + +bool AbilityManagerService::GetAnimationFlag() +{ + return isAnimationEnabled_; +} + #endif int AbilityManagerService::CheckCallServicePermission(const AbilityRequest &abilityRequest) diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 63d51a2cc8..4298b50791 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -2587,7 +2587,8 @@ int AbilityManagerStub::RegisterWindowManagerServiceHandlerInner(MessageParcel & TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s read WMS handler failed!", __func__); return ERR_NULL_OBJECT; } - return RegisterWindowManagerServiceHandler(handler); + bool animationEnabled = data.ReadBool(); + return RegisterWindowManagerServiceHandler(handler, animationEnabled); } int AbilityManagerStub::CompleteFirstFrameDrawingInner(MessageParcel &data, MessageParcel &reply) diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 526afcae46..dce62c1c3f 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -2074,7 +2074,8 @@ void MissionListManager::MoveToBackgroundTask(const std::shared_ptrGetAbilityInfo().name.c_str()); abilityRecord->SetIsNewWant(false); if (abilityRecord->lifeCycleStateInfo_.sceneFlag != SCENE_FLAG_KEYGUARD && - !abilityRecord->IsClearMissionFlag() && !isClose) { + !abilityRecord->IsClearMissionFlag() && + !(isClose && OHOS::DelayedSingleton::GetInstance()->GetAnimationFlag())) { UpdateMissionSnapshot(abilityRecord); } 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 6b43a178ce..34ce4ca100 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 @@ -305,7 +305,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } 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 09403279ab..02a91d6a0c 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 @@ -269,7 +269,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } diff --git a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp index 4fcdd85271..f2444dc66f 100644 --- a/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp +++ b/test/mock/frameworks_kits_appkit_native_test/ability_delegator/mock_ability_delegator_stub.cpp @@ -462,7 +462,8 @@ int MockAbilityDelegatorStub::SetMissionIcon( return 0; } -int MockAbilityDelegatorStub::RegisterWindowManagerServiceHandler(const sptr& handler) +int MockAbilityDelegatorStub::RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled) { return 0; } @@ -473,7 +474,8 @@ int MockAbilityDelegatorStub2::SetMissionIcon( return 0; } -int MockAbilityDelegatorStub2::RegisterWindowManagerServiceHandler(const sptr& handler) +int MockAbilityDelegatorStub2::RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled) { 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 cf399653bc..c894116e1e 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 @@ -182,7 +182,8 @@ public: MOCK_METHOD2(SetMissionLabel, int(const sptr& token, const std::string& label)); int SetMissionIcon( const sptr& token, const std::shared_ptr& icon) override; - int RegisterWindowManagerServiceHandler(const sptr& handler); + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true); void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} #endif MOCK_METHOD2(IsValidMissionIds, int32_t(const std::vector&, std::vector&)); @@ -363,7 +364,8 @@ public: MOCK_METHOD2(SetMissionLabel, int(const sptr& token, const std::string& label)); int SetMissionIcon( const sptr& token, const std::shared_ptr& icon) override; - int RegisterWindowManagerServiceHandler(const sptr& handler); + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true); void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} #endif MOCK_METHOD2(IsValidMissionIds, int32_t(const std::vector&, std::vector&)); 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 a1d89e3338..97fda0551b 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 @@ -260,7 +260,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } 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 254183a4b1..884d9bdfc1 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 @@ -283,7 +283,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } diff --git a/test/moduletest/mock/include/mock_ability_mgr_service.h b/test/moduletest/mock/include/mock_ability_mgr_service.h index ec80cca0a9..cfb532afa8 100644 --- a/test/moduletest/mock/include/mock_ability_mgr_service.h +++ b/test/moduletest/mock/include/mock_ability_mgr_service.h @@ -190,7 +190,8 @@ public: return 0; } - virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } diff --git a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h index 596e07d73f..d8f9221b80 100644 --- a/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h +++ b/test/unittest/ability_manager_client_branch_test/ability_manager_stub_mock_test.h @@ -272,7 +272,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { 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 e9324f32c8..846aa58092 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 @@ -1625,7 +1625,7 @@ HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_SetMissionLabel_001, TestS HWTEST_F(AbilityManagerProxyTest, AbilityManagerProxy_RegisterWindowManagerServiceHandler_001, TestSize.Level1) { sptr handler = nullptr; - auto res = proxy_->RegisterWindowManagerServiceHandler(handler); + auto res = proxy_->RegisterWindowManagerServiceHandler(handler, true); EXPECT_EQ(res, INNER_ERR); } 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 59e8bccf92..86bb93404b 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 @@ -293,7 +293,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { 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 047860ba53..7113d2d70b 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 @@ -344,7 +344,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { 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 338123ebab..247150ed60 100644 --- a/test/unittest/ability_manager_test/ability_manager_stub_mock.h +++ b/test/unittest/ability_manager_test/ability_manager_stub_mock.h @@ -272,7 +272,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h index 68d1f2fb9f..0aab8add09 100644 --- a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -248,7 +248,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h index b074b5ce3d..332c998789 100644 --- a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -250,7 +250,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index d3229f0c50..d09df29e23 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -206,7 +206,8 @@ public: return 0; } - int RegisterWindowManagerServiceHandler(const sptr& handler) override + int RegisterWindowManagerServiceHandler(const sptr& handler, + bool animationEnabled = true) override { return 0; } From 82fb739c12bb571e7ac109118c52482cc7a9ed18 Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Sat, 29 Jun 2024 09:16:24 +0800 Subject: [PATCH 109/148] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=92=88=E5=AF=B9fil?= =?UTF-8?q?e=5Faccess=5Fextension=E7=9A=84=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- services/abilitymgr/src/utils/extension_permissions_util.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/services/abilitymgr/src/utils/extension_permissions_util.cpp b/services/abilitymgr/src/utils/extension_permissions_util.cpp index 7b8384cc89..ad821f0865 100644 --- a/services/abilitymgr/src/utils/extension_permissions_util.cpp +++ b/services/abilitymgr/src/utils/extension_permissions_util.cpp @@ -50,9 +50,6 @@ bool ExtensionPermissionsUtil::CheckSAPermission(const AppExecFwk::ExtensionAbil } else if (extensionType == AppExecFwk::ExtensionAbilityType::ENTERPRISE_ADMIN) { checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( "ohos.permission.CONNECT_ENTERPRISE_ADMIN_EXTENSION"); - } else if (extensionType == AppExecFwk::ExtensionAbilityType::FILEACCESS_EXTENSION) { - checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( - "ohos.permission.CONNECT_FILE_ACCESS_EXTENSION"); } else if (extensionType == AppExecFwk::ExtensionAbilityType::PRINT) { checkRet = PermissionVerification::GetInstance()->VerifyCallingPermission( "ohos.permission.CONNECT_PRINT_EXTENSION"); From 2f8d98f2ffa48988c96ac0835516427948b66d11 Mon Sep 17 00:00:00 2001 From: wanganjie Date: Sat, 29 Jun 2024 10:32:53 +0800 Subject: [PATCH 110/148] =?UTF-8?q?UIExtension=E5=AE=89=E5=85=A8=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E9=80=9A=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wanganjie --- .../auto_fill_extension_ability/js_auto_fill_extension.cpp | 1 + .../ability/native/ui_extension_ability/js_ui_extension.cpp | 1 + .../ability/native/ui_extension_ability/js_ui_extension_base.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp index bbdd7d3a0c..2e082ec39e 100644 --- a/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp +++ b/frameworks/native/ability/native/auto_fill_extension_ability/js_auto_fill_extension.cpp @@ -493,6 +493,7 @@ bool JsAutoFillExtension::HandleAutoFillCreate(const AAFwk::Want &want, const sp option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION); option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION); option->SetParentId(sessionInfo->hostWindowId); + option->SetUIExtensionUsage(static_cast(sessionInfo->uiExtensionUsage)); auto uiWindow = Rosen::Window::Create(option, GetContext(), sessionInfo->sessionToken); if (uiWindow == nullptr) { TAG_LOGE(AAFwkTag::AUTOFILL_EXT, "Create ui window error."); diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp index a4946e933c..9f7507b2c6 100755 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension.cpp @@ -708,6 +708,7 @@ sptr JsUIExtension::CreateUIWindow(const std::shared_ptrSetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION); option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION); option->SetParentId(sessionInfo->hostWindowId); + option->SetUIExtensionUsage(static_cast(sessionInfo->uiExtensionUsage)); return Rosen::Window::Create(option, GetContext(), sessionInfo->sessionToken); } diff --git a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp index 556d3e7fac..7b1a1c819d 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_ui_extension_base.cpp @@ -503,6 +503,7 @@ bool JsUIExtensionBase::HandleSessionCreate(const AAFwk::Want &want, const sptr< option->SetWindowType(Rosen::WindowType::WINDOW_TYPE_UI_EXTENSION); option->SetWindowSessionType(Rosen::WindowSessionType::EXTENSION_SESSION); option->SetParentId(sessionInfo->hostWindowId); + option->SetUIExtensionUsage(static_cast(sessionInfo->uiExtensionUsage)); auto uiWindow = Rosen::Window::Create(option, context_, sessionInfo->sessionToken); if (uiWindow == nullptr) { TAG_LOGE(AAFwkTag::UI_EXT, "create ui window error."); From 104064ac377bc7352ccf82530324b0375a7fddc5 Mon Sep 17 00:00:00 2001 From: donglin Date: Sat, 29 Jun 2024 02:34:55 +0000 Subject: [PATCH 111/148] Add new kill process permission Signed-off-by: donglin Change-Id: Ibd73837f43c1fe38694f4156eca2c9b3323f8b6c --- .../appmgr/include/app_mgr_service_inner.h | 6 +- services/appmgr/src/ams_mgr_scheduler.cpp | 2 +- services/appmgr/src/app_mgr_service_inner.cpp | 74 +++++++++---------- .../common/include/permission_constants.h | 1 + .../app_mgr_service_inner_test.cpp | 12 +-- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index c845210aec..5811df4aad 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -726,7 +726,7 @@ public: virtual int GetRenderProcessTerminationStatus(pid_t renderPid, int &status); - int VerifyProcessPermission(const sptr &token) const; + int VerifyKillProcessPermission(const sptr &token) const; int VerifyAccountPermission(const std::string &permissionName, const int userId) const; @@ -1318,9 +1318,9 @@ private: static void PointerDeviceEventCallback(const char *key, const char *value, void *context); - int VerifyProcessPermission() const; + int VerifyKillProcessPermission(const std::string &bundleName) const; - int VerifyProcessPermission(const std::string &bundleName) const; + int32_t VerifyKillProcessPermissionCommon() const; bool CheckCallerIsAppGallery(); diff --git a/services/appmgr/src/ams_mgr_scheduler.cpp b/services/appmgr/src/ams_mgr_scheduler.cpp index e77bf605c7..2b1060dcf4 100644 --- a/services/appmgr/src/ams_mgr_scheduler.cpp +++ b/services/appmgr/src/ams_mgr_scheduler.cpp @@ -192,7 +192,7 @@ void AmsMgrScheduler::KillProcessByAbilityToken(const sptr &token return; } - if (amsMgrServiceInner_->VerifyProcessPermission(token) != ERR_OK) { + if (amsMgrServiceInner_->VerifyKillProcessPermission(token) != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "%{public}s: Permission verification failed", __func__); return; } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 98de52e645..968c660aa3 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -1128,7 +1128,7 @@ int32_t AppMgrServiceInner::KillApplication(const std::string &bundleName) return KillApplicationByBundleName(bundleName); } - auto result = VerifyProcessPermission(bundleName); + auto result = VerifyKillProcessPermission(bundleName); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return result; @@ -1146,7 +1146,7 @@ int32_t AppMgrServiceInner::KillApplicationByUid(const std::string &bundleName, int32_t result = ERR_OK; if (!CheckCallerIsAppGallery()) { - result = VerifyProcessPermission(bundleName); + result = VerifyKillProcessPermission(bundleName); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "Permission verification failed."); return result; @@ -4317,33 +4317,13 @@ int32_t AppMgrServiceInner::NotifyAppMgrRecordExitReason(int32_t pid, int32_t re return ERR_OK; } -int AppMgrServiceInner::VerifyProcessPermission() const +int AppMgrServiceInner::VerifyKillProcessPermission(const std::string &bundleName) const { - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - - if (VerifyAPL()) { - return ERR_OK; - } - - auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( - AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES); - return isCallingPerm ? ERR_OK : ERR_PERMISSION_DENIED; -} - -int AppMgrServiceInner::VerifyProcessPermission(const std::string &bundleName) const -{ - CHECK_CALLER_IS_SYSTEM_APP; - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); - if (isSaCall || isShellCall) { - return ERR_OK; - } - - if (VerifyAPL()) { - return ERR_OK; + TAG_LOGI(AAFwkTag::APPMGR, "Check Kill permission, callerUid:%{public}d, callerPid:%{public}d", + IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingPid()); + int32_t ret = VerifyKillProcessPermissionCommon(); + if (ret != ERR_PERMISSION_DENIED) { + return ret; } auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( @@ -4363,16 +4343,13 @@ int AppMgrServiceInner::VerifyProcessPermission(const std::string &bundleName) c return ERR_OK; } -int AppMgrServiceInner::VerifyProcessPermission(const sptr &token) const +int AppMgrServiceInner::VerifyKillProcessPermission(const sptr &token) const { - CHECK_CALLER_IS_SYSTEM_APP; - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (isSaCall) { - return ERR_OK; - } - - if (VerifyAPL()) { - return ERR_OK; + TAG_LOGI(AAFwkTag::APPMGR, "Check Kill permission, callerUid:%{public}d, callerPid:%{public}d", + IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingPid()); + int32_t ret = VerifyKillProcessPermissionCommon(); + if (ret != ERR_PERMISSION_DENIED) { + return ret; } auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( @@ -4392,6 +4369,29 @@ int AppMgrServiceInner::VerifyProcessPermission(const sptr &token return ERR_OK; } +int32_t AppMgrServiceInner::VerifyKillProcessPermissionCommon() const +{ + CHECK_CALLER_IS_SYSTEM_APP; + auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( + AAFwk::PermissionConstants::PERMISSION_KILL_APP_PROCESSES); + if (isCallingPerm) { + return ERR_OK; + } + + // VerifyAPL and ohos.permission.CLEAN_BACKGROUND_PROCESSES will be removed on API18 + auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); + if (isSaCall || isShellCall) { + return ERR_OK; + } + + if (VerifyAPL()) { + return ERR_OK; + } + + return ERR_PERMISSION_DENIED; +} + bool AppMgrServiceInner::CheckCallerIsAppGallery() { TAG_LOGD(AAFwkTag::APPMGR, "called"); diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index 25f5d28bc4..da8db187b2 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -56,6 +56,7 @@ constexpr const char* PERMISSION_START_SHORTCUT = "ohos.permission.START_SHORTCU constexpr const char* PERMISSION_PRELOAD_APPLICATION = "ohos.permission.PRELOAD_APPLICATION"; constexpr const char* PERMISSION_SET_PROCESS_CACHE_STATE = "ohos.permission.SET_PROCESS_CACHE_STATE"; constexpr const char* PERMISSION_PRELOAD_UI_EXTENSION_ABILITY = "ohos.permission.PRELOAD_UI_EXTENSION_ABILITY"; +constexpr const char* PERMISSION_KILL_APP_PROCESSES = "ohos.permission.KILL_APP_PROCESSES"; } // namespace PermissionConstants } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index 20ddd169dc..4710f75dad 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -2940,23 +2940,23 @@ HWTEST_F(AppMgrServiceInnerTest, NotifyAppMgrRecordExitReason_001, TestSize.Leve } /** - * @tc.name: VerifyProcessPermission_001 + * @tc.name: VerifyKillProcessPermission_001 * @tc.desc: verify process permission. * @tc.type: FUNC * @tc.require: issueI5W4S7 */ -HWTEST_F(AppMgrServiceInnerTest, VerifyProcessPermission_001, TestSize.Level0) +HWTEST_F(AppMgrServiceInnerTest, VerifyKillProcessPermission_001, TestSize.Level0) { - TAG_LOGI(AAFwkTag::TEST, "VerifyProcessPermission_001 start"); + TAG_LOGI(AAFwkTag::TEST, "VerifyKillProcessPermission_001 start"); auto appMgrServiceInner = std::make_shared(); EXPECT_NE(appMgrServiceInner, nullptr); - appMgrServiceInner->VerifyProcessPermission(""); + appMgrServiceInner->VerifyKillProcessPermission(""); appMgrServiceInner->appRunningManager_ = nullptr; - appMgrServiceInner->VerifyProcessPermission(""); + appMgrServiceInner->VerifyKillProcessPermission(""); - TAG_LOGI(AAFwkTag::TEST, "VerifyProcessPermission_001 end"); + TAG_LOGI(AAFwkTag::TEST, "VerifyKillProcessPermission_001 end"); } /** From d0a25be4c60fd6ef7cf96070631d7ba6bb9f101f Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Sat, 29 Jun 2024 11:00:03 +0800 Subject: [PATCH 112/148] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- test/unittest/ability_scheduler_proxy_test/BUILD.gn | 1 + test/unittest/data_ability_record_test/BUILD.gn | 1 + test/unittest/mission_listener_proxy_test/BUILD.gn | 1 + test/unittest/pending_want_record_test/BUILD.gn | 1 + test/unittest/remote_mission_listener_proxy_test/BUILD.gn | 1 + test/unittest/want_receiver_proxy_test/BUILD.gn | 1 + test/unittest/want_sender_proxy_test/BUILD.gn | 1 + test/unittest/want_sender_stub_test/BUILD.gn | 1 + 8 files changed, 8 insertions(+) diff --git a/test/unittest/ability_scheduler_proxy_test/BUILD.gn b/test/unittest/ability_scheduler_proxy_test/BUILD.gn index 32b8e84667..56595beb00 100644 --- a/test/unittest/ability_scheduler_proxy_test/BUILD.gn +++ b/test/unittest/ability_scheduler_proxy_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("ability_scheduler_proxy_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/data_ability_record_test/BUILD.gn b/test/unittest/data_ability_record_test/BUILD.gn index b0e7a34721..229e712f82 100644 --- a/test/unittest/data_ability_record_test/BUILD.gn +++ b/test/unittest/data_ability_record_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("data_ability_record_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/mission_listener_proxy_test/BUILD.gn b/test/unittest/mission_listener_proxy_test/BUILD.gn index 586d23d39b..a301cdf7ce 100755 --- a/test/unittest/mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/mission_listener_proxy_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("mission_listener_proxy_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/pending_want_record_test/BUILD.gn b/test/unittest/pending_want_record_test/BUILD.gn index fd639818d6..6db281af99 100644 --- a/test/unittest/pending_want_record_test/BUILD.gn +++ b/test/unittest/pending_want_record_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("pending_want_record_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn index fc84df01e6..661f9d8ddb 100755 --- a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("remote_mission_listener_proxy_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/want_receiver_proxy_test/BUILD.gn b/test/unittest/want_receiver_proxy_test/BUILD.gn index a5aef87d5b..b89a6d5b07 100644 --- a/test/unittest/want_receiver_proxy_test/BUILD.gn +++ b/test/unittest/want_receiver_proxy_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("want_receiver_proxy_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/want_sender_proxy_test/BUILD.gn b/test/unittest/want_sender_proxy_test/BUILD.gn index 02a82d91e4..be1d18fa25 100644 --- a/test/unittest/want_sender_proxy_test/BUILD.gn +++ b/test/unittest/want_sender_proxy_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("want_sender_proxy_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ diff --git a/test/unittest/want_sender_stub_test/BUILD.gn b/test/unittest/want_sender_stub_test/BUILD.gn index 02b0ea3f07..40b263aae9 100644 --- a/test/unittest/want_sender_stub_test/BUILD.gn +++ b/test/unittest/want_sender_stub_test/BUILD.gn @@ -22,6 +22,7 @@ ohos_unittest("want_sender_stub_test") { cfi = true cfi_cross_dso = true debug = false + blocklist = "../../cfi_blocklist.txt" } branch_protector_ret = "pac_ret" include_dirs = [ From 84d49b97855f15d12eaaffd7bbf03bf7586d9891 Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Sat, 29 Jun 2024 10:52:52 +0800 Subject: [PATCH 113/148] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8B=AC=E7=AB=8B?= =?UTF-8?q?=E6=B2=99=E7=AE=B1=E5=92=8C=E9=9A=94=E7=A6=BB=E6=8E=A7=E5=88=B6?= =?UTF-8?q?flag=E7=9A=84=E4=BC=A0=E9=80=92=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- services/appmgr/src/app_mgr_service_inner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c353c86558..94646ab318 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2755,15 +2755,15 @@ void AppMgrServiceInner::QueryExtensionSandBox(const std::string &moduleName, co extensionInfos.insert(extensionInfos.end(), hapModuleInfo.extensionInfos.begin(), hapModuleInfo.extensionInfos.end()); } - auto infoExisted = [&moduleName, &abilityName](const ExtensionAbilityInfo& info) { - return info.moduleName == moduleName && info.name == abilityName && info.needCreateSandbox; + startMsg.strictMode = strictMode; + auto infoExisted = [&moduleName, &abilityName, &strictMode](const ExtensionAbilityInfo& info) { + return info.moduleName == moduleName && info.name == abilityName && info.needCreateSandbox && strictMode; }; auto infoIter = std::find_if(extensionInfos.begin(), extensionInfos.end(), infoExisted); DataGroupInfoList extensionDataGroupInfoList; if (infoIter != extensionInfos.end()) { - startMsg.isolatedExtension = infoIter->needCreateSandbox; + startMsg.isolatedExtension = true; startMsg.extensionSandboxPath = infoIter->moduleName + "-" + infoIter->name; - startMsg.strictMode = strictMode; for (auto dataGroupInfo : dataGroupInfoList) { auto groupIdExisted = [&dataGroupInfo](const std::string &dataGroupId) { return dataGroupInfo.dataGroupId == dataGroupId; From c634faee53ce2f242c391b7bdd82acf7dacb3cda Mon Sep 17 00:00:00 2001 From: wangzhen Date: Sat, 29 Jun 2024 06:37:02 +0000 Subject: [PATCH 114/148] Revert "Correct mistakes in recent pr" This reverts commit 3f0f17aec2807c012ddfbe5759a59b81b27f76ed. Signed-off-by: wangzhen --- frameworks/native/ability/native/BUILD.gn | 62 +------------------ .../native/free_install_observer_proxy.cpp | 5 -- interfaces/inner_api/ability_manager/BUILD.gn | 1 - .../include/free_install_observer_interface.h | 2 - services/abilitymgr/BUILD.gn | 1 - .../abilitymgr/include/ability_service_util.h | 2 +- .../abilitymgr/src/ability_manager_stub.cpp | 2 +- .../interceptor/ability_jump_interceptor.cpp | 2 +- .../src/interceptor/control_interceptor.cpp | 2 +- .../interceptor/disposed_rule_interceptor.cpp | 2 +- .../src/system_dialog_scheduler.cpp | 4 +- 11 files changed, 10 insertions(+), 75 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 97f5d3c6ad..6b00f2fd30 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -184,61 +184,6 @@ ohos_shared_library("abilitykit_utils") { part_name = "ability_runtime" } -ohos_shared_library("free_install_observer") { - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - cfi_vcall_icall_only = true - debug = false - } - branch_protector_ret = "pac_ret" - - include_dirs = [ - "${ability_runtime_innerkits_path}/ability_manager/include", - "${ability_runtime_path}/interfaces/kits/native/ability/native", - "${ability_runtime_services_path}/common/include", - ] - - defines = [] - if (ability_runtime_graphics) { - defines += [ - "SUPPORT_GRAPHICS", - "SUPPORT_SCREEN", - ] - } - - if (target_cpu == "arm64") { - defines += [ "APP_USE_ARM64" ] - } else if (target_cpu == "arm") { - defines += [ "APP_USE_ARM" ] - } else if (target_cpu == "x86_64") { - defines += [ "APP_USE_X86_64" ] - } - - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - - sources = [ - "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", - "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", - ] - - external_deps = [ - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - ] - - innerapi_tags = [ "platformsdk" ] - subsystem_name = "ability" - part_name = "ability_runtime" -} - ohos_shared_library("abilitykit_native") { include_dirs = [ "${ability_runtime_path}/utils/global/time/include" ] @@ -262,6 +207,8 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/data_ability_helper_impl.cpp", "${ability_runtime_native_path}/ability/native/data_ability_impl.cpp", "${ability_runtime_native_path}/ability/native/data_uri_utils.cpp", + "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", + "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", "${ability_runtime_native_path}/ability/native/insight_intent_host_client.cpp", "${ability_runtime_native_path}/ability/native/js_free_install_observer.cpp", "${ability_runtime_native_path}/ability/native/new_ability_impl.cpp", @@ -282,7 +229,6 @@ ohos_shared_library("abilitykit_native") { deps = [ ":continuation_ipc", ":extension_blocklist_config", - ":free_install_observer", "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", @@ -1340,9 +1286,7 @@ ohos_shared_library("auto_startup_callback") { "${ability_runtime_native_path}/ability/native/auto_startup_callback_stub.cpp", ] - deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager_base", - ] + deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager" ] configs = [ "${ability_runtime_services_path}/common:common_config" ] diff --git a/frameworks/native/ability/native/free_install_observer_proxy.cpp b/frameworks/native/ability/native/free_install_observer_proxy.cpp index 0639e07700..097e807698 100644 --- a/frameworks/native/ability/native/free_install_observer_proxy.cpp +++ b/frameworks/native/ability/native/free_install_observer_proxy.cpp @@ -63,10 +63,5 @@ void FreeInstallObserverProxy::OnInstallFinished(const std::string &bundleName, return; } } - -sptr BuildFreeInstallObserver(sptr remoteObject) -{ - return iface_cast(remoteObject); -} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 8c51078db6..2b5c335327 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -172,7 +172,6 @@ ohos_shared_library("ability_manager") { "${ability_runtime_native_path}/ability/native/task_handler_client.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_client.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_client.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ability_manager_collaborator_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_manager_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", diff --git a/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h b/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h index 004fe99d22..33de6df6b0 100644 --- a/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h +++ b/interfaces/inner_api/ability_manager/include/free_install_observer_interface.h @@ -40,8 +40,6 @@ public: ON_INSTALL_FINISHED = 1, }; }; - -sptr BuildFreeInstallObserver(sptr remoteObject); } // namespace AbilityRuntime } // namespace OHOS diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 73c8b63024..34df94b82c 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -117,7 +117,6 @@ ohos_shared_library("abilityms") { "${ability_runtime_innerkits_path}/session_handler:session_handler", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:auto_startup_callback", - "${ability_runtime_native_path}/ability/native:free_install_observer", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_path}/utils/server/startup:startup_util", diff --git a/services/abilitymgr/include/ability_service_util.h b/services/abilitymgr/include/ability_service_util.h index 6bf23591e4..9e946a4e50 100644 --- a/services/abilitymgr/include/ability_service_util.h +++ b/services/abilitymgr/include/ability_service_util.h @@ -42,7 +42,7 @@ constexpr const char* MARKET_CROWD_TEST_BUNDLE_PARAM = "crowd_test_bundle_name"; want.SetElementName(appGalleryBundleName, ""); want.SetAction(action); want.SetParam(MARKET_CROWD_TEST_BUNDLE_PARAM, bundleName); - return DelayedSingleton::GetInstance()->StartAbility(want, userId, requestCode); + return DelayedSingleton::GetInstance()->StartAbility(want, requestCode, userId); } } // namespace AbilityUtil } // namespace AAFwk diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 96819038ac..c802a2a7b0 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -2698,7 +2698,7 @@ int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, M int AbilityManagerStub::AddFreeInstallObserverInner(MessageParcel &data, MessageParcel &reply) { sptr observer = - AbilityRuntime::BuildFreeInstallObserver(data.ReadRemoteObject()); + iface_cast(data.ReadRemoteObject()); if (observer == nullptr) { TAG_LOGE(AAFwkTag::ABILITYMGR, "observer is nullptr"); return ERR_INVALID_VALUE; diff --git a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp index f6aadfcaaa..8b77ea4c59 100644 --- a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp @@ -76,7 +76,7 @@ ErrCode AbilityJumpInterceptor::DoProcess(AbilityInterceptorParam param) AbilityUtil::ParseJumpInterceptorWant(dialogWant, controlRule.callerPkg); LoadAppLabelInfo(dialogWant, controlRule, param.userId); int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility(dialogWant, - param.userId, param.requestCode)); + param.requestCode, param.userId)); if (ret != ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "appInterceptor Dialog StartAbility error, ret:%{public}d", ret); return ret; diff --git a/services/abilitymgr/src/interceptor/control_interceptor.cpp b/services/abilitymgr/src/interceptor/control_interceptor.cpp index ec7af704c1..7a88aadb91 100644 --- a/services/abilitymgr/src/interceptor/control_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/control_interceptor.cpp @@ -58,7 +58,7 @@ ErrCode ControlInterceptor::DoProcess(AbilityInterceptorParam param) controlRule.controlWant = controlWant; } int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *controlRule.controlWant, param.userId, param.requestCode)); + *controlRule.controlWant, param.requestCode, param.userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Control implicit start appgallery failed."); return ret; diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index 669369820a..7bac4f97b2 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -62,7 +62,7 @@ ErrCode DisposedRuleInterceptor::DoProcess(AbilityInterceptorParam param) SetInterceptInfo(param.want, disposedRule); if (disposedRule.componentType == AppExecFwk::ComponentType::UI_ABILITY) { int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *disposedRule.want, param.userId, param.requestCode)); + *disposedRule.want, param.requestCode, param.userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "DisposedRuleInterceptor start ability failed."); return ret; diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index e0b3b50cdb..9adc899c15 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -441,7 +441,7 @@ int SystemDialogScheduler::GetSelectorDialogWantCommon(const std::vector Date: Sat, 29 Jun 2024 14:57:20 +0800 Subject: [PATCH 115/148] Revert "Rearrange deps and compiling modules" This reverts commit d3cc5d599c8288f69f48963d623ea4344f77205b. Signed-off-by: wangzhen --- bundle.json | 8 - .../napi_common_ability.cpp | 2 +- frameworks/native/ability/native/BUILD.gn | 1 + .../distributed_client.cpp | 0 frameworks/native/appkit/app/main_thread.cpp | 4 +- interfaces/inner_api/ability_manager/BUILD.gn | 112 +---------- .../include/ability_first_frame_state_data.h | 1 + .../distributed_client.h | 0 .../distributed_parcel_helper.h | 0 services/abilitymgr/BUILD.gn | 12 +- services/abilitymgr/abilitymgr.gni | 12 +- .../abilitymgr/include/ability_service_util.h | 50 ----- services/abilitymgr/include/ability_util.h | 24 ++- services/abilitymgr/include/app_scheduler.h | 1 + .../ui_ability_lifecycle_manager.h | 3 - ...ity_first_frame_state_observer_manager.cpp | 1 - services/abilitymgr/src/ability_record.cpp | 5 +- .../abilitymgr/src/assert_fault_proxy.cpp | 23 +-- services/abilitymgr/src/disposed_observer.cpp | 5 +- .../interceptor/ability_jump_interceptor.cpp | 4 +- .../src/interceptor/control_interceptor.cpp | 6 +- .../interceptor/crowd_test_interceptor.cpp | 2 +- .../interceptor/disposed_rule_interceptor.cpp | 6 +- .../abilitymgr/src/pending_want_manager.cpp | 3 +- .../src/system_dialog_scheduler.cpp | 180 +++++++++--------- services/appmgr/BUILD.gn | 2 +- .../include/window_focus_changed_listener.h | 2 +- .../window_visibility_changed_listener.h | 2 +- services/appmgr/src/app_mgr_service_inner.cpp | 10 +- services/uripermmgr/BUILD.gn | 2 + test/fuzztest/startability_fuzzer/BUILD.gn | 1 - test/moduletest/ability_test/BUILD.gn | 1 - .../start_option_display_id_test/BUILD.gn | 1 - ...irst_frame_state_observer_manager_test.cpp | 1 - .../ability_interceptor_test.cpp | 1 + .../BUILD.gn | 1 - .../ability_manager_proxy_test/BUILD.gn | 1 - .../BUILD.gn | 2 - .../BUILD.gn | 1 - .../ability_manager_stub_test.cpp | 1 - test/unittest/ability_record_test/BUILD.gn | 1 - .../ability_record_test.cpp | 2 +- .../ams_ability_running_record_test/BUILD.gn | 2 +- test/unittest/ams_app_workflow_test/BUILD.gn | 2 +- .../ams_recent_app_list_test/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../ams_service_event_drive_test/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../ams_service_startup_test/BUILD.gn | 2 +- .../BUILD.gn | 2 +- .../app_mgr_service_inner_test.cpp | 2 +- .../BUILD.gn | 1 - .../BUILD.gn | 2 +- .../pending_want_record_test/BUILD.gn | 1 - test/unittest/sender_info_test/BUILD.gn | 1 - .../service_extension_context_test/BUILD.gn | 1 - .../start_option_display_id_test/BUILD.gn | 1 - test/unittest/start_options_test/BUILD.gn | 1 - test/unittest/trigger_Info_test/BUILD.gn | 1 - .../BUILD.gn | 1 - .../unittest/want_receiver_stub_test/BUILD.gn | 1 - test/unittest/want_sender_proxy_test/BUILD.gn | 1 - test/unittest/want_sender_stub_test/BUILD.gn | 1 - 63 files changed, 196 insertions(+), 332 deletions(-) rename {services/abilitymgr/src => frameworks/native/ability/native/distributed_ability_runtime}/distributed_client.cpp (100%) rename {services/abilitymgr/include => interfaces/kits/native/ability/native/distributed_ability_runtime}/distributed_client.h (100%) rename {services/abilitymgr/include => interfaces/kits/native/ability/native/distributed_ability_runtime}/distributed_parcel_helper.h (100%) delete mode 100644 services/abilitymgr/include/ability_service_util.h diff --git a/bundle.json b/bundle.json index da4a0f7565..379d7b2caf 100644 --- a/bundle.json +++ b/bundle.json @@ -457,14 +457,6 @@ ] }, "name": "//foundation/ability/ability_runtime/frameworks/native/ability/native:dialog_request_callback" - }, - { - "header": { - "header_base": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager/include", - "header_files": [ - ] - }, - "name": "//foundation/ability/ability_runtime/interfaces/inner_api/ability_manager:ability_manager_base" } ], "test": [ diff --git a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp index dc188d8af5..74adc1291a 100644 --- a/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp +++ b/frameworks/js/napi/inner/napi_ability_common/napi_common_ability.cpp @@ -21,8 +21,8 @@ #include #include "ability_util.h" -#include "ability_manager_client.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "js_napi_common_ability.h" #include "js_runtime_utils.h" #include "napi_common_ability_execute_utils.h" diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 6b00f2fd30..072c6b6aaf 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -207,6 +207,7 @@ ohos_shared_library("abilitykit_native") { "${ability_runtime_native_path}/ability/native/data_ability_helper_impl.cpp", "${ability_runtime_native_path}/ability/native/data_ability_impl.cpp", "${ability_runtime_native_path}/ability/native/data_uri_utils.cpp", + "${ability_runtime_native_path}/ability/native/distributed_ability_runtime/distributed_client.cpp", "${ability_runtime_native_path}/ability/native/free_install_observer_proxy.cpp", "${ability_runtime_native_path}/ability/native/free_install_observer_stub.cpp", "${ability_runtime_native_path}/ability/native/insight_intent_host_client.cpp", diff --git a/services/abilitymgr/src/distributed_client.cpp b/frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp similarity index 100% rename from services/abilitymgr/src/distributed_client.cpp rename to frameworks/native/ability/native/distributed_ability_runtime/distributed_client.cpp diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 118441082d..e5aee1878f 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -31,7 +31,6 @@ #include "ability_thread.h" #include "ability_util.h" #include "app_loader.h" -#include "ability_manager_client.h" #include "app_recovery.h" #include "app_utils.h" #include "appfreeze_inner.h" @@ -59,6 +58,7 @@ #include "file_path_utils.h" #include "freeze_util.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "resource_config_helper.h" #ifdef SUPPORT_SCREEN #include "locale_config.h" @@ -1602,7 +1602,7 @@ void MainThread::HandleLaunchApplication(const AppLaunchData &appLaunchData, con TAG_LOGI(AAFwkTag::APPKIT, "hisysevent write result=%{public}d, send event [FRAMEWORK,PROCESS_KILL]," " pid=%{public}d, processName=%{public}s, msg=%{public}s", result, pid, processName.c_str(), KILL_REASON); - + if (ApplicationDataManager::GetInstance().NotifyUnhandledException(summary) && ApplicationDataManager::GetInstance().NotifyExceptionObject(appExecErrorObj)) { return; diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 2b5c335327..f43c92b47a 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -29,6 +29,7 @@ config("ability_manager_public_config") { "${ability_runtime_path}/interfaces/kits/native/ability/native", "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits", "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed", + "${bundlefwk_inner_api_path}/appexecfwk_base/include", "${ability_runtime_innerkits_path}/ability_manager/include", "${ability_runtime_innerkits_path}/app_manager/include/appmgr", "${ability_runtime_path}/interfaces/kits/native/appkit/app", @@ -57,112 +58,6 @@ config("ability_manager_public_config") { } } -ohos_shared_library("ability_manager_base") { - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - cfi_vcall_icall_only = true - debug = false - } - branch_protector_ret = "pac_ret" - - include_dirs = [ - "${ability_runtime_innerkits_path}/ability_manager/include", - "${ability_runtime_innerkits_path}/ability_manager/include/status_bar_delegate", - "${ability_runtime_path}/interfaces/kits/native/ability/native", - "${ability_runtime_services_path}/abilitymgr/include", - "${ability_runtime_services_path}/common/include", - ] - - defines = [] - - if (ability_command_for_test) { - defines += [ "ABILITY_COMMAND_FOR_TEST" ] - } - - if (ability_runtime_graphics) { - defines += [ - "SUPPORT_GRAPHICS", - "SUPPORT_SCREEN", - ] - } - - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - - sources = [ - "${ability_runtime_native_path}/ability/native/data_ability_operation.cpp", - "${ability_runtime_native_path}/ability/native/data_ability_operation_builder.cpp", - "${ability_runtime_native_path}/ability/native/data_ability_result.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/dialog_session_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/exit_reason.cpp", - "${ability_runtime_services_path}/abilitymgr/src/extension_running_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_param.cpp", - "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp", - "${ability_runtime_services_path}/abilitymgr/src/launch_param.cpp", - "${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/mission_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/open_link/open_link_options.cpp", - "${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/remote_on_listener_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/sender_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ui_extension_ability_connect_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/ui_extension_host_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", - "${ability_runtime_services_path}/abilitymgr/src/want_sender_info.cpp", - "${ability_runtime_services_path}/abilitymgr/src/wants_info.cpp", - "src/status_bar_delegate/status_bar_delegate_proxy.cpp", - ] - - if (ability_runtime_graphics) { - sources += [ - "src/ability_first_frame_state_data.cpp", - "src/ability_first_frame_state_observer_proxy.cpp", - ] - } - - deps = [ - ":ability_start_options", - ":ability_start_setting", - ] - - external_deps = [ - "ability_base:base", - "bundle_framework:appexecfwk_base", - "bundle_framework:libappexecfwk_common", - "c_utils:utils", - "hilog:libhilog", - "hitrace:hitrace_meter", - "ipc:ipc_core", - ] - - public_external_deps = [ - "ability_base:configuration", - "ability_base:want", - "ability_base:zuri", - "bundle_framework:appexecfwk_core", - "relational_store:native_dataability", - "relational_store:native_rdb", - ] - - innerapi_tags = [ - "platformsdk", - "sasdk", - ] - subsystem_name = "ability" - part_name = "ability_runtime" -} - ohos_shared_library("ability_manager") { sources = [ "${ability_runtime_native_path}/ability/native/data_ability_operation.cpp", @@ -175,12 +70,14 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/ability_manager_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_running_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/ability_scheduler_stub.cpp", + "${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/acquire_share_data_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/caller_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/dialog_session_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/exit_reason.cpp", "${ability_runtime_services_path}/abilitymgr/src/extension_running_info.cpp", + "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_param.cpp", "${ability_runtime_services_path}/abilitymgr/src/insight_intent_execute_result.cpp", @@ -188,6 +85,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/lifecycle_state_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/mission_listener_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/open_link/open_link_options.cpp", + "${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/prepare_terminate_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_mission_listener_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/remote_on_listener_proxy.cpp", @@ -203,6 +101,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/want_sender_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/want_sender_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/wants_info.cpp", + "src/status_bar_delegate/status_bar_delegate_proxy.cpp", "src/status_bar_delegate/status_bar_delegate_stub.cpp", "src/window_manager_service_handler_proxy.cpp", "src/window_manager_service_handler_stub.cpp", @@ -211,6 +110,7 @@ ohos_shared_library("ability_manager") { if (ability_runtime_graphics) { sources += [ "src/ability_first_frame_state_data.cpp", + "src/ability_first_frame_state_observer_proxy.cpp", "src/ability_first_frame_state_observer_stub.cpp", ] } diff --git a/interfaces/inner_api/ability_manager/include/ability_first_frame_state_data.h b/interfaces/inner_api/ability_manager/include/ability_first_frame_state_data.h index 59f86d7d68..f1b32351c6 100644 --- a/interfaces/inner_api/ability_manager/include/ability_first_frame_state_data.h +++ b/interfaces/inner_api/ability_manager/include/ability_first_frame_state_data.h @@ -20,6 +20,7 @@ #include #include "parcel.h" +#include "app_mgr_constants.h" #include "iremote_object.h" namespace OHOS { diff --git a/services/abilitymgr/include/distributed_client.h b/interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_client.h similarity index 100% rename from services/abilitymgr/include/distributed_client.h rename to interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_client.h diff --git a/services/abilitymgr/include/distributed_parcel_helper.h b/interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_parcel_helper.h similarity index 100% rename from services/abilitymgr/include/distributed_parcel_helper.h rename to interfaces/kits/native/ability/native/distributed_ability_runtime/distributed_parcel_helper.h diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 34df94b82c..5aeef4ad1d 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -106,7 +106,7 @@ ohos_shared_library("abilityms") { ] include_dirs = [ "${ability_runtime_services_path}/appdfr/include" ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager_base", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/ability_manager:mission_info", @@ -116,6 +116,7 @@ ohos_shared_library("abilityms") { "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_innerkits_path}/session_handler:session_handler", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:auto_startup_callback", "${ability_runtime_native_path}/appkit:appkit_manager_helper", "${ability_runtime_path}/utils/global/freeze:freeze_util", @@ -130,6 +131,7 @@ ohos_shared_library("abilityms") { external_deps = [ "ability_base:base", "ability_base:configuration", + "ability_base:extractortool", "ability_base:session_info", "ability_base:view_data", "ability_base:want", @@ -140,6 +142,7 @@ ohos_shared_library("abilityms") { "bundle_framework:appexecfwk_core", "bundle_framework:libappexecfwk_common", "c_utils:utils", + "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "config_policy:configpolicy_util", "dsoftbus:softbus_client", @@ -161,7 +164,11 @@ ohos_shared_library("abilityms") { "relational_store:native_rdb", "safwk:system_ability_fwk", "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + "window_manager:libwsutils", + "window_manager:scene_session", "window_manager:session_manager_lite", + "window_manager:sms", ] public_external_deps = [ "background_task_mgr:bgtaskmgr_innerkits" ] @@ -185,7 +192,10 @@ ohos_shared_library("abilityms") { external_deps += [ "ability_base:session_info", "i18n:intl_util", + "icu:shared_icuuc", "image_framework:image_native", + "input:libmmi-client", + "resource_management:global_resmgr", "screenlock_mgr:screenlock_client", "window_manager:libdm", "window_manager:libmodal_system_ui_extension_client", diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index c8fecb97fd..37afe7c10a 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -37,12 +37,19 @@ abilityms_files = [ "src/data_ability_record.cpp", "src/dialog_session_record.cpp", "src/lifecycle_deal.cpp", + "src/ability_running_info.cpp", "src/ecological_rule/ability_ecological_rule_mgr_service_param.cpp", "src/ecological_rule/ability_ecological_rule_mgr_service.cpp", "src/extension_config.cpp", + "src/extension_running_info.cpp", + "src/caller_info.cpp", + "src/sender_info.cpp", "src/sub_managers_helper.cpp", + "src/wants_info.cpp", + "src/want_sender_info.cpp", "src/pending_want_record.cpp", "src/want_receiver_proxy.cpp", + "src/want_sender_proxy.cpp", "src/want_sender_stub.cpp", "src/pending_want_key.cpp", "src/pending_want_manager.cpp", @@ -79,6 +86,8 @@ abilityms_files = [ "src/ui_extension_record.cpp", "src/ui_extension_record_factory.cpp", "src/screen_lock/unlock_screen_manager.cpp", + "src/start_options.cpp", + "src/user_callback_proxy.cpp", "src/call_container.cpp", "src/call_record.cpp", "src/inner_mission_info.cpp", @@ -114,7 +123,6 @@ abilityms_files = [ "src/atomic_service_status_callback.cpp", "src/free_install_manager.cpp", "src/free_install_observer_manager.cpp", - "src/distributed_client.cpp", "src/background_task_observer.cpp", "src/resident_process_manager.cpp", @@ -126,7 +134,9 @@ abilityms_files = [ "src/ability_auto_startup_data_manager.cpp", "src/ability_auto_startup_service.cpp", + "src/auto_startup_info.cpp", "src/insight_intent_execute_manager.cpp", + "src/insight_intent_execute_result.cpp", "src/ability_manager_event_subscriber.cpp", diff --git a/services/abilitymgr/include/ability_service_util.h b/services/abilitymgr/include/ability_service_util.h deleted file mode 100644 index 9e946a4e50..0000000000 --- a/services/abilitymgr/include/ability_service_util.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_ABILITY_RUNTIME_ABILITY_SERVICE_UTIL_H -#define OHOS_ABILITY_RUNTIME_ABILITY_SERVICE_UTIL_H - -#include "ability_manager_service.h" -#include "bundle_mgr_helper.h" -#include "hilog_tag_wrapper.h" - -namespace OHOS { -namespace AAFwk { -namespace AbilityUtil { -constexpr const char* MARKET_BUNDLE_NAME = "com.huawei.hmsapp.appgallery"; -constexpr const char* MARKET_CROWD_TEST_BUNDLE_PARAM = "crowd_test_bundle_name"; - -[[maybe_unused]] static int StartAppgallery(const std::string &bundleName, const int requestCode, const int32_t userId, - const std::string &action) -{ - std::string appGalleryBundleName; - auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); - if (bundleMgrHelper == nullptr || !bundleMgrHelper->QueryAppGalleryBundleName(appGalleryBundleName)) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Get bundle manager helper failed or QueryAppGalleryBundleName failed."); - appGalleryBundleName = MARKET_BUNDLE_NAME; - } - - TAG_LOGD(AAFwkTag::ABILITYMGR, "appGalleryBundleName:%{public}s", appGalleryBundleName.c_str()); - - Want want; - want.SetElementName(appGalleryBundleName, ""); - want.SetAction(action); - want.SetParam(MARKET_CROWD_TEST_BUNDLE_PARAM, bundleName); - return DelayedSingleton::GetInstance()->StartAbility(want, requestCode, userId); -} -} // namespace AbilityUtil -} // namespace AAFwk -} // namespace OHOS -#endif \ No newline at end of file diff --git a/services/abilitymgr/include/ability_util.h b/services/abilitymgr/include/ability_util.h index 5097d4770f..b8abf0a737 100644 --- a/services/abilitymgr/include/ability_util.h +++ b/services/abilitymgr/include/ability_util.h @@ -20,11 +20,12 @@ #include #include "ability_config.h" +#include "ability_manager_client.h" #include "ability_manager_errors.h" -#include "ability_window_configuration.h" #include "app_jump_control_rule.h" #include "bundle_mgr_helper.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "in_process_call_wrapper.h" #include "ipc_skeleton.h" #include "permission_verification.h" @@ -44,6 +45,8 @@ constexpr const char* DLP_PARAMS_SANDBOX = "ohos.dlp.params.sandbox"; constexpr const char* DLP_PARAMS_BUNDLE_NAME = "ohos.dlp.params.bundleName"; constexpr const char* DLP_PARAMS_MODULE_NAME = "ohos.dlp.params.moduleName"; constexpr const char* DLP_PARAMS_ABILITY_NAME = "ohos.dlp.params.abilityName"; +constexpr const char* MARKET_BUNDLE_NAME = "com.huawei.hmsapp.appgallery"; +constexpr const char* MARKET_CROWD_TEST_BUNDLE_PARAM = "crowd_test_bundle_name"; constexpr const char* BUNDLE_NAME_SELECTOR_DIALOG = "com.ohos.amsdialog"; constexpr const char* JUMP_INTERCEPTOR_DIALOG_CALLER_PKG = "interceptor_callerPkg"; @@ -320,6 +323,25 @@ static constexpr int64_t MICROSECONDS = 1000000; // MICROSECONDS mean 10^6 mi } } +[[maybe_unused]] static int StartAppgallery(const std::string &bundleName, const int requestCode, const int32_t userId, + const std::string &action) +{ + std::string appGalleryBundleName; + auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); + if (bundleMgrHelper == nullptr || !bundleMgrHelper->QueryAppGalleryBundleName(appGalleryBundleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get bundle manager helper failed or QueryAppGalleryBundleName failed."); + appGalleryBundleName = MARKET_BUNDLE_NAME; + } + + TAG_LOGD(AAFwkTag::ABILITYMGR, "appGalleryBundleName:%{public}s", appGalleryBundleName.c_str()); + + Want want; + want.SetElementName(appGalleryBundleName, ""); + want.SetAction(action); + want.SetParam(MARKET_CROWD_TEST_BUNDLE_PARAM, bundleName); + return AbilityManagerClient::GetInstance()->StartAbility(want, requestCode, userId); +} + inline ErrCode EdmErrorType(bool isEdm) { if (isEdm) { diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 650fd973b0..b3c0f98d6e 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -21,6 +21,7 @@ #include "ability_debug_response_interface.h" #include "ability_info.h" +#include "ability_manager_client.h" #include "app_debug_listener_interface.h" #include "application_info.h" #include "appmgr/app_mgr_client.h" diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index eafc34b6c8..0110e3f3e4 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -28,9 +28,6 @@ #include "isession_handler_interface.h" namespace OHOS { -namespace AbilityRuntime { -class IStatusBarDelegate; -} namespace AAFwk { class SessionInfo; class StatusBarDelegateManager; diff --git a/services/abilitymgr/src/ability_first_frame_state_observer_manager.cpp b/services/abilitymgr/src/ability_first_frame_state_observer_manager.cpp index 4bb65a6ddd..b3fef29578 100644 --- a/services/abilitymgr/src/ability_first_frame_state_observer_manager.cpp +++ b/services/abilitymgr/src/ability_first_frame_state_observer_manager.cpp @@ -18,7 +18,6 @@ #include "ability_first_frame_state_data.h" #include "ability_first_frame_state_observer_stub.h" -#include "ability_manager_errors.h" #include "application_info.h" #include "hilog_tag_wrapper.h" #include "permission_verification.h" diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index a9ee71c9c8..b58772a0c0 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -20,6 +20,7 @@ #include #include +#include "constants.h" #include "ability_event_handler.h" #include "ability_manager_service.h" #include "ability_resident_process_rdb.h" @@ -45,6 +46,7 @@ #include "errors.h" #include "event_report.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "os_account_manager_wrapper.h" #include "parameters.h" #include "res_sched_util.h" @@ -2231,8 +2233,7 @@ void AbilityRecord::DumpUIExtensionRootHostInfo(std::vector &info) } UIExtensionHostInfo hostInfo; - auto ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->GetUIExtensionRootHostInfo( - token, hostInfo)); + auto ret = IN_PROCESS_CALL(AAFwk::AbilityManagerClient::GetInstance()->GetUIExtensionRootHostInfo(token, hostInfo)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Get ui extension host info failed with %{public}d.", ret); return; diff --git a/services/abilitymgr/src/assert_fault_proxy.cpp b/services/abilitymgr/src/assert_fault_proxy.cpp index d214333416..448d410eda 100644 --- a/services/abilitymgr/src/assert_fault_proxy.cpp +++ b/services/abilitymgr/src/assert_fault_proxy.cpp @@ -12,17 +12,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "ability_manager_service.h" +#include "ability_manager_client.h" #include "assert_fault_proxy.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "scene_board_judgement.h" #include "task_handler_wrap.h" namespace OHOS { namespace AbilityRuntime { namespace { -constexpr const char* ASSERT_FAULT_DETAIL = "assertFaultDialogDetail"; -constexpr const char* UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; +constexpr char ASSERT_FAULT_DETAIL[] = "assertFaultDialogDetail"; +constexpr char UIEXTENSION_TYPE_KEY[] = "ability.want.params.uiExtensionType"; constexpr int32_t INVALID_USERID = -1; constexpr int32_t MESSAGE_PARCEL_KEY_SIZE = 3; constexpr uint32_t COMMAND_START_DIALOG = 1; @@ -109,9 +110,9 @@ bool ModalSystemAssertUIExtension::CreateModalUIExtension(const AAFwk::Want &wan return false; } callback->SetReqeustAssertDialogWant(want); - auto abilityMs = DelayedSingleton::GetInstance(); - if (abilityMs == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "ConnectSystemUi abilityMs is nullptr"); + auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); + if (abilityManagerClient == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "ConnectSystemUi AbilityManagerClient is nullptr"); TryNotifyOneWaitingThread(); return false; } @@ -121,7 +122,7 @@ bool ModalSystemAssertUIExtension::CreateModalUIExtension(const AAFwk::Want &wan } else { systemUIWant.SetElementName("com.ohos.systemui", "com.ohos.systemui.dialog"); } - auto result = abilityMs->ConnectAbility(systemUIWant, callback, nullptr, INVALID_USERID); + auto result = abilityManagerClient->ConnectAbility(systemUIWant, callback, INVALID_USERID); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ConnectSystemUi ConnectAbility dialog failed, result = %{public}d", result); TryNotifyOneWaitingThread(); @@ -135,9 +136,9 @@ bool ModalSystemAssertUIExtension::DisconnectSystemUI() TAG_LOGD(AAFwkTag::ABILITYMGR, "Called."); bool retVal = true; do { - auto abilityMs = DelayedSingleton::GetInstance(); - if (abilityMs == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityMs is nullptr"); + auto abilityManagerClient = AAFwk::AbilityManagerClient::GetInstance(); + if (abilityManagerClient == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerClient is nullptr"); retVal = false; break; } @@ -147,7 +148,7 @@ bool ModalSystemAssertUIExtension::DisconnectSystemUI() retVal = false; break; } - auto result = abilityMs->DisconnectAbility(callback); + auto result = abilityManagerClient->DisconnectAbility(callback); if (result != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "DisconnectAbility dialog failed, result = %{public}d", result); retVal = false; diff --git a/services/abilitymgr/src/disposed_observer.cpp b/services/abilitymgr/src/disposed_observer.cpp index 96b3616dca..4294e40e0e 100644 --- a/services/abilitymgr/src/disposed_observer.cpp +++ b/services/abilitymgr/src/disposed_observer.cpp @@ -15,10 +15,10 @@ #include "disposed_observer.h" -#include "ability_manager_service.h" #include "interceptor/disposed_rule_interceptor.h" #include "ability_record.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "modal_system_ui_extension.h" #include "want.h" namespace OHOS { @@ -56,8 +56,7 @@ void DisposedObserver::OnPageShow(const AppExecFwk::PageStateData &pageStateData { TAG_LOGD(AAFwkTag::ABILITYMGR, "Call"); if (disposedRule_.componentType == AppExecFwk::ComponentType::UI_ABILITY) { - int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *disposedRule_.want)); + int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*disposedRule_.want)); if (ret != ERR_OK) { interceptor_->UnregisterObserver(pageStateData.bundleName); TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to start disposed ability"); diff --git a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp index 8b77ea4c59..6de7371132 100644 --- a/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/ability_jump_interceptor.cpp @@ -15,11 +15,11 @@ #include "interceptor/ability_jump_interceptor.h" -#include "ability_manager_service.h" #include "ability_util.h" #include "accesstoken_kit.h" #include "app_jump_control_rule.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "permission_constants.h" @@ -75,7 +75,7 @@ ErrCode AbilityJumpInterceptor::DoProcess(AbilityInterceptorParam param) Want dialogWant = sysDialogScheduler->GetJumpInterceptorDialogWant(targetWant); AbilityUtil::ParseJumpInterceptorWant(dialogWant, controlRule.callerPkg); LoadAppLabelInfo(dialogWant, controlRule, param.userId); - int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility(dialogWant, + int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(dialogWant, param.requestCode, param.userId)); if (ret != ERR_OK) { TAG_LOGI(AAFwkTag::ABILITYMGR, "appInterceptor Dialog StartAbility error, ret:%{public}d", ret); diff --git a/services/abilitymgr/src/interceptor/control_interceptor.cpp b/services/abilitymgr/src/interceptor/control_interceptor.cpp index 7a88aadb91..2641a04fdd 100644 --- a/services/abilitymgr/src/interceptor/control_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/control_interceptor.cpp @@ -15,10 +15,10 @@ #include "interceptor/control_interceptor.h" -#include "ability_manager_service.h" #include "ability_util.h" #include "app_running_control_rule_result.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "want_params_wrapper.h" @@ -57,8 +57,8 @@ ErrCode ControlInterceptor::DoProcess(AbilityInterceptorParam param) controlWant->SetParam(INTERCEPT_MODULE_NAME, param.want.GetElement().GetModuleName()); controlRule.controlWant = controlWant; } - int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *controlRule.controlWant, param.requestCode, param.userId)); + int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*controlRule.controlWant, + param.requestCode, param.userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Control implicit start appgallery failed."); return ret; diff --git a/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp b/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp index 1f699e965f..e874f343c3 100644 --- a/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/crowd_test_interceptor.cpp @@ -16,8 +16,8 @@ #include "interceptor/crowd_test_interceptor.h" #include "ability_util.h" -#include "ability_service_util.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "in_process_call_wrapper.h" #include "start_ability_utils.h" diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index 7bac4f97b2..16a6b38728 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -15,10 +15,10 @@ #include "interceptor/disposed_rule_interceptor.h" -#include "ability_manager_service.h" #include "ability_record.h" #include "ability_util.h" #include "hilog_tag_wrapper.h" +#include "hilog_wrapper.h" #include "hitrace_meter.h" #include "in_process_call_wrapper.h" #include "iservice_registry.h" @@ -61,8 +61,8 @@ ErrCode DisposedRuleInterceptor::DoProcess(AbilityInterceptorParam param) } SetInterceptInfo(param.want, disposedRule); if (disposedRule.componentType == AppExecFwk::ComponentType::UI_ABILITY) { - int ret = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->StartAbility( - *disposedRule.want, param.requestCode, param.userId)); + int ret = IN_PROCESS_CALL(AbilityManagerClient::GetInstance()->StartAbility(*disposedRule.want, + param.requestCode, param.userId)); if (ret != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "DisposedRuleInterceptor start ability failed."); return ret; diff --git a/services/abilitymgr/src/pending_want_manager.cpp b/services/abilitymgr/src/pending_want_manager.cpp index 4262988431..f40caa2286 100644 --- a/services/abilitymgr/src/pending_want_manager.cpp +++ b/services/abilitymgr/src/pending_want_manager.cpp @@ -21,7 +21,6 @@ #include "ability_manager_service.h" #include "ability_util.h" -#include "common_event_manager.h" #include "distributed_client.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" @@ -335,7 +334,7 @@ int32_t PendingWantManager::PendingWantPublishCommonEvent( eventPublishData.SetSubscriberPermissions(permissions); } - bool result = IN_PROCESS_CALL(CommonEventManager::PublishCommonEvent( + bool result = IN_PROCESS_CALL(DelayedSingleton::GetInstance()->PublishCommonEvent( eventData, eventPublishData, nullptr, callerUid, callerTokenId)); return ((result == true) ? ERR_OK : (-1)); } diff --git a/services/abilitymgr/src/system_dialog_scheduler.cpp b/services/abilitymgr/src/system_dialog_scheduler.cpp index 9adc899c15..b2c21b78d4 100644 --- a/services/abilitymgr/src/system_dialog_scheduler.cpp +++ b/services/abilitymgr/src/system_dialog_scheduler.cpp @@ -19,6 +19,7 @@ #include "app_utils.h" #include "display_info.h" +#include "constants.h" #include "ability_record.h" #include "ability_util.h" #include "app_gallery_enable_util.h" @@ -38,99 +39,98 @@ namespace OHOS { namespace AAFwk { -constexpr int32_t UI_SELECTOR_DIALOG_WIDTH = 328 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_HEIGHT = 350 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_HEIGHT_NARROW = 350 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_WIDTH_NARROW = 328 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PHONE_H1 = 240 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PHONE_H2 = 340 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PHONE_H3 = 350 * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PC_H0 = 1; -constexpr int32_t UI_SELECTOR_DIALOG_PC_H2 = (64 * 2 + 56 + 48 + 54 + 64 + 48 + 2) * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PC_H3 = (64 * 3 + 56 + 48 + 54 + 64 + 48 + 2) * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PC_H4 = (64 * 4 + 56 + 48 + 54 + 64 + 48 + 2) * 2; -constexpr int32_t UI_SELECTOR_DIALOG_PC_H5 = (64 * 4 + 56 + 48 + 54 + 64 + 48 + 58 + 2) * 2; +const int32_t UI_SELECTOR_DIALOG_WIDTH = 328 * 2; +const int32_t UI_SELECTOR_DIALOG_HEIGHT = 350 * 2; +const int32_t UI_SELECTOR_DIALOG_HEIGHT_NARROW = 350 * 2; +const int32_t UI_SELECTOR_DIALOG_WIDTH_NARROW = 328 * 2; +const int32_t UI_SELECTOR_DIALOG_PHONE_H1 = 240 * 2; +const int32_t UI_SELECTOR_DIALOG_PHONE_H2 = 340 * 2; +const int32_t UI_SELECTOR_DIALOG_PHONE_H3 = 350 * 2; +const int32_t UI_SELECTOR_DIALOG_PC_H0 = 1; +const int32_t UI_SELECTOR_DIALOG_PC_H2 = (64 * 2 + 56 + 48 + 54 + 64 + 48 + 2) * 2; +const int32_t UI_SELECTOR_DIALOG_PC_H3 = (64 * 3 + 56 + 48 + 54 + 64 + 48 + 2) * 2; +const int32_t UI_SELECTOR_DIALOG_PC_H4 = (64 * 4 + 56 + 48 + 54 + 64 + 48 + 2) * 2; +const int32_t UI_SELECTOR_DIALOG_PC_H5 = (64 * 4 + 56 + 48 + 54 + 64 + 48 + 58 + 2) * 2; -constexpr int32_t UI_SELECTOR_PORTRAIT_PHONE_H1 = 280; -constexpr int32_t UI_SELECTOR_PORTRAIT_PHONE_H2 = 400; -constexpr int32_t UI_SELECTOR_PORTRAIT_PHONE_H3 = 410; -constexpr int32_t UI_SELECTOR_LANDSCAPE_SIGNAL_BAR = 24; -constexpr int32_t UI_SELECTOR_LANDSCAPE_HEIGHT = 350; -constexpr int32_t UI_SELECTOR_LANDSCAPE_HEIGHT_NARROW = 350; -constexpr int32_t UI_SELECTOR_LANDSCAPE_PHONE_H1 = 280; -constexpr int32_t UI_SELECTOR_LANDSCAPE_PHONE_H2 = 400; -constexpr int32_t UI_SELECTOR_LANDSCAPE_PHONE_H3 = 410; -constexpr int32_t UI_SELECTOR_LANDSCAPE_COUNT_THREE = 3; -constexpr int32_t UI_SELECTOR_LANDSCAPE_COUNT_FOUR = 4; -constexpr float UI_SELECTOR_LANDSCAPE_GRILLE_LARGE = 0.107692; -constexpr float UI_SELECTOR_LANDSCAPE_GRILLE_SAMLL = 0.015385; -constexpr float UI_SELECTOR_LANDSCAPE_MAX_RATIO = 0.9; -constexpr float UI_SELECTOR_PORTRAIT_WIDTH_RATIO = 0.8; -constexpr float UI_SELECTOR_PORTRAIT_WIDTH_EDGE_RATIO = 0.1; -constexpr float UI_SELECTOR_PORTRAIT_HEIGHT_RATIO = 0.98; +const int32_t UI_SELECTOR_PORTRAIT_PHONE_H1 = 280; +const int32_t UI_SELECTOR_PORTRAIT_PHONE_H2 = 400; +const int32_t UI_SELECTOR_PORTRAIT_PHONE_H3 = 410; +const int32_t UI_SELECTOR_LANDSCAPE_SIGNAL_BAR = 24; +const int32_t UI_SELECTOR_LANDSCAPE_HEIGHT = 350; +const int32_t UI_SELECTOR_LANDSCAPE_HEIGHT_NARROW = 350; +const int32_t UI_SELECTOR_LANDSCAPE_PHONE_H1 = 280; +const int32_t UI_SELECTOR_LANDSCAPE_PHONE_H2 = 400; +const int32_t UI_SELECTOR_LANDSCAPE_PHONE_H3 = 410; +const int32_t UI_SELECTOR_LANDSCAPE_COUNT_THREE = 3; +const int32_t UI_SELECTOR_LANDSCAPE_COUNT_FOUR = 4; +const float UI_SELECTOR_LANDSCAPE_GRILLE_LARGE = 0.107692; +const float UI_SELECTOR_LANDSCAPE_GRILLE_SAMLL = 0.015385; +const float UI_SELECTOR_LANDSCAPE_MAX_RATIO = 0.9; +const float UI_SELECTOR_PORTRAIT_WIDTH_RATIO = 0.8; +const float UI_SELECTOR_PORTRAIT_WIDTH_EDGE_RATIO = 0.1; +const float UI_SELECTOR_PORTRAIT_HEIGHT_RATIO = 0.98; -constexpr int32_t UI_TIPS_DIALOG_WIDTH = 328 * 2; -constexpr int32_t UI_TIPS_DIALOG_HEIGHT = 135 * 2; -constexpr int32_t UI_TIPS_DIALOG_HEIGHT_NARROW = 135 * 2; -constexpr int32_t UI_TIPS_DIALOG_WIDTH_NARROW = 328 * 2; +const int32_t UI_TIPS_DIALOG_WIDTH = 328 * 2; +const int32_t UI_TIPS_DIALOG_HEIGHT = 135 * 2; +const int32_t UI_TIPS_DIALOG_HEIGHT_NARROW = 135 * 2; +const int32_t UI_TIPS_DIALOG_WIDTH_NARROW = 328 * 2; -constexpr int32_t UI_JUMP_INTERCEPTOR_DIALOG_WIDTH = 328 * 2; -constexpr int32_t UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT = 135 * 2; -constexpr int32_t UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT_NARROW = 135 * 2; -constexpr int32_t UI_JUMP_INTERCEPTOR_DIALOG_WIDTH_NARROW = 328 * 2; +const int32_t UI_JUMP_INTERCEPTOR_DIALOG_WIDTH = 328 * 2; +const int32_t UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT = 135 * 2; +const int32_t UI_JUMP_INTERCEPTOR_DIALOG_HEIGHT_NARROW = 135 * 2; +const int32_t UI_JUMP_INTERCEPTOR_DIALOG_WIDTH_NARROW = 328 * 2; -constexpr int32_t UI_DIALOG_WIDTH = 328 * 2; -constexpr int32_t UI_DIALOG_HEIGHT = 192 * 2; -constexpr const char* APP_NAME = "appName"; -constexpr const char* IS_DEFAULT_SELECTOR = "isDefaultSelector"; -constexpr const char* OFF_SET_X = "offsetX"; -constexpr const char* OFF_SET_Y = "offsetY"; -constexpr const char* WIDTH = "width"; -constexpr const char* HEIGHT = "height"; -constexpr const char* MODEL_FLAG = "modelFlag"; -constexpr const char* ACTION = "action"; -constexpr const char* OVERSIZE_HEIGHT = "oversizeHeight"; +const int32_t UI_ANR_DIALOG_WIDTH = 328 * 2; +const int32_t UI_ANR_DIALOG_HEIGHT = 192 * 2; +const std::string APP_NAME = "appName"; +const std::string IS_DEFAULT_SELECTOR = "isDefaultSelector"; +const std::string OFF_SET_X = "offsetX"; +const std::string OFF_SET_Y = "offsetY"; +const std::string WIDTH = "width"; +const std::string HEIGHT = "height"; +const std::string MODEL_FLAG = "modelFlag"; +const std::string ACTION = "action"; +const std::string OVERSIZE_HEIGHT = "oversizeHeight"; -constexpr int32_t UI_HALF = 2; -constexpr int32_t UI_DEFAULT_BUTTOM_CLIP = 100; -constexpr int32_t UI_WIDTH_780DP = 1560; -constexpr int32_t UI_DEFAULT_WIDTH = 2560; -constexpr int32_t UI_DEFAULT_HEIGHT = 1600; +const int32_t UI_HALF = 2; +const int32_t UI_DEFAULT_BUTTOM_CLIP = 100; +const int32_t UI_WIDTH_780DP = 1560; +const int32_t UI_DEFAULT_WIDTH = 2560; +const int32_t UI_DEFAULT_HEIGHT = 1600; -constexpr const char* STR_PHONE = "phone"; -constexpr const char* STR_DEFAULT = "default"; -constexpr const char* DIALOG_NAME_TIPS = "dialog_tips_service"; -constexpr const char* DIALOG_SELECTOR_NAME = "dialog_selector_service"; -constexpr const char* DIALOG_JUMP_INTERCEPTOR_NAME = "dialog_jump_interceptor_service"; +const std::string STR_PHONE = "phone"; +const std::string STR_DEFAULT = "default"; +const std::string DIALOG_NAME_ANR = "dialog_anr_service"; +const std::string DIALOG_NAME_TIPS = "dialog_tips_service"; +const std::string DIALOG_SELECTOR_NAME = "dialog_selector_service"; +const std::string DIALOG_JUMP_INTERCEPTOR_NAME = "dialog_jump_interceptor_service"; -constexpr const char* BUNDLE_NAME = "bundleName"; -constexpr const char* BUNDLE_NAME_DIALOG = "com.ohos.amsdialog"; -constexpr const char* DIALOG_PARAMS = "params"; -constexpr const char* DIALOG_POSITION = "position"; -constexpr const char* VERTICAL_SCREEN_DIALOG_POSITION = "landscapeScreen"; -constexpr const char* ABILITY_NAME_FREEZE_DIALOG = "SwitchUserDialog"; -constexpr const char* ABILITY_NAME_ASSERT_FAULT_DIALOG = "AssertFaultDialog"; -constexpr const char* ABILITY_NAME_TIPS_DIALOG = "TipsDialog"; -constexpr const char* ABILITY_NAME_SELECTOR_DIALOG = "SelectorDialog"; -constexpr const char* ABILITY_NAME_APPGALLERY_SELECTOR_DIALOG = "AppSelectorExtensionAbility"; -constexpr const char* UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; -constexpr const char* UIEXTENSION_SYS_COMMON_UI = "sys/commonUI"; -constexpr const char* CALLER_TOKEN = "callerToken"; -constexpr const char* ABILITY_NAME_JUMP_INTERCEPTOR_DIALOG = "JumpInterceptorDialog"; -constexpr const char* TYPE_ONLY_MATCH_WILDCARD = "reserved/wildcard"; -constexpr const char* ORIENTATION = "orientation"; -constexpr const char* ABS_CODE_PATH = "/data/app/el1/bundle/public"; -constexpr const char* FILE_SEPARATOR = "/"; +const std::string BUNDLE_NAME = "bundleName"; +const std::string BUNDLE_NAME_DIALOG = "com.ohos.amsdialog"; +const std::string DIALOG_PARAMS = "params"; +const std::string DIALOG_POSITION = "position"; +const std::string VERTICAL_SCREEN_DIALOG_POSITION = "landscapeScreen"; +const std::string ABILITY_NAME_FREEZE_DIALOG = "SwitchUserDialog"; +const std::string ABILITY_NAME_ASSERT_FAULT_DIALOG = "AssertFaultDialog"; +const std::string ABILITY_NAME_TIPS_DIALOG = "TipsDialog"; +const std::string ABILITY_NAME_SELECTOR_DIALOG = "SelectorDialog"; +const std::string ABILITY_NAME_APPGALLERY_SELECTOR_DIALOG = "AppSelectorExtensionAbility"; +const std::string UIEXTENSION_TYPE_KEY = "ability.want.params.uiExtensionType"; +const std::string UIEXTENSION_SYS_COMMON_UI = "sys/commonUI"; +const std::string CALLER_TOKEN = "callerToken"; +const std::string ABILITY_NAME_JUMP_INTERCEPTOR_DIALOG = "JumpInterceptorDialog"; +const std::string TYPE_ONLY_MATCH_WILDCARD = "reserved/wildcard"; +const std::string ORIENTATION = "orientation"; -constexpr int32_t LINE_NUMS_ZERO = 0; -constexpr int32_t LINE_NUMS_TWO = 2; -constexpr int32_t LINE_NUMS_THREE = 3; -constexpr int32_t LINE_NUMS_FOUR = 4; -constexpr int32_t LINE_NUMS_EIGHT = 8; +const int32_t LINE_NUMS_ZERO = 0; +const int32_t LINE_NUMS_TWO = 2; +const int32_t LINE_NUMS_THREE = 3; +const int32_t LINE_NUMS_FOUR = 4; +const int32_t LINE_NUMS_EIGHT = 8; -constexpr float WIDTH_MULTIPLE = 0.8; -constexpr float HEIGHT_MULTIPLE = 0.3; -constexpr float SETX_WIDTH_MULTIPLE = 0.1; +const float WIDTH_MULTIPLE = 0.8; +const float HEIGHT_MULTIPLE = 0.3; +const float SETX_WIDTH_MULTIPLE = 0.1; Want SystemDialogScheduler::GetTipsDialogWant(const sptr &callerToken) { @@ -468,18 +468,18 @@ void SystemDialogScheduler::InitDialogPosition(DialogType type, DialogPosition & switch (type) { case DialogType::DIALOG_ANR: if (position.wideScreen) { - position.width = UI_DIALOG_WIDTH; - position.height = UI_DIALOG_HEIGHT; - position.width_narrow = UI_DIALOG_WIDTH; - position.height_narrow = UI_DIALOG_HEIGHT; + position.width = UI_ANR_DIALOG_WIDTH; + position.height = UI_ANR_DIALOG_HEIGHT; + position.width_narrow = UI_ANR_DIALOG_WIDTH; + position.height_narrow = UI_ANR_DIALOG_HEIGHT; position.align = DialogAlign::CENTER; } else { position.width = display->GetWidth(); position.height = display->GetHeight(); position.width_narrow = display->GetWidth(); position.height_narrow = display->GetHeight(); - position.window_width = UI_DIALOG_WIDTH; - position.window_height = UI_DIALOG_HEIGHT; + position.window_width = UI_ANR_DIALOG_WIDTH; + position.window_height = UI_ANR_DIALOG_HEIGHT; position.align = DialogAlign::CENTER; } break; diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index e7c41e0785..397b7a04dd 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -151,7 +151,7 @@ ohos_shared_library("libappms") { deps += [] external_deps += [ "i18n:intl_util", - "window_manager:libwm_lite", + "window_manager:libwm", "window_manager:libwsutils", ] } diff --git a/services/appmgr/include/window_focus_changed_listener.h b/services/appmgr/include/window_focus_changed_listener.h index 42ed5fa7c9..003e596b24 100644 --- a/services/appmgr/include/window_focus_changed_listener.h +++ b/services/appmgr/include/window_focus_changed_listener.h @@ -17,7 +17,7 @@ #define OHOS_ABILITY_RUNTIME_WINDOW_FOCUS_CHANGE_LISTENER_H #ifdef SUPPORT_SCREEN -#include "window_manager_lite.h" +#include "window_manager.h" #endif // SUPPORT_SCREEN #include "task_handler_wrap.h" diff --git a/services/appmgr/include/window_visibility_changed_listener.h b/services/appmgr/include/window_visibility_changed_listener.h index c4f6b53d8a..765b30b554 100644 --- a/services/appmgr/include/window_visibility_changed_listener.h +++ b/services/appmgr/include/window_visibility_changed_listener.h @@ -18,7 +18,7 @@ #include "task_handler_wrap.h" #ifdef SUPPORT_SCREEN -#include "window_manager_lite.h" +#include "window_manager.h" #endif // SUPPORT_SCREEN namespace OHOS { namespace AppExecFwk { diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c353c86558..39d40d3728 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -640,7 +640,7 @@ void AppMgrServiceInner::MakeProcessName(const std::shared_ptr &abi if (appIndex != 0) { processName += std::to_string(appIndex); } - + if (!specifiedProcessFlag.empty()) { processName = (processName + ":" + specifiedProcessFlag).substr(0, MAX_SPECIFIED_PROCESS_NAME_LENGTH); TAG_LOGI(AAFwkTag::APPMGR, "specifiedProcessFlag = %{public}s, processName = %{public}s", @@ -4814,7 +4814,7 @@ void AppMgrServiceInner::RegisterFocusListener() TAG_LOGE(AAFwkTag::APPMGR, "no focusListener_"); return; } - WindowManagerLite::GetInstance().RegisterFocusChangedListener(focusListener_); + WindowManager::GetInstance().RegisterFocusChangedListener(focusListener_); #endif // SUPPORT_SCREEN TAG_LOGI(AAFwkTag::APPMGR, "RegisterFocusListener end"); } @@ -4827,7 +4827,7 @@ void AppMgrServiceInner::FreeFocusListener() TAG_LOGE(AAFwkTag::APPMGR, "no focusListener_"); return; } - WindowManagerLite::GetInstance().UnregisterFocusChangedListener(focusListener_); + WindowManager::GetInstance().UnregisterFocusChangedListener(focusListener_); focusListener_ = nullptr; #endif // SUPPORT_SCREEN TAG_LOGI(AAFwkTag::APPMGR, "FreeFocusListener end"); @@ -4916,7 +4916,7 @@ void AppMgrServiceInner::InitWindowVisibilityChangedListener() TAG_LOGE(AAFwkTag::APPMGR, "Window visibility changed listener is nullptr."); return; } - WindowManagerLite::GetInstance().RegisterVisibilityChangedListener(inner->windowVisibilityChangedListener_); + WindowManager::GetInstance().RegisterVisibilityChangedListener(inner->windowVisibilityChangedListener_); }; if (taskHandler_ == nullptr) { @@ -4934,7 +4934,7 @@ void AppMgrServiceInner::FreeWindowVisibilityChangedListener() TAG_LOGW(AAFwkTag::APPMGR, "Visibility listener has been freed."); return; } - WindowManagerLite::GetInstance().UnregisterVisibilityChangedListener(windowVisibilityChangedListener_); + WindowManager::GetInstance().UnregisterVisibilityChangedListener(windowVisibilityChangedListener_); } void AppMgrServiceInner::HandleWindowVisibilityChanged( diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index 785746ebaf..3cc96c1294 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -73,6 +73,7 @@ ohos_shared_library("libupms") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", "graphic_2d:color_manager", @@ -123,6 +124,7 @@ ohos_static_library("libupms_static") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_core", "common_event_service:cesfwk_innerkits", "hilog:libhilog", "init:libbeget_proxy", diff --git a/test/fuzztest/startability_fuzzer/BUILD.gn b/test/fuzztest/startability_fuzzer/BUILD.gn index de661e3377..6cdc816bd9 100755 --- a/test/fuzztest/startability_fuzzer/BUILD.gn +++ b/test/fuzztest/startability_fuzzer/BUILD.gn @@ -42,7 +42,6 @@ ohos_fuzztest("StartAbilityFuzzTest") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/moduletest/ability_test/BUILD.gn b/test/moduletest/ability_test/BUILD.gn index 18f014593a..338cc91f6c 100644 --- a/test/moduletest/ability_test/BUILD.gn +++ b/test/moduletest/ability_test/BUILD.gn @@ -57,7 +57,6 @@ ohos_moduletest("ability_moduletest") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:ability_thread", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/moduletest/start_option_display_id_test/BUILD.gn b/test/moduletest/start_option_display_id_test/BUILD.gn index f3f6dfa979..8200567b7d 100644 --- a/test/moduletest/start_option_display_id_test/BUILD.gn +++ b/test/moduletest/start_option_display_id_test/BUILD.gn @@ -26,7 +26,6 @@ ohos_moduletest("start_option_module_test") { configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ability_first_frame_state_observer_manager_test/ability_first_frame_state_observer_manager_test.cpp b/test/unittest/ability_first_frame_state_observer_manager_test/ability_first_frame_state_observer_manager_test.cpp index b1ed86bd2b..62fc2599f3 100644 --- a/test/unittest/ability_first_frame_state_observer_manager_test/ability_first_frame_state_observer_manager_test.cpp +++ b/test/unittest/ability_first_frame_state_observer_manager_test/ability_first_frame_state_observer_manager_test.cpp @@ -20,7 +20,6 @@ #undef protected #include #include "ability_first_frame_state_observer_stub.h" -#include "ability_manager_errors.h" #include "iremote_broker.h" #include "mock/include/mock_permission_verification.h" #include "mock/include/mock_my_flag.h" diff --git a/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp b/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp index 6c0451345b..2055bee7f3 100644 --- a/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp +++ b/test/unittest/ability_interceptor_test/ability_interceptor_test.cpp @@ -57,6 +57,7 @@ public: void AbilityInterceptorTest::SetUpTestCase() { GTEST_LOG_(INFO) << "AbilityInterceptorTest SetUpTestCase called"; + AbilityManagerClient::GetInstance()->CleanAllMissions(); OHOS::DelayedSingleton::DestroyInstance(); OHOS::DelayedSingleton::GetInstance()->RegisterSystemAbility( diff --git a/test/unittest/ability_manager_client_branch_test/BUILD.gn b/test/unittest/ability_manager_client_branch_test/BUILD.gn index 313201ab54..aed05b337b 100644 --- a/test/unittest/ability_manager_client_branch_test/BUILD.gn +++ b/test/unittest/ability_manager_client_branch_test/BUILD.gn @@ -42,7 +42,6 @@ ohos_unittest("ability_manager_client_branch_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:mission_info", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/unittest/ability_manager_proxy_test/BUILD.gn b/test/unittest/ability_manager_proxy_test/BUILD.gn index 65efd7546f..5402ce7ce4 100644 --- a/test/unittest/ability_manager_proxy_test/BUILD.gn +++ b/test/unittest/ability_manager_proxy_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("ability_manager_proxy_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:mission_info", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/ability_manager_service_second_test/BUILD.gn b/test/unittest/ability_manager_service_second_test/BUILD.gn index 395f4ba9a8..07b1f0c246 100644 --- a/test/unittest/ability_manager_service_second_test/BUILD.gn +++ b/test/unittest/ability_manager_service_second_test/BUILD.gn @@ -33,8 +33,6 @@ ohos_unittest("ability_manager_service_second_test") { configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_manager_base", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/ability_manager:mission_info", "${ability_runtime_innerkits_path}/app_manager:app_manager", diff --git a/test/unittest/ability_manager_service_third_test/BUILD.gn b/test/unittest/ability_manager_service_third_test/BUILD.gn index 58c9de5fb7..ea969a38f6 100644 --- a/test/unittest/ability_manager_service_third_test/BUILD.gn +++ b/test/unittest/ability_manager_service_third_test/BUILD.gn @@ -61,7 +61,6 @@ ohos_unittest("ability_manager_service_third_test") { configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/ability_manager:mission_info", "${ability_runtime_innerkits_path}/app_manager:app_manager", diff --git a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp index 3e1139b26b..9ef2da5edb 100644 --- a/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp +++ b/test/unittest/ability_manager_stub_test/ability_manager_stub_test.cpp @@ -14,7 +14,6 @@ */ #include -#include "ability_manager_errors.h" #include "ability_manager_stub_impl_mock.h" #include "ability_scheduler.h" #include "app_debug_listener_stub_mock.h" diff --git a/test/unittest/ability_record_test/BUILD.gn b/test/unittest/ability_record_test/BUILD.gn index 82d5a3ea44..0a4d80bca1 100644 --- a/test/unittest/ability_record_test/BUILD.gn +++ b/test/unittest/ability_record_test/BUILD.gn @@ -53,7 +53,6 @@ ohos_unittest("ability_record_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/ability_manager:mission_info", "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", diff --git a/test/unittest/ability_record_test/ability_record_test.cpp b/test/unittest/ability_record_test/ability_record_test.cpp index c65541e6b2..fe0559f9ee 100644 --- a/test/unittest/ability_record_test/ability_record_test.cpp +++ b/test/unittest/ability_record_test/ability_record_test.cpp @@ -46,6 +46,7 @@ using namespace testing::ext; using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityBase::Constants; namespace OHOS { namespace AAFwk { @@ -55,7 +56,6 @@ const std::string DLP_BUNDLE_NAME = "com.ohos.dlpmanager"; const std::string SHELL_ASSISTANT_BUNDLENAME = "com.huawei.shell_assistant"; const std::string SHOW_ON_LOCK_SCREEN = "ShowOnLockScreen"; const std::string URI_PERMISSION_TABLE_NAME = "uri_permission"; -constexpr const char* COMPRESS_PROPERTY = "compress"; } class AbilityRecordTest : public testing::TestWithParam { public: diff --git a/test/unittest/ams_ability_running_record_test/BUILD.gn b/test/unittest/ams_ability_running_record_test/BUILD.gn index d45c2bec41..29c0891ac0 100644 --- a/test/unittest/ams_ability_running_record_test/BUILD.gn +++ b/test/unittest/ams_ability_running_record_test/BUILD.gn @@ -88,7 +88,7 @@ ohos_unittest("AmsAbilityRunningRecordTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm_lite" ] + external_deps += [ "window_manager:libwm" ] } } diff --git a/test/unittest/ams_app_workflow_test/BUILD.gn b/test/unittest/ams_app_workflow_test/BUILD.gn index 825c9976e6..3324ddeb3d 100644 --- a/test/unittest/ams_app_workflow_test/BUILD.gn +++ b/test/unittest/ams_app_workflow_test/BUILD.gn @@ -83,7 +83,7 @@ ohos_unittest("AmsWorkFlowTest") { if (ability_runtime_graphics) { external_deps += [ - "window_manager:libwm_lite", + "window_manager:libwm", "window_manager:libwsutils", ] } diff --git a/test/unittest/ams_recent_app_list_test/BUILD.gn b/test/unittest/ams_recent_app_list_test/BUILD.gn index e9ece8c44b..3af421ac51 100644 --- a/test/unittest/ams_recent_app_list_test/BUILD.gn +++ b/test/unittest/ams_recent_app_list_test/BUILD.gn @@ -100,7 +100,7 @@ ohos_unittest("AmsRecentAppListTest") { if (ability_runtime_graphics) { external_deps += [ - "window_manager:libwm_lite", + "window_manager:libwm", "window_manager:libwsutils", ] } diff --git a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn index 770271f47f..38cad787fb 100644 --- a/test/unittest/ams_service_app_spawn_client_test/BUILD.gn +++ b/test/unittest/ams_service_app_spawn_client_test/BUILD.gn @@ -94,7 +94,7 @@ ohos_unittest("AmsServiceAppSpawnClientTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm_lite" ] + external_deps += [ "window_manager:libwm" ] } subsystem_name = "ability" diff --git a/test/unittest/ams_service_event_drive_test/BUILD.gn b/test/unittest/ams_service_event_drive_test/BUILD.gn index 73c34b8350..bd625ebb80 100644 --- a/test/unittest/ams_service_event_drive_test/BUILD.gn +++ b/test/unittest/ams_service_event_drive_test/BUILD.gn @@ -98,7 +98,7 @@ ohos_unittest("AmsServiceEventDriveTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm_lite" ] + external_deps += [ "window_manager:libwm" ] } } diff --git a/test/unittest/ams_service_load_ability_process_test/BUILD.gn b/test/unittest/ams_service_load_ability_process_test/BUILD.gn index 86df52e9c0..5da2d9ef83 100644 --- a/test/unittest/ams_service_load_ability_process_test/BUILD.gn +++ b/test/unittest/ams_service_load_ability_process_test/BUILD.gn @@ -103,7 +103,7 @@ ohos_unittest("AmsServiceLoadAbilityProcessTest") { if (ability_runtime_graphics) { external_deps += [ - "window_manager:libwm_lite", + "window_manager:libwm", "window_manager:libwsutils", ] } diff --git a/test/unittest/ams_service_startup_test/BUILD.gn b/test/unittest/ams_service_startup_test/BUILD.gn index 3e2793f67c..0c22400abd 100644 --- a/test/unittest/ams_service_startup_test/BUILD.gn +++ b/test/unittest/ams_service_startup_test/BUILD.gn @@ -93,7 +93,7 @@ ohos_unittest("AmsServiceStartupTest") { ] if (ability_runtime_graphics) { - external_deps += [ "window_manager:libwm_lite" ] + external_deps += [ "window_manager:libwm" ] } } diff --git a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn index 05dcf4307a..4ba9bc5b9c 100644 --- a/test/unittest/app_mgr_service_event_handler_test/BUILD.gn +++ b/test/unittest/app_mgr_service_event_handler_test/BUILD.gn @@ -98,7 +98,7 @@ ohos_unittest("AMSEventHandlerTest") { if (ability_runtime_graphics) { external_deps += [ - "window_manager:libwm_lite", + "window_manager:libwm", "window_manager:libwsutils", ] } diff --git a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp index d57cd8865b..5ffd8e2ae0 100644 --- a/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp +++ b/test/unittest/app_mgr_service_inner_test/app_mgr_service_inner_test.cpp @@ -4303,7 +4303,7 @@ HWTEST_F(AppMgrServiceInnerTest, SetSupportedProcessCacheSelf_001, TestSize.Leve EXPECT_NE(appMgrServiceInner, nullptr); bool isSupported = false; - EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), AAFwk::CHECK_PERMISSION_FAILED); + EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), CHECK_PERMISSION_FAILED); appMgrServiceInner->appRunningManager_ = nullptr; EXPECT_EQ(appMgrServiceInner->SetSupportedProcessCacheSelf(isSupported), ERR_NO_INIT); diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn index 6f0f8660ca..3a95c5a187 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn @@ -41,7 +41,6 @@ ohos_unittest("ability_context_impl_test") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:mission_info", "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index bdfd558403..a4e60acdeb 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -2014,7 +2014,7 @@ ohos_unittest("reserse_continuation_scheduler_primary_proxy_test") { ohos_unittest("distributed_client_test") { module_out_path = module_output_path sources = [ - "${ability_runtime_services_path}/abilitymgr/src/distributed_client.cpp", + "${ability_runtime_native_path}/ability/native/distributed_ability_runtime/distributed_client.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_ability_connect_callback.cpp", "distributed_client_test.cpp", ] diff --git a/test/unittest/pending_want_record_test/BUILD.gn b/test/unittest/pending_want_record_test/BUILD.gn index fd639818d6..abe41db7b8 100644 --- a/test/unittest/pending_want_record_test/BUILD.gn +++ b/test/unittest/pending_want_record_test/BUILD.gn @@ -44,7 +44,6 @@ ohos_unittest("pending_want_record_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/sender_info_test/BUILD.gn b/test/unittest/sender_info_test/BUILD.gn index bb3d4217b1..42338c58b6 100644 --- a/test/unittest/sender_info_test/BUILD.gn +++ b/test/unittest/sender_info_test/BUILD.gn @@ -37,7 +37,6 @@ ohos_unittest("sender_info_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/service_extension_context_test/BUILD.gn b/test/unittest/service_extension_context_test/BUILD.gn index ffed8bfbaa..613a45a60a 100644 --- a/test/unittest/service_extension_context_test/BUILD.gn +++ b/test/unittest/service_extension_context_test/BUILD.gn @@ -40,7 +40,6 @@ ohos_unittest("service_extension_context_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_napi_path}/inner/napi_common:napi_common", "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_native_path}/ability/native:abilitykit_native", diff --git a/test/unittest/start_option_display_id_test/BUILD.gn b/test/unittest/start_option_display_id_test/BUILD.gn index 498b299d6a..7d21032355 100644 --- a/test/unittest/start_option_display_id_test/BUILD.gn +++ b/test/unittest/start_option_display_id_test/BUILD.gn @@ -26,7 +26,6 @@ ohos_unittest("start_option_display_id_test") { configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ] deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/app_manager:app_manager", "${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper", "${ability_runtime_services_path}/abilitymgr:abilityms", diff --git a/test/unittest/start_options_test/BUILD.gn b/test/unittest/start_options_test/BUILD.gn index 842bfdcec1..eb8b0f8469 100755 --- a/test/unittest/start_options_test/BUILD.gn +++ b/test/unittest/start_options_test/BUILD.gn @@ -30,7 +30,6 @@ ohos_unittest("start_options_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/trigger_Info_test/BUILD.gn b/test/unittest/trigger_Info_test/BUILD.gn index 4dfb289f4e..7c883d7e15 100644 --- a/test/unittest/trigger_Info_test/BUILD.gn +++ b/test/unittest/trigger_Info_test/BUILD.gn @@ -29,7 +29,6 @@ ohos_unittest("trigger_Info_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_services_path}/abilitymgr:abilityms", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", diff --git a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn index e85f589d8f..b3e31e0715 100644 --- a/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn +++ b/test/unittest/ui_ability_lifecycle_manager_test/BUILD.gn @@ -45,7 +45,6 @@ ohos_unittest("ui_ability_lifecycle_manager_test") { deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", "${ability_runtime_innerkits_path}/ability_manager:ability_start_setting", "${ability_runtime_innerkits_path}/ability_manager:process_options", "${ability_runtime_innerkits_path}/app_manager:app_manager", diff --git a/test/unittest/want_receiver_stub_test/BUILD.gn b/test/unittest/want_receiver_stub_test/BUILD.gn index 4cb687cb2b..3cd0a69ab2 100644 --- a/test/unittest/want_receiver_stub_test/BUILD.gn +++ b/test/unittest/want_receiver_stub_test/BUILD.gn @@ -40,7 +40,6 @@ ohos_unittest("want_receiver_stub_test") { } deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", - "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/want_sender_proxy_test/BUILD.gn b/test/unittest/want_sender_proxy_test/BUILD.gn index 02a82d91e4..78f816ebdc 100644 --- a/test/unittest/want_sender_proxy_test/BUILD.gn +++ b/test/unittest/want_sender_proxy_test/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("want_sender_proxy_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", diff --git a/test/unittest/want_sender_stub_test/BUILD.gn b/test/unittest/want_sender_stub_test/BUILD.gn index 02b0ea3f07..88ea2ff79a 100644 --- a/test/unittest/want_sender_stub_test/BUILD.gn +++ b/test/unittest/want_sender_stub_test/BUILD.gn @@ -44,7 +44,6 @@ ohos_unittest("want_sender_stub_test") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${ability_runtime_innerkits_path}/wantagent:wantagent_innerkits", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:perm_verification", From 3af1f44d9314d9c17c7c25d6de0775f011498fc4 Mon Sep 17 00:00:00 2001 From: xlw Date: Fri, 28 Jun 2024 11:32:09 +0800 Subject: [PATCH 116/148] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=B4=E6=B5=8B?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xlw Change-Id: Icaae9a715bc8f65fc39d02c353d61a42e4641b35 --- frameworks/native/ability/native/BUILD.gn | 1 + .../native/ability/native/extension_impl.cpp | 28 +++++++++++++++++++ .../ability_runtime/context/context_impl.cpp | 22 +++++++++++++++ .../service_extension_context.cpp | 3 ++ .../native/ability/native/extension_base.inl | 2 +- .../native/ability/native/extension_impl.h | 4 ++- .../ability_runtime/context/context_impl.h | 2 ++ services/abilitymgr/include/ability_config.h | 1 + .../src/ability_connect_manager.cpp | 8 ++++-- 9 files changed, 67 insertions(+), 4 deletions(-) diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index 5d3898ed6e..4adfe8744f 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -462,6 +462,7 @@ ohos_shared_library("extensionkit_native") { "eventhandler:libeventhandler", "hilog:libhilog", "hitrace:hitrace_meter", + "ipc:ipc_core", "json:nlohmann_json_static", "napi:ace_napi", ] diff --git a/frameworks/native/ability/native/extension_impl.cpp b/frameworks/native/ability/native/extension_impl.cpp index 631b48815c..d51a0f2ffe 100644 --- a/frameworks/native/ability/native/extension_impl.cpp +++ b/frameworks/native/ability/native/extension_impl.cpp @@ -19,13 +19,20 @@ #include "ability_local_record.h" #include "ability_transaction_callback_info.h" #include "hitrace_meter.h" +#include "ipc_object_proxy.h" #include "extension_context.h" #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "ui_extension_utils.h" + namespace OHOS { namespace AbilityRuntime { +ExtensionImpl::~ExtensionImpl() +{ + TAG_LOGI(AAFwkTag::EXT, "~ExtensionImpl"); +} + void ExtensionImpl::Init(const std::shared_ptr &application, const std::shared_ptr &record, std::shared_ptr &extension, @@ -48,12 +55,33 @@ void ExtensionImpl::Init(const std::shared_ptr &app extension_->SetExtensionWindowLifeCycleListener( sptr(new ExtensionWindowLifeCycleImpl(token_, shared_from_this()))); } + if (record->GetAbilityInfo()->name == "com.ohos.callui.ServiceAbility") { + PrintTokenInfo(); + } } extension_->Init(record, application, handler, token); lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; skipCommandExtensionWithIntent_ = false; } +void ExtensionImpl::PrintTokenInfo() const +{ + if (token_ == nullptr) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is null"); + return; + } + if (!token_->IsProxyObject()) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is not proxy"); + return; + } + IPCObjectProxy *tokenProxyObject = reinterpret_cast(token_.GetRefPtr()); + if (tokenProxyObject != nullptr) { + std::string remoteDescriptor = Str16ToStr8(tokenProxyObject->GetInterfaceDescriptor()); + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility handle: %{public}d, descriptor: %{public}s", + tokenProxyObject->GetHandle(), remoteDescriptor.c_str()); + } +} + /** * @brief Handling the life cycle switching of Extension. * diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index cc2aec0eee..7881b0b2b1 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -31,6 +31,7 @@ #include "hilog_tag_wrapper.h" #include "hilog_wrapper.h" #include "hitrace_meter.h" +#include "ipc_object_proxy.h" #include "ipc_singleton.h" #include "js_runtime_utils.h" #ifdef SUPPORT_SCREEN @@ -1000,6 +1001,9 @@ void ContextImpl::SetToken(const sptr &token) return; } token_ = token; + if (GetBundleName() == "com.ohos.callui") { + PrintTokenInfo(); + } } sptr ContextImpl::GetToken() @@ -1248,5 +1252,23 @@ int32_t ContextImpl::SetSupportedProcessCacheSelf(bool isSupport) } return appMgrClient->SetSupportedProcessCacheSelf(isSupport); } + +void ContextImpl::PrintTokenInfo() const +{ + if (token_ == nullptr) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is null"); + return; + } + if (!token_->IsProxyObject()) { + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility token is not proxy"); + return; + } + IPCObjectProxy *tokenProxyObject = reinterpret_cast(token_.GetRefPtr()); + if (tokenProxyObject != nullptr) { + std::string remoteDescriptor = Str16ToStr8(tokenProxyObject->GetInterfaceDescriptor()); + TAG_LOGI(AAFwkTag::EXT, "com.ohos.callui.ServiceAbility handle: %{public}d, descriptor: %{public}s", + tokenProxyObject->GetHandle(), remoteDescriptor.c_str()); + } +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/native/appkit/ability_runtime/service_extension_context.cpp b/frameworks/native/appkit/ability_runtime/service_extension_context.cpp index e3649d0694..7f5344f134 100644 --- a/frameworks/native/appkit/ability_runtime/service_extension_context.cpp +++ b/frameworks/native/appkit/ability_runtime/service_extension_context.cpp @@ -132,6 +132,9 @@ ErrCode ServiceExtensionContext::StartAbilityWithAccount(const AAFwk::Want &want TAG_LOGI(AAFwkTag::APPKIT, "accountId: %{public}d, ability: %{public}s, caller: %{public}s", accountId, want.GetElement().GetURI().c_str(), callerName.c_str()); (const_cast(want)).SetParam(START_ABILITY_TYPE, true); + if (callerName == "com.ohos.callui.ServiceAbility") { + PrintTokenInfo(); + } ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->StartAbility( want, token_, ILLEGAL_REQUEST_CODE, accountId); TAG_LOGD(AAFwkTag::APPKIT, "%{public}s. End calling StartAbilityWithAccount. ret=%{public}d", __func__, err); diff --git a/interfaces/kits/native/ability/native/extension_base.inl b/interfaces/kits/native/ability/native/extension_base.inl index 440300077b..218c9ddd00 100644 --- a/interfaces/kits/native/ability/native/extension_base.inl +++ b/interfaces/kits/native/ability/native/extension_base.inl @@ -39,7 +39,6 @@ std::shared_ptr ExtensionBase::CreateAndInitContext(const std::shared_ptr< { TAG_LOGD(AAFwkTag::EXT, "begin init base"); std::shared_ptr context = std::make_shared(); - context->SetToken(token); auto appContext = Context::GetApplicationContext(); if (appContext == nullptr) { TAG_LOGE(AAFwkTag::EXT, "ServiceExtension::CreateAndInitContext appContext is nullptr"); @@ -48,6 +47,7 @@ std::shared_ptr ExtensionBase::CreateAndInitContext(const std::shared_ptr< context->SetApplicationInfo(appContext->GetApplicationInfo()); context->SetResourceManager(appContext->GetResourceManager()); context->SetParentContext(appContext); + context->SetToken(token); if (record == nullptr) { TAG_LOGE(AAFwkTag::EXT, "ServiceExtension::CreateAndInitContext record is nullptr"); return context; diff --git a/interfaces/kits/native/ability/native/extension_impl.h b/interfaces/kits/native/ability/native/extension_impl.h index 56d52ff761..e1cae8cf56 100644 --- a/interfaces/kits/native/ability/native/extension_impl.h +++ b/interfaces/kits/native/ability/native/extension_impl.h @@ -38,7 +38,7 @@ namespace AbilityRuntime { class ExtensionImpl : public std::enable_shared_from_this { public: ExtensionImpl() = default; - virtual ~ExtensionImpl() = default; + virtual ~ExtensionImpl(); /** * @brief Init the object. @@ -205,6 +205,8 @@ protected: private: inline bool UIExtensionAbilityExecuteInsightIntent(const Want &want); + void PrintTokenInfo() const; + int lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; sptr token_; std::shared_ptr extension_; 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 71c8043dd5..bd1b9939fd 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/context_impl.h @@ -364,6 +364,8 @@ public: int32_t SetSupportedProcessCacheSelf(bool isSupport); + void PrintTokenInfo() const; + static const int EL_DEFAULT = 1; protected: diff --git a/services/abilitymgr/include/ability_config.h b/services/abilitymgr/include/ability_config.h index 65f393f128..ad41abbb48 100644 --- a/services/abilitymgr/include/ability_config.h +++ b/services/abilitymgr/include/ability_config.h @@ -38,6 +38,7 @@ constexpr const char* SCENEBOARD_ABILITY_NAME = "com.ohos.sceneboard.MainAbility constexpr const char* GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager"; constexpr const char* GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; constexpr const char* PARAMS_STREAM = "ability.params.stream"; +constexpr const char* CALLUI_ABILITY_NAME = "com.ohos.callui.ServiceAbility"; constexpr const char* MISSION_NAME_MARK_HEAD = "#"; constexpr const char* MISSION_NAME_SEPARATOR = ":"; } // namespace AbilityConfig diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 2c9af82570..269ec90ad0 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -764,6 +764,7 @@ int AbilityConnectManager::DisconnectAbilityLocked(const sptr abilityRecord) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "terminate record called."); if (!GetAbilityRecordById(abilityRecord->GetRecordId())) { return; } @@ -2011,15 +2012,18 @@ void AbilityConnectManager::OnTimeOut(uint32_t msgId, int64_t abilityRecordId) void AbilityConnectManager::HandleInactiveTimeout(const std::shared_ptr &ability) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout start"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout start"); CHECK_POINTER(ability); if (ability->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Handle root launcher inactive timeout."); // terminate the timeout root launcher. DelayedSingleton::GetInstance()->AttachTimeOut(ability->GetToken()); } + if (ability->GetAbilityInfo().name == AbilityConfig::CALLUI_ABILITY_NAME && ability->GetStartId() == 0) { + HandleConnectTimeoutTask(ability); + } - TAG_LOGD(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout end"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "HandleInactiveTimeout end"); } bool AbilityConnectManager::IsAbilityNeedKeepAlive(const std::shared_ptr &abilityRecord) From 52e9ec2b4d255b04d87cb64e1e97b2d1a1fefcf0 Mon Sep 17 00:00:00 2001 From: xiaoyuan Date: Sat, 29 Jun 2024 09:05:59 +0000 Subject: [PATCH 117/148] =?UTF-8?q?=E5=8E=9F=E7=94=9F=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=B1=BB=E6=8E=A7=E4=BB=B6=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=A7=86=E8=A7=89=E6=90=9C=E7=B4=A2uiextensiontype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaoyuan --- services/common/include/ui_extension_utils.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/services/common/include/ui_extension_utils.h b/services/common/include/ui_extension_utils.h index 87b42fc8fd..081ca4c7eb 100755 --- a/services/common/include/ui_extension_utils.h +++ b/services/common/include/ui_extension_utils.h @@ -63,7 +63,8 @@ inline std::unordered_set GetUiExtensionSet() AppExecFwk::ExtensionAbilityType::LIVEVIEW_LOCKSCREEN, AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOEDITOR, AppExecFwk::ExtensionAbilityType::PHOTO_EDITOR, - AppExecFwk::ExtensionAbilityType::SYSPICKER_AUDIOPICKER + AppExecFwk::ExtensionAbilityType::SYSPICKER_AUDIOPICKER, + AppExecFwk::ExtensionAbilityType::SYS_VISUAL }; } @@ -99,7 +100,8 @@ inline bool IsSystemUIExtension(const AppExecFwk::ExtensionAbilityType type) AppExecFwk::ExtensionAbilityType::AUTO_FILL_SMART, AppExecFwk::ExtensionAbilityType::SYSPICKER_FILEPICKER, AppExecFwk::ExtensionAbilityType::SYSDIALOG_USERAUTH, - AppExecFwk::ExtensionAbilityType::HMS_ACCOUNT + AppExecFwk::ExtensionAbilityType::HMS_ACCOUNT, + AppExecFwk::ExtensionAbilityType::SYS_VISUAL }; return systemUiExtensionSet.find(type) != systemUiExtensionSet.end(); } @@ -126,7 +128,8 @@ inline bool IsPublicForEmbedded(const AppExecFwk::ExtensionAbilityType type) AppExecFwk::ExtensionAbilityType::EMBEDDED_UI, // EMBEDDED_UI usage within the app AppExecFwk::ExtensionAbilityType::ADS, AppExecFwk::ExtensionAbilityType::SYSPICKER_PHOTOPICKER, - AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL + AppExecFwk::ExtensionAbilityType::SYSPICKER_MEDIACONTROL, + AppExecFwk::ExtensionAbilityType::SYS_VISUAL }; return publicForEmbeddedSet.find(type) != publicForEmbeddedSet.end(); } From 03154f36ce0de73c6054e26cfedc226116cf1e63 Mon Sep 17 00:00:00 2001 From: "zhangyafei.echo" Date: Thu, 27 Jun 2024 15:36:56 +0800 Subject: [PATCH 118/148] Context support sendable. Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo Change-Id: I33e62951224ec2d9840e0e4b24d9cc314ac99df9 --- frameworks/js/napi/BUILD.gn | 1 + .../app/sendable_context_manager/BUILD.gn | 61 +++ .../js_sendable_context_manager.cpp | 378 ++++++++++++++++++ .../js_sendable_context_manager.h | 32 ++ .../native_module.cpp | 30 ++ .../ability_runtime/app/js_ability_stage.cpp | 40 +- .../app/js_ability_stage_context.cpp | 3 +- .../app/js_ability_stage_context.h | 3 +- 8 files changed, 524 insertions(+), 24 deletions(-) create mode 100644 frameworks/js/napi/app/sendable_context_manager/BUILD.gn create mode 100644 frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.cpp create mode 100644 frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.h create mode 100644 frameworks/js/napi/app/sendable_context_manager/native_module.cpp diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index fee3fa07d2..8fea470fe3 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -42,6 +42,7 @@ group("napi_packages") { "${ability_runtime_napi_path}/app/error_manager:errormanager_napi", "${ability_runtime_napi_path}/app/js_app_manager:appmanager", "${ability_runtime_napi_path}/app/recovery:apprecovery_napi", + "${ability_runtime_napi_path}/app/sendable_context_manager:sendablecontextmanager_napi", "${ability_runtime_napi_path}/app/test_runner:testrunner_napi", "${ability_runtime_napi_path}/app_startup/async_task_callback:asynctaskcallback_napi", "${ability_runtime_napi_path}/app_startup/async_task_excutor:asynctaskexcutor_napi", diff --git a/frameworks/js/napi/app/sendable_context_manager/BUILD.gn b/frameworks/js/napi/app/sendable_context_manager/BUILD.gn new file mode 100644 index 0000000000..d40d0ba834 --- /dev/null +++ b/frameworks/js/napi/app/sendable_context_manager/BUILD.gn @@ -0,0 +1,61 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_shared_library("sendablecontextmanager_napi") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + branch_protector_ret = "pac_ret" + + include_dirs = [ + "${ability_runtime_napi_path}/ability_auto_startup_callback", + "${ability_runtime_path}/interfaces/kits/native/ability/native/ability_runtime", + ] + + sources = [ + "js_sendable_context_manager.cpp", + "native_module.cpp", + ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/napi_base_context:napi_base_context", + "${ability_runtime_innerkits_path}/runtime:runtime", + "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability:ability_context_native", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:app_context_utils", + "${ability_runtime_native_path}/appkit:appkit_native", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hilog:libhilog", + "napi:ace_napi", + ] + + relative_install_dir = "module/app/ability" + subsystem_name = "ability" + part_name = "ability_runtime" +} diff --git a/frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.cpp b/frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.cpp new file mode 100644 index 0000000000..6500d8bc7f --- /dev/null +++ b/frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.cpp @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_sendable_context_manager.h" + +#include "ability_context.h" +#include "context.h" +#include "js_ability_context.h" +#include "js_ability_stage_context.h" +#include "js_application_context_utils.h" +#include "js_context_utils.h" +#include "js_error_utils.h" +#include "js_runtime_utils.h" +#include "hilog_tag_wrapper.h" +#include "napi_base_context.h" + +namespace OHOS { +namespace AbilityRuntime { +namespace { +constexpr size_t ARGC_ONE = 1; +} // namespace + +class JsContext { +public: + explicit JsContext(std::weak_ptr&& context) : context_(std::move(context)) {} + virtual ~JsContext() = default; + + static void Finalizer(napi_env env, void* data, void* hint); + + std::weak_ptr context_; +}; + +void JsContext::Finalizer(napi_env env, void* data, void* hint) +{ + TAG_LOGD(AAFwkTag::CONTEXT, "JsContext finalizer."); + if (data == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Input data invalid."); + return; + } + std::unique_ptr(static_cast(data)); +} + +napi_value CreateSendableContextObject(napi_env env, std::shared_ptr context) +{ + auto jsContext = std::make_unique(context); + napi_value objValue = nullptr; + auto status = napi_ok; + // Sendable context has no property for now. + status = napi_create_sendable_object_with_properties(env, 0, nullptr, &objValue); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "Create sendable context failed with %{public}d.", status); + return nullptr; + } + + status = napi_wrap_sendable(env, objValue, jsContext.release(), JsContext::Finalizer, nullptr); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "Wrap sendable failed with %{public}d.", status); + return nullptr; + } + + return objValue; +} + +napi_value CreateJsBaseContextFromSendable(napi_env env, void* wrapped) +{ + JsContext *sendableContext = static_cast(wrapped); + if (sendableContext == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed."); + return nullptr; + } + + auto weakContext = sendableContext->context_; + std::shared_ptr context = weakContext.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid."); + return nullptr; + } + + // create normal context + return CreateJsBaseContext(env, context); +} + +napi_value CreateJsApplicationContextFromSendable(napi_env env, void* wrapped) +{ + JsContext *sendableContext = static_cast(wrapped); + if (sendableContext == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed."); + return nullptr; + } + + auto weakContext = sendableContext->context_; + std::shared_ptr context = weakContext.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid."); + return nullptr; + } + + // create application context + return JsApplicationContextUtils::CreateJsApplicationContext(env); +} + +napi_value CreateJsAbilityStageContextFromSendable(napi_env env, void* wrapped) +{ + JsContext *sendableContext = static_cast(wrapped); + if (sendableContext == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed."); + return nullptr; + } + + auto weakContext = sendableContext->context_; + std::shared_ptr context = weakContext.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid."); + return nullptr; + } + + // create normal abilitystage context + return CreateJsAbilityStageContext(env, context); +} + +napi_value CreateJsUIAbilityContextFromSendable(napi_env env, void* wrapped) +{ + JsContext *sendableContext = static_cast(wrapped); + if (sendableContext == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Get sendable context failed."); + return nullptr; + } + + auto weakContext = sendableContext->context_; + std::shared_ptr context = weakContext.lock(); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Context invalid."); + return nullptr; + } + + auto uiAbilityContext = AbilityRuntime::Context::ConvertTo(context); + if (uiAbilityContext == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Convert to UIAbility context failed."); + return nullptr; + } + + // create normal uiability context + return CreateJsAbilityContext(env, uiAbilityContext); +} + +class JsSendableContextManager { +public: + JsSendableContextManager() = default; + ~JsSendableContextManager() = default; + + static void Finalizer(napi_env env, void *data, void *hint) + { + TAG_LOGD(AAFwkTag::CONTEXT, "JsSendableContextManager finalizer."); + if (data == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Input data invalid."); + return; + } + std::unique_ptr(static_cast(data)); + } + + static napi_value ConvertFromContext(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertFromContext); + } + + static napi_value ConvertToContext(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToContext); + } + + static napi_value ConvertToApplicationContext(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToApplicationContext); + } + + static napi_value ConvertToAbilityStageContext(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToAbilityStageContext); + } + + static napi_value ConvertToUIAbilityContext(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsSendableContextManager, OnConvertToUIAbilityContext); + } + +private: + napi_value OnConvertFromContext(napi_env env, NapiCallbackInfo &info) + { + TAG_LOGD(AAFwkTag::CONTEXT, "Convert from context."); + if (info.argc != ARGC_ONE) { + TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid."); + ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid."); + return CreateJsUndefined(env); + } + + // Get native context + bool stageMode = false; + napi_status status = IsStageContext(env, info.argv[0], stageMode); + if (status != napi_ok || !stageMode) { + TAG_LOGE(AAFwkTag::CONTEXT, "Context isn't stageMode, status is %{public}d.", status); + ThrowInvalidParamError(env, "Parse param context failed, must be a context of stageMode."); + return CreateJsUndefined(env); + } + + auto context = GetStageModeContext(env, info.argv[0]); + if (context == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "get context failed"); + ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr."); + return CreateJsUndefined(env); + } + + // create sendable context + return CreateSendableContextObject(env, context); + } + + napi_value OnConvertToContext(napi_env env, NapiCallbackInfo &info) + { + TAG_LOGD(AAFwkTag::CONTEXT, "Convert to context."); + if (info.argc != ARGC_ONE) { + TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid."); + ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid."); + return CreateJsUndefined(env); + } + + // Get context + void *wrapped = nullptr; + auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status); + ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid."); + return CreateJsUndefined(env); + } + + // Create normal context + auto object = CreateJsBaseContextFromSendable(env, wrapped); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Create base context failed."); + ThrowInvalidParamError(env, "Parameter error: Create context failed."); + return CreateJsUndefined(env); + } + + return object; + } + + napi_value OnConvertToApplicationContext(napi_env env, NapiCallbackInfo &info) + { + TAG_LOGD(AAFwkTag::CONTEXT, "Convert to application context."); + if (info.argc != ARGC_ONE) { + TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid."); + ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid."); + return CreateJsUndefined(env); + } + + // Get context + void *wrapped = nullptr; + auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status); + ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid."); + return CreateJsUndefined(env); + } + + // Create normal context + auto object = CreateJsApplicationContextFromSendable(env, wrapped); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Create base context failed."); + ThrowInvalidParamError(env, "Parameter error: Create application context failed."); + return CreateJsUndefined(env); + } + + return object; + } + + napi_value OnConvertToAbilityStageContext(napi_env env, NapiCallbackInfo &info) + { + TAG_LOGD(AAFwkTag::CONTEXT, "Convert to ability stage context."); + if (info.argc != ARGC_ONE) { + TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid."); + ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid."); + return CreateJsUndefined(env); + } + + // Get context + void *wrapped = nullptr; + auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status); + ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid."); + return CreateJsUndefined(env); + } + + // Create normal context + auto object = CreateJsAbilityStageContextFromSendable(env, wrapped); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Create base context failed."); + ThrowInvalidParamError(env, "Parameter error: Create ability stage context failed."); + return CreateJsUndefined(env); + } + + return object; + } + + napi_value OnConvertToUIAbilityContext(napi_env env, NapiCallbackInfo &info) + { + TAG_LOGD(AAFwkTag::CONTEXT, "Convert to uiability context."); + if (info.argc != ARGC_ONE) { + TAG_LOGE(AAFwkTag::CONTEXT, "The number of parameter is invalid."); + ThrowInvalidParamError(env, "Parameter error: The number of parameter is invalid."); + return CreateJsUndefined(env); + } + + // Get context + void *wrapped = nullptr; + auto status = napi_unwrap_sendable(env, info.argv[0], &wrapped); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "Unwrap sendable object failed with %{public}d.", status); + ThrowInvalidParamError(env, "Parameter error: Input parameter is invalid."); + return CreateJsUndefined(env); + } + + // Create uiability context + auto object = CreateJsUIAbilityContextFromSendable(env, wrapped); + if (object == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Create uiability context failed."); + ThrowInvalidParamError(env, "Parameter error: Create uiability context failed."); + return CreateJsUndefined(env); + } + + return object; + } +}; + +napi_value CreateJsSendableContextManager(napi_env env, napi_value exportObj) +{ + TAG_LOGD(AAFwkTag::CONTEXT, "Create sendable context manager."); + if (env == nullptr || exportObj == nullptr) { + TAG_LOGE(AAFwkTag::CONTEXT, "Invalid parameter."); + return nullptr; + } + + napi_status status = napi_ok; + std::unique_ptr sendableMgr = std::make_unique(); + status = napi_wrap(env, exportObj, sendableMgr.release(), JsSendableContextManager::Finalizer, nullptr, nullptr); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "napi wrap failed with %{public}d.", status); + return nullptr; + } + + napi_property_descriptor properties[] = { + DECLARE_NAPI_FUNCTION("convertFromContext", JsSendableContextManager::ConvertFromContext), + DECLARE_NAPI_FUNCTION("convertToContext", JsSendableContextManager::ConvertToContext), + DECLARE_NAPI_FUNCTION("convertToApplicationContext", JsSendableContextManager::ConvertToApplicationContext), + DECLARE_NAPI_FUNCTION("convertToAbilityStageContext", JsSendableContextManager::ConvertToAbilityStageContext), + DECLARE_NAPI_FUNCTION("convertToUIAbilityContext", JsSendableContextManager::ConvertToUIAbilityContext), + }; + + status = napi_define_properties(env, exportObj, sizeof(properties) / sizeof(properties[0]), properties); + if (status != napi_ok) { + TAG_LOGE(AAFwkTag::CONTEXT, "napi define property failed with %{public}d.", status); + return nullptr; + } + + return exportObj; +} +} // namespace AbilityRuntime +} // namespace OHOS diff --git a/frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.h b/frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.h new file mode 100644 index 0000000000..e5a3a2dbde --- /dev/null +++ b/frameworks/js/napi/app/sendable_context_manager/js_sendable_context_manager.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_JS_SENDABLE_CONTEXT_MANAGER_H +#define OHOS_ABILITY_RUNTIME_JS_SENDABLE_CONTEXT_MANAGER_H + +#include "native_engine/native_engine.h" + +namespace OHOS { +namespace AbilityRuntime { +class Context; +napi_value CreateJsSendableContextManager(napi_env env, napi_value exportObj); +napi_value CreateSendableContextObject(napi_env env, std::shared_ptr context); +napi_value CreateJsBaseContextFromSendable(napi_env env, void* wrapped); +napi_value CreateJsApplicationContextFromSendable(napi_env env, void* wrapped); +napi_value CreateJsAbilityStageContextFromSendable(napi_env env, void* wrapped); +napi_value CreateJsUIAbilityContextFromSendable(napi_env env, void* wrapped); +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_JS_SENDABLE_CONTEXT_MANAGER_H diff --git a/frameworks/js/napi/app/sendable_context_manager/native_module.cpp b/frameworks/js/napi/app/sendable_context_manager/native_module.cpp new file mode 100644 index 0000000000..c967bbeb8c --- /dev/null +++ b/frameworks/js/napi/app/sendable_context_manager/native_module.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_sendable_context_manager.h" +#include "native_engine/native_engine.h" + +static napi_module _module = { + .nm_version = 0, + .nm_filename = "app/ability/libsendablecontextmanager_napi.so", + .nm_register_func = OHOS::AbilityRuntime::CreateJsSendableContextManager, + .nm_modname = "app.ability.sendableContextManager", +}; + +extern "C" __attribute__((constructor)) +void NapiAppAbilitySendableContextManagerAutoRegister() +{ + napi_module_register(&_module); +} diff --git a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp index dfa9b9d7be..2a60ed8886 100644 --- a/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp +++ b/frameworks/native/appkit/ability_runtime/app/js_ability_stage.cpp @@ -50,7 +50,7 @@ constexpr const char* WAIT_ON_MAIN_THREAD = "waitOnMainThread"; constexpr const char* CONFIG_ENTRY = "configEntry"; constexpr const char *TASKPOOL = "taskPool"; constexpr const char *TASKPOOL_LOWER = "taskpool"; - + napi_value AttachAbilityStageContext(napi_env env, void *value, void *) { TAG_LOGD(AAFwkTag::APPKIT, "AttachAbilityStageContext"); @@ -63,7 +63,7 @@ napi_value AttachAbilityStageContext(napi_env env, void *value, void *) TAG_LOGW(AAFwkTag::APPKIT, "invalid context."); return nullptr; } - napi_value object = CreateJsAbilityStageContext(env, ptr, nullptr, nullptr); + napi_value object = CreateJsAbilityStageContext(env, ptr); auto systemModule = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityStageContext", &object, 1); if (systemModule == nullptr) { TAG_LOGW(AAFwkTag::APPKIT, "invalid systemModule."); @@ -169,7 +169,7 @@ void JsAbilityStage::Init(const std::shared_ptr &context, TAG_LOGE(AAFwkTag::APPKIT, "stage is nullptr"); return; } - + SetJsAbilityStage(context); } @@ -415,12 +415,12 @@ int32_t JsAbilityStage::RegisterStartupTaskFromProfile(std::vector TAG_LOGE(AAFwkTag::APPKIT, "context is nullptr."); return false; } - + auto resMgr = context->GetResourceManager(); if (!resMgr) { TAG_LOGE(AAFwkTag::APPKIT, "resMgr is nullptr."); return false; } - + auto hapModuleInfo = context->GetHapModuleInfo(); if (!hapModuleInfo) { TAG_LOGE(AAFwkTag::APPKIT, "hapModuleInfo is nullptr."); return false; } - + jsRuntime_.UpdateModuleNameAndAssetPath(hapModuleInfo->moduleName); bool isCompressed = !hapModuleInfo->hapPath.empty(); std::string appStartup = hapModuleInfo->appStartup; @@ -452,7 +452,7 @@ bool JsAbilityStage::GetProfileInfoFromResourceManager(std::vector TAG_LOGE(AAFwkTag::APPKIT, "appStartup invalid."); return false; } - + GetResFromResMgr(appStartup, resMgr, isCompressed, profileInfo); if (profileInfo.empty()) { TAG_LOGE(AAFwkTag::APPKIT, "appStartup config not exist."); @@ -482,17 +482,17 @@ std::unique_ptr JsAbilityStage::LoadJsSrcEntry(const std::strin bool esmodule = hapModuleInfo->compileMode == AppExecFwk::CompileMode::ES_MODULE; std::string moduleName(hapModuleInfo->moduleName); std::string srcPath(moduleName + "/" + srcEntry); - + auto pos = srcPath.rfind('.'); if (pos == std::string::npos) { return nullptr; } srcPath.erase(pos); srcPath.append(".abc"); - + std::unique_ptr jsCode( jsRuntime_.LoadModule(moduleName, srcPath, hapModuleInfo->hapPath, esmodule)); - + return jsCode; } @@ -550,7 +550,7 @@ void JsAbilityStage::SetOptionalParameters( jsStartupTask.SetCallCreateOnMainThread(true); } } - + if (module.contains(WAIT_ON_MAIN_THREAD) && module[WAIT_ON_MAIN_THREAD].is_boolean()) { jsStartupTask.SetWaitOnMainThread(module.at(WAIT_ON_MAIN_THREAD).get()); } else { @@ -596,7 +596,7 @@ bool JsAbilityStage::AnalyzeProfileInfoAndRegisterStartupTask(const std::vector< TAG_LOGE(AAFwkTag::APPKIT, "Invalid module data."); return false; } - + std::unique_ptr startupJsRef = LoadJsSrcEntry(module.at(SRC_ENTRY).get()); if (startupJsRef == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "load js appStartup tasks failed."); @@ -728,7 +728,7 @@ bool JsAbilityStage::GetResFromResMgr( TAG_LOGE(AAFwkTag::APPKIT, "res name is empty."); return false; } - + size_t pos = resName.rfind(PROFILE_FILE_PREFIX); if ((pos == std::string::npos) || (pos == resName.length() - strlen(PROFILE_FILE_PREFIX))) { TAG_LOGE(AAFwkTag::APPKIT, "res name %{public}s is invalid.", resName.c_str()); @@ -779,10 +779,10 @@ void JsAbilityStage::SetJsAbilityStage(const std::shared_ptr &context) TAG_LOGE(AAFwkTag::APPKIT, "context is nullptr"); return; } - + HandleScope handleScope(jsRuntime_); auto env = jsRuntime_.GetNapiEnv(); - + napi_value obj = nullptr; if (jsAbilityStageObj_) { obj = jsAbilityStageObj_->GetNapiValue(); @@ -791,8 +791,8 @@ void JsAbilityStage::SetJsAbilityStage(const std::shared_ptr &context) return; } } - - napi_value contextObj = CreateJsAbilityStageContext(env, context, nullptr, nullptr); + + napi_value contextObj = CreateJsAbilityStageContext(env, context); shellContextRef_ = JsRuntime::LoadSystemModuleByEngine(env, "application.AbilityStageContext", &contextObj, 1); if (shellContextRef_ == nullptr) { TAG_LOGE(AAFwkTag::APPKIT, "Failed to get LoadSystemModuleByEngine"); @@ -807,7 +807,7 @@ void JsAbilityStage::SetJsAbilityStage(const std::shared_ptr &context) napi_coerce_to_native_binding_object( env, contextObj, DetachCallbackFunc, AttachAbilityStageContext, workContext, nullptr); context->Bind(jsRuntime_, shellContextRef_.get()); - + if (obj != nullptr) { napi_set_named_property(env, obj, "context", contextObj); } diff --git a/frameworks/native/appkit/ability_runtime/app/js_ability_stage_context.cpp b/frameworks/native/appkit/ability_runtime/app/js_ability_stage_context.cpp index 0c6dc28d79..027d622bc4 100644 --- a/frameworks/native/appkit/ability_runtime/app/js_ability_stage_context.cpp +++ b/frameworks/native/appkit/ability_runtime/app/js_ability_stage_context.cpp @@ -52,8 +52,7 @@ void JsAbilityStageContext::ConfigurationUpdated(napi_env env, std::shared_ptr context, DetachCallback detach, NapiAttachCallback attach) +napi_value CreateJsAbilityStageContext(napi_env env, std::shared_ptr context) { TAG_LOGD(AAFwkTag::APPKIT, "called."); napi_value objValue = CreateJsBaseContext(env, context); diff --git a/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage_context.h b/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage_context.h index efb7d3c5a2..cc878f1b2c 100644 --- a/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/app/js_ability_stage_context.h @@ -39,8 +39,7 @@ private: std::weak_ptr context_; }; -napi_value CreateJsAbilityStageContext(napi_env env, - std::shared_ptr context, DetachCallback detach, NapiAttachCallback attach); +napi_value CreateJsAbilityStageContext(napi_env env, std::shared_ptr context); } // namespace AbilityRuntime } // namespace OHOS #endif // OHOS_ABILITY_RUNTIME_JS_ABILITY_STAGE_CONTEXT_H From 4705d6086dbd306e75e2081689974c9c594715d7 Mon Sep 17 00:00:00 2001 From: zhangyafei-echo Date: Fri, 28 Jun 2024 16:38:38 +0800 Subject: [PATCH 119/148] AbilityLifeCycle support onWindowStageCreate, onSaveState, onContinue. Signed-off-by: zhangyafei-echo Change-Id: Ieec1c584694cd664efe8cd1f77a2616be2aa502b --- .../ability_lifecycle_callback.js | 20 +++++ .../native/ability_runtime/js_ui_ability.cpp | 27 +++++- .../context/ability_lifecycle_callback.cpp | 27 ++++++ .../context/application_context.cpp | 82 +++++++++++++++++++ .../context/ability_lifecycle_callback.h | 15 ++++ .../context/application_context.h | 7 ++ 6 files changed, 175 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/app/ability_lifecycle_callback/ability_lifecycle_callback.js b/frameworks/js/napi/app/ability_lifecycle_callback/ability_lifecycle_callback.js index 8f67916249..36f032f2ab 100644 --- a/frameworks/js/napi/app/ability_lifecycle_callback/ability_lifecycle_callback.js +++ b/frameworks/js/napi/app/ability_lifecycle_callback/ability_lifecycle_callback.js @@ -83,6 +83,26 @@ class AbilityLifecycleCallback { onAbilityWillBackground(ability) { console.log('onAbilityWillBackground'); } + + onAbilityWillContinue(ability) { + console.log('onAbilityWillContinue'); + } + + onWindowStageWillRestore(ability, windowStage) { + console.log('onWindowStageWillRestore'); + } + + onWindowStageRestore(ability, windowStage) { + console.log('onWindowStageRestore'); + } + + onAbilityWillSaveState(ability) { + console.log('onAbilityWillSaveState'); + } + + onAbilitySaveState(ability) { + console.log('onAbilitySaveState'); + } } export default AbilityLifecycleCallback; \ No newline at end of file diff --git a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp index 5f55701f4f..3de7258f6d 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ui_ability.cpp @@ -520,15 +520,21 @@ void JsUIAbility::OnSceneRestored() } UpdateJsWindowStage(jsAppWindowStage->GetNapiValue()); napi_value argv[] = {jsAppWindowStage->GetNapiValue()}; + jsWindowStageObj_ = std::shared_ptr(jsAppWindowStage.release()); + auto applicationContext = AbilityRuntime::Context::GetApplicationContext(); + if (applicationContext != nullptr) { + applicationContext->DispatchOnWindowStageWillRestore(jsAbilityObj_, jsWindowStageObj_); + } CallObjectMethod("onWindowStageRestore", argv, ArraySize(argv)); + if (applicationContext != nullptr) { + applicationContext->DispatchOnWindowStageRestore(jsAbilityObj_, jsWindowStageObj_); + } auto delegator = AppExecFwk::AbilityDelegatorRegistry::GetAbilityDelegator(); if (delegator) { TAG_LOGD(AAFwkTag::UIABILITY, "Call PostPerformScenceRestored."); delegator->PostPerformScenceRestored(CreateADelegatorAbilityProperty()); } - - jsWindowStageObj_ = std::shared_ptr(jsAppWindowStage.release()); } void JsUIAbility::OnSceneWillDestroy() @@ -1074,6 +1080,12 @@ int32_t JsUIAbility::OnContinue(WantParams &wantParams) TAG_LOGE(AAFwkTag::UIABILITY, "Failed to get Ability object."); return AppExecFwk::ContinuationManagerStage::OnContinueResult::REJECT; } + + auto applicationContext = AbilityRuntime::Context::GetApplicationContext(); + if (applicationContext != nullptr) { + applicationContext->DispatchOnAbilityWillContinue(jsAbilityObj_); + } + napi_value jsWantParams = OHOS::AppExecFwk::WrapWantParams(env, wantParams); napi_value result = CallObjectMethod("onContinue", &jsWantParams, 1, true); int32_t onContinueRes = 0; @@ -1089,7 +1101,6 @@ int32_t JsUIAbility::OnContinue(WantParams &wantParams) } } OHOS::AppExecFwk::UnwrapWantParams(env, jsWantParams, wantParams); - auto applicationContext = AbilityRuntime::Context::GetApplicationContext(); if (applicationContext != nullptr) { applicationContext->DispatchOnAbilityContinue(jsAbilityObj_); } @@ -1111,6 +1122,11 @@ int32_t JsUIAbility::OnSaveState(int32_t reason, WantParams &wantParams) return -1; } + auto applicationContext = AbilityRuntime::Context::GetApplicationContext(); + if (applicationContext != nullptr) { + applicationContext->DispatchOnAbilityWillSaveState(jsAbilityObj_); + } + napi_value methodOnSaveState = nullptr; napi_get_named_property(env, obj, "onSaveState", &methodOnSaveState); if (methodOnSaveState == nullptr) { @@ -1130,6 +1146,11 @@ int32_t JsUIAbility::OnSaveState(int32_t reason, WantParams &wantParams) TAG_LOGE(AAFwkTag::UIABILITY, "AppRecovery no result return from onSaveState."); return -1; } + + if (applicationContext != nullptr) { + applicationContext->DispatchOnAbilitySaveState(jsAbilityObj_); + } + return numberResult; } diff --git a/frameworks/native/appkit/ability_runtime/context/ability_lifecycle_callback.cpp b/frameworks/native/appkit/ability_runtime/context/ability_lifecycle_callback.cpp index d01f096843..fa837cdc19 100644 --- a/frameworks/native/appkit/ability_runtime/context/ability_lifecycle_callback.cpp +++ b/frameworks/native/appkit/ability_runtime/context/ability_lifecycle_callback.cpp @@ -149,6 +149,33 @@ void JsAbilityLifecycleCallback::OnAbilityContinue(const std::shared_ptr &ability) +{ + CallJsMethod("onAbilityWillContinue", ability); +} + +void JsAbilityLifecycleCallback::OnWindowStageWillRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) +{ + CallWindowStageJsMethod("onWindowStageWillRestore", ability, windowStage); +} + +void JsAbilityLifecycleCallback::OnWindowStageRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) +{ + CallWindowStageJsMethod("onWindowStageRestore", ability, windowStage); +} + +void JsAbilityLifecycleCallback::OnAbilityWillSaveState(const std::shared_ptr &ability) +{ + CallJsMethod("onAbilityWillSaveState", ability); +} + +void JsAbilityLifecycleCallback::OnAbilitySaveState(const std::shared_ptr &ability) +{ + CallJsMethod("onAbilitySaveState", ability); +} + int32_t JsAbilityLifecycleCallback::Register(napi_value jsCallback, bool isSync) { TAG_LOGD(AAFwkTag::APPKIT, "enter"); diff --git a/frameworks/native/appkit/ability_runtime/context/application_context.cpp b/frameworks/native/appkit/ability_runtime/context/application_context.cpp index b9f37fb133..b9052269de 100644 --- a/frameworks/native/appkit/ability_runtime/context/application_context.cpp +++ b/frameworks/native/appkit/ability_runtime/context/application_context.cpp @@ -235,6 +235,88 @@ void ApplicationContext::DispatchOnAbilityContinue(const std::shared_ptr &ability) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilityWillContinue."); + if (ability == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability is nullptr."); + return; + } + + std::lock_guard lock(callbackLock_); + for (auto callback : callbacks_) { + if (callback != nullptr) { + callback->OnAbilityWillContinue(ability); + } + } +} + +void ApplicationContext::DispatchOnWindowStageWillRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onWindowStageWillRestore."); + if (ability == nullptr || windowStage == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability or windowStage is null."); + return; + } + + std::lock_guard lock(callbackLock_); + for (auto callback : callbacks_) { + if (callback != nullptr) { + callback->OnWindowStageWillRestore(ability, windowStage); + } + } +} + +void ApplicationContext::DispatchOnWindowStageRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onWindowStageRestore."); + if (ability == nullptr || windowStage == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability or windowStage is null."); + return; + } + + std::lock_guard lock(callbackLock_); + for (auto callback : callbacks_) { + if (callback != nullptr) { + callback->OnWindowStageRestore(ability, windowStage); + } + } +} + +void ApplicationContext::DispatchOnAbilityWillSaveState(const std::shared_ptr &ability) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilityWillSaveState."); + if (ability == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability is nullptr."); + return; + } + + std::lock_guard lock(callbackLock_); + for (auto callback : callbacks_) { + if (callback != nullptr) { + callback->OnAbilityWillSaveState(ability); + } + } +} + +void ApplicationContext::DispatchOnAbilitySaveState(const std::shared_ptr &ability) +{ + TAG_LOGD(AAFwkTag::APPKIT, "Dispatch onAbilitySaveState."); + if (ability == nullptr) { + TAG_LOGE(AAFwkTag::APPKIT, "Parameters invalid, ability is nullptr."); + return; + } + + std::lock_guard lock(callbackLock_); + for (auto callback : callbacks_) { + if (callback != nullptr) { + callback->OnAbilitySaveState(ability); + } + } +} + void ApplicationContext::DispatchConfigurationUpdated(const AppExecFwk::Configuration &config) { std::lock_guard lock(envCallbacksLock_); diff --git a/interfaces/kits/native/appkit/ability_runtime/context/ability_lifecycle_callback.h b/interfaces/kits/native/appkit/ability_runtime/context/ability_lifecycle_callback.h index 815034abc3..02417f1191 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/ability_lifecycle_callback.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/ability_lifecycle_callback.h @@ -212,6 +212,14 @@ public: * @StageModelOnly */ virtual void OnAbilityContinue(const std::shared_ptr &ability) = 0; + + virtual void OnAbilityWillContinue(const std::shared_ptr &ability) {} + virtual void OnWindowStageWillRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) {} + virtual void OnWindowStageRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) {} + virtual void OnAbilityWillSaveState(const std::shared_ptr &ability) {} + virtual void OnAbilitySaveState(const std::shared_ptr &ability) {} }; class JsAbilityLifecycleCallback : public AbilityLifecycleCallback, @@ -241,6 +249,13 @@ public: void OnAbilityForeground(const std::shared_ptr &ability) override; void OnAbilityBackground(const std::shared_ptr &ability) override; void OnAbilityContinue(const std::shared_ptr &ability) override; + void OnAbilityWillContinue(const std::shared_ptr &ability) override; + void OnWindowStageWillRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) override; + void OnWindowStageRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage) override; + void OnAbilityWillSaveState(const std::shared_ptr &ability) override; + void OnAbilitySaveState(const std::shared_ptr &ability) override; int32_t Register(napi_value jsCallback, bool isSync = false); bool UnRegister(int32_t callbackId, bool isSync = false); bool IsEmpty() const; 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 1e2d2355e4..cc594b7235 100644 --- a/interfaces/kits/native/appkit/ability_runtime/context/application_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/context/application_context.h @@ -54,6 +54,13 @@ public: void DispatchOnAbilityForeground(const std::shared_ptr &ability); void DispatchOnAbilityBackground(const std::shared_ptr &ability); void DispatchOnAbilityContinue(const std::shared_ptr &ability); + void DispatchOnAbilityWillContinue(const std::shared_ptr &ability); + void DispatchOnWindowStageWillRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage); + void DispatchOnWindowStageRestore(const std::shared_ptr &ability, + const std::shared_ptr &windowStage); + void DispatchOnAbilityWillSaveState(const std::shared_ptr &ability); + void DispatchOnAbilitySaveState(const std::shared_ptr &ability); void DispatchConfigurationUpdated(const AppExecFwk::Configuration &config); void DispatchMemoryLevel(const int level); void NotifyApplicationForeground(); From 9b20a59dbc8ff19c5f34f600cf9d1220583e2e2d Mon Sep 17 00:00:00 2001 From: hhl Date: Sat, 29 Jun 2024 18:01:53 +0800 Subject: [PATCH 120/148] change get bundleName Signed-off-by: hhl --- services/appdfr/include/appfreeze_manager.h | 11 ++- services/appdfr/src/appfreeze_manager.cpp | 70 ++++--------------- services/appmgr/src/app_mgr_service_inner.cpp | 14 ++-- 3 files changed, 28 insertions(+), 67 deletions(-) diff --git a/services/appdfr/include/appfreeze_manager.h b/services/appdfr/include/appfreeze_manager.h index 4b1319b0cb..0a6b615bba 100644 --- a/services/appdfr/include/appfreeze_manager.h +++ b/services/appdfr/include/appfreeze_manager.h @@ -81,10 +81,10 @@ public: bool IsProcessDebug(int32_t pid, std::string processName); bool IsNeedIgnoreFreezeEvent(int32_t pid); void DeleteStack(int pid); - bool CancelAppFreezeDetect(int32_t pid); - void RemoveDeathProcess(std::string processName); - void ResetAppfreezeState(int32_t pid); - bool IsValidFreezeFilter(int32_t pid); + bool CancelAppFreezeDetect(int32_t pid, const std::string& bundleName); + void RemoveDeathProcess(std::string bundleName); + void ResetAppfreezeState(int32_t pid, const std::string& bundleName); + bool IsValidFreezeFilter(int32_t pid, const std::string& bundleName); private: AppfreezeManager& operator=(const AppfreezeManager&) = delete; @@ -103,9 +103,6 @@ private: int GetFreezeState(int32_t pid); int64_t GetFreezeTime(int32_t pid); void ClearOldInfo(); - std::string FormatCmdLine(const std::string& cmdLine); - std::string GetProcessName(int32_t pid); - std::string GetBundleName(int32_t pid); static const inline std::string LOGGER_DEBUG_PROC_PATH = "/proc/transaction_proc"; std::string name_; diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index cfaa565bba..7ef54765a0 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -548,86 +548,44 @@ bool AppfreezeManager::IsNeedIgnoreFreezeEvent(int32_t pid) } } -std::string AppfreezeManager::FormatCmdLine(const std::string& cmdLine) +bool AppfreezeManager::CancelAppFreezeDetect(int32_t pid, const std::string& bundleName) { - std::string::size_type startPos = 0; - std::string::size_type endPos = cmdLine.size(); - for (std::string::size_type i = 0; i < cmdLine.size(); i++) { - if (cmdLine[i] == '/') { - startPos = i + 1; - } else if (cmdLine[i] == '\0') { - endPos = i; - break; - } - } - return cmdLine.substr(startPos, endPos - startPos); -} - -std::string AppfreezeManager::GetProcessName(int32_t pid) -{ - std::ifstream cmdLineFile("/proc/" + std::to_string(pid) + "/cmdline"); - std::string processName; - if (cmdLineFile) { - std::getline(cmdLineFile, processName); - cmdLineFile.close(); - processName = FormatCmdLine(processName); - return processName; - } else { - TAG_LOGI(AAFwkTag::APPDFR, "GetProcessName failed, pid: %{public}d", pid); - return ""; - } -} - -std::string AppfreezeManager::GetBundleName(int32_t pid) -{ - std::string processName = GetProcessName(pid); - if (processName.find(":") != std::string::npos) { - return processName.substr(0, processName.find(":")); - } - return processName; -} - -bool AppfreezeManager::CancelAppFreezeDetect(int32_t pid) -{ - std::string processName = GetBundleName(pid); - if (processName.empty()) { + if (bundleName.empty()) { return false; } std::lock_guard lock(freezeFilterMutex_); AppFreezeInfo info; info.pid = pid; info.state = AppFreezeState::APPFREEZE_STATE_CANCELING; - appfreezeFilterMap_.emplace(processName, info); + appfreezeFilterMap_.emplace(bundleName, info); return true; } -void AppfreezeManager::RemoveDeathProcess(std::string processName) +void AppfreezeManager::RemoveDeathProcess(std::string bundleName) { std::lock_guard lock(freezeFilterMutex_); - auto it = appfreezeFilterMap_.find(processName); + auto it = appfreezeFilterMap_.find(bundleName); if (it != appfreezeFilterMap_.end()) { - TAG_LOGD(AAFwkTag::APPDFR, "RemoveDeathProcess processName: %{public}s", - processName.c_str()); + TAG_LOGD(AAFwkTag::APPDFR, "RemoveDeathProcess bundleName: %{public}s", + bundleName.c_str()); appfreezeFilterMap_.erase(it); } } -void AppfreezeManager::ResetAppfreezeState(int32_t pid) +void AppfreezeManager::ResetAppfreezeState(int32_t pid, const std::string& bundleName) { - std::string processName = GetBundleName(pid); std::lock_guard lock(freezeFilterMutex_); - if (appfreezeFilterMap_.find(processName) != appfreezeFilterMap_.end()) { - TAG_LOGD(AAFwkTag::APPDFR, "ResetAppfreezeState processName: %{public}s", - processName.c_str()); - appfreezeFilterMap_[processName].state = AppFreezeState::APPFREEZE_STATE_CANCELED; + if (appfreezeFilterMap_.find(bundleName) != appfreezeFilterMap_.end()) { + TAG_LOGD(AAFwkTag::APPDFR, "ResetAppfreezeState bundleName: %{public}s", + bundleName.c_str()); + appfreezeFilterMap_[bundleName].state = AppFreezeState::APPFREEZE_STATE_CANCELED; } } -bool AppfreezeManager::IsValidFreezeFilter(int32_t pid) +bool AppfreezeManager::IsValidFreezeFilter(int32_t pid, const std::string& bundleName) { std::lock_guard lock(freezeFilterMutex_); - std::string processName = GetBundleName(pid); - if (appfreezeFilterMap_.find(processName) != appfreezeFilterMap_.end()) { + if (appfreezeFilterMap_.find(bundleName) != appfreezeFilterMap_.end()) { return false; } return true; diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index c353c86558..37acd7eb92 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5307,10 +5307,16 @@ int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData bool AppMgrServiceInner::SetAppFreezeFilter(int32_t pid) { int32_t callingPid = IPCSkeleton::GetCallingPid(); - if (callingPid == pid && AppExecFwk::AppfreezeManager::GetInstance()->IsValidFreezeFilter(pid)) { - bool cancelResult = AppExecFwk::AppfreezeManager::GetInstance()->CancelAppFreezeDetect(pid); - auto resetAppfreezeTask = [pid, innerService = shared_from_this()]() { - AppExecFwk::AppfreezeManager::GetInstance()->ResetAppfreezeState(pid); + auto callerRecord = GetAppRunningRecordByPid(pid); + if (callerRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "SetAppFreezeFilter callerRecord is nullptr, can not get callerBundleName."); + return false; + } + std::string bundleName = callerRecord->GetBundleName(); + if (callingPid == pid && AppExecFwk::AppfreezeManager::GetInstance()->IsValidFreezeFilter(pid, bundleName)) { + bool cancelResult = AppExecFwk::AppfreezeManager::GetInstance()->CancelAppFreezeDetect(pid, bundleName); + auto resetAppfreezeTask = [pid, bundleName, innerService = shared_from_this()]() { + AppExecFwk::AppfreezeManager::GetInstance()->ResetAppfreezeState(pid, bundleName); }; constexpr int32_t waitTime = 120000; // wait 2min taskHandler_->SubmitTask(resetAppfreezeTask, "resetAppfreezeTask", waitTime); From d6e06bccddf628478adf22cc3eb86ce05ccca60d Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Sat, 29 Jun 2024 19:20:07 +0800 Subject: [PATCH 121/148] foreground Signed-off-by: savior-xzh Change-Id: I43956afa1e6be94208051a6ac6f48cfc915aa32e --- services/abilitymgr/src/restart_app_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/abilitymgr/src/restart_app_manager.cpp b/services/abilitymgr/src/restart_app_manager.cpp index c64bb13605..077c8416e9 100644 --- a/services/abilitymgr/src/restart_app_manager.cpp +++ b/services/abilitymgr/src/restart_app_manager.cpp @@ -55,8 +55,7 @@ bool RestartAppManager::IsForegroundToRestartApp() const auto callerPid = IPCSkeleton::GetCallingPid(); AppExecFwk::RunningProcessInfo processInfo; DelayedSingleton::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo); - if (processInfo.state_ == AppProcessState::APP_STATE_FOREGROUND || processInfo.isFocused || - processInfo.isAbilityForegrounding) { + if (processInfo.isFocused || processInfo.isAbilityForegrounding) { return true; } TAG_LOGE(AAFwkTag::ABILITYMGR, "IsForegroundToRestartApp, app stae is not foreground."); From 1a85aa63c26f6a347eaad7a17c150b24557057a5 Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Fri, 28 Jun 2024 16:57:58 +0800 Subject: [PATCH 122/148] =?UTF-8?q?=E9=9C=B8=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: savior-xzh Change-Id: Iff9bd5d04382a01b988b1d0612727fd2427f03a5 --- services/abilitymgr/src/ability_manager_service.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 9b96841d7b..60a4d5525a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -931,6 +931,16 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo); + bool isDelegatorCall = processInfo.isTestProcess && want.GetBoolParam(IS_DELEGATOR_CALL, false); + if (callerToken == nullptr && !IsCallerSceneBoard() && !isDelegatorCall && !isForegroundToRestartApp && + !PermissionVerification::GetInstance()->IsSACall() && !PermissionVerification::GetInstance()->IsShellCall()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller is invalid."); + return ERR_INVALID_CALLER; + } { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "CHECK_DLP"); if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || From 0738cd2c7db1f6f6bbacdb257ae97816082b6864 Mon Sep 17 00:00:00 2001 From: xia Date: Sun, 30 Jun 2024 13:57:51 +0800 Subject: [PATCH 123/148] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dapplication=E7=94=9F?= =?UTF-8?q?=E5=91=BD=E5=91=A8=E6=9C=9F=E5=AE=89=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xia --- services/appmgr/src/app_mgr_service_inner.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 5eef5278b9..c8ca2005b6 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -933,8 +933,7 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); auto appRecord = GetAppRunningRecordByAppRecordId(recordId); - if (!appRecord || (!appRecord->IsUpdateStateFromService() - && appRecord->GetApplicationPendingState() != ApplicationPendingState::FOREGROUNDING)) { + if (!appRecord || appRecord->GetApplicationPendingState() != ApplicationPendingState::FOREGROUNDING) { TAG_LOGE(AAFwkTag::APPMGR, "get app record failed"); return; } From dd3943c4c9bb34982181f2120a0b17a0d6274bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Sun, 30 Jun 2024 06:05:41 +0000 Subject: [PATCH 124/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 1 - 1 file changed, 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 47cf1c9592..3a3097785b 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -207,7 +207,6 @@ struct SelectorPhoneDialog { .rowsGap(12) .margin({ top: 30 }) .height(210) - .align(Alignment.Center) }, item => item) } .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 }) From a58ea090cc5a43856b3e25c7680989dc2ebbe357 Mon Sep 17 00:00:00 2001 From: liweifeng Date: Sun, 30 Jun 2024 16:37:03 +0800 Subject: [PATCH 125/148] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20ui=20extension=20i?= =?UTF-8?q?nfo=20=E8=8E=B7=E5=8F=96=20inner=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liweifeng Change-Id: I48adb998f61a07a726a662aa46a4353e975128ae --- interfaces/inner_api/ability_manager/BUILD.gn | 1 + .../include/ability_manager_client.h | 11 ++++ .../include/ability_manager_interface.h | 16 ++++++ .../ability_manager_ipc_interface_code.h | 3 + .../include/ui_extension_session_info.h | 38 +++++++++++++ .../include/ability_connect_manager.h | 11 ++++ .../include/ability_manager_proxy.h | 11 ++++ .../include/ability_manager_service.h | 11 ++++ .../abilitymgr/include/ability_manager_stub.h | 1 + .../include/extension_record_manager.h | 7 ++- .../src/ability_connect_manager.cpp | 8 +++ .../abilitymgr/src/ability_manager_client.cpp | 9 +++ .../abilitymgr/src/ability_manager_proxy.cpp | 41 ++++++++++++++ .../src/ability_manager_service.cpp | 28 ++++++++++ .../abilitymgr/src/ability_manager_stub.cpp | 30 ++++++++++ .../src/extension_record_manager.cpp | 31 +++++++++++ .../src/ui_extension_session_info.cpp | 55 +++++++++++++++++++ 17 files changed, 310 insertions(+), 2 deletions(-) create mode 100755 interfaces/inner_api/ability_manager/include/ui_extension_session_info.h create mode 100755 services/abilitymgr/src/ui_extension_session_info.cpp diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 8c51078db6..85dd19c377 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -197,6 +197,7 @@ ohos_shared_library("ability_manager") { "${ability_runtime_services_path}/abilitymgr/src/system_ability_token_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_ability_connect_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/ui_extension_host_info.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ui_extension_session_info.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_proxy.cpp", "${ability_runtime_services_path}/abilitymgr/src/user_callback_stub.cpp", "${ability_runtime_services_path}/abilitymgr/src/want_receiver_stub.cpp", 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 41799952e9..7953d7287b 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1408,6 +1408,17 @@ public: ErrCode GetUIExtensionRootHostInfo(const sptr token, UIExtensionHostInfo &hostInfo, int32_t userId = DEFAULT_INVAL_VALUE); + /** + * @brief Get ui extension session info + * + * @param token The ability token. + * @param uiExtensionSessionInfo The ui extension session info. + * @param userId The user id. + * @return int32_t Returns ERR_OK on success, others on failure. + */ + ErrCode GetUIExtensionSessionInfo(const sptr token, UIExtensionSessionInfo &uiExtensionSessionInfo, + int32_t userId = DEFAULT_INVAL_VALUE); + /** * @brief Restart app self. * @param want The ability type must be UIAbility. 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 cbd89b0fe0..e52e0a6120 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -53,6 +53,7 @@ #include "system_memory_attr.h" #include "ui_extension_ability_connect_info.h" #include "ui_extension_host_info.h" +#include "ui_extension_session_info.h" #include "ui_extension_window_command.h" #include "uri.h" #include "want.h" @@ -76,6 +77,7 @@ using InsightIntentExecuteParam = AppExecFwk::InsightIntentExecuteParam; using InsightIntentExecuteResult = AppExecFwk::InsightIntentExecuteResult; using UIExtensionAbilityConnectInfo = AbilityRuntime::UIExtensionAbilityConnectInfo; using UIExtensionHostInfo = AbilityRuntime::UIExtensionHostInfo; +using UIExtensionSessionInfo = AbilityRuntime::UIExtensionSessionInfo; #ifdef SUPPORT_SCREEN using IAbilityFirstFrameStateObserver = AppExecFwk::IAbilityFirstFrameStateObserver; #endif @@ -1511,6 +1513,20 @@ public: return 0; } + /** + * @brief Get ui extension session info + * + * @param token The ability token. + * @param uiExtensionSessionInfo The ui extension session info. + * @param userId The user id. + * @return int32_t Returns ERR_OK on success, others on failure. + */ + virtual int32_t GetUIExtensionSessionInfo(const sptr token, + UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId = DEFAULT_INVAL_VALUE) + { + return 0; + } + /** * @brief Restart app self. * @param want The ability type must be UIAbility. diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index b1df9a4286..be19807767 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -401,6 +401,9 @@ enum class AbilityManagerInterfaceCode { // ipc id for start UIExtension ability constrained embedded START_UI_EXTENSION_CONSTRAINED_EMBEDDED = 1064, + // get ui extension session info + GET_UI_EXTENSION_SESSION_INFO = 1065, + // ipc id for continue ability(1101) START_CONTINUATION = 1101, diff --git a/interfaces/inner_api/ability_manager/include/ui_extension_session_info.h b/interfaces/inner_api/ability_manager/include/ui_extension_session_info.h new file mode 100755 index 0000000000..9201916b32 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/ui_extension_session_info.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_UI_EXTENSION_SESSION_INFO_H +#define OHOS_ABILITY_RUNTIME_UI_EXTENSION_SESSION_INFO_H + +#include "parcel.h" +#include "session_info_constants.h" + +namespace OHOS { +namespace AbilityRuntime { +class UIExtensionSessionInfo : public Parcelable { +public: + UIExtensionSessionInfo() = default; + virtual ~UIExtensionSessionInfo() = default; + + bool Marshalling(Parcel &parcel) const override; + static UIExtensionSessionInfo *Unmarshalling(Parcel &parcel); + + int32_t persistentId = 0; + uint32_t hostWindowId = 0; + AAFwk::UIExtensionUsage uiExtensionUsage = AAFwk::UIExtensionUsage::MODAL; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_UI_EXTENSION_SESSION_INFO_H diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 526a98850b..183ec86a56 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -44,6 +44,7 @@ namespace AAFwk { using OHOS::AppExecFwk::AbilityType; using UIExtensionAbilityConnectInfo = AbilityRuntime::UIExtensionAbilityConnectInfo; using UIExtensionAbilityConnectManager = AbilityRuntime::ExtensionRecordManager; +using UIExtensionSessionInfo = AbilityRuntime::UIExtensionSessionInfo; /** * @class AbilityConnectManager * AbilityConnectManager provides a facility for managing service ability connection. @@ -301,6 +302,16 @@ public: std::shared_ptr GetUIExtensionRootHostInfo(const sptr token); + /** + * @brief Get ui extension session info + * + * @param token The ability token. + * @param uiExtensionSessionInfo The ui extension session info. + * @param userId The user id. + * @return int32_t Returns ERR_OK on success, others on failure. + */ + int32_t GetUIExtensionSessionInfo(const sptr token, UIExtensionSessionInfo &uiExtensionSessionInfo); + void CloseAssertDialog(const std::string &assertSessionId); void SignRestartAppFlag(const std::string &bundleName); diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 77717b3947..5ddeb1ee3d 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -1177,6 +1177,17 @@ public: int32_t GetUIExtensionRootHostInfo(const sptr token, UIExtensionHostInfo &hostInfo, int32_t userId = DEFAULT_INVAL_VALUE) override; + /** + * @brief Get ui extension session info + * + * @param token The ability token. + * @param uiExtensionSessionInfo The ui extension session info. + * @param userId The user id. + * @return int32_t Returns ERR_OK on success, others on failure. + */ + int32_t GetUIExtensionSessionInfo(const sptr token, UIExtensionSessionInfo &uiExtensionSessionInfo, + int32_t userId = DEFAULT_INVAL_VALUE) override; + /** * @brief Restart app self. * @param want The ability type must be UIAbility. diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index ab3f78dc45..826bff81b7 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1622,6 +1622,17 @@ public: int32_t GetUIExtensionRootHostInfo(const sptr token, UIExtensionHostInfo &hostInfo, int32_t userId = DEFAULT_INVAL_VALUE) override; + /** + * @brief Get ui extension session info + * + * @param token The ability token. + * @param uiExtensionSessionInfo The ui extension session info. + * @param userId The user id. + * @return int32_t Returns ERR_OK on success, others on failure. + */ + int32_t GetUIExtensionSessionInfo(const sptr token, UIExtensionSessionInfo &uiExtensionSessionInfo, + int32_t userId = DEFAULT_INVAL_VALUE) override; + /** * Set the enable status for starting and stopping resident processes. * The caller application can only set the resident status of the configured process. diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index e0f2423669..0049dc34a6 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -288,6 +288,7 @@ private: int32_t GetForegroundUIAbilitiesInner(MessageParcel &data, MessageParcel &reply); int32_t GetUIExtensionRootHostInfoInner(MessageParcel &data, MessageParcel &reply); + int32_t GetUIExtensionSessionInfoInner(MessageParcel &data, MessageParcel &reply); int32_t RestartAppInner(MessageParcel &data, MessageParcel &reply); int32_t RequestAssertFaultDialogInner(MessageParcel &data, MessageParcel &reply); int32_t NotifyDebugAssertResultInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/extension_record_manager.h b/services/abilitymgr/include/extension_record_manager.h index ff7879cee3..621d6fdf74 100644 --- a/services/abilitymgr/include/extension_record_manager.h +++ b/services/abilitymgr/include/extension_record_manager.h @@ -25,6 +25,7 @@ #include "ability_record.h" #include "extension_record.h" #include "ui_extension_host_info.h" +#include "ui_extension_session_info.h" namespace OHOS { namespace AbilityRuntime { @@ -89,14 +90,14 @@ public: int32_t CreateExtensionRecord(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName, std::shared_ptr &extensionRecord, int32_t &extensionRecordId); - + bool IsPreloadExtensionRecord(const AAFwk::AbilityRequest &abilityRequest, const std::string &hostBundleName, std::shared_ptr &extensionRecord, bool &isLoaded); int32_t AddPreloadUIExtensionRecord(const std::shared_ptr abilityRecord); void RemoveAllPreloadUIExtensionRecord(PreLoadUIExtensionMapKey &preLoadUIExtensionInfo); - + bool RemovePreloadUIExtensionRecord( const std::tuple extensionRecordMapKey); @@ -111,6 +112,8 @@ public: std::shared_ptr GetUIExtensionRootHostInfo(const sptr token); + int32_t GetUIExtensionSessionInfo(const sptr token, UIExtensionSessionInfo &uiExtensionSessionInfo); + void LoadTimeout(int32_t extensionRecordId); void ForegroundTimeout(int32_t extensionRecordId); void BackgroundTimeout(int32_t extensionRecordId); diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 2c9af82570..cc02df8349 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -2932,6 +2932,14 @@ std::shared_ptr AbilityConnectManager::GetUIExtensionRootH return uiExtensionAbilityRecordMgr_->GetUIExtensionRootHostInfo(token); } +int32_t AbilityConnectManager::GetUIExtensionSessionInfo(const sptr token, + UIExtensionSessionInfo &uiExtensionSessionInfo) +{ + CHECK_POINTER_AND_RETURN(token, ERR_NULL_OBJECT); + CHECK_POINTER_AND_RETURN(uiExtensionAbilityRecordMgr_, ERR_NULL_OBJECT); + return uiExtensionAbilityRecordMgr_->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); +} + void AbilityConnectManager::SignRestartAppFlag(const std::string &bundleName) { std::lock_guard lock(serviceMapMutex_); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 2f40567de3..b739aeaec9 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1843,6 +1843,15 @@ ErrCode AbilityManagerClient::GetUIExtensionRootHostInfo(const sptrGetUIExtensionRootHostInfo(token, hostInfo, userId); } +ErrCode AbilityManagerClient::GetUIExtensionSessionInfo(const sptr token, + UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "Get ui extension session info."); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo, userId); +} + int32_t AbilityManagerClient::RestartApp(const AAFwk::Want &want) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index eaa0675f88..e726a5bb3c 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -5072,6 +5072,47 @@ int32_t AbilityManagerProxy::GetUIExtensionRootHostInfo(const sptr token, + UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId) +{ + if (token == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Input param invalid."); + return ERR_INVALID_VALUE; + } + + MessageParcel data; + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write remote object failed."); + return INNER_ERR; + } + + if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write flag and token failed."); + return INNER_ERR; + } + + if (!data.WriteInt32(userId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write userId failed."); + return INNER_ERR; + } + + MessageParcel reply; + MessageOption option; + auto error = SendRequest(AbilityManagerInterfaceCode::GET_UI_EXTENSION_SESSION_INFO, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error); + return error; + } + + std::unique_ptr info(reply.ReadParcelable()); + if (info == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get host info failed."); + return INNER_ERR; + } + uiExtensionSessionInfo = *info; + return reply.ReadInt32(); +} + int32_t AbilityManagerProxy::RestartApp(const AAFwk::Want &want) { MessageParcel data; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 974f3c6fb2..d3e3b3b1da 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -10445,6 +10445,34 @@ int32_t AbilityManagerService::GetUIExtensionRootHostInfo(const sptr token, + UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Get ui extension host info."); + CHECK_POINTER_AND_RETURN(token, ERR_INVALID_VALUE); + + if (!AAFwk::PermissionVerification::GetInstance()->IsSACall() && !IsCallerSceneBoard()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Permission deny."); + return ERR_PERMISSION_DENIED; + } + + auto validUserId = GetValidUserId(userId); + auto connectManager = GetConnectManagerByUserId(validUserId); + if (connectManager == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Connect manager is nullptr, userId: %{public}d.", validUserId); + return ERR_INVALID_VALUE; + } + + auto ret = connectManager->GetUIExtensionSessionInfo(token, uiExtensionSessionInfo); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get ui extension session info failed."); + return ret; + } + + return ERR_OK; +} + int32_t AbilityManagerService::RestartApp(const AAFwk::Want &want) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call."); diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 96819038ac..6afdfc8849 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -544,6 +544,9 @@ int AbilityManagerStub::OnRemoteRequestInnerFourteenth(uint32_t code, MessagePar if (interfaceCode == AbilityManagerInterfaceCode::GET_UI_EXTENSION_ROOT_HOST_INFO) { return GetUIExtensionRootHostInfoInner(data, reply); } + if (interfaceCode == AbilityManagerInterfaceCode::GET_UI_EXTENSION_SESSION_INFO) { + return GetUIExtensionSessionInfoInner(data, reply); + } if (interfaceCode == AbilityManagerInterfaceCode::PRELOAD_UIEXTENSION_ABILITY) { return PreloadUIExtensionAbilityInner(data, reply); } @@ -3755,6 +3758,33 @@ int32_t AbilityManagerStub::GetUIExtensionRootHostInfoInner(MessageParcel &data, return NO_ERROR; } +int32_t AbilityManagerStub::GetUIExtensionSessionInfoInner(MessageParcel &data, MessageParcel &reply) +{ + sptr callerToken = nullptr; + if (data.ReadBool()) { + callerToken = data.ReadRemoteObject(); + if (callerToken == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller token is nullptr."); + return ERR_INVALID_VALUE; + } + } + + int32_t userId = data.ReadInt32(); + UIExtensionSessionInfo uiExtensionSessionInfo; + auto result = GetUIExtensionSessionInfo(callerToken, uiExtensionSessionInfo, userId); + if (!reply.WriteParcelable(&uiExtensionSessionInfo)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write ui extension session info failed."); + return ERR_INVALID_VALUE; + } + + if (!reply.WriteInt32(result)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write result failed."); + return ERR_INVALID_VALUE; + } + + return NO_ERROR; +} + int32_t AbilityManagerStub::RestartAppInner(MessageParcel &data, MessageParcel &reply) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call."); diff --git a/services/abilitymgr/src/extension_record_manager.cpp b/services/abilitymgr/src/extension_record_manager.cpp index 69ed57db37..a490bfd71d 100644 --- a/services/abilitymgr/src/extension_record_manager.cpp +++ b/services/abilitymgr/src/extension_record_manager.cpp @@ -589,6 +589,37 @@ std::shared_ptr ExtensionRecordManager::GetUIExtensionRoot return AAFwk::Token::GetAbilityRecordByToken(rootCallerToken); } +int32_t ExtensionRecordManager::GetUIExtensionSessionInfo( + const sptr token, UIExtensionSessionInfo &uiExtensionSessionInfo) +{ + if (token == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Input param invalid."); + return ERR_NULL_OBJECT; + } + + auto abilityRecord = AAFwk::Token::GetAbilityRecordByToken(token); + if (abilityRecord == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get ability record failed."); + return ERR_NULL_OBJECT; + } + + if (!AAFwk::UIExtensionUtils::IsUIExtension(abilityRecord->GetAbilityInfo().extensionAbilityType)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "Not ui extension ability."); + return ERR_INVALID_VALUE; + } + + auto sessionInfo = abilityRecord->GetSessionInfo(); + if (sessionInfo == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "session info is null."); + return ERR_NULL_OBJECT; + } + + uiExtensionSessionInfo.persistentId = sessionInfo->persistentId; + uiExtensionSessionInfo.hostWindowId = sessionInfo->hostWindowId; + uiExtensionSessionInfo.uiExtensionUsage = sessionInfo->uiExtensionUsage; + return ERR_OK; +} + std::shared_ptr ExtensionRecordManager::GetExtensionRecordById(int32_t extensionRecordId) { std::lock_guard lock(mutex_); diff --git a/services/abilitymgr/src/ui_extension_session_info.cpp b/services/abilitymgr/src/ui_extension_session_info.cpp new file mode 100755 index 0000000000..4eb5a8249e --- /dev/null +++ b/services/abilitymgr/src/ui_extension_session_info.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ui_extension_session_info.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AbilityRuntime { +UIExtensionSessionInfo *UIExtensionSessionInfo::Unmarshalling(Parcel &parcel) +{ + UIExtensionSessionInfo *info = new (std::nothrow) UIExtensionSessionInfo(); + if (info == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Create ui extension session info failed."); + return nullptr; + } + info->persistentId = parcel.ReadInt32(); + info->hostWindowId = parcel.ReadUint32(); + info->uiExtensionUsage = static_cast(parcel.ReadUint32()); + return info; +} + +bool UIExtensionSessionInfo::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(persistentId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write persistent id failed."); + return false; + } + + if (!parcel.WriteUint32(hostWindowId)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write host window id failed."); + return false; + } + + if (!parcel.WriteUint32(static_cast(uiExtensionUsage))) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write uiExtensionUsage failed."); + return false; + } + + return true; +} +} // namespace AbilityRuntime +} // namespace OHOS From 7babbeca1050406bc541940e727ef643b9b8ae04 Mon Sep 17 00:00:00 2001 From: mayunteng_1 Date: Mon, 1 Jul 2024 06:26:38 +0000 Subject: [PATCH 126/148] =?UTF-8?q?=E4=BF=AE=E6=94=B9OnAnr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: mayunteng_1 Change-Id: Ic4b592bf386ec9a43bc106acfebb9a7af5454425 --- .../applicationanrlistener_fuzzer.cpp | 2 +- .../dfr_test/appfreeze_inner_test/appfreeze_inner_test.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fuzztest/applicationanrlistener_fuzzer/applicationanrlistener_fuzzer.cpp b/test/fuzztest/applicationanrlistener_fuzzer/applicationanrlistener_fuzzer.cpp index 20dbf02568..76df529fbe 100755 --- a/test/fuzztest/applicationanrlistener_fuzzer/applicationanrlistener_fuzzer.cpp +++ b/test/fuzztest/applicationanrlistener_fuzzer/applicationanrlistener_fuzzer.cpp @@ -117,7 +117,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) // fuzz for ApplicationAnrListener auto applicationAnrListener = std::make_shared(); - applicationAnrListener->OnAnr(int32Param); + applicationAnrListener->OnAnr(int32Param, 0); // fuzz for FreeInstallManager auto abilityms = std::make_shared(); diff --git a/test/unittest/dfr_test/appfreeze_inner_test/appfreeze_inner_test.cpp b/test/unittest/dfr_test/appfreeze_inner_test/appfreeze_inner_test.cpp index 0eae9e539c..8c2aefc3f5 100644 --- a/test/unittest/dfr_test/appfreeze_inner_test/appfreeze_inner_test.cpp +++ b/test/unittest/dfr_test/appfreeze_inner_test/appfreeze_inner_test.cpp @@ -130,12 +130,12 @@ HWTEST_F(AppfreezeInnerTest, AppfreezeInner_IsNeedIgnoreFreezeEvent_001, TestSiz int32_t pid = static_cast(getprocpid()); std::shared_ptr listener = std::make_shared(); - listener->OnAnr(pid); + listener->OnAnr(pid, 0); int left = 61; // over 1min while (left > 0) { left = sleep(left); } - listener->OnAnr(pid); + listener->OnAnr(pid, 0); } /** From 934f340ba0fc8c9bece1c1209b2451a86aacde17 Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Tue, 25 Jun 2024 12:06:20 +0800 Subject: [PATCH 127/148] =?UTF-8?q?EmbeddableUIAbility=E5=A2=9E=E5=8A=A0op?= =?UTF-8?q?enlink=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- .../js_embeddable_ui_ability_context.cpp | 17 +++++++++++++++++ .../js_embeddable_ui_ability_context.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp b/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp index d65cc503d7..cff2dcca72 100644 --- a/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp +++ b/frameworks/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.cpp @@ -66,6 +66,11 @@ napi_value JsEmbeddableUIAbilityContext::StartAbility(napi_env env, napi_callbac GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbility); } +napi_value JsEmbeddableUIAbilityContext::OpenLink(napi_env env, napi_callback_info info) +{ + GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnOpenLink); +} + napi_value JsEmbeddableUIAbilityContext::StartAbilityForResult(napi_env env, napi_callback_info info) { GET_NAPI_INFO_AND_CALL(env, info, JsEmbeddableUIAbilityContext, OnStartAbilityForResult); @@ -187,6 +192,17 @@ napi_value JsEmbeddableUIAbilityContext::OnStartAbility(napi_env env, NapiCallba return jsAbilityContext_->OnStartAbility(env, info); } +napi_value JsEmbeddableUIAbilityContext::OnOpenLink(napi_env env, NapiCallbackInfo& info) +{ + if (screenMode_ == AAFwk::EMBEDDED_FULL_SCREEN_MODE) { + TAG_LOGI(AAFwkTag::UI_EXT, "Start openlink in embedded screen mode."); + CHECK_POINTER_RETURN(env, jsUIExtensionContext_); + return jsUIExtensionContext_->OnOpenLink(env, info); + } + CHECK_POINTER_RETURN(env, jsAbilityContext_); + return jsAbilityContext_->OnOpenLink(env, info); +} + napi_value JsEmbeddableUIAbilityContext::OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info) { if (screenMode_ == AAFwk::EMBEDDED_FULL_SCREEN_MODE) { @@ -524,6 +540,7 @@ napi_value JsEmbeddableUIAbilityContext::CreateJsEmbeddableUIAbilityContext(napi const char* moduleName = "JsEmbeddableUIAbilityContext"; BindNativeFunction(env, objValue, "startAbility", moduleName, StartAbility); + BindNativeFunction(env, objValue, "openLink", moduleName, OpenLink); BindNativeFunction(env, objValue, "startAbilityForResult", moduleName, StartAbilityForResult); BindNativeFunction(env, objValue, "connectServiceExtensionAbility", moduleName, ConnectAbility); BindNativeFunction(env, objValue, "disconnectServiceExtensionAbility", moduleName, DisconnectAbility); diff --git a/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h b/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h index 8ddc914ad8..a6def0cf90 100644 --- a/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h +++ b/interfaces/kits/native/ability/native/ui_extension_ability/js_embeddable_ui_ability_context.h @@ -37,6 +37,7 @@ public: ~JsEmbeddableUIAbilityContext() = default; static void Finalizer(napi_env env, void* data, void* hint); static napi_value StartAbility(napi_env env, napi_callback_info info); + static napi_value OpenLink(napi_env env, napi_callback_info info); static napi_value StartAbilityForResult(napi_env env, napi_callback_info info); static napi_value ConnectAbility(napi_env env, napi_callback_info info); static napi_value DisconnectAbility(napi_env env, napi_callback_info info); @@ -68,6 +69,7 @@ private: static void WrapJsUIExtensionContext(napi_env env, std::shared_ptr uiExtContext, napi_value &objValue, int32_t screenMode); napi_value OnStartAbility(napi_env env, NapiCallbackInfo& info); + napi_value OnOpenLink(napi_env env, NapiCallbackInfo& info); napi_value OnStartAbilityForResult(napi_env env, NapiCallbackInfo& info); napi_value OnConnectAbility(napi_env env, NapiCallbackInfo& info); napi_value OnDisconnectAbility(napi_env env, NapiCallbackInfo& info); From 589155aeff137649032472bb6902f02b00536ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Mon, 1 Jul 2024 06:54:23 +0000 Subject: [PATCH 128/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 5e48109e3b..0b34bfa971 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -207,7 +207,7 @@ struct SelectorPhoneDialog { .columnsGap(12) .rowsGap(12) .margin({ top: 30 }) - .height(210) + .height(240) .align(Alignment.Center) }, item => item) } From 67c7370507d17e65b4b5efa9e7d488dcfd7a5c53 Mon Sep 17 00:00:00 2001 From: zhanheng Date: Sat, 29 Jun 2024 09:43:58 +0800 Subject: [PATCH 129/148] modify heapdump api Signed-off-by: z00522183 Change-Id: I91c0b1eafb52a61ea0010eb5e2d5914a89d43319 --- frameworks/native/appkit/app/main_thread.cpp | 2 +- frameworks/native/runtime/js_runtime.cpp | 12 +++++++++--- interfaces/inner_api/runtime/include/cj_runtime.h | 2 +- interfaces/inner_api/runtime/include/js_runtime.h | 2 +- interfaces/inner_api/runtime/include/runtime.h | 2 +- .../mock/frameworks_kits_runtime_test/mock_runtime.h | 2 +- test/unittest/runtime_test/js_runtime_test.cpp | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index 118441082d..7f239b4982 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -2516,7 +2516,7 @@ void MainThread::HandleDumpHeap(bool isPrivate) }; ffrt::submit(taskFork, {}, {}, ffrt::task_attr().qos(ffrt::qos_user_initiated)); - runtime->DumpCpuProfile(isPrivate); + runtime->DumpCpuProfile(); } void MainThread::DestroyHeapProfiler() diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 9e190d33f4..8d6627c80c 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -1187,11 +1187,11 @@ void JsRuntime::RemoveTask(const std::string& name) jsEnv_->RemoveTask(name); } -void JsRuntime::DumpCpuProfile(bool isPrivate) +void JsRuntime::DumpCpuProfile() { auto nativeEngine = GetNativeEnginePointer(); CHECK_POINTER(nativeEngine); - nativeEngine->DumpCpuProfile(true, DumpFormat::JSON, isPrivate, false); + nativeEngine->DumpCpuProfile(); } void JsRuntime::DumpHeapSnapshot(bool isPrivate) @@ -1205,7 +1205,13 @@ void JsRuntime::DumpHeapSnapshot(uint32_t tid, bool isFullGC) { auto vm = GetEcmaVm(); CHECK_POINTER(vm); - DFXJSNApi::DumpHeapSnapshot(vm, 0, true, false, false, isFullGC, tid); + panda::ecmascript::DumpSnapShotOption dumpOption; + dumpOption.dumpFormat = panda::ecmascript::DumpFormat::JSON; + dumpOption.isVmMode = true; + dumpOption.isPrivate = false; + dumpOption.captureNumericValue = false; + dumpOption.isFullGC = isFullGC; + DFXJSNApi::DumpHeapSnapshot(vm, dumpOption, tid); } void JsRuntime::ForceFullGC(uint32_t tid) diff --git a/interfaces/inner_api/runtime/include/cj_runtime.h b/interfaces/inner_api/runtime/include/cj_runtime.h index cb68f2a087..291aa3ac05 100644 --- a/interfaces/inner_api/runtime/include/cj_runtime.h +++ b/interfaces/inner_api/runtime/include/cj_runtime.h @@ -61,7 +61,7 @@ public: void ForceFullGC() override {}; void ForceFullGC(uint32_t tid) override {}; void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}; - void DumpCpuProfile(bool isPrivate) override {}; + void DumpCpuProfile() override {}; void AllowCrossThreadExecution() override {}; void GetHeapPrepare() override {}; void RegisterUncaughtExceptionHandler(const CJUncaughtExceptionInfo& uncaughtExceptionInfo); diff --git a/interfaces/inner_api/runtime/include/js_runtime.h b/interfaces/inner_api/runtime/include/js_runtime.h index ceabd8f2b4..460c240d26 100644 --- a/interfaces/inner_api/runtime/include/js_runtime.h +++ b/interfaces/inner_api/runtime/include/js_runtime.h @@ -81,7 +81,7 @@ public: void PostSyncTask(const std::function& task, const std::string& name); void RemoveTask(const std::string& name); void DumpHeapSnapshot(bool isPrivate) override; - void DumpCpuProfile(bool isPrivate) override; + void DumpCpuProfile() override; void DestroyHeapProfiler() override; void ForceFullGC() override; void ForceFullGC(uint32_t tid) override; diff --git a/interfaces/inner_api/runtime/include/runtime.h b/interfaces/inner_api/runtime/include/runtime.h index 8d0f13be06..3efbd8f7e0 100644 --- a/interfaces/inner_api/runtime/include/runtime.h +++ b/interfaces/inner_api/runtime/include/runtime.h @@ -85,7 +85,7 @@ public: virtual void StartDebugMode(const DebugOption debugOption) = 0; virtual void DumpHeapSnapshot(bool isPrivate) = 0; - virtual void DumpCpuProfile(bool isPrivate) = 0; + virtual void DumpCpuProfile() = 0; virtual void DestroyHeapProfiler() = 0; virtual void ForceFullGC() = 0; virtual void ForceFullGC(uint32_t tid) = 0; diff --git a/test/mock/frameworks_kits_runtime_test/mock_runtime.h b/test/mock/frameworks_kits_runtime_test/mock_runtime.h index 4af4217006..d2ff739231 100644 --- a/test/mock/frameworks_kits_runtime_test/mock_runtime.h +++ b/test/mock/frameworks_kits_runtime_test/mock_runtime.h @@ -57,7 +57,7 @@ public: { return; } - void DumpCpuProfile(bool isPrivate) override + void DumpCpuProfile() override { return; } diff --git a/test/unittest/runtime_test/js_runtime_test.cpp b/test/unittest/runtime_test/js_runtime_test.cpp index 7d5abc7dbc..050e00772a 100755 --- a/test/unittest/runtime_test/js_runtime_test.cpp +++ b/test/unittest/runtime_test/js_runtime_test.cpp @@ -1465,7 +1465,7 @@ HWTEST_F(JsRuntimeTest, DumpCpuProfile_0100, TestSize.Level1) { auto jsRuntime = std::make_unique(); bool isPrivate = true; - jsRuntime->DumpCpuProfile(isPrivate); + jsRuntime->DumpCpuProfile(); EXPECT_TRUE(jsRuntime != nullptr); } From a1186963891ef68469509a1f4786500074fdccb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Mon, 1 Jul 2024 06:56:23 +0000 Subject: [PATCH 130/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index 0c9d5709c4..d79e53d7db 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -210,7 +210,7 @@ struct SelectorPhoneDialog { .height(240) }, item => item) } - .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 ,top: 10}) + .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4}) .align(Alignment.Center) .width('90%') .indicator(this.phoneShowData.totalCount() > 1) From a578eea1b0da6cb2ccf650b3142d2292f25e6930 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Mon, 1 Jul 2024 15:07:19 +0800 Subject: [PATCH 131/148] fix foreground timeuot Signed-off-by: gongyuechen --- .../scene_board/ui_ability_lifecycle_manager.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index ab7f2efb49..8b0c892696 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -116,17 +116,13 @@ int UIAbilityLifecycleManager::StartUIAbility(AbilityRequest &abilityRequest, sp TAG_LOGD(AAFwkTag::ABILITYMGR, "StartUIAbility, specifyTokenId is %{public}u.", abilityRequest.specifyTokenId); uiAbilityRecord->SetSpecifyTokenId(abilityRequest.specifyTokenId); - if (uiAbilityRecord->GetPendingState() == AbilityState::FOREGROUND) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "pending state is FOREGROUND."); + if (uiAbilityRecord->GetPendingState() != AbilityState::INITIAL) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "pending state is FOREGROUND or BACKGROUND, dropped."); uiAbilityRecord->SetPendingState(AbilityState::FOREGROUND); return ERR_OK; } else { - TAG_LOGD(AAFwkTag::ABILITYMGR, "pending state is not FOREGROUND."); + TAG_LOGD(AAFwkTag::ABILITYMGR, "pending state is not FOREGROUND or BACKGROUND."); uiAbilityRecord->SetPendingState(AbilityState::FOREGROUND); - if (uiAbilityRecord->IsLoading()) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "ability: %{public}s is loading.", abilityRequest.abilityInfo.name.c_str()); - return ERR_OK; - } } if (iter == sessionAbilityMap_.end()) { @@ -735,6 +731,11 @@ int UIAbilityLifecycleManager::MinimizeUIAbility(const std::shared_ptrGetAbilityInfo().name.c_str()); abilityRecord->SetMinimizeReason(fromUser); + if (abilityRecord->GetPendingState() != AbilityState::INITIAL) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "pending state is FOREGROUND or BACKGROUND, dropped."); + abilityRecord->SetPendingState(AbilityState::BACKGROUND); + return ERR_OK; + } abilityRecord->SetPendingState(AbilityState::BACKGROUND); if (!abilityRecord->IsAbilityState(AbilityState::FOREGROUND)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "ability state is not foreground"); @@ -1061,6 +1062,7 @@ void UIAbilityLifecycleManager::CompleteBackground(const std::shared_ptr::GetInstance()->MoveToBackground(abilityRecord->GetToken()); if (abilityRecord->GetPendingState() == AbilityState::FOREGROUND) { + abilityRecord->PostForegroundTimeoutTask(); abilityRecord->PostForegroundTimeoutTask(); DelayedSingleton::GetInstance()->MoveToForeground(abilityRecord->GetToken()); } else if (abilityRecord->GetPendingState() == AbilityState::BACKGROUND) { From db1bcf58c98e52320741ff5ec0b6f9c4c214c440 Mon Sep 17 00:00:00 2001 From: XKK Date: Mon, 1 Jul 2024 16:01:01 +0800 Subject: [PATCH 132/148] =?UTF-8?q?context=20=E9=87=8C=E9=9D=A2=E8=8E=B7?= =?UTF-8?q?=E5=8F=96mcc=E5=92=8Cmnc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- frameworks/native/runtime/js_data_struct_converter.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frameworks/native/runtime/js_data_struct_converter.cpp b/frameworks/native/runtime/js_data_struct_converter.cpp index e00e571ce1..8630ac898c 100644 --- a/frameworks/native/runtime/js_data_struct_converter.cpp +++ b/frameworks/native/runtime/js_data_struct_converter.cpp @@ -118,6 +118,13 @@ napi_value CreateJsConfiguration(napi_env env, const AppExecFwk::Configuration& std::string fontWeightScale = configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE); napi_set_named_property(env, object, "fontWeightScale", CreateJsValue(env, fontWeightScale == "" ? 1.0 : std::stod(fontWeightScale))); + + napi_set_named_property(env, object, "mcc", CreateJsValue(env, + configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MCC))); + + napi_set_named_property(env, object, "mnc", CreateJsValue(env, + configuration.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_MNC))); + return object; } From e2f565bfe49d63892c62ca064f098b93321eddd5 Mon Sep 17 00:00:00 2001 From: wangdengze Date: Mon, 1 Jul 2024 16:06:53 +0800 Subject: [PATCH 133/148] UAF Signed-off-by: wangdengze --- .../include/dataobs_mgr_client.h | 2 +- .../dataobsmgr/src/dataobs_mgr_client.cpp | 50 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h index ac4b7280aa..d6789dee21 100644 --- a/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h +++ b/interfaces/inner_api/dataobs_manager/include/dataobs_mgr_client.h @@ -112,7 +112,7 @@ private: * * @return Returns SUCCESS on success, others on failure. */ - Status Connect(); + std::pair> GetObsMgr(); void ResetService(); void OnRemoteDied(); diff --git a/services/dataobsmgr/src/dataobs_mgr_client.cpp b/services/dataobsmgr/src/dataobs_mgr_client.cpp index 45332c3593..a1193be328 100644 --- a/services/dataobsmgr/src/dataobs_mgr_client.cpp +++ b/services/dataobsmgr/src/dataobs_mgr_client.cpp @@ -80,10 +80,11 @@ DataObsMgrClient::~DataObsMgrClient() */ ErrCode DataObsMgrClient::RegisterObserver(const Uri &uri, sptr dataObserver) { - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - auto status = dataObsManger_->RegisterObserver(uri, dataObserver); + auto status = dataObsManger->RegisterObserver(uri, dataObserver); if (status != NO_ERROR) { return status; } @@ -104,10 +105,11 @@ ErrCode DataObsMgrClient::RegisterObserver(const Uri &uri, sptr dataObserver) { - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - auto status = dataObsManger_->UnregisterObserver(uri, dataObserver); + auto status = dataObsManger->UnregisterObserver(uri, dataObserver); if (status != NO_ERROR) { return status; } @@ -129,10 +131,11 @@ ErrCode DataObsMgrClient::UnregisterObserver(const Uri &uri, sptrNotifyChange(uri); + return dataObsManger->NotifyChange(uri); } /** @@ -140,43 +143,44 @@ ErrCode DataObsMgrClient::NotifyChange(const Uri &uri) * * @return Returns SUCCESS on success, others on failure. */ -Status DataObsMgrClient::Connect() +std::pair> DataObsMgrClient::GetObsMgr() { std::lock_guard lock(mutex_); if (dataObsManger_ != nullptr) { - return SUCCESS; + return std::make_pair(SUCCESS, dataObsManger_); } sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { TAG_LOGE(AAFwkTag::DBOBSMGR, "fail to get Registry"); - return GET_DATAOBS_SERVICE_FAILED; + return std::make_pair(GET_DATAOBS_SERVICE_FAILED, nullptr); } auto remoteObject = systemManager->CheckSystemAbility(DATAOBS_MGR_SERVICE_SA_ID); if (remoteObject == nullptr) { TAG_LOGE(AAFwkTag::DBOBSMGR, "fail to get systemAbility"); - return GET_DATAOBS_SERVICE_FAILED; + return std::make_pair(GET_DATAOBS_SERVICE_FAILED, nullptr); } dataObsManger_ = iface_cast(remoteObject); if (dataObsManger_ == nullptr) { TAG_LOGE(AAFwkTag::DBOBSMGR, "fail to get IDataObsMgr"); - return GET_DATAOBS_SERVICE_FAILED; + return std::make_pair(GET_DATAOBS_SERVICE_FAILED, nullptr); } sptr serviceDeathRecipient(new (std::nothrow) ServiceDeathRecipient(GetInstance())); dataObsManger_->AsObject()->AddDeathRecipient(serviceDeathRecipient); - return SUCCESS; + return std::make_pair(SUCCESS, dataObsManger_); } Status DataObsMgrClient::RegisterObserverExt(const Uri &uri, sptr dataObserver, bool isDescendants) { - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - auto status = dataObsManger_->RegisterObserverExt(uri, dataObserver, isDescendants); + auto status = dataObsManger->RegisterObserverExt(uri, dataObserver, isDescendants); if (status != SUCCESS) { return status; } @@ -189,10 +193,11 @@ Status DataObsMgrClient::RegisterObserverExt(const Uri &uri, sptr dataObserver) { - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - auto status = dataObsManger_->UnregisterObserverExt(uri, dataObserver); + auto status = dataObsManger->UnregisterObserverExt(uri, dataObserver); if (status != SUCCESS) { return status; } @@ -207,10 +212,11 @@ Status DataObsMgrClient::UnregisterObserverExt(const Uri &uri, sptr dataObserver) { - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - auto status = dataObsManger_->UnregisterObserverExt(dataObserver); + auto status = dataObsManger->UnregisterObserverExt(dataObserver); if (status != SUCCESS) { return status; } @@ -220,10 +226,11 @@ Status DataObsMgrClient::UnregisterObserverExt(sptr dataOb Status DataObsMgrClient::NotifyChangeExt(const ChangeInfo &changeInfo) { - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { return DATAOBS_SERVICE_NOT_CONNECTED; } - return dataObsManger_->NotifyChangeExt(changeInfo); + return dataObsManger->NotifyChangeExt(changeInfo); } void DataObsMgrClient::ResetService() @@ -236,7 +243,8 @@ void DataObsMgrClient::OnRemoteDied() { std::this_thread::sleep_for(std::chrono::seconds(RESUB_INTERVAL)); ResetService(); - if (Connect() != SUCCESS) { + auto [errCode, dataObsManger] = GetObsMgr(); + if (errCode != SUCCESS) { sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemManager == nullptr) { TAG_LOGE(AAFwkTag::DBOBSMGR, "System mgr is nullptr"); From 16b1e499af2ce88efb6acb0430aca6a9adfb6562 Mon Sep 17 00:00:00 2001 From: zhangyuhang72 Date: Mon, 1 Jul 2024 16:10:45 +0800 Subject: [PATCH 134/148] =?UTF-8?q?fix=E9=80=80=E5=87=BA=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E6=9E=9A=E4=B8=BE=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangyuhang72 Change-Id: Ia7cbc5212f437942a6c98b6507558050482c3881 --- services/abilitymgr/src/app_exit_reason_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/app_exit_reason_helper.cpp b/services/abilitymgr/src/app_exit_reason_helper.cpp index 1f11ab24bd..5c9a33206d 100644 --- a/services/abilitymgr/src/app_exit_reason_helper.cpp +++ b/services/abilitymgr/src/app_exit_reason_helper.cpp @@ -250,7 +250,7 @@ void AppExitReasonHelper::GetActiveAbilityListFromUIAbilityManager(int32_t uid, bool AppExitReasonHelper::IsExitReasonValid(const ExitReason &exitReason) { const Reason reason = exitReason.reason; - return reason >= REASON_MIN || reason <= REASON_MAX; + return reason >= REASON_MIN && reason <= REASON_MAX; } } // namespace AppExecFwk } // namespace OHOS From 8b6661735117612794d7de92d6bb1f0b87c7ca0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E8=89=AF=E4=BC=9F?= Date: Mon, 1 Jul 2024 08:30:49 +0000 Subject: [PATCH 135/148] update services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 夏良伟 --- .../entry/src/main/ets/pages/selectorPhoneDialog.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets index d79e53d7db..4c46f0e0df 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/pages/selectorPhoneDialog.ets @@ -206,11 +206,11 @@ struct SelectorPhoneDialog { .rowsTemplate(this.selector.swiper.gridRows) .columnsGap(12) .rowsGap(12) - .margin({ top: 30 }) - .height(240) + .margin({ top: 10 }) + .height(300) }, item => item) } - .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4}) + .indicatorStyle({ color: '#bebdc0', selectedColor: '#ff326Ce9', size: 4 }) .align(Alignment.Center) .width('90%') .indicator(this.phoneShowData.totalCount() > 1) From 446df957c247c631d5e7651cede771dfc0851163 Mon Sep 17 00:00:00 2001 From: savior-xzh Date: Mon, 1 Jul 2024 17:23:00 +0800 Subject: [PATCH 136/148] gettopability Signed-off-by: savior-xzh Change-Id: Idad75c7eee21425ac2ee2ca678be44e5ac4d9455 --- services/abilitymgr/src/ability_manager_service.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index b9074bba2b..1a86fe860a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -8185,6 +8185,10 @@ AppExecFwk::ElementName AbilityManagerService::GetTopAbility(bool isNeedLocalDev HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::ABILITYMGR, "%{public}s start.", __func__); AppExecFwk::ElementName elementName = {}; + if (!PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "caller can not use system-api."); + return elementName; + } #ifdef SUPPORT_GRAPHICS sptr token; int ret = IN_PROCESS_CALL(GetTopAbility(token)); From 4d4da290c321e4db5208a0517be13f7b1d9060d7 Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Mon, 1 Jul 2024 20:18:29 +0800 Subject: [PATCH 137/148] =?UTF-8?q?openLink=E6=8E=A5=E5=8F=A3=E9=9A=90?= =?UTF-8?q?=E5=BC=8F=E5=8C=B9=E9=85=8D=E6=97=B6=E4=BC=A0=E9=80=92action,?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=BB=98=E8=AE=A4=E5=BA=94=E7=94=A8=E6=8B=89?= =?UTF-8?q?=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- .../abilitymgr/src/implicit_start_processor.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/services/abilitymgr/src/implicit_start_processor.cpp b/services/abilitymgr/src/implicit_start_processor.cpp index 319ab7d48d..ba492ea992 100644 --- a/services/abilitymgr/src/implicit_start_processor.cpp +++ b/services/abilitymgr/src/implicit_start_processor.cpp @@ -372,6 +372,13 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, static_cast(AppExecFwk::GetAbilityInfoFlag::GET_ABILITY_INFO_ONLY_SYSTEM_APP); } + if (isOpenLink) { + std::string linkUriScheme = request.want.GetUri().GetScheme(); + if (linkUriScheme == HTTPS_SCHEME_NAME || linkUriScheme == HTTP_SCHEME_NAME) { + request.want.SetAction(ACTION_VIEW); + } + } + IN_PROCESS_CALL_WITHOUT_RET(bundleMgrHelper->ImplicitQueryInfos( request.want, abilityInfoFlag, userId, withDefault, abilityInfos, extensionInfos, findDefaultApp)); @@ -422,13 +429,6 @@ int ImplicitStartProcessor::GenerateAbilityRequestByAction(int32_t userId, } } - if (isOpenLink) { - std::string linkUriScheme = request.want.GetUri().GetScheme(); - if (linkUriScheme == HTTPS_SCHEME_NAME || linkUriScheme == HTTP_SCHEME_NAME) { - request.want.SetAction(ACTION_VIEW); - } - } - if (abilityInfos.size() == 1) { auto skillUri = abilityInfos.front().skillUri; SetTargetLinkInfo(skillUri, request.want); From 6c3aabb6bd89ff087a8eef738cb7a20ac12e85d8 Mon Sep 17 00:00:00 2001 From: liangzhao Date: Mon, 1 Jul 2024 13:29:32 +0000 Subject: [PATCH 138/148] fix cache mgr asan heap usf Signed-off-by: liangzhao --- services/abilitymgr/src/ability_cache_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_cache_manager.cpp b/services/abilitymgr/src/ability_cache_manager.cpp index e2271b2a56..b6e3763d04 100644 --- a/services/abilitymgr/src/ability_cache_manager.cpp +++ b/services/abilitymgr/src/ability_cache_manager.cpp @@ -163,7 +163,7 @@ std::shared_ptr AbilityCacheManager::GetAbilityRecInProcList(cons auto recIter = procRecordsInfo.recList.begin(); while (recIter != procRecordsInfo.recList.end()) { if (IsRecInfoSame(abilityRequest, *recIter)) { - std::shared_ptr &abilityRecord = *recIter; + std::shared_ptr abilityRecord = *recIter; procRecordsInfo.recList.erase(recIter); procRecordsInfo.cnt--; return abilityRecord; From 562295ace10345807c63aeb4367c726d9047cc19 Mon Sep 17 00:00:00 2001 From: ZitongLi Date: Mon, 1 Jul 2024 13:47:12 +0000 Subject: [PATCH 139/148] fix the crash of cpu profiler caused by ffrt Signed-off-by: ZitongLi Change-Id: I5acf540102a0620fd9f0154ed8a07826912e5889 --- frameworks/native/runtime/js_worker.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frameworks/native/runtime/js_worker.cpp b/frameworks/native/runtime/js_worker.cpp index fad54284f3..ef326f799d 100644 --- a/frameworks/native/runtime/js_worker.cpp +++ b/frameworks/native/runtime/js_worker.cpp @@ -100,7 +100,7 @@ void InitWorkerFunc(NativeEngine* nativeEngine) } if (g_debugMode) { - auto instanceId = getproctid(); + auto instanceId = arkNativeEngine->GetThreadIdOrTaskId(); std::string instanceName = "workerThread_" + std::to_string(instanceId); bool needBreakPoint = ConnectServerManager::Get().AddInstance(instanceId, instanceId, instanceName); if (g_nativeStart) { @@ -128,9 +128,9 @@ void OffWorkerFunc(NativeEngine* nativeEngine) } if (g_debugMode) { - auto instanceId = getproctid(); - ConnectServerManager::Get().RemoveInstance(instanceId); auto arkNativeEngine = static_cast(nativeEngine); + auto instanceId = arkNativeEngine->GetThreadIdOrTaskId(); + ConnectServerManager::Get().RemoveInstance(instanceId); auto vm = const_cast(arkNativeEngine->GetEcmaVm()); panda::JSNApi::StopDebugger(vm); } From 047afbbec06b7ba9d633e510b9a2e70005c10631 Mon Sep 17 00:00:00 2001 From: wangzhen Date: Tue, 2 Jul 2024 09:42:31 +0800 Subject: [PATCH 140/148] Blocked by mutex Signed-off-by: wangzhen --- services/abilitymgr/include/ability_connect_manager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 526a98850b..7c10bcec3d 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -595,12 +595,12 @@ private: const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; const std::string TASK_ON_ABILITY_DIED = "OnAbilityDiedTask"; - std::mutex serialMutex_; + ffrt::mutex serialMutex_; std::mutex connectMapMutex_; ConnectMapType connectMap_; - std::mutex serviceMapMutex_; + ffrt::mutex serviceMapMutex_; ServiceMapType serviceMap_; ServiceMapType terminatingExtensionMap_; From f4d71dc8451f969018fa19998fbe0fa1a293f6bd Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Tue, 2 Jul 2024 14:46:13 +0800 Subject: [PATCH 141/148] =?UTF-8?q?=E9=85=8D=E5=90=88=E5=8C=85=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=88=A0=E9=99=A4=E7=A9=BA=E6=8E=A5=E5=8F=A3GetBundle?= =?UTF-8?q?GidsByUid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- .../bundle_mgr_helper.cpp | 13 ------------- .../bundle_mgr_helper.h | 1 - services/appmgr/src/app_mgr_service_inner.cpp | 4 ---- .../common/include/mock_bundle_manager_service.h | 5 ----- .../include/mock_bundle_manager.h | 2 -- .../src/mock_bundle_manager.cpp | 6 ------ test/moduletest/mock/include/mock_bundle_mgr.h | 4 ---- .../bundle_mgr_helper_test.cpp | 14 -------------- 8 files changed, 49 deletions(-) diff --git a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp index bc79ee9e88..3bcfc8f1db 100644 --- a/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp +++ b/frameworks/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp @@ -713,19 +713,6 @@ bool BundleMgrHelper::QueryDataGroupInfos( return bundleMgr->QueryDataGroupInfos(bundleName, userId, infos); } -bool BundleMgrHelper::GetBundleGidsByUid(const std::string &bundleName, const int32_t &uid, std::vector &gids) -{ - TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called."); - auto bundleMgr = Connect(); - if (bundleMgr == nullptr) { - TAG_LOGE(AAFwkTag::BUNDLEMGRHELPER, "Failed to connect."); - return false; - } - - HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); - return bundleMgr->GetBundleGidsByUid(bundleName, uid, gids); -} - bool BundleMgrHelper::RegisterBundleEventCallback(const sptr &bundleEventCallback) { TAG_LOGD(AAFwkTag::BUNDLEMGRHELPER, "Called."); diff --git a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h index 8ea8710ed1..a7b8f81e58 100644 --- a/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h +++ b/interfaces/kits/native/appkit/ability_bundle_manager_helper/bundle_mgr_helper.h @@ -83,7 +83,6 @@ public: bool &findDefaultApp); bool CleanBundleDataFiles(const std::string &bundleName, int32_t userId, int32_t appCloneIndex); bool QueryDataGroupInfos(const std::string &bundleName, int32_t userId, std::vector &infos); - bool GetBundleGidsByUid(const std::string &bundleName, const int32_t &uid, std::vector &gids); bool RegisterBundleEventCallback(const sptr &bundleEventCallback); bool GetBundleInfos( const BundleFlag flag, std::vector &bundleInfos, int32_t userId = Constants::UNSPECIFIED_USERID); diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index e0ef1ca689..535439bd93 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2738,10 +2738,6 @@ int32_t AppMgrServiceInner::CreateStartMsg(const std::string &processName, uint3 TAG_LOGI(AAFwkTag::APPMGR, "apl is %{public}s, bundleName is %{public}s, startFlags is %{public}d", startMsg.apl.c_str(), bundleInfo.name.c_str(), startFlags); - if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleGidsByUid(bundleInfo.name, uid, startMsg.gids))) { - TAG_LOGE(AAFwkTag::APPMGR, "GetBundleGids is fail."); - return ERR_INVALID_OPERATION; - } autoSync.Sync(); return ERR_OK; } diff --git a/test/mock/common/include/mock_bundle_manager_service.h b/test/mock/common/include/mock_bundle_manager_service.h index b791cfbb70..08c79a5696 100644 --- a/test/mock/common/include/mock_bundle_manager_service.h +++ b/test/mock/common/include/mock_bundle_manager_service.h @@ -47,11 +47,6 @@ public: return overlayModuleProxy; } - bool GetBundleGidsByUid(const std::string &bundleName, const int &uid, std::vector &gids) - { - return true; - } - bool GetBundleInfo(const std::string &bundleName, const AppExecFwk::BundleFlag flag, AppExecFwk::BundleInfo &bundleInfo, int32_t userId) override { diff --git a/test/mock/services_appmgr_test/include/mock_bundle_manager.h b/test/mock/services_appmgr_test/include/mock_bundle_manager.h index ad2d3bbdd0..574959563b 100644 --- a/test/mock/services_appmgr_test/include/mock_bundle_manager.h +++ b/test/mock/services_appmgr_test/include/mock_bundle_manager.h @@ -100,8 +100,6 @@ public: const std::string& bundleName, const BundleFlag flag, BundleInfo& bundleInfo, int32_t userId) override; virtual bool GetBundleInfos( const BundleFlag flag, std::vector& bundleInfos, int32_t userId) override; - bool GetBundleGidsByUid( - const std::string& bundleName, const int& uid, std::vector& gids) override; virtual bool GetBundleGids(const std::string& bundleName, std::vector& gids) override; virtual bool GetHapModuleInfo(const AbilityInfo& abilityInfo, HapModuleInfo& hapModuleInfo); virtual bool GetHapModuleInfo( diff --git a/test/mock/services_appmgr_test/src/mock_bundle_manager.cpp b/test/mock/services_appmgr_test/src/mock_bundle_manager.cpp index e72157a97f..6ec416fd52 100644 --- a/test/mock/services_appmgr_test/src/mock_bundle_manager.cpp +++ b/test/mock/services_appmgr_test/src/mock_bundle_manager.cpp @@ -275,12 +275,6 @@ bool BundleMgrService::GetBundleInfos( return true; } -bool BundleMgrService::GetBundleGidsByUid( - const std::string& bundleName, const int& uid, std::vector& gids) -{ - return true; -} - void BundleMgrService::PushTestHelloIndexAbility(int index) { AbilityInfo info; diff --git a/test/moduletest/mock/include/mock_bundle_mgr.h b/test/moduletest/mock/include/mock_bundle_mgr.h index 5afeea0231..4469ddf249 100644 --- a/test/moduletest/mock/include/mock_bundle_mgr.h +++ b/test/moduletest/mock/include/mock_bundle_mgr.h @@ -329,10 +329,6 @@ public: bool GetApplicationInfo( const std::string& appName, const ApplicationFlag flag, const int userId, ApplicationInfo& appInfo) override; - virtual bool GetBundleGidsByUid(const std::string& bundleName, const int& uid, std::vector& gids) override - { - return true; - } bool ImplicitQueryInfos(const Want& want, int32_t flags, int32_t userId, bool withDefault, std::vector& abilityInfos, std::vector& extensionInfos) override; diff --git a/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp b/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp index f42dd485cc..1dfb8464fa 100644 --- a/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp +++ b/test/unittest/bundle_mgr_helper_test/bundle_mgr_helper_test.cpp @@ -265,20 +265,6 @@ HWTEST_F(BundleMgrHelperTest, BundleMgrHelperTest_QueryDataGroupInfos_001, TestS EXPECT_EQ(ret, false); } -/** - * @tc.name: BundleMgrHelperTest_GetBundleGidsByUid_001 - * @tc.desc: GetBundleGidsByUid - * @tc.type: FUNC - */ -HWTEST_F(BundleMgrHelperTest, BundleMgrHelperTest_GetBundleGidsByUid_001, TestSize.Level1) -{ - std::string bundleName; - int32_t uid = DEFAULT_USERID; - std::vector gids; - auto ret = bundleMgrHelper->GetBundleGidsByUid(bundleName, uid, gids); - EXPECT_EQ(ret, true); -} - /** * @tc.name: BundleMgrHelperTest_RegisterBundleEventCallback_001 * @tc.desc: RegisterBundleEventCallback From 92c3067bb575c96022edcc1aa047cf1c22f345f0 Mon Sep 17 00:00:00 2001 From: huzeshan Date: Tue, 2 Jul 2024 10:20:25 +0800 Subject: [PATCH 142/148] =?UTF-8?q?=E3=80=90=E5=BA=94=E7=94=A8=E7=83=AD?= =?UTF-8?q?=E5=90=AF=E9=9C=80=E6=B1=82=E3=80=91=E6=B8=85=E7=90=86=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E5=89=8D=E9=80=9A=E7=9F=A5=E9=80=80=E5=87=BA=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huzeshan --- .../appmgr/include/cache_process_manager.h | 1 + services/appmgr/src/app_running_record.cpp | 2 ++ services/appmgr/src/cache_process_manager.cpp | 28 +++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/services/appmgr/include/cache_process_manager.h b/services/appmgr/include/cache_process_manager.h index 482215f285..7e766df29e 100644 --- a/services/appmgr/include/cache_process_manager.h +++ b/services/appmgr/include/cache_process_manager.h @@ -44,6 +44,7 @@ public: void UpdateTypeByToken(const sptr &token, const std::shared_ptr &appRecord); void UpdateTypeByAbility(const std::shared_ptr &abilityRecord, const std::shared_ptr &appRecord); + void PrepareActivateCache(const std::shared_ptr &appRecord); private: bool IsAppAbilitiesEmpty(const std::shared_ptr &appRecord); int GetCurrentCachedProcNum(); diff --git a/services/appmgr/src/app_running_record.cpp b/services/appmgr/src/app_running_record.cpp index 09b0c7b773..fd929bc26a 100644 --- a/services/appmgr/src/app_running_record.cpp +++ b/services/appmgr/src/app_running_record.cpp @@ -658,6 +658,8 @@ void AppRunningRecord::ScheduleBackgroundRunning() void AppRunningRecord::ScheduleProcessSecurityExit() { if (appLifeCycleDeal_) { + auto appRecord = shared_from_this(); + DelayedSingleton::GetInstance()->PrepareActivateCache(appRecord); appLifeCycleDeal_->ScheduleProcessSecurityExit(); } } diff --git a/services/appmgr/src/cache_process_manager.cpp b/services/appmgr/src/cache_process_manager.cpp index 49b1a73ca9..0f6d8cef57 100644 --- a/services/appmgr/src/cache_process_manager.cpp +++ b/services/appmgr/src/cache_process_manager.cpp @@ -359,6 +359,8 @@ bool CacheProcessManager::KillProcessByRecord(const std::shared_ptrOnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_READY); // this uses ScheduleProcessSecurityExit appMgrSptr->KillApplicationByRecord(appRecord); return true; @@ -465,9 +467,31 @@ void CacheProcessManager::UpdateTypeByAbility(const std::shared_ptrGetBundleName().c_str(), srvExtRecords.size()); + TAG_LOGD(AAFwkTag::APPMGR, + "%{public}s of %{public}s is service, will not cache, service records size: %{public}zu.", + abilityInfo->name.c_str(), appRecord->GetBundleName().c_str(), srvExtRecords.size()); } } + +void CacheProcessManager::PrepareActivateCache(const std::shared_ptr &appRecord) +{ + HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); + if (!QueryEnableProcessCache()) { + return; + } + if (appRecord == nullptr) { + return; + } + if (!IsCachedProcess(appRecord)) { + return; + } + TAG_LOGD(AAFwkTag::APPMGR, "%{public}s needs activate.", appRecord->GetBundleName().c_str()); + auto appMgrSptr = appMgr_.lock(); + if (appMgrSptr == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appMgr is nullptr"); + return; + } + appMgrSptr->OnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_READY); +} } // namespace OHOS } // namespace AppExecFwk \ No newline at end of file From 7a0cc99a378fb71c9afbd5b0f26159b74aff6cf9 Mon Sep 17 00:00:00 2001 From: hhl Date: Tue, 2 Jul 2024 15:02:15 +0800 Subject: [PATCH 143/148] Input event occurs, report eventId. Signed-off-by: hhl --- .../native/appkit/dfr/appfreeze_inner.cpp | 1 + .../app_manager/include/appmgr/fault_data.h | 2 ++ .../app_manager/src/appmgr/fault_data.cpp | 12 +++++++ services/appdfr/src/appfreeze_manager.cpp | 31 +++++++++++++------ .../appdfr/src/application_anr_listener.cpp | 1 + services/appmgr/src/app_mgr_service_inner.cpp | 5 +-- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/frameworks/native/appkit/dfr/appfreeze_inner.cpp b/frameworks/native/appkit/dfr/appfreeze_inner.cpp index 32b2af337d..42c79941c0 100644 --- a/frameworks/native/appkit/dfr/appfreeze_inner.cpp +++ b/frameworks/native/appkit/dfr/appfreeze_inner.cpp @@ -170,6 +170,7 @@ int AppfreezeInner::AcquireStack(const FaultData& info, bool onlyMainThread) faultData.notifyApp = false; faultData.waitSaveState = false; faultData.forceExit = false; + faultData.eventId = it->eventId; bool isExit = IsExitApp(it->errorObject.name); if (isExit) { faultData.forceExit = true; diff --git a/interfaces/inner_api/app_manager/include/appmgr/fault_data.h b/interfaces/inner_api/app_manager/include/appmgr/fault_data.h index 4fc07219f0..c7703f7802 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/fault_data.h +++ b/interfaces/inner_api/app_manager/include/appmgr/fault_data.h @@ -64,6 +64,7 @@ struct FaultData : public Parcelable { bool notifyApp = false; bool forceExit = false; uint32_t state = 0; + int32_t eventId = -1; sptr token = nullptr; }; @@ -84,6 +85,7 @@ struct AppFaultDataBySA : public Parcelable { bool notifyApp = false; bool forceExit = false; uint32_t state = 0; + int32_t eventId = -1; sptr token = nullptr; }; } // namespace AppExecFwk diff --git a/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp b/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp index 57be82fe66..f9165469d6 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/fault_data.cpp @@ -60,6 +60,7 @@ bool FaultData::ReadFromParcel(Parcel &parcel) notifyApp = parcel.ReadBool(); forceExit = parcel.ReadBool(); state = parcel.ReadUint32(); + eventId = parcel.ReadInt32(); if (parcel.ReadBool()) { token = (static_cast(&parcel))->ReadRemoteObject(); } @@ -123,6 +124,11 @@ bool FaultData::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(eventId)) { + TAG_LOGE(AAFwkTag::APPMGR, "EventId [%{public}u] write int32 failed.", eventId); + return false; + } + if (token == nullptr) { if (!parcel.WriteBool(false)) { TAG_LOGE(AAFwkTag::APPMGR, "Token falge [false] write bool failed."); @@ -180,6 +186,7 @@ bool AppFaultDataBySA::ReadFromParcel(Parcel &parcel) notifyApp = parcel.ReadBool(); forceExit = parcel.ReadBool(); state = parcel.ReadUint32(); + eventId = parcel.ReadInt32(); if (parcel.ReadBool()) { token = (static_cast(&parcel))->ReadRemoteObject(); } @@ -248,6 +255,11 @@ bool AppFaultDataBySA::Marshalling(Parcel &parcel) const return false; } + if (!parcel.WriteInt32(eventId)) { + TAG_LOGE(AAFwkTag::APPMGR, "EventId [%{public}u] write int32 failed.", eventId); + return false; + } + if (token == nullptr) { if (!parcel.WriteBool(false)) { TAG_LOGE(AAFwkTag::APPMGR, "Token falge [false] write bool failed."); diff --git a/services/appdfr/src/appfreeze_manager.cpp b/services/appdfr/src/appfreeze_manager.cpp index 7ef54765a0..8cdd49504c 100644 --- a/services/appdfr/src/appfreeze_manager.cpp +++ b/services/appdfr/src/appfreeze_manager.cpp @@ -41,6 +41,7 @@ namespace AppExecFwk { namespace { constexpr char EVENT_UID[] = "UID"; constexpr char EVENT_PID[] = "PID"; +constexpr char EVENT_INPUT_ID[] = "INPUT_ID"; constexpr char EVENT_MESSAGE[] = "MSG"; constexpr char EVENT_PACKAGE_NAME[] = "PACKAGE_NAME"; constexpr char EVENT_PROCESS_NAME[] = "PROCESS_NAME"; @@ -134,6 +135,7 @@ int AppfreezeManager::AppfreezeHandleWithStack(const FaultData& faultData, const faultNotifyData.errorObject.message = faultData.errorObject.message; faultNotifyData.errorObject.stack = faultData.errorObject.stack; faultNotifyData.faultType = FaultDataType::APP_FREEZE; + faultNotifyData.eventId = faultData.eventId; HITRACE_METER_FMT(HITRACE_TAG_APP, "AppfreezeHandleWithStack pid:%d-name:%s", appInfo.pid, faultData.errorObject.name.c_str()); @@ -234,6 +236,7 @@ int AppfreezeManager::AcquireStack(const FaultData& faultData, const AppfreezeMa faultNotifyData.errorObject.message = faultData.errorObject.message; faultNotifyData.errorObject.stack = faultData.errorObject.stack; faultNotifyData.faultType = FaultDataType::APP_FREEZE; + faultNotifyData.eventId = faultData.eventId; std::string binderInfo; std::set pids = GetBinderPeerPids(binderInfo, pid); if (pids.empty()) { @@ -262,17 +265,25 @@ int AppfreezeManager::NotifyANR(const FaultData& faultData, const AppfreezeManag std::string appRunningUniqueId = ""; DelayedSingleton::GetInstance()->GetAppRunningUniqueIdByPid(appInfo.pid, appRunningUniqueId); - - int ret = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, faultData.errorObject.name, - OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_UID, appInfo.uid, EVENT_PID, appInfo.pid, - EVENT_PACKAGE_NAME, appInfo.bundleName, EVENT_PROCESS_NAME, appInfo.processName, EVENT_MESSAGE, - faultData.errorObject.message, EVENT_STACK, faultData.errorObject.stack, BINDER_INFO, binderInfo, - APP_RUNNING_UNIQUE_ID, appRunningUniqueId); - + int ret = -1; + if (faultData.errorObject.name == AppFreezeType::APP_INPUT_BLOCK) { + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, faultData.errorObject.name, + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_UID, appInfo.uid, EVENT_PID, appInfo.pid, + EVENT_PACKAGE_NAME, appInfo.bundleName, EVENT_PROCESS_NAME, appInfo.processName, EVENT_MESSAGE, + faultData.errorObject.message, EVENT_STACK, faultData.errorObject.stack, BINDER_INFO, binderInfo, + APP_RUNNING_UNIQUE_ID, appRunningUniqueId, EVENT_INPUT_ID, faultData.eventId); + } else { + HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK, faultData.errorObject.name, + OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, EVENT_UID, appInfo.uid, EVENT_PID, appInfo.pid, + EVENT_PACKAGE_NAME, appInfo.bundleName, EVENT_PROCESS_NAME, appInfo.processName, EVENT_MESSAGE, + faultData.errorObject.message, EVENT_STACK, faultData.errorObject.stack, BINDER_INFO, binderInfo, + APP_RUNNING_UNIQUE_ID, appRunningUniqueId); + } TAG_LOGI(AAFwkTag::APPDFR, - "reportEvent:%{public}s, pid:%{public}d, bundleName:%{public}s, appRunningUniqueId:%{public}s " - "hisysevent write ret = %{public}d.", - faultData.errorObject.name.c_str(), appInfo.pid, appInfo.bundleName.c_str(), appRunningUniqueId.c_str(), ret); + "reportEvent:%{public}s, pid:%{public}d, bundleName:%{public}s, appRunningUniqueId:%{public}s" + ", eventId:%{public}d hisysevent write ret = %{public}d.", + faultData.errorObject.name.c_str(), appInfo.pid, appInfo.bundleName.c_str(), appRunningUniqueId.c_str(), + faultData.eventId, ret); return 0; } diff --git a/services/appdfr/src/application_anr_listener.cpp b/services/appdfr/src/application_anr_listener.cpp index d0d77bb502..7f2866d356 100644 --- a/services/appdfr/src/application_anr_listener.cpp +++ b/services/appdfr/src/application_anr_listener.cpp @@ -40,6 +40,7 @@ void ApplicationAnrListener::OnAnr(int32_t pid, int32_t eventId) const faultData.waitSaveState = false; faultData.notifyApp = false; faultData.forceExit = false; + faultData.eventId = eventId; DelayedSingleton::GetInstance()->NotifyAppFaultBySA(faultData); } } // namespace AAFwk diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index e0ef1ca689..10c7dfe3d1 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -5295,8 +5295,8 @@ int32_t AppMgrServiceInner::NotifyAppFaultBySA(const AppFaultDataBySA &faultData } record->NotifyAppFault(transformedFaultData); TAG_LOGW(AAFwkTag::APPMGR, "FaultDataBySA is: name: %{public}s, faultType: %{public}s, uid: %{public}d," - "pid: %{public}d, bundleName: %{public}s", faultData.errorObject.name.c_str(), - FaultTypeToString(faultData.faultType).c_str(), uid, pid, bundleName.c_str()); + "pid: %{public}d, bundleName: %{public}s, eventId: %{public}d", faultData.errorObject.name.c_str(), + FaultTypeToString(faultData.faultType).c_str(), uid, pid, bundleName.c_str(), faultData.eventId); return ERR_OK; } TAG_LOGD(AAFwkTag::APPMGR, "this is not called by SA."); @@ -5339,6 +5339,7 @@ FaultData AppMgrServiceInner::ConvertDataTypes(const AppFaultDataBySA &faultData newfaultData.forceExit = faultData.forceExit; newfaultData.token = faultData.token; newfaultData.state = faultData.state; + newfaultData.eventId = faultData.eventId; return newfaultData; } From 92b6848ae91803d56e93ddad84bae55f3e1e211c Mon Sep 17 00:00:00 2001 From: yangxuguang-huawei Date: Mon, 27 May 2024 09:23:43 +0800 Subject: [PATCH 144/148] feat: refactor uiability start animation Signed-off-by: yangxuguang-huawei --- .../service_extension_context.js | 5 + .../js/napi/wantConstant/want_constant.cpp | 5 + .../ability_business_error.cpp | 5 +- .../native/js_service_extension_context.cpp | 79 +++ .../service_extension_context.cpp | 13 + .../include/ability_manager_client.h | 12 + .../include/ability_manager_errors.h | 5 + .../include/ability_manager_interface.h | 15 + .../ability_manager_ipc_interface_code.h | 3 + .../ability_business_error.h | 3 + .../service_extension_context.h | 3 + .../include/ability_manager_proxy.h | 12 + .../include/ability_manager_service.h | 50 ++ .../abilitymgr/include/ability_manager_stub.h | 1 + .../abilitymgr/include/free_install_manager.h | 67 ++- .../ui_ability_lifecycle_manager.h | 8 +- .../abilitymgr/src/ability_manager_client.cpp | 9 + .../abilitymgr/src/ability_manager_proxy.cpp | 33 ++ .../src/ability_manager_service.cpp | 553 +++++++++++++++--- .../abilitymgr/src/ability_manager_stub.cpp | 14 + .../abilitymgr/src/free_install_manager.cpp | 179 +++++- .../ui_ability_lifecycle_manager.cpp | 23 +- .../common/include/permission_constants.h | 1 + .../common/include/permission_verification.h | 2 + .../common/src/permission_verification.cpp | 12 + 25 files changed, 999 insertions(+), 113 deletions(-) diff --git a/frameworks/js/napi/service_extension_context/service_extension_context.js b/frameworks/js/napi/service_extension_context/service_extension_context.js index 548bdfb6a1..717724ceed 100644 --- a/frameworks/js/napi/service_extension_context/service_extension_context.js +++ b/frameworks/js/napi/service_extension_context/service_extension_context.js @@ -154,6 +154,11 @@ class ServiceExtensionContext extends ExtensionContext { return; }); } + + preStartMission(bundleName, moduleName, abilityName, startTime) { + console.log('preStartMission'); + return this.__context_impl__.preStartMission(bundleName, moduleName, abilityName, startTime); + } } export default ServiceExtensionContext; diff --git a/frameworks/js/napi/wantConstant/want_constant.cpp b/frameworks/js/napi/wantConstant/want_constant.cpp index 406a449b7b..9bda492061 100644 --- a/frameworks/js/napi/wantConstant/want_constant.cpp +++ b/frameworks/js/napi/wantConstant/want_constant.cpp @@ -114,6 +114,11 @@ napi_value WantConstantInit(napi_env env, napi_value exports) SetNamedProperty(env, params, "ohos.extra.param.key.supportContinueSourceExit", "SUPPORT_CONTINUE_SOURCE_EXIT_KEY"); SetNamedProperty(env, params, "ohos.extra.param.key.showMode", "SHOW_MODE_KEY"); SetNamedProperty(env, params, "ohos.extra.param.key.appCloneIndex", "APP_CLONE_INDEX_KEY"); + SetNamedProperty(env, params, "ohos.param.atomicservice.pagePath", "PAGE_PATH"); + SetNamedProperty(env, params, "ohos.param.atomicservice.routerName", "ROUTER_NAME"); + SetNamedProperty(env, params, "ohos.param.atomicservice.pageSourceFile", "PAGE_SOURCE_FILE"); + SetNamedProperty(env, params, "ohos.param.atomicservice.buildFunction", "BUILD_FUNCTION"); + SetNamedProperty(env, params, "ohos.param.atomicservice.subpackageName", "SUB_PACKAGE_NAME"); napi_property_descriptor exportFuncs[] = { DECLARE_NAPI_PROPERTY("Action", action), DECLARE_NAPI_PROPERTY("Entity", entity), diff --git a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp index c067148df6..1df63993d6 100644 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -85,6 +85,7 @@ constexpr const char* ERROR_MSG_NOT_APP_CLONE = "The target app is not Clone."; constexpr const char* ERROR_MSG_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED = "The extension can not start the specified third party application."; constexpr const char* ERROR_MSG_EXTENSION_START_SERVICE_CONTROLLED = "The extension can not start the service."; +constexpr const char* ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST = "The target free install task does not exist."; // follow ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST of appexecfwk_errors.h in bundle_framework constexpr int32_t ERR_BUNDLE_MANAGER_BUNDLE_NOT_EXIST = 8521220; @@ -144,7 +145,8 @@ static std::unordered_map ERR_CODE_MAP = { { AbilityErrorCode::ERROR_CODE_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED, ERROR_MSG_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED }, { AbilityErrorCode::ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED, ERROR_MSG_EXTENSION_START_SERVICE_CONTROLLED}, - { AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST} + { AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID, ERROR_MSG_TARGET_BUNDLE_NOT_EXIST}, + { AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST, ERROR_MSG_FREE_INSTALL_TASK_NOT_EXIST } }; static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { @@ -207,6 +209,7 @@ static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP AbilityErrorCode::ERROR_CODE_EXTENSION_START_THIRD_PARTY_APP_CONTROLLED}, {EXTENSION_BLOCKED_BY_SERVICE_LIST, AbilityErrorCode::ERROR_CODE_EXTENSION_START_SERVICE_CONTROLLED}, {ERR_BUNDLE_NOT_EXIST, AbilityErrorCode::ERROR_CODE_BUNDLE_NAME_INVALID}, + {ERR_FREE_INSTALL_TASK_NOT_EXIST, AbilityErrorCode::ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST}, }; } diff --git a/frameworks/native/ability/native/js_service_extension_context.cpp b/frameworks/native/ability/native/js_service_extension_context.cpp index 5507b4343f..fe1df2a755 100644 --- a/frameworks/native/ability/native/js_service_extension_context.cpp +++ b/frameworks/native/ability/native/js_service_extension_context.cpp @@ -45,12 +45,14 @@ namespace { constexpr int32_t INDEX_ZERO = 0; constexpr int32_t INDEX_ONE = 1; constexpr int32_t INDEX_TWO = 2; +constexpr int32_t INDEX_THREE = 3; constexpr int32_t ERROR_CODE_ONE = 1; constexpr int32_t ERROR_CODE_TWO = 2; constexpr size_t ARGC_ZERO = 0; constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_THREE = 3; +constexpr size_t ARGC_FOUR = 4; class StartAbilityByCallParameters { public: @@ -170,6 +172,11 @@ public: GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnRequestModalUIExtension); } + static napi_value PreStartMission(napi_env env, napi_callback_info info) + { + GET_NAPI_INFO_AND_CALL(env, info, JsServiceExtensionContext, OnPreStartMission); + } + private: std::weak_ptr context_; sptr freeInstallObserver_ = nullptr; @@ -1043,6 +1050,76 @@ private: return result; } + bool ParsePreStartMissionArgs(const napi_env &env, const NapiCallbackInfo &info, std::string& bundleName, + std::string& moduleName, std::string& abilityName, std::string& startTime) + { + if (info.argc < ARGC_FOUR) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "wrong arguments num"); + ThrowTooFewParametersError(env); + return false; + } + + std::string args[ARGC_FOUR]; + for (size_t i = 0; i < ARGC_FOUR; i++) { + if (!CheckTypeForNapiValue(env, info.argv[i], napi_string)) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "param must be string"); + return false; + } + if (!ConvertFromJsValue(env, info.argv[i], args[i])) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "parameter invalid"); + return false; + } + } + + bundleName = args[INDEX_ZERO]; + moduleName = args[INDEX_ONE]; + abilityName = args[INDEX_TWO]; + startTime = args[INDEX_THREE]; + + return true; + } + + napi_value OnPreStartMission(napi_env env, NapiCallbackInfo& info) + { + TAG_LOGD(AAFwkTag::SERVICE_EXT, "called"); + if (info.argc < ARGC_FOUR) { + ThrowTooFewParametersError(env); + return CreateJsUndefined(env); + } + + std::string bundleName; + std::string moduleName; + std::string abilityName; + std::string startTime; + if (!ParsePreStartMissionArgs(env, info, bundleName, moduleName, abilityName, startTime)) { + TAG_LOGE(AAFwkTag::SERVICE_EXT, "parse preStartMission arguments failed"); + ThrowInvalidParamError(env, "Parse params failed, params must be strings."); + return CreateJsUndefined(env); + } + + NapiAsyncTask::CompleteCallback complete = + [weak = context_, bundleName, moduleName, abilityName, startTime]( + napi_env env, NapiAsyncTask& task, int32_t status) { + auto context = weak.lock(); + if (!context) { + TAG_LOGW(AAFwkTag::SERVICE_EXT, "context is released"); + task.Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER)); + return; + } + auto errcode = context->PreStartMission(bundleName, moduleName, abilityName, startTime); + if (errcode == 0) { + task.ResolveWithNoError(env, CreateJsUndefined(env)); + return; + } + task.Reject(env, CreateJsErrorByNativeErr(env, errcode)); + }; + + napi_value result = nullptr; + NapiAsyncTask::ScheduleHighQos("JSServiceExtensionContext::OnPreStartMission", + env, CreateAsyncTaskWithLastParam(env, nullptr, nullptr, std::move(complete), &result)); + return result; + } + NapiAsyncTask::ExecuteCallback GetStartAbilityExecFunc(const AAFwk::Want &want, const AAFwk::StartOptions &startOptions, int32_t userId, bool useOption, std::shared_ptr retCode) { @@ -1154,6 +1231,8 @@ napi_value CreateJsServiceExtensionContext(napi_env env, std::shared_ptrtype; } + +ErrCode ServiceExtensionContext::PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) +{ + TAG_LOGI(AAFwkTag::APPKIT, "Called."); + ErrCode err = AAFwk::AbilityManagerClient::GetInstance()->PreStartMission( + bundleName, moduleName, abilityName, startTime); + if (err != ERR_OK) { + TAG_LOGE(AAFwkTag::APPKIT, "ServiceExtensionContext::PreStartMission is failed %{public}d", err); + } + TAG_LOGI(AAFwkTag::APPKIT, "End."); + return err; +} } // namespace AbilityRuntime } // namespace OHOS 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 ec1bc2bb16..ae28461a43 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_client.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_client.h @@ -1499,6 +1499,18 @@ public: */ void NotifyFrozenProcessByRSS(const std::vector &pidList, int32_t uid); + /** + * Open atomic service window prior to finishing free install. + * + * @param bundleName, the bundle name of the atomic service. + * @param moduleName, the module name of the atomic service. + * @param abilityName, the ability name of the atomic service. + * @param startTime, the starting time of the free install task. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime); + private: AbilityManagerClient(); DISALLOW_COPY_AND_MOVE(AbilityManagerClient); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 531e2a7c6b..d87203b303 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -550,6 +550,11 @@ enum { */ ERR_BUNDLE_NOT_EXIST, + /* + * Result (2097260) for target free install task does not exist. + */ + ERR_FREE_INSTALL_TASK_NOT_EXIST = 2097260, + /** * Native error(3000000) for target bundle not exist. */ 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 2d1974bf9c..8d8418726e 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -1632,6 +1632,21 @@ public: { return; } + + /** + * Open atomic service window prior to finishing free install. + * + * @param bundleName, the bundle name of the atomic service. + * @param moduleName, the module name of the atomic service. + * @param abilityName, the ability name of the atomic service. + * @param startTime, the starting time of the free install task. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h index b1df9a4286..eb493e49a4 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_ipc_interface_code.h @@ -447,6 +447,9 @@ enum class AbilityManagerInterfaceCode { // ipc for notify frozen process by RSS NOTIFY_FROZEN_PROCESS_BY_RSS = 1130, + // ipc id for pre-start mission + PRE_START_MISSION = 1135, + // ipc id 2001-3000 for tools // ipc id for dumping state (2001) DUMP_STATE = 2001, diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index d17d0afba0..424f861a83 100644 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -179,6 +179,9 @@ enum class AbilityErrorCode { ERROR_CODE_SET_SUPPORTED_PROCESS_CACHE_AGAIN = 16300006, + // target free install task does not exist. + ERROR_CODE_FREE_INSTALL_TASK_NOT_EXIST = 16300007, + ERROR_CODE_BUNDLE_NAME_INVALID = 18500001, }; diff --git a/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h b/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h index e50ebbdc46..8a2fc9cff6 100644 --- a/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h +++ b/interfaces/kits/native/appkit/ability_runtime/service_extension_context.h @@ -158,6 +158,9 @@ public: ErrCode RequestModalUIExtension(const Want &want); + ErrCode PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime); + using SelfType = ServiceExtensionContext; static const size_t CONTEXT_TYPE_ID; diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 5f0815559e..3a930db0bb 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -1268,6 +1268,18 @@ public: */ virtual void NotifyFrozenProcessByRSS(const std::vector &pidList, int32_t uid) override; + /** + * Open atomic service window prior to finishing free install. + * + * @param bundleName, the bundle name of the atomic service. + * @param moduleName, the module name of the atomic service. + * @param abilityName, the ability name of the atomic service. + * @param startTime, the starting time of the free install task. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 43d3ff7022..ab4d88d7ca 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -16,6 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H #define OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H +#include #include #include #include @@ -30,6 +31,7 @@ #include "ability_connect_manager.h" #include "ability_debug_deal.h" #include "ability_event_handler.h" +#include "ability_info.h" #include "ability_manager_event_subscriber.h" #include "ability_manager_stub.h" #include "ams_configuration_parameter.h" @@ -83,6 +85,7 @@ enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; constexpr int32_t BASE_USER_RANGE = 200000; constexpr int32_t U0_USER_ID = 0; constexpr int32_t INVALID_USER_ID = -1; +constexpr const char* KEY_SESSION_ID = "com.ohohs.param.sessionId"; using OHOS::AppExecFwk::IAbilityController; class PendingWantManager; struct StartAbilityInfo; @@ -1698,6 +1701,23 @@ public: void HandleRestartResidentProcessDependedOnWeb(); + /** + * Open atomic service window prior to finishing free install. + * + * @param bundleName, the bundle name of the atomic service. + * @param moduleName, the module name of the atomic service. + * @param abilityName, the ability name of the atomic service. + * @param startTime, the starting time of the free install task. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) override; + + int32_t StartUIAbilityByPreInstall(const FreeInstallInfo &taskInfo); + + void NotifySCBToHandleException(sptr callerToken, int errCode, + const std::string& reason); + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; @@ -1808,6 +1828,12 @@ private: int StartRemoteAbility(const Want &want, int requestCode, int32_t validUserId, const sptr &callerToken); + int StartUIAbilityBySCBDefault(sptr sessionInfo, bool &isColdStart); + int StartUIAbilityByPreInstallInner(sptr sessionInfo, + uint32_t specifyTokenId, bool &isColdStart); + int32_t PreStartInner(const FreeInstallInfo& taskInfo); + void RemovePreStartSession(const std::string& sessionId); + int ConnectLocalAbility( const Want &want, const int32_t userId, @@ -2172,6 +2198,28 @@ private: int CheckUIExtensionUsage(AppExecFwk::UIExtensionUsage uiExtensionUsage, AppExecFwk::ExtensionAbilityType extensionType); + int CheckExtensionCallPermission(const Want& want, const AbilityRequest& abilityRequest); + + int CheckServiceCallPermission(const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo); + + int CheckBrokerCallPermission(const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo); + + int CheckAbilityCallPermission(const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo, uint32_t specifyTokenId); + + int CheckCallPermission(const Want& want, const AppExecFwk::AbilityInfo& abilityInfo, + const AbilityRequest& abilityRequest, bool isForegroundToRestartApp, + bool isSendDialogResult, uint32_t specifyTokenId, + const std::string& callerBundleName); + + int StartAbilityByConnectManager(const Want& want, const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo, int validUserId, sptr callerToken); + + int PreStartFreeInstall(const Want &want, sptr callerToken, + uint32_t specifyTokenId, bool isStartAsCaller, Want &localWant); + constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; @@ -2194,8 +2242,10 @@ private: ffrt::mutex globalLock_; ffrt::mutex bgtaskObserverMutex_; ffrt::mutex abilityTokenLock_; + ffrt::mutex preStartSessionMapLock_; std::multimap timeoutMap_; + std::map> preStartSessionMap_; static sptr instance_; int32_t uniqueId_ = 0; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index e0f2423669..cf8242d279 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -295,6 +295,7 @@ private: int32_t GetAbilityStateByPersistentIdInner(MessageParcel &data, MessageParcel &reply); int32_t TransferAbilityResultForExtensionInner(MessageParcel &data, MessageParcel &reply); int32_t NotifyFrozenProcessByRSSInner(MessageParcel &data, MessageParcel &reply); + int32_t PreStartMissionInner(MessageParcel &data, MessageParcel &reply); int OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); int OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data, diff --git a/services/abilitymgr/include/free_install_manager.h b/services/abilitymgr/include/free_install_manager.h index 15285b8de1..fa4ca9c1fa 100644 --- a/services/abilitymgr/include/free_install_manager.h +++ b/services/abilitymgr/include/free_install_manager.h @@ -39,6 +39,9 @@ struct FreeInstallInfo { std::string identity; sptr callerToken = nullptr; sptr dmsCallback = nullptr; + bool isPreStartMissionCalled = false; + bool isStartUIAbilityBySCBCalled = false; + uint32_t specifyTokenId = 0; }; /** @@ -79,7 +82,7 @@ public: * @return Returns ERR_OK on success, others on failure. */ int StartFreeInstall(const Want &want, int32_t userId, int requestCode, const sptr &callerToken, - bool isAsync = false); + bool isAsync = false, uint32_t specifyTokenId = 0); /** * Start to remote free install. @@ -130,6 +133,60 @@ public: */ void OnRemoveTimeoutTask(const Want &want); + /** + * Get free install task info. + * + * @param bundleName, the bundle name of the task. + * @param abilityName, the ability name of the task. + * @param startTime, the start time of the task. + * @param taskInfo, the found task info + * @return Returns true on success, false on failure. + */ + bool GetFreeInstallTaskInfo(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, FreeInstallInfo& taskInfo); + + /** + * Get free install task info. + * + * @param sessionId, the sessionId of the task. + * @param taskInfo, the found task info + * @return Returns true on success, false on failure. + */ + bool GetFreeInstallTaskInfo(const std::string& sessionId, FreeInstallInfo& taskInfo); + + /** + * Set the isStartUIAbilityBySCBCalled flag of the given free install task. + * + * @param bundleName, the bundle name of the task. + * @param abilityName, the abilitu name of the task. + * @param startTime, the start time of the task. + * @param scbCallStatus, the status of whether StartUIAbilityBySCB is called. + */ + void SetSCBCallStatus(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, bool scbCallStatus); + + /** + * Set the isPreStartMissionCalled flag of the given free install task. + * + * @param bundleName, the bundle name of the task. + * @param abilityName, the abilitu name of the task. + * @param startTime, the start time of the task. + * @param preStartMissionCallStatus, the status of whether PreStartMission is called. + */ + void SetPreStartMissionCallStatus(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, bool preStartMissionCallStatus); + + /** + * Set the sessionId of the given free install task. + * + * @param bundleName, the bundle name of the task. + * @param abilityName, the abilitu name of the task. + * @param startTime, the start time of the task. + * @param sessionId, the sessionId of the free install task. + */ + void SetFreeInstallTaskSessionId(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, const std::string& sessionId); + private: std::weak_ptr server_; std::vector freeInstallList_; @@ -153,7 +210,7 @@ private: bool IsTopAbility(const sptr &callerToken); void NotifyFreeInstallResult(const Want &want, int resultCode, bool isAsync = false); FreeInstallInfo BuildFreeInstallInfo(const Want &want, int32_t userId, int requestCode, - const sptr &callerToken, bool isAsync); + const sptr &callerToken, bool isAsync, uint32_t specifyTokenId = 0); std::time_t GetTimeStamp(); void RemoveFreeInstallInfo(const std::string &bundleName, const std::string &abilityName, @@ -167,7 +224,13 @@ private: void StartAbilityByFreeInstall(FreeInstallInfo &info, std::string &bundleName, std::string &abilityName, std::string &startTime); + void StartAbilityByPreInstall(FreeInstallInfo &info, std::string &bundleName, std::string &abilityName, + std::string &startTime); int32_t UpdateElementName(Want &want, int32_t userId) const; + void HandleFreeInstallResult(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync); + void HandleOnFreeInstallSuccess(FreeInstallInfo &freeInstallInfo, bool isAsync); + void HandleOnFreeInstallFail(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync); + void NotifySCBToHandleException(const FreeInstallInfo &info, int resultCode); }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h index 0110e3f3e4..5de5dbc783 100644 --- a/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h +++ b/services/abilitymgr/include/scene_board/ui_ability_lifecycle_manager.h @@ -150,6 +150,9 @@ public: int NotifySCBToStartUIAbility(const AbilityRequest &abilityRequest); + int NotifySCBToPreStartUIAbility(const AbilityRequest &abilityRequest, + sptr &sessionInfo); + /** * @brief handle time out event * @@ -353,6 +356,9 @@ public: int32_t GetAbilityStateByPersistentId(int32_t persistentId, bool &state); + void NotifySCBToHandleException(const std::shared_ptr &ability, int32_t errorCode, + const std::string& errorReason); + private: int32_t GetPersistentIdByAbilityRequest(const AbilityRequest &abilityRequest, bool &reuse) const; int32_t GetReusedSpecifiedPersistentId(const AbilityRequest &abilityRequest, bool &reuse) const; @@ -374,8 +380,6 @@ private: void HandleForegroundFailed(const std::shared_ptr &ability, AbilityState state = AbilityState::INITIAL); void HandleForegroundTimeout(const std::shared_ptr &ability); - void NotifySCBToHandleException(const std::shared_ptr &ability, int32_t errorCode, - std::string errorReason); void MoveToBackground(const std::shared_ptr &abilityRecord); void CompleteBackground(const std::shared_ptr &abilityRecord); void PrintTimeOutLog(std::shared_ptr ability, uint32_t msgId, bool isHalf = false); diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index dcc954fe2c..a774b10e71 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -1911,5 +1911,14 @@ void AbilityManagerClient::NotifyFrozenProcessByRSS(const std::vector & CHECK_POINTER_RETURN(abms); return abms->NotifyFrozenProcessByRSS(pidList, uid); } + +ErrCode AbilityManagerClient::PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->PreStartMission(bundleName, moduleName, abilityName, startTime); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 1acf8c728a..5bb68fad08 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -5303,5 +5303,38 @@ void AbilityManagerProxy::NotifyFrozenProcessByRSS(const std::vector &p TAG_LOGE(AAFwkTag::ABILITYMGR, "AbilityManagerProxy: SendRequest err %{public}d", error); } } + +int32_t AbilityManagerProxy::PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return IPC_PROXY_ERR; + } + if (!data.WriteString(bundleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write bundleName failed."); + return INNER_ERR; + } + if (!data.WriteString(moduleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write moduleName failed."); + return INNER_ERR; + } + if (!data.WriteString(abilityName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write abilityName failed."); + return INNER_ERR; + } + if (!data.WriteString(startTime)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "write startTime failed."); + return INNER_ERR; + } + auto error = SendRequest(AbilityManagerInterfaceCode::PRE_START_MISSION, data, reply, option); + if (error != NO_ERROR) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index f3ea63520c..3a77aacc0b 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -33,7 +33,6 @@ #include "ability_background_connection.h" #include "ability_connect_manager.h" #include "ability_debug_deal.h" -#include "ability_info.h" #include "ability_manager_constants.h" #include "ability_manager_errors.h" #include "ability_manager_radar.h" @@ -914,6 +913,97 @@ void AbilityManagerService::SetReserveInfo(const std::string &linkString) #endif // SUPPORT_SCREEN } +int AbilityManagerService::CheckExtensionCallPermission(const Want& want, const AbilityRequest& abilityRequest) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "startExtensionCheck"); + auto isSACall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + auto isSystemAppCall = AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall(); + auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); + auto isToPermissionMgr = IsTargetPermission(want); + if (!isSACall && !isSystemAppCall && !isShellCall && !isToPermissionMgr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, + "Cannot start extension by start ability, use startServiceExtensionAbility."); + return ERR_WRONG_INTERFACE_CALL; + } + int result = CheckCallServicePermission(abilityRequest); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed"); + } + return result; +} + +int AbilityManagerService::CheckServiceCallPermission(const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, + "Check call service or extension permission, name is %{public}s.", abilityInfo.name.c_str()); + int result = CheckCallServicePermission(abilityRequest); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed"); + } + return result; +} + +int AbilityManagerService::CheckBrokerCallPermission(const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo) +{ + // temp add for broker, remove when delete issacall + if (abilityRequest.collaboratorType != CollaboratorType::RESERVE_TYPE && !abilityInfo.visible) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Check permission failed"); + return CHECK_PERMISSION_FAILED; + } + TAG_LOGD(AAFwkTag::ABILITYMGR, + "Check call service or extension permission, name is %{public}s.", abilityInfo.name.c_str()); + auto collaborator = GetCollaborator(CollaboratorType::RESERVE_TYPE); + if (collaborator == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Collaborator is nullptr."); + return CHECK_PERMISSION_FAILED; + } + int result = collaborator->CheckCallAbilityPermission(abilityRequest.want); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed from broker."); + return CHECK_PERMISSION_FAILED; + } + return result; +} + +int AbilityManagerService::CheckAbilityCallPermission(const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo, uint32_t specifyTokenId) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "Check call ability permission, name is %{public}s.", abilityInfo.name.c_str()); + int result = CheckCallAbilityPermission(abilityRequest, specifyTokenId); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed"); + } + return result; +} + +int AbilityManagerService::CheckCallPermission(const Want& want, const AppExecFwk::AbilityInfo& abilityInfo, + const AbilityRequest& abilityRequest, bool isForegroundToRestartApp, + bool isSendDialogResult, uint32_t specifyTokenId, + const std::string& callerBundleName) +{ + auto type = abilityInfo.type; + if (type == AppExecFwk::AbilityType::DATA) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Cannot start data ability by start ability."); + return ERR_WRONG_INTERFACE_CALL; + } + if (type == AppExecFwk::AbilityType::EXTENSION) { + return CheckExtensionCallPermission(want, abilityRequest); + } + if (type == AppExecFwk::AbilityType::SERVICE) { + return CheckServiceCallPermission(abilityRequest, abilityInfo); + } + if ((callerBundleName == SHELL_ASSISTANT_BUNDLENAME && AppUtils::GetInstance().IsSupportAncoApp()) || + IPCSkeleton::GetCallingUid() == BROKER_UID) { + return CheckBrokerCallPermission(abilityRequest, abilityInfo); + } + if (!isForegroundToRestartApp && (!isSendDialogResult || want.GetBoolParam("isSelector", false))) { + return CheckAbilityCallPermission(abilityRequest, abilityInfo, specifyTokenId); + } + return ERR_OK; +} + int AbilityManagerService::StartAbilityInner(const Want &want, const sptr &callerToken, int requestCode, int32_t userId, bool isStartAsCaller, bool isSendDialogResult, uint32_t specifyTokenId, bool isForegroundToRestartApp, bool isImplicit) @@ -1017,23 +1107,16 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(want)).RemoveParam("send_to_erms_embedded"); - Want localWant = want; - if (!localWant.GetDeviceId().empty()) { - localWant.SetDeviceId(""); - } - if (specifyTokenId > 0 && callerToken != nullptr) { // for sa specify tokenId and caller token - UpdateCallerInfoFromToken(localWant, callerToken); - } else if (!isStartAsCaller) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "do not start as caller, UpdateCallerInfo"); - UpdateCallerInfo(localWant, callerToken); + Want localWant; + result = PreStartFreeInstall(want, callerToken, specifyTokenId, isStartAsCaller, localWant); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "PreStartFreeInstall failed."); + return result; } if (isStartFreeInstallByWant) { - return freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken, true); + return freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, + callerToken, true, specifyTokenId); } int32_t ret = freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken, false); if (ret == ERR_OK) { @@ -1078,60 +1161,11 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrIsSACall(); - auto isSystemAppCall = AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall(); - auto isShellCall = AAFwk::PermissionVerification::GetInstance()->IsShellCall(); - auto isToPermissionMgr = IsTargetPermission(want); - if (!isSACall && !isSystemAppCall && !isShellCall && !isToPermissionMgr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, - "Cannot start extension by start ability, use startServiceExtensionAbility."); - return ERR_WRONG_INTERFACE_CALL; - } - result = CheckCallServicePermission(abilityRequest); - if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed"); - return result; - } - } else if (type == AppExecFwk::AbilityType::SERVICE) { - TAG_LOGD(AAFwkTag::ABILITYMGR, - "Check call service or extension permission, name is %{public}s.", abilityInfo.name.c_str()); - result = CheckCallServicePermission(abilityRequest); - if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed"); - return result; - } - } else if ((callerBundleName == SHELL_ASSISTANT_BUNDLENAME && AppUtils::GetInstance().IsSupportAncoApp()) || - IPCSkeleton::GetCallingUid() == BROKER_UID) { - // temp add for broker, remove when delete issacall - if (abilityRequest.collaboratorType != CollaboratorType::RESERVE_TYPE && !abilityInfo.visible) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Check permission failed"); - return CHECK_PERMISSION_FAILED; - } - TAG_LOGD(AAFwkTag::ABILITYMGR, - "Check call service or extension permission, name is %{public}s.", abilityInfo.name.c_str()); - auto collaborator = GetCollaborator(CollaboratorType::RESERVE_TYPE); - if (collaborator == nullptr) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Collaborator is nullptr."); - return CHECK_PERMISSION_FAILED; - } - result = collaborator->CheckCallAbilityPermission(abilityRequest.want); - if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed from broker."); - return CHECK_PERMISSION_FAILED; - } - } else if (!isForegroundToRestartApp && (!isSendDialogResult || want.GetBoolParam("isSelector", false))) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Check call ability permission, name is %{public}s.", abilityInfo.name.c_str()); - result = CheckCallAbilityPermission(abilityRequest, specifyTokenId); - if (result != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "Check permission failed"); - return result; - } + result = CheckCallPermission(want, abilityInfo, abilityRequest, isForegroundToRestartApp, + isSendDialogResult, specifyTokenId, callerBundleName); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "CheckCallPermission error, result is %{public}d.", result); + return result; } Want newWant = abilityRequest.want; @@ -1170,16 +1204,9 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptr(want)); - return connectManager->StartAbility(abilityRequest); + if (abilityInfo.type == AppExecFwk::AbilityType::SERVICE || + abilityInfo.type == AppExecFwk::AbilityType::EXTENSION) { + return StartAbilityByConnectManager(want, abilityRequest, abilityInfo, validUserId, callerToken); } if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { @@ -1224,6 +1251,42 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrStartAbility(abilityRequest); } +int AbilityManagerService::PreStartFreeInstall(const Want &want, sptr callerToken, + uint32_t specifyTokenId, bool isStartAsCaller, Want &localWant) +{ + if (freeInstallManager_ == nullptr) { + return ERR_INVALID_VALUE; + } + (const_cast(want)).RemoveParam("send_to_erms_embedded"); + localWant = want; + if (!localWant.GetDeviceId().empty()) { + localWant.SetDeviceId(""); + } + if (specifyTokenId > 0 && callerToken != nullptr) { // for sa specify tokenId and caller token + UpdateCallerInfoFromToken(localWant, callerToken); + } else if (!isStartAsCaller) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "do not start as caller, UpdateCallerInfo"); + UpdateCallerInfo(localWant, callerToken); + } else { + TAG_LOGD(AAFwkTag::ABILITYMGR, "start as caller, skip UpdateCallerInfo!"); + } + return ERR_OK; +} + +int AbilityManagerService::StartAbilityByConnectManager(const Want& want, const AbilityRequest& abilityRequest, + const AppExecFwk::AbilityInfo& abilityInfo, int validUserId, sptr callerToken) +{ + auto connectManager = GetConnectManagerByUserId(validUserId); + if (!connectManager) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "connectManager is nullptr. userId=%{public}d", validUserId); + return ERR_INVALID_VALUE; + } + TAG_LOGD(AAFwkTag::ABILITYMGR, "Start service or extension, name is %{public}s.", abilityInfo.name.c_str()); + ReportEventToRSS(abilityInfo, callerToken); + InsightIntentExecuteParam::RemoveInsightIntent(const_cast(want)); + return connectManager->StartAbility(abilityRequest); +} + int AbilityManagerService::StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting, const sptr &callerToken, int32_t userId, int requestCode) { @@ -1583,7 +1646,8 @@ int AbilityManagerService::StartAbilityForOptionInner(const Want &want, const St TAG_LOGD(AAFwkTag::ABILITYMGR, "do not start as caller, UpdateCallerInfo"); UpdateCallerInfo(localWant, callerToken); } - return freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, callerToken, true); + return freeInstallManager_->StartFreeInstall(localWant, validUserId, requestCode, + callerToken, true, specifyTokenId); } if (!JudgeMultiUserConcurrency(validUserId)) { TAG_LOGE(AAFwkTag::ABILITYMGR, "Multi-user non-concurrent mode is not satisfied."); @@ -1926,6 +1990,52 @@ int AbilityManagerService::StartUIAbilityBySCB(sptr sessionInfo, bo return ERR_WRONG_INTERFACE_CALL; } + if (!(sessionInfo->want).HasParameter(KEY_SESSION_ID)) { + return StartUIAbilityBySCBDefault(sessionInfo, isColdStart); + } + + std::string sessionId = (sessionInfo->want).GetStringParam(KEY_SESSION_ID); + if (sessionId.empty()) { + return StartUIAbilityBySCBDefault(sessionInfo, isColdStart); + } + + TAG_LOGI(AAFwkTag::ABILITYMGR, "sessionId=%{public}s", sessionId.c_str()); + FreeInstallInfo taskInfo; + if (!freeInstallManager_->GetFreeInstallTaskInfo(sessionId, taskInfo)) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "failed to find free isntall task"); + return StartUIAbilityBySCBDefault(sessionInfo, isColdStart); + } + + if (taskInfo.isInstalled) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "free install task is already finished"); + auto err = StartUIAbilityByPreInstallInner(sessionInfo, taskInfo.specifyTokenId, isColdStart); + if (err != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilityByPreInstallInner failed."); + } + return err; + } + + { + std::lock_guard guard(preStartSessionMapLock_); + preStartSessionMap_.insert(std::make_pair(sessionId, sessionInfo)); + } + + TAG_LOGI(AAFwkTag::ABILITYMGR, "free install task is still in progress"); + const Want& want = sessionInfo->want; + if (freeInstallManager_ == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "freeInstallManager_ is nullptr."); + return ERR_INVALID_VALUE; + } + freeInstallManager_->SetSCBCallStatus(want.GetElement().GetBundleName(), want.GetElement().GetAbilityName(), + want.GetStringParam(Want::PARAM_RESV_START_TIME), true); + return ERR_OK; +} + +int AbilityManagerService::StartUIAbilityBySCBDefault(sptr sessionInfo, bool &isColdStart) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Call."); + auto currentUserId = IPCSkeleton::GetCallingUid() / BASE_USER_RANGE; if (sessionInfo->userId == DEFAULT_INVAL_VALUE) { sessionInfo->userId = currentUserId; @@ -10865,5 +10975,288 @@ void AbilityManagerService::HandleRestartResidentProcessDependedOnWeb() CHECK_POINTER_LOG(appMgr, "get appMgr fail"); appMgr->RestartResidentProcessDependedOnWeb(); } + +int32_t AbilityManagerService::PreStartMission(const std::string& bundleName, const std::string& moduleName, + const std::string& abilityName, const std::string& startTime) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "Called."); + CHECK_CALLER_IS_SYSTEM_APP; + + if (!PermissionVerification::GetInstance()->VerifyPreStartAtomicServicePermission()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "calling user is not ag."); + return ERR_PERMISSION_DENIED; + } + + if (!freeInstallManager_) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "freeInstallManager_ is nullptr."); + return ERR_INVALID_VALUE; + } + + FreeInstallInfo taskInfo; + if (!freeInstallManager_->GetFreeInstallTaskInfo(bundleName, abilityName, startTime, taskInfo)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, + "failed to find free install task info:bundleName=%{public}s,abilityName=%{public}s,startTime=%{public}s", + bundleName.c_str(), abilityName.c_str(), startTime.c_str()); + return ERR_FREE_INSTALL_TASK_NOT_EXIST; + } + + if (taskInfo.isInstalled) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "atomic service is already installed."); + return ERR_OK; + } + + return PreStartInner(taskInfo); +} + +int32_t AbilityManagerService::PreStartInner(const FreeInstallInfo& taskInfo) +{ + TAG_LOGD(AAFwkTag::ABILITYMGR, "Called."); + + const Want& want = taskInfo.want; + sptr callerToken = taskInfo.callerToken; + + EventInfo eventInfo = BuildEventInfo(want, taskInfo.userId); + SendAbilityEvent(EventName::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); + + if (callerToken != nullptr && !VerificationAllToken(callerToken)) { + eventInfo.errCode = ERR_INVALID_VALUE; + SendAbilityEvent(EventName::START_ABILITY_ERROR, HiSysEventType::FAULT, eventInfo); + return ERR_INVALID_CALLER; + } + + int32_t oriValidUserId = GetValidUserId(taskInfo.userId); + + int32_t appIndex = 0; + StartAbilityInfoWrap threadLocalInfo(want, oriValidUserId, + StartAbilityUtils::GetAppIndex(want, callerToken, appIndex), callerToken); + + AbilityRequest abilityRequest = { + .want = want, + .requestCode = taskInfo.requestCode, + .callerToken = callerToken, + .startSetting = nullptr + }; + + TAG_LOGD(AAFwkTag::ABILITYMGR, "do not start as caller, UpdateCallerInfo"); + UpdateCallerInfo(abilityRequest.want, callerToken); + + // sceneboard + abilityRequest.userId = oriValidUserId; + abilityRequest.want.SetParam(IS_CALL_BY_SCB, false); + std::string sessionId = std::to_string(std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()).count()); + abilityRequest.want.SetParam(KEY_SESSION_ID, sessionId); + auto uiAbilityManager = GetUIAbilityManagerByUserId(oriValidUserId); + CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); + sptr sessionInfo = nullptr; + auto errCode = uiAbilityManager->NotifySCBToPreStartUIAbility(abilityRequest, sessionInfo); + if (errCode != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to notify sceneboard to pre-start uiability."); + return errCode; + } + freeInstallManager_->SetFreeInstallTaskSessionId(taskInfo.want.GetElement().GetBundleName(), + taskInfo.want.GetElement().GetAbilityName(), + taskInfo.want.GetStringParam(Want::PARAM_RESV_START_TIME), sessionId); + + freeInstallManager_->SetPreStartMissionCallStatus(taskInfo.want.GetElement().GetBundleName(), + taskInfo.want.GetElement().GetAbilityName(), + taskInfo.want.GetStringParam(Want::PARAM_RESV_START_TIME), + true); + return ERR_OK; +} + +int32_t AbilityManagerService::StartUIAbilityByPreInstall(const FreeInstallInfo &taskInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + TAG_LOGI(AAFwkTag::ABILITYMGR, "Called."); + const auto& want = taskInfo.want; + auto sessionId = want.GetStringParam(KEY_SESSION_ID); + if (sessionId.empty()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "session id is empty."); + return ERR_INVALID_VALUE; + } + auto bundleName = want.GetElement().GetBundleName(); + auto abilityName = want.GetElement().GetAbilityName(); + auto startTime = want.GetStringParam(Want::PARAM_RESV_START_TIME); + TAG_LOGI(AAFwkTag::ABILITYMGR, "Called." + "sessionId=%{public}s,bundleName=%{public}s,abilityName=%{public}s,startTime=%{public}s", + sessionId.c_str(), bundleName.c_str(), abilityName.c_str(), startTime.c_str()); + sptr sessionInfo = nullptr; + { + std::lock_guard guard(preStartSessionMapLock_); + auto it = preStartSessionMap_.find(sessionId); + if (it == preStartSessionMap_.end()) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to find session info with sessionId=%{public}s", + sessionId.c_str()); + return ERR_INVALID_VALUE; + } + sessionInfo = it->second; + } + + if (!taskInfo.isStartUIAbilityBySCBCalled) { + TAG_LOGI(AAFwkTag::ABILITYMGR, "Free install is finished, StartUIAbilityBySCB has not been called."); + return ERR_OK; + } + + int errCode = ERR_OK; + bool isColdStart = true; + if ((errCode = StartUIAbilityByPreInstallInner(sessionInfo, taskInfo.specifyTokenId, isColdStart)) != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "StartUIAbilityByPreInstallInner failed,errCode=%{public}d.", errCode); + } + RemovePreStartSession(sessionId); + return errCode; +} + +// StartUIAbilityByPreInstallInner is called when free install task is already finished +int AbilityManagerService::StartUIAbilityByPreInstallInner(sptr sessionInfo, + uint32_t specifyTokenId, bool &isColdStart) +{ + TAG_LOGI(AAFwkTag::ABILITYMGR, "Called."); + auto callerToken = sessionInfo->callerToken; + const auto& want = sessionInfo->want; + const auto userId = sessionInfo->userId; + const auto requestCode = sessionInfo->requestCode; + bool isStartAsCaller = false; + + if (callerToken != nullptr && !VerificationAllToken(callerToken)) { + auto isSpecificSA = AAFwk::PermissionVerification::GetInstance()-> + CheckSpecificSystemAbilityAccessPermission(DMS_PROCESS_NAME); + if (!isSpecificSA) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s VerificationAllToken failed.", __func__); + return ERR_INVALID_CALLER; + } + TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s: Caller is specific system ability.", __func__); + } + + int32_t oriValidUserId = GetValidUserId(userId); + int32_t validUserId = oriValidUserId; + + int32_t appIndex = 0; + if (!StartAbilityUtils::GetAppIndex(want, callerToken, appIndex)) { + return ERR_APP_CLONE_INDEX_INVALID; + } + StartAbilityInfoWrap threadLocalInfo(want, validUserId, appIndex, callerToken); + AbilityInterceptorParam interceptorParam = AbilityInterceptorParam(want, requestCode, GetUserId(), + true, nullptr); + auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : + interceptorExecuter_->DoProcess(interceptorParam); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptorExecuter_ is nullptr or DoProcess return error."); + return result; + } + + AbilityRequest abilityRequest; + result = GenerateAbilityRequest(want, requestCode, abilityRequest, callerToken, validUserId); + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); + std::string callerBundleName = abilityRecord ? abilityRecord->GetAbilityInfo().bundleName : ""; + + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "Generate ability request local error."); + return result; + } + if (!UriUtils::GetInstance().CheckNonImplicitShareFileUri(abilityRequest)) { + return ERR_SHARE_FILE_URI_NON_IMPLICITLY; + } + + if (specifyTokenId > 0 && callerToken != nullptr) { // for sa specify tokenId and caller token + UpdateCallerInfoFromToken(abilityRequest.want, callerToken); + } else if (!isStartAsCaller) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "do not start as caller, UpdateCallerInfo"); + UpdateCallerInfo(abilityRequest.want, callerToken); + } else if (callerBundleName == BUNDLE_NAME_DIALOG) { +#ifdef SUPPORT_SCREEN + CHECK_POINTER_AND_RETURN(implicitStartProcessor_, ERR_IMPLICIT_START_ABILITY_FAIL); + implicitStartProcessor_->ResetCallingIdentityAsCaller(abilityRequest.want.GetIntParam( + Want::PARAM_RESV_CALLER_TOKEN, 0)); +#endif // SUPPORT_SCREEN + } + + auto abilityInfo = abilityRequest.abilityInfo; + validUserId = abilityInfo.applicationInfo.singleton ? U0_USER_ID : validUserId; + TAG_LOGD(AAFwkTag::ABILITYMGR, "userId is : %{public}d, singleton is : %{public}d", + validUserId, static_cast(abilityInfo.applicationInfo.singleton)); + + result = CheckStaticCfgPermission(abilityRequest, isStartAsCaller, + abilityRequest.want.GetIntParam(Want::PARAM_RESV_CALLER_TOKEN, 0), false, false, false); + if (result != AppExecFwk::Constants::PERMISSION_GRANTED) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "CheckStaticCfgPermission error, result is %{public}d.", result); + return ERR_STATIC_CFG_PERMISSION; + } + + result = CheckCallPermission(want, abilityInfo, abilityRequest, false, + false, specifyTokenId, callerBundleName); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "CheckCallPermission error, result is %{public}d.", result); + return result; + } + + Want newWant = abilityRequest.want; + AbilityInterceptorParam afterCheckParam = AbilityInterceptorParam(newWant, requestCode, GetUserId(), + true, callerToken, std::make_shared(abilityInfo), isStartAsCaller); + result = afterCheckExecuter_ == nullptr ? ERR_INVALID_VALUE : + afterCheckExecuter_->DoProcess(afterCheckParam); + bool isReplaceWantExist = newWant.GetBoolParam("queryWantFromErms", false); + newWant.RemoveParam("queryWantFromErms"); + if (result != ERR_OK && isReplaceWantExist == false) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "DoProcess failed or replaceWant not exist"); + return result; + } + if (result != ERR_OK && isReplaceWantExist && + callerBundleName != BUNDLE_NAME_DIALOG) { + std::string dialogSessionId; +#ifdef SUPPORT_SCREEN + std::vector dialogAppInfos(1); + if (GenerateDialogSessionRecord(abilityRequest, GetUserId(), dialogSessionId, dialogAppInfos, false)) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "create dialog by ui extension"); + return CreateModalDialog(newWant, callerToken, dialogSessionId); + } +#endif // SUPPORT_SCREEN + TAG_LOGE(AAFwkTag::ABILITYMGR, "create dialog by ui extension failed"); + return INNER_ERR; + } + + if (abilityInfo.type == AppExecFwk::AbilityType::SERVICE || + abilityInfo.type == AppExecFwk::AbilityType::EXTENSION) { + return StartAbilityByConnectManager(want, abilityRequest, abilityInfo, validUserId, callerToken); + } + + if (!IsAbilityControllerStart(want, abilityInfo.bundleName)) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "IsAbilityControllerStart failed: %{public}s.", abilityInfo.bundleName.c_str()); + return ERR_WOULD_BLOCK; + } + + abilityRequest.want.RemoveParam(SPECIFY_TOKEN_ID); + if (specifyTokenId > 0) { + TAG_LOGD(AAFwkTag::ABILITYMGR, "Set specifyTokenId, the specifyTokenId is %{public}d.", specifyTokenId); + abilityRequest.want.SetParam(SPECIFY_TOKEN_ID, static_cast(specifyTokenId)); + abilityRequest.specifyTokenId = specifyTokenId; + } + abilityRequest.want.RemoveParam(PARAM_SPECIFIED_PROCESS_FLAG); + + auto uiAbilityManager = GetCurrentUIAbilityManager(); + CHECK_POINTER_AND_RETURN(uiAbilityManager, ERR_INVALID_VALUE); + + return uiAbilityManager->StartUIAbility(abilityRequest, sessionInfo, isColdStart); +} + +void AbilityManagerService::NotifySCBToHandleException(sptr callerToken, int32_t errCode, + const std::string& reason) +{ + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); + if (abilityRecord == nullptr) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "no such ability record matched token"); + return; + } + auto uiAbilityManager = GetCurrentUIAbilityManager(); + CHECK_POINTER(uiAbilityManager); + + return uiAbilityManager->NotifySCBToHandleException(abilityRecord, errCode, reason); +} + +void AbilityManagerService::RemovePreStartSession(const std::string& sessionId) +{ + std::lock_guard guard(preStartSessionMapLock_); + preStartSessionMap_.erase(sessionId); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index adb20bfbb5..cf5eb84b3d 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -743,6 +743,9 @@ int AbilityManagerStub::OnRemoteRequestInnerNineteenth(uint32_t code, MessagePar if (interfaceCode == AbilityManagerInterfaceCode::NOTIFY_FROZEN_PROCESS_BY_RSS) { return NotifyFrozenProcessByRSSInner(data, reply); } + if (interfaceCode == AbilityManagerInterfaceCode::PRE_START_MISSION) { + return PreStartMissionInner(data, reply); + } return ERR_CODE_NOT_EXIST; } @@ -3892,5 +3895,16 @@ int32_t AbilityManagerStub::NotifyFrozenProcessByRSSInner(MessageParcel &data, M NotifyFrozenProcessByRSS(pidList, uid); return NO_ERROR; } + +int32_t AbilityManagerStub::PreStartMissionInner(MessageParcel &data, MessageParcel &reply) +{ + std::string bundleName = data.ReadString(); + std::string moduleName = data.ReadString(); + std::string abilityName = data.ReadString(); + std::string startTime = data.ReadString(); + int32_t result = PreStartMission(bundleName, moduleName, abilityName, startTime); + reply.WriteInt32(result); + return NO_ERROR; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/free_install_manager.cpp b/services/abilitymgr/src/free_install_manager.cpp index 0613d673b1..d7e626a454 100644 --- a/services/abilitymgr/src/free_install_manager.cpp +++ b/services/abilitymgr/src/free_install_manager.cpp @@ -83,7 +83,7 @@ bool FreeInstallManager::IsTopAbility(const sptr &callerToken) } int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int requestCode, - const sptr &callerToken, bool isAsync) + const sptr &callerToken, bool isAsync, uint32_t specifyTokenId) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGI(AAFwkTag::FREE_INSTALL, "StartFreeInstall called"); @@ -91,7 +91,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r if (!isSaCall && !IsTopAbility(callerToken)) { return NOT_TOP_ABILITY; } - FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken, isAsync); + FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken, isAsync, specifyTokenId); { std::lock_guard lock(freeInstallListLock_); freeInstallList_.push_back(info); @@ -162,13 +162,14 @@ int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int } FreeInstallInfo FreeInstallManager::BuildFreeInstallInfo(const Want &want, int32_t userId, int requestCode, - const sptr &callerToken, bool isAsync) + const sptr &callerToken, bool isAsync, uint32_t specifyTokenId) { FreeInstallInfo info = { .want = want, .userId = userId, .requestCode = requestCode, - .callerToken = callerToken + .callerToken = callerToken, + .specifyTokenId = specifyTokenId }; if (!isAsync) { auto promise = std::make_shared>(); @@ -259,42 +260,73 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod bool isFromRemote = want.GetBoolParam(FROM_REMOTE_KEY, false); TAG_LOGI(AAFwkTag::FREE_INSTALL, "isFromRemote = %{public}d", isFromRemote); for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { - std::string bundleName = (*it).want.GetElement().GetBundleName(); - std::string abilityName = (*it).want.GetElement().GetAbilityName(); - std::string startTime = (*it).want.GetStringParam(Want::PARAM_RESV_START_TIME); + FreeInstallInfo &freeInstallInfo = *it; + std::string bundleName = freeInstallInfo.want.GetElement().GetBundleName(); + std::string abilityName = freeInstallInfo.want.GetElement().GetAbilityName(); + std::string startTime = freeInstallInfo.want.GetStringParam(Want::PARAM_RESV_START_TIME); if (want.GetElement().GetBundleName().compare(bundleName) != 0 || want.GetElement().GetAbilityName().compare(abilityName) != 0 || want.GetStringParam(Want::PARAM_RESV_START_TIME).compare(startTime) != 0) { - it++; continue; } - if (!isAsync && (*it).promise == nullptr) { + if (!isAsync && freeInstallInfo.promise == nullptr) { it++; continue; } - - if (resultCode == ERR_OK) { - TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall success."); - if (isAsync) { - StartAbilityByFreeInstall(*it, bundleName, abilityName, startTime); - } else { - (*it).promise->set_value(resultCode); - } - } else { - TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall failed."); - if (isAsync) { - DelayedSingleton::GetInstance()->OnInstallFinished( - bundleName, abilityName, startTime, resultCode); - } else { - (*it).promise->set_value(resultCode); - } - } - + freeInstallInfo.isInstalled = true; + HandleFreeInstallResult(freeInstallInfo, resultCode, isAsync); it = freeInstallList_.erase(it); } } +void FreeInstallManager::HandleOnFreeInstallSuccess(FreeInstallInfo &freeInstallInfo, bool isAsync) +{ + TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall success."); + + if (isAsync) { + std::string startTime = freeInstallInfo.want.GetStringParam(Want::PARAM_RESV_START_TIME); + std::string bundleName = freeInstallInfo.want.GetElement().GetBundleName(); + std::string abilityName = freeInstallInfo.want.GetElement().GetAbilityName(); + if (freeInstallInfo.isPreStartMissionCalled) { + StartAbilityByPreInstall(freeInstallInfo, bundleName, abilityName, startTime); + return; + } + StartAbilityByFreeInstall(freeInstallInfo, bundleName, abilityName, startTime); + return; + } + freeInstallInfo.promise->set_value(ERR_OK); +} + +void FreeInstallManager::HandleOnFreeInstallFail(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync) +{ + TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall failed."); + + if (isAsync) { + if (freeInstallInfo.isPreStartMissionCalled) { + DelayedSingleton::GetInstance()->NotifySCBToHandleException( + freeInstallInfo.callerToken, resultCode, "free install failed"); + } + std::string startTime = freeInstallInfo.want.GetStringParam(Want::PARAM_RESV_START_TIME); + std::string bundleName = freeInstallInfo.want.GetElement().GetBundleName(); + std::string abilityName = freeInstallInfo.want.GetElement().GetAbilityName(); + + DelayedSingleton::GetInstance()->OnInstallFinished( + bundleName, abilityName, startTime, resultCode); + return; + } + freeInstallInfo.promise->set_value(resultCode); +} + +void FreeInstallManager::HandleFreeInstallResult(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync) +{ + if (resultCode == ERR_OK) { + HandleOnFreeInstallSuccess(freeInstallInfo, isAsync); + return; + } + HandleOnFreeInstallFail(freeInstallInfo, resultCode, isAsync); +} + void FreeInstallManager::StartAbilityByFreeInstall(FreeInstallInfo &info, std::string &bundleName, std::string &abilityName, std::string &startTime) { @@ -315,6 +347,25 @@ void FreeInstallManager::StartAbilityByFreeInstall(FreeInstallInfo &info, std::s bundleName, abilityName, startTime, result); } +void FreeInstallManager::StartAbilityByPreInstall(FreeInstallInfo &info, std::string &bundleName, + std::string &abilityName, std::string &startTime) +{ + info.want.SetFlags(info.want.GetFlags() ^ Want::FLAG_INSTALL_ON_DEMAND); + auto identity = IPCSkeleton::ResetCallingIdentity(); + IPCSkeleton::SetCallingIdentity(info.identity); + int32_t result = ERR_OK; + if (info.want.GetElement().GetAbilityName().empty()) { + result = UpdateElementName(info.want, info.userId); + } + if (result == ERR_OK) { + result = DelayedSingleton::GetInstance()->StartUIAbilityByPreInstall(info); + } + IPCSkeleton::SetCallingIdentity(identity); + TAG_LOGI(AAFwkTag::FREE_INSTALL, "The result of StartAbility is %{public}d.", result); + DelayedSingleton::GetInstance()->OnInstallFinished( + bundleName, abilityName, startTime, result); +} + int32_t FreeInstallManager::UpdateElementName(Want &want, int32_t userId) const { auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper(); @@ -528,5 +579,79 @@ void FreeInstallManager::RemoveFreeInstallInfo(const std::string &bundleName, co } } } + +bool FreeInstallManager::GetFreeInstallTaskInfo(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, FreeInstallInfo& taskInfo) +{ + std::lock_guard lock(freeInstallListLock_); + for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { + if ((*it).want.GetElement().GetBundleName() == bundleName && + (*it).want.GetElement().GetAbilityName() == abilityName && + (*it).want.GetStringParam(Want::PARAM_RESV_START_TIME) == startTime) { + taskInfo = *it; + return true; + } + it++; + } + return false; +} + +bool FreeInstallManager::GetFreeInstallTaskInfo(const std::string& sessionId, FreeInstallInfo& taskInfo) +{ + std::lock_guard lock(freeInstallListLock_); + for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { + if ((*it).want.GetStringParam(KEY_SESSION_ID) == sessionId) { + taskInfo = *it; + return true; + } + it++; + } + return false; +} + +void FreeInstallManager::SetSCBCallStatus(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, bool scbCallStatus) +{ + std::lock_guard lock(freeInstallListLock_); + for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { + if ((*it).want.GetElement().GetBundleName() == bundleName && + (*it).want.GetElement().GetAbilityName() == abilityName && + (*it).want.GetStringParam(Want::PARAM_RESV_START_TIME) == startTime) { + (*it).isStartUIAbilityBySCBCalled = scbCallStatus; + return; + } + it++; + } +} + +void FreeInstallManager::SetPreStartMissionCallStatus(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, bool preStartMissionCallStatus) +{ + std::lock_guard lock(freeInstallListLock_); + for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { + if ((*it).want.GetElement().GetBundleName() == bundleName && + (*it).want.GetElement().GetAbilityName() == abilityName && + (*it).want.GetStringParam(Want::PARAM_RESV_START_TIME) == startTime) { + (*it).isPreStartMissionCalled = preStartMissionCallStatus; + return; + } + it++; + } +} + +void FreeInstallManager::SetFreeInstallTaskSessionId(const std::string& bundleName, const std::string& abilityName, + const std::string& startTime, const std::string& sessionId) +{ + std::lock_guard lock(freeInstallListLock_); + for (auto it = freeInstallList_.begin(); it != freeInstallList_.end();) { + if ((*it).want.GetElement().GetBundleName() == bundleName && + (*it).want.GetElement().GetAbilityName() == abilityName && + (*it).want.GetStringParam(Want::PARAM_RESV_START_TIME) == startTime) { + (*it).want.SetParam(KEY_SESSION_ID, sessionId); + return; + } + it++; + } +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp index b27e31c602..81f92ee8cb 100644 --- a/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp +++ b/services/abilitymgr/src/scene_board/ui_ability_lifecycle_manager.cpp @@ -345,6 +345,7 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse); sessionInfo->userId = userId_; sessionInfo->processOptions = abilityRequest.processOptions; + sessionInfo->isAtomicService = (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); TAG_LOGI( AAFwkTag::ABILITYMGR, "Reused sessionId: %{public}d, userId: %{public}d.", sessionInfo->persistentId, userId_); int ret = NotifySCBPendingActivation(sessionInfo, abilityRequest); @@ -352,6 +353,18 @@ int UIAbilityLifecycleManager::NotifySCBToStartUIAbility(const AbilityRequest &a return ret; } +int UIAbilityLifecycleManager::NotifySCBToPreStartUIAbility(const AbilityRequest &abilityRequest, + sptr &sessionInfo) +{ + HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + + std::lock_guard guard(sessionLock_); + sessionInfo = CreateSessionInfo(abilityRequest); + sessionInfo->requestCode = abilityRequest.requestCode; + sessionInfo->isAtomicService = true; + return NotifySCBPendingActivation(sessionInfo, abilityRequest); +} + int UIAbilityLifecycleManager::DispatchState(const std::shared_ptr &abilityRecord, int state) { switch (state) { @@ -820,6 +833,7 @@ int UIAbilityLifecycleManager::CallAbilityLocked(const AbilityRequest &abilityRe NotifyAbilityToken(uiAbilityRecord->GetToken(), abilityRequest); // new version started by call type + const auto& abilityInfo = abilityRequest.abilityInfo; auto ret = ResolveAbility(uiAbilityRecord, abilityRequest); if (ret == ResolveResultType::OK_HAS_REMOTE_OBJ) { TAG_LOGD(AAFwkTag::ABILITYMGR, "target ability has been resolved."); @@ -830,6 +844,8 @@ int UIAbilityLifecycleManager::CallAbilityLocked(const AbilityRequest &abilityRe sessionInfo->state = CallToState::FOREGROUND; sessionInfo->reuse = reuse; sessionInfo->uiAbilityId = uiAbilityRecord->GetAbilityRecordId(); + sessionInfo->isAtomicService = + (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); uiAbilityRecord->PostForegroundTimeoutTask(); DelayedSingleton::GetInstance()->MoveToForeground(uiAbilityRecord->GetToken()); return NotifySCBPendingActivation(sessionInfo, abilityRequest); @@ -844,6 +860,7 @@ int UIAbilityLifecycleManager::CallAbilityLocked(const AbilityRequest &abilityRe sessionInfo->persistentId = persistentId; sessionInfo->reuse = reuse; sessionInfo->uiAbilityId = uiAbilityRecord->GetAbilityRecordId(); + sessionInfo->isAtomicService = (abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); if (abilityRequest.want.GetBoolParam(Want::PARAM_RESV_CALL_TO_FOREGROUND, false)) { sessionInfo->state = CallToState::FOREGROUND; } else { @@ -1360,7 +1377,7 @@ void UIAbilityLifecycleManager::SetRootSceneSession(const sptr &r } void UIAbilityLifecycleManager::NotifySCBToHandleException(const std::shared_ptr &abilityRecord, - int32_t errorCode, std::string errorReason) + int32_t errorCode, const std::string& errorReason) { TAG_LOGD(AAFwkTag::ABILITYMGR, "call"); if (abilityRecord == nullptr) { @@ -1512,6 +1529,8 @@ void UIAbilityLifecycleManager::OnStartSpecifiedProcessResponse(const AAFwk::Wan sessionInfo->requestCode = abilityRequest.requestCode; sessionInfo->persistentId = GetPersistentIdByAbilityRequest(abilityRequest, sessionInfo->reuse); sessionInfo->userId = abilityRequest.userId; + sessionInfo->isAtomicService = + (abilityRequest.abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); TAG_LOGI(AAFwkTag::ABILITYMGR, "Reused sessionId: %{public}d, userId: %{public}d.", sessionInfo->persistentId, abilityRequest.userId); NotifySCBPendingActivation(sessionInfo, abilityRequest); @@ -2451,6 +2470,8 @@ int UIAbilityLifecycleManager::StartWithPersistentIdByDistributed(const AbilityR sessionInfo->persistentId = persistentId; sessionInfo->userId = userId_; sessionInfo->processOptions = abilityRequest.processOptions; + sessionInfo->isAtomicService = + (abilityRequest.abilityInfo.applicationInfo.bundleType == AppExecFwk::BundleType::ATOMIC_SERVICE); return NotifySCBPendingActivation(sessionInfo, abilityRequest); } diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index 25f5d28bc4..60c80808e0 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -56,6 +56,7 @@ constexpr const char* PERMISSION_START_SHORTCUT = "ohos.permission.START_SHORTCU constexpr const char* PERMISSION_PRELOAD_APPLICATION = "ohos.permission.PRELOAD_APPLICATION"; constexpr const char* PERMISSION_SET_PROCESS_CACHE_STATE = "ohos.permission.SET_PROCESS_CACHE_STATE"; constexpr const char* PERMISSION_PRELOAD_UI_EXTENSION_ABILITY = "ohos.permission.PRELOAD_UI_EXTENSION_ABILITY"; +constexpr const char* PERMISSION_PRE_START_ATOMIC_SERVICE = "ohos.permission.PRE_START_ATOMIC_SERVICE"; } // namespace PermissionConstants } // namespace AAFwk } // namespace OHOS diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index c45ab2a48a..b38bf5a2c6 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -101,6 +101,8 @@ struct VerificationInfo { bool VerifySetProcessCachePermission() const; + bool VerifyPreStartAtomicServicePermission() const; + private: DISALLOW_COPY_AND_MOVE(PermissionVerification); diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index c851f29542..92608fa1db 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -482,5 +482,17 @@ bool PermissionVerification::VerifySetProcessCachePermission() const TAG_LOGW(AAFwkTag::APPMGR, "Permission verification failed"); return false; } + +bool PermissionVerification::VerifyPreStartAtomicServicePermission() const +{ + if (VerifyCallingPermission(PermissionConstants::PERMISSION_PRE_START_ATOMIC_SERVICE)) { + TAG_LOGD(AAFwkTag::APPMGR, "verify permission %{public}s succeeded.", + PermissionConstants::PERMISSION_PRE_START_ATOMIC_SERVICE); + return true; + } + TAG_LOGW(AAFwkTag::APPMGR, "verify permission %{public}s failed.", + PermissionConstants::PERMISSION_PRE_START_ATOMIC_SERVICE); + return false; +} } // namespace AAFwk } // namespace OHOS From 5952a0c400cd8c6fd61fc38a40fa6e81ca538228 Mon Sep 17 00:00:00 2001 From: XKK Date: Wed, 3 Jul 2024 11:03:52 +0800 Subject: [PATCH 145/148] =?UTF-8?q?hilog=20=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: XKK --- .../ability_runtime/connection_manager.cpp | 6 ++-- .../dialog_ui_extension_callback.cpp | 4 +-- .../native/ability_runtime/cj_ui_ability.cpp | 4 +-- .../native/ability/native/extension_impl.cpp | 4 +-- .../native/js_service_extension_context.cpp | 4 +-- .../runner_runtime/cj_test_runner.cpp | 36 +++++++++---------- .../runner_runtime/cj_test_runner_object.cpp | 18 +++++----- .../context/js_application_context_utils.cpp | 4 +-- .../context/js_context_utils.cpp | 2 +- frameworks/native/runtime/cj_runtime.cpp | 27 +++++++------- .../src/js_application_context_utils.cpp | 2 +- 11 files changed, 56 insertions(+), 55 deletions(-) diff --git a/frameworks/native/ability/ability_runtime/connection_manager.cpp b/frameworks/native/ability/ability_runtime/connection_manager.cpp index 1f41e4da44..279b7ce2bb 100644 --- a/frameworks/native/ability/ability_runtime/connection_manager.cpp +++ b/frameworks/native/ability/ability_runtime/connection_manager.cpp @@ -250,19 +250,19 @@ bool ConnectionManager::DisconnectNonexistentService( std::lock_guard lock(connectionsLock_); abilityConnections = abilityConnections_; } - HILOG_DEBUG("abilityConnectionsSize: %{public}zu", abilityConnections.size()); + TAG_LOGD(AAFwkTag::CONNECTION, "abilityConnectionsSize: %{public}zu", abilityConnections.size()); for (auto &&abilityConnection : abilityConnections) { ConnectionInfo connectionInfo = abilityConnection.first; if (connectionInfo.abilityConnection == connection && connectionInfo.connectReceiver.GetBundleName() == element.GetBundleName()) { - HILOG_DEBUG("find connection."); + TAG_LOGD(AAFwkTag::CONNECTION, "find connection."); exit = true; break; } } if (!exit) { - HILOG_ERROR("this service need disconnect"); + TAG_LOGE(AAFwkTag::CONNECTION, "this service need disconnect"); AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connection); return true; } diff --git a/frameworks/native/ability/ability_runtime/dialog_ui_extension_callback.cpp b/frameworks/native/ability/ability_runtime/dialog_ui_extension_callback.cpp index b707ef8984..eab5c5ef8f 100644 --- a/frameworks/native/ability/ability_runtime/dialog_ui_extension_callback.cpp +++ b/frameworks/native/ability/ability_runtime/dialog_ui_extension_callback.cpp @@ -23,10 +23,10 @@ DialogUIExtensionCallback::DialogUIExtensionCallback(const std::weak_ptr(AbilityRuntime::GetJsErrorCodeByNativeError(*innerErrorCode)); if (errcode) { connection->CallJsFailed(errcode); diff --git a/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner.cpp b/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner.cpp index 2033a5f95f..59478ab38a 100644 --- a/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner.cpp +++ b/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner.cpp @@ -18,7 +18,7 @@ #include #include "ability_delegator_registry.h" -#include "hilog_wrapper.h" +#include "hilog_tag_wrapper.h" #include "runner_runtime/cj_test_runner_object.h" namespace OHOS { @@ -27,26 +27,26 @@ namespace RunnerRuntime { std::unique_ptr CJTestRunner::Create(const std::unique_ptr &runtime, const std::shared_ptr &args, const AppExecFwk::BundleInfo &bundleInfo) { - HILOG_INFO("CJTestRunner::Create start."); + TAG_LOGI(AAFwkTag::DELEGATOR, "CJTestRunner::Create start."); if (!runtime) { - HILOG_ERROR("Invalid runtime"); + TAG_LOGE(AAFwkTag::DELEGATOR, "Invalid runtime"); return nullptr; } auto cjRuntime = static_cast(runtime.get()); if (!cjRuntime->IsAppLibLoaded()) { - HILOG_ERROR("CJTestRunner: AppLib Not Loaded"); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunner: AppLib Not Loaded"); return nullptr; } if (!args) { - HILOG_ERROR("Invalid ability delegator args"); + TAG_LOGE(AAFwkTag::DELEGATOR, "Invalid ability delegator args"); return nullptr; } auto pTestRunner = new (std::nothrow) CJTestRunner(*cjRuntime, args, bundleInfo); if (!pTestRunner) { - HILOG_ERROR("Failed to create test runner"); + TAG_LOGE(AAFwkTag::DELEGATOR, "Failed to create test runner"); return nullptr; } @@ -65,11 +65,11 @@ CJTestRunner::~CJTestRunner() = default; bool CJTestRunner::Initialize() { if (!cjRuntime_.IsAppLibLoaded()) { - HILOG_ERROR("CJTestRunner: AppLib Not Loaded"); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunner: AppLib Not Loaded"); return false; } if (!cjTestRunnerObj_) { - HILOG_ERROR("CJTestRunnerObj does not exist, Initialize failed."); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunnerObj does not exist, Initialize failed."); return false; } return true; @@ -77,34 +77,34 @@ bool CJTestRunner::Initialize() void CJTestRunner::Prepare() { - HILOG_INFO("Enter"); + TAG_LOGI(AAFwkTag::DELEGATOR, "Enter"); TestRunner::Prepare(); if (!cjTestRunnerObj_) { - HILOG_ERROR("CJTestRunnerObj does not exist, Prepare failed."); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunnerObj does not exist, Prepare failed."); return; } cjTestRunnerObj_->OnPrepare(); - HILOG_INFO("End"); + TAG_LOGI(AAFwkTag::DELEGATOR, "End"); } void CJTestRunner::Run() { - HILOG_INFO("Enter"); + TAG_LOGI(AAFwkTag::DELEGATOR, "Enter"); TestRunner::Run(); if (!cjTestRunnerObj_) { - HILOG_ERROR("CJTestRunnerObj does not exist, OnRun failed."); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJTestRunnerObj does not exist, OnRun failed."); return; } cjTestRunnerObj_->OnRun(); - HILOG_INFO("End"); + TAG_LOGI(AAFwkTag::DELEGATOR, "End"); } void CJTestRunner::ReportFinished(const std::string &msg) { - HILOG_INFO("Enter"); + TAG_LOGI(AAFwkTag::DELEGATOR, "Enter"); auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { - HILOG_ERROR("delegator is null."); + TAG_LOGE(AAFwkTag::DELEGATOR, "delegator is null."); return; } @@ -113,10 +113,10 @@ void CJTestRunner::ReportFinished(const std::string &msg) void CJTestRunner::ReportStatus(const std::string &msg) { - HILOG_INFO("Enter"); + TAG_LOGI(AAFwkTag::DELEGATOR, "Enter"); auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { - HILOG_ERROR("delegator is null."); + TAG_LOGE(AAFwkTag::DELEGATOR, "delegator is null."); return; } diff --git a/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner_object.cpp b/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner_object.cpp index 68ea89ca09..b3fc0acc42 100644 --- a/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner_object.cpp +++ b/frameworks/native/appkit/ability_delegator/runner_runtime/cj_test_runner_object.cpp @@ -17,7 +17,7 @@ #include -#include "hilog_wrapper.h" +#include "hilog_tag_wrapper.h" namespace { // g_cjTestRunnerFuncs is used to save cj functions. @@ -28,20 +28,20 @@ CJTestRunnerFuncs* g_cjTestRunnerFuncs = nullptr; void RegisterCJTestRunnerFuncs(void (*registerFunc)(CJTestRunnerFuncs*)) { - HILOG_INFO("RegisterCJTestRunnerFuncs start."); + TAG_LOGI(AAFwkTag::DELEGATOR, "RegisterCJTestRunnerFuncs start."); if (g_cjTestRunnerFuncs != nullptr) { - HILOG_ERROR("Repeated registration for cj functions of CJTestRunner."); + TAG_LOGE(AAFwkTag::DELEGATOR, "Repeated registration for cj functions of CJTestRunner."); return; } if (registerFunc == nullptr) { - HILOG_ERROR("RegisterCJTestRunnerFuncs failed, registerFunc is nullptr."); + TAG_LOGE(AAFwkTag::DELEGATOR, "RegisterCJTestRunnerFuncs failed, registerFunc is nullptr."); return; } g_cjTestRunnerFuncs = new CJTestRunnerFuncs(); registerFunc(g_cjTestRunnerFuncs); - HILOG_INFO("RegisterCJTestRunnerFuncs end."); + TAG_LOGI(AAFwkTag::DELEGATOR, "RegisterCJTestRunnerFuncs end."); } namespace OHOS { @@ -49,12 +49,12 @@ namespace RunnerRuntime { std::shared_ptr CJTestRunnerObject::LoadModule(const std::string& name) { if (g_cjTestRunnerFuncs == nullptr) { - HILOG_ERROR("cj functions for CJTestRunner are not registered"); + TAG_LOGE(AAFwkTag::DELEGATOR, "cj functions for CJTestRunner are not registered"); return nullptr; } auto id = g_cjTestRunnerFuncs->cjTestRunnerCreate(name.c_str()); if (id == 0) { - HILOG_ERROR( + TAG_LOGE(AAFwkTag::DELEGATOR, "Failed to invoke CJTestRunnerObject::LoadModule. Ability: %{public}s is not registered.", name.c_str()); return nullptr; } @@ -70,7 +70,7 @@ CJTestRunnerObject::~CJTestRunnerObject() void CJTestRunnerObject::OnRun() const { if (g_cjTestRunnerFuncs == nullptr) { - HILOG_ERROR("cj functions for CJTestRunner are not registered"); + TAG_LOGE(AAFwkTag::DELEGATOR, "cj functions for CJTestRunner are not registered"); return; } g_cjTestRunnerFuncs->cjTestRunnerOnRun(id_); @@ -79,7 +79,7 @@ void CJTestRunnerObject::OnRun() const void CJTestRunnerObject::OnPrepare() const { if (g_cjTestRunnerFuncs == nullptr) { - HILOG_ERROR("cj functions for CJTestRunner are not registered"); + TAG_LOGE(AAFwkTag::DELEGATOR, "cj functions for CJTestRunner are not registered"); return; } g_cjTestRunnerFuncs->cjTestRunnerOnPrepare(id_); 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 7625adeb80..631fb0109a 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 @@ -431,7 +431,7 @@ napi_value JsApplicationContextUtils::OnGetCloudFileDir(napi_env env, NapiCallba { auto applicationContext = applicationContext_.lock(); if (!applicationContext) { - HILOG_WARN("applicationContext is already released"); + TAG_LOGW(AAFwkTag::APPKIT, "applicationContext is already released"); return CreateJsUndefined(env); } std::string path = applicationContext->GetCloudFileDir(); @@ -711,7 +711,7 @@ napi_value JsApplicationContextUtils::PreloadUIExtensionAbility(napi_env env, na napi_value JsApplicationContextUtils::OnPreloadUIExtensionAbility(napi_env env, NapiCallbackInfo& info) { - HILOG_DEBUG("called"); + TAG_LOGD(AAFwkTag::APPKIT, "called"); if (info.argc < ARGC_ONE) { TAG_LOGW(AAFwkTag::APPKIT, "Params error!"); ThrowTooFewParametersError(env); diff --git a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp index 20acd7c2ed..e4b9db0fc0 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp @@ -509,7 +509,7 @@ napi_value JsBaseContext::OnGetCloudFileDir(napi_env env, NapiCallbackInfo& info { auto context = context_.lock(); if (!context) { - HILOG_WARN("context is already released"); + TAG_LOGW(AAFwkTag::APPKIT, "context is already released"); return CreateJsUndefined(env); } std::string path = context->GetCloudFileDir(); diff --git a/frameworks/native/runtime/cj_runtime.cpp b/frameworks/native/runtime/cj_runtime.cpp index 6484de795d..d069c1b192 100644 --- a/frameworks/native/runtime/cj_runtime.cpp +++ b/frameworks/native/runtime/cj_runtime.cpp @@ -20,7 +20,7 @@ #include #include "cj_environment.h" -#include "hilog_wrapper.h" +#include "hilog_tag_wrapper.h" #include "hdc_register.h" #include "connect_server_manager.h" @@ -51,7 +51,7 @@ void CJRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths) std::string appPath = ""; for (const auto& kv : appLibPaths) { for (const auto& libPath : kv.second) { - HILOG_INFO("SetCJAppLibPath: %{public}s.", libPath.c_str()); + TAG_LOGI(AAFwkTag::DELEGATOR, "SetCJAppLibPath: %{public}s.", libPath.c_str()); CJRuntime::appLibPaths_.emplace_back(libPath); appPath += appPath.empty() ? libPath : ":" + libPath; } @@ -65,19 +65,19 @@ void CJRuntime::SetAppLibPath(const AppLibPathMap& appLibPaths) bool CJRuntime::Initialize(const Options& options) { if (options.lang != GetLanguage()) { - HILOG_ERROR("CJRuntime Initialize fail, language mismatch"); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJRuntime Initialize fail, language mismatch"); return false; } if (!OHOS::CJEnvironment::GetInstance()->StartRuntime()) { - HILOG_ERROR("start cj runtime failed"); + TAG_LOGE(AAFwkTag::DELEGATOR, "start cj runtime failed"); return false; } if (!OHOS::CJEnvironment::GetInstance()->StartUIScheduler()) { - HILOG_ERROR("start cj ui context failed"); + TAG_LOGE(AAFwkTag::DELEGATOR, "start cj ui context failed"); return false; } if (!LoadCJAppLibrary(CJRuntime::appLibPaths_)) { - HILOG_ERROR("CJRuntime::Initialize fail, load app library fail."); + TAG_LOGE(AAFwkTag::DELEGATOR, "CJRuntime::Initialize fail, load app library fail."); return false; } bundleName_ = options.bundleName; @@ -102,7 +102,7 @@ bool CJRuntime::LoadCJAppLibrary(const AppLibPathVec& appLibPaths) handle = OHOS::CJEnvironment::GetInstance()->LoadCJLibrary(itor.path().c_str()); if (handle == nullptr) { char* errMsg = dlerror(); - HILOG_ERROR( + TAG_LOGE(AAFwkTag::DELEGATOR, "Failed to load %{public}s : reason: %{public}s.", itor.path().c_str(), errMsg ? errMsg : "null"); return false; } @@ -130,7 +130,7 @@ void CJRuntime::SetHWAsanVersion() void CJRuntime::StartDebugMode(const DebugOption dOption) { if (debugModel_) { - HILOG_INFO("Already in debug mode"); + TAG_LOGI(AAFwkTag::DELEGATOR, "Already in debug mode"); return; } @@ -139,12 +139,13 @@ void CJRuntime::StartDebugMode(const DebugOption dOption) const std::string bundleName = bundleName_; std::string inputProcessName = bundleName_ != dOption.processName ? dOption.processName : ""; - HILOG_INFO("StartDebugMode %{public}s", bundleName_.c_str()); + TAG_LOGI(AAFwkTag::DELEGATOR, "StartDebugMode %{public}s", bundleName_.c_str()); HdcRegister::Get().StartHdcRegister(bundleName_, inputProcessName, isDebugApp, [bundleName, isStartWithDebug, isDebugApp](int socketFd, std::string option) { - HILOG_INFO("HdcRegister callback is call, socket fd is %{public}d, option is %{public}s.", - socketFd, option.c_str()); + TAG_LOGI(AAFwkTag::DELEGATOR, + "HdcRegister callback is call, socket fd is %{public}d, option is %{public}s.", + socketFd, option.c_str()); if (option.find(DEBUGGER) == std::string::npos) { if (!isDebugApp) { ConnectServerManager::Get().StopConnectServer(false); @@ -152,7 +153,7 @@ void CJRuntime::StartDebugMode(const DebugOption dOption) ConnectServerManager::Get().SendDebuggerInfo(isStartWithDebug, isDebugApp); ConnectServerManager::Get().StartConnectServer(bundleName, socketFd, false); } else { - HILOG_ERROR("debugger service unexpected option: %{public}s", option.c_str()); + TAG_LOGE(AAFwkTag::DELEGATOR, "debugger service unexpected option: %{public}s", option.c_str()); } }); if (isDebugApp) { @@ -170,5 +171,5 @@ bool CJRuntime::StartDebugger() void CJRuntime::UnLoadCJAppLibrary() { - HILOG_INFO("UnLoadCJAppLibrary not support yet"); + TAG_LOGI(AAFwkTag::DELEGATOR, "UnLoadCJAppLibrary not support yet"); } diff --git a/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp b/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp index ec74fcc551..efde447aee 100644 --- a/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp +++ b/frameworks/simulator/ability_simulator/src/js_application_context_utils.cpp @@ -227,7 +227,7 @@ napi_value JsApplicationContextUtils::OnGetCloudFileDir(napi_env env, NapiCallba { auto context = context_.lock(); if (!context) { - HILOG_WARN("context is already released"); + TAG_LOGW(AAFwkTag::ABILITY_SIM, "context is already released"); return CreateJsUndefined(env); } std::string path = context->GetCloudFileDir(); From 988055f5fd5997628762879d6f08325565f3df5c Mon Sep 17 00:00:00 2001 From: liangzhao Date: Wed, 3 Jul 2024 03:32:21 +0000 Subject: [PATCH 146/148] fix loop operation for ability in ability cache Signed-off-by: liangzhao --- .../include/ability_cache_manager.h | 40 +++++ .../include/ability_connect_manager.h | 1 + .../abilitymgr/src/ability_cache_manager.cpp | 97 ++++++++++- .../src/ability_connect_manager.cpp | 132 ++++++++++++-- .../ability_cache_manager_test.cpp | 164 ++++++++++++++++++ 5 files changed, 414 insertions(+), 20 deletions(-) diff --git a/services/abilitymgr/include/ability_cache_manager.h b/services/abilitymgr/include/ability_cache_manager.h index fb23674f35..1c2538288a 100644 --- a/services/abilitymgr/include/ability_cache_manager.h +++ b/services/abilitymgr/include/ability_cache_manager.h @@ -21,6 +21,8 @@ #include #include +#include "ability_config.h" +#include "ability_info.h" #include "ability_record.h" namespace OHOS { namespace AAFwk { @@ -31,6 +33,7 @@ namespace AAFwk { class AbilityCacheManager { public: using AbilityInfo = OHOS::AppExecFwk::AbilityInfo; + using AbilityType = OHOS::AppExecFwk::AbilityType; /** * Get ability cache manager. * @return AbilityCacheManager @@ -70,6 +73,43 @@ public: * @return AbilityRecord if one is matched, otherwise nullptr. */ std::shared_ptr FindRecordByToken(const sptr &token); + + /** + * Get all the abilities of current ability cache manager. + * @return AbilityRecord list. + */ + std::list> GetAbilityList(); + + /** + * Get a single ability by sessionId from ability cache manager. + * @param assertSessionId the ability assertSessionId to be searched in cache manager. + * @return AbilityRecord if one is matched, otherwise nullptr. + */ + std::shared_ptr FindRecordBySessionId(const std::string &assertSessionId); + + /** + * Get a single ability by serviceKey from ability cache manager. + * @param serviceKey the ability serviceKey to be searched in cache manager. + * @return AbilityRecord if one is matched, otherwise nullptr. + */ + std::shared_ptr FindRecordByServiceKey(const std::string &serviceKey); + + /** + * Remove the launcher death recipient from ability cache manager. + */ + void RemoveLauncherDeathRecipient(); + + /** + * Sign the restart flag by bundleName of ability from ability cache manager. + * @param bundleName the ability bundleName to be searched in cache manager. + */ + void SignRestartAppFlag(const std::string &bundleName); + + /** + * Delete the invalid ability by bundleName from ability cache manager. + * @param bundleName the ability bundleName to be searched in cache manager. + */ + void DeleteInvalidServiceRecord(const std::string &bundleName); private: AbilityCacheManager(); ~AbilityCacheManager(); diff --git a/services/abilitymgr/include/ability_connect_manager.h b/services/abilitymgr/include/ability_connect_manager.h index 526a98850b..a0f8871ce6 100644 --- a/services/abilitymgr/include/ability_connect_manager.h +++ b/services/abilitymgr/include/ability_connect_manager.h @@ -590,6 +590,7 @@ private: void KeepAbilityAlive(const std::shared_ptr &abilityRecord, int32_t currentUserId); void ProcessEliminateAbilityRecord(std::shared_ptr eliminateRecord); + std::string GetServiceKey(const std::shared_ptr &service); private: const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; diff --git a/services/abilitymgr/src/ability_cache_manager.cpp b/services/abilitymgr/src/ability_cache_manager.cpp index b6e3763d04..cde717d481 100644 --- a/services/abilitymgr/src/ability_cache_manager.cpp +++ b/services/abilitymgr/src/ability_cache_manager.cpp @@ -21,6 +21,8 @@ namespace OHOS { namespace AAFwk { +const std::string FRS_APP_INDEX = "ohos.extra.param.key.frs_index"; +const std::string FRS_BUNDLE_NAME = "com.ohos.formrenderservice"; AbilityCacheManager::AbilityCacheManager() {} @@ -194,12 +196,14 @@ std::shared_ptr AbilityCacheManager::FindRecordByToken(const sptr TAG_LOGE(AAFwkTag::ABILITYMGR, "The param token is nullptr for FindRecordByToken operation."); return nullptr; } + std::lock_guard lock(mutex_); auto it = devRecLru_.begin(); while (it != devRecLru_.end()) { sptr srcToken = (*it)->GetToken(); if (srcToken == token) { std::shared_ptr &abilityRecord = *it; - TAG_LOGD(AAFwkTag::ABILITYMGR, "Find the ability from lru, service:%{public}s, extension type %{public}d", + TAG_LOGD(AAFwkTag::ABILITYMGR, + "Find the ability by token from lru, service:%{public}s, extension type %{public}d", abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); return abilityRecord; } else { @@ -208,5 +212,96 @@ std::shared_ptr AbilityCacheManager::FindRecordByToken(const sptr } return nullptr; } + +std::list> AbilityCacheManager::GetAbilityList() +{ + std::lock_guard lock(mutex_); + return devRecLru_; +} + +std::shared_ptr AbilityCacheManager::FindRecordBySessionId(const std::string &assertSessionId) +{ + std::lock_guard lock(mutex_); + auto it = devRecLru_.begin(); + while (it != devRecLru_.end()) { + auto assertSessionStr = (*it)->GetWant().GetStringParam(Want::PARAM_ASSERT_FAULT_SESSION_ID); + if (assertSessionStr == assertSessionId) { + std::shared_ptr &abilityRecord = *it; + TAG_LOGD(AAFwkTag::ABILITYMGR, + "Find the ability by sessionId from lru, service:%{public}s, extension type %{public}d", + abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); + return abilityRecord; + } else { + it++; + } + } + return nullptr; +} + +std::shared_ptr AbilityCacheManager::FindRecordByServiceKey(const std::string &serviceKey) +{ + std::lock_guard lock(mutex_); + auto it = devRecLru_.begin(); + while (it != devRecLru_.end()) { + std::string curServiceKey = (*it)->GetURI(); + if (FRS_BUNDLE_NAME == (*it)->GetAbilityInfo().bundleName) { + curServiceKey = curServiceKey + std::to_string((*it)->GetWant().GetIntParam(FRS_APP_INDEX, 0)); + } + if (curServiceKey.compare(serviceKey) == 0) { + std::shared_ptr &abilityRecord = *it; + TAG_LOGD(AAFwkTag::ABILITYMGR, + "Find the ability by serviceKey from lru, service:%{public}s, extension type %{public}d", + abilityRecord->GetURI().c_str(), abilityRecord->GetAbilityInfo().extensionAbilityType); + return abilityRecord; + } else { + it++; + } + } + return nullptr; +} + +void AbilityCacheManager::RemoveLauncherDeathRecipient() +{ + std::lock_guard lock(mutex_); + auto it = devRecLru_.begin(); + while (it != devRecLru_.end()) { + auto targetExtension = *it; + if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION && + ((targetExtension->GetAbilityInfo().name == AbilityConfig::LAUNCHER_ABILITY_NAME && + targetExtension->GetAbilityInfo().bundleName == AbilityConfig::LAUNCHER_BUNDLE_NAME) || + targetExtension->IsSceneBoard())) { + targetExtension->RemoveAbilityDeathRecipient(); + return; + } + it++; + } +} + +void AbilityCacheManager::SignRestartAppFlag(const std::string &bundleName) +{ + std::lock_guard lock(mutex_); + auto it = devRecLru_.begin(); + while (it != devRecLru_.end()) { + auto abilityRecord = *it; + if (abilityRecord != nullptr && abilityRecord->GetApplicationInfo().bundleName == bundleName) { + abilityRecord->SetRestartAppFlag(true); + } + it++; + } +} + +void AbilityCacheManager::DeleteInvalidServiceRecord(const std::string &bundleName) +{ + std::lock_guard lock(mutex_); + auto it = devRecLru_.begin(); + while (it != devRecLru_.end()) { + auto abilityRecord = *it; + if (abilityRecord != nullptr && abilityRecord->GetApplicationInfo().bundleName == bundleName) { + RemoveAbilityRecInProcList(abilityRecord); + RemoveAbilityRecInDevList(abilityRecord); + } + it++; + } +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 269ec90ad0..c68d5853ed 100644 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -765,7 +765,8 @@ int AbilityConnectManager::DisconnectAbilityLocked(const sptr abilityRecord) { TAG_LOGI(AAFwkTag::ABILITYMGR, "terminate record called."); - if (!GetAbilityRecordById(abilityRecord->GetRecordId())) { + if (!GetAbilityRecordById(abilityRecord->GetRecordId()) && + !AbilityCacheManager::GetInstance().FindRecordByToken(abilityRecord->GetToken())) { return; } auto timeoutTask = [abilityRecord, connectManager = shared_from_this()]() { @@ -892,6 +893,22 @@ void AbilityConnectManager::OnAppStateChanged(const AppInfo &info) } } }); + + auto cacheAbilityList = AbilityCacheManager::GetInstance().GetAbilityList(); + std::for_each(cacheAbilityList.begin(), cacheAbilityList.end(), [&info](std::shared_ptr &service) { + if (service && (info.processName == service->GetAbilityInfo().process || + info.processName == service->GetApplicationInfo().bundleName)) { + auto appName = service->GetApplicationInfo().name; + auto uid = service->GetAbilityInfo().applicationInfo.uid; + auto isExist = [&appName, &uid](const AppData &appData) { + return appData.appName == appName && appData.uid == uid; + }; + auto iter = std::find_if(info.appData.begin(), info.appData.end(), isExist); + if (iter != info.appData.end()) { + service->SetAppState(info.state); + } + } + }); } int AbilityConnectManager::AbilityTransitionDone(const sptr &token, int state) @@ -2175,7 +2192,7 @@ void AbilityConnectManager::HandleNotifyAssertFaultDialogDied(const std::shared_ void AbilityConnectManager::CloseAssertDialog(const std::string &assertSessionId) { TAG_LOGD(AAFwkTag::ABILITYMGR, "Called"); - sptr token; + std::shared_ptr abilityRecord = nullptr; { std::lock_guard lock(serviceMapMutex_); for (const auto &item : serviceMap_) { @@ -2185,14 +2202,26 @@ void AbilityConnectManager::CloseAssertDialog(const std::string &assertSessionId auto assertSessionStr = item.second->GetWant().GetStringParam(Want::PARAM_ASSERT_FAULT_SESSION_ID); if (assertSessionStr == assertSessionId) { - TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate assert fault dialog called."); - terminatingExtensionMap_.emplace(item.first, item.second); - token = item.second->GetToken(); + abilityRecord = item.second; serviceMap_.erase(item.first); break; } } } + if (abilityRecord == nullptr) { + abilityRecord = AbilityCacheManager::GetInstance().FindRecordBySessionId(assertSessionId); + AbilityCacheManager::GetInstance().Remove(abilityRecord); + } + if (abilityRecord == nullptr) { + return; + } + TAG_LOGD(AAFwkTag::ABILITYMGR, "Terminate assert fault dialog called."); + std::string serviceKey = abilityRecord->GetURI(); + if (FRS_BUNDLE_NAME == abilityRecord->GetAbilityInfo().bundleName) { + serviceKey = serviceKey + std::to_string(abilityRecord->GetWant().GetIntParam(FRS_APP_INDEX, 0)); + } + terminatingExtensionMap_.emplace(serviceKey, abilityRecord); + sptr token = abilityRecord->GetToken(); if (token != nullptr) { std::lock_guard lock(serialMutex_); TerminateAbilityLocked(token); @@ -2273,10 +2302,20 @@ void AbilityConnectManager::RestartAbility(const std::shared_ptr } } +std::string AbilityConnectManager::GetServiceKey(const std::shared_ptr &service) +{ + std::string serviceKey = service->GetURI(); + if (FRS_BUNDLE_NAME == service->GetAbilityInfo().bundleName) { + serviceKey = serviceKey + std::to_string(service->GetWant().GetIntParam(FRS_APP_INDEX, 0)); + } + return serviceKey; +} + void AbilityConnectManager::DumpState(std::vector &info, bool isClient, const std::string &args) { TAG_LOGI(AAFwkTag::ABILITYMGR, "args:%{public}s.", args.c_str()); auto serviceMapBack = GetServiceMap(); + auto cacheList = AbilityCacheManager::GetInstance().GetAbilityList(); if (!args.empty()) { auto it = std::find_if(serviceMapBack.begin(), serviceMapBack.end(), [&args](const auto &service) { return service.first.compare(args) == 0; @@ -2287,7 +2326,21 @@ void AbilityConnectManager::DumpState(std::vector &info, bool isCli it->second->DumpService(info, isClient); } } else { - info.emplace_back(args + ": Nothing to dump."); + info.emplace_back(args + ": Nothing to dump from serviceMap."); + } + + std::string serviceKey; + auto iter = std::find_if(cacheList.begin(), cacheList.end(), [&args, &serviceKey, this](const auto &service) { + serviceKey = GetServiceKey(service); + return serviceKey.compare(args) == 0; + }); + if (iter != cacheList.end()) { + info.emplace_back("uri [ " + serviceKey + " ]"); + if (*iter != nullptr) { + (*iter)->DumpService(info, isClient); + } + } else { + info.emplace_back(args + ": Nothing to dump from lru cache."); } } else { info.emplace_back(" ExtensionRecords:"); @@ -2297,6 +2350,13 @@ void AbilityConnectManager::DumpState(std::vector &info, bool isCli service.second->DumpService(info, isClient); } } + for (auto &&service : cacheList) { + std::string serviceKey = GetServiceKey(service); + info.emplace_back(" uri [" + serviceKey + "]"); + if (service != nullptr) { + service->DumpService(info, isClient); + } + } } } @@ -2314,11 +2374,19 @@ void AbilityConnectManager::DumpStateByUri(std::vector &info, bool info.emplace_back("uri [ " + it->first + " ]"); extensionAbilityRecord = it->second; } else { - info.emplace_back(args + ": Nothing to dump."); + info.emplace_back(args + ": Nothing to dump from serviceMap."); } } if (extensionAbilityRecord != nullptr) { extensionAbilityRecord->DumpService(info, params, isClient); + return; + } + extensionAbilityRecord = AbilityCacheManager::GetInstance().FindRecordByServiceKey(args); + if (extensionAbilityRecord != nullptr) { + info.emplace_back("uri [ " + args + " ]"); + extensionAbilityRecord->DumpService(info, params, isClient); + } else { + info.emplace_back(args + ": Nothing to dump from lru cache."); } } @@ -2345,6 +2413,25 @@ void AbilityConnectManager::GetExtensionRunningInfos(int upperLimit, std::vector } }; std::for_each(serviceMapBack.begin(), serviceMapBack.end(), queryInfo); + + auto cacheAbilityList = AbilityCacheManager::GetInstance().GetAbilityList(); + auto queryInfoForCache = [&](std::shared_ptr &service) { + if (static_cast(info.size()) >= upperLimit) { + return; + } + CHECK_POINTER(service); + + if (isPerm) { + GetExtensionRunningInfo(service, userId, info); + } else { + auto callingTokenId = IPCSkeleton::GetCallingTokenID(); + auto tokenID = service->GetApplicationInfo().accessTokenId; + if (callingTokenId == tokenID) { + GetExtensionRunningInfo(service, userId, info); + } + } + }; + std::for_each(cacheAbilityList.begin(), cacheAbilityList.end(), queryInfoForCache); } void AbilityConnectManager::GetAbilityRunningInfos(std::vector &info, bool isPerm) @@ -2429,15 +2516,18 @@ void AbilityConnectManager::PauseExtensions() void AbilityConnectManager::RemoveLauncherDeathRecipient() { TAG_LOGI(AAFwkTag::ABILITYMGR, "Call."); - std::lock_guard lock(serviceMapMutex_); - for (auto it = serviceMap_.begin(); it != serviceMap_.end(); ++it) { - auto targetExtension = it->second; - if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION && - (IsLauncher(targetExtension) || targetExtension->IsSceneBoard())) { - targetExtension->RemoveAbilityDeathRecipient(); - break; + { + std::lock_guard lock(serviceMapMutex_); + for (auto it = serviceMap_.begin(); it != serviceMap_.end(); ++it) { + auto targetExtension = it->second; + if (targetExtension != nullptr && targetExtension->GetAbilityInfo().type == AbilityType::EXTENSION && + (IsLauncher(targetExtension) || targetExtension->IsSceneBoard())) { + targetExtension->RemoveAbilityDeathRecipient(); + return; + } } } + AbilityCacheManager::GetInstance().RemoveLauncherDeathRecipient(); } bool AbilityConnectManager::IsLauncher(std::shared_ptr serviceExtension) const @@ -2938,13 +3028,16 @@ std::shared_ptr AbilityConnectManager::GetUIExtensionRootH void AbilityConnectManager::SignRestartAppFlag(const std::string &bundleName) { - std::lock_guard lock(serviceMapMutex_); - for (auto &[key, abilityRecord] : serviceMap_) { - if (abilityRecord == nullptr || abilityRecord->GetApplicationInfo().bundleName != bundleName) { - continue; + { + std::lock_guard lock(serviceMapMutex_); + for (auto &[key, abilityRecord] : serviceMap_) { + if (abilityRecord == nullptr || abilityRecord->GetApplicationInfo().bundleName != bundleName) { + continue; + } + abilityRecord->SetRestartAppFlag(true); } - abilityRecord->SetRestartAppFlag(true); } + AbilityCacheManager::GetInstance().SignRestartAppFlag(bundleName); } void AbilityConnectManager::DeleteInvalidServiceRecord(const std::string &bundleName) @@ -2959,6 +3052,7 @@ void AbilityConnectManager::DeleteInvalidServiceRecord(const std::string &bundle ++it; } } + AbilityCacheManager::GetInstance().DeleteInvalidServiceRecord(bundleName); } bool AbilityConnectManager::AddToServiceMap(const std::string &key, std::shared_ptr abilityRecord) diff --git a/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp b/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp index e164f9f3be..e5a5c92bbb 100644 --- a/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp +++ b/test/unittest/ability_cache_manager_test/ability_cache_manager_test.cpp @@ -500,5 +500,169 @@ HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindByToken_001, TestSize.L EXPECT_EQ(recGet->GetRecordId(), recId); } +/** + * @tc.name: AbilityCacheManagerGetAbilityList_001 + * @tc.desc: Put a single ability record into cache and get ability list + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerGetAbilityList_001, TestSize.Level0) +{ + OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.moduleName = "TestModuleName"; + abilityInfo.bundleName = "TestBundleName"; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + applicationInfo.accessTokenId = 0; + Want want; + auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord_->Init(); + int recId = abilityRecord_->GetRecordId(); + std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + EXPECT_EQ(rec, nullptr); + auto abilityList = OHOS::AAFwk::AbilityCacheManager::GetInstance().GetAbilityList(); + EXPECT_EQ(abilityList.size(), 1); + auto recordFind = *(abilityList.begin()); + EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recordFind->GetRecordId(), recId); + OHOS::AAFwk::AbilityCacheManager::GetInstance().Remove(abilityRecord_); +} + +/** + * @tc.name: AbilityCacheManagerFindBySessionId_001 + * @tc.desc: Put a single ability record into cache and find it, find will not remove cache + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindBySessionId_001, TestSize.Level0) +{ + OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + std::string sessionId = "TestSessionId"; + abilityInfo.moduleName = "TestModuleName"; + abilityInfo.bundleName = "TestBundleName"; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + applicationInfo.accessTokenId = 0; + Want want; + want.SetParam(Want::PARAM_ASSERT_FAULT_SESSION_ID, sessionId); + auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord_->Init(); + int recId = abilityRecord_->GetRecordId(); + std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + EXPECT_EQ(rec, nullptr); + auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().FindRecordBySessionId(sessionId); + EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recordFind->GetRecordId(), recId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo = abilityInfo; + abilityRequest.appInfo = applicationInfo; + auto recGet = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); + EXPECT_EQ(recGet->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recGet->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recGet->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recGet->GetRecordId(), recId); +} + +/** + * @tc.name: AbilityCacheManagerFindByServiceKey_001 + * @tc.desc: Put a single ability record into cache and find it, find will not remove cache + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerFindByServiceKey_001, TestSize.Level0) +{ + OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.moduleName = "TestModuleName"; + abilityInfo.bundleName = "TestBundleName"; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + applicationInfo.accessTokenId = 0; + Want want; + auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord_->Init(); + int recId = abilityRecord_->GetRecordId(); + std::string serviceKey = abilityRecord_->GetURI(); + std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + EXPECT_EQ(rec, nullptr); + auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().FindRecordByServiceKey(serviceKey); + EXPECT_EQ(recordFind->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recordFind->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recordFind->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recordFind->GetRecordId(), recId); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo = abilityInfo; + abilityRequest.appInfo = applicationInfo; + auto recGet = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); + EXPECT_EQ(recGet->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(recGet->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(recGet->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(recGet->GetRecordId(), recId); +} + +/** + * @tc.name: AbilityCacheManagerSignRestartAppFlag_001 + * @tc.desc: Put a single ability record into cache and sign restart app flag + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerSignRestartAppFlag_001, TestSize.Level0) +{ + OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.moduleName = "TestModuleName"; + abilityInfo.bundleName = "TestBundleName"; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + applicationInfo.accessTokenId = 0; + applicationInfo.bundleName = abilityInfo.bundleName; + Want want; + auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord_->Init(); + int recId = abilityRecord_->GetRecordId(); + std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + EXPECT_EQ(rec, nullptr); + OHOS::AAFwk::AbilityCacheManager::GetInstance().SignRestartAppFlag(applicationInfo.bundleName); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo = abilityInfo; + abilityRequest.appInfo = applicationInfo; + auto recordFind = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); + EXPECT_EQ(recordFind->GetRestartAppFlag(), true); +} + +/** + * @tc.name: AbilityCacheManagerDeleteInvalidRecord_001 + * @tc.desc: Put a single ability record into cache and delete it by bundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AbilityCacheManagerTest, AbilityCacheManagerDeleteInvalidRecord_001, TestSize.Level0) +{ + OHOS::AAFwk::AbilityCacheManager::GetInstance().Init(10, 5); + OHOS::AppExecFwk::AbilityInfo abilityInfo; + abilityInfo.moduleName = "TestModuleName"; + abilityInfo.bundleName = "TestBundleName"; + OHOS::AppExecFwk::ApplicationInfo applicationInfo; + applicationInfo.accessTokenId = 0; + Want want; + auto abilityRecord_ = std::make_shared(want, abilityInfo, applicationInfo); + abilityRecord_->Init(); + int recId = abilityRecord_->GetRecordId(); + std::shared_ptr rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Put(abilityRecord_); + EXPECT_EQ(rec, nullptr); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo = abilityInfo; + abilityRequest.appInfo = applicationInfo; + rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); + EXPECT_EQ(rec->GetApplicationInfo().accessTokenId, applicationInfo.accessTokenId); + EXPECT_EQ(rec->GetAbilityInfo().moduleName, abilityInfo.moduleName); + EXPECT_EQ(rec->GetAbilityInfo().bundleName, abilityInfo.bundleName); + EXPECT_EQ(rec->GetRecordId(), recId); + OHOS::AAFwk::AbilityCacheManager::GetInstance().DeleteInvalidServiceRecord(abilityInfo.bundleName); + rec = OHOS::AAFwk::AbilityCacheManager::GetInstance().Get(abilityRequest); + EXPECT_EQ(rec, nullptr); +} } // namespace AAFwk } // namespace OHOS From 9816c40d78b03608e7ebcce1a1f583c68b898242 Mon Sep 17 00:00:00 2001 From: songjindian Date: Thu, 4 Jul 2024 11:10:22 +0800 Subject: [PATCH 147/148] =?UTF-8?q?=E9=80=82=E9=85=8D=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E8=B0=83=E5=BA=A6=E6=9C=80=E6=96=B0uid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songjindian --- services/appmgr/src/app_mgr_service_inner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 51f838f120..c0e27d3b52 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -216,6 +216,7 @@ constexpr int32_t FOUNDATION_UID = 5523; constexpr int32_t QUICKFIX_UID = 5524; constexpr int32_t DEFAULT_USER_ID = 0; constexpr int32_t CURRENT_USER_ID = -1; +constexpr int32_t RESOURCE_MANAGER_UID = 1096; constexpr int32_t BLUETOOTH_GROUPID = 1002; @@ -5660,7 +5661,7 @@ int32_t AppMgrServiceInner::ChangeAppGcState(pid_t pid, int32_t state) { auto callerUid = IPCSkeleton::GetCallingUid(); TAG_LOGD(AAFwkTag::APPMGR, "called, pid:%{public}d, state:%{public}d, uid:%{public}d.", pid, state, callerUid); - if (callerUid != ROOT_UID) { // The current UID for resource management is 0 + if (callerUid != RESOURCE_MANAGER_UID) { // The current UID for resource management is 1096 TAG_LOGE(AAFwkTag::APPMGR, "The caller is not a resource manager."); return ERR_INVALID_VALUE; } From 42d79287d11524178b68facd199c2a0c88b3095f Mon Sep 17 00:00:00 2001 From: hanchenZz Date: Thu, 4 Jul 2024 10:40:52 +0800 Subject: [PATCH 148/148] =?UTF-8?q?=E6=95=B4=E6=94=B9=E6=9C=AA=E4=BD=BF?= =?UTF-8?q?=E7=94=A8TAG=5FLOG=E6=89=93=E5=8D=B0=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hanchenZz --- services/abilitymgr/src/ability_manager_proxy.cpp | 8 ++++---- services/abilitymgr/src/ability_manager_service.cpp | 6 +++--- services/abilitymgr/src/ability_manager_stub.cpp | 2 +- .../src/interceptor/disposed_rule_interceptor.cpp | 2 +- services/appmgr/src/app_spawn_client.cpp | 4 ++-- services/common/src/event_report.cpp | 7 ++++--- services/common/src/permission_verification.cpp | 12 ++++++++---- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 1914ff778a..c865e4a50f 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -5189,22 +5189,22 @@ int32_t AbilityManagerProxy::SetResidentProcessEnabled(const std::string &bundle { MessageParcel data; if (!WriteInterfaceToken(data)) { - HILOG_ERROR("Write interface token failed."); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed."); return INNER_ERR; } if (!data.WriteString(bundleName)) { - HILOG_ERROR("Write bundl name failed."); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write bundl name failed."); return INNER_ERR; } if (!data.WriteBool(enable)) { - HILOG_ERROR("Write enable status failed."); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write enable status failed."); return INNER_ERR; } MessageParcel reply; MessageOption option; auto ret = SendRequest(AbilityManagerInterfaceCode::SET_RESIDENT_PROCESS_ENABLE, data, reply, option); if (ret != NO_ERROR) { - HILOG_ERROR("Send request error: %{public}d.", ret); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d.", ret); return ret; } diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 9c692a9ca0..d3f304fb7f 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -10378,13 +10378,13 @@ int32_t AbilityManagerService::SetResidentProcessEnabled(const std::string &bund { TAG_LOGD(AAFwkTag::ABILITYMGR, "Called."); if (!AAFwk::PermissionVerification::GetInstance()->IsSystemAppCall()) { - HILOG_ERROR("Permission verification failed."); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Permission verification failed."); return ERR_NOT_SYSTEM_APP; } auto residentProcessManager = DelayedSingleton::GetInstance(); if (residentProcessManager == nullptr) { - HILOG_ERROR("Get resident proces mgr is nullptr"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Get resident proces mgr is nullptr"); return INNER_ERR; } @@ -10393,7 +10393,7 @@ int32_t AbilityManagerService::SetResidentProcessEnabled(const std::string &bund auto callerPid = IPCSkeleton::GetCallingPid(); DelayedSingleton::GetInstance()->GetBundleNameByPid(callerPid, callerName, uid); if (callerName.empty()) { - HILOG_ERROR("Failed to obtain caller name."); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to obtain caller name."); return INNER_ERR; } diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 1d344c51f2..d9490e0016 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -3841,7 +3841,7 @@ int32_t AbilityManagerStub::SetResidentProcessEnableInner(MessageParcel &data, M bool enable = data.ReadBool(); auto result = SetResidentProcessEnabled(bundleName, enable); if (!reply.WriteInt32(result)) { - HILOG_ERROR("Write result failed."); + TAG_LOGE(AAFwkTag::ABILITYMGR, "Write result failed."); return ERR_INVALID_VALUE; } return NO_ERROR; diff --git a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp index 16a6b38728..eb2d57e626 100644 --- a/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp +++ b/services/abilitymgr/src/interceptor/disposed_rule_interceptor.cpp @@ -108,7 +108,7 @@ bool DisposedRuleInterceptor::CheckControl(const Want &want, int32_t userId, auto ret = IN_PROCESS_CALL(appControlMgr->GetAbilityRunningControlRule(bundleName, userId, disposedRuleList)); if (ret != ERR_OK || disposedRuleList.empty()) { - HILOG_DEBUG("Get No DisposedRule"); + TAG_LOGD(AAFwkTag::ABILITYMGR, "Get No DisposedRule"); return false; } } diff --git a/services/appmgr/src/app_spawn_client.cpp b/services/appmgr/src/app_spawn_client.cpp index 5452ce4ece..d1a31262c1 100644 --- a/services/appmgr/src/app_spawn_client.cpp +++ b/services/appmgr/src/app_spawn_client.cpp @@ -50,7 +50,7 @@ AppSpawnClient::AppSpawnClient(bool isNWebSpawn) AppSpawnClient::AppSpawnClient(const char* serviceName) { - HILOG_DEBUG("AppspawnCreateClient"); + TAG_LOGD(AAFwkTag::APPMGR, "AppspawnCreateClient"); std::string serviceName__ = serviceName; if (serviceName__ == APPSPAWN_SERVER_NAME) { serviceName_ = APPSPAWN_SERVER_NAME; @@ -59,7 +59,7 @@ AppSpawnClient::AppSpawnClient(const char* serviceName) } else if (serviceName__ == NWEBSPAWN_SERVER_NAME) { serviceName_ = NWEBSPAWN_SERVER_NAME; } else { - HILOG_ERROR("unknown service name"); + TAG_LOGE(AAFwkTag::APPMGR, "unknown service name"); serviceName_ = NWEBSPAWN_SERVER_NAME; } state_ = SpawnConnectionState::STATE_NOT_CONNECT; diff --git a/services/common/src/event_report.cpp b/services/common/src/event_report.cpp index b1e17b3616..4ad86acb85 100644 --- a/services/common/src/event_report.cpp +++ b/services/common/src/event_report.cpp @@ -114,7 +114,7 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty TAG_LOGE(AAFwkTag::DEFAULT, "invalid eventName"); return; } - HILOG_DEBUG("EventName is %{public}s", name.c_str()); + TAG_LOGD(AAFwkTag::DEFAULT, "EventName is %{public}s", name.c_str()); switch (eventName) { case EventName::START_ABILITY_ERROR: case EventName::TERMINATE_ABILITY_ERROR: @@ -182,8 +182,9 @@ void EventReport::SendAbilityEvent(const EventName &eventName, HiSysEventType ty EVENT_KEY_CALLER_BUNDLE_NAME, eventInfo.callerBundleName); break; case EventName::START_STANDARD_ABILITIES: - HILOG_DEBUG("EventInfo is [%{public}d, %{public}s, %{public}s, %{public}s]", eventInfo.userId, - eventInfo.bundleName.c_str(), eventInfo.moduleName.c_str(), eventInfo.abilityName.c_str()); + TAG_LOGD(AAFwkTag::DEFAULT, "EventInfo is [%{public}d, %{public}s, %{public}s, %{public}s]", + eventInfo.userId, eventInfo.bundleName.c_str(), eventInfo.moduleName.c_str(), + eventInfo.abilityName.c_str()); HiSysEventWrite( HiSysEvent::Domain::AAFWK, name, diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index 92608fa1db..72b99ddf97 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -209,10 +209,12 @@ int32_t PermissionVerification::VerifyUpdateConfigurationPerm() const int32_t PermissionVerification::VerifyUpdateAPPConfigurationPerm() const { if (VerifyCallingPermission(PermissionConstants::PERMISSION_UPDATE_APP_CONFIGURATION)) { - HILOG_INFO("Verify permission %{public}s succeed.", PermissionConstants::PERMISSION_UPDATE_APP_CONFIGURATION); + TAG_LOGI(AAFwkTag::DEFAULT, + "Verify permission %{public}s succeed.", PermissionConstants::PERMISSION_UPDATE_APP_CONFIGURATION); return ERR_OK; } - HILOG_ERROR("Verify permission %{public}s failed.", PermissionConstants::PERMISSION_UPDATE_APP_CONFIGURATION); + TAG_LOGE(AAFwkTag::DEFAULT, + "Verify permission %{public}s failed.", PermissionConstants::PERMISSION_UPDATE_APP_CONFIGURATION); return ERR_PERMISSION_DENIED; } @@ -466,10 +468,12 @@ bool PermissionVerification::VerifyShellStartExtensionType(int32_t type) const bool PermissionVerification::VerifyPreloadApplicationPermission() const { if (VerifyCallingPermission(PermissionConstants::PERMISSION_PRELOAD_APPLICATION)) { - HILOG_DEBUG("Verify permission %{public}s succeed.", PermissionConstants::PERMISSION_PRELOAD_APPLICATION); + TAG_LOGD(AAFwkTag::DEFAULT, "Verify permission %{public}s succeed.", + PermissionConstants::PERMISSION_PRELOAD_APPLICATION); return true; } - HILOG_ERROR("Verify permission %{public}s failed.", PermissionConstants::PERMISSION_PRELOAD_APPLICATION); + TAG_LOGE(AAFwkTag::DEFAULT, "Verify permission %{public}s failed.", + PermissionConstants::PERMISSION_PRELOAD_APPLICATION); return false; }