diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 3d8d10569d..3881341c36 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -90,6 +90,8 @@ ohos_shared_library("app_manager") { "src/appmgr/configuration_observer_proxy.cpp", "src/appmgr/configuration_observer_stub.cpp", "src/appmgr/fault_data.cpp", + "src/appmgr/kia_interceptor_proxy.cpp", + "src/appmgr/kia_interceptor_stub.cpp", "src/appmgr/memory_level_info.cpp", "src/appmgr/native_child_notify_proxy.cpp", "src/appmgr/native_child_notify_stub.cpp", 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 cbcccf798b..c41eac2d23 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 @@ -28,6 +28,7 @@ #include "child_process_info.h" #include "child_process_request.h" #include "fault_data.h" +#include "kia_interceptor_interface.h" #include "iapp_state_callback.h" #include "iapplication_state_observer.h" #include "iconfiguration_observer.h" @@ -639,6 +640,20 @@ public: */ virtual int32_t UnregisterRenderStateObserver(const sptr &observer) = 0; + /** + * Register KIA interceptor. + * @param interceptor KIA interceptor. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t RegisterKiaInterceptor(const sptr &interceptor) = 0; + + /** + * Check if the given pid is a KIA process. + * @param pid process id. + * @return Returns true if it is a KIA process, false otherwise. + */ + virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) = 0; + /** * Update render state. * @param renderPid Render pid. 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 3a563c6840..b96c5b65be 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 @@ -113,6 +113,8 @@ enum class AppMgrInterfaceCode { GET_SUPPORTED_PROCESS_CACHE_PIDS = 87, GET_ALL_CHILDREN_PROCESSES = 88, SET_SUPPORTED_PROCESS_CACHE = 89, + REGISTER_KIA_INTERCEPTOR = 90, + CHECK_IS_KIA_PROCESS = 91, }; } // 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 3e35437035..30723a40b9 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 @@ -570,6 +570,20 @@ public: */ virtual int32_t UnregisterRenderStateObserver(const sptr &observer) override; + /** + * Register KIA interceptor. + * @param interceptor KIA interceptor. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t RegisterKiaInterceptor(const sptr &interceptor) override; + + /** + * Check if the given pid is a KIA process. + * @param pid process id. + * @return Returns true if it is a KIA process, false otherwise. + */ + virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override; + /** * Update render state. * @param renderPid Render pid. 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 1514c13539..6bdf62d82e 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 @@ -138,6 +138,8 @@ private: int32_t HandleClearUpApplicationDataBySelf(MessageParcel &data, MessageParcel& reply); int32_t HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleRegisterRenderStateObserver(MessageParcel &data, MessageParcel &reply); + int32_t HandleRegisterKiaInterceptor(MessageParcel &data, MessageParcel &reply); + int32_t HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &reply); int32_t HandleUnregisterRenderStateObserver(MessageParcel &data, MessageParcel &reply); int32_t HandleUpdateRenderState(MessageParcel &data, MessageParcel &reply); int32_t HandleSignRestartAppFlag(MessageParcel &data, MessageParcel &reply); diff --git a/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_interface.h b/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_interface.h new file mode 100644 index 0000000000..9e8fb7252c --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_interface.h @@ -0,0 +1,37 @@ +/* + * 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_KIA_INTERCEPTOR_INTERFACE_H +#define OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_INTERFACE_H + +#include + +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +class IKiaInterceptor : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IKiaInterceptor"); + virtual int OnIntercept(AAFwk::Want &want) = 0; + + enum { + KIA_INTERCEPTOR_ON_INTERCEPT = 0, + }; +}; +} // namespace AppExecFwk +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_INTERFACE_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_proxy.h new file mode 100644 index 0000000000..ca579bc05c --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_proxy.h @@ -0,0 +1,41 @@ +/* + * 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_KIA_INTERCEPTOR_PROXY_H +#define OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_PROXY_H + +#include "kia_interceptor_interface.h" + +#include + +namespace OHOS { +namespace AppExecFwk { +class KiaInterceptorProxy : public IRemoteProxy { +public: + explicit KiaInterceptorProxy(const sptr &impl) : IRemoteProxy(impl) + {} + + virtual ~KiaInterceptorProxy() + {} + + virtual int OnIntercept(AAFwk::Want &want) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_PROXY_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_stub.h b/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_stub.h new file mode 100644 index 0000000000..682f511cab --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/kia_interceptor_stub.h @@ -0,0 +1,39 @@ +/* + * 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_KIA_INTERCEPTOR_STUB_H +#define OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_STUB_H + +#include "kia_interceptor_interface.h" + +#include +#include + +namespace OHOS { +namespace AppExecFwk { +class KiaInterceptorStub : public IRemoteStub { +public: + KiaInterceptorStub(); + virtual ~KiaInterceptorStub(); + + virtual int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + int OnInterceptInner(MessageParcel &data, MessageParcel &reply); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_KIA_INTERCEPTOR_STUB_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 78c5d28951..85e4014ad2 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 @@ -1987,5 +1987,53 @@ int32_t AppMgrProxy::GetSupportedProcessCachePids(const std::string &bundleName, } return reply.ReadInt32(); } + +int32_t AppMgrProxy::RegisterKiaInterceptor(const sptr &interceptor) +{ + if (interceptor == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr."); + return ERR_INVALID_VALUE; + } + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return ERR_INVALID_VALUE; + } + + if (!data.WriteRemoteObject(interceptor->AsObject())) { + TAG_LOGE(AAFwkTag::APPMGR, "write interceptor failed."); + return ERR_INVALID_VALUE; + } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::REGISTER_KIA_INTERCEPTOR, data, reply, option); + return reply.ReadInt32(); +} + +int32_t AppMgrProxy::CheckIsKiaProcess(pid_t pid, bool &isKia) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed."); + return ERR_INVALID_VALUE; + } + + if (!data.WriteInt32(pid)) { + TAG_LOGE(AAFwkTag::APPMGR, "write pid failed."); + return ERR_INVALID_VALUE; + } + + PARCEL_UTIL_SENDREQ_RET_INT(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS, data, reply, option); + int32_t ret = reply.ReadInt32(); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "failed,ret=%{public}d.", ret); + return ret; + } + isKia = reply.ReadBool(); + return ERR_OK; +} } // 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 2cb27b80e5..0e9689bbad 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 @@ -353,6 +353,10 @@ int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &da return HandleGetSupportedProcessCachePids(data, reply); case static_cast(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES): return HandleGetAllChildrenProcesses(data, reply); + case static_cast(AppMgrInterfaceCode::REGISTER_KIA_INTERCEPTOR): + return HandleRegisterKiaInterceptor(data, reply); + case static_cast(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS): + return HandleCheckIsKiaProcess(data, reply); } return INVALID_FD; } @@ -1642,5 +1646,33 @@ int32_t AppMgrStub::GetSupportedProcessCachePids(const std::string &bundleName, { return NO_ERROR; } + +int32_t AppMgrStub::HandleRegisterKiaInterceptor(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + sptr interceptor = iface_cast(data.ReadRemoteObject()); + if (interceptor == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr."); + return ERR_INVALID_VALUE; + } + + reply.WriteInt32(RegisterKiaInterceptor(interceptor)); + return NO_ERROR; +} + +int32_t AppMgrStub::HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &reply) +{ + TAG_LOGD(AAFwkTag::APPMGR, "call"); + int pid = data.ReadInt32(); + bool isKia = false; + int result = CheckIsKiaProcess(pid, isKia); + reply.WriteInt32(result); + if (result != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "failed,result=%{public}d.", result); + return result; + } + reply.WriteBool(isKia); + return NO_ERROR; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/kia_interceptor_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/kia_interceptor_proxy.cpp new file mode 100644 index 0000000000..685b0f3791 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/kia_interceptor_proxy.cpp @@ -0,0 +1,65 @@ +/* + * 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 "kia_interceptor_proxy.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +bool KiaInterceptorProxy::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(KiaInterceptorProxy::GetDescriptor())) { + TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed"); + return false; + } + return true; +} + +int KiaInterceptorProxy::OnIntercept(AAFwk::Want &want) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return ERR_INVALID_VALUE; + } + data.WriteParcelable(&want); + sptr remote = Remote(); + if (remote == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL"); + return ERR_INVALID_VALUE; + } + int32_t ret = remote->SendRequest(static_cast(IKiaInterceptor::KIA_INTERCEPTOR_ON_INTERCEPT), + data, reply, option); + if (ret != NO_ERROR) { + TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d.", ret); + return ret; + } + int resultCode = reply.ReadInt32(); + if (resultCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "OnIntercept failed, resultCode=%{public}d.", resultCode); + return resultCode; + } + sptr resultWant = reply.ReadParcelable(); + if (resultWant == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "resultWant is nullptr."); + return ERR_INVALID_VALUE; + } + want = *resultWant; + return resultCode; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/interfaces/inner_api/app_manager/src/appmgr/kia_interceptor_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/kia_interceptor_stub.cpp new file mode 100644 index 0000000000..96eb5f7504 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/kia_interceptor_stub.cpp @@ -0,0 +1,59 @@ +/* + * 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 "kia_interceptor_stub.h" + +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +KiaInterceptorStub::KiaInterceptorStub() {} + +KiaInterceptorStub::~KiaInterceptorStub() {} + +int KiaInterceptorStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + TAG_LOGD(AAFwkTag::APPMGR, "cmd=%d,flags=%d", code, option.GetFlags()); + std::u16string descriptor = KiaInterceptorStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + TAG_LOGI(AAFwkTag::APPMGR, "local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + if (code == KIA_INTERCEPTOR_ON_INTERCEPT) { + return OnInterceptInner(data, reply); + } + TAG_LOGW(AAFwkTag::APPMGR, "KiaInterceptorStub::OnRemoteRequest, default case, need check."); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int KiaInterceptorStub::OnInterceptInner(MessageParcel &data, MessageParcel &reply) +{ + sptr want = data.ReadParcelable(); + int resultCode = OnIntercept(*want); + if (!reply.WriteInt32(resultCode)) { + TAG_LOGE(AAFwkTag::APPMGR, "write resultCode failed."); + return ERR_INVALID_VALUE; + } + if (!reply.WriteParcelable(want)) { + TAG_LOGE(AAFwkTag::APPMGR, "write want failed."); + return ERR_INVALID_VALUE; + } + + return NO_ERROR; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 9dd4dcee36..f659659ee5 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -83,7 +83,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"; +constexpr const char* KEY_SESSION_ID = "com.ohos.param.sessionId"; using OHOS::AppExecFwk::IAbilityController; class PendingWantManager; struct StartAbilityInfo; diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index cccece1d4b..89ad3618f2 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -77,6 +77,7 @@ ohos_shared_library("libappms") { defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ] defines += [ "AMS_LOG_DOMAIN = 0xD001303" ] defines += [ "OHOS_ACCOUNT_ENABLED" ] + defines += [ "INCLUDE_ZURI" ] if (product_name != "ohcore") { defines += [ "APP_MGR_SERVICE_APPMS" ] @@ -114,6 +115,7 @@ ohos_shared_library("libappms") { "ability_base:base", "ability_base:configuration", "ability_base:want", + "ability_base:zuri", "access_token:libaccesstoken_sdk", "appspawn:appspawn_client", "bundle_framework:appexecfwk_base", diff --git a/services/appmgr/include/app_mgr_service.h b/services/appmgr/include/app_mgr_service.h index 07fb020737..bf2b7554b9 100644 --- a/services/appmgr/include/app_mgr_service.h +++ b/services/appmgr/include/app_mgr_service.h @@ -347,6 +347,20 @@ public: virtual int32_t UnregisterConfigurationObserver(const sptr &observer) override; + /** + * Register KIA interceptor. + * @param interceptor KIA interceptor. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int32_t RegisterKiaInterceptor(const sptr &interceptor) override; + + /** + * Check if the given pid is a KIA process. + * @param pid process id. + * @return Returns true if it is a KIA process, false otherwise. + */ + virtual int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override; + bool GetAppRunningStateByBundleName(const std::string &bundleName) override; int32_t NotifyLoadRepairPatch(const std::string &bundleName, const sptr &callback) override; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 4df7070c07..40fb9bc742 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -58,6 +58,7 @@ #include "iremote_object.h" #include "irender_state_observer.h" #include "istart_specified_ability_response.h" +#include "kia_interceptor_interface.h" #include "record_query_result.h" #include "refbase.h" #include "remote_client_manager.h" @@ -472,7 +473,8 @@ public: const BundleInfo &bundleInfo, const HapModuleInfo &hapModuleInfo, std::shared_ptr want, - int32_t abilityRecordId); + int32_t abilityRecordId, + bool isKia = false); /** * OnStop, Application management service stopped. @@ -1195,6 +1197,10 @@ public: */ virtual int32_t GetSupportedProcessCachePids(const std::string &bundleName, std::vector &pidList); + int32_t RegisterKiaInterceptor(const sptr &interceptor); + + int32_t CheckIsKiaProcess(pid_t pid, bool &isKia); + private: int32_t ForceKillApplicationInner(const std::string &bundleName, const int userId = -1, const int appIndex = 0); @@ -1556,6 +1562,10 @@ private: const HapModuleInfo &hapModuleInfo, std::string &processName) const; void DealMultiUserConfig(const Configuration &config, const int32_t userId); bool CheckIsDebugApp(const std::string &bundleName); + void MakeKiaProcess(std::shared_ptr want, bool &isKia, std::string &watermarkBusinessName, + bool &isWatermarkEnabled, bool &isFileUri, std::string &processName); + void ProcessKia(bool isKia, std::shared_ptr appRecord, + const std::string& watermarkBusinessName, bool isWatermarkEnabled); const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask"; std::vector appStateCallbacks_; std::shared_ptr remoteClientManager_; @@ -1602,7 +1612,7 @@ private: std::mutex loadTaskListMutex_; std::vector loadAbilityTaskFuncList_; - + sptr kiaInterceptor_; std::shared_ptr multiUserConfigurationMgr_; }; } // namespace AppExecFwk diff --git a/services/appmgr/include/app_running_manager.h b/services/appmgr/include/app_running_manager.h index d810d1576a..218246eed8 100644 --- a/services/appmgr/include/app_running_manager.h +++ b/services/appmgr/include/app_running_manager.h @@ -350,7 +350,9 @@ public: void SetMultiUserConfigurationMgr(const std::shared_ptr& multiUserConfigurationMgr); - private: + int32_t CheckIsKiaProcess(pid_t pid, bool &isKia); + +private: std::shared_ptr GetAbilityRunningRecord(const int64_t eventId); int32_t AssignRunningProcessInfoByAppRecord( std::shared_ptr appRecord, AppExecFwk::RunningProcessInfo &info) const; diff --git a/services/appmgr/include/app_running_record.h b/services/appmgr/include/app_running_record.h index 59bab93b2c..3f2bf94d65 100644 --- a/services/appmgr/include/app_running_record.h +++ b/services/appmgr/include/app_running_record.h @@ -850,6 +850,16 @@ public: void SetUIAbilityLaunched(bool hasLaunched); bool HasUIAbilityLaunched(); + inline void SetIsKia(bool isKia) + { + isKia_ = isKia; + } + + inline bool GetIsKia() const + { + return isKia_; + } + private: /** * SearchTheModuleInfoNeedToUpdated, Get an uninitialized abilityStage data. @@ -1005,6 +1015,7 @@ private: bool isDependedOnArkWeb_ = false; bool isUserRequestCleaning_ = false; bool hasUIAbilityLaunched_ = false; + bool isKia_ = false; }; } // namespace AppExecFwk diff --git a/services/appmgr/src/app_mgr_service.cpp b/services/appmgr/src/app_mgr_service.cpp index a6786a7d05..400305fb0c 100644 --- a/services/appmgr/src/app_mgr_service.cpp +++ b/services/appmgr/src/app_mgr_service.cpp @@ -1622,5 +1622,25 @@ int32_t AppMgrService::GetSupportedProcessCachePids(const std::string &bundleNam } return appMgrServiceInner_->GetSupportedProcessCachePids(bundleName, pidList); } + +int32_t AppMgrService::RegisterKiaInterceptor(const sptr &interceptor) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called"); + if (!appMgrServiceInner_) { + TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr"); + return ERR_INVALID_VALUE; + } + return appMgrServiceInner_->RegisterKiaInterceptor(interceptor); +} + +int32_t AppMgrService::CheckIsKiaProcess(pid_t pid, bool &isKia) +{ + TAG_LOGD(AAFwkTag::APPMGR, "Called"); + if (!appMgrServiceInner_) { + TAG_LOGE(AAFwkTag::APPMGR, "appMgrServiceInner_ is nullptr"); + return ERR_INVALID_VALUE; + } + return appMgrServiceInner_->CheckIsKiaProcess(pid, isKia); +} } // 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 db554563ec..fc96498c39 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -236,6 +236,9 @@ constexpr const char* ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId"; constexpr const char* PROCESS_EXIT_EVENT_TASK = "Send Process Exit Event Task"; constexpr const char* KILL_PROCESS_REASON_PREFIX = "Kill Reason:"; constexpr const char* PRELOAD_APPLIATION_TASK = "PreloadApplicactionTask"; +constexpr int32_t FILE_GUARD_UID = 6266; +constexpr const char* KEY_WATERMARK_BUSINESS_NAME = "com.ohos.param.watermarkBusinessName"; +constexpr const char* KEY_IS_WATERMARK_ENABLED = "com.ohos.param.isWatermarkEnabled"; constexpr const char* PROC_SELF_TASK_PATH = "/proc/self/task/"; @@ -481,6 +484,61 @@ void AppMgrServiceInner::HandlePreloadApplication(const PreloadRequest &request) } } +void AppMgrServiceInner::MakeKiaProcess(std::shared_ptr want, bool &isKia, + std::string &watermarkBusinessName, bool &isWatermarkEnabled, + bool &isFileUri, std::string &processName) +{ + if (want == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr"); + return; + } +#ifdef INCLUDE_ZURI + isFileUri = !want->GetUriString().empty() && want->GetUri().GetScheme() == "file"; +#endif + if (isFileUri && kiaInterceptor_ != nullptr) { + auto resultCode = kiaInterceptor_->OnIntercept(*want); + watermarkBusinessName = want->GetStringParam(KEY_WATERMARK_BUSINESS_NAME); + isWatermarkEnabled = want->GetBoolParam(KEY_IS_WATERMARK_ENABLED, false); + TAG_LOGI(AAFwkTag::APPMGR, "After calling kiaInterceptor_->OnIntercept," + "resultCode=%{public}d,watermarkBusinessName=%{private}s,isWatermarkEnabled=%{private}d", + resultCode, watermarkBusinessName.c_str(), + static_cast(isWatermarkEnabled)); + isKia = (resultCode == ERR_OK && !watermarkBusinessName.empty() && isWatermarkEnabled); + if (isKia) { + processName += "_KIA"; + } + } +} + +void AppMgrServiceInner::ProcessKia(bool isKia, std::shared_ptr appRecord, + const std::string& watermarkBusinessName, bool isWatermarkEnabled) +{ + if (appRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appRecord is nullptr"); + return; + } + if (!isKia) { + return; + } +#ifdef SUPPORT_SCREEN + TAG_LOGI(AAFwkTag::APPMGR, "Openning KIA file, start setting watermark"); + int32_t resultCode = static_cast(WindowManager::GetInstance().SetProcessWatermark( + appRecord->GetPriorityObject()->GetPid(), watermarkBusinessName, isWatermarkEnabled)); + if (resultCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "setting watermark fails with result code:%{public}d", resultCode); + return; + } + TAG_LOGI(AAFwkTag::APPMGR, "setting watermark succeeds, start setting snapshot skip"); + resultCode = static_cast(WindowManager::GetInstance().SkipSnapshotForAppProcess( + appRecord->GetPriorityObject()->GetPid(), isWatermarkEnabled)); + if (resultCode != ERR_OK) { + TAG_LOGE(AAFwkTag::APPMGR, "setting snapshot skip fails with result code:%{public}d", resultCode); + return; + } + TAG_LOGI(AAFwkTag::APPMGR, "setting snapshot skip succeeds"); +#endif // SUPPORT_SCREEN +} + void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, std::shared_ptr appInfo, std::shared_ptr want, std::shared_ptr loadParam) { @@ -527,6 +585,12 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s MakeProcessName(abilityInfo, appInfo, hapModuleInfo, appIndex, specifiedProcessFlag, processName); TAG_LOGI(AAFwkTag::APPMGR, "%{public}s name:%{public}s-%{public}s processName = %{public}s", __func__, abilityInfo->bundleName.c_str(), abilityInfo->name.c_str(), processName.c_str()); + + bool isKia = false; + std::string watermarkBusinessName; + bool isWatermarkEnabled = false; + bool isFileUri = false; + MakeKiaProcess(want, isKia, watermarkBusinessName, isWatermarkEnabled, isFileUri, processName); std::shared_ptr appRecord; bool isProcCache = false; @@ -545,9 +609,10 @@ void AppMgrServiceInner::LoadAbility(std::shared_ptr abilityInfo, s bundleInfo.name, appInfo->uid, AbilityRuntime::RunningStatus::APP_RUNNING_START); } appRecord = CreateAppRunningRecord(loadParam->token, loadParam->preToken, appInfo, abilityInfo, - processName, bundleInfo, hapModuleInfo, want, loadParam->abilityRecordId); + processName, bundleInfo, hapModuleInfo, want, loadParam->abilityRecordId, isKia); LoadAbilityNoAppRecord(appRecord, loadParam->isShellCall, appInfo, abilityInfo, processName, specifiedProcessFlag, bundleInfo, hapModuleInfo, want, appExistFlag, false, loadParam->token); + ProcessKia(isKia, appRecord, watermarkBusinessName, isWatermarkEnabled); } else { TAG_LOGI(AAFwkTag::APPMGR, "have apprecord"); if (!isProcCache) { @@ -2155,7 +2220,7 @@ std::shared_ptr AppMgrServiceInner::GetAppRunningRecordByPid(c std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(sptr token, sptr preToken, std::shared_ptr appInfo, std::shared_ptr abilityInfo, const std::string &processName, const BundleInfo &bundleInfo, - const HapModuleInfo &hapModuleInfo, std::shared_ptr want, int32_t abilityRecordId) + const HapModuleInfo &hapModuleInfo, std::shared_ptr want, int32_t abilityRecordId, bool isKia) { HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); if (want != nullptr && (want->GetBoolParam(DEBUG_APP, false) || want->GetBoolParam(NATIVE_DEBUG, false))) { @@ -2180,6 +2245,7 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(spt appRecord->SetTaskHandler(taskHandler_); appRecord->SetEventHandler(eventHandler_); appRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, want, abilityRecordId); + appRecord->SetIsKia(isKia); if (want) { appRecord->SetDebugApp(want->GetBoolParam(DEBUG_APP, false)); appRecord->SetNativeDebug(want->GetBoolParam("nativeDebug", false)); @@ -7842,5 +7908,34 @@ int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bund } return ERR_OK; } + +int AppMgrServiceInner::RegisterKiaInterceptor(const sptr &interceptor) +{ + TAG_LOGI(AAFwkTag::APPMGR, "call"); + if (IPCSkeleton::GetCallingUid() != FILE_GUARD_UID) { + TAG_LOGE(AAFwkTag::APPMGR, "only open to file guard."); + return ERR_PERMISSION_DENIED; + } + if (interceptor == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr."); + return ERR_INVALID_VALUE; + } + kiaInterceptor_ = interceptor; + return ERR_OK; +} + +int32_t AppMgrServiceInner::CheckIsKiaProcess(pid_t pid, bool &isKia) +{ + TAG_LOGI(AAFwkTag::APPMGR, "call"); + if (IPCSkeleton::GetCallingUid() != FILE_GUARD_UID) { + TAG_LOGE(AAFwkTag::APPMGR, "only open to file guard."); + return ERR_PERMISSION_DENIED; + } + if (!appRunningManager_) { + TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is nullptr"); + return ERR_INVALID_VALUE; + } + return appRunningManager_->CheckIsKiaProcess(pid, isKia); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/appmgr/src/app_running_manager.cpp b/services/appmgr/src/app_running_manager.cpp index 191cf47719..069c006c35 100644 --- a/services/appmgr/src/app_running_manager.cpp +++ b/services/appmgr/src/app_running_manager.cpp @@ -1658,5 +1658,16 @@ void AppRunningManager::SetMultiUserConfigurationMgr( { multiUserConfigurationMgr_ = multiUserConfigurationMgr; } + +int32_t AppRunningManager::CheckIsKiaProcess(pid_t pid, bool &isKia) +{ + auto appRunningRecord = GetAppRunningRecordByPid(pid); + if (appRunningRecord == nullptr) { + TAG_LOGE(AAFwkTag::APPMGR, "appRunningRecord is nullptr"); + return ERR_INVALID_VALUE; + } + isKia = appRunningRecord->GetIsKia(); + return ERR_OK; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h index abfbea82f0..00fe29b877 100644 --- a/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h +++ b/test/mock/frameworks_kits_appkit_test/include/mock_app_mgr_service.h @@ -88,6 +88,8 @@ public: const sptr &callback)); MOCK_METHOD2(GetSupportedProcessCachePids, int32_t(const std::string &bundleName, std::vector &pidList)); + MOCK_METHOD1(RegisterKiaInterceptor, int32_t(const sptr &interceptor)); + MOCK_METHOD2(CheckIsKiaProcess, int32_t(pid_t pid, bool &isKia)); void AttachApplication(const sptr& app) { 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 8030c70bd5..99ddb9e92f 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 @@ -112,6 +112,8 @@ public: MOCK_METHOD2(GetSupportedProcessCachePids, int32_t(const std::string &bundleName, std::vector &pidList)); + MOCK_METHOD1(RegisterKiaInterceptor, int32_t(const sptr &interceptor)); + MOCK_METHOD2(CheckIsKiaProcess, int32_t(pid_t pid, bool &isKia)); virtual int StartUserTestProcess( const AAFwk::Want &want, const sptr &observer, const BundleInfo &bundleInfo, int32_t userId) { diff --git a/test/unittest/appkit/main_thread_test/main_thread_test.cpp b/test/unittest/appkit/main_thread_test/main_thread_test.cpp index fe8c3918c6..0fe86c7ca0 100644 --- a/test/unittest/appkit/main_thread_test/main_thread_test.cpp +++ b/test/unittest/appkit/main_thread_test/main_thread_test.cpp @@ -257,6 +257,16 @@ class MockAppMgrStub : public AppMgrStub { { return true; } + + int32_t RegisterKiaInterceptor(const sptr &interceptor) override + { + return 0; + } + + int32_t CheckIsKiaProcess(pid_t pid, bool &isKia) override + { + return 0; + } }; /*