1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "appspawn_hook.h" 17#include "appspawn_manager.h" 18#include "appspawn_utils.h" 19 20static int TestPluginReportProcessExit(const AppSpawnMgr *content, const AppSpawnedProcess *appInfo) 21{ 22 APPSPAWN_LOGI("Process %{public}s exit", appInfo->name); 23 return 0; 24} 25 26static int TestPluginReportProcessAdd(const AppSpawnMgr *content, const AppSpawnedProcess *appInfo) 27{ 28 APPSPAWN_LOGI("Process %{public}s add", appInfo->name); 29 return 0; 30} 31 32static int TestPluginPreload(AppSpawnMgr *content) 33{ 34 APPSPAWN_LOGI("TestPlugin preload"); 35 return 0; 36} 37 38static int TestPluginExit(AppSpawnMgr *content) 39{ 40 APPSPAWN_LOGI("TestPlugin exit"); 41 return 0; 42} 43 44 45static int TestPluginPreFork(AppSpawnMgr *content, AppSpawningCtx *property) 46{ 47 APPSPAWN_LOGI("TestPlugin pre fork for %{public}s ", GetProcessName(property)); 48 return 0; 49} 50 51static int TestPluginPreReply(AppSpawnMgr *content, AppSpawningCtx *property) 52{ 53 APPSPAWN_LOGI("TestPlugin pre reply to client for %{public}s ", GetProcessName(property)); 54 return 0; 55} 56 57static int TestPluginPostReply(AppSpawnMgr *content, AppSpawningCtx *property) 58{ 59 APPSPAWN_LOGI("TestPlugin post reply to client for %{public}s ", GetProcessName(property)); 60 return 0; 61} 62 63static int ChildPreColdBoot(AppSpawnMgr *content, AppSpawningCtx *property) 64{ 65 APPSPAWN_LOGI("TestPlugin pre cold boot for %{public}s ", GetProcessName(property)); 66 return 0; 67} 68static int ChildExecute(AppSpawnMgr *content, AppSpawningCtx *property) 69{ 70 APPSPAWN_LOGI("TestPlugin set app property for %{public}s ", GetProcessName(property)); 71 return 0; 72} 73static int ChildPreRely(AppSpawnMgr *content, AppSpawningCtx *property) 74{ 75 APPSPAWN_LOGI("TestPlugin pre reply to parent for %{public}s ", GetProcessName(property)); 76 return 0; 77} 78static int ChildPostRely(AppSpawnMgr *content, AppSpawningCtx *property) 79{ 80 APPSPAWN_LOGI("TestPlugin post reply to parent for %{public}s ", GetProcessName(property)); 81 return 0; 82} 83static int ChildPreRun(AppSpawnMgr *content, AppSpawningCtx *property) 84{ 85 APPSPAWN_LOGI("TestPlugin pre child run for %{public}s ", GetProcessName(property)); 86 return 0; 87} 88 89MODULE_CONSTRUCTOR(void) 90{ 91 APPSPAWN_LOGI("Load test plugin module ..."); 92 AddProcessMgrHook(STAGE_SERVER_APP_DIED, 0, TestPluginReportProcessExit); 93 AddProcessMgrHook(STAGE_SERVER_APP_ADD, 0, TestPluginReportProcessAdd); 94 AddServerStageHook(STAGE_SERVER_EXIT, 0, TestPluginExit); 95 AddPreloadHook(HOOK_PRIO_LOWEST - 1, TestPluginPreload); 96 AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_COMMON - 1, TestPluginPreFork); 97 AddAppSpawnHook(STAGE_PARENT_POST_RELY, HOOK_PRIO_COMMON - 1, TestPluginPostReply); 98 AddAppSpawnHook(STAGE_PARENT_PRE_RELY, HOOK_PRIO_COMMON - 1, TestPluginPreReply); 99 AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_COMMON - 1, ChildPreColdBoot); 100 AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_HIGHEST - 1, ChildExecute); 101 AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_COMMON - 1, ChildExecute); 102 AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX - 1, ChildExecute); 103 AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX + 1, ChildExecute); 104 AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_PROPERTY - 1, ChildExecute); 105 AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_PROPERTY + 1, ChildExecute); 106 AddAppSpawnHook(STAGE_CHILD_PRE_RELY, HOOK_PRIO_COMMON - 1, ChildPreRely); 107 AddAppSpawnHook(STAGE_CHILD_POST_RELY, HOOK_PRIO_COMMON - 1, ChildPostRely); 108 AddAppSpawnHook(STAGE_CHILD_PRE_RUN, HOOK_PRIO_COMMON - 1, ChildPreRun); 109} 110