diff --git a/frameworks/native/child_process/include/native_child_callback.h b/frameworks/native/child_process/include/native_child_callback.h index 128ef026e504fe182fefc6121ab626abb5fc4a27..c13e68d8d0205190658b4919bd20733fec83359e 100644 --- a/frameworks/native/child_process/include/native_child_callback.h +++ b/frameworks/native/child_process/include/native_child_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -29,9 +29,9 @@ public: explicit NativeChildCallback(OH_Ability_OnNativeChildProcessStarted cb); ~NativeChildCallback() = default; - void OnNativeChildStarted(const sptr &nativeChild) override; - void OnError(int32_t errCode) override; - int32_t OnNativeChildExit(int32_t pid, int32_t signal) override; + ErrCode OnNativeChildStarted(const sptr &nativeChild) override; + ErrCode OnError(int32_t errCode) override; + ErrCode OnNativeChildExit(int32_t pid, int32_t signal) override; bool IsCallbacksEmpty(); void AddExitCallback(OH_Ability_OnNativeChildProcessExit callback); diff --git a/frameworks/native/child_process/src/native_child_callback.cpp b/frameworks/native/child_process/src/native_child_callback.cpp index 86e451643422f67d45353c6f571e3d5dc2d6d5fc..95a743ba6be1adde7ebeb3837752567ef67c98dc 100644 --- a/frameworks/native/child_process/src/native_child_callback.cpp +++ b/frameworks/native/child_process/src/native_child_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -26,16 +26,16 @@ NativeChildCallback::NativeChildCallback(OH_Ability_OnNativeChildProcessStarted { } -void NativeChildCallback::OnNativeChildStarted(const sptr &nativeChild) +ErrCode NativeChildCallback::OnNativeChildStarted(const sptr &nativeChild) { if (callback_ == nullptr) { TAG_LOGE(AAFwkTag::PROCESSMGR, "null callback_"); - return; + return ERR_INVALID_VALUE; } if (!nativeChild) { TAG_LOGE(AAFwkTag::PROCESSMGR, "null nativeChild"); - return; + return ERR_INVALID_VALUE; } TAG_LOGI(AAFwkTag::PROCESSMGR, "Native child process started"); @@ -44,20 +44,21 @@ void NativeChildCallback::OnNativeChildStarted(const sptr &native if (ipcProxy == nullptr) { TAG_LOGE(AAFwkTag::PROCESSMGR, "null ipcProxy"); callback_(NCP_ERR_INTERNAL, nullptr); - return; + return ERR_INVALID_VALUE; } callback_(static_cast(ChildProcessManagerErrorCode::ERR_OK), ipcProxy); callback_ = nullptr; ChildCallbackManager::GetInstance().RemoveRemoteObject(this); + return ERR_OK; } -void NativeChildCallback::OnError(int32_t errCode) +ErrCode NativeChildCallback::OnError(int32_t errCode) { if (callback_ == nullptr) { TAG_LOGE(AAFwkTag::PROCESSMGR, "null callback_"); - return; + return ERR_INVALID_VALUE; } TAG_LOGI(AAFwkTag::PROCESSMGR, "Native child process start err %{public}d", errCode); @@ -65,9 +66,10 @@ void NativeChildCallback::OnError(int32_t errCode) callback_ = nullptr; ChildCallbackManager::GetInstance().RemoveRemoteObject(this); + return ERR_OK; } -int32_t NativeChildCallback::OnNativeChildExit(int32_t pid, int32_t signal) +ErrCode NativeChildCallback::OnNativeChildExit(int32_t pid, int32_t signal) { auto exitCallbacks = GetExitCallbacks(); for (const auto &exitCallback : exitCallbacks) { diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 59318b86d696ecc230586dab81c63f9db0e2327e..25215c2930dfd893e749d599777da0a989246fc3 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -45,6 +45,7 @@ idl_gen_interface("appmgr_innerkits") { sources = [ "idl/IAbilityDebugResponse.idl", "idl/IAppDebugListener.idl", + "idl/INativeChildNotify.idl", "idl/IStartSpecifiedAbilityResponse.idl", ] log_domainid = "0xD001311" @@ -206,8 +207,6 @@ ohos_shared_library("app_manager") { "src/appmgr/kia_interceptor_stub.cpp", "src/appmgr/killed_process_info.cpp", "src/appmgr/memory_level_info.cpp", - "src/appmgr/native_child_notify_proxy.cpp", - "src/appmgr/native_child_notify_stub.cpp", "src/appmgr/page_state_data.cpp", "src/appmgr/priority_object.cpp", "src/appmgr/process_data.cpp", diff --git a/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_stub.h b/interfaces/inner_api/app_manager/idl/INativeChildNotify.idl similarity index 38% rename from interfaces/inner_api/app_manager/include/appmgr/native_child_notify_stub.h rename to interfaces/inner_api/app_manager/idl/INativeChildNotify.idl index e81ad08281f066a910bf1bc832f0ffa896bcc370..496990474684d54a8a27c2edd25527e2b718f109 100644 --- a/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_stub.h +++ b/interfaces/inner_api/app_manager/idl/INativeChildNotify.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -13,30 +13,10 @@ * limitations under the License. */ -#ifndef OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_STUB_H -#define OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_STUB_H +sequenceable OHOS.IRemoteObject; -#include "native_child_notify_interface.h" -#include "iremote_stub.h" - -namespace OHOS { -namespace AppExecFwk { - -class NativeChildNotifyStub : public IRemoteStub { -public: - NativeChildNotifyStub() = default; - virtual ~NativeChildNotifyStub() = default; - - int OnRemoteRequest( - uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t HandleOnNativeChildStarted(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnError(MessageParcel &data, MessageParcel &reply); - int32_t HandleOnNativeChildExit(MessageParcel &data, MessageParcel &reply); -}; - -} // OHOS -} // AppExecFwk - -#endif // OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_STUB_H \ No newline at end of file +interface OHOS.AppExecFwk.INativeChildNotify { + [oneway] void OnNativeChildStarted([in] IRemoteObject nativeChild); + [oneway] void OnError([in] int errorCode); + [oneway] void OnNativeChildExit([in] int pid, [in] int signal); +}; \ No newline at end of file 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 f0d1dbfabbf912a084e45c7843e572d219179b4a..578504cc9d6d0493c85c353c5d5475a529eab716 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 @@ -36,6 +36,7 @@ #include "iapp_state_callback.h" #include "iapplication_state_observer.h" #include "iconfiguration_observer.h" +#include "inative_child_notify.h" #include "iquick_fix_callback.h" #include "iremote_broker.h" #include "iremote_object.h" @@ -51,7 +52,6 @@ #include "app_jsheap_mem_info.h" #include "app_cjheap_mem_info.h" #include "running_multi_info.h" -#include "native_child_notify_interface.h" namespace OHOS { namespace AppExecFwk { diff --git a/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_interface.h b/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_interface.h deleted file mode 100644 index 3eba849f17f2c7eace96039793fa91017db33727..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_interface.h +++ /dev/null @@ -1,65 +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_NATIVE_CHILD_NOTIFY_INTERFACE_H -#define OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_INTERFACE_H - -#include "iremote_broker.h" - -namespace OHOS { -namespace AppExecFwk { - -class INativeChildNotify : public IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.NativeChildNotify"); - - /** - * Notify native child process started. - * - * @param nativeChild child process ipc object - */ - virtual void OnNativeChildStarted(const sptr &nativeChild) = 0; - - /** - * Notify native child process start failed. - * - * @param errCode failed error code - */ - virtual void OnError(int32_t errCode) = 0; - - /** - * Notify native child process exit. - * - * @param pid child process pid - * @param signal child process exit signal - * @return Returns ERR_OK on success, others on failure. - */ - virtual int32_t OnNativeChildExit(int32_t pid, int32_t signal) = 0; - - enum { - // ipc id for OnNativeChildStarted - IPC_ID_ON_NATIVE_CHILD_STARTED = 0, - - // ipc id for OnError - IPC_ID_ON_ERROR = 1, - - IPC_ID_ON_NATIVE_CHILD_EXIT = 2 - }; -}; - -} // OHOS -} // AppExecFwk - -#endif // OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_INTERFACE_H \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_proxy.h deleted file mode 100644 index d843439fb1e2938a7016f0c5bf2fa25e8b6aef95..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/app_manager/include/appmgr/native_child_notify_proxy.h +++ /dev/null @@ -1,44 +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_NATIVE_CHILD_NOTIFY_PROXY_H -#define OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_PROXY_H - -#include "native_child_notify_interface.h" -#include "iremote_proxy.h" - -namespace OHOS { -namespace AppExecFwk { - -class NativeChildNotifyProxy : public IRemoteProxy { -public: - explicit NativeChildNotifyProxy(const sptr &impl); - virtual ~NativeChildNotifyProxy() = default; - - void OnNativeChildStarted(const sptr &nativeChild) override; - void OnError(int32_t errCode) override; - int32_t OnNativeChildExit(int32_t pid, int32_t signal) override; - -private: - bool WriteInterfaceToken(MessageParcel &data); - int32_t SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption& option); - - static inline BrokerDelegator delegator_; -}; - -} // OHOS -} // AppExecFwk - -#endif // OHOS_ABILITY_RUNTIME_NATIVE_CHILD_NOTIFY_PROXY_H \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/src/appmgr/native_child_notify_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/native_child_notify_proxy.cpp deleted file mode 100644 index 533799eaa6a49e3ad5266d3bd6c4d3261808bc6c..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/native_child_notify_proxy.cpp +++ /dev/null @@ -1,116 +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. - */ - -#include "native_child_notify_proxy.h" -#include "hilog_tag_wrapper.h" -#include "ipc_types.h" - -namespace OHOS { -namespace AppExecFwk { - -NativeChildNotifyProxy::NativeChildNotifyProxy(const sptr &impl) - : IRemoteProxy(impl) -{ -} - -bool NativeChildNotifyProxy::WriteInterfaceToken(MessageParcel &data) -{ - if (!data.WriteInterfaceToken(NativeChildNotifyProxy::GetDescriptor())) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write interface token failed"); - return false; - } - - return true; -} - -int32_t NativeChildNotifyProxy::SendRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption& option) -{ - sptr remote = Remote(); - if (!remote) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy get remote object failed"); - return ERR_NULL_OBJECT; - } - - int32_t ret = remote->SendRequest(code, data, reply, option); - if (ret != NO_ERROR) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy SendRequest failed(%{public}d)", ret); - return ret; - } - - return NO_ERROR; -} - -void NativeChildNotifyProxy::OnNativeChildStarted(const sptr &nativeChild) -{ - TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyProxy OnNativeChildStarted"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - return; - } - - if (!data.WriteRemoteObject(nativeChild)) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write native child ipc object failed."); - return; - } - - SendRequest(INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_STARTED, data, reply, option); -} - -void NativeChildNotifyProxy::OnError(int32_t errCode) -{ - TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyProxy OnError(%{public}d)", errCode); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - return; - } - - if (!data.WriteInt32(errCode)) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write error code failed."); - return; - } - - SendRequest(INativeChildNotify::IPC_ID_ON_ERROR, data, reply, option); -} - -int32_t NativeChildNotifyProxy::OnNativeChildExit(int32_t pid, int32_t signal) -{ - TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyProxy OnNativeChildExit"); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_ASYNC); - if (!WriteInterfaceToken(data)) { - return ERR_NULL_OBJECT; - } - - if (!data.WriteInt32(pid)) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write native child pid failed."); - return ERR_NULL_OBJECT; - } - - if (!data.WriteInt32(signal)) { - TAG_LOGE(AAFwkTag::APPMGR, "NativeChildNotifyProxy write native child signal failed."); - return ERR_NULL_OBJECT; - } - - return SendRequest(INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_EXIT, data, reply, option); -} - -} // OHOS -} // AppExecFwk \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/src/appmgr/native_child_notify_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/native_child_notify_stub.cpp deleted file mode 100644 index 7d1e49251544887d8822facead7fa5e820d8fbd0..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/app_manager/src/appmgr/native_child_notify_stub.cpp +++ /dev/null @@ -1,81 +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. - */ - -#include "native_child_notify_stub.h" -#include "hilog_tag_wrapper.h" -#include "ipc_types.h" - -namespace OHOS { -namespace AppExecFwk { - -int NativeChildNotifyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyStub::OnRemoteRequest, code=%{public}u, flags=%{public}d.", - code, option.GetFlags()); - std::u16string descriptor = NativeChildNotifyStub::GetDescriptor(); - std::u16string remoteDesc = data.ReadInterfaceToken(); - if (descriptor != remoteDesc) { - TAG_LOGE(AAFwkTag::APPMGR, "A local descriptor is not equivalent to a remote"); - return ERR_INVALID_STATE; - } - - int32_t ret; - switch (code) { - case INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_STARTED: - ret = HandleOnNativeChildStarted(data, reply); - break; - - case INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_EXIT: - ret = HandleOnNativeChildExit(data, reply); - break; - - case INativeChildNotify::IPC_ID_ON_ERROR: - ret = HandleOnError(data, reply); - break; - - default: - TAG_LOGW(AAFwkTag::APPMGR, "NativeChildNotifyStub Unknow ipc call(%{public}u)", code); - ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); - break; - } - - TAG_LOGD(AAFwkTag::APPMGR, "NativeChildNotifyStub::OnRemoteRequest end"); - return ret; -} - -int32_t NativeChildNotifyStub::HandleOnNativeChildStarted(MessageParcel &data, MessageParcel &reply) -{ - sptr cb = data.ReadRemoteObject(); - OnNativeChildStarted(cb); - return ERR_NONE; -} - -int32_t NativeChildNotifyStub::HandleOnNativeChildExit(MessageParcel &data, MessageParcel &reply) -{ - int pid = data.ReadInt32(); - int signal = data.ReadInt32(); - return OnNativeChildExit(pid, signal); -} - -int32_t NativeChildNotifyStub::HandleOnError(MessageParcel &data, MessageParcel &reply) -{ - int32_t err = data.ReadInt32(); - OnError(err); - return ERR_NONE; -} - -} // OHOS -} // AppExecFwk diff --git a/interfaces/inner_api/child_process_manager/include/native_child_ipc_process.h b/interfaces/inner_api/child_process_manager/include/native_child_ipc_process.h index 5a007069e87a215803738223958fb1eb2edb77e5..f69b5fb9144b1bf03636891c8d6da1bf8eed749f 100644 --- a/interfaces/inner_api/child_process_manager/include/native_child_ipc_process.h +++ b/interfaces/inner_api/child_process_manager/include/native_child_ipc_process.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -18,7 +18,7 @@ #include #include "child_process.h" -#include "native_child_notify_interface.h" +#include "inative_child_notify.h" #include "ipc_inner_object.h" namespace OHOS { diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 4f4588802e2f10fd120223cd4dad8da384b76e64..33fca399edbb310f79426c586b206ae771d3aacc 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -61,6 +61,7 @@ #include "iapp_state_callback.h" #include "iapplication_state_observer.h" #include "iconfiguration_observer.h" +#include "inative_child_notify.h" #include "iremote_object.h" #include "irender_state_observer.h" #include "istart_specified_ability_response.h" @@ -82,7 +83,6 @@ #include "running_multi_info.h" #include "multi_user_config_mgr.h" #include "iuser_callback.h" -#include "native_child_notify_interface.h" namespace OHOS { namespace AbilityRuntime { diff --git a/services/appmgr/include/app_native_spawn_manager.h b/services/appmgr/include/app_native_spawn_manager.h index 31f4a2793c73353edc93a1ed093259274daca8db..0fcfd4153ecdd4910f9b989724399031cd673bfe 100644 --- a/services/appmgr/include/app_native_spawn_manager.h +++ b/services/appmgr/include/app_native_spawn_manager.h @@ -20,7 +20,7 @@ #include #include "nocopyable.h" #include "app_running_manager.h" -#include "native_child_notify_interface.h" +#include "inative_child_notify.h" namespace OHOS { namespace AppExecFwk { diff --git a/test/fuzztest/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer.cpp b/test/fuzztest/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer.cpp index 0a571fa70c90061c765a4c90103997ff74b4cb92..3b8a5210b42f769469e9e647028e18dec6e8079d 100644 --- a/test/fuzztest/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer.cpp +++ b/test/fuzztest/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer/abilityinterfacesappmgrnativechildnotifyproxy_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -19,8 +19,8 @@ #include #define private public +#include "inative_child_notify.h" #include "native_child_notify_proxy.h" -#include "native_child_notify_interface.h" #undef private #include "securec.h" @@ -72,21 +72,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) infosProxy->OnNativeChildStarted(nativeChild); int32_t errCode = static_cast(GetU32Data(data)); infosProxy->OnError(errCode); - MessageParcel parcel; - parcel.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN); - parcel.WriteBuffer(data, size); - parcel.RewindRead(0); - MessageParcel parcels; - parcels.WriteInterfaceToken(AMSMGR_INTERFACE_TOKEN); - parcels.WriteBuffer(data, size); - parcels.RewindRead(0); - infosProxy->WriteInterfaceToken(parcels); - uint32_t codeOne = static_cast(INPUT_ZERO); - MessageParcel reply; - MessageOption option; - infosProxy->SendRequest(codeOne, parcel, reply, option); - uint32_t codeTwo = static_cast(INPUT_ONE); - infosProxy->SendRequest(codeTwo, parcel, reply, option); return true; } } diff --git a/test/fuzztest/abilityinterfacesappmgrnativechildnotifystub_fuzzer/abilityinterfacesappmgrnativechildnotifystub_fuzzer.cpp b/test/fuzztest/abilityinterfacesappmgrnativechildnotifystub_fuzzer/abilityinterfacesappmgrnativechildnotifystub_fuzzer.cpp index ac67588a931237589c45bd4df7d94419c08e12ad..68361148c332a9b9c0cd60ba35d63ba86667bb16 100644 --- a/test/fuzztest/abilityinterfacesappmgrnativechildnotifystub_fuzzer/abilityinterfacesappmgrnativechildnotifystub_fuzzer.cpp +++ b/test/fuzztest/abilityinterfacesappmgrnativechildnotifystub_fuzzer/abilityinterfacesappmgrnativechildnotifystub_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-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 @@ -20,8 +20,8 @@ #define private public #define protected public +#include "inative_child_notify.h" #include "native_child_notify_stub.h" -#include "native_child_notify_interface.h" #undef protected #undef private @@ -58,9 +58,18 @@ public: virtual ~ NativeChildNotifyStubFUZZ() {}; int OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override{ return 0; }; - void OnNativeChildStarted(const sptr &nativeChild) override{}; - void OnError(int32_t errCode) override{}; - int32_t OnNativeChildExit(int32_t pid, int32_t signal) override{ return 0; }; + ErrCode OnNativeChildStarted(const sptr &nativeChild) override + { + return ERR_OK; + } + ErrCode OnError(int32_t errCode) override + { + return ERR_OK; + } + ErrCode OnNativeChildExit(int32_t pid, int32_t signal) override + { + return ERR_OK; + } }; sptr GetFuzzAbilityToken() @@ -79,7 +88,7 @@ sptr GetFuzzAbilityToken() bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { - uint32_t code = static_cast(INativeChildNotify::IPC_ID_ON_NATIVE_CHILD_STARTED); + uint32_t code = static_cast(INativeChildNotifyIpcCode::COMMAND_ON_NATIVE_CHILD_STARTED); MessageParcel parcel; parcel.WriteInterfaceToken(NATIVE_CHILD_NOTIFY_TOKEN); parcel.WriteBuffer(data, size); @@ -88,7 +97,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) MessageOption option; std::shared_ptr abms = std::make_shared(); abms->OnRemoteRequest(code, parcel, reply, option); - code = static_cast(INativeChildNotify::IPC_ID_ON_ERROR); + code = static_cast(INativeChildNotifyIpcCode::COMMAND_ON_ERROR); abms->OnRemoteRequest(code, parcel, reply, option); return true; } diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 88c49ffabd1c02478f8f28cef43f7d8a446f3d25..56ca4fa8c83c1573bf757d095ed662a4f72b7514 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -43,8 +43,6 @@ ohos_source_set("appmgr_test_source") { "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_scheduler_host.cpp", "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_scheduler_proxy.cpp", "${ability_runtime_innerkits_path}/app_manager/src/appmgr/fault_data.cpp", - "${ability_runtime_innerkits_path}/app_manager/src/appmgr/native_child_notify_proxy.cpp", - "${ability_runtime_innerkits_path}/app_manager/src/appmgr/native_child_notify_stub.cpp", "${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_info.cpp", "${ability_runtime_innerkits_path}/app_manager/src/appmgr/profile.cpp", "${ability_runtime_innerkits_path}/app_manager/src/appmgr/render_scheduler_host.cpp", diff --git a/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp b/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp index f12b91f70f0075cdee33a2b1804e0711e77bd3ec..6372eb3d018a914c79611163a73029b1a4be5f70 100644 --- a/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp +++ b/test/unittest/ams_ipc_interface_test/ams_ipc_appmgr_interface_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 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 @@ -45,9 +45,18 @@ public: NativeChildCallbackMock() = default; virtual ~NativeChildCallbackMock() = default; - void OnNativeChildStarted(const sptr &nativeChild) {} - void OnError(int32_t errCode) {} - int32_t OnNativeChildExit(int32_t pid, int32_t signal) { return 0; } + ErrCode OnNativeChildStarted(const sptr &nativeChild) + { + return ERR_OK; + } + ErrCode OnError(int32_t errCode) + { + return ERR_OK; + } + ErrCode OnNativeChildExit(int32_t pid, int32_t signal) + { + return ERR_OK; + } }; class AmsIpcAppMgrInterfaceTest : public testing::Test { 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 7cdbab6100cb6b8934dde76ddf2957e339c410c8..1de9b86baf1e0818f3958c50a8c2d553e729f595 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 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -58,9 +58,18 @@ public: NativeChildCallbackMock() = default; virtual ~NativeChildCallbackMock() = default; - void OnNativeChildStarted(const sptr &nativeChild) {} - void OnError(int32_t errCode) {} - int32_t OnNativeChildExit(int32_t pid, int32_t signal) { return 0; } + ErrCode OnNativeChildStarted(const sptr &nativeChild) + { + return ERR_OK; + } + ErrCode OnError(int32_t errCode) + { + return ERR_OK; + } + ErrCode OnNativeChildExit(int32_t pid, int32_t signal) + { + return ERR_OK; + } }; class AppMgrStubTest : public testing::Test {