From e0f9a86be9be628d01b78a8b145c0142ff8bbdcf Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Wed, 3 Sep 2025 17:09:16 +0800 Subject: [PATCH 01/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- config.gni | 6 ++ .../innerkits/ipc_core/include/ipc_skeleton.h | 26 +++++++++ .../ipc_core/include/message_option.h | 1 + interfaces/innerkits/ipc_single/BUILD.gn | 6 ++ .../include/dbinder_base_invoker_define.h | 4 ++ .../include/dbinder_base_invoker_interface.h | 14 +++++ .../src/core/framework/include/sys_binder.h | 17 +++++- .../core/framework/source/ipc_skeleton.cpp | 20 +++++++ .../src/core/invoker/include/binder_invoker.h | 6 ++ .../core/invoker/include/iremote_invoker.h | 6 ++ .../core/invoker/source/binder_invoker.cpp | 42 ++++++++++++++ ipc/native/test/unittest/common/BUILD.gn | 4 ++ .../common/binder_invoker_unittest.cpp | 38 +++++++++++++ .../unittest/common/ipc_skeleton_unittest.cpp | 56 +++++++++++++++++++ .../unittest/common/mock_iremote_invoker.h | 4 ++ ipc/test/auxiliary/native/BUILD.gn | 13 +++++ .../auxiliary/native/include/test_service.h | 3 + .../native/include/test_service_base.h | 5 ++ .../native/include/test_service_client.h | 3 + .../native/include/test_service_proxy.h | 3 + .../native/include/test_service_stub.h | 3 + ipc/test/auxiliary/native/src/main_client.cpp | 15 +++++ .../auxiliary/native/src/test_service.cpp | 7 +++ .../native/src/test_service_client.cpp | 17 ++++++ .../native/src/test_service_proxy.cpp | 48 ++++++++++++++++ .../native/src/test_service_stub.cpp | 11 ++++ .../binderinvokernew004_fuzzer.cpp | 1 - .../ipc/native/src/core/source/BUILD.gn | 4 ++ test/unittest/mock/mock_iremote_invoker.h | 4 ++ 29 files changed, 385 insertions(+), 2 deletions(-) diff --git a/config.gni b/config.gni index bf6ea89d..5d3c8bbd 100644 --- a/config.gni +++ b/config.gni @@ -23,6 +23,7 @@ declare_args() { hiviewdfx_backtrace_support = false hiviewdfx_hisysevent_support = false ipc_proxy_dfx_backtrace_enabled = false + ipc_freeze_process_support = false } if (defined(global_parts_info) && @@ -44,3 +45,8 @@ if (defined(global_parts_info) && defined(global_parts_info.hiviewdfx_hisysevent)) { hiviewdfx_hisysevent_support = true } + +if (defined(global_parts_info) && + defined(global_parts_info.officeservice_space_mgr_service)) { + ipc_freeze_process_support = true +} \ No newline at end of file diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index a19a0e79..d4f53b0c 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -207,6 +207,32 @@ public: * @since 20 */ static uint32_t GetDCallingTokenID(); + +#ifdef FREEZE_PROCESS_SUPPORT + /** + * @brief Freeze or unfreeze a process. + * @param pid Process ID to freeze or unfreeze. + * @param freeze True to freeze the process, false to unfreeze it. + * @param timeout Timeout value in milliseconds to wait for the stub to finish processing requests + * before freezing. If the timeout is reached and processing is not completed, the freeze operation + * will be abandoned. + * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code + * defined in {@link ipc_types.h} otherwise. + * @since 20 + */ + static int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout); + + /** + * @brief Check if a process is frozen. + * @param pid Process ID to check. + * @param isFreeze Reference to a boolean variable that will store the freeze status of the process. + * True if the process is frozen, false otherwise. + * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code + * defined in {@link ipc_types.h} otherwise. + * @since 20 + */ + static int32_t CheckFreeze(uint32_t pid, bool &isFreeze); +#endif // FREEZE_PROCESS_SUPPORT }; class IPCDfx { diff --git a/interfaces/innerkits/ipc_core/include/message_option.h b/interfaces/innerkits/ipc_core/include/message_option.h index bd9f222f..0fe51ff6 100644 --- a/interfaces/innerkits/ipc_core/include/message_option.h +++ b/interfaces/innerkits/ipc_core/include/message_option.h @@ -26,6 +26,7 @@ public: TF_STATUS_CODE = 0x08, TF_ACCEPT_FDS = 0x10, TF_WAIT_TIME = 0x8, + TF_UPDATE_TXN = 0x40, TF_ASYNC_WAKEUP_LATER = 0x100000, }; MessageOption(int flags = TF_SYNC, int waitTime = TF_WAIT_TIME); diff --git a/interfaces/innerkits/ipc_single/BUILD.gn b/interfaces/innerkits/ipc_single/BUILD.gn index 497d8b40..23d8913c 100644 --- a/interfaces/innerkits/ipc_single/BUILD.gn +++ b/interfaces/innerkits/ipc_single/BUILD.gn @@ -122,6 +122,9 @@ ohos_shared_library("ipc_single") { if (hiviewdfx_hisysevent_support) { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } + if (ipc_freeze_process_support) { + defines += [ "FREEZE_PROCESS_SUPPORT" ] + } innerapi_tags = [ "chipsetsdk", "platformsdk", @@ -164,6 +167,9 @@ ohos_shared_library("ipc_single_test") { if (hiviewdfx_hisysevent_support) { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } + if (ipc_freeze_process_support) { + defines += [ "FREEZE_PROCESS_SUPPORT" ] + } innerapi_tags = [ "chipsetsdk_sp", "platformsdk", diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h index 157db0e7..fe6add34 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h @@ -77,6 +77,10 @@ public: virtual sptr GetSAMgrObject() override; virtual bool SetRegistryObject(sptr &object) override; virtual void FreeBuffer(void *data) override; +#ifdef FREEZE_PROCESS_SUPPORT + virtual int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) override; + virtual int32_t CheckFreeze(uint32_t pid, bool &isFreeze) override; +#endif // FREEZE_PROCESS_SUPPORT virtual std::shared_ptr WriteTransaction(int cmd, uint32_t flags, int32_t handle, int32_t socketId, uint32_t code, MessageParcel &data, uint64_t &seqNumber, int status); virtual int SendOrWaitForCompletion(int userWaitTime, uint64_t seqNumber, std::shared_ptr sessionOfPeer, diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index 7561c06a..e179c402 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -188,6 +188,20 @@ template void DBinderBaseInvoker::FreeBuffer(void *data) return; } +#ifdef FREEZE_PROCESS_SUPPORT +template +int32_t bool DBinderBaseInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +{ + return ERR_NONE; +} + +template +int32_t bool DBinderBaseInvoker::CheckFreeze(uint32_t pid, bool &isFreeze) +{ + return ERR_NONE; +} +#endif // FREEZE_PROCESS_SUPPORT + template bool DBinderBaseInvoker::CheckTransactionData(const dbinder_transaction_data *tr) const { if (tr->sizeOfSelf == 0 || tr->sizeOfSelf > SOCKET_MAX_BUFF_SIZE || tr->buffer_size > SOCKET_MAX_BUFF_SIZE || diff --git a/ipc/native/src/core/framework/include/sys_binder.h b/ipc/native/src/core/framework/include/sys_binder.h index 206e09e6..54dd232d 100644 --- a/ipc/native/src/core/framework/include/sys_binder.h +++ b/ipc/native/src/core/framework/include/sys_binder.h @@ -62,6 +62,18 @@ struct flat_binder_object { }; binder_uintptr_t cookie; }; + +struct binder_freeze_info { + __u32 pid; + __u32 enable; + __u32 timeout_ms; +}; + +struct binder_frozen_state_info { + __u32 pid; + bool has_unfrozen; +}; + #ifndef __linux__ #define HMB_ERROR_INFO_LEN 64 struct hmb_detailed_err { @@ -160,6 +172,8 @@ struct binder_sender_info { #define BINDER_GET_NODE_DEBUG_INFO _IOWR('b', 11, struct binder_node_debug_info) #define BINDER_GET_NODE_INFO_FOR_REF _IOWR('b', 12, struct binder_node_info_for_ref) #define BINDER_SET_CONTEXT_MGR_EXT _IOW('b', 13, struct flat_binder_object) +#define BINDER_FREEZE _IOW('b', 14, struct binder_freeze_info) +#define BINDER_GET_FROZEN_STATE _IOW('b', 15, struct binder_frozen_state_info) #define BINDER_FEATURE_SET _IOWR('b', 30, struct binder_feature_set) #define BINDER_GET_ACCESS_TOKEN _IOWR('b', 31, struct access_token) #define BINDER_GET_SENDER_INFO _IOWR('b', 32, struct binder_sender_info) @@ -241,7 +255,8 @@ enum binder_driver_return_protocol { BR_DEAD_BINDER = _IOR('r', 15, binder_uintptr_t), BR_CLEAR_DEATH_NOTIFICATION_DONE = _IOR('r', 16, binder_uintptr_t), BR_FAILED_REPLY = _IO('r', 17), - BR_RELEASE_NODE = _IO('r', 18), + BR_FROZEN_REPLY = _IO('r', 18), + BR_TRANSACTION_PENDING_FROZEN = _IO('r', 20), }; enum binder_driver_command_protocol { BC_TRANSACTION = _IOW('c', 0, struct binder_transaction_data), diff --git a/ipc/native/src/core/framework/source/ipc_skeleton.cpp b/ipc/native/src/core/framework/source/ipc_skeleton.cpp index 7948b69c..94c93f85 100644 --- a/ipc/native/src/core/framework/source/ipc_skeleton.cpp +++ b/ipc/native/src/core/framework/source/ipc_skeleton.cpp @@ -330,6 +330,26 @@ uint32_t IPCSkeleton::GetDCallingTokenID() return static_cast(GetSelfTokenID()); } +#ifdef FREEZE_PROCESS_SUPPORT +int32_t IPCSkeleton::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +{ + IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); + if (invoker == nullptr) { + return IPC_SKELETON_NULL_OBJECT_ERR; + } + return invoker->FreezeProcess(pid, freeze, timeout); +} + +int32_t IPCSkeleton::CheckFreeze(uint32_t pid, bool &isFreeze) +{ + IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); + if (invoker == nullptr) { + return IPC_SKELETON_NULL_OBJECT_ERR; + } + return invoker->CheckFreeze(pid, isFreeze); +} +#endif // FREEZE_PROCESS_SUPPORT + void IPCDfx::BlockUntilThreadAvailable() { IPCProcessSkeleton *current = IPCProcessSkeleton::GetCurrent(); diff --git a/ipc/native/src/core/invoker/include/binder_invoker.h b/ipc/native/src/core/invoker/include/binder_invoker.h index d8743e2b..d2362351 100644 --- a/ipc/native/src/core/invoker/include/binder_invoker.h +++ b/ipc/native/src/core/invoker/include/binder_invoker.h @@ -90,6 +90,12 @@ public: int SendRequest(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; +#ifdef FREEZE_PROCESS_SUPPORT + int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) override; + + int32_t CheckFreeze(uint32_t pid, bool &isFreeze) override; +#endif // FREEZE_PROCESS_SUPPORT + int SendReply(MessageParcel &reply, uint32_t flags, int32_t result) override; bool FlattenObject(Parcel &parcel, const IRemoteObject *object) const override; diff --git a/ipc/native/src/core/invoker/include/iremote_invoker.h b/ipc/native/src/core/invoker/include/iremote_invoker.h index 9feb8517..3d5753f9 100644 --- a/ipc/native/src/core/invoker/include/iremote_invoker.h +++ b/ipc/native/src/core/invoker/include/iremote_invoker.h @@ -51,6 +51,12 @@ public: virtual int SendRequest(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) = 0; +#ifdef FREEZE_PROCESS_SUPPORT + virtual int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) = 0; + + virtual int32_t CheckFreeze(uint32_t pid, bool &isFreeze) = 0; +#endif // FREEZE_PROCESS_SUPPORT + virtual bool AddDeathRecipient(int32_t handle, void *cookie) = 0; virtual bool RemoveDeathRecipient(int32_t handle, void *cookie) = 0; diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index d0fded34..519e20c6 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -737,6 +737,42 @@ int32_t BinderInvoker::SamgrServiceSendRequest( return error; } +#ifdef FREEZE_PROCESS_SUPPORT +int32_t BinderInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +{ + if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { + return IPC_INVOKER_CONNECT_ERR; + } + binder_freeze_info info; + info.enable = pid; + info.enable = freeze; + info.timeout_ms = timeout; + int error = binderConnector_->WriteBinder(BINDER_FREEZE, &info); + if (error != ERR_NONE) { + ZLOGE(LABEL, "Freeze process failed, error:%{public}d", error); + return error; + } + return ERR_NONE; +} + +int32_t BinderInvoker::CheckFreeze(uint32_t pid, bool &isFreeze) +{ + if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { + return IPC_INVOKER_CONNECT_ERR; + } + binder_frozen_state_info info; + info.pid = pid; + info.has_unfrozen = false; + int error = binderConnector_->WriteBinder(BINDER_GET_FROZEN_STATE, &info); + if (error != ERR_NONE) { + ZLOGE(LABEL, "Get freeze state failed, error:%{public}d", error); + return error; + } + isFreeze = !info.has_unfrozen; + return ERR_NONE; +} +#endif // FREEZE_PROCESS_SUPPORT + int32_t BinderInvoker::GeneralServiceSendRequest( const binder_transaction_data &tr, MessageParcel &data, MessageParcel &reply, MessageOption &option) { @@ -1230,10 +1266,16 @@ void BinderInvoker::DealWithCmd(MessageParcel *reply, bool &continueLoop, int32_ { switch (cmd) { case BR_TRANSACTION_COMPLETE: +#ifdef FREEZE_PROCESS_SUPPORT + case BR_TRANSACTION_PENDING_FROZEN: +#endif // FREEZE_PROCESS_SUPPORT OnTransactionComplete(reply, continueLoop, error, cmd); break; case BR_DEAD_REPLY: case BR_FAILED_REPLY: +#ifdef FREEZE_PROCESS_SUPPORT + case BR_FROZEN_REPLY: +#endif // FREEZE_PROCESS_SUPPORT OnDeadOrFailedReply(reply, continueLoop, error, cmd); break; case BR_REPLY: diff --git a/ipc/native/test/unittest/common/BUILD.gn b/ipc/native/test/unittest/common/BUILD.gn index f894a221..699de142 100644 --- a/ipc/native/test/unittest/common/BUILD.gn +++ b/ipc/native/test/unittest/common/BUILD.gn @@ -62,6 +62,10 @@ template("ipc_unittest") { "samgr:samgr_proxy", ] + if (ipc_freeze_process_support) { + defines = ["FREEZE_PROCESS_SUPPORT"] + } + if (hiviewdfx_hisysevent_support) { external_deps += [ "hisysevent:libhisysevent" ] } diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index f24bce52..0157ea5e 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -25,6 +25,7 @@ #include "ipc_process_skeleton.h" #include "sys_binder.h" +using namespace testing; using namespace testing::ext; using namespace OHOS; @@ -830,4 +831,41 @@ HWTEST_F(BinderInvokerUnitTest, GetInvocationStateTest001, TestSize.Level1) binderInvoker.isFirstInvoke_ = STATUS_FIRST_INVOKE; EXPECT_EQ(binderInvoker.GetInvocationState(), STATUS_FIRST_INVOKE); } + +#ifdef FREEZE_PROCESS_SUPPORT +/** +* @tc.name: FreezeProcessTest001 +* @tc.desc: cover FreezeProcess branch +* @tc.type: FUNC +*/ +HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) +{ + BinderInvoker binderInvoker; + binderInvoker.binderConnector_ = nullptr; + EXPECT_EQ(binderInvoker.FreezeProcess(1, true, 1), IPC_INVOKER_CONNECT_ERR); + + BinderConnector *binderConnector = BinderConnector::GetInstance(); + binderConnector->driverFD_ = -1; + binderInvoker.binderConnector_ = binderConnector; + EXPECT_EQ(binderInvoker.FreezeProcess(1, true, 1), IPC_INVOKER_CONNECT_ERR); +} + +/** +* @tc.name: CheckFreezeTest +* @tc.desc: cover CheckFreeze branch +* @tc.type: FUNC +*/ +HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest, TestSize.Level1) +{ + bool isFreeze = false; + BinderInvoker binderInvoker; + binderInvoker.binderConnector_ = nullptr; + EXPECT_EQ(binderInvoker.CheckFreeze(1, isFreeze), IPC_INVOKER_CONNECT_ERR); + + BinderConnector *binderConnector = BinderConnector::GetInstance(); + binderConnector->driverFD_ = -1; + binderInvoker.binderConnector_ = binderConnector; + EXPECT_EQ(binderInvoker.CheckFreeze(1, isFreeze), IPC_INVOKER_CONNECT_ERR); +} +#endif // FREEZE_PROCESS_SUPPORT } // namespace OHOS \ No newline at end of file diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index 71223a8f..8e35ca66 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -35,6 +35,7 @@ #undef protected #undef private +using namespace testing; using namespace testing::ext; using namespace OHOS; @@ -906,4 +907,59 @@ HWTEST_F(IPCSkeletonTest, GetDCallingTokenIDInRPC, TestSize.Level1) ASSERT_EQ(tokenId, 0); } + +#ifdef FREEZE_PROCESS_SUPPORT +/** + * @tc.name: FreezeProcessTest + * @tc.desc: Verify the FreezeProcess function. + * @tc.type: FUNC + */ +HWTEST_F(IPCSkeletonTest, FreezeProcessTest, TestSize.Level1) +{ + IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent(); + ASSERT_NE(current, nullptr); + MockIRemoteInvoker *binderInvoker = new (std::nothrow) MockIRemoteInvoker(); + ASSERT_NE(binderInvoker, nullptr); + MockIRemoteInvoker *dbinderInvoker = new (std::nothrow) MockIRemoteInvoker(); + ASSERT_NE(dbinderInvoker, nullptr); + + current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; + current->invokers_[IRemoteObject::IF_PROT_DATABUS] = dbinderInvoker; + + EXPECT_CALL(*binderInvoker, FreezeProcess(testing::_, testing::_, testing::_)()) + .WillRepeatedly(testing::Return(ERR_NONE)); + + ASSERT_EQ(IPCSkeleton::FreezeProcess(0, true, 0), ERR_NONE); + std::fill(current->invokers_, current->invokers_ + IPCThreadSkeleton::INVOKER_MAX_COUNT, nullptr); + delete binderInvoker; + delete dbinderInvoker; +} + +/** + * @tc.name: CheckFreezeTest + * @tc.desc: Verify the CheckFreeze function. + * @tc.type: FUNC + */ +HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) +{ + IPCThreadSkeleton *current = IPCThreadSkeleton::GetCurrent(); + ASSERT_NE(current, nullptr); + MockIRemoteInvoker *binderInvoker = new (std::nothrow) MockIRemoteInvoker(); + ASSERT_NE(binderInvoker, nullptr); + MockIRemoteInvoker *dbinderInvoker = new (std::nothrow) MockIRemoteInvoker(); + ASSERT_NE(dbinderInvoker, nullptr); + + current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; + current->invokers_[IRemoteObject::IF_PROT_DATABUS] = dbinderInvoker; + + EXPECT_CALL(*binderInvoker, CheckFreeze(testing::_, testing::_)()) + .WillRepeatedly(testing::Return(ERR_NONE)); + + bool isFreeze = false; + ASSERT_EQ(IPCSkeleton::CheckFreeze(0, isFreeze), ERR_NONE); + std::fill(current->invokers_, current->invokers_ + IPCThreadSkeleton::INVOKER_MAX_COUNT, nullptr); + delete binderInvoker; + delete dbinderInvoker; +} +#endif // FREEZE_PROCESS_SUPPORT } // namespace OHOS \ No newline at end of file diff --git a/ipc/native/test/unittest/common/mock_iremote_invoker.h b/ipc/native/test/unittest/common/mock_iremote_invoker.h index b53f3bb8..e0402d68 100644 --- a/ipc/native/test/unittest/common/mock_iremote_invoker.h +++ b/ipc/native/test/unittest/common/mock_iremote_invoker.h @@ -41,6 +41,10 @@ public: MOCK_METHOD3(SendReply, int(MessageParcel &reply, uint32_t flags, int32_t result)); MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); +#ifdef FREEZE_PROCESS_SUPPORT + MOCK_METHOD3(FreezeProcess, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); + MOCK_METHOD2(CheckFreeze, int32_t(uint32_t pid, bool &isFreeze)); +#endif // FREEZE_PROCESS_SUPPORT MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD1(SetMaxWorkThread, bool(int maxThreadNum)); diff --git a/ipc/test/auxiliary/native/BUILD.gn b/ipc/test/auxiliary/native/BUILD.gn index 8832a75c..e5d4b12a 100644 --- a/ipc/test/auxiliary/native/BUILD.gn +++ b/ipc/test/auxiliary/native/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import("//build/ohos.gni") +import("//foundation/communication/ipc/config.gni") SUBSYSTEM_DIR = "//foundation/communication/ipc" IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native" @@ -31,6 +32,10 @@ ohos_shared_library("ipc_test_helper") { "./src/test_service_stub.cpp", ] + if (ipc_freeze_process_support) { + defines = [ "FREEZE_PROCESS_SUPPORT" ] + } + configs = [ "$IPC_TEST_ROOT:ipc_test_config", "$SUBSYSTEM_DIR/config:ipc_util_config", @@ -90,6 +95,10 @@ ohos_executable("ipc_client_test") { "$SUBSYSTEM_DIR/interfaces/innerkits/c_api:ipc_capi", ] + if (ipc_freeze_process_support) { + defines = [ "FREEZE_PROCESS_SUPPORT" ] + } + external_deps = [ "access_token:libnativetoken_shared", "access_token:libtokensetproc_shared", @@ -125,6 +134,10 @@ ohos_shared_library("ipc_test_helper_extra") { "$SUBSYSTEM_DIR/config:ipc_util_config", ] + if (ipc_freeze_process_support) { + defines = [ "FREEZE_PROCESS_SUPPORT" ] + } + deps = [ "$SUBSYSTEM_DIR/interfaces/innerkits/c_api:ipc_capi", "$SUBSYSTEM_DIR/interfaces/innerkits/ipc_single:ipc_single_test", diff --git a/ipc/test/auxiliary/native/include/test_service.h b/ipc/test/auxiliary/native/include/test_service.h index c7ece976..a522e2af 100644 --- a/ipc/test/auxiliary/native/include/test_service.h +++ b/ipc/test/auxiliary/native/include/test_service.h @@ -56,6 +56,9 @@ public: int TestSendTooManyRequest(int data, int &reply) override; int TestMultiThreadSendRequest(int data, int &reply) override; int TestQueryThreadInvocationState() override; +#ifdef FREEZE_PROCESS_SUPPORT + int TestFreezeProcess() override; +#endif // FREEZE_PROCESS_SUPPORT private: int testFd_; std::mutex remoteObjectsMutex_; diff --git a/ipc/test/auxiliary/native/include/test_service_base.h b/ipc/test/auxiliary/native/include/test_service_base.h index fd969b7c..e0670ca3 100644 --- a/ipc/test/auxiliary/native/include/test_service_base.h +++ b/ipc/test/auxiliary/native/include/test_service_base.h @@ -56,6 +56,8 @@ public: TRANS_ID_UNREGISTER_REMOTE_STUB_OBJECT = 24, TRANS_ID_QUERY_REMOTE_PROXY_OBJECT = 25, TRANS_ID_QUERY_THREAD_INVOCATION_STATE = 26, + TRANS_ID_TEST_FREEZE_PROCESS = 27, + TRANS_ID_TEST_TXN_ASYNC_TRANS = 28, }; public: virtual int TestSyncTransaction(int value, int &reply, int delayTime = 0) = 0; @@ -87,6 +89,9 @@ public: virtual int TestSendTooManyRequest(int data, int &reply) = 0; virtual int TestMultiThreadSendRequest(int data, int &reply) = 0; virtual int TestQueryThreadInvocationState() = 0; +#ifdef FREEZE_PROCESS_SUPPORT + virtual int TestFreezeProcess() = 0; +#endif // FREEZE_PROCESS_SUPPORT public: DECLARE_INTERFACE_DESCRIPTOR(u"test.ipc.ITestService"); diff --git a/ipc/test/auxiliary/native/include/test_service_client.h b/ipc/test/auxiliary/native/include/test_service_client.h index 605e805d..bc22e773 100644 --- a/ipc/test/auxiliary/native/include/test_service_client.h +++ b/ipc/test/auxiliary/native/include/test_service_client.h @@ -45,6 +45,9 @@ public: bool TestUnRegisterRemoteStub(); bool TestSendTooManyRequest(); bool TestMultiThreadSendRequest(); +#ifdef FREEZE_PROCESS_SUPPORT + int TestFreezeProcess(); +#endif // FREEZE_PROCESS_SUPPORT bool TestQueryThreadInvocationState(); private: diff --git a/ipc/test/auxiliary/native/include/test_service_proxy.h b/ipc/test/auxiliary/native/include/test_service_proxy.h index c6334114..15d0cd67 100644 --- a/ipc/test/auxiliary/native/include/test_service_proxy.h +++ b/ipc/test/auxiliary/native/include/test_service_proxy.h @@ -51,6 +51,9 @@ public: sptr TestQueryRemoteProxy(const char *descriptor) override; int TestSendTooManyRequest(int data, int &reply) override; int TestMultiThreadSendRequest(int data, int &reply) override; +#ifdef FREEZE_PROCESS_SUPPORT + int TestFreezeProcess() override; +#endif // FREEZE_PROCESS_SUPPORT int TestQueryThreadInvocationState() override; private: diff --git a/ipc/test/auxiliary/native/include/test_service_stub.h b/ipc/test/auxiliary/native/include/test_service_stub.h index b5190036..32bdfaa8 100644 --- a/ipc/test/auxiliary/native/include/test_service_stub.h +++ b/ipc/test/auxiliary/native/include/test_service_stub.h @@ -50,6 +50,9 @@ private: int32_t QueryRemoteProxy(MessageParcel &data, MessageParcel &reply); int32_t ServerFlushAsyncCalls(MessageParcel &data, MessageParcel &reply); int32_t ServerThreadInvocationState(MessageParcel &data, MessageParcel &reply); +#ifdef FREEZE_PROCESS_SUPPORT + int32_t ServerTestFreezeProcess(MessageParcel &data, MessageParcel &reply); +#endif // FREEZE_PROCESS_SUPPORT void InitMessageProcessMap(); using TestServiceStubFunc = int32_t(TestServiceStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/ipc/test/auxiliary/native/src/main_client.cpp b/ipc/test/auxiliary/native/src/main_client.cpp index 6a486a57..e5d66bc5 100644 --- a/ipc/test/auxiliary/native/src/main_client.cpp +++ b/ipc/test/auxiliary/native/src/main_client.cpp @@ -82,6 +82,18 @@ void TestCaseSyncTrans(std::shared_ptr &testClient) } } +#ifdef FREEZE_PROCESS_SUPPORT +void TestCaseFreezeProcess(std::shared_ptr &testClient) +{ + bool ret = testClient->TestFreezeProcess(); + if (!ret) { + std::cout << "[FAILED] Execution of TestFreezeProcess case failed" < &testClient) { bool ret = testClient->StartPingService(); @@ -229,6 +241,9 @@ void ExecuteAllTestCase() TestCaseRegisterRemoteStub(testClient); TestCaseTooManyRequests(testClient); TestCaseMultiThreadSendRequest(testClient); +#ifdef FREEZE_PROCESS_SUPPORT + TestCaseFreezeProcess(testClient); +#endif // FREEZE_PROCESS_SUPPORT ZLOGI(LABEL, "All test cases have been executed"); } diff --git a/ipc/test/auxiliary/native/src/test_service.cpp b/ipc/test/auxiliary/native/src/test_service.cpp index c8b6b110..379b2695 100644 --- a/ipc/test/auxiliary/native/src/test_service.cpp +++ b/ipc/test/auxiliary/native/src/test_service.cpp @@ -345,4 +345,11 @@ int TestService::TestQueryThreadInvocationState() return state; } + +#ifdef FREEZE_PROCESS_SUPPORT +int TestService::TestFreezeProcess() +{ + return 0; +} +#endif // FREEZE_PROCESS_SUPPORT } // namespace OHOS diff --git a/ipc/test/auxiliary/native/src/test_service_client.cpp b/ipc/test/auxiliary/native/src/test_service_client.cpp index 154a7b0e..479c965f 100644 --- a/ipc/test/auxiliary/native/src/test_service_client.cpp +++ b/ipc/test/auxiliary/native/src/test_service_client.cpp @@ -74,6 +74,23 @@ bool TestServiceClient::StartSyncTransaction() return true; } +#ifdef FREEZE_PROCESS_SUPPORT +bool TestServiceClient::TestFreezeProcess() +{ + if (testService_ == nullptr) { + ZLOGE(LABEL, "The testService_ object is an empty object"); + return false; + } + + int ret = testService_->TestFreezeProcess(); + if (ret != 0) { + ZLOGE(LABEL, "TestFreezeProcess function call failed"); + return false; + } + return true; +} +#endif // FREEZE_PROCESS_SUPPORT + bool TestServiceClient::StartPingService() { if (testService_ == nullptr) { diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index 7a043511..b5e8b7b7 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -95,6 +97,52 @@ int TestServiceProxy::TestSyncTransaction(int value, int &reply, int delayTime) return ret; } +#ifdef FREEZE_PROCESS_SUPPORT +int TestServiceProxy::TestFreezeProcess() +{ + ZLOGI(LABEL, "TestFreezeProcess"); + + auto remote = Remote(); + if (remote == nullptr) { + ZLOGI(LABEL, "The obtained proxy is a null pointer"); + return -1; + } + + MessageOption option; + MessageParcel dataParcel; + MessageParcel replyParcel; + int ret = remote->SendRequest(TRANS_ID_TEST_FREEZE_PROCESS, dataParcel, replyParcel, option); + if (ret != ERR_NONE) { + return ret; + } + int pid = replyParcel.ReadInt32(); + ZLOGI(LABEL, "Get pid from server, server pid = %{public}d", pid); + + int timeout = 1000; + auto res = IPCSkeleton::FreezeProcess(pid, true, timeout); + if (res != ERR_NONE) { + ZLOGI(LABEL, "FreezeProcess failed, error code = %{public}d", res); + return res; + } + + bool isFreeze = false; + res = IPCSkeleton::CheckFreeze(pid, isFreeze); + if (res != ERR_NONE || !isFreeze) { + ZLOGI(LABEL, "CheckFreeze failed, error code = %{public}d isFreeze = %{public}d ", res, isFreeze); + return -1; + } + + ret = remote->SendRequest(TRANS_ID_TEST_FREEZE_PROCESS, dataParcel, replyParcel, option); + if (ret != ERR_NONE) { + ZLOGI(LABEL, "SendRequest failed, error code = %{public}d", ret); + return -1; + } + + ZLOGI(LABEL, "TestFreezeProcess success"); + return 0; +} +#endif // FREEZE_PROCESS_SUPPORT + int TestServiceProxy::TestSendTooManyRequest(int data, int &reply) { int ret = 0; diff --git a/ipc/test/auxiliary/native/src/test_service_stub.cpp b/ipc/test/auxiliary/native/src/test_service_stub.cpp index d9a082d6..549216b6 100644 --- a/ipc/test/auxiliary/native/src/test_service_stub.cpp +++ b/ipc/test/auxiliary/native/src/test_service_stub.cpp @@ -72,6 +72,9 @@ void TestServiceStub::InitMessageProcessMap() funcMap_[static_cast(TRANS_ID_UNREGISTER_REMOTE_STUB_OBJECT)] = &TestServiceStub::UnRegisterRemoteStub; funcMap_[static_cast(TRANS_ID_QUERY_REMOTE_PROXY_OBJECT)] = &TestServiceStub::QueryRemoteProxy; funcMap_[static_cast(TRANS_ID_QUERY_THREAD_INVOCATION_STATE)] = &TestServiceStub::ServerThreadInvocationState; +#ifdef FREEZE_PROCESS_SUPPORT + funcMap_[static_cast(TRANS_ID_TEST_FREEZE_PROCESS)] = &TestServiceStub::ServerTestFreezeProcess; +#endif // FREEZE_PROCESS_SUPPORT } int32_t TestServiceStub::ServerSyncTransaction(MessageParcel &data, MessageParcel &reply) @@ -483,4 +486,12 @@ int32_t TestServiceStub::ServerThreadInvocationState(MessageParcel &data, Messag reply.WriteInt32(ret); return ret; } + +#ifdef FREEZE_PROCESS_SUPPORT +int32_t TestServiceStub::ServerTestFreezeProcess(MessageParcel &data, MessageParcel &reply) +{ + reply.WriteInt32(getpid()); + return 0; +} +#endif // FREEZE_PROCESS_SUPPORT } // namespace OHOS diff --git a/test/fuzztest/ipc/native/src/core/binderinvokernew/binderinvokernew004_fuzzer/binderinvokernew004_fuzzer.cpp b/test/fuzztest/ipc/native/src/core/binderinvokernew/binderinvokernew004_fuzzer/binderinvokernew004_fuzzer.cpp index 3c886ed5..c3b8c88f 100644 --- a/test/fuzztest/ipc/native/src/core/binderinvokernew/binderinvokernew004_fuzzer/binderinvokernew004_fuzzer.cpp +++ b/test/fuzztest/ipc/native/src/core/binderinvokernew/binderinvokernew004_fuzzer/binderinvokernew004_fuzzer.cpp @@ -42,7 +42,6 @@ static const std::vector cmdList = { binder_driver_return_protocol::BR_DEAD_BINDER, binder_driver_return_protocol::BR_CLEAR_DEATH_NOTIFICATION_DONE, binder_driver_return_protocol::BR_FAILED_REPLY, - binder_driver_return_protocol::BR_RELEASE_NODE, }; void HandleReplyFuzzTest(FuzzedDataProvider &provider) diff --git a/test/unittest/ipc/native/src/core/source/BUILD.gn b/test/unittest/ipc/native/src/core/source/BUILD.gn index 8236f82c..c843dc2d 100644 --- a/test/unittest/ipc/native/src/core/source/BUILD.gn +++ b/test/unittest/ipc/native/src/core/source/BUILD.gn @@ -64,6 +64,10 @@ template("ipc_unittest") { "samgr:samgr_proxy", ] + if (ipc_freeze_process_support) { + defines += [ "FREEZE_PROCESS_SUPPORT" ] + } + if (hiviewdfx_hisysevent_support) { external_deps += [ "hisysevent:libhisysevent" ] } diff --git a/test/unittest/mock/mock_iremote_invoker.h b/test/unittest/mock/mock_iremote_invoker.h index b524b532..bb2d41a6 100644 --- a/test/unittest/mock/mock_iremote_invoker.h +++ b/test/unittest/mock/mock_iremote_invoker.h @@ -41,6 +41,10 @@ public: MOCK_METHOD3(SendReply, int(MessageParcel &reply, uint32_t flags, int32_t result)); MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); +#ifdef FREEZE_PROCESS_SUPPORT + MOCK_METHOD3(FreezeProcess, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); + MOCK_METHOD2(CheckFreeze, int32_t(uint32_t pid, bool &isFreeze)); +#endif // FREEZE_PROCESS_SUPPORT MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD1(SetMaxWorkThread, bool(int maxThreadNum)); -- Gitee From 44fa7308e470a4d74f28ff02c4cd62225831677c Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 09:43:04 +0800 Subject: [PATCH 02/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- config.gni | 4 ++-- interfaces/innerkits/ipc_single/BUILD.gn | 4 ++-- ipc/native/test/unittest/common/BUILD.gn | 2 +- .../test/unittest/common/ipc_skeleton_unittest.cpp | 12 ++---------- ipc/test/auxiliary/native/BUILD.gn | 6 +++--- test/unittest/ipc/native/src/core/source/BUILD.gn | 2 +- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/config.gni b/config.gni index 5d3c8bbd..1b3e9cc4 100644 --- a/config.gni +++ b/config.gni @@ -23,7 +23,7 @@ declare_args() { hiviewdfx_backtrace_support = false hiviewdfx_hisysevent_support = false ipc_proxy_dfx_backtrace_enabled = false - ipc_freeze_process_support = false + ipc_freeze_process_enabled = false } if (defined(global_parts_info) && @@ -48,5 +48,5 @@ if (defined(global_parts_info) && if (defined(global_parts_info) && defined(global_parts_info.officeservice_space_mgr_service)) { - ipc_freeze_process_support = true + ipc_freeze_process_enabled = true } \ No newline at end of file diff --git a/interfaces/innerkits/ipc_single/BUILD.gn b/interfaces/innerkits/ipc_single/BUILD.gn index 23d8913c..30e5ce17 100644 --- a/interfaces/innerkits/ipc_single/BUILD.gn +++ b/interfaces/innerkits/ipc_single/BUILD.gn @@ -122,7 +122,7 @@ ohos_shared_library("ipc_single") { if (hiviewdfx_hisysevent_support) { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines += [ "FREEZE_PROCESS_SUPPORT" ] } innerapi_tags = [ @@ -167,7 +167,7 @@ ohos_shared_library("ipc_single_test") { if (hiviewdfx_hisysevent_support) { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines += [ "FREEZE_PROCESS_SUPPORT" ] } innerapi_tags = [ diff --git a/ipc/native/test/unittest/common/BUILD.gn b/ipc/native/test/unittest/common/BUILD.gn index 699de142..4053f230 100644 --- a/ipc/native/test/unittest/common/BUILD.gn +++ b/ipc/native/test/unittest/common/BUILD.gn @@ -62,7 +62,7 @@ template("ipc_unittest") { "samgr:samgr_proxy", ] - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines = ["FREEZE_PROCESS_SUPPORT"] } diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index 8e35ca66..b0a546bb 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -920,19 +920,15 @@ HWTEST_F(IPCSkeletonTest, FreezeProcessTest, TestSize.Level1) ASSERT_NE(current, nullptr); MockIRemoteInvoker *binderInvoker = new (std::nothrow) MockIRemoteInvoker(); ASSERT_NE(binderInvoker, nullptr); - MockIRemoteInvoker *dbinderInvoker = new (std::nothrow) MockIRemoteInvoker(); - ASSERT_NE(dbinderInvoker, nullptr); current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - current->invokers_[IRemoteObject::IF_PROT_DATABUS] = dbinderInvoker; EXPECT_CALL(*binderInvoker, FreezeProcess(testing::_, testing::_, testing::_)()) .WillRepeatedly(testing::Return(ERR_NONE)); ASSERT_EQ(IPCSkeleton::FreezeProcess(0, true, 0), ERR_NONE); - std::fill(current->invokers_, current->invokers_ + IPCThreadSkeleton::INVOKER_MAX_COUNT, nullptr); + current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; - delete dbinderInvoker; } /** @@ -946,20 +942,16 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) ASSERT_NE(current, nullptr); MockIRemoteInvoker *binderInvoker = new (std::nothrow) MockIRemoteInvoker(); ASSERT_NE(binderInvoker, nullptr); - MockIRemoteInvoker *dbinderInvoker = new (std::nothrow) MockIRemoteInvoker(); - ASSERT_NE(dbinderInvoker, nullptr); current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - current->invokers_[IRemoteObject::IF_PROT_DATABUS] = dbinderInvoker; EXPECT_CALL(*binderInvoker, CheckFreeze(testing::_, testing::_)()) .WillRepeatedly(testing::Return(ERR_NONE)); bool isFreeze = false; ASSERT_EQ(IPCSkeleton::CheckFreeze(0, isFreeze), ERR_NONE); - std::fill(current->invokers_, current->invokers_ + IPCThreadSkeleton::INVOKER_MAX_COUNT, nullptr); + current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; - delete dbinderInvoker; } #endif // FREEZE_PROCESS_SUPPORT } // namespace OHOS \ No newline at end of file diff --git a/ipc/test/auxiliary/native/BUILD.gn b/ipc/test/auxiliary/native/BUILD.gn index e5d4b12a..ff2f7e9e 100644 --- a/ipc/test/auxiliary/native/BUILD.gn +++ b/ipc/test/auxiliary/native/BUILD.gn @@ -32,7 +32,7 @@ ohos_shared_library("ipc_test_helper") { "./src/test_service_stub.cpp", ] - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines = [ "FREEZE_PROCESS_SUPPORT" ] } @@ -95,7 +95,7 @@ ohos_executable("ipc_client_test") { "$SUBSYSTEM_DIR/interfaces/innerkits/c_api:ipc_capi", ] - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines = [ "FREEZE_PROCESS_SUPPORT" ] } @@ -134,7 +134,7 @@ ohos_shared_library("ipc_test_helper_extra") { "$SUBSYSTEM_DIR/config:ipc_util_config", ] - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines = [ "FREEZE_PROCESS_SUPPORT" ] } diff --git a/test/unittest/ipc/native/src/core/source/BUILD.gn b/test/unittest/ipc/native/src/core/source/BUILD.gn index c843dc2d..f60cbe8a 100644 --- a/test/unittest/ipc/native/src/core/source/BUILD.gn +++ b/test/unittest/ipc/native/src/core/source/BUILD.gn @@ -64,7 +64,7 @@ template("ipc_unittest") { "samgr:samgr_proxy", ] - if (ipc_freeze_process_support) { + if (ipc_freeze_process_enabled) { defines += [ "FREEZE_PROCESS_SUPPORT" ] } -- Gitee From a85f0a111131a380dd0e4563868bb60e1473a76b Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 11:24:50 +0800 Subject: [PATCH 03/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- .../src/core/dbinder/include/dbinder_base_invoker_interface.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index e179c402..cab1f462 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -190,13 +190,13 @@ template void DBinderBaseInvoker::FreeBuffer(void *data) #ifdef FREEZE_PROCESS_SUPPORT template -int32_t bool DBinderBaseInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +int32_t DBinderBaseInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) { return ERR_NONE; } template -int32_t bool DBinderBaseInvoker::CheckFreeze(uint32_t pid, bool &isFreeze) +int32_t DBinderBaseInvoker::CheckFreeze(uint32_t pid, bool &isFreeze) { return ERR_NONE; } -- Gitee From f186e367067a7573e7ee470eaef4bbbc37942bc6 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 12:01:29 +0800 Subject: [PATCH 04/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- bundle.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 9c9b4e07..981e1b1f 100644 --- a/bundle.json +++ b/bundle.json @@ -23,7 +23,8 @@ "features": [ "ipc_feature_rpc_enabled", "ipc_feature_test_enabled", - "ipc_feature_trace_enabled" + "ipc_feature_trace_enabled", + "ipc_freeze_process_enabled" ], "syscap":[ "SystemCapability.Communication.IPC.Core" -- Gitee From 88eb77d702a7bbdceaac4e6e4546d9107f56642d Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 15:17:23 +0800 Subject: [PATCH 05/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- config.gni | 5 ----- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 4 ++-- .../dbinder/include/dbinder_base_invoker_define.h | 4 ++-- .../dbinder/include/dbinder_base_invoker_interface.h | 4 ++-- .../src/core/framework/source/ipc_skeleton.cpp | 8 ++++---- ipc/native/src/core/invoker/include/binder_invoker.h | 4 ++-- .../src/core/invoker/include/iremote_invoker.h | 4 ++-- .../src/core/invoker/source/binder_invoker.cpp | 4 ++-- .../test/unittest/common/binder_invoker_unittest.cpp | 12 ++++++------ .../test/unittest/common/ipc_skeleton_unittest.cpp | 12 ++++++------ .../test/unittest/common/mock_iremote_invoker.h | 4 ++-- ipc/test/auxiliary/native/src/test_service_proxy.cpp | 8 ++++---- test/unittest/mock/mock_iremote_invoker.h | 4 ++-- 13 files changed, 36 insertions(+), 41 deletions(-) diff --git a/config.gni b/config.gni index 1b3e9cc4..bf23e32e 100644 --- a/config.gni +++ b/config.gni @@ -44,9 +44,4 @@ if (defined(global_parts_info) && if (defined(global_parts_info) && defined(global_parts_info.hiviewdfx_hisysevent)) { hiviewdfx_hisysevent_support = true -} - -if (defined(global_parts_info) && - defined(global_parts_info.officeservice_space_mgr_service)) { - ipc_freeze_process_enabled = true } \ No newline at end of file diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index d4f53b0c..64b9bc5e 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -220,7 +220,7 @@ public: * defined in {@link ipc_types.h} otherwise. * @since 20 */ - static int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout); + static int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout); /** * @brief Check if a process is frozen. @@ -231,7 +231,7 @@ public: * defined in {@link ipc_types.h} otherwise. * @since 20 */ - static int32_t CheckFreeze(uint32_t pid, bool &isFreeze); + static int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze); #endif // FREEZE_PROCESS_SUPPORT }; diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h index fe6add34..aee87a71 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h @@ -78,8 +78,8 @@ public: virtual bool SetRegistryObject(sptr &object) override; virtual void FreeBuffer(void *data) override; #ifdef FREEZE_PROCESS_SUPPORT - virtual int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) override; - virtual int32_t CheckFreeze(uint32_t pid, bool &isFreeze) override; + virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; + virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) override; #endif // FREEZE_PROCESS_SUPPORT virtual std::shared_ptr WriteTransaction(int cmd, uint32_t flags, int32_t handle, int32_t socketId, uint32_t code, MessageParcel &data, uint64_t &seqNumber, int status); diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index cab1f462..f0397459 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -190,13 +190,13 @@ template void DBinderBaseInvoker::FreeBuffer(void *data) #ifdef FREEZE_PROCESS_SUPPORT template -int32_t DBinderBaseInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { return ERR_NONE; } template -int32_t DBinderBaseInvoker::CheckFreeze(uint32_t pid, bool &isFreeze) +int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) { return ERR_NONE; } diff --git a/ipc/native/src/core/framework/source/ipc_skeleton.cpp b/ipc/native/src/core/framework/source/ipc_skeleton.cpp index 94c93f85..7047b26e 100644 --- a/ipc/native/src/core/framework/source/ipc_skeleton.cpp +++ b/ipc/native/src/core/framework/source/ipc_skeleton.cpp @@ -331,22 +331,22 @@ uint32_t IPCSkeleton::GetDCallingTokenID() } #ifdef FREEZE_PROCESS_SUPPORT -int32_t IPCSkeleton::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +int32_t IPCSkeleton::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); if (invoker == nullptr) { return IPC_SKELETON_NULL_OBJECT_ERR; } - return invoker->FreezeProcess(pid, freeze, timeout); + return invoker->Freeze(pid, freeze, timeout); } -int32_t IPCSkeleton::CheckFreeze(uint32_t pid, bool &isFreeze) +int32_t IPCSkeleton::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) { IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); if (invoker == nullptr) { return IPC_SKELETON_NULL_OBJECT_ERR; } - return invoker->CheckFreeze(pid, isFreeze); + return invoker->GetProcessFreezeInfo(pid, isFreeze); } #endif // FREEZE_PROCESS_SUPPORT diff --git a/ipc/native/src/core/invoker/include/binder_invoker.h b/ipc/native/src/core/invoker/include/binder_invoker.h index d2362351..6064d7a8 100644 --- a/ipc/native/src/core/invoker/include/binder_invoker.h +++ b/ipc/native/src/core/invoker/include/binder_invoker.h @@ -91,9 +91,9 @@ public: MessageOption &option) override; #ifdef FREEZE_PROCESS_SUPPORT - int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) override; + int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; - int32_t CheckFreeze(uint32_t pid, bool &isFreeze) override; + int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) override; #endif // FREEZE_PROCESS_SUPPORT int SendReply(MessageParcel &reply, uint32_t flags, int32_t result) override; diff --git a/ipc/native/src/core/invoker/include/iremote_invoker.h b/ipc/native/src/core/invoker/include/iremote_invoker.h index 3d5753f9..70d93630 100644 --- a/ipc/native/src/core/invoker/include/iremote_invoker.h +++ b/ipc/native/src/core/invoker/include/iremote_invoker.h @@ -52,9 +52,9 @@ public: MessageOption &option) = 0; #ifdef FREEZE_PROCESS_SUPPORT - virtual int32_t FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) = 0; + virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) = 0; - virtual int32_t CheckFreeze(uint32_t pid, bool &isFreeze) = 0; + virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) = 0; #endif // FREEZE_PROCESS_SUPPORT virtual bool AddDeathRecipient(int32_t handle, void *cookie) = 0; diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 519e20c6..5a6d5c55 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -738,7 +738,7 @@ int32_t BinderInvoker::SamgrServiceSendRequest( } #ifdef FREEZE_PROCESS_SUPPORT -int32_t BinderInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout) +int32_t BinderInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { return IPC_INVOKER_CONNECT_ERR; @@ -755,7 +755,7 @@ int32_t BinderInvoker::FreezeProcess(uint32_t pid, bool freeze, uint32_t timeout return ERR_NONE; } -int32_t BinderInvoker::CheckFreeze(uint32_t pid, bool &isFreeze) +int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) { if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { return IPC_INVOKER_CONNECT_ERR; diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index 0157ea5e..8ecc2fb7 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -835,24 +835,24 @@ HWTEST_F(BinderInvokerUnitTest, GetInvocationStateTest001, TestSize.Level1) #ifdef FREEZE_PROCESS_SUPPORT /** * @tc.name: FreezeProcessTest001 -* @tc.desc: cover FreezeProcess branch +* @tc.desc: cover Freeze branch * @tc.type: FUNC */ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) { BinderInvoker binderInvoker; binderInvoker.binderConnector_ = nullptr; - EXPECT_EQ(binderInvoker.FreezeProcess(1, true, 1), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.Freeze(1, true, 1), IPC_INVOKER_CONNECT_ERR); BinderConnector *binderConnector = BinderConnector::GetInstance(); binderConnector->driverFD_ = -1; binderInvoker.binderConnector_ = binderConnector; - EXPECT_EQ(binderInvoker.FreezeProcess(1, true, 1), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.Freeze(1, true, 1), IPC_INVOKER_CONNECT_ERR); } /** * @tc.name: CheckFreezeTest -* @tc.desc: cover CheckFreeze branch +* @tc.desc: cover GetProcessFreezeInfo branch * @tc.type: FUNC */ HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest, TestSize.Level1) @@ -860,12 +860,12 @@ HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest, TestSize.Level1) bool isFreeze = false; BinderInvoker binderInvoker; binderInvoker.binderConnector_ = nullptr; - EXPECT_EQ(binderInvoker.CheckFreeze(1, isFreeze), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); BinderConnector *binderConnector = BinderConnector::GetInstance(); binderConnector->driverFD_ = -1; binderInvoker.binderConnector_ = binderConnector; - EXPECT_EQ(binderInvoker.CheckFreeze(1, isFreeze), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); } #endif // FREEZE_PROCESS_SUPPORT } // namespace OHOS \ No newline at end of file diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index b0a546bb..f9024480 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -911,7 +911,7 @@ HWTEST_F(IPCSkeletonTest, GetDCallingTokenIDInRPC, TestSize.Level1) #ifdef FREEZE_PROCESS_SUPPORT /** * @tc.name: FreezeProcessTest - * @tc.desc: Verify the FreezeProcess function. + * @tc.desc: Verify the Freeze function. * @tc.type: FUNC */ HWTEST_F(IPCSkeletonTest, FreezeProcessTest, TestSize.Level1) @@ -923,17 +923,17 @@ HWTEST_F(IPCSkeletonTest, FreezeProcessTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - EXPECT_CALL(*binderInvoker, FreezeProcess(testing::_, testing::_, testing::_)()) + EXPECT_CALL(*binderInvoker, Freeze(testing::_, testing::_, testing::_)()) .WillRepeatedly(testing::Return(ERR_NONE)); - ASSERT_EQ(IPCSkeleton::FreezeProcess(0, true, 0), ERR_NONE); + ASSERT_EQ(IPCSkeleton::Freeze(0, true, 0), ERR_NONE); current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; } /** * @tc.name: CheckFreezeTest - * @tc.desc: Verify the CheckFreeze function. + * @tc.desc: Verify the GetProcessFreezeInfo function. * @tc.type: FUNC */ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) @@ -945,11 +945,11 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - EXPECT_CALL(*binderInvoker, CheckFreeze(testing::_, testing::_)()) + EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(testing::_, testing::_)()) .WillRepeatedly(testing::Return(ERR_NONE)); bool isFreeze = false; - ASSERT_EQ(IPCSkeleton::CheckFreeze(0, isFreeze), ERR_NONE); + ASSERT_EQ(IPCSkeleton::GetProcessFreezeInfo(0, isFreeze), ERR_NONE); current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; } diff --git a/ipc/native/test/unittest/common/mock_iremote_invoker.h b/ipc/native/test/unittest/common/mock_iremote_invoker.h index e0402d68..f833d628 100644 --- a/ipc/native/test/unittest/common/mock_iremote_invoker.h +++ b/ipc/native/test/unittest/common/mock_iremote_invoker.h @@ -42,8 +42,8 @@ public: MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); #ifdef FREEZE_PROCESS_SUPPORT - MOCK_METHOD3(FreezeProcess, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); - MOCK_METHOD2(CheckFreeze, int32_t(uint32_t pid, bool &isFreeze)); + MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); + MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreeze)); #endif // FREEZE_PROCESS_SUPPORT MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index b5e8b7b7..60042e06 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -119,16 +119,16 @@ int TestServiceProxy::TestFreezeProcess() ZLOGI(LABEL, "Get pid from server, server pid = %{public}d", pid); int timeout = 1000; - auto res = IPCSkeleton::FreezeProcess(pid, true, timeout); + auto res = IPCSkeleton::Freeze(pid, true, timeout); if (res != ERR_NONE) { - ZLOGI(LABEL, "FreezeProcess failed, error code = %{public}d", res); + ZLOGI(LABEL, "Freeze failed, error code = %{public}d", res); return res; } bool isFreeze = false; - res = IPCSkeleton::CheckFreeze(pid, isFreeze); + res = IPCSkeleton::GetProcessFreezeInfo(pid, isFreeze); if (res != ERR_NONE || !isFreeze) { - ZLOGI(LABEL, "CheckFreeze failed, error code = %{public}d isFreeze = %{public}d ", res, isFreeze); + ZLOGI(LABEL, "GetProcessFreezeInfo failed, error code = %{public}d isFreeze = %{public}d ", res, isFreeze); return -1; } diff --git a/test/unittest/mock/mock_iremote_invoker.h b/test/unittest/mock/mock_iremote_invoker.h index bb2d41a6..c699ed79 100644 --- a/test/unittest/mock/mock_iremote_invoker.h +++ b/test/unittest/mock/mock_iremote_invoker.h @@ -42,8 +42,8 @@ public: MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); #ifdef FREEZE_PROCESS_SUPPORT - MOCK_METHOD3(FreezeProcess, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); - MOCK_METHOD2(CheckFreeze, int32_t(uint32_t pid, bool &isFreeze)); + MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); + MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreeze)); #endif // FREEZE_PROCESS_SUPPORT MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); -- Gitee From 203cf3008624eabe73401a3a5dc3305b80640281 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 15:35:10 +0800 Subject: [PATCH 06/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index 64b9bc5e..c2e0ddbb 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -223,7 +223,7 @@ public: static int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout); /** - * @brief Check if a process is frozen. + * @brief Get the freeze status of a specified process. * @param pid Process ID to check. * @param isFreeze Reference to a boolean variable that will store the freeze status of the process. * True if the process is frozen, false otherwise. -- Gitee From e1226b7d6de8ef618684f2d7feb874e0f719b337 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 16:01:56 +0800 Subject: [PATCH 07/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 11 +++++------ interfaces/innerkits/ipc_single/BUILD.gn | 4 ++-- .../dbinder/include/dbinder_base_invoker_define.h | 4 ++-- .../dbinder/include/dbinder_base_invoker_interface.h | 4 ++-- .../src/core/framework/source/ipc_skeleton.cpp | 4 ++-- ipc/native/src/core/invoker/include/binder_invoker.h | 4 ++-- .../src/core/invoker/include/iremote_invoker.h | 4 ++-- .../src/core/invoker/source/binder_invoker.cpp | 12 ++++++------ ipc/native/test/unittest/common/BUILD.gn | 2 +- .../test/unittest/common/binder_invoker_unittest.cpp | 4 ++-- .../test/unittest/common/ipc_skeleton_unittest.cpp | 4 ++-- .../test/unittest/common/mock_iremote_invoker.h | 4 ++-- ipc/test/auxiliary/native/BUILD.gn | 6 +++--- ipc/test/auxiliary/native/include/test_service.h | 4 ++-- .../auxiliary/native/include/test_service_base.h | 4 ++-- .../auxiliary/native/include/test_service_client.h | 4 ++-- .../auxiliary/native/include/test_service_proxy.h | 4 ++-- .../auxiliary/native/include/test_service_stub.h | 4 ++-- ipc/test/auxiliary/native/src/main_client.cpp | 8 ++++---- ipc/test/auxiliary/native/src/test_service.cpp | 4 ++-- .../auxiliary/native/src/test_service_client.cpp | 4 ++-- ipc/test/auxiliary/native/src/test_service_proxy.cpp | 4 ++-- ipc/test/auxiliary/native/src/test_service_stub.cpp | 8 ++++---- test/unittest/ipc/native/src/core/source/BUILD.gn | 2 +- test/unittest/mock/mock_iremote_invoker.h | 4 ++-- 25 files changed, 60 insertions(+), 61 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index c2e0ddbb..4eb2109c 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -208,15 +208,14 @@ public: */ static uint32_t GetDCallingTokenID(); -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED /** * @brief Freeze or unfreeze a process. * @param pid Process ID to freeze or unfreeze. * @param freeze True to freeze the process, false to unfreeze it. - * @param timeout Timeout value in milliseconds to wait for the stub to finish processing requests - * before freezing. If the timeout is reached and processing is not completed, the freeze operation - * will be abandoned. - * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code + * @param timeout Timeout value in milliseconds to wait for the stub to finish processing requests before freezing. + * If the timeout is reached and processing is not completed, the freeze operation will be abandoned. + * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code * defined in {@link ipc_types.h} otherwise. * @since 20 */ @@ -232,7 +231,7 @@ public: * @since 20 */ static int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze); -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED }; class IPCDfx { diff --git a/interfaces/innerkits/ipc_single/BUILD.gn b/interfaces/innerkits/ipc_single/BUILD.gn index 30e5ce17..faebf370 100644 --- a/interfaces/innerkits/ipc_single/BUILD.gn +++ b/interfaces/innerkits/ipc_single/BUILD.gn @@ -123,7 +123,7 @@ ohos_shared_library("ipc_single") { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } if (ipc_freeze_process_enabled) { - defines += [ "FREEZE_PROCESS_SUPPORT" ] + defines += [ "FREEZE_PROCESS_ENABLED" ] } innerapi_tags = [ "chipsetsdk", @@ -168,7 +168,7 @@ ohos_shared_library("ipc_single_test") { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } if (ipc_freeze_process_enabled) { - defines += [ "FREEZE_PROCESS_SUPPORT" ] + defines += [ "FREEZE_PROCESS_ENABLED" ] } innerapi_tags = [ "chipsetsdk_sp", diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h index aee87a71..13097708 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h @@ -77,10 +77,10 @@ public: virtual sptr GetSAMgrObject() override; virtual bool SetRegistryObject(sptr &object) override; virtual void FreeBuffer(void *data) override; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) override; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED virtual std::shared_ptr WriteTransaction(int cmd, uint32_t flags, int32_t handle, int32_t socketId, uint32_t code, MessageParcel &data, uint64_t &seqNumber, int status); virtual int SendOrWaitForCompletion(int userWaitTime, uint64_t seqNumber, std::shared_ptr sessionOfPeer, diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index f0397459..e643cb64 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -188,7 +188,7 @@ template void DBinderBaseInvoker::FreeBuffer(void *data) return; } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED template int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { @@ -200,7 +200,7 @@ int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze { return ERR_NONE; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED template bool DBinderBaseInvoker::CheckTransactionData(const dbinder_transaction_data *tr) const { diff --git a/ipc/native/src/core/framework/source/ipc_skeleton.cpp b/ipc/native/src/core/framework/source/ipc_skeleton.cpp index 7047b26e..7e1e387f 100644 --- a/ipc/native/src/core/framework/source/ipc_skeleton.cpp +++ b/ipc/native/src/core/framework/source/ipc_skeleton.cpp @@ -330,7 +330,7 @@ uint32_t IPCSkeleton::GetDCallingTokenID() return static_cast(GetSelfTokenID()); } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int32_t IPCSkeleton::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); @@ -348,7 +348,7 @@ int32_t IPCSkeleton::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) } return invoker->GetProcessFreezeInfo(pid, isFreeze); } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED void IPCDfx::BlockUntilThreadAvailable() { diff --git a/ipc/native/src/core/invoker/include/binder_invoker.h b/ipc/native/src/core/invoker/include/binder_invoker.h index 6064d7a8..e340a438 100644 --- a/ipc/native/src/core/invoker/include/binder_invoker.h +++ b/ipc/native/src/core/invoker/include/binder_invoker.h @@ -90,11 +90,11 @@ public: int SendRequest(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) override; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED int SendReply(MessageParcel &reply, uint32_t flags, int32_t result) override; diff --git a/ipc/native/src/core/invoker/include/iremote_invoker.h b/ipc/native/src/core/invoker/include/iremote_invoker.h index 70d93630..34272fe0 100644 --- a/ipc/native/src/core/invoker/include/iremote_invoker.h +++ b/ipc/native/src/core/invoker/include/iremote_invoker.h @@ -51,11 +51,11 @@ public: virtual int SendRequest(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) = 0; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) = 0; virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) = 0; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED virtual bool AddDeathRecipient(int32_t handle, void *cookie) = 0; diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 5a6d5c55..a5b52130 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -737,7 +737,7 @@ int32_t BinderInvoker::SamgrServiceSendRequest( return error; } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int32_t BinderInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { @@ -771,7 +771,7 @@ int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) isFreeze = !info.has_unfrozen; return ERR_NONE; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED int32_t BinderInvoker::GeneralServiceSendRequest( const binder_transaction_data &tr, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1266,16 +1266,16 @@ void BinderInvoker::DealWithCmd(MessageParcel *reply, bool &continueLoop, int32_ { switch (cmd) { case BR_TRANSACTION_COMPLETE: -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED case BR_TRANSACTION_PENDING_FROZEN: -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED OnTransactionComplete(reply, continueLoop, error, cmd); break; case BR_DEAD_REPLY: case BR_FAILED_REPLY: -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED case BR_FROZEN_REPLY: -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED OnDeadOrFailedReply(reply, continueLoop, error, cmd); break; case BR_REPLY: diff --git a/ipc/native/test/unittest/common/BUILD.gn b/ipc/native/test/unittest/common/BUILD.gn index 4053f230..9e714b8b 100644 --- a/ipc/native/test/unittest/common/BUILD.gn +++ b/ipc/native/test/unittest/common/BUILD.gn @@ -63,7 +63,7 @@ template("ipc_unittest") { ] if (ipc_freeze_process_enabled) { - defines = ["FREEZE_PROCESS_SUPPORT"] + defines = ["FREEZE_PROCESS_ENABLED"] } if (hiviewdfx_hisysevent_support) { diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index 8ecc2fb7..f0a6215c 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -832,7 +832,7 @@ HWTEST_F(BinderInvokerUnitTest, GetInvocationStateTest001, TestSize.Level1) EXPECT_EQ(binderInvoker.GetInvocationState(), STATUS_FIRST_INVOKE); } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED /** * @tc.name: FreezeProcessTest001 * @tc.desc: cover Freeze branch @@ -867,5 +867,5 @@ HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest, TestSize.Level1) binderInvoker.binderConnector_ = binderConnector; EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED } // namespace OHOS \ No newline at end of file diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index f9024480..81f51cf7 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -908,7 +908,7 @@ HWTEST_F(IPCSkeletonTest, GetDCallingTokenIDInRPC, TestSize.Level1) ASSERT_EQ(tokenId, 0); } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED /** * @tc.name: FreezeProcessTest * @tc.desc: Verify the Freeze function. @@ -953,5 +953,5 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED } // namespace OHOS \ No newline at end of file diff --git a/ipc/native/test/unittest/common/mock_iremote_invoker.h b/ipc/native/test/unittest/common/mock_iremote_invoker.h index f833d628..9f76dc20 100644 --- a/ipc/native/test/unittest/common/mock_iremote_invoker.h +++ b/ipc/native/test/unittest/common/mock_iremote_invoker.h @@ -41,10 +41,10 @@ public: MOCK_METHOD3(SendReply, int(MessageParcel &reply, uint32_t flags, int32_t result)); MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreeze)); -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD1(SetMaxWorkThread, bool(int maxThreadNum)); diff --git a/ipc/test/auxiliary/native/BUILD.gn b/ipc/test/auxiliary/native/BUILD.gn index ff2f7e9e..22933ef5 100644 --- a/ipc/test/auxiliary/native/BUILD.gn +++ b/ipc/test/auxiliary/native/BUILD.gn @@ -33,7 +33,7 @@ ohos_shared_library("ipc_test_helper") { ] if (ipc_freeze_process_enabled) { - defines = [ "FREEZE_PROCESS_SUPPORT" ] + defines = [ "FREEZE_PROCESS_ENABLED" ] } configs = [ @@ -96,7 +96,7 @@ ohos_executable("ipc_client_test") { ] if (ipc_freeze_process_enabled) { - defines = [ "FREEZE_PROCESS_SUPPORT" ] + defines = [ "FREEZE_PROCESS_ENABLED" ] } external_deps = [ @@ -135,7 +135,7 @@ ohos_shared_library("ipc_test_helper_extra") { ] if (ipc_freeze_process_enabled) { - defines = [ "FREEZE_PROCESS_SUPPORT" ] + defines = [ "FREEZE_PROCESS_ENABLED" ] } deps = [ diff --git a/ipc/test/auxiliary/native/include/test_service.h b/ipc/test/auxiliary/native/include/test_service.h index a522e2af..2bf519d6 100644 --- a/ipc/test/auxiliary/native/include/test_service.h +++ b/ipc/test/auxiliary/native/include/test_service.h @@ -56,9 +56,9 @@ public: int TestSendTooManyRequest(int data, int &reply) override; int TestMultiThreadSendRequest(int data, int &reply) override; int TestQueryThreadInvocationState() override; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int TestFreezeProcess() override; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED private: int testFd_; std::mutex remoteObjectsMutex_; diff --git a/ipc/test/auxiliary/native/include/test_service_base.h b/ipc/test/auxiliary/native/include/test_service_base.h index e0670ca3..8cf748e5 100644 --- a/ipc/test/auxiliary/native/include/test_service_base.h +++ b/ipc/test/auxiliary/native/include/test_service_base.h @@ -89,9 +89,9 @@ public: virtual int TestSendTooManyRequest(int data, int &reply) = 0; virtual int TestMultiThreadSendRequest(int data, int &reply) = 0; virtual int TestQueryThreadInvocationState() = 0; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED virtual int TestFreezeProcess() = 0; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED public: DECLARE_INTERFACE_DESCRIPTOR(u"test.ipc.ITestService"); diff --git a/ipc/test/auxiliary/native/include/test_service_client.h b/ipc/test/auxiliary/native/include/test_service_client.h index bc22e773..71effdfb 100644 --- a/ipc/test/auxiliary/native/include/test_service_client.h +++ b/ipc/test/auxiliary/native/include/test_service_client.h @@ -45,9 +45,9 @@ public: bool TestUnRegisterRemoteStub(); bool TestSendTooManyRequest(); bool TestMultiThreadSendRequest(); -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int TestFreezeProcess(); -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED bool TestQueryThreadInvocationState(); private: diff --git a/ipc/test/auxiliary/native/include/test_service_proxy.h b/ipc/test/auxiliary/native/include/test_service_proxy.h index 15d0cd67..f3975684 100644 --- a/ipc/test/auxiliary/native/include/test_service_proxy.h +++ b/ipc/test/auxiliary/native/include/test_service_proxy.h @@ -51,9 +51,9 @@ public: sptr TestQueryRemoteProxy(const char *descriptor) override; int TestSendTooManyRequest(int data, int &reply) override; int TestMultiThreadSendRequest(int data, int &reply) override; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int TestFreezeProcess() override; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED int TestQueryThreadInvocationState() override; private: diff --git a/ipc/test/auxiliary/native/include/test_service_stub.h b/ipc/test/auxiliary/native/include/test_service_stub.h index 32bdfaa8..e926dcb5 100644 --- a/ipc/test/auxiliary/native/include/test_service_stub.h +++ b/ipc/test/auxiliary/native/include/test_service_stub.h @@ -50,9 +50,9 @@ private: int32_t QueryRemoteProxy(MessageParcel &data, MessageParcel &reply); int32_t ServerFlushAsyncCalls(MessageParcel &data, MessageParcel &reply); int32_t ServerThreadInvocationState(MessageParcel &data, MessageParcel &reply); -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int32_t ServerTestFreezeProcess(MessageParcel &data, MessageParcel &reply); -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED void InitMessageProcessMap(); using TestServiceStubFunc = int32_t(TestServiceStub::*)(MessageParcel &data, MessageParcel &reply); diff --git a/ipc/test/auxiliary/native/src/main_client.cpp b/ipc/test/auxiliary/native/src/main_client.cpp index e5d66bc5..a8fc2823 100644 --- a/ipc/test/auxiliary/native/src/main_client.cpp +++ b/ipc/test/auxiliary/native/src/main_client.cpp @@ -82,7 +82,7 @@ void TestCaseSyncTrans(std::shared_ptr &testClient) } } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED void TestCaseFreezeProcess(std::shared_ptr &testClient) { bool ret = testClient->TestFreezeProcess(); @@ -92,7 +92,7 @@ void TestCaseFreezeProcess(std::shared_ptr &testClient) std::cout << "[PASS] Execution of TestFreezeProcess case Successful" < &testClient) { @@ -241,9 +241,9 @@ void ExecuteAllTestCase() TestCaseRegisterRemoteStub(testClient); TestCaseTooManyRequests(testClient); TestCaseMultiThreadSendRequest(testClient); -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED TestCaseFreezeProcess(testClient); -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED ZLOGI(LABEL, "All test cases have been executed"); } diff --git a/ipc/test/auxiliary/native/src/test_service.cpp b/ipc/test/auxiliary/native/src/test_service.cpp index 379b2695..c20fef86 100644 --- a/ipc/test/auxiliary/native/src/test_service.cpp +++ b/ipc/test/auxiliary/native/src/test_service.cpp @@ -346,10 +346,10 @@ int TestService::TestQueryThreadInvocationState() return state; } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int TestService::TestFreezeProcess() { return 0; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED } // namespace OHOS diff --git a/ipc/test/auxiliary/native/src/test_service_client.cpp b/ipc/test/auxiliary/native/src/test_service_client.cpp index 479c965f..3b3481e6 100644 --- a/ipc/test/auxiliary/native/src/test_service_client.cpp +++ b/ipc/test/auxiliary/native/src/test_service_client.cpp @@ -74,7 +74,7 @@ bool TestServiceClient::StartSyncTransaction() return true; } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED bool TestServiceClient::TestFreezeProcess() { if (testService_ == nullptr) { @@ -89,7 +89,7 @@ bool TestServiceClient::TestFreezeProcess() } return true; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED bool TestServiceClient::StartPingService() { diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index 60042e06..e413fd7e 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -97,7 +97,7 @@ int TestServiceProxy::TestSyncTransaction(int value, int &reply, int delayTime) return ret; } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int TestServiceProxy::TestFreezeProcess() { ZLOGI(LABEL, "TestFreezeProcess"); @@ -141,7 +141,7 @@ int TestServiceProxy::TestFreezeProcess() ZLOGI(LABEL, "TestFreezeProcess success"); return 0; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED int TestServiceProxy::TestSendTooManyRequest(int data, int &reply) { diff --git a/ipc/test/auxiliary/native/src/test_service_stub.cpp b/ipc/test/auxiliary/native/src/test_service_stub.cpp index 549216b6..d5575315 100644 --- a/ipc/test/auxiliary/native/src/test_service_stub.cpp +++ b/ipc/test/auxiliary/native/src/test_service_stub.cpp @@ -72,9 +72,9 @@ void TestServiceStub::InitMessageProcessMap() funcMap_[static_cast(TRANS_ID_UNREGISTER_REMOTE_STUB_OBJECT)] = &TestServiceStub::UnRegisterRemoteStub; funcMap_[static_cast(TRANS_ID_QUERY_REMOTE_PROXY_OBJECT)] = &TestServiceStub::QueryRemoteProxy; funcMap_[static_cast(TRANS_ID_QUERY_THREAD_INVOCATION_STATE)] = &TestServiceStub::ServerThreadInvocationState; -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED funcMap_[static_cast(TRANS_ID_TEST_FREEZE_PROCESS)] = &TestServiceStub::ServerTestFreezeProcess; -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED } int32_t TestServiceStub::ServerSyncTransaction(MessageParcel &data, MessageParcel &reply) @@ -487,11 +487,11 @@ int32_t TestServiceStub::ServerThreadInvocationState(MessageParcel &data, Messag return ret; } -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED int32_t TestServiceStub::ServerTestFreezeProcess(MessageParcel &data, MessageParcel &reply) { reply.WriteInt32(getpid()); return 0; } -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED } // namespace OHOS diff --git a/test/unittest/ipc/native/src/core/source/BUILD.gn b/test/unittest/ipc/native/src/core/source/BUILD.gn index f60cbe8a..a66535e3 100644 --- a/test/unittest/ipc/native/src/core/source/BUILD.gn +++ b/test/unittest/ipc/native/src/core/source/BUILD.gn @@ -65,7 +65,7 @@ template("ipc_unittest") { ] if (ipc_freeze_process_enabled) { - defines += [ "FREEZE_PROCESS_SUPPORT" ] + defines += [ "FREEZE_PROCESS_ENABLED" ] } if (hiviewdfx_hisysevent_support) { diff --git a/test/unittest/mock/mock_iremote_invoker.h b/test/unittest/mock/mock_iremote_invoker.h index c699ed79..d003c004 100644 --- a/test/unittest/mock/mock_iremote_invoker.h +++ b/test/unittest/mock/mock_iremote_invoker.h @@ -41,10 +41,10 @@ public: MOCK_METHOD3(SendReply, int(MessageParcel &reply, uint32_t flags, int32_t result)); MOCK_METHOD5(SendRequest, int(int handle, uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); -#ifdef FREEZE_PROCESS_SUPPORT +#ifdef FREEZE_PROCESS_ENABLED MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreeze)); -#endif // FREEZE_PROCESS_SUPPORT +#endif // FREEZE_PROCESS_ENABLED MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD1(SetMaxWorkThread, bool(int maxThreadNum)); -- Gitee From 73e5f9cf67b9658912844101e8209bac46798673 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 16:50:07 +0800 Subject: [PATCH 08/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- .../common/binder_invoker_unittest.cpp | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index f0a6215c..96342acd 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -833,6 +833,22 @@ HWTEST_F(BinderInvokerUnitTest, GetInvocationStateTest001, TestSize.Level1) } #ifdef FREEZE_PROCESS_ENABLED +/** +* @tc.name: FreezeProcessTest001 +* @tc.desc: cover Freeze branch +* @tc.type: FUNC +*/ +HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) +{ + BinderInvoker binderInvoker; + BinderConnector::instance_ = nullptr; + binderInvoker.binderConnector_ = BinderConnector::GetInstance(); + EXPECT_EQ(binderInvoker.Freeze(get_pid(), false, 1), ERR_NONE); + + bool isFreeze = false; + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), ERR_NONE); +} + /** * @tc.name: FreezeProcessTest001 * @tc.desc: cover Freeze branch @@ -851,11 +867,29 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) } /** -* @tc.name: CheckFreezeTest +* @tc.name: CheckFreezeTest02 +* @tc.desc: cover GetProcessFreezeInfo branch +* @tc.type: FUNC +*/ +HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest02, TestSize.Level1) +{ + bool isFreeze = false; + BinderInvoker binderInvoker; + binderInvoker.binderConnector_ = nullptr; + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); + + BinderConnector *binderConnector = BinderConnector::GetInstance(); + binderConnector->driverFD_ = -1; + binderInvoker.binderConnector_ = binderConnector; + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); +} + +/** +* @tc.name: CheckFreezeTest02 * @tc.desc: cover GetProcessFreezeInfo branch * @tc.type: FUNC */ -HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest, TestSize.Level1) +HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest02, TestSize.Level1) { bool isFreeze = false; BinderInvoker binderInvoker; -- Gitee From acebcd67d29c6fb1f55fe3765c97e6f239795efd Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Fri, 5 Sep 2025 16:53:05 +0800 Subject: [PATCH 09/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- .../common/binder_invoker_unittest.cpp | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index 96342acd..8eaae634 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -834,7 +834,7 @@ HWTEST_F(BinderInvokerUnitTest, GetInvocationStateTest001, TestSize.Level1) #ifdef FREEZE_PROCESS_ENABLED /** -* @tc.name: FreezeProcessTest001 +* @tc.name: FreezeProcessTest * @tc.desc: cover Freeze branch * @tc.type: FUNC */ @@ -854,7 +854,7 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) * @tc.desc: cover Freeze branch * @tc.type: FUNC */ -HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) +HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest001, TestSize.Level1) { BinderInvoker binderInvoker; binderInvoker.binderConnector_ = nullptr; @@ -867,29 +867,11 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) } /** -* @tc.name: CheckFreezeTest02 -* @tc.desc: cover GetProcessFreezeInfo branch -* @tc.type: FUNC -*/ -HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest02, TestSize.Level1) -{ - bool isFreeze = false; - BinderInvoker binderInvoker; - binderInvoker.binderConnector_ = nullptr; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); - - BinderConnector *binderConnector = BinderConnector::GetInstance(); - binderConnector->driverFD_ = -1; - binderInvoker.binderConnector_ = binderConnector; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); -} - -/** -* @tc.name: CheckFreezeTest02 +* @tc.name: GetProcessFreezeInfoTest * @tc.desc: cover GetProcessFreezeInfo branch * @tc.type: FUNC */ -HWTEST_F(BinderInvokerUnitTest, CheckFreezeTest02, TestSize.Level1) +HWTEST_F(BinderInvokerUnitTest, GetProcessFreezeInfoTest, TestSize.Level1) { bool isFreeze = false; BinderInvoker binderInvoker; -- Gitee From bee83d1a2ea7ecfab83da5df0b4b603a37451630 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Sat, 6 Sep 2025 14:48:30 +0800 Subject: [PATCH 10/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- ipc/test/auxiliary/native/include/test_service_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ipc/test/auxiliary/native/include/test_service_client.h b/ipc/test/auxiliary/native/include/test_service_client.h index 71effdfb..be2625d3 100644 --- a/ipc/test/auxiliary/native/include/test_service_client.h +++ b/ipc/test/auxiliary/native/include/test_service_client.h @@ -46,7 +46,7 @@ public: bool TestSendTooManyRequest(); bool TestMultiThreadSendRequest(); #ifdef FREEZE_PROCESS_ENABLED - int TestFreezeProcess(); + bool TestFreezeProcess(); #endif // FREEZE_PROCESS_ENABLED bool TestQueryThreadInvocationState(); -- Gitee From 2d069f0bddc2715534acd3391d355effadc7b8fb Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Sat, 6 Sep 2025 14:49:17 +0800 Subject: [PATCH 11/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index 4eb2109c..fcd97b86 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -215,7 +215,7 @@ public: * @param freeze True to freeze the process, false to unfreeze it. * @param timeout Timeout value in milliseconds to wait for the stub to finish processing requests before freezing. * If the timeout is reached and processing is not completed, the freeze operation will be abandoned. - * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code + * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code * defined in {@link ipc_types.h} otherwise. * @since 20 */ -- Gitee From e4139f4684f0fd15d51a9b192cca31a427b63fbf Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Sat, 6 Sep 2025 21:02:18 +0800 Subject: [PATCH 12/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_types.h | 1 + .../core/dbinder/include/dbinder_base_invoker_interface.h | 4 ++-- ipc/native/src/core/invoker/source/binder_invoker.cpp | 4 ++-- ipc/test/auxiliary/native/src/main_client.cpp | 7 ++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_types.h b/interfaces/innerkits/ipc_core/include/ipc_types.h index 540aac3b..facfceba 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_types.h +++ b/interfaces/innerkits/ipc_core/include/ipc_types.h @@ -138,6 +138,7 @@ enum { RPC_BASE_INVOKER_TRANSLATE_ERR, RPC_BASE_INVOKER_STUBINDEX_ERR, RPC_BASE_INVOKER_MALLOC_ERR, + RPC_BASE_INVOKER_NOT_SUPPORT_ERR, RPC_DATABUS_INVOKER_ERR = 600, RPC_DATABUS_INVOKER_INVALID_DATA_ERR, RPC_DATABUS_INVOKER_CLOSED_PEER_ERR, diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index e643cb64..59e9aecc 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -192,13 +192,13 @@ template void DBinderBaseInvoker::FreeBuffer(void *data) template int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { - return ERR_NONE; + return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; } template int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) { - return ERR_NONE; + return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; } #endif // FREEZE_PROCESS_ENABLED diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index a5b52130..1b152a13 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -749,7 +749,7 @@ int32_t BinderInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) info.timeout_ms = timeout; int error = binderConnector_->WriteBinder(BINDER_FREEZE, &info); if (error != ERR_NONE) { - ZLOGE(LABEL, "Freeze process failed, error:%{public}d", error); + ZLOGE(LABEL, "failed, error:%{public}d", error); return error; } return ERR_NONE; @@ -765,7 +765,7 @@ int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) info.has_unfrozen = false; int error = binderConnector_->WriteBinder(BINDER_GET_FROZEN_STATE, &info); if (error != ERR_NONE) { - ZLOGE(LABEL, "Get freeze state failed, error:%{public}d", error); + ZLOGE(LABEL, "error:%{public}d", error); return error; } isFreeze = !info.has_unfrozen; diff --git a/ipc/test/auxiliary/native/src/main_client.cpp b/ipc/test/auxiliary/native/src/main_client.cpp index a8fc2823..17e0818f 100644 --- a/ipc/test/auxiliary/native/src/main_client.cpp +++ b/ipc/test/auxiliary/native/src/main_client.cpp @@ -86,11 +86,8 @@ void TestCaseSyncTrans(std::shared_ptr &testClient) void TestCaseFreezeProcess(std::shared_ptr &testClient) { bool ret = testClient->TestFreezeProcess(); - if (!ret) { - std::cout << "[FAILED] Execution of TestFreezeProcess case failed" < Date: Mon, 8 Sep 2025 09:55:59 +0800 Subject: [PATCH 13/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 2 +- .../src/core/dbinder/include/dbinder_base_invoker_define.h | 2 +- .../core/dbinder/include/dbinder_base_invoker_interface.h | 2 +- ipc/native/src/core/framework/source/ipc_skeleton.cpp | 4 ++-- ipc/native/src/core/invoker/include/binder_invoker.h | 2 +- ipc/native/src/core/invoker/source/binder_invoker.cpp | 6 +++--- ipc/native/test/unittest/common/binder_invoker_unittest.cpp | 6 +++--- ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp | 4 ++-- ipc/native/test/unittest/common/mock_iremote_invoker.h | 2 +- ipc/test/auxiliary/native/src/test_service_proxy.cpp | 4 ++-- test/unittest/mock/mock_iremote_invoker.h | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index fcd97b86..4a1e7296 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -230,7 +230,7 @@ public: * defined in {@link ipc_types.h} otherwise. * @since 20 */ - static int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze); + static int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen); #endif // FREEZE_PROCESS_ENABLED }; diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h index 13097708..7d1f8cab 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h @@ -79,7 +79,7 @@ public: virtual void FreeBuffer(void *data) override; #ifdef FREEZE_PROCESS_ENABLED virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; - virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) override; + virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) override; #endif // FREEZE_PROCESS_ENABLED virtual std::shared_ptr WriteTransaction(int cmd, uint32_t flags, int32_t handle, int32_t socketId, uint32_t code, MessageParcel &data, uint64_t &seqNumber, int status); diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index 59e9aecc..aaec62a5 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -196,7 +196,7 @@ int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeou } template -int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) +int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) { return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; } diff --git a/ipc/native/src/core/framework/source/ipc_skeleton.cpp b/ipc/native/src/core/framework/source/ipc_skeleton.cpp index 7e1e387f..f555f1aa 100644 --- a/ipc/native/src/core/framework/source/ipc_skeleton.cpp +++ b/ipc/native/src/core/framework/source/ipc_skeleton.cpp @@ -340,13 +340,13 @@ int32_t IPCSkeleton::Freeze(uint32_t pid, bool freeze, uint32_t timeout) return invoker->Freeze(pid, freeze, timeout); } -int32_t IPCSkeleton::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) +int32_t IPCSkeleton::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) { IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); if (invoker == nullptr) { return IPC_SKELETON_NULL_OBJECT_ERR; } - return invoker->GetProcessFreezeInfo(pid, isFreeze); + return invoker->GetProcessFreezeInfo(pid, isFreezen); } #endif // FREEZE_PROCESS_ENABLED diff --git a/ipc/native/src/core/invoker/include/binder_invoker.h b/ipc/native/src/core/invoker/include/binder_invoker.h index e340a438..793c7eb5 100644 --- a/ipc/native/src/core/invoker/include/binder_invoker.h +++ b/ipc/native/src/core/invoker/include/binder_invoker.h @@ -93,7 +93,7 @@ public: #ifdef FREEZE_PROCESS_ENABLED int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; - int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) override; + int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) override; #endif // FREEZE_PROCESS_ENABLED int SendReply(MessageParcel &reply, uint32_t flags, int32_t result) override; diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 1b152a13..6ff1381b 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -744,7 +744,7 @@ int32_t BinderInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) return IPC_INVOKER_CONNECT_ERR; } binder_freeze_info info; - info.enable = pid; + info.pid = pid; info.enable = freeze; info.timeout_ms = timeout; int error = binderConnector_->WriteBinder(BINDER_FREEZE, &info); @@ -755,7 +755,7 @@ int32_t BinderInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) return ERR_NONE; } -int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) +int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) { if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { return IPC_INVOKER_CONNECT_ERR; @@ -768,7 +768,7 @@ int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) ZLOGE(LABEL, "error:%{public}d", error); return error; } - isFreeze = !info.has_unfrozen; + isFreezen = !info.has_unfrozen; return ERR_NONE; } #endif // FREEZE_PROCESS_ENABLED diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index 8eaae634..e4bf578d 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -843,10 +843,10 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) BinderInvoker binderInvoker; BinderConnector::instance_ = nullptr; binderInvoker.binderConnector_ = BinderConnector::GetInstance(); - EXPECT_EQ(binderInvoker.Freeze(get_pid(), false, 1), ERR_NONE); + EXPECT_EQ(binderInvoker.Freeze(getpid(), false, 1), ERR_NONE); - bool isFreeze = false; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), ERR_NONE); + bool isFreezen = false; + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreezen), ERR_NONE); } /** diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index 81f51cf7..66046516 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -948,8 +948,8 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(testing::_, testing::_)()) .WillRepeatedly(testing::Return(ERR_NONE)); - bool isFreeze = false; - ASSERT_EQ(IPCSkeleton::GetProcessFreezeInfo(0, isFreeze), ERR_NONE); + bool isFreezen = false; + ASSERT_EQ(IPCSkeleton::GetProcessFreezeInfo(0, isFreezen), ERR_NONE); current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; } diff --git a/ipc/native/test/unittest/common/mock_iremote_invoker.h b/ipc/native/test/unittest/common/mock_iremote_invoker.h index 9f76dc20..19911f4c 100644 --- a/ipc/native/test/unittest/common/mock_iremote_invoker.h +++ b/ipc/native/test/unittest/common/mock_iremote_invoker.h @@ -43,7 +43,7 @@ public: MessageParcel &reply, MessageOption &option)); #ifdef FREEZE_PROCESS_ENABLED MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); - MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreeze)); + MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreezen)); #endif // FREEZE_PROCESS_ENABLED MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index e413fd7e..0073031e 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -126,9 +126,9 @@ int TestServiceProxy::TestFreezeProcess() } bool isFreeze = false; - res = IPCSkeleton::GetProcessFreezeInfo(pid, isFreeze); + res = IPCSkeleton::GetProcessFreezeInfo(pid, isFreezen); if (res != ERR_NONE || !isFreeze) { - ZLOGI(LABEL, "GetProcessFreezeInfo failed, error code = %{public}d isFreeze = %{public}d ", res, isFreeze); + ZLOGI(LABEL, "GetProcessFreezeInfo failed, error code = %{public}d isFreezen = %{public}d ", res, isFreezen); return -1; } diff --git a/test/unittest/mock/mock_iremote_invoker.h b/test/unittest/mock/mock_iremote_invoker.h index d003c004..7a8e1401 100644 --- a/test/unittest/mock/mock_iremote_invoker.h +++ b/test/unittest/mock/mock_iremote_invoker.h @@ -43,7 +43,7 @@ public: MessageParcel &reply, MessageOption &option)); #ifdef FREEZE_PROCESS_ENABLED MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); - MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreeze)); + MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreezen)); #endif // FREEZE_PROCESS_ENABLED MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); -- Gitee From 3c3d66998ed7a67b645b4423a6d9c07e34a69366 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Mon, 8 Sep 2025 10:59:51 +0800 Subject: [PATCH 14/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- .../innerkits/ipc_core/include/ipc_skeleton.h | 2 +- .../src/core/invoker/include/iremote_invoker.h | 2 +- .../unittest/common/binder_invoker_unittest.cpp | 6 +++--- .../auxiliary/native/src/test_service_proxy.cpp | 16 ++++++++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index 4a1e7296..f52f0ad1 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -224,7 +224,7 @@ public: /** * @brief Get the freeze status of a specified process. * @param pid Process ID to check. - * @param isFreeze Reference to a boolean variable that will store the freeze status of the process. + * @param isFreezen Reference to a boolean variable that will store the freeze status of the process. * True if the process is frozen, false otherwise. * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code * defined in {@link ipc_types.h} otherwise. diff --git a/ipc/native/src/core/invoker/include/iremote_invoker.h b/ipc/native/src/core/invoker/include/iremote_invoker.h index 34272fe0..784c05b3 100644 --- a/ipc/native/src/core/invoker/include/iremote_invoker.h +++ b/ipc/native/src/core/invoker/include/iremote_invoker.h @@ -54,7 +54,7 @@ public: #ifdef FREEZE_PROCESS_ENABLED virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) = 0; - virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) = 0; + virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) = 0; #endif // FREEZE_PROCESS_ENABLED virtual bool AddDeathRecipient(int32_t handle, void *cookie) = 0; diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index e4bf578d..35558665 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -873,15 +873,15 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest001, TestSize.Level1) */ HWTEST_F(BinderInvokerUnitTest, GetProcessFreezeInfoTest, TestSize.Level1) { - bool isFreeze = false; + bool isFreezen = false; BinderInvoker binderInvoker; binderInvoker.binderConnector_ = nullptr; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreezen), IPC_INVOKER_CONNECT_ERR); BinderConnector *binderConnector = BinderConnector::GetInstance(); binderConnector->driverFD_ = -1; binderInvoker.binderConnector_ = binderConnector; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreeze), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreezen), IPC_INVOKER_CONNECT_ERR); } #endif // FREEZE_PROCESS_ENABLED } // namespace OHOS \ No newline at end of file diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index 0073031e..0e028c0a 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -125,13 +125,25 @@ int TestServiceProxy::TestFreezeProcess() return res; } - bool isFreeze = false; + bool isFreezen = false; res = IPCSkeleton::GetProcessFreezeInfo(pid, isFreezen); - if (res != ERR_NONE || !isFreeze) { + if (res != ERR_NONE || !isFreezen) { ZLOGI(LABEL, "GetProcessFreezeInfo failed, error code = %{public}d isFreezen = %{public}d ", res, isFreezen); return -1; } + ret = remote->SendRequest(TRANS_ID_TEST_FREEZE_PROCESS, dataParcel, replyParcel, option); + if (ret == ERR_NONE) { + ZLOGI(LABEL, "SendRequest success, so freeze process fail"); + return -1; + } + + res = IPCSkeleton::Freeze(pid, false, timeout); + if (res != ERR_NONE) { + ZLOGI(LABEL, "Freeze failed, error code = %{public}d", res); + return res; + } + ret = remote->SendRequest(TRANS_ID_TEST_FREEZE_PROCESS, dataParcel, replyParcel, option); if (ret != ERR_NONE) { ZLOGI(LABEL, "SendRequest failed, error code = %{public}d", ret); -- Gitee From 02165a7937c89f9f064bbc24f038ea352b763d1f Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Mon, 8 Sep 2025 15:23:27 +0800 Subject: [PATCH 15/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index 66046516..4bc8e04f 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -923,7 +923,7 @@ HWTEST_F(IPCSkeletonTest, FreezeProcessTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - EXPECT_CALL(*binderInvoker, Freeze(testing::_, testing::_, testing::_)()) + EXPECT_CALL(*binderInvoker, Freeze(testing::_, testing::_, testing::_)) .WillRepeatedly(testing::Return(ERR_NONE)); ASSERT_EQ(IPCSkeleton::Freeze(0, true, 0), ERR_NONE); @@ -945,7 +945,7 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(testing::_, testing::_)()) + EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(testing::_, testing::_)) .WillRepeatedly(testing::Return(ERR_NONE)); bool isFreezen = false; -- Gitee From af8d8ee746aa476e5702be0eae76ba1ccd1279b9 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Mon, 8 Sep 2025 19:43:22 +0800 Subject: [PATCH 16/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 4 ++-- .../core/dbinder/include/dbinder_base_invoker_define.h | 2 +- .../dbinder/include/dbinder_base_invoker_interface.h | 2 +- ipc/native/src/core/framework/source/ipc_skeleton.cpp | 4 ++-- ipc/native/src/core/invoker/include/binder_invoker.h | 2 +- ipc/native/src/core/invoker/include/iremote_invoker.h | 2 +- ipc/native/src/core/invoker/source/binder_invoker.cpp | 4 ++-- .../test/unittest/common/binder_invoker_unittest.cpp | 10 +++++----- .../test/unittest/common/ipc_skeleton_unittest.cpp | 4 ++-- ipc/native/test/unittest/common/mock_iremote_invoker.h | 2 +- ipc/test/auxiliary/native/src/test_service_proxy.cpp | 8 ++++---- test/unittest/mock/mock_iremote_invoker.h | 2 +- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index f52f0ad1..379da143 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -224,13 +224,13 @@ public: /** * @brief Get the freeze status of a specified process. * @param pid Process ID to check. - * @param isFreezen Reference to a boolean variable that will store the freeze status of the process. + * @param isFrozen Reference to a boolean variable that will store the freeze status of the process. * True if the process is frozen, false otherwise. * @return Returns {@link ERR_NONE} if the operation is successful; returns an error code * defined in {@link ipc_types.h} otherwise. * @since 20 */ - static int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen); + static int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFrozen); #endif // FREEZE_PROCESS_ENABLED }; diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h index 7d1f8cab..609f69cf 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_define.h @@ -79,7 +79,7 @@ public: virtual void FreeBuffer(void *data) override; #ifdef FREEZE_PROCESS_ENABLED virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; - virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) override; + virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) override; #endif // FREEZE_PROCESS_ENABLED virtual std::shared_ptr WriteTransaction(int cmd, uint32_t flags, int32_t handle, int32_t socketId, uint32_t code, MessageParcel &data, uint64_t &seqNumber, int status); diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index aaec62a5..e296e2a9 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -196,7 +196,7 @@ int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeou } template -int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) +int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) { return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; } diff --git a/ipc/native/src/core/framework/source/ipc_skeleton.cpp b/ipc/native/src/core/framework/source/ipc_skeleton.cpp index f555f1aa..f2ccbed2 100644 --- a/ipc/native/src/core/framework/source/ipc_skeleton.cpp +++ b/ipc/native/src/core/framework/source/ipc_skeleton.cpp @@ -340,13 +340,13 @@ int32_t IPCSkeleton::Freeze(uint32_t pid, bool freeze, uint32_t timeout) return invoker->Freeze(pid, freeze, timeout); } -int32_t IPCSkeleton::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) +int32_t IPCSkeleton::GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) { IRemoteInvoker *invoker = IPCThreadSkeleton::GetDefaultInvoker(); if (invoker == nullptr) { return IPC_SKELETON_NULL_OBJECT_ERR; } - return invoker->GetProcessFreezeInfo(pid, isFreezen); + return invoker->GetProcessFreezeInfo(pid, isFrozen); } #endif // FREEZE_PROCESS_ENABLED diff --git a/ipc/native/src/core/invoker/include/binder_invoker.h b/ipc/native/src/core/invoker/include/binder_invoker.h index 793c7eb5..08df160f 100644 --- a/ipc/native/src/core/invoker/include/binder_invoker.h +++ b/ipc/native/src/core/invoker/include/binder_invoker.h @@ -93,7 +93,7 @@ public: #ifdef FREEZE_PROCESS_ENABLED int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) override; - int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) override; + int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) override; #endif // FREEZE_PROCESS_ENABLED int SendReply(MessageParcel &reply, uint32_t flags, int32_t result) override; diff --git a/ipc/native/src/core/invoker/include/iremote_invoker.h b/ipc/native/src/core/invoker/include/iremote_invoker.h index 784c05b3..3ceae6a8 100644 --- a/ipc/native/src/core/invoker/include/iremote_invoker.h +++ b/ipc/native/src/core/invoker/include/iremote_invoker.h @@ -54,7 +54,7 @@ public: #ifdef FREEZE_PROCESS_ENABLED virtual int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout) = 0; - virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) = 0; + virtual int32_t GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) = 0; #endif // FREEZE_PROCESS_ENABLED virtual bool AddDeathRecipient(int32_t handle, void *cookie) = 0; diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 6ff1381b..70151ec8 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -755,7 +755,7 @@ int32_t BinderInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) return ERR_NONE; } -int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) +int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) { if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { return IPC_INVOKER_CONNECT_ERR; @@ -768,7 +768,7 @@ int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreezen) ZLOGE(LABEL, "error:%{public}d", error); return error; } - isFreezen = !info.has_unfrozen; + isFrozen = !info.has_unfrozen; return ERR_NONE; } #endif // FREEZE_PROCESS_ENABLED diff --git a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp index 35558665..f5782f3a 100644 --- a/ipc/native/test/unittest/common/binder_invoker_unittest.cpp +++ b/ipc/native/test/unittest/common/binder_invoker_unittest.cpp @@ -845,8 +845,8 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest, TestSize.Level1) binderInvoker.binderConnector_ = BinderConnector::GetInstance(); EXPECT_EQ(binderInvoker.Freeze(getpid(), false, 1), ERR_NONE); - bool isFreezen = false; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreezen), ERR_NONE); + bool isFrozen = false; + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFrozen), ERR_NONE); } /** @@ -873,15 +873,15 @@ HWTEST_F(BinderInvokerUnitTest, FreezeProcessTest001, TestSize.Level1) */ HWTEST_F(BinderInvokerUnitTest, GetProcessFreezeInfoTest, TestSize.Level1) { - bool isFreezen = false; + bool isFrozen = false; BinderInvoker binderInvoker; binderInvoker.binderConnector_ = nullptr; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreezen), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFrozen), IPC_INVOKER_CONNECT_ERR); BinderConnector *binderConnector = BinderConnector::GetInstance(); binderConnector->driverFD_ = -1; binderInvoker.binderConnector_ = binderConnector; - EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFreezen), IPC_INVOKER_CONNECT_ERR); + EXPECT_EQ(binderInvoker.GetProcessFreezeInfo(1, isFrozen), IPC_INVOKER_CONNECT_ERR); } #endif // FREEZE_PROCESS_ENABLED } // namespace OHOS \ No newline at end of file diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index 4bc8e04f..c73734a8 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -948,8 +948,8 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(testing::_, testing::_)) .WillRepeatedly(testing::Return(ERR_NONE)); - bool isFreezen = false; - ASSERT_EQ(IPCSkeleton::GetProcessFreezeInfo(0, isFreezen), ERR_NONE); + bool isFrozen = false; + ASSERT_EQ(IPCSkeleton::GetProcessFreezeInfo(0, isFrozen), ERR_NONE); current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = nullptr; delete binderInvoker; } diff --git a/ipc/native/test/unittest/common/mock_iremote_invoker.h b/ipc/native/test/unittest/common/mock_iremote_invoker.h index 19911f4c..fd4007df 100644 --- a/ipc/native/test/unittest/common/mock_iremote_invoker.h +++ b/ipc/native/test/unittest/common/mock_iremote_invoker.h @@ -43,7 +43,7 @@ public: MessageParcel &reply, MessageOption &option)); #ifdef FREEZE_PROCESS_ENABLED MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); - MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreezen)); + MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFrozen)); #endif // FREEZE_PROCESS_ENABLED MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index 0e028c0a..a2e679c0 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -125,10 +125,10 @@ int TestServiceProxy::TestFreezeProcess() return res; } - bool isFreezen = false; - res = IPCSkeleton::GetProcessFreezeInfo(pid, isFreezen); - if (res != ERR_NONE || !isFreezen) { - ZLOGI(LABEL, "GetProcessFreezeInfo failed, error code = %{public}d isFreezen = %{public}d ", res, isFreezen); + bool isFrozen = false; + res = IPCSkeleton::GetProcessFreezeInfo(pid, isFrozen); + if (res != ERR_NONE || !isFrozen) { + ZLOGI(LABEL, "GetProcessFreezeInfo failed, error code = %{public}d isFrozen = %{public}d ", res, isFrozen); return -1; } diff --git a/test/unittest/mock/mock_iremote_invoker.h b/test/unittest/mock/mock_iremote_invoker.h index 7a8e1401..49ae4603 100644 --- a/test/unittest/mock/mock_iremote_invoker.h +++ b/test/unittest/mock/mock_iremote_invoker.h @@ -43,7 +43,7 @@ public: MessageParcel &reply, MessageOption &option)); #ifdef FREEZE_PROCESS_ENABLED MOCK_METHOD3(Freeze, int32_t(uint32_t pid, bool freeze, uint32_t timeout)); - MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFreezen)); + MOCK_METHOD2(GetProcessFreezeInfo, int32_t(uint32_t pid, bool &isFrozen)); #endif // FREEZE_PROCESS_ENABLED MOCK_METHOD2(AddDeathRecipient, bool(int32_t handle, void *cookie)); MOCK_METHOD2(RemoveDeathRecipient, bool(int32_t handle, void *cookie)); -- Gitee From f1c1d242a94426c91d6ba313d51a0ef0181f6f2b Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Mon, 8 Sep 2025 19:44:30 +0800 Subject: [PATCH 17/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp index c73734a8..d7c8a62f 100644 --- a/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp +++ b/ipc/native/test/unittest/common/ipc_skeleton_unittest.cpp @@ -923,7 +923,7 @@ HWTEST_F(IPCSkeletonTest, FreezeProcessTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - EXPECT_CALL(*binderInvoker, Freeze(testing::_, testing::_, testing::_)) + EXPECT_CALL(*binderInvoker, Freeze(_, _, _)) .WillRepeatedly(testing::Return(ERR_NONE)); ASSERT_EQ(IPCSkeleton::Freeze(0, true, 0), ERR_NONE); @@ -945,7 +945,7 @@ HWTEST_F(IPCSkeletonTest, CheckFreezeTest, TestSize.Level1) current->invokers_[IRemoteObject::IF_PROT_DEFAULT] = binderInvoker; - EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(testing::_, testing::_)) + EXPECT_CALL(*binderInvoker, GetProcessFreezeInfo(_, _)) .WillRepeatedly(testing::Return(ERR_NONE)); bool isFrozen = false; -- Gitee From 4ca079172d0e0ece73c74b9c3aca8a533af1e5b8 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Mon, 8 Sep 2025 19:48:41 +0800 Subject: [PATCH 18/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- ipc/test/auxiliary/native/include/test_service_base.h | 1 - ipc/test/auxiliary/native/src/test_service_proxy.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ipc/test/auxiliary/native/include/test_service_base.h b/ipc/test/auxiliary/native/include/test_service_base.h index 8cf748e5..591712f8 100644 --- a/ipc/test/auxiliary/native/include/test_service_base.h +++ b/ipc/test/auxiliary/native/include/test_service_base.h @@ -57,7 +57,6 @@ public: TRANS_ID_QUERY_REMOTE_PROXY_OBJECT = 25, TRANS_ID_QUERY_THREAD_INVOCATION_STATE = 26, TRANS_ID_TEST_FREEZE_PROCESS = 27, - TRANS_ID_TEST_TXN_ASYNC_TRANS = 28, }; public: virtual int TestSyncTransaction(int value, int &reply, int delayTime = 0) = 0; diff --git a/ipc/test/auxiliary/native/src/test_service_proxy.cpp b/ipc/test/auxiliary/native/src/test_service_proxy.cpp index a2e679c0..ce0036b3 100644 --- a/ipc/test/auxiliary/native/src/test_service_proxy.cpp +++ b/ipc/test/auxiliary/native/src/test_service_proxy.cpp @@ -140,8 +140,8 @@ int TestServiceProxy::TestFreezeProcess() res = IPCSkeleton::Freeze(pid, false, timeout); if (res != ERR_NONE) { - ZLOGI(LABEL, "Freeze failed, error code = %{public}d", res); - return res; + ZLOGI(LABEL, "Unfreeze failed, error code = %{public}d", res); + return -1; } ret = remote->SendRequest(TRANS_ID_TEST_FREEZE_PROCESS, dataParcel, replyParcel, option); -- Gitee From 0db121eb9ff60808857a4ba59021342e6e2af4e5 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Wed, 10 Sep 2025 09:28:36 +0800 Subject: [PATCH 19/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- bundle.json | 2 +- config.gni | 2 +- interfaces/innerkits/ipc_single/BUILD.gn | 4 ++-- .../core/dbinder/include/dbinder_base_invoker_interface.h | 2 +- ipc/native/test/unittest/common/BUILD.gn | 2 +- ipc/test/auxiliary/native/BUILD.gn | 6 +++--- test/unittest/ipc/native/src/core/source/BUILD.gn | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bundle.json b/bundle.json index 981e1b1f..33457e07 100644 --- a/bundle.json +++ b/bundle.json @@ -24,7 +24,7 @@ "ipc_feature_rpc_enabled", "ipc_feature_test_enabled", "ipc_feature_trace_enabled", - "ipc_freeze_process_enabled" + "ipc_feature_freeze_enabled" ], "syscap":[ "SystemCapability.Communication.IPC.Core" diff --git a/config.gni b/config.gni index bf23e32e..d154289a 100644 --- a/config.gni +++ b/config.gni @@ -23,7 +23,7 @@ declare_args() { hiviewdfx_backtrace_support = false hiviewdfx_hisysevent_support = false ipc_proxy_dfx_backtrace_enabled = false - ipc_freeze_process_enabled = false + ipc_feature_freeze_enabled = false } if (defined(global_parts_info) && diff --git a/interfaces/innerkits/ipc_single/BUILD.gn b/interfaces/innerkits/ipc_single/BUILD.gn index faebf370..b81c1be8 100644 --- a/interfaces/innerkits/ipc_single/BUILD.gn +++ b/interfaces/innerkits/ipc_single/BUILD.gn @@ -122,7 +122,7 @@ ohos_shared_library("ipc_single") { if (hiviewdfx_hisysevent_support) { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines += [ "FREEZE_PROCESS_ENABLED" ] } innerapi_tags = [ @@ -167,7 +167,7 @@ ohos_shared_library("ipc_single_test") { if (hiviewdfx_hisysevent_support) { defines += [ "HIVIEWDFX_HISYSEVENT_SUPPORT" ] } - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines += [ "FREEZE_PROCESS_ENABLED" ] } innerapi_tags = [ diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index e296e2a9..59e9aecc 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -196,7 +196,7 @@ int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeou } template -int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) +int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) { return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; } diff --git a/ipc/native/test/unittest/common/BUILD.gn b/ipc/native/test/unittest/common/BUILD.gn index 9e714b8b..97ca7ff1 100644 --- a/ipc/native/test/unittest/common/BUILD.gn +++ b/ipc/native/test/unittest/common/BUILD.gn @@ -62,7 +62,7 @@ template("ipc_unittest") { "samgr:samgr_proxy", ] - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines = ["FREEZE_PROCESS_ENABLED"] } diff --git a/ipc/test/auxiliary/native/BUILD.gn b/ipc/test/auxiliary/native/BUILD.gn index 22933ef5..356d8f40 100644 --- a/ipc/test/auxiliary/native/BUILD.gn +++ b/ipc/test/auxiliary/native/BUILD.gn @@ -32,7 +32,7 @@ ohos_shared_library("ipc_test_helper") { "./src/test_service_stub.cpp", ] - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines = [ "FREEZE_PROCESS_ENABLED" ] } @@ -95,7 +95,7 @@ ohos_executable("ipc_client_test") { "$SUBSYSTEM_DIR/interfaces/innerkits/c_api:ipc_capi", ] - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines = [ "FREEZE_PROCESS_ENABLED" ] } @@ -134,7 +134,7 @@ ohos_shared_library("ipc_test_helper_extra") { "$SUBSYSTEM_DIR/config:ipc_util_config", ] - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines = [ "FREEZE_PROCESS_ENABLED" ] } diff --git a/test/unittest/ipc/native/src/core/source/BUILD.gn b/test/unittest/ipc/native/src/core/source/BUILD.gn index a66535e3..b0a93d82 100644 --- a/test/unittest/ipc/native/src/core/source/BUILD.gn +++ b/test/unittest/ipc/native/src/core/source/BUILD.gn @@ -64,7 +64,7 @@ template("ipc_unittest") { "samgr:samgr_proxy", ] - if (ipc_freeze_process_enabled) { + if (ipc_feature_freeze_enabled) { defines += [ "FREEZE_PROCESS_ENABLED" ] } -- Gitee From 88dd7511ce74bf08af198b0eae1cda7a5777e3c8 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Wed, 10 Sep 2025 16:27:21 +0800 Subject: [PATCH 20/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- ipc/native/src/core/framework/include/sys_binder.h | 4 ++-- ipc/native/src/core/invoker/source/binder_invoker.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ipc/native/src/core/framework/include/sys_binder.h b/ipc/native/src/core/framework/include/sys_binder.h index 54dd232d..9df23917 100644 --- a/ipc/native/src/core/framework/include/sys_binder.h +++ b/ipc/native/src/core/framework/include/sys_binder.h @@ -69,7 +69,7 @@ struct binder_freeze_info { __u32 timeout_ms; }; -struct binder_frozen_state_info { +struct binder_freeze_state_info { __u32 pid; bool has_unfrozen; }; @@ -173,7 +173,7 @@ struct binder_sender_info { #define BINDER_GET_NODE_INFO_FOR_REF _IOWR('b', 12, struct binder_node_info_for_ref) #define BINDER_SET_CONTEXT_MGR_EXT _IOW('b', 13, struct flat_binder_object) #define BINDER_FREEZE _IOW('b', 14, struct binder_freeze_info) -#define BINDER_GET_FROZEN_STATE _IOW('b', 15, struct binder_frozen_state_info) +#define BINDER_GET_FROZEN_STATE _IOW('b', 15, struct binder_freeze_state_info) #define BINDER_FEATURE_SET _IOWR('b', 30, struct binder_feature_set) #define BINDER_GET_ACCESS_TOKEN _IOWR('b', 31, struct access_token) #define BINDER_GET_SENDER_INFO _IOWR('b', 32, struct binder_sender_info) diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 70151ec8..8cfc480f 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -760,7 +760,7 @@ int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { return IPC_INVOKER_CONNECT_ERR; } - binder_frozen_state_info info; + binder_freeze_state_info info; info.pid = pid; info.has_unfrozen = false; int error = binderConnector_->WriteBinder(BINDER_GET_FROZEN_STATE, &info); -- Gitee From d0fde350ffcdbda52d10286586e4cd60b61658d5 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Thu, 11 Sep 2025 10:34:25 +0800 Subject: [PATCH 21/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- .../src/core/invoker/include/binder_invoker.h | 4 ++++ .../core/invoker/source/binder_invoker.cpp | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ipc/native/src/core/invoker/include/binder_invoker.h b/ipc/native/src/core/invoker/include/binder_invoker.h index 08df160f..c4ad9cfb 100644 --- a/ipc/native/src/core/invoker/include/binder_invoker.h +++ b/ipc/native/src/core/invoker/include/binder_invoker.h @@ -206,6 +206,10 @@ private: void OnTransactionComplete(MessageParcel *reply, bool &continueLoop, int32_t &error, uint32_t cmd); +#ifdef FREEZE_PROCESS_ENABLED + void OnTransactionPendingFrozen(MessageParcel *reply, bool &continueLoop, int32_t &error, uint32_t cmd); +#endif // FREEZE_PROCESS_ENABLED + void OnDeadOrFailedReply(MessageParcel *reply, bool &continueLoop, int32_t &error, uint32_t cmd); void OnReply(MessageParcel *reply, bool &continueLoop, int32_t &error, uint32_t cmd); diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 8cfc480f..57de7f22 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -1220,6 +1220,19 @@ void BinderInvoker::OnTransactionComplete(MessageParcel *reply, bool &continueLo continueLoop = false; } } + +#ifdef FREEZE_PROCESS_ENABLED +void BinderInvoker::OnTransactionPendingFrozen(MessageParcel *reply, bool &continueLoop, int32_t &error, uint32_t cmd) +{ + (void)error; + (void)cmd; + + if (reply == nullptr) { + continueLoop = false; + } +} +#endif // FREEZE_PROCESS_ENABLED + #ifndef __linux__ bool BinderInvoker::GetDetailedErrorInfo(uint32_t &errorCode, std::string &errDesc) { @@ -1266,11 +1279,13 @@ void BinderInvoker::DealWithCmd(MessageParcel *reply, bool &continueLoop, int32_ { switch (cmd) { case BR_TRANSACTION_COMPLETE: + OnTransactionComplete(reply, continueLoop, error, cmd); + break; #ifdef FREEZE_PROCESS_ENABLED case BR_TRANSACTION_PENDING_FROZEN: -#endif // FREEZE_PROCESS_ENABLED - OnTransactionComplete(reply, continueLoop, error, cmd); + OnTransactionPendingFrozen(reply, continueLoop, error, cmd); break; +#endif // FREEZE_PROCESS_ENABLED case BR_DEAD_REPLY: case BR_FAILED_REPLY: #ifdef FREEZE_PROCESS_ENABLED -- Gitee From b6a258c9ab5b763096d57a0c07b231c1ec8a726c Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Thu, 11 Sep 2025 20:52:54 +0800 Subject: [PATCH 22/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_skeleton.h | 4 ++-- ipc/native/src/core/framework/include/sys_binder.h | 7 ++++--- ipc/native/src/core/invoker/source/binder_invoker.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h index 379da143..010e919d 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_skeleton.h +++ b/interfaces/innerkits/ipc_core/include/ipc_skeleton.h @@ -210,7 +210,7 @@ public: #ifdef FREEZE_PROCESS_ENABLED /** - * @brief Freeze or unfreeze a process. + * @brief Freeze binder transaction of the specific process. * @param pid Process ID to freeze or unfreeze. * @param freeze True to freeze the process, false to unfreeze it. * @param timeout Timeout value in milliseconds to wait for the stub to finish processing requests before freezing. @@ -222,7 +222,7 @@ public: static int32_t Freeze(uint32_t pid, bool freeze, uint32_t timeout); /** - * @brief Get the freeze status of a specified process. + * @brief Get binder transaction freeze status of the specific process. * @param pid Process ID to check. * @param isFrozen Reference to a boolean variable that will store the freeze status of the process. * True if the process is frozen, false otherwise. diff --git a/ipc/native/src/core/framework/include/sys_binder.h b/ipc/native/src/core/framework/include/sys_binder.h index 9df23917..9e9f2bb8 100644 --- a/ipc/native/src/core/framework/include/sys_binder.h +++ b/ipc/native/src/core/framework/include/sys_binder.h @@ -69,9 +69,10 @@ struct binder_freeze_info { __u32 timeout_ms; }; -struct binder_freeze_state_info { +struct binder_proc_frozen_state { __u32 pid; - bool has_unfrozen; + // false: process is fully frozen, true: process is not fully frozen + bool has_not_frozen; }; #ifndef __linux__ @@ -173,7 +174,7 @@ struct binder_sender_info { #define BINDER_GET_NODE_INFO_FOR_REF _IOWR('b', 12, struct binder_node_info_for_ref) #define BINDER_SET_CONTEXT_MGR_EXT _IOW('b', 13, struct flat_binder_object) #define BINDER_FREEZE _IOW('b', 14, struct binder_freeze_info) -#define BINDER_GET_FROZEN_STATE _IOW('b', 15, struct binder_freeze_state_info) +#define BINDER_GET_FROZEN_STATE _IOW('b', 15, struct binder_proc_frozen_state) #define BINDER_FEATURE_SET _IOWR('b', 30, struct binder_feature_set) #define BINDER_GET_ACCESS_TOKEN _IOWR('b', 31, struct access_token) #define BINDER_GET_SENDER_INFO _IOWR('b', 32, struct binder_sender_info) diff --git a/ipc/native/src/core/invoker/source/binder_invoker.cpp b/ipc/native/src/core/invoker/source/binder_invoker.cpp index 57de7f22..6f7e1cd6 100644 --- a/ipc/native/src/core/invoker/source/binder_invoker.cpp +++ b/ipc/native/src/core/invoker/source/binder_invoker.cpp @@ -760,15 +760,15 @@ int32_t BinderInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFrozen) if ((binderConnector_ == nullptr) || (!binderConnector_->IsDriverAlive())) { return IPC_INVOKER_CONNECT_ERR; } - binder_freeze_state_info info; + binder_proc_frozen_state info; info.pid = pid; - info.has_unfrozen = false; + info.has_not_frozen = false; int error = binderConnector_->WriteBinder(BINDER_GET_FROZEN_STATE, &info); if (error != ERR_NONE) { ZLOGE(LABEL, "error:%{public}d", error); return error; } - isFrozen = !info.has_unfrozen; + isFrozen = !info.has_not_frozen; return ERR_NONE; } #endif // FREEZE_PROCESS_ENABLED -- Gitee From e5684357295c3c4eb912941fcf83e40635019636 Mon Sep 17 00:00:00 2001 From: dengliang <15934868816@139.com> Date: Thu, 11 Sep 2025 21:15:02 +0800 Subject: [PATCH 23/23] binder freeze process Signed-off-by: dengliang <15934868816@139.com> --- interfaces/innerkits/ipc_core/include/ipc_types.h | 1 - .../src/core/dbinder/include/dbinder_base_invoker_interface.h | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interfaces/innerkits/ipc_core/include/ipc_types.h b/interfaces/innerkits/ipc_core/include/ipc_types.h index facfceba..540aac3b 100644 --- a/interfaces/innerkits/ipc_core/include/ipc_types.h +++ b/interfaces/innerkits/ipc_core/include/ipc_types.h @@ -138,7 +138,6 @@ enum { RPC_BASE_INVOKER_TRANSLATE_ERR, RPC_BASE_INVOKER_STUBINDEX_ERR, RPC_BASE_INVOKER_MALLOC_ERR, - RPC_BASE_INVOKER_NOT_SUPPORT_ERR, RPC_DATABUS_INVOKER_ERR = 600, RPC_DATABUS_INVOKER_INVALID_DATA_ERR, RPC_DATABUS_INVOKER_CLOSED_PEER_ERR, diff --git a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h index 59e9aecc..e643cb64 100644 --- a/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h +++ b/ipc/native/src/core/dbinder/include/dbinder_base_invoker_interface.h @@ -192,13 +192,13 @@ template void DBinderBaseInvoker::FreeBuffer(void *data) template int32_t DBinderBaseInvoker::Freeze(uint32_t pid, bool freeze, uint32_t timeout) { - return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; + return ERR_NONE; } template int32_t DBinderBaseInvoker::GetProcessFreezeInfo(uint32_t pid, bool &isFreeze) { - return RPC_BASE_INVOKER_NOT_SUPPORT_ERR; + return ERR_NONE; } #endif // FREEZE_PROCESS_ENABLED -- Gitee