From c5e13dfe40c79cada5ea386409f7948dc2a7d098 Mon Sep 17 00:00:00 2001 From: yh Date: Fri, 15 Nov 2024 10:21:24 +0800 Subject: [PATCH 1/2] debug hap Signed-off-by: yh Change-Id: I748d1b65cb867616962c58e12915a6d006b42eef --- interfaces/innerkits/include/appspawn.h | 1 + modules/module_engine/include/appspawn_hook.h | 2 +- standard/appspawn_service.c | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 8f67c151..6c89b350 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -106,6 +106,7 @@ typedef enum { MSG_BEGET_SPAWNTIME, MSG_UPDATE_MOUNT_POINTS, MSG_RESTART_SPAWNER, + MSG_UNINSTALL_DEBUG_HAP, MAX_TYPE_INVALID } AppSpawnMsgType; diff --git a/modules/module_engine/include/appspawn_hook.h b/modules/module_engine/include/appspawn_hook.h index 9201cce4..440d81ca 100644 --- a/modules/module_engine/include/appspawn_hook.h +++ b/modules/module_engine/include/appspawn_hook.h @@ -64,7 +64,7 @@ typedef enum TagAppSpawnHookStage { STAGE_PARENT_POST_FORK = 21, STAGE_PARENT_PRE_RELY = 22, STAGE_PARENT_POST_RELY = 23, - + STAGE_PARENT_UNINSTALL, // run in child process STAGE_CHILD_PRE_COLDBOOT = 30, // clear env, set token before cold boot STAGE_CHILD_EXECUTE, diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 05aaed7c..2b73dc68 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1419,6 +1419,19 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo APPSPAWN_LOGE("Failed to execv, ret %{public}d, errno %{public}d", ret, errno); } +APPSPAWN_STATIC int ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) +{ + APPSPAWN_LOGI("ProcessUninstallDebugHap start"); + APPSPAWN_CHECK(connection != NULL && message != NULL, return APPSPAWN_ARG_INVALID, + "ProcessUninstallDebugHap invalid param"); + + AppSpawningCtx *property = CreateAppSpawningCtx(); + APPSPAWN_CHECK(property != NULL, return APPSPAWN_SYSTEM_ERROR, "create appspawn ctx failed"); + property->message = message; + property->message->connection = connection; + return AppSpawnHookExecute(STAGE_PARENT_UNINSTALL, 0, GetAppSpawnContent(), &property->client); +} + static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) { AppSpawnMsg *msg = &message->msgHeader; @@ -1463,6 +1476,11 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_RESTART_SPAWNER: ProcessSpawnRestartMsg(connection, message); break; + case MSG_UNINSTALL_DEBUG_HAP: + ret = ProcessUninstallDebugHap(connection, message); + SendResponse(connection, msg, ret, 0); + DeleteAppSpawnMsg(message); + break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); DeleteAppSpawnMsg(message); -- Gitee From d70ae4793cb862bb0eeceef7d604b3883a709640 Mon Sep 17 00:00:00 2001 From: yh Date: Tue, 26 Nov 2024 15:58:17 +0800 Subject: [PATCH 2/2] modify debug Signed-off-by: yh Change-Id: Ic6192b45d2b50191baa60ad23917082b909d6b74 --- interfaces/innerkits/include/appspawn.h | 1 + standard/appspawn_service.c | 20 ++++++------ test/moduletest/appspawn_client_test.cpp | 40 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 6c89b350..7ff70b1e 100644 --- a/interfaces/innerkits/include/appspawn.h +++ b/interfaces/innerkits/include/appspawn.h @@ -276,6 +276,7 @@ int AppSpawnClientAddPermission(AppSpawnClientHandle handle, AppSpawnReqMsgHandl #define MSG_EXT_NAME_PROCESS_TYPE "ProcessType" #define MSG_EXT_NAME_MAX_CHILD_PROCCESS_MAX "MaxChildProcess" #define MSG_EXT_NAME_APP_FD "AppFd" +#define MSG_EXT_NAME_USERID "uid" int AppSpawnReqMsgAddExtInfo(AppSpawnReqMsgHandle reqHandle, const char *name, const uint8_t *value, uint32_t valueLen); diff --git a/standard/appspawn_service.c b/standard/appspawn_service.c index 2b73dc68..d9b0ab80 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1419,17 +1419,21 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo APPSPAWN_LOGE("Failed to execv, ret %{public}d, errno %{public}d", ret, errno); } -APPSPAWN_STATIC int ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) +APPSPAWN_STATIC void ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) { APPSPAWN_LOGI("ProcessUninstallDebugHap start"); - APPSPAWN_CHECK(connection != NULL && message != NULL, return APPSPAWN_ARG_INVALID, - "ProcessUninstallDebugHap invalid param"); - AppSpawningCtx *property = CreateAppSpawningCtx(); - APPSPAWN_CHECK(property != NULL, return APPSPAWN_SYSTEM_ERROR, "create appspawn ctx failed"); + if (property == NULL) { + SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); + DeleteAppSpawnMsg(message); + return; + } + property->message = message; property->message->connection = connection; - return AppSpawnHookExecute(STAGE_PARENT_UNINSTALL, 0, GetAppSpawnContent(), &property->client); + int ret = AppSpawnHookExecute(STAGE_PARENT_UNINSTALL, 0, GetAppSpawnContent(), &property->client); + SendResponse(connection, &message->msgHeader, ret, 0); + DeleteAppSpawningCtx(property); } static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message) @@ -1477,9 +1481,7 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess ProcessSpawnRestartMsg(connection, message); break; case MSG_UNINSTALL_DEBUG_HAP: - ret = ProcessUninstallDebugHap(connection, message); - SendResponse(connection, msg, ret, 0); - DeleteAppSpawnMsg(message); + ProcessUninstallDebugHap(connection, message); break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); diff --git a/test/moduletest/appspawn_client_test.cpp b/test/moduletest/appspawn_client_test.cpp index eedc2050..3272b03d 100644 --- a/test/moduletest/appspawn_client_test.cpp +++ b/test/moduletest/appspawn_client_test.cpp @@ -120,5 +120,45 @@ HWTEST_F(AppSpawnClientTest, AppSpawn_Client_test002, TestSize.Level0) AppSpawnClientDestroy(clientHandle); } +HWTEST_F(AppSpawnClientTest, AppSpawn_Client_test003, TestSize.Level0) +{ + AppSpawnClientHandle clientHandle = CreateClient(APPSPAWN_SERVER_NAME); + ASSERT_EQ(clientHandle != NULL, 1); + + AppSpawnReqMsgHandle reqHandle = 0; + int ret = AppSpawnReqMsgCreate(MSG_UNINSTALL_DEBUG_HAP, "test.uninstall", &reqHandle); + ASSERT_EQ(ret, 0); + + ret = AppSpawnReqMsgSetBundleInfo(reqHandle, 100, "test.uninstall"); + ASSERT_EQ(ret, 0); + + AppSpawnResult result = {}; + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + if (ret == 0 && result.pid > 0) { + kill(result.pid, SIGKILL); + } + AppSpawnClientDestroy(clientHandle); +} + +HWTEST_F(AppSpawnClientTest, AppSpawn_Client_test004, TestSize.Level0) +{ + AppSpawnClientHandle clientHandle = CreateClient(APPSPAWN_SERVER_NAME); + ASSERT_EQ(clientHandle != NULL, 1); + + AppSpawnReqMsgHandle reqHandle = 0; + int ret = AppSpawnReqMsgCreate(MSG_UNINSTALL_DEBUG_HAP, "test.uninstall", &reqHandle); + ASSERT_EQ(ret, 0); + + ret = AppSpawnReqMsgAddStringInfo(reqHandle, MSG_EXT_NAME_USERID, "100"); + ASSERT_EQ(ret, 0); + + AppSpawnResult result = {}; + ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result); + if (ret == 0 && result.pid > 0) { + kill(result.pid, SIGKILL); + } + AppSpawnClientDestroy(clientHandle); +} + } // namespace AppSpawn } // namespace OHOS -- Gitee