diff --git a/interfaces/innerkits/include/appspawn.h b/interfaces/innerkits/include/appspawn.h index 93252cb2f715f1f7ef35398da4de84f9c25eb965..097e28297e65a600434d66828a9847fdde719b29 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; @@ -275,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" #define MSG_EXT_NAME_JIT_PERMISSIONS "JITPermissions" int AppSpawnReqMsgAddExtInfo(AppSpawnReqMsgHandle reqHandle, const char *name, const uint8_t *value, uint32_t valueLen); diff --git a/modules/module_engine/include/appspawn_hook.h b/modules/module_engine/include/appspawn_hook.h index 9201cce438400dcc176f9eff470a64e8d12cda25..440d81ca57fdd0e2a263566c095b177c0b4debc7 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 b5fa4983a4479e0c8de75986709fa9ea709b2076..6e59a236d84b8a129ae1591b9a19a8d456db9e1c 100644 --- a/standard/appspawn_service.c +++ b/standard/appspawn_service.c @@ -1419,6 +1419,23 @@ static void ProcessSpawnRestartMsg(AppSpawnConnection *connection, AppSpawnMsgNo APPSPAWN_LOGE("Failed to execv, ret %{public}d, errno %{public}d", ret, errno); } +APPSPAWN_STATIC void ProcessUninstallDebugHap(AppSpawnConnection *connection, AppSpawnMsgNode *message) +{ + APPSPAWN_LOGI("ProcessUninstallDebugHap start"); + AppSpawningCtx *property = CreateAppSpawningCtx(); + if (property == NULL) { + SendResponse(connection, &message->msgHeader, APPSPAWN_SYSTEM_ERROR, 0); + DeleteAppSpawnMsg(message); + return; + } + + property->message = message; + property->message->connection = connection; + 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) { AppSpawnMsg *msg = &message->msgHeader; @@ -1463,6 +1480,9 @@ static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *mess case MSG_RESTART_SPAWNER: ProcessSpawnRestartMsg(connection, message); break; + case MSG_UNINSTALL_DEBUG_HAP: + ProcessUninstallDebugHap(connection, message); + break; default: SendResponse(connection, msg, APPSPAWN_MSG_INVALID, 0); DeleteAppSpawnMsg(message); diff --git a/test/moduletest/appspawn_client_test.cpp b/test/moduletest/appspawn_client_test.cpp index eedc2050a19e67299b205f2feb85c7dd7f31efda..3272b03d0322ce0c3d18e8b0bbb21c5cdf3687fa 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