169570cc8Sopenharmony_ci/* 269570cc8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 369570cc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 469570cc8Sopenharmony_ci * you may not use this file except in compliance with the License. 569570cc8Sopenharmony_ci * You may obtain a copy of the License at 669570cc8Sopenharmony_ci * 769570cc8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 869570cc8Sopenharmony_ci * 969570cc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1069570cc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1169570cc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1269570cc8Sopenharmony_ci * See the License for the specific language governing permissions and 1369570cc8Sopenharmony_ci * limitations under the License. 1469570cc8Sopenharmony_ci */ 1569570cc8Sopenharmony_ci 1669570cc8Sopenharmony_ci#include "appspawn_hook.h" 1769570cc8Sopenharmony_ci#include "appspawn_manager.h" 1869570cc8Sopenharmony_ci#include "appspawn_utils.h" 1969570cc8Sopenharmony_ci 2069570cc8Sopenharmony_cistatic int TestPluginReportProcessExit(const AppSpawnMgr *content, const AppSpawnedProcess *appInfo) 2169570cc8Sopenharmony_ci{ 2269570cc8Sopenharmony_ci APPSPAWN_LOGI("Process %{public}s exit", appInfo->name); 2369570cc8Sopenharmony_ci return 0; 2469570cc8Sopenharmony_ci} 2569570cc8Sopenharmony_ci 2669570cc8Sopenharmony_cistatic int TestPluginReportProcessAdd(const AppSpawnMgr *content, const AppSpawnedProcess *appInfo) 2769570cc8Sopenharmony_ci{ 2869570cc8Sopenharmony_ci APPSPAWN_LOGI("Process %{public}s add", appInfo->name); 2969570cc8Sopenharmony_ci return 0; 3069570cc8Sopenharmony_ci} 3169570cc8Sopenharmony_ci 3269570cc8Sopenharmony_cistatic int TestPluginPreload(AppSpawnMgr *content) 3369570cc8Sopenharmony_ci{ 3469570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin preload"); 3569570cc8Sopenharmony_ci return 0; 3669570cc8Sopenharmony_ci} 3769570cc8Sopenharmony_ci 3869570cc8Sopenharmony_cistatic int TestPluginExit(AppSpawnMgr *content) 3969570cc8Sopenharmony_ci{ 4069570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin exit"); 4169570cc8Sopenharmony_ci return 0; 4269570cc8Sopenharmony_ci} 4369570cc8Sopenharmony_ci 4469570cc8Sopenharmony_ci 4569570cc8Sopenharmony_cistatic int TestPluginPreFork(AppSpawnMgr *content, AppSpawningCtx *property) 4669570cc8Sopenharmony_ci{ 4769570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin pre fork for %{public}s ", GetProcessName(property)); 4869570cc8Sopenharmony_ci return 0; 4969570cc8Sopenharmony_ci} 5069570cc8Sopenharmony_ci 5169570cc8Sopenharmony_cistatic int TestPluginPreReply(AppSpawnMgr *content, AppSpawningCtx *property) 5269570cc8Sopenharmony_ci{ 5369570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin pre reply to client for %{public}s ", GetProcessName(property)); 5469570cc8Sopenharmony_ci return 0; 5569570cc8Sopenharmony_ci} 5669570cc8Sopenharmony_ci 5769570cc8Sopenharmony_cistatic int TestPluginPostReply(AppSpawnMgr *content, AppSpawningCtx *property) 5869570cc8Sopenharmony_ci{ 5969570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin post reply to client for %{public}s ", GetProcessName(property)); 6069570cc8Sopenharmony_ci return 0; 6169570cc8Sopenharmony_ci} 6269570cc8Sopenharmony_ci 6369570cc8Sopenharmony_cistatic int ChildPreColdBoot(AppSpawnMgr *content, AppSpawningCtx *property) 6469570cc8Sopenharmony_ci{ 6569570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin pre cold boot for %{public}s ", GetProcessName(property)); 6669570cc8Sopenharmony_ci return 0; 6769570cc8Sopenharmony_ci} 6869570cc8Sopenharmony_cistatic int ChildExecute(AppSpawnMgr *content, AppSpawningCtx *property) 6969570cc8Sopenharmony_ci{ 7069570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin set app property for %{public}s ", GetProcessName(property)); 7169570cc8Sopenharmony_ci return 0; 7269570cc8Sopenharmony_ci} 7369570cc8Sopenharmony_cistatic int ChildPreRely(AppSpawnMgr *content, AppSpawningCtx *property) 7469570cc8Sopenharmony_ci{ 7569570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin pre reply to parent for %{public}s ", GetProcessName(property)); 7669570cc8Sopenharmony_ci return 0; 7769570cc8Sopenharmony_ci} 7869570cc8Sopenharmony_cistatic int ChildPostRely(AppSpawnMgr *content, AppSpawningCtx *property) 7969570cc8Sopenharmony_ci{ 8069570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin post reply to parent for %{public}s ", GetProcessName(property)); 8169570cc8Sopenharmony_ci return 0; 8269570cc8Sopenharmony_ci} 8369570cc8Sopenharmony_cistatic int ChildPreRun(AppSpawnMgr *content, AppSpawningCtx *property) 8469570cc8Sopenharmony_ci{ 8569570cc8Sopenharmony_ci APPSPAWN_LOGI("TestPlugin pre child run for %{public}s ", GetProcessName(property)); 8669570cc8Sopenharmony_ci return 0; 8769570cc8Sopenharmony_ci} 8869570cc8Sopenharmony_ci 8969570cc8Sopenharmony_ciMODULE_CONSTRUCTOR(void) 9069570cc8Sopenharmony_ci{ 9169570cc8Sopenharmony_ci APPSPAWN_LOGI("Load test plugin module ..."); 9269570cc8Sopenharmony_ci AddProcessMgrHook(STAGE_SERVER_APP_DIED, 0, TestPluginReportProcessExit); 9369570cc8Sopenharmony_ci AddProcessMgrHook(STAGE_SERVER_APP_ADD, 0, TestPluginReportProcessAdd); 9469570cc8Sopenharmony_ci AddServerStageHook(STAGE_SERVER_EXIT, 0, TestPluginExit); 9569570cc8Sopenharmony_ci AddPreloadHook(HOOK_PRIO_LOWEST - 1, TestPluginPreload); 9669570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_PARENT_PRE_FORK, HOOK_PRIO_COMMON - 1, TestPluginPreFork); 9769570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_PARENT_POST_RELY, HOOK_PRIO_COMMON - 1, TestPluginPostReply); 9869570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_PARENT_PRE_RELY, HOOK_PRIO_COMMON - 1, TestPluginPreReply); 9969570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_PRE_COLDBOOT, HOOK_PRIO_COMMON - 1, ChildPreColdBoot); 10069570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_HIGHEST - 1, ChildExecute); 10169570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_COMMON - 1, ChildExecute); 10269570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX - 1, ChildExecute); 10369570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_SANDBOX + 1, ChildExecute); 10469570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_PROPERTY - 1, ChildExecute); 10569570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_EXECUTE, HOOK_PRIO_PROPERTY + 1, ChildExecute); 10669570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_PRE_RELY, HOOK_PRIO_COMMON - 1, ChildPreRely); 10769570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_POST_RELY, HOOK_PRIO_COMMON - 1, ChildPostRely); 10869570cc8Sopenharmony_ci AddAppSpawnHook(STAGE_CHILD_PRE_RUN, HOOK_PRIO_COMMON - 1, ChildPreRun); 10969570cc8Sopenharmony_ci} 110