devicedebug代码差异同步

Signed-off-by: 王达 <wangda20@huawei.com>
This commit is contained in:
王达 2024-11-06 10:18:12 +08:00
parent 61386951b5
commit df39049e19
4 changed files with 40 additions and 31 deletions

View File

@ -43,6 +43,7 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO
{
cJSON *root = cJSON_CreateObject();
if (root == NULL) {
cJSON_Delete(args);
DEVICEDEBUG_LOGE("devicedebug json write create root object unsuccess");
return NULL;
}
@ -58,20 +59,6 @@ APPSPAWN_STATIC char* DeviceDebugJsonStringGeneral(int pid, const char *op, cJSO
APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal)
{
AppSpawnClientHandle clientHandle;
int ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
if (ret != 0) {
DEVICEDEBUG_LOGE("devicedebug appspawn client init unsuccess, ret=%{public}d", ret);
return ret;
}
AppSpawnReqMsgHandle reqHandle;
ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle);
if (ret != 0) {
DEVICEDEBUG_LOGE("devicedebug appspawn message create unsuccess, ret=%{public}d", ret);
return ret;
}
cJSON *args = cJSON_CreateObject();
if (args == NULL) {
DEVICEDEBUG_LOGE("devicedebug json write create args object unsuccess");
@ -80,20 +67,39 @@ APPSPAWN_STATIC int DeviceDebugKill(int pid, int signal)
cJSON_AddNumberToObject(args, "signal", signal);
char *jsonString = DeviceDebugJsonStringGeneral(pid, "kill", args);
if (jsonString == NULL) {
cJSON_Delete(args);
return DEVICEDEBUG_ERRNO_JSON_CREATED_FAILED;
}
AppSpawnReqMsgHandle reqHandle;
int ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle);
if (ret != 0) {
free(jsonString);
DEVICEDEBUG_LOGE("devicedebug appspawn message create unsuccess, ret=%{public}d", ret);
return ret;
}
ret = AppSpawnReqMsgAddExtInfo(reqHandle, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1);
if (ret != 0) {
DEVICEDEBUG_LOGE("devicedebug appspawn message add devicedebug[%{public}s] unsuccess, ret=%{public}d",
jsonString, ret);
free(jsonString);
AppSpawnReqMsgFree(reqHandle);
return ret;
}
AppSpawnClientHandle clientHandle;
ret = AppSpawnClientInit(APPSPAWN_SERVER_NAME, &clientHandle);
if (ret != 0) {
free(jsonString);
AppSpawnReqMsgFree(reqHandle);
DEVICEDEBUG_LOGE("devicedebug appspawn client init unsuccess, ret=%{public}d", ret);
return ret;
}
AppSpawnResult result = {0};
ret = AppSpawnClientSendMsg(clientHandle, reqHandle, &result);
AppSpawnClientDestroy(clientHandle);
free(jsonString);
if (ret != 0) {
DEVICEDEBUG_LOGE("devicedebug appspawn send msg unsuccess, ret=%{public}d", ret);
return ret;

View File

@ -458,7 +458,6 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
APPSPAWN_CHECK(ret == 0, LE_CloseStreamTask(LE_GetDefaultLoop(), taskHandle);
return, "Failed to create time for connection");
}
return;
}
static char *GetMapMem(uint32_t clientId, const char *processName, uint32_t size, bool readOnly, bool isNweb)
@ -928,7 +927,7 @@ static void WaitChildTimeout(const TimerHandle taskHandle, void *context)
DeleteAppSpawningCtx(property);
}
static int ProcessChildFdCheck(int fd, AppSpawningCtx *property, int *pResult)
static int ProcessChildFdCheck(int fd, AppSpawningCtx *property)
{
int result = 0;
(void)read(fd, &result, sizeof(result));
@ -941,7 +940,6 @@ static int ProcessChildFdCheck(int fd, AppSpawningCtx *property, int *pResult)
DeleteAppSpawningCtx(property);
return -1;
}
*pResult = result;
return 0;
}
@ -952,13 +950,12 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_
property->forkCtx.watcherHandle = NULL; // delete watcher
LE_RemoveWatcher(LE_GetDefaultLoop(), (WatcherHandle)taskHandle);
int result = 0;
if (ProcessChildFdCheck(fd, property, &result) != 0) {
if (ProcessChildFdCheck(fd, property) != 0) {
return;
}
// success
bool isDebuggable = CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE) == 1 ? true : false;
bool isDebuggable = CheckAppMsgFlagsSet(property, APP_FLAGS_DEBUGGABLE);
AppSpawnedProcess *appInfo = AddSpawnedProcess(property->pid, GetBundleName(property), isDebuggable);
if (appInfo) {
AppSpawnMsgDacInfo *dacInfo = GetAppProperty(property, TLV_DAC_INFO);
@ -977,7 +974,7 @@ static void ProcessChildResponse(const WatcherHandle taskHandle, int fd, uint32_
ProcessMgrHookExecute(STAGE_SERVER_APP_ADD, GetAppSpawnContent(), appInfo);
// response
AppSpawnHookExecute(STAGE_PARENT_PRE_RELY, 0, GetAppSpawnContent(), &property->client);
SendResponse(property->message->connection, &property->message->msgHeader, result, property->pid);
SendResponse(property->message->connection, &property->message->msgHeader, 0, property->pid);
AppSpawnHookExecute(STAGE_PARENT_POST_RELY, 0, GetAppSpawnContent(), &property->client);
#ifdef DEBUG_BEGETCTL_BOOT
if (IsDeveloperModeOpen()) {
@ -1538,22 +1535,27 @@ APPSPAWN_STATIC int ProcessAppSpawnDeviceDebugMsg(AppSpawnMsgNode *message)
cJSON *app = cJSON_GetObjectItem(json, "app");
if (!cJSON_IsNumber(app)) {
APPSPAWN_LOGE("appspawn devicedebug json get app fail");
cJSON_Delete(json);
return -1;
}
cJSON *op = cJSON_GetObjectItem(json, "op");
if (!cJSON_IsString(op) || op->valuestring == NULL) {
APPSPAWN_LOGE("appspawn devicedebug json get op fail");
cJSON_Delete(json);
return -1;
}
cJSON *args = cJSON_GetObjectItem(json, "args");
if (!cJSON_IsObject(args)) {
APPSPAWN_LOGE("appspawn devicedebug json get args fail");
cJSON_Delete(json);
return -1;
}
return AppspawnDevicedebugDeal(op->valuestring, app->valueint, args);
int result = AppspawnDevicedebugDeal(op->valuestring, app->valueint, args);
cJSON_Delete(json);
return result;
}
static void ProcessRecvMsg(AppSpawnConnection *connection, AppSpawnMsgNode *message)

View File

@ -567,20 +567,20 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_009, TestSize.Level0)
APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret);
AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName());
EXPECT_NE(app, nullptr);
ASSERT_NE(app, nullptr);
AppSpawnReqMsgHandle reqHandle2;
ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2);
EXPECT_GT(sprintf_s(pid, 16, "%d", app->pid), 0);
ASSERT_GT(sprintf_s(pid, 16, "%d", app->pid), 0);
AppSpawnReqMsgAddStringInfo(reqHandle2, "signal", "-9");
AppSpawnReqMsgAddStringInfo(reqHandle2, "pid", pid);
ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result);
AppSpawnClientDestroy(clientHandle);
APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d",
ret, result.result);
ASSERT_EQ(kill(app->pid, SIGKILL), 0);
} while (0);
AppSpawnClientDestroy(clientHandle);
ASSERT_EQ(ret, 0);
ASSERT_EQ(result.result, -1);
}
@ -604,15 +604,15 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0)
APPSPAWN_CHECK(ret == 0, break, "Failed to send msg %{public}d", ret);
AppSpawnedProcess *app = GetSpawnedProcessByName(testServer->GetDefaultTestAppBundleName());
EXPECT_NE(app, nullptr);
ASSERT_NE(app, nullptr);
AppSpawnReqMsgHandle reqHandle2;
ret = AppSpawnReqMsgCreate(MSG_DEVICE_DEBUG, "devicedebug", &reqHandle2);
cJSON *args = cJSON_CreateObject();
EXPECT_NE(args, nullptr);
ASSERT_NE(args, nullptr);
cJSON_AddNumberToObject(args, "signal", 9);
cJSON *root = cJSON_CreateObject();
EXPECT_NE(root, nullptr);
ASSERT_NE(root, nullptr);
cJSON_AddNumberToObject(root, "app", app->pid);
cJSON_AddStringToObject(root, "op", "kill");
cJSON_AddItemToObject(root, "args", args);
@ -621,11 +621,12 @@ HWTEST_F(AppSpawnServiceTest, App_Spawn_Msg_010, TestSize.Level0)
ret = AppSpawnReqMsgAddExtInfo(reqHandle2, "devicedebug", (uint8_t *)jsonString, strlen(jsonString) + 1);
ASSERT_EQ(ret, 0);
ret = AppSpawnClientSendMsg(clientHandle, reqHandle2, &result);
AppSpawnClientDestroy(clientHandle);
free(jsonString);
APPSPAWN_CHECK(ret == 0 && result.result == 0, break, "Failed to send msg ret:%{public}d, result:%{public}d",
ret, result.result);
} while (0);
AppSpawnClientDestroy(clientHandle);
ASSERT_EQ(ret, 0);
ASSERT_EQ(result.result, 0);
}

View File

@ -1,4 +1,4 @@
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Copyright (c) 2024 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at