diff --git a/interfaces/inner_api/ability_manager/BUILD.gn b/interfaces/inner_api/ability_manager/BUILD.gn index 55d58d3ea7abfb7c584459f4181dd618d19c0223..fe92dd3919a82a7fa09ddc18d704d2df7d413d23 100644 --- a/interfaces/inner_api/ability_manager/BUILD.gn +++ b/interfaces/inner_api/ability_manager/BUILD.gn @@ -41,7 +41,7 @@ config("ability_manager_public_config") { "${ability_runtime_path}/interfaces/kits/native/appkit", "${ability_runtime_innerkits_path}/dataobs_manager/include", ] - + configs = [ "${ability_runtime_innerkits_path}/app_manager:appmgr_innerkits_config", ] defines = [] if (ability_command_for_test) { @@ -134,6 +134,7 @@ ohos_shared_library("ability_manager") { public_configs = [ ":ability_manager_public_config", "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_innerkits_path}/app_manager:appmgr_innerkits_config", ] public_deps = [ ":ability_connect_callback_stub" ] diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index c9658b81753f9371a938e6f71a55f0b8f1ebf6d0..cc682af75ac33bbc951ec4ca68ee36dfcf348a96 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021-2023 Huawei Device Co., Ltd. +# Copyright (c) 2021-2025 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 @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") @@ -40,7 +41,116 @@ config("appmgr_core_config") { } } +idl_gen_interface("appmgr_innerkits") { + sources = [ + "idl/IAppStateCallback.idl", + ] + sources_common = [ + "IAppMgrConstants.idl", + ] + log_domainid = "0xD001311" + log_tag = "AppMgr" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +config("appmgr_innerkits_config") { + include_dirs = [ "${target_gen_dir}" ] +} + +ohos_source_set("appmgr_innerkits_include") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + + public_configs = [ + ":appmgr_innerkits_config", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_innerkits_config", + "${ability_runtime_path}/utils/server/startup:startup_util_config", + ] + + deps = [ + ":appmgr_innerkits", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_innerkits", + "${ability_runtime_path}/utils/server/startup:startup_util", + ] + external_deps = [ + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "samgr:samgr_proxy", + "ability_base:configuration", + ] + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_source_set("appmgr_innerkits_source") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + cfi_vcall_icall_only = true + debug = false + } + configs = [ + ":appmgr_core_config", + ":appmgr_sdk_config", + ] + + public_configs = [ + ":appmgr_innerkits_config", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_innerkits_config", + "${ability_runtime_path}/utils/server/startup:startup_util_config", + ] + + output_values = get_target_outputs(":appmgr_innerkits") + sources = filter_include(output_values, [ "*.cpp" ]) + + deps = [ + ":appmgr_innerkits", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_innerkits", + "${ability_runtime_path}/utils/server/startup:startup_util", + ] + external_deps = [ + "c_utils:utils", + "faultloggerd:libfaultloggerd", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "samgr:samgr_proxy", + "ability_base:configuration", + "ability_base:session_info", + "ability_base:want", + "bundle_framework:appexecfwk_base", + ] + + subsystem_name = "ability" + part_name = "ability_runtime" +} + ohos_shared_library("app_manager") { + 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 = [ @@ -85,8 +195,6 @@ ohos_shared_library("app_manager") { "src/appmgr/app_scheduler_host.cpp", "src/appmgr/app_scheduler_proxy.cpp", "src/appmgr/app_service_manager.cpp", - "src/appmgr/app_state_callback_host.cpp", - "src/appmgr/app_state_callback_proxy.cpp", "src/appmgr/app_state_data.cpp", "src/appmgr/application_state_observer_proxy.cpp", "src/appmgr/application_state_observer_stub.cpp", @@ -128,7 +236,10 @@ ohos_shared_library("app_manager") { public_configs = [ ":appmgr_core_config", + ":appmgr_innerkits_config", ":appmgr_sdk_config", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_innerkits_config", + "${ability_runtime_path}/utils/server/startup:startup_util_config", ] defines = [ "AMS_LOG_TAG = \"AppexecfwkCore\"" ] @@ -138,6 +249,7 @@ ohos_shared_library("app_manager") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ + ":appmgr_innerkits_source", "${ability_runtime_path}/utils/global/freeze:freeze_util", "${ability_runtime_path}/utils/server/startup:startup_util", "${ability_runtime_services_path}/common:app_util", diff --git a/interfaces/inner_api/app_manager/idl/IAppMgrConstants.idl b/interfaces/inner_api/app_manager/idl/IAppMgrConstants.idl new file mode 100644 index 0000000000000000000000000000000000000000..6d1013bcfa56dbc986db7a3384c75d44bebe7d8b --- /dev/null +++ b/interfaces/inner_api/app_manager/idl/IAppMgrConstants.idl @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 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. + */ + +package OHOS.AppExecFwk; + + enum AbilityState { + ABILITY_STATE_CREATE = 0, + ABILITY_STATE_READY, + ABILITY_STATE_FOREGROUND, + ABILITY_STATE_FOCUS, + ABILITY_STATE_BACKGROUND, + ABILITY_STATE_TERMINATED, + ABILITY_STATE_END, + ABILITY_STATE_CONNECTED, + ABILITY_STATE_DISCONNECTED, +}; diff --git a/interfaces/inner_api/app_manager/idl/IAppStateCallback.idl b/interfaces/inner_api/app_manager/idl/IAppStateCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..fff348fc806d71dcdd1686dddb07125a33706898 --- /dev/null +++ b/interfaces/inner_api/app_manager/idl/IAppStateCallback.idl @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2025 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. + */ + +sequenceable OHOS.IRemoteObject; +sequenceable app_process_data..OHOS.AppExecFwk.AppProcessData; +sequenceable OHOS.AppExecFwk.Configuration; +sequenceable bundle_info..OHOS.AppExecFwk.BundleInfo; +sequenceable running_process_info..OHOS.AppExecFwk.RunningProcessInfo; + +import IAppMgrConstants; + +interface OHOS.AppExecFwk.IAppStateCallback { + [oneway] void OnAppStateChanged([in] AppProcessData appProcessData); + [oneway] void OnAbilityRequestDone([in] IRemoteObject token, [in] AbilityState state); + [oneway] void NotifyConfigurationChange([in] Configuration config, [in] int userId); + [oneway] void NotifyStartResidentProcess([in] List bundleInfos); + [oneway] void NotifyStartKeepAliveProcess([in] List bundleInfos); + [oneway] void OnAppRemoteDied([in] List abilityTokens); + [oneway] void OnStartProcessFailed([in] IRemoteObject token); + [oneway] void NotifyAppPreCache([in] int pid, [in] int userId); + [oneway] void OnCacheExitInfo([in] unsigned int accessTokenId, [in] RunningProcessInfo exitInfo, + [in] String bundleName, [in] List abilityNames, [in] List uiExtensionNames); +} \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h index ec040e460b4390f02c9f8578f7997da7e42517bd..27f8a73e5fde0b5312ebfb097600bf6866eaf6dc 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h +++ b/interfaces/inner_api/app_manager/include/appmgr/app_mgr_constants.h @@ -16,6 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_APP_MGR_CONSTANTS_H #define OHOS_ABILITY_RUNTIME_APP_MGR_CONSTANTS_H +#include "iapp_mgr_constants.h" namespace OHOS { namespace AppExecFwk { namespace Constants { @@ -52,18 +53,6 @@ enum class ApplicationScheduleState { SCHEDULE_BACKGROUNDING, }; -enum class AbilityState { - ABILITY_STATE_CREATE = 0, - ABILITY_STATE_READY, - ABILITY_STATE_FOREGROUND, - ABILITY_STATE_FOCUS, - ABILITY_STATE_BACKGROUND, - ABILITY_STATE_TERMINATED, - ABILITY_STATE_END, - ABILITY_STATE_CONNECTED, - ABILITY_STATE_DISCONNECTED, -}; - enum class ExtensionState { EXTENSION_STATE_CREATE = 0, EXTENSION_STATE_READY, diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index b0fd3beeac876bf5434115ebc2555215b245e4e8..bf8072ee672aa9975e1f7ba0ed092950f4bd1311 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -65,6 +65,11 @@ config("abilityms_config") { "${ability_runtime_utils_path}/server/constant", ] + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_innerkits_config", + "${ability_runtime_innerkits_path}/app_manager:appmgr_innerkits_config", + ] + defines = [] if (ability_command_for_test) { diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index b2de5a3951123671c45bf65a83bfed95c0db35da..f956a62ef3c48197921767c2ac4ec7ad5dbb9a9f 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -25,7 +25,7 @@ #include "app_debug_listener_interface.h" #include "application_info.h" #include "appmgr/app_mgr_client.h" -#include "appmgr/app_state_callback_host.h" +#include "app_state_callback_stub.h" #include "appmgr/start_specified_ability_response_stub.h" #include "bundle_info.h" #include "fault_data.h" @@ -141,7 +141,7 @@ public: * @class AppScheduler * AppScheduler , access app manager service. */ -class AppScheduler : virtual RefBase, public AppExecFwk::AppStateCallbackHost { +class AppScheduler : virtual RefBase, public AppExecFwk::AppStateCallbackStub { DECLARE_DELAYED_SINGLETON(AppScheduler) public: /** @@ -616,48 +616,49 @@ protected: * @param token,ability's token. * @param state,the state of ability lift cycle. */ - virtual void OnAbilityRequestDone(const sptr &token, const AppExecFwk::AbilityState state) override; + virtual ErrCode OnAbilityRequestDone(const sptr &token, + const AppExecFwk::AbilityState state) override; /** * Application state changed callback. * * @param appProcessData Process data */ - virtual void OnAppStateChanged(const AppExecFwk::AppProcessData &appData) override; + virtual ErrCode OnAppStateChanged(const AppExecFwk::AppProcessData &appData) override; /** * @brief Notify application update system environment changes. * @param config System environment change parameters. * @param userId userId Designation User ID. */ - virtual void NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) override; + virtual ErrCode NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) override; /** * @brief Notify abilityms start resident process. * @param bundleInfos resident process bundle infos. */ - virtual void NotifyStartResidentProcess(std::vector &bundleInfos) override; + virtual ErrCode NotifyStartResidentProcess(const std::vector &bundleInfos) override; /** * @brief Notify abilityms start keep-alive process. * @param bundleInfos resident process bundle infos. */ - virtual void NotifyStartKeepAliveProcess(std::vector &bundleInfos) override; + virtual ErrCode NotifyStartKeepAliveProcess(const std::vector &bundleInfos) override; /** * @brief Notify abilityms app process OnRemoteDied * @param abilityTokens abilities in died process. */ - virtual void OnAppRemoteDied(const std::vector> &abilityTokens) override; + virtual ErrCode OnAppRemoteDied(const std::vector> &abilityTokens) override; - virtual void OnStartProcessFailed(sptr token) override; + virtual ErrCode OnStartProcessFailed(const sptr &token) override; /** * @brief Notify abilityms app process pre cache * @param pid process pid. * @param userId userId Designation User ID. */ - virtual void NotifyAppPreCache(int32_t pid, int32_t userId) override; + virtual ErrCode NotifyAppPreCache(int32_t pid, int32_t userId) override; /** * @brief Notify abilityms exit info @@ -667,7 +668,7 @@ protected: * @param abilityNames abilityNames in app. * @param uiExtensionNames uiExtensionNames in app. */ - virtual void OnCacheExitInfo(uint32_t accessTokenId, const AppExecFwk::RunningProcessInfo &exitInfo, + virtual ErrCode OnCacheExitInfo(uint32_t accessTokenId, const AppExecFwk::RunningProcessInfo &exitInfo, const std::string &bundleName, const std::vector &abilityNames, const std::vector &uiExtensionNames) override; diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index d6385c53b441b67a4d3d654c749e136024d108af..d3daa6149e35f9695e220cf4fa169ab3d09c2ca3 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -199,65 +199,73 @@ AppAbilityState AppScheduler::GetAbilityState() const return appAbilityState_; } -void AppScheduler::OnAbilityRequestDone(const sptr &token, const AppExecFwk::AbilityState state) +ErrCode AppScheduler::OnAbilityRequestDone(const sptr &token, const AppExecFwk::AbilityState state) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); TAG_LOGD(AAFwkTag::ABILITYMGR, "state:%{public}d", static_cast(state)); auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); appAbilityState_ = ConvertToAppAbilityState(static_cast(state)); callback->OnAbilityRequestDone(token, static_cast(state)); + return ERR_OK; } -void AppScheduler::NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) +ErrCode AppScheduler::NotifyConfigurationChange(const AppExecFwk::Configuration &config, int32_t userId) { auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); callback->NotifyConfigurationChange(config, userId); + return ERR_OK; } -void AppScheduler::NotifyStartResidentProcess(std::vector &bundleInfos) +ErrCode AppScheduler::NotifyStartResidentProcess(const std::vector &bundleInfos) { auto callback = callback_.lock(); - CHECK_POINTER(callback); - callback->NotifyStartResidentProcess(bundleInfos); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); + callback->NotifyStartResidentProcess(const_cast&>(bundleInfos)); + return ERR_OK; } -void AppScheduler::NotifyStartKeepAliveProcess(std::vector &bundleInfos) +ErrCode AppScheduler::NotifyStartKeepAliveProcess(const std::vector &bundleInfos) { auto callback = callback_.lock(); - CHECK_POINTER(callback); - callback->NotifyStartKeepAliveProcess(bundleInfos); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); + callback->NotifyStartKeepAliveProcess(const_cast&>(bundleInfos)); + return ERR_OK; } -void AppScheduler::OnAppRemoteDied(const std::vector> &abilityTokens) +ErrCode AppScheduler::OnAppRemoteDied(const std::vector> &abilityTokens) { auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); callback->OnAppRemoteDied(abilityTokens); + return ERR_OK; } -void AppScheduler::OnStartProcessFailed(sptr token) +ErrCode AppScheduler::OnStartProcessFailed(const sptr& token) { auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); callback->OnStartProcessFailed(token); + return ERR_OK; } -void AppScheduler::OnCacheExitInfo(uint32_t accessTokenId, const AppExecFwk::RunningProcessInfo &exitInfo, +ErrCode AppScheduler::OnCacheExitInfo(uint32_t accessTokenId, const AppExecFwk::RunningProcessInfo &exitInfo, const std::string &bundleName, const std::vector &abilityNames, const std::vector &uiExtensionNames) { auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); callback->OnCacheExitInfo(accessTokenId, exitInfo, bundleName, abilityNames, uiExtensionNames); + return ERR_OK; } -void AppScheduler::NotifyAppPreCache(int32_t pid, int32_t userId) +ErrCode AppScheduler::NotifyAppPreCache(int32_t pid, int32_t userId) { auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); callback->NotifyAppPreCache(pid, userId); + return ERR_OK; } int AppScheduler::KillApplication(const std::string &bundleName, bool clearPageStack, int32_t appIndex) @@ -326,11 +334,11 @@ void AppScheduler::PrepareTerminate(const sptr &token, bool clear IN_PROCESS_CALL_WITHOUT_RET(appMgrClient_->PrepareTerminate(token, clearMissionFlag)); } -void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) +ErrCode AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); auto callback = callback_.lock(); - CHECK_POINTER(callback); + CHECK_POINTER_AND_RETURN(callback, INNER_ERR); AppInfo info; for (const auto &list : appData.appDatas) { AppData data; @@ -345,6 +353,7 @@ void AppScheduler::OnAppStateChanged(const AppExecFwk::AppProcessData &appData) info.instanceKey = appData.instanceKey; info.bundleName = appData.bundleName; callback->OnAppStateChanged(info); + return ERR_OK; } void AppScheduler::GetRunningProcessInfoByToken(const sptr &token, AppExecFwk::RunningProcessInfo &info)