1 /*
2 * Copyright (c) 2021-2025 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 "app_mgr_stub.h"
17
18 #include "ability_info.h"
19 #include "ability_manager_errors.h"
20 #include "app_jsheap_mem_info.h"
21 #include "app_cjheap_mem_info.h"
22 #include "app_malloc_info.h"
23 #include "app_mgr_proxy.h"
24 #include "app_scheduler_interface.h"
25 #include "appexecfwk_errors.h"
26 #include "bundle_info.h"
27 #ifdef SUPPORT_CHILD_PROCESS
28 #include "child_process_request.h"
29 #endif // SUPPORT_CHILD_PROCESS
30 #include "hilog_tag_wrapper.h"
31 #include "hitrace_meter.h"
32 #include "iapp_state_callback.h"
33 #include "ipc_skeleton.h"
34 #include "ipc_types.h"
35 #include "iremote_object.h"
36 #include "memory_level_info.h"
37 #include "running_process_info.h"
38 #include "want.h"
39
40 namespace OHOS {
41 namespace AppExecFwk {
42 constexpr int32_t CYCLE_LIMIT = 1000;
43 constexpr int32_t MAX_PROCESS_STATE_COUNT = 1000;
44 constexpr int32_t MAX_BACKGROUND_APP_COUNT = 1000;
45
AppMgrStub()46 AppMgrStub::AppMgrStub() {}
47
~AppMgrStub()48 AppMgrStub::~AppMgrStub() {}
49
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)50 int AppMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
51 {
52 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code,
53 option.GetFlags());
54 std::u16string descriptor = AppMgrStub::GetDescriptor();
55 std::u16string remoteDescriptor = data.ReadInterfaceToken();
56 if (descriptor != remoteDescriptor) {
57 TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
58 return ERR_INVALID_STATE;
59 }
60 return OnRemoteRequestInner(code, data, reply, option);
61 }
62
OnRemoteRequestInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)63 int32_t AppMgrStub::OnRemoteRequestInner(uint32_t code, MessageParcel &data,
64 MessageParcel &reply, MessageOption &option)
65 {
66 int retCode = ERR_OK;
67 retCode = OnRemoteRequestInnerFirst(code, data, reply, option);
68 if (retCode != INVALID_FD) {
69 return retCode;
70 }
71 retCode = OnRemoteRequestInnerSecond(code, data, reply, option);
72 if (retCode != INVALID_FD) {
73 return retCode;
74 }
75 retCode = OnRemoteRequestInnerThird(code, data, reply, option);
76 if (retCode != INVALID_FD) {
77 return retCode;
78 }
79 retCode = OnRemoteRequestInnerFourth(code, data, reply, option);
80 if (retCode != INVALID_FD) {
81 return retCode;
82 }
83 retCode = OnRemoteRequestInnerFifth(code, data, reply, option);
84 if (retCode != INVALID_FD) {
85 return retCode;
86 }
87 retCode = OnRemoteRequestInnerSixth(code, data, reply, option);
88 if (retCode != INVALID_FD) {
89 return retCode;
90 }
91 retCode = OnRemoteRequestInnerSeventh(code, data, reply, option);
92 if (retCode != INVALID_FD) {
93 return retCode;
94 }
95 retCode = OnRemoteRequestInnerEighth(code, data, reply, option);
96 if (retCode != INVALID_FD) {
97 return retCode;
98 }
99 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::OnRemoteRequest end");
100 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
101 }
102
OnRemoteRequestInnerFirst(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)103 int32_t AppMgrStub::OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
104 MessageParcel &reply, MessageOption &option)
105 {
106 switch (static_cast<uint32_t>(code)) {
107 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_ATTACH_APPLICATION):
108 return HandleAttachApplication(data, reply);
109 case static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION):
110 return HandlePreloadApplication(data, reply);
111 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED):
112 return HandleApplicationForegrounded(data, reply);
113 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED):
114 return HandleApplicationBackgrounded(data, reply);
115 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_TERMINATED):
116 return HandleApplicationTerminated(data, reply);
117 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_ABILITY_CLEANED):
118 return HandleAbilityCleaned(data, reply);
119 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_MGR_INSTANCE):
120 return HandleGetAmsMgr(data, reply);
121 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA):
122 return HandleClearUpApplicationData(data, reply);
123 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RUNNING_PROCESSES):
124 return HandleGetAllRunningProcesses(data, reply);
125 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_NOTIFY_MEMORY_LEVEL):
126 return HandleNotifyMemoryLevel(data, reply);
127 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_NOTIFY_PROC_MEMORY_LEVEL):
128 return HandleNotifyProcMemoryLevel(data, reply);
129 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID):
130 return HandleGetProcessRunningInfosByUserId(data, reply);
131 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_ADD_ABILITY_STAGE_INFO_DONE):
132 return HandleAddAbilityStageDone(data, reply);
133 case static_cast<uint32_t>(AppMgrInterfaceCode::STARTUP_RESIDENT_PROCESS):
134 return HandleStartupResidentProcess(data, reply);
135 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APPLICATION_STATE_OBSERVER):
136 return HandleRegisterApplicationStateObserver(data, reply);
137 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APPLICATION_STATE_OBSERVER):
138 return HandleUnregisterApplicationStateObserver(data, reply);
139 case static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_MODULE_FINISHED):
140 return HandlePreloadModuleFinished(data, reply);
141 }
142 return INVALID_FD;
143 }
144
OnRemoteRequestInnerSecond(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)145 int32_t AppMgrStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data,
146 MessageParcel &reply, MessageOption &option)
147 {
148 switch (static_cast<uint32_t>(code)) {
149 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_FOREGROUND_APPLICATIONS):
150 return HandleGetForegroundApplications(data, reply);
151 case static_cast<uint32_t>(AppMgrInterfaceCode::START_USER_TEST_PROCESS):
152 return HandleStartUserTestProcess(data, reply);
153 case static_cast<uint32_t>(AppMgrInterfaceCode::FINISH_USER_TEST):
154 return HandleFinishUserTest(data, reply);
155 case static_cast<uint32_t>(AppMgrInterfaceCode::SCHEDULE_ACCEPT_WANT_DONE):
156 return HandleScheduleAcceptWantDone(data, reply);
157 case static_cast<uint32_t>(AppMgrInterfaceCode::SCHEDULE_NEW_PROCESS_REQUEST_DONE):
158 return HandleScheduleNewProcessRequestDone(data, reply);
159 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID):
160 return HandleGetAbilityRecordsByProcessID(data, reply);
161 case static_cast<uint32_t>(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS):
162 return HandlePreStartNWebSpawnProcess(data, reply);
163 case static_cast<uint32_t>(AppMgrInterfaceCode::START_RENDER_PROCESS):
164 return HandleStartRenderProcess(data, reply);
165 case static_cast<uint32_t>(AppMgrInterfaceCode::ATTACH_RENDER_PROCESS):
166 return HandleAttachRenderProcess(data, reply);
167 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RENDER_PROCESS_TERMINATION_STATUS):
168 return HandleGetRenderProcessTerminationStatus(data, reply);
169 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_CONFIGURATION):
170 return HandleGetConfiguration(data, reply);
171 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION):
172 return HandleUpdateConfiguration(data, reply);
173 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER):
174 return HandleRegisterConfigurationObserver(data, reply);
175 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_CONFIGURATION_OBSERVER):
176 return HandleUnregisterConfigurationObserver(data, reply);
177 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_PROCESS_RUNNING_INFORMATION):
178 return HandleGetProcessRunningInformation(data, reply);
179 case static_cast<uint32_t>(AppMgrInterfaceCode::DUMP_HEAP_MEMORY_PROCESS):
180 return HandleDumpHeapMemory(data, reply);
181 case static_cast<uint32_t>(AppMgrInterfaceCode::DUMP_JSHEAP_MEMORY_PROCESS):
182 return HandleDumpJsHeapMemory(data, reply);
183 case static_cast<uint32_t>(AppMgrInterfaceCode::DUMP_CJHEAP_MEMORY_PROCESS):
184 return HandleDumpCjHeapMemory(data, reply);
185 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME):
186 return HandleGetRunningMultiAppInfoByBundleName(data, reply);
187 }
188 return INVALID_FD;
189 }
190
OnRemoteRequestInnerThird(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)191 int32_t AppMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data,
192 MessageParcel &reply, MessageOption &option)
193 {
194 switch (static_cast<uint32_t>(code)) {
195 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_STATE):
196 return HandleGetAppRunningStateByBundleName(data, reply);
197 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_LOAD_REPAIR_PATCH):
198 return HandleNotifyLoadRepairPatch(data, reply);
199 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_HOT_RELOAD_PAGE):
200 return HandleNotifyHotReloadPage(data, reply);
201 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
202 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
203 return HandleSetContinuousTaskProcess(data, reply);
204 #endif
205 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH):
206 return HandleNotifyUnLoadRepairPatch(data, reply);
207 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_SHARED_BUNDLE_RUNNING):
208 return HandleIsSharedBundleRunning(data, reply);
209 case static_cast<uint32_t>(AppMgrInterfaceCode::START_NATIVE_PROCESS_FOR_DEBUGGER):
210 return HandleStartNativeProcessForDebugger(data, reply);
211 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT):
212 return HandleNotifyFault(data, reply);
213 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME):
214 return HandleGetAllRunningInstanceKeysByBundleName(data, reply);
215 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_SELF):
216 return HandleGetAllRunningInstanceKeysBySelf(data, reply);
217 }
218 return INVALID_FD;
219 }
220
OnRemoteRequestInnerFourth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)221 int32_t AppMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &data,
222 MessageParcel &reply, MessageOption &option)
223 {
224 switch (static_cast<uint32_t>(code)) {
225 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
226 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
227 return HandleSetContinuousTaskProcess(data, reply);
228 #endif
229 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA):
230 return HandleNotifyFaultBySA(data, reply);
231 case static_cast<uint32_t>(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID):
232 return HandleJudgeSandboxByPid(data, reply);
233 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_APPFREEZE_FILTER):
234 return HandleSetAppFreezeFilter(data, reply);
235 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID):
236 return HandleGetBundleNameByPid(data, reply);
237 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_PID):
238 return HandleGetRunningProcessInfoByPid(data, reply);
239 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_CHILD_PROCESS_PID):
240 return HandleGetRunningProcessInfoByChildProcessPid(data, reply);
241 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RENDER_PROCESSES):
242 return HandleGetAllRenderProcesses(data, reply);
243 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID):
244 return HandleGetProcessMemoryByPid(data, reply);
245 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_TERMINATING_BY_PID):
246 return HandleIsTerminatingByPid(data, reply);
247 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_SPECIFIED_MODULE_LOADED):
248 return HandleIsSpecifiedModuleLoaded(data, reply);
249 }
250 return INVALID_FD;
251 }
252
OnRemoteRequestInnerFifth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)253 int32_t AppMgrStub::OnRemoteRequestInnerFifth(uint32_t code, MessageParcel &data,
254 MessageParcel &reply, MessageOption &option)
255 {
256 switch (static_cast<uint32_t>(code)) {
257 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
258 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
259 return HandleSetContinuousTaskProcess(data, reply);
260 #endif
261 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_PIDS_BY_BUNDLENAME):
262 return HandleGetRunningProcessInformation(data, reply);
263 case static_cast<uint32_t>(AppMgrInterfaceCode::CHANGE_APP_GC_STATE):
264 return HandleChangeAppGcState(data, reply);
265 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_PAGE_SHOW):
266 return HandleNotifyPageShow(data, reply);
267 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_PAGE_HIDE):
268 return HandleNotifyPageHide(data, reply);
269 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APP_RUNNING_STATUS_LISTENER):
270 return HandleRegisterAppRunningStatusListener(data, reply);
271 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APP_RUNNING_STATUS_LISTENER):
272 return HandleUnregisterAppRunningStatusListener(data, reply);
273 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APP_FOREGROUND_STATE_OBSERVER):
274 return HandleRegisterAppForegroundStateObserver(data, reply);
275 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APP_FOREGROUND_STATE_OBSERVER):
276 return HandleUnregisterAppForegroundStateObserver(data, reply);
277 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER):
278 return HandleRegisterAbilityForegroundStateObserver(data, reply);
279 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER):
280 return HandleUnregisterAbilityForegroundStateObserver(data, reply);
281 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_APPLICATION_RUNNING):
282 return HandleIsApplicationRunning(data, reply);
283 #ifdef SUPPORT_CHILD_PROCESS
284 case static_cast<uint32_t>(AppMgrInterfaceCode::START_CHILD_PROCESS):
285 return HandleStartChildProcess(data, reply);
286 #endif // SUPPORT_CHILD_PROCESS
287 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_NATIVE_CHILD_EXIT_NOTIFY):
288 return HandleRegisterNativeChildExitNotify(data, reply);
289 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_NATIVE_CHILD_EXIT_NOTIFY):
290 return HandleUnregisterNativeChildExitNotify(data, reply);
291 }
292 return INVALID_FD;
293 }
294
OnRemoteRequestInnerSixth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)295 int32_t AppMgrStub::OnRemoteRequestInnerSixth(uint32_t code, MessageParcel &data,
296 MessageParcel &reply, MessageOption &option)
297 {
298 switch (static_cast<uint32_t>(code)) {
299 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
300 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
301 return HandleSetContinuousTaskProcess(data, reply);
302 #endif
303 #ifdef SUPPORT_CHILD_PROCESS
304 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_CHILD_PROCCESS_INFO_FOR_SELF):
305 return HandleGetChildProcessInfoForSelf(data, reply);
306 case static_cast<uint32_t>(AppMgrInterfaceCode::ATTACH_CHILD_PROCESS):
307 return HandleAttachChildProcess(data, reply);
308 case static_cast<uint32_t>(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY):
309 return HandleExitChildProcessSafely(data, reply);
310 #endif // SUPPORT_CHILD_PROCESS
311 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_FINAL_APP_PROCESS):
312 return HandleIsFinalAppProcess(data, reply);
313 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA_BY_SELF):
314 return HandleClearUpApplicationDataBySelf(data, reply);
315 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_RENDER_STATUS_OBSERVER):
316 return HandleRegisterRenderStateObserver(data, reply);
317 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_RENDER_STATUS_OBSERVER):
318 return HandleUnregisterRenderStateObserver(data, reply);
319 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_RENDER_STATUS):
320 return HandleUpdateRenderState(data, reply);
321 case static_cast<uint32_t>(AppMgrInterfaceCode::SIGN_RESTART_APP_FLAG):
322 return HandleSignRestartAppFlag(data, reply);
323 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_UNIQUE_ID_BY_PID):
324 return HandleGetAppRunningUniqueIdByPid(data, reply);
325 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_ROOT_HOST_PID):
326 return HandleGetAllUIExtensionRootHostPid(data, reply);
327 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_PROVIDER_PID):
328 return HandleGetAllUIExtensionProviderPid(data, reply);
329 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_APP_RUNNING_BY_BUNDLE_NAME_AND_USER_ID):
330 return HandleIsAppRunningByBundleNameAndUserId(data, reply);
331 }
332 return INVALID_FD;
333 }
334
OnRemoteRequestInnerSeventh(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)335 int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &data,
336 MessageParcel &reply, MessageOption &option)
337 {
338 switch (static_cast<uint32_t>(code)) {
339 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
340 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
341 return HandleSetContinuousTaskProcess(data, reply);
342 #endif
343 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION_BY_BUNDLE_NAME):
344 return HandleUpdateConfigurationByBundleName(data, reply);
345 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_MEMORY_SIZE_STATE_CHANGED):
346 return HandleNotifyMemorySizeStateChanged(data, reply);
347 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF):
348 return HandleSetSupportedProcessCacheSelf(data, reply);
349 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE):
350 return HandleSetSupportedProcessCache(data, reply);
351 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_PROCESS_CACHE_SUPPORTED):
352 return HandleIsProcessCacheSupported(data, reply);
353 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_PROCESS_CACHE_ENABLE):
354 return HandleSetProcessCacheEnable(data, reply);
355 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_BUNDLE_TYPE):
356 return HandleGetRunningProcessesByBundleType(data, reply);
357 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_APP_ASSERT_PAUSE_STATE_SELF):
358 return HandleSetAppAssertionPauseState(data, reply);
359 #ifdef SUPPORT_CHILD_PROCESS
360 case static_cast<uint32_t>(AppMgrInterfaceCode::CREATE_NATIVE_CHILD_PROCESS):
361 return HandleCreateNativeChildProcess(data, reply);
362 #endif // SUPPORT_CHILD_PROCESS
363 case static_cast<uint32_t>(AppMgrInterfaceCode::SAVE_BROWSER_CHANNEL):
364 return HandleSaveBrowserChannel(data, reply);
365 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_APP_RUNNING):
366 return HandleIsAppRunning(data, reply);
367 case static_cast<uint32_t>(AppMgrInterfaceCode::CHECK_CALLING_IS_USER_TEST_MODE):
368 return HandleCheckCallingIsUserTestMode(data, reply);
369 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_PROCESS_DEPENDED_ON_WEB):
370 return HandleNotifyProcessDependedOnWeb(data, reply);
371 case static_cast<uint32_t>(AppMgrInterfaceCode::KILL_PROCESS_DEPENDED_ON_WEB):
372 return HandleKillProcessDependedOnWeb(data, reply);
373 case static_cast<uint32_t>(AppMgrInterfaceCode::RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB):
374 return HandleRestartResidentProcessDependedOnWeb(data, reply);
375 #ifdef SUPPORT_CHILD_PROCESS
376 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES):
377 return HandleGetAllChildrenProcesses(data, reply);
378 #endif // SUPPORT_CHILD_PROCESS
379 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_SUPPORTED_PROCESS_CACHE_PIDS):
380 return HandleGetSupportedProcessCachePids(data, reply);
381 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_KIA_INTERCEPTOR):
382 return HandleRegisterKiaInterceptor(data, reply);
383 case static_cast<uint32_t>(AppMgrInterfaceCode::CHECK_IS_KIA_PROCESS):
384 return HandleCheckIsKiaProcess(data, reply);
385 case static_cast<uint32_t>(AppMgrInterfaceCode::KILL_APP_SELF_WITH_INSTANCE_KEY):
386 return HandleKillAppSelfWithInstanceKey(data, reply);
387 }
388 return INVALID_FD;
389 }
390
OnRemoteRequestInnerEighth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)391 int32_t AppMgrStub::OnRemoteRequestInnerEighth(uint32_t code, MessageParcel &data,
392 MessageParcel &reply, MessageOption &option)
393 {
394 switch (static_cast<uint32_t>(code)) {
395 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_INSTANCE_KEY_BY_SPECIFIED_ID):
396 return HandleUpdateInstanceKeyBySpecifiedId(data, reply);
397 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_PROCESS_MEMORY_STATE):
398 return HandleUpdateProcessMemoryState(data, reply);
399 case static_cast<uint32_t>(AppMgrInterfaceCode::LAUNCH_ABILITY):
400 return HandleLaunchAbility(data, reply);
401 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION_POLICY):
402 return HandleUpdateConfigurationForBackgroundApp(data, reply);
403 case static_cast<uint32_t>(AppMgrInterfaceCode::PROMOTE_CURRENT_TO_CANDIDATE_MASTER_PROCESS):
404 return HandlePromoteCurrentToCandidateMasterProcess(data, reply);
405 case static_cast<uint32_t>(AppMgrInterfaceCode::DEMOTE_CURRENT_FROM_CANDIDATE_MASTER_PROCESS):
406 return HandleDemoteCurrentFromCandidateMasterProcess(data, reply);
407 case static_cast<uint32_t>(AppMgrInterfaceCode::QUERY_RUNNING_SHARED_BUNDLES):
408 return HandleQueryRunningSharedBundles(data, reply);
409 }
410 return INVALID_FD;
411 }
412
HandleAttachApplication(MessageParcel & data,MessageParcel & reply)413 int32_t AppMgrStub::HandleAttachApplication(MessageParcel &data, MessageParcel &reply)
414 {
415 HITRACE_METER(HITRACE_TAG_APP);
416 sptr<IRemoteObject> client = data.ReadRemoteObject();
417 if (client == nullptr) {
418 TAG_LOGE(AAFwkTag::APPMGR, "remote object null");
419 }
420 AttachApplication(client);
421 return NO_ERROR;
422 }
423
HandlePreloadApplication(MessageParcel & data,MessageParcel & reply)424 int32_t AppMgrStub::HandlePreloadApplication(MessageParcel &data, MessageParcel &reply)
425 {
426 HITRACE_METER(HITRACE_TAG_APP);
427 TAG_LOGD(AAFwkTag::APPMGR, "called");
428 std::string bundleName = Str16ToStr8(data.ReadString16());
429 int32_t userId = data.ReadInt32();
430 int32_t preloadMode = data.ReadInt32();
431 int32_t appIndex = data.ReadInt32();
432 auto result = PreloadApplication(bundleName, userId, static_cast<AppExecFwk::PreloadMode>(preloadMode), appIndex);
433 if (!reply.WriteInt32(result)) {
434 TAG_LOGE(AAFwkTag::APPMGR, "Stub HandlePreloadApplication Write result failed.");
435 return ERR_APPEXECFWK_PARCEL_ERROR;
436 }
437 return NO_ERROR;
438 }
439
HandlePreloadModuleFinished(MessageParcel & data,MessageParcel & reply)440 int32_t AppMgrStub::HandlePreloadModuleFinished(MessageParcel &data, MessageParcel &reply)
441 {
442 TAG_LOGD(AAFwkTag::APPMGR, "HandlePreloadModuleFinished called");
443 HITRACE_METER(HITRACE_TAG_APP);
444 int32_t recordId = data.ReadInt32();
445 PreloadModuleFinished(recordId);
446 return NO_ERROR;
447 }
448
449
HandleApplicationForegrounded(MessageParcel & data,MessageParcel & reply)450 int32_t AppMgrStub::HandleApplicationForegrounded(MessageParcel &data, MessageParcel &reply)
451 {
452 HITRACE_METER(HITRACE_TAG_APP);
453 ApplicationForegrounded(data.ReadInt32());
454 return NO_ERROR;
455 }
456
HandleApplicationBackgrounded(MessageParcel & data,MessageParcel & reply)457 int32_t AppMgrStub::HandleApplicationBackgrounded(MessageParcel &data, MessageParcel &reply)
458 {
459 HITRACE_METER(HITRACE_TAG_APP);
460 ApplicationBackgrounded(data.ReadInt32());
461 return NO_ERROR;
462 }
463
HandleApplicationTerminated(MessageParcel & data,MessageParcel & reply)464 int32_t AppMgrStub::HandleApplicationTerminated(MessageParcel &data, MessageParcel &reply)
465 {
466 HITRACE_METER(HITRACE_TAG_APP);
467 ApplicationTerminated(data.ReadInt32());
468 return NO_ERROR;
469 }
470
HandleAbilityCleaned(MessageParcel & data,MessageParcel & reply)471 int32_t AppMgrStub::HandleAbilityCleaned(MessageParcel &data, MessageParcel &reply)
472 {
473 HITRACE_METER(HITRACE_TAG_APP);
474 sptr<IRemoteObject> token = data.ReadRemoteObject();
475 AbilityCleaned(token);
476 return NO_ERROR;
477 }
478
HandleGetAmsMgr(MessageParcel & data,MessageParcel & reply)479 int32_t AppMgrStub::HandleGetAmsMgr(MessageParcel &data, MessageParcel &reply)
480 {
481 HITRACE_METER(HITRACE_TAG_APP);
482 int32_t result = NO_ERROR;
483 sptr<IAmsMgr> amsMgr = GetAmsMgr();
484 if (!amsMgr) {
485 TAG_LOGE(AAFwkTag::APPMGR, "abilitymgr instance is nullptr");
486 result = ERR_NO_INIT;
487 } else {
488 if (!reply.WriteRemoteObject(amsMgr->AsObject())) {
489 TAG_LOGE(AAFwkTag::APPMGR, "failed to reply abilitymgr instance to client, for write parcel error");
490 result = ERR_APPEXECFWK_PARCEL_ERROR;
491 }
492 }
493 reply.WriteInt32(result);
494 return NO_ERROR;
495 }
496
HandleClearUpApplicationData(MessageParcel & data,MessageParcel & reply)497 int32_t AppMgrStub::HandleClearUpApplicationData(MessageParcel &data, MessageParcel &reply)
498 {
499 HITRACE_METER(HITRACE_TAG_APP);
500 std::string bundleName = data.ReadString();
501 int32_t appCloneIndex = data.ReadInt32();
502 int32_t userId = data.ReadInt32();
503 int32_t result = ClearUpApplicationData(bundleName, appCloneIndex, userId);
504 reply.WriteInt32(result);
505 return NO_ERROR;
506 }
507
HandleClearUpApplicationDataBySelf(MessageParcel & data,MessageParcel & reply)508 int32_t AppMgrStub::HandleClearUpApplicationDataBySelf(MessageParcel &data, MessageParcel &reply)
509 {
510 HITRACE_METER(HITRACE_TAG_APP);
511 int32_t userId = data.ReadInt32();
512 int32_t result = ClearUpApplicationDataBySelf(userId);
513 reply.WriteInt32(result);
514 return NO_ERROR;
515 }
516
HandleGetAllRunningProcesses(MessageParcel & data,MessageParcel & reply)517 int32_t AppMgrStub::HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply)
518 {
519 HITRACE_METER(HITRACE_TAG_APP);
520 std::vector<RunningProcessInfo> info;
521 auto result = GetAllRunningProcesses(info);
522 reply.WriteInt32(info.size());
523 for (auto &it : info) {
524 if (!reply.WriteParcelable(&it)) {
525 return ERR_INVALID_VALUE;
526 }
527 }
528 if (!reply.WriteInt32(result)) {
529 return ERR_INVALID_VALUE;
530 }
531 return NO_ERROR;
532 }
533
HandleGetRunningMultiAppInfoByBundleName(MessageParcel & data,MessageParcel & reply)534 int32_t AppMgrStub::HandleGetRunningMultiAppInfoByBundleName(MessageParcel &data, MessageParcel &reply)
535 {
536 std::string bundleName = data.ReadString();
537 RunningMultiAppInfo info;
538 int32_t result = GetRunningMultiAppInfoByBundleName(bundleName, info);
539 if (!reply.WriteParcelable(&info)) {
540 return ERR_INVALID_VALUE;
541 }
542 if (!reply.WriteInt32(result)) {
543 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
544 return ERR_INVALID_VALUE;
545 }
546 return NO_ERROR;
547 }
548
HandleGetAllRunningInstanceKeysBySelf(MessageParcel & data,MessageParcel & reply)549 int32_t AppMgrStub::HandleGetAllRunningInstanceKeysBySelf(MessageParcel &data, MessageParcel &reply)
550 {
551 std::vector<std::string> instanceKeys;
552 int32_t result = GetAllRunningInstanceKeysBySelf(instanceKeys);
553 if (!reply.WriteStringVector(instanceKeys)) {
554 TAG_LOGE(AAFwkTag::APPMGR, "failed to write isntanceKeys");
555 return ERR_INVALID_VALUE;
556 }
557 if (!reply.WriteInt32(result)) {
558 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
559 return ERR_INVALID_VALUE;
560 }
561 return NO_ERROR;
562 }
563
HandleGetAllRunningInstanceKeysByBundleName(MessageParcel & data,MessageParcel & reply)564 int32_t AppMgrStub::HandleGetAllRunningInstanceKeysByBundleName(MessageParcel &data, MessageParcel &reply)
565 {
566 std::string bundleName = data.ReadString();
567 int32_t userId = data.ReadInt32();
568 std::vector<std::string> instanceKeys;
569 int32_t result = GetAllRunningInstanceKeysByBundleName(bundleName, instanceKeys, userId);
570 if (!reply.WriteStringVector(instanceKeys)) {
571 TAG_LOGE(AAFwkTag::APPMGR, "failed to write isntanceKeys");
572 return ERR_INVALID_VALUE;
573 }
574 if (!reply.WriteInt32(result)) {
575 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
576 return ERR_INVALID_VALUE;
577 }
578 return NO_ERROR;
579 }
580
HandleGetRunningProcessesByBundleType(MessageParcel & data,MessageParcel & reply)581 int32_t AppMgrStub::HandleGetRunningProcessesByBundleType(MessageParcel &data, MessageParcel &reply)
582 {
583 HITRACE_METER(HITRACE_TAG_APP);
584 int32_t bundleType = data.ReadInt32();
585 std::vector<RunningProcessInfo> info;
586 auto result = GetRunningProcessesByBundleType(static_cast<BundleType>(bundleType), info);
587 reply.WriteInt32(info.size());
588 for (auto &it : info) {
589 if (!reply.WriteParcelable(&it)) {
590 return ERR_INVALID_VALUE;
591 }
592 }
593 if (!reply.WriteInt32(result)) {
594 return ERR_INVALID_VALUE;
595 }
596 return NO_ERROR;
597 }
598
HandleGetProcessRunningInfosByUserId(MessageParcel & data,MessageParcel & reply)599 int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply)
600 {
601 HITRACE_METER(HITRACE_TAG_APP);
602 int32_t userId = data.ReadInt32();
603 std::vector<RunningProcessInfo> info;
604 auto result = GetProcessRunningInfosByUserId(info, userId);
605 reply.WriteInt32(info.size());
606 for (auto &it : info) {
607 if (!reply.WriteParcelable(&it)) {
608 return ERR_INVALID_VALUE;
609 }
610 }
611 if (!reply.WriteInt32(result)) {
612 return ERR_INVALID_VALUE;
613 }
614 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleGetAllRunningProcesses end");
615 return NO_ERROR;
616 }
617
HandleGetAllRenderProcesses(MessageParcel & data,MessageParcel & reply)618 int32_t AppMgrStub::HandleGetAllRenderProcesses(MessageParcel &data, MessageParcel &reply)
619 {
620 HITRACE_METER(HITRACE_TAG_APP);
621 std::vector<RenderProcessInfo> info;
622 auto result = GetAllRenderProcesses(info);
623 reply.WriteInt32(info.size());
624 for (auto &it : info) {
625 if (!reply.WriteParcelable(&it)) {
626 return ERR_INVALID_VALUE;
627 }
628 }
629 if (!reply.WriteInt32(result)) {
630 return ERR_INVALID_VALUE;
631 }
632 return NO_ERROR;
633 }
634
635 #ifdef SUPPORT_CHILD_PROCESS
HandleGetAllChildrenProcesses(MessageParcel & data,MessageParcel & reply)636 int32_t AppMgrStub::HandleGetAllChildrenProcesses(MessageParcel &data, MessageParcel &reply)
637 {
638 HITRACE_METER(HITRACE_TAG_APP);
639 std::vector<ChildProcessInfo> info;
640 auto result = GetAllChildrenProcesses(info);
641 reply.WriteInt32(info.size());
642 for (auto &it : info) {
643 if (!reply.WriteParcelable(&it)) {
644 TAG_LOGE(AAFwkTag::APPMGR, "Write ChildProcessInfo faild, child pid=%{public}d", it.pid);
645 return ERR_INVALID_VALUE;
646 }
647 }
648 if (!reply.WriteInt32(result)) {
649 TAG_LOGE(AAFwkTag::APPMGR, "Write result faild");
650 return ERR_INVALID_VALUE;
651 }
652 return NO_ERROR;
653 }
654 #endif // SUPPORT_CHILD_PROCESS
655
HandleJudgeSandboxByPid(MessageParcel & data,MessageParcel & reply)656 int32_t AppMgrStub::HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply)
657 {
658 HITRACE_METER(HITRACE_TAG_APP);
659 int32_t pid = data.ReadInt32();
660 bool isSandbox = false;
661 auto result = JudgeSandboxByPid(pid, isSandbox);
662 if (!reply.WriteBool(isSandbox)) {
663 return ERR_INVALID_VALUE;
664 }
665 if (!reply.WriteInt32(result)) {
666 return ERR_INVALID_VALUE;
667 }
668 return NO_ERROR;
669 }
670
HandleIsTerminatingByPid(MessageParcel & data,MessageParcel & reply)671 int32_t AppMgrStub::HandleIsTerminatingByPid(MessageParcel &data, MessageParcel &reply)
672 {
673 HITRACE_METER(HITRACE_TAG_APP);
674 int32_t pid = data.ReadInt32();
675 bool isTerminating = false;
676 auto result = IsTerminatingByPid(pid, isTerminating);
677 if (!reply.WriteBool(isTerminating)) {
678 return ERR_INVALID_VALUE;
679 }
680 if (!reply.WriteInt32(result)) {
681 return ERR_INVALID_VALUE;
682 }
683 return NO_ERROR;
684 }
685
HandleGetProcessRunningInformation(MessageParcel & data,MessageParcel & reply)686 int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply)
687 {
688 HITRACE_METER(HITRACE_TAG_APP);
689 RunningProcessInfo info;
690 auto result = GetProcessRunningInformation(info);
691 if (!reply.WriteParcelable(&info)) {
692 return ERR_INVALID_VALUE;
693 }
694 if (!reply.WriteInt32(result)) {
695 return ERR_INVALID_VALUE;
696 }
697 return NO_ERROR;
698 }
699
HandleAddAbilityStageDone(MessageParcel & data,MessageParcel & reply)700 int32_t AppMgrStub::HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply)
701 {
702 int32_t recordId = data.ReadInt32();
703 AddAbilityStageDone(recordId);
704 return NO_ERROR;
705 }
706
HandleNotifyMemoryLevel(MessageParcel & data,MessageParcel & reply)707 int32_t AppMgrStub::HandleNotifyMemoryLevel(MessageParcel &data, MessageParcel &reply)
708 {
709 HITRACE_METER(HITRACE_TAG_APP);
710 int32_t level = data.ReadInt32();
711 auto result = NotifyMemoryLevel(level);
712 if (!reply.WriteInt32(result)) {
713 return ERR_INVALID_VALUE;
714 }
715 return NO_ERROR;
716 }
717
HandleNotifyProcMemoryLevel(MessageParcel & data,MessageParcel & reply)718 int32_t AppMgrStub::HandleNotifyProcMemoryLevel(MessageParcel &data, MessageParcel &reply)
719 {
720 HITRACE_METER(HITRACE_TAG_APP);
721 std::unique_ptr<MemoryLevelInfo> memoryLevelInfo(data.ReadParcelable<MemoryLevelInfo>());
722 if (memoryLevelInfo.get() == nullptr) {
723 return ERR_INVALID_VALUE;
724 }
725 auto result = NotifyProcMemoryLevel(memoryLevelInfo->GetProcLevelMap());
726 if (!reply.WriteInt32(result)) {
727 return ERR_INVALID_VALUE;
728 }
729 return NO_ERROR;
730 }
731
HandleDumpHeapMemory(MessageParcel & data,MessageParcel & reply)732 int32_t AppMgrStub::HandleDumpHeapMemory(MessageParcel &data, MessageParcel &reply)
733 {
734 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleDumpHeapMemory.");
735 HITRACE_METER(HITRACE_TAG_APP);
736 int32_t pid = data.ReadInt32();
737 struct OHOS::AppExecFwk::MallocInfo mallocInfo;
738 auto result = DumpHeapMemory(pid, mallocInfo);
739 if (result != NO_ERROR) {
740 return result;
741 }
742 reply.WriteParcelable(&mallocInfo);
743 return NO_ERROR;
744 }
745
HandleDumpJsHeapMemory(MessageParcel & data,MessageParcel & reply)746 int32_t AppMgrStub::HandleDumpJsHeapMemory(MessageParcel &data, MessageParcel &reply)
747 {
748 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleDumpJsHeapMemory.");
749 HITRACE_METER(HITRACE_TAG_APP);
750 std::unique_ptr<JsHeapDumpInfo> info(data.ReadParcelable<JsHeapDumpInfo>());
751 if (info == nullptr) {
752 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
753 return ERR_INVALID_VALUE;
754 }
755 auto result = DumpJsHeapMemory(*info);
756 if (!reply.WriteInt32(result)) {
757 TAG_LOGE(AAFwkTag::APPMGR, "write result error");
758 return ERR_INVALID_VALUE;
759 }
760 return NO_ERROR;
761 }
762
HandleDumpCjHeapMemory(MessageParcel & data,MessageParcel & reply)763 int32_t AppMgrStub::HandleDumpCjHeapMemory(MessageParcel &data, MessageParcel &reply)
764 {
765 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleDumpCjHeapMemory.");
766 HITRACE_METER(HITRACE_TAG_APP);
767 std::unique_ptr<CjHeapDumpInfo> info(data.ReadParcelable<CjHeapDumpInfo>());
768 if (info == nullptr) {
769 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
770 return ERR_INVALID_VALUE;
771 }
772 auto result = DumpCjHeapMemory(*info);
773 if (!reply.WriteInt32(result)) {
774 TAG_LOGE(AAFwkTag::APPMGR, "write result error");
775 return ERR_INVALID_VALUE;
776 }
777 return NO_ERROR;
778 }
779
HandleStartupResidentProcess(MessageParcel & data,MessageParcel & reply)780 int32_t AppMgrStub::HandleStartupResidentProcess(MessageParcel &data, MessageParcel &reply)
781 {
782 HITRACE_METER(HITRACE_TAG_APP);
783 std::vector<AppExecFwk::BundleInfo> bundleInfos;
784 int32_t infoSize = data.ReadInt32();
785 if (infoSize > CYCLE_LIMIT) {
786 TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
787 return ERR_INVALID_VALUE;
788 }
789 for (int32_t i = 0; i < infoSize; i++) {
790 std::unique_ptr<AppExecFwk::BundleInfo> bundleInfo(data.ReadParcelable<AppExecFwk::BundleInfo>());
791 if (!bundleInfo) {
792 TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable infos failed.");
793 return ERR_INVALID_VALUE;
794 }
795 bundleInfos.emplace_back(*bundleInfo);
796 }
797 StartupResidentProcess(bundleInfos);
798 return NO_ERROR;
799 }
800
HandleRegisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)801 int32_t AppMgrStub::HandleRegisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
802 {
803 std::vector<std::string> bundleNameList;
804 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
805 if (callback == nullptr) {
806 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
807 return ERR_INVALID_VALUE;
808 }
809 data.ReadStringVector(&bundleNameList);
810 int32_t result = RegisterApplicationStateObserver(callback, bundleNameList);
811 reply.WriteInt32(result);
812 return NO_ERROR;
813 }
814
HandleUnregisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)815 int32_t AppMgrStub::HandleUnregisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
816 {
817 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
818 if (callback == nullptr) {
819 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
820 return ERR_INVALID_VALUE;
821 }
822 int32_t result = UnregisterApplicationStateObserver(callback);
823 reply.WriteInt32(result);
824 return NO_ERROR;
825 }
826
HandleRegisterAbilityForegroundStateObserver(MessageParcel & data,MessageParcel & reply)827 int32_t AppMgrStub::HandleRegisterAbilityForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
828 {
829 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
830 auto callback = iface_cast<AppExecFwk::IAbilityForegroundStateObserver>(data.ReadRemoteObject());
831 if (callback == nullptr) {
832 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
833 return ERR_INVALID_VALUE;
834 }
835 int32_t result = RegisterAbilityForegroundStateObserver(callback);
836 if (!reply.WriteInt32(result)) {
837 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
838 return ERR_INVALID_VALUE;
839 }
840 return NO_ERROR;
841 }
842
HandleUnregisterAbilityForegroundStateObserver(MessageParcel & data,MessageParcel & reply)843 int32_t AppMgrStub::HandleUnregisterAbilityForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
844 {
845 auto callback = iface_cast<AppExecFwk::IAbilityForegroundStateObserver>(data.ReadRemoteObject());
846 int32_t result = UnregisterAbilityForegroundStateObserver(callback);
847 if (!reply.WriteInt32(result)) {
848 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
849 return ERR_INVALID_VALUE;
850 }
851 return NO_ERROR;
852 }
853
HandleGetForegroundApplications(MessageParcel & data,MessageParcel & reply)854 int32_t AppMgrStub::HandleGetForegroundApplications(MessageParcel &data, MessageParcel &reply)
855 {
856 std::vector<AppStateData> appStateDatas;
857 int32_t result = GetForegroundApplications(appStateDatas);
858 reply.WriteInt32(appStateDatas.size());
859 for (auto &it : appStateDatas) {
860 if (!reply.WriteParcelable(&it)) {
861 return ERR_INVALID_VALUE;
862 }
863 }
864 if (!reply.WriteInt32(result)) {
865 return ERR_INVALID_VALUE;
866 }
867 return result;
868 }
869
HandleStartUserTestProcess(MessageParcel & data,MessageParcel & reply)870 int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply)
871 {
872 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
873 if (want == nullptr) {
874 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
875 return ERR_INVALID_VALUE;
876 }
877 auto observer = data.ReadRemoteObject();
878 std::unique_ptr<BundleInfo> bundleInfo(data.ReadParcelable<BundleInfo>());
879 if (bundleInfo == nullptr) {
880 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
881 return ERR_INVALID_VALUE;
882 }
883 int32_t userId = data.ReadInt32();
884 int32_t result = StartUserTestProcess(*want, observer, *bundleInfo, userId);
885 reply.WriteInt32(result);
886 return result;
887 }
888
HandleFinishUserTest(MessageParcel & data,MessageParcel & reply)889 int32_t AppMgrStub::HandleFinishUserTest(MessageParcel &data, MessageParcel &reply)
890 {
891 std::string msg = data.ReadString();
892 int64_t resultCode = data.ReadInt64();
893 std::string bundleName = data.ReadString();
894 int32_t result = FinishUserTest(msg, resultCode, bundleName);
895 reply.WriteInt32(result);
896 return result;
897 }
898
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)899 int32_t AppMgrStub::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
900 const std::vector<std::string> &bundleNameList)
901 {
902 return NO_ERROR;
903 }
904
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)905 int32_t AppMgrStub::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
906 {
907 return NO_ERROR;
908 }
909
GetForegroundApplications(std::vector<AppStateData> & list)910 int32_t AppMgrStub::GetForegroundApplications(std::vector<AppStateData> &list)
911 {
912 return NO_ERROR;
913 }
914
HandleScheduleAcceptWantDone(MessageParcel & data,MessageParcel & reply)915 int32_t AppMgrStub::HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply)
916 {
917 auto recordId = data.ReadInt32();
918 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
919 if (want == nullptr) {
920 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
921 return ERR_INVALID_VALUE;
922 }
923 auto flag = data.ReadString();
924
925 ScheduleAcceptWantDone(recordId, *want, flag);
926 delete want;
927 return NO_ERROR;
928 }
929
HandleScheduleNewProcessRequestDone(MessageParcel & data,MessageParcel & reply)930 int32_t AppMgrStub::HandleScheduleNewProcessRequestDone(MessageParcel &data, MessageParcel &reply)
931 {
932 auto recordId = data.ReadInt32();
933 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
934 if (want == nullptr) {
935 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
936 return ERR_INVALID_VALUE;
937 }
938 auto flag = data.ReadString();
939
940 ScheduleNewProcessRequestDone(recordId, *want, flag);
941 delete want;
942 return NO_ERROR;
943 }
944
HandleGetAbilityRecordsByProcessID(MessageParcel & data,MessageParcel & reply)945 int32_t AppMgrStub::HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply)
946 {
947 HITRACE_METER(HITRACE_TAG_APP);
948 int32_t pid = data.ReadInt32();
949 std::vector<sptr<IRemoteObject>> tokens;
950 auto result = GetAbilityRecordsByProcessID(pid, tokens);
951 reply.WriteInt32(tokens.size());
952 for (auto &it : tokens) {
953 if (!reply.WriteRemoteObject(it)) {
954 TAG_LOGE(AAFwkTag::APPMGR, "failed to write query result.");
955 return ERR_FLATTEN_OBJECT;
956 }
957 }
958 if (!reply.WriteInt32(result)) {
959 return ERR_INVALID_VALUE;
960 }
961 return NO_ERROR;
962 }
963
HandlePreStartNWebSpawnProcess(MessageParcel & data,MessageParcel & reply)964 int32_t AppMgrStub::HandlePreStartNWebSpawnProcess(MessageParcel &data, MessageParcel &reply)
965 {
966 TAG_LOGI(AAFwkTag::APPMGR, "HandlePreNWebSpawnProcess");
967 int32_t result = PreStartNWebSpawnProcess();
968 if (!reply.WriteInt32(result)) {
969 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
970 return ERR_INVALID_VALUE;
971 }
972 return result;
973 }
974
HandleStartRenderProcess(MessageParcel & data,MessageParcel & reply)975 int32_t AppMgrStub::HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply)
976 {
977 std::string renderParam = data.ReadString();
978 int32_t ipcFd = data.ReadFileDescriptor();
979 int32_t sharedFd = data.ReadFileDescriptor();
980 int32_t crashFd = data.ReadFileDescriptor();
981 int32_t renderPid = 0;
982 bool isGPU = data.ReadBool();
983 int32_t result =
984 StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd, renderPid, isGPU);
985 if (!reply.WriteInt32(result)) {
986 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
987 return ERR_INVALID_VALUE;
988 }
989 if (!reply.WriteInt32(renderPid)) {
990 TAG_LOGE(AAFwkTag::APPMGR, "write renderPid error.");
991 return ERR_INVALID_VALUE;
992 }
993 return result;
994 }
995
HandleAttachRenderProcess(MessageParcel & data,MessageParcel & reply)996 int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply)
997 {
998 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
999 sptr<IRemoteObject> scheduler = data.ReadRemoteObject();
1000 AttachRenderProcess(scheduler);
1001 return NO_ERROR;
1002 }
1003
HandleSaveBrowserChannel(MessageParcel & data,MessageParcel & reply)1004 int32_t AppMgrStub::HandleSaveBrowserChannel(MessageParcel &data, MessageParcel &reply)
1005 {
1006 sptr<IRemoteObject> browser = data.ReadRemoteObject();
1007 SaveBrowserChannel(browser);
1008 return NO_ERROR;
1009 }
1010
HandleGetRenderProcessTerminationStatus(MessageParcel & data,MessageParcel & reply)1011 int32_t AppMgrStub::HandleGetRenderProcessTerminationStatus(MessageParcel &data, MessageParcel &reply)
1012 {
1013 int32_t renderPid = data.ReadInt32();
1014 if (renderPid <= 0) {
1015 TAG_LOGE(AAFwkTag::APPMGR, "invalid renderPid value");
1016 return ERR_INVALID_VALUE;
1017 }
1018 int status = 0;
1019 int32_t result = GetRenderProcessTerminationStatus(renderPid, status);
1020 if (!reply.WriteInt32(result)) {
1021 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
1022 return ERR_INVALID_VALUE;
1023 }
1024 if (!reply.WriteInt32(status)) {
1025 TAG_LOGE(AAFwkTag::APPMGR, "write status error.");
1026 return ERR_INVALID_VALUE;
1027 }
1028 return result;
1029 }
1030
HandleGetConfiguration(MessageParcel & data,MessageParcel & reply)1031 int32_t AppMgrStub::HandleGetConfiguration(MessageParcel &data, MessageParcel &reply)
1032 {
1033 Configuration config;
1034 int ret = GetConfiguration(config);
1035 if (ret != ERR_OK) {
1036 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub GetConfiguration error");
1037 return ERR_INVALID_VALUE;
1038 }
1039 if (!reply.WriteParcelable(&config)) {
1040 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub GetConfiguration error");
1041 return ERR_INVALID_VALUE;
1042 }
1043 if (!reply.WriteInt32(ret)) {
1044 return ERR_INVALID_VALUE;
1045 }
1046 return NO_ERROR;
1047 }
1048
HandleUpdateConfiguration(MessageParcel & data,MessageParcel & reply)1049 int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel &reply)
1050 {
1051 std::unique_ptr<Configuration> config(data.ReadParcelable<Configuration>());
1052 if (!config) {
1053 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
1054 return ERR_INVALID_VALUE;
1055 }
1056 int32_t userId = data.ReadInt32();
1057 int32_t ret = UpdateConfiguration(*config, userId);
1058 if (!reply.WriteInt32(ret)) {
1059 return ERR_INVALID_VALUE;
1060 }
1061 return NO_ERROR;
1062 }
1063
HandleUpdateConfigurationForBackgroundApp(MessageParcel & data,MessageParcel & reply)1064 int32_t AppMgrStub::HandleUpdateConfigurationForBackgroundApp(MessageParcel &data, MessageParcel &reply)
1065 {
1066 TAG_LOGD(AAFwkTag::APPMGR, "called");
1067 std::vector<BackgroundAppInfo> appInfos;
1068 uint32_t size = data.ReadUint32();
1069 if (size <= 0 || size > MAX_BACKGROUND_APP_COUNT) {
1070 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
1071 return ERR_INVALID_VALUE;
1072 }
1073 appInfos.resize(size);
1074 if (appInfos.capacity() < size) {
1075 TAG_LOGE(AAFwkTag::APPMGR, "Resource allocation error");
1076 return ERR_NO_MEMORY;
1077 }
1078 for (auto &item : appInfos) {
1079 std::unique_ptr<BackgroundAppInfo> tmpInfo(data.ReadParcelable<BackgroundAppInfo>());
1080 if (tmpInfo == nullptr) {
1081 TAG_LOGE(AAFwkTag::APPMGR, "tmpInfo null");
1082 return ERR_INVALID_VALUE;
1083 }
1084 item = *tmpInfo;
1085 }
1086 std::unique_ptr<AppExecFwk::ConfigurationPolicy> policy(data.ReadParcelable<AppExecFwk::ConfigurationPolicy>());
1087 if (policy == nullptr) {
1088 TAG_LOGE(AAFwkTag::APPMGR, "policy null");
1089 return ERR_INVALID_VALUE;
1090 }
1091 int32_t userId = data.ReadInt32();
1092 int32_t result = UpdateConfigurationForBackgroundApp(appInfos, *policy, userId);
1093 if (!reply.WriteInt32(result)) {
1094 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1095 return ERR_INVALID_VALUE;
1096 }
1097 return NO_ERROR;
1098 }
1099
HandleUpdateConfigurationByBundleName(MessageParcel & data,MessageParcel & reply)1100 int32_t AppMgrStub::HandleUpdateConfigurationByBundleName(MessageParcel &data, MessageParcel &reply)
1101 {
1102 std::unique_ptr<Configuration> config(data.ReadParcelable<Configuration>());
1103 if (!config) {
1104 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
1105 return ERR_INVALID_VALUE;
1106 }
1107 std::string name = data.ReadString();
1108 auto appIndex = data.ReadInt32();
1109 int32_t ret = UpdateConfigurationByBundleName(*config, name, appIndex);
1110 if (!reply.WriteInt32(ret)) {
1111 return ERR_INVALID_VALUE;
1112 }
1113 return NO_ERROR;
1114 }
1115
HandleRegisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)1116 int32_t AppMgrStub::HandleRegisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
1117 {
1118 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
1119 if (observer == nullptr) {
1120 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
1121 return ERR_INVALID_VALUE;
1122 }
1123 int32_t result = RegisterConfigurationObserver(observer);
1124 reply.WriteInt32(result);
1125 return NO_ERROR;
1126 }
1127
HandleUnregisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)1128 int32_t AppMgrStub::HandleUnregisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
1129 {
1130 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
1131 if (observer == nullptr) {
1132 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
1133 return ERR_INVALID_VALUE;
1134 }
1135 int32_t result = UnregisterConfigurationObserver(observer);
1136 reply.WriteInt32(result);
1137 return NO_ERROR;
1138 }
1139
HandleGetAppRunningStateByBundleName(MessageParcel & data,MessageParcel & reply)1140 int32_t AppMgrStub::HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply)
1141 {
1142 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1143 TAG_LOGD(AAFwkTag::APPMGR, "called");
1144 std::string bundleName = data.ReadString();
1145 auto ret = GetAppRunningStateByBundleName(bundleName);
1146 if (!reply.WriteBool(ret)) {
1147 return ERR_INVALID_VALUE;
1148 }
1149 return NO_ERROR;
1150 }
1151
HandleNotifyLoadRepairPatch(MessageParcel & data,MessageParcel & reply)1152 int32_t AppMgrStub::HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
1153 {
1154 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1155 TAG_LOGD(AAFwkTag::APPMGR, "called");
1156 std::string bundleName = data.ReadString();
1157 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
1158 if (callback == nullptr) {
1159 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1160 return ERR_INVALID_VALUE;
1161 }
1162 auto ret = NotifyLoadRepairPatch(bundleName, callback);
1163 if (!reply.WriteInt32(ret)) {
1164 return ERR_INVALID_VALUE;
1165 }
1166 return NO_ERROR;
1167 }
1168
HandleNotifyHotReloadPage(MessageParcel & data,MessageParcel & reply)1169 int32_t AppMgrStub::HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply)
1170 {
1171 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1172 TAG_LOGD(AAFwkTag::APPMGR, "called");
1173 std::string bundleName = data.ReadString();
1174 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
1175 if (callback == nullptr) {
1176 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1177 return ERR_INVALID_VALUE;
1178 }
1179 auto ret = NotifyHotReloadPage(bundleName, callback);
1180 if (!reply.WriteInt32(ret)) {
1181 return ERR_INVALID_VALUE;
1182 }
1183 return NO_ERROR;
1184 }
1185
1186 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
HandleSetContinuousTaskProcess(MessageParcel & data,MessageParcel & reply)1187 int32_t AppMgrStub::HandleSetContinuousTaskProcess(MessageParcel &data, MessageParcel &reply)
1188 {
1189 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1190 TAG_LOGD(AAFwkTag::APPMGR, "called");
1191 int32_t pid = data.ReadInt32();
1192 bool isContinuousTask = data.ReadBool();
1193 auto ret = SetContinuousTaskProcess(pid, isContinuousTask);
1194 if (!reply.WriteInt32(ret)) {
1195 return ERR_INVALID_VALUE;
1196 }
1197 return NO_ERROR;
1198 }
1199 #endif
1200
HandleNotifyUnLoadRepairPatch(MessageParcel & data,MessageParcel & reply)1201 int32_t AppMgrStub::HandleNotifyUnLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
1202 {
1203 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1204 TAG_LOGD(AAFwkTag::APPMGR, "called");
1205 std::string bundleName = data.ReadString();
1206 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
1207 if (callback == nullptr) {
1208 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1209 return ERR_INVALID_VALUE;
1210 }
1211 auto ret = NotifyUnLoadRepairPatch(bundleName, callback);
1212 if (!reply.WriteInt32(ret)) {
1213 return ERR_INVALID_VALUE;
1214 }
1215 return NO_ERROR;
1216 }
1217
HandleIsSharedBundleRunning(MessageParcel & data,MessageParcel & reply)1218 int32_t AppMgrStub::HandleIsSharedBundleRunning(MessageParcel &data, MessageParcel &reply)
1219 {
1220 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1221 TAG_LOGD(AAFwkTag::APPMGR, "called");
1222 std::string bundleName = data.ReadString();
1223 uint32_t versionCode = data.ReadUint32();
1224 bool result = IsSharedBundleRunning(bundleName, versionCode);
1225 if (!reply.WriteBool(result)) {
1226 return ERR_INVALID_VALUE;
1227 }
1228 return NO_ERROR;
1229 }
1230
HandleStartNativeProcessForDebugger(MessageParcel & data,MessageParcel & reply)1231 int32_t AppMgrStub::HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply)
1232 {
1233 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1234 TAG_LOGD(AAFwkTag::APPMGR, "called");
1235 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1236 if (want == nullptr) {
1237 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
1238 return ERR_INVALID_VALUE;
1239 }
1240 auto result = StartNativeProcessForDebugger(*want);
1241 if (!reply.WriteInt32(result)) {
1242 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1243 return ERR_INVALID_VALUE;
1244 }
1245 return NO_ERROR;
1246 }
1247
HandleGetBundleNameByPid(MessageParcel & data,MessageParcel & reply)1248 int32_t AppMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply)
1249 {
1250 int32_t pid = data.ReadInt32();
1251 std::string bundleName;
1252 int32_t uid;
1253 auto result = GetBundleNameByPid(pid, bundleName, uid);
1254 if (result != ERR_OK) {
1255 return result;
1256 }
1257
1258 if (!reply.WriteString(bundleName)) {
1259 return ERR_INVALID_VALUE;
1260 }
1261
1262 if (!reply.WriteInt32(uid)) {
1263 return ERR_INVALID_VALUE;
1264 }
1265 return NO_ERROR;
1266 }
1267
HandleGetRunningProcessInfoByPid(MessageParcel & data,MessageParcel & reply)1268 int32_t AppMgrStub::HandleGetRunningProcessInfoByPid(MessageParcel &data, MessageParcel &reply)
1269 {
1270 RunningProcessInfo processInfo;
1271 auto pid = static_cast<pid_t>(data.ReadInt32());
1272 auto result = GetRunningProcessInfoByPid(pid, processInfo);
1273 if (!reply.WriteParcelable(&processInfo)) {
1274 TAG_LOGE(AAFwkTag::APPMGR, "failed");
1275 return ERR_INVALID_VALUE;
1276 }
1277 if (!reply.WriteInt32(result)) {
1278 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1279 return ERR_INVALID_VALUE;
1280 }
1281 return NO_ERROR;
1282 }
1283
HandleGetRunningProcessInfoByChildProcessPid(MessageParcel & data,MessageParcel & reply)1284 int32_t AppMgrStub::HandleGetRunningProcessInfoByChildProcessPid(MessageParcel &data, MessageParcel &reply)
1285 {
1286 RunningProcessInfo processInfo;
1287 auto childPid = static_cast<pid_t>(data.ReadInt32());
1288 auto result = GetRunningProcessInfoByChildProcessPid(childPid, processInfo);
1289 if (!reply.WriteParcelable(&processInfo)) {
1290 TAG_LOGE(AAFwkTag::APPMGR, "failed");
1291 return ERR_INVALID_VALUE;
1292 }
1293 if (!reply.WriteInt32(result)) {
1294 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1295 return ERR_INVALID_VALUE;
1296 }
1297 return NO_ERROR;
1298 }
1299
HandleNotifyFault(MessageParcel & data,MessageParcel & reply)1300 int32_t AppMgrStub::HandleNotifyFault(MessageParcel &data, MessageParcel &reply)
1301 {
1302 std::unique_ptr<FaultData> faultData(data.ReadParcelable<FaultData>());
1303 if (faultData == nullptr) {
1304 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<FaultData> failed");
1305 return ERR_INVALID_VALUE;
1306 }
1307
1308 int32_t result = NotifyAppFault(*faultData);
1309 if (!reply.WriteInt32(result)) {
1310 TAG_LOGE(AAFwkTag::APPMGR, "reply write failed.");
1311 return ERR_INVALID_VALUE;
1312 }
1313 return NO_ERROR;
1314 }
1315
HandleNotifyFaultBySA(MessageParcel & data,MessageParcel & reply)1316 int32_t AppMgrStub::HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &reply)
1317 {
1318 std::unique_ptr<AppFaultDataBySA> faultData(data.ReadParcelable<AppFaultDataBySA>());
1319 if (faultData == nullptr) {
1320 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<AppFaultDataBySA> failed");
1321 return ERR_INVALID_VALUE;
1322 }
1323
1324 int32_t result = NotifyAppFaultBySA(*faultData);
1325 if (!reply.WriteInt32(result)) {
1326 TAG_LOGE(AAFwkTag::APPMGR, "reply write failed.");
1327 return ERR_INVALID_VALUE;
1328 }
1329 return NO_ERROR;
1330 }
1331
HandleSetAppFreezeFilter(MessageParcel & data,MessageParcel & reply)1332 int32_t AppMgrStub::HandleSetAppFreezeFilter(MessageParcel &data, MessageParcel &reply)
1333 {
1334 int32_t pid = data.ReadInt32();
1335 bool result = SetAppFreezeFilter(pid);
1336 if (!reply.WriteBool(result)) {
1337 TAG_LOGE(AAFwkTag::APPMGR, "reply write failed.");
1338 return ERR_INVALID_VALUE;
1339 }
1340 return NO_ERROR;
1341 }
1342
HandleGetProcessMemoryByPid(MessageParcel & data,MessageParcel & reply)1343 int32_t AppMgrStub::HandleGetProcessMemoryByPid(MessageParcel &data, MessageParcel &reply)
1344 {
1345 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1346 int32_t pid = data.ReadInt32();
1347 int32_t memorySize = 0;
1348 auto result = GetProcessMemoryByPid(pid, memorySize);
1349 if (!reply.WriteInt32(memorySize)) {
1350 TAG_LOGE(AAFwkTag::APPMGR, "Memory size write failed.");
1351 return ERR_INVALID_VALUE;
1352 }
1353 if (!reply.WriteInt32(result)) {
1354 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1355 return ERR_INVALID_VALUE;
1356 }
1357 return NO_ERROR;
1358 }
1359
HandleGetRunningProcessInformation(MessageParcel & data,MessageParcel & reply)1360 int32_t AppMgrStub::HandleGetRunningProcessInformation(MessageParcel &data, MessageParcel &reply)
1361 {
1362 HITRACE_METER(HITRACE_TAG_APP);
1363 std::string bundleName = data.ReadString();
1364 int32_t userId = data.ReadInt32();
1365 std::vector<RunningProcessInfo> info;
1366 auto result = GetRunningProcessInformation(bundleName, userId, info);
1367 reply.WriteInt32(info.size());
1368 for (auto &it : info) {
1369 if (!reply.WriteParcelable(&it)) {
1370 return ERR_INVALID_VALUE;
1371 }
1372 }
1373 if (!reply.WriteInt32(result)) {
1374 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1375 return ERR_INVALID_VALUE;
1376 }
1377 return NO_ERROR;
1378 }
1379
HandleChangeAppGcState(MessageParcel & data,MessageParcel & reply)1380 int32_t AppMgrStub::HandleChangeAppGcState(MessageParcel &data, MessageParcel &reply)
1381 {
1382 HITRACE_METER(HITRACE_TAG_APP);
1383 int32_t pid = data.ReadInt32();
1384 int32_t state = data.ReadInt32();
1385 uint64_t tid = data.ReadUint64();
1386 int32_t ret = ChangeAppGcState(pid, state, tid);
1387 reply.WriteInt32(ret);
1388 return NO_ERROR;
1389 }
1390
HandleNotifyPageShow(MessageParcel & data,MessageParcel & reply)1391 int32_t AppMgrStub::HandleNotifyPageShow(MessageParcel &data, MessageParcel &reply)
1392 {
1393 sptr<IRemoteObject> token = data.ReadRemoteObject();
1394 std::unique_ptr<PageStateData> pageStateData(data.ReadParcelable<PageStateData>());
1395 if (token == nullptr || pageStateData == nullptr) {
1396 TAG_LOGE(AAFwkTag::APPMGR, "read data failed");
1397 return ERR_INVALID_VALUE;
1398 }
1399
1400 auto result = NotifyPageShow(token, *pageStateData);
1401 if (!reply.WriteInt32(result)) {
1402 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1403 return ERR_INVALID_VALUE;
1404 }
1405 return NO_ERROR;
1406 }
1407
HandleNotifyPageHide(MessageParcel & data,MessageParcel & reply)1408 int32_t AppMgrStub::HandleNotifyPageHide(MessageParcel &data, MessageParcel &reply)
1409 {
1410 sptr<IRemoteObject> token = data.ReadRemoteObject();
1411 std::unique_ptr<PageStateData> pageStateData(data.ReadParcelable<PageStateData>());
1412 if (token == nullptr || pageStateData == nullptr) {
1413 TAG_LOGE(AAFwkTag::APPMGR, "read data failed");
1414 return ERR_INVALID_VALUE;
1415 }
1416
1417 auto result = NotifyPageHide(token, *pageStateData);
1418 if (!reply.WriteInt32(result)) {
1419 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1420 return ERR_INVALID_VALUE;
1421 }
1422 return NO_ERROR;
1423 }
1424
HandleRegisterAppRunningStatusListener(MessageParcel & data,MessageParcel & reply)1425 int32_t AppMgrStub::HandleRegisterAppRunningStatusListener(MessageParcel &data, MessageParcel &reply)
1426 {
1427 auto listener = data.ReadRemoteObject();
1428 if (listener == nullptr) {
1429 TAG_LOGE(AAFwkTag::APPMGR, "Read data failed.");
1430 return ERR_INVALID_VALUE;
1431 }
1432
1433 auto result = RegisterAppRunningStatusListener(listener);
1434 if (!reply.WriteInt32(result)) {
1435 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1436 return ERR_INVALID_VALUE;
1437 }
1438 return NO_ERROR;
1439 }
1440
HandleUnregisterAppRunningStatusListener(MessageParcel & data,MessageParcel & reply)1441 int32_t AppMgrStub::HandleUnregisterAppRunningStatusListener(MessageParcel &data, MessageParcel &reply)
1442 {
1443 auto listener = data.ReadRemoteObject();
1444 if (listener == nullptr) {
1445 TAG_LOGE(AAFwkTag::APPMGR, "Read data failed.");
1446 return ERR_INVALID_VALUE;
1447 }
1448
1449 auto result = UnregisterAppRunningStatusListener(listener);
1450 if (!reply.WriteInt32(result)) {
1451 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1452 return ERR_INVALID_VALUE;
1453 }
1454 return NO_ERROR;
1455 }
1456
HandleRegisterAppForegroundStateObserver(MessageParcel & data,MessageParcel & reply)1457 int32_t AppMgrStub::HandleRegisterAppForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
1458 {
1459 auto callback = iface_cast<AppExecFwk::IAppForegroundStateObserver>(data.ReadRemoteObject());
1460 if (callback == nullptr) {
1461 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1462 return ERR_INVALID_VALUE;
1463 }
1464 int32_t result = RegisterAppForegroundStateObserver(callback);
1465 if (!reply.WriteInt32(result)) {
1466 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1467 return ERR_INVALID_VALUE;
1468 }
1469 return NO_ERROR;
1470 }
1471
HandleUnregisterAppForegroundStateObserver(MessageParcel & data,MessageParcel & reply)1472 int32_t AppMgrStub::HandleUnregisterAppForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
1473 {
1474 auto callback = iface_cast<AppExecFwk::IAppForegroundStateObserver>(data.ReadRemoteObject());
1475 if (callback == nullptr) {
1476 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1477 return ERR_INVALID_VALUE;
1478 }
1479 int32_t result = UnregisterAppForegroundStateObserver(callback);
1480 if (!reply.WriteInt32(result)) {
1481 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1482 return ERR_INVALID_VALUE;
1483 }
1484 return NO_ERROR;
1485 }
1486
HandleIsApplicationRunning(MessageParcel & data,MessageParcel & reply)1487 int32_t AppMgrStub::HandleIsApplicationRunning(MessageParcel &data, MessageParcel &reply)
1488 {
1489 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1490 TAG_LOGD(AAFwkTag::APPMGR, "called");
1491 std::string bundleName = data.ReadString();
1492 bool isRunning = false;
1493 int32_t result = IsApplicationRunning(bundleName, isRunning);
1494 if (!reply.WriteBool(isRunning)) {
1495 return ERR_INVALID_VALUE;
1496 }
1497 if (!reply.WriteInt32(result)) {
1498 return ERR_INVALID_VALUE;
1499 }
1500 return NO_ERROR;
1501 }
1502
HandleIsAppRunning(MessageParcel & data,MessageParcel & reply)1503 int32_t AppMgrStub::HandleIsAppRunning(MessageParcel &data, MessageParcel &reply)
1504 {
1505 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1506 TAG_LOGD(AAFwkTag::APPMGR, "called");
1507 std::string bundleName = data.ReadString();
1508 bool isRunning = false;
1509 int32_t appCloneIndex = data.ReadInt32();
1510 int32_t result = IsAppRunning(bundleName, appCloneIndex, isRunning);
1511 if (!reply.WriteBool(isRunning)) {
1512 return ERR_INVALID_VALUE;
1513 }
1514 if (!reply.WriteInt32(result)) {
1515 return ERR_INVALID_VALUE;
1516 }
1517 return NO_ERROR;
1518 }
1519
HandleIsAppRunningByBundleNameAndUserId(MessageParcel & data,MessageParcel & reply)1520 int32_t AppMgrStub::HandleIsAppRunningByBundleNameAndUserId(MessageParcel &data, MessageParcel &reply)
1521 {
1522 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1523 TAG_LOGD(AAFwkTag::APPMGR, "called");
1524 std::string bundleName = data.ReadString();
1525 bool isRunning = false;
1526 int32_t userId = data.ReadInt32();
1527 int32_t result = IsAppRunningByBundleNameAndUserId(bundleName, userId, isRunning);
1528 if (!reply.WriteBool(isRunning)) {
1529 return ERR_INVALID_VALUE;
1530 }
1531 if (!reply.WriteInt32(result)) {
1532 return ERR_INVALID_VALUE;
1533 }
1534 return NO_ERROR;
1535 }
1536
1537 #ifdef SUPPORT_CHILD_PROCESS
HandleStartChildProcess(MessageParcel & data,MessageParcel & reply)1538 int32_t AppMgrStub::HandleStartChildProcess(MessageParcel &data, MessageParcel &reply)
1539 {
1540 TAG_LOGD(AAFwkTag::APPMGR, "called");
1541 std::unique_ptr<ChildProcessRequest> request(data.ReadParcelable<ChildProcessRequest>());
1542 if (!request) {
1543 return IPC_STUB_ERR;
1544 }
1545 int32_t childPid = 0;
1546 int32_t result = StartChildProcess(childPid, *request);
1547 if (!reply.WriteInt32(result)) {
1548 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1549 return IPC_STUB_ERR;
1550 }
1551 if (result == ERR_OK && !reply.WriteInt32(childPid)) {
1552 TAG_LOGE(AAFwkTag::APPMGR, "Write childPid error.");
1553 return IPC_STUB_ERR;
1554 }
1555 return NO_ERROR;
1556 }
1557
HandleGetChildProcessInfoForSelf(MessageParcel & data,MessageParcel & reply)1558 int32_t AppMgrStub::HandleGetChildProcessInfoForSelf(MessageParcel &data, MessageParcel &reply)
1559 {
1560 TAG_LOGD(AAFwkTag::APPMGR, "called");
1561 ChildProcessInfo info;
1562 auto result = GetChildProcessInfoForSelf(info);
1563 if (!reply.WriteInt32(result)) {
1564 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1565 return ERR_INVALID_VALUE;
1566 }
1567 if (result == ERR_OK && !reply.WriteParcelable(&info)) {
1568 return ERR_INVALID_VALUE;
1569 }
1570 return NO_ERROR;
1571 }
1572
HandleAttachChildProcess(MessageParcel & data,MessageParcel & reply)1573 int32_t AppMgrStub::HandleAttachChildProcess(MessageParcel &data, MessageParcel &reply)
1574 {
1575 TAG_LOGD(AAFwkTag::APPMGR, "called");
1576 sptr<IRemoteObject> scheduler = data.ReadRemoteObject();
1577 AttachChildProcess(scheduler);
1578 return NO_ERROR;
1579 }
1580
HandleExitChildProcessSafely(MessageParcel & data,MessageParcel & reply)1581 int32_t AppMgrStub::HandleExitChildProcessSafely(MessageParcel &data, MessageParcel &reply)
1582 {
1583 TAG_LOGD(AAFwkTag::APPMGR, "called");
1584 ExitChildProcessSafely();
1585 return NO_ERROR;
1586 }
1587 #endif // SUPPORT_CHILD_PROCESS
1588
HandleRegisterNativeChildExitNotify(MessageParcel & data,MessageParcel & reply)1589 int32_t AppMgrStub::HandleRegisterNativeChildExitNotify(MessageParcel &data, MessageParcel &reply)
1590 {
1591 TAG_LOGD(AAFwkTag::APPMGR, "called");
1592 auto callback = iface_cast<AppExecFwk::INativeChildNotify>(data.ReadRemoteObject());
1593 if (callback == nullptr) {
1594 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1595 return ERR_INVALID_VALUE;
1596 }
1597 int32_t result = RegisterNativeChildExitNotify(callback);
1598 if (!reply.WriteInt32(result)) {
1599 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1600 return ERR_INVALID_VALUE;
1601 }
1602 return NO_ERROR;
1603 }
1604
HandleUnregisterNativeChildExitNotify(MessageParcel & data,MessageParcel & reply)1605 int32_t AppMgrStub::HandleUnregisterNativeChildExitNotify(MessageParcel &data, MessageParcel &reply)
1606 {
1607 TAG_LOGD(AAFwkTag::APPMGR, "called");
1608 auto callback = iface_cast<AppExecFwk::INativeChildNotify>(data.ReadRemoteObject());
1609 if (callback == nullptr) {
1610 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1611 return ERR_INVALID_VALUE;
1612 }
1613 int32_t result = UnregisterNativeChildExitNotify(callback);
1614 if (!reply.WriteInt32(result)) {
1615 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1616 return ERR_INVALID_VALUE;
1617 }
1618 return NO_ERROR;
1619 }
1620
HandleIsFinalAppProcess(MessageParcel & data,MessageParcel & reply)1621 int32_t AppMgrStub::HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply)
1622 {
1623 TAG_LOGD(AAFwkTag::APPMGR, "called");
1624 if (!reply.WriteBool(IsFinalAppProcess())) {
1625 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write bool result.");
1626 return ERR_INVALID_VALUE;
1627 }
1628 return NO_ERROR;
1629 }
1630
HandleRegisterRenderStateObserver(MessageParcel & data,MessageParcel & reply)1631 int32_t AppMgrStub::HandleRegisterRenderStateObserver(MessageParcel &data, MessageParcel &reply)
1632 {
1633 TAG_LOGD(AAFwkTag::APPMGR, "called");
1634 auto callback = iface_cast<AppExecFwk::IRenderStateObserver>(data.ReadRemoteObject());
1635 if (callback == nullptr) {
1636 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1637 return ERR_INVALID_VALUE;
1638 }
1639 int32_t result = RegisterRenderStateObserver(callback);
1640 if (!reply.WriteInt32(result)) {
1641 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1642 return ERR_INVALID_VALUE;
1643 }
1644 return NO_ERROR;
1645 }
1646
HandleUnregisterRenderStateObserver(MessageParcel & data,MessageParcel & reply)1647 int32_t AppMgrStub::HandleUnregisterRenderStateObserver(MessageParcel &data, MessageParcel &reply)
1648 {
1649 TAG_LOGD(AAFwkTag::APPMGR, "called");
1650 auto callback = iface_cast<AppExecFwk::IRenderStateObserver>(data.ReadRemoteObject());
1651 if (callback == nullptr) {
1652 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1653 return ERR_INVALID_VALUE;
1654 }
1655 int32_t result = UnregisterRenderStateObserver(callback);
1656 if (!reply.WriteInt32(result)) {
1657 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1658 return ERR_INVALID_VALUE;
1659 }
1660 return NO_ERROR;
1661 }
1662
HandleUpdateRenderState(MessageParcel & data,MessageParcel & reply)1663 int32_t AppMgrStub::HandleUpdateRenderState(MessageParcel &data, MessageParcel &reply)
1664 {
1665 TAG_LOGD(AAFwkTag::APPMGR, "called");
1666 int32_t pid = data.ReadInt32();
1667 int32_t state = data.ReadInt32();
1668 int32_t result = UpdateRenderState(pid, state);
1669 if (!reply.WriteInt32(result)) {
1670 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1671 return ERR_INVALID_VALUE;
1672 }
1673 return NO_ERROR;
1674 }
1675
HandleSignRestartAppFlag(MessageParcel & data,MessageParcel & reply)1676 int32_t AppMgrStub::HandleSignRestartAppFlag(MessageParcel &data, MessageParcel &reply)
1677 {
1678 TAG_LOGD(AAFwkTag::APPMGR, "called");
1679 auto uid = data.ReadInt32();
1680 auto instanceKey = data.ReadString();
1681 auto ret = SignRestartAppFlag(uid, instanceKey);
1682 if (!reply.WriteInt32(ret)) {
1683 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1684 return IPC_STUB_ERR;
1685 }
1686 return NO_ERROR;
1687 }
1688
HandleGetAppRunningUniqueIdByPid(MessageParcel & data,MessageParcel & reply)1689 int32_t AppMgrStub::HandleGetAppRunningUniqueIdByPid(MessageParcel &data, MessageParcel &reply)
1690 {
1691 TAG_LOGD(AAFwkTag::APPMGR, "called");
1692 int32_t pid = data.ReadInt32();
1693 std::string appRunningUniqueId;
1694 int32_t result = GetAppRunningUniqueIdByPid(pid, appRunningUniqueId);
1695 if (!reply.WriteInt32(result)) {
1696 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1697 return IPC_STUB_ERR;
1698 }
1699 if (result == ERR_OK && !reply.WriteString(appRunningUniqueId)) {
1700 TAG_LOGE(AAFwkTag::APPMGR, "GetAppRunningUniqueIdByPid err or Write appRunningUniqueId error.");
1701 return IPC_STUB_ERR;
1702 }
1703
1704 return NO_ERROR;
1705 }
1706
HandleGetAllUIExtensionRootHostPid(MessageParcel & data,MessageParcel & reply)1707 int32_t AppMgrStub::HandleGetAllUIExtensionRootHostPid(MessageParcel &data, MessageParcel &reply)
1708 {
1709 pid_t pid = data.ReadInt32();
1710 std::vector<pid_t> hostPids;
1711 auto result = GetAllUIExtensionRootHostPid(pid, hostPids);
1712 reply.WriteInt32(hostPids.size());
1713 for (auto &it : hostPids) {
1714 if (!reply.WriteInt32(it)) {
1715 TAG_LOGE(AAFwkTag::APPMGR, "Write host pid failed.");
1716 return ERR_INVALID_VALUE;
1717 }
1718 }
1719
1720 if (!reply.WriteInt32(result)) {
1721 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
1722 return ERR_INVALID_VALUE;
1723 }
1724
1725 return NO_ERROR;
1726 }
1727
HandleGetAllUIExtensionProviderPid(MessageParcel & data,MessageParcel & reply)1728 int32_t AppMgrStub::HandleGetAllUIExtensionProviderPid(MessageParcel &data, MessageParcel &reply)
1729 {
1730 pid_t hostPid = data.ReadInt32();
1731 std::vector<pid_t> providerPids;
1732 auto result = GetAllUIExtensionProviderPid(hostPid, providerPids);
1733 reply.WriteInt32(providerPids.size());
1734 for (auto &it : providerPids) {
1735 if (!reply.WriteInt32(it)) {
1736 TAG_LOGE(AAFwkTag::APPMGR, "Write provider pid failed.");
1737 return ERR_INVALID_VALUE;
1738 }
1739 }
1740
1741 if (!reply.WriteInt32(result)) {
1742 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
1743 return ERR_INVALID_VALUE;
1744 }
1745
1746 return NO_ERROR;
1747 }
1748
HandleNotifyMemorySizeStateChanged(MessageParcel & data,MessageParcel & reply)1749 int32_t AppMgrStub::HandleNotifyMemorySizeStateChanged(MessageParcel &data, MessageParcel &reply)
1750 {
1751 int32_t memorySizeState = data.ReadInt32();
1752 int result = NotifyMemorySizeStateChanged(memorySizeState);
1753 if (!reply.WriteInt32(result)) {
1754 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1755 return ERR_INVALID_VALUE;
1756 }
1757 return NO_ERROR;
1758 }
1759
HandleSetSupportedProcessCache(MessageParcel & data,MessageParcel & reply)1760 int32_t AppMgrStub::HandleSetSupportedProcessCache(MessageParcel &data, MessageParcel &reply)
1761 {
1762 TAG_LOGD(AAFwkTag::APPMGR, "called");
1763 bool isSupport = data.ReadBool();
1764 int32_t pid = data.ReadInt32();
1765 auto ret = SetSupportedProcessCache(pid, isSupport);
1766 if (!reply.WriteInt32(ret)) {
1767 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1768 return IPC_STUB_ERR;
1769 }
1770 return NO_ERROR;
1771 }
1772
HandleIsProcessCacheSupported(MessageParcel & data,MessageParcel & reply)1773 int32_t AppMgrStub::HandleIsProcessCacheSupported(MessageParcel &data, MessageParcel &reply)
1774 {
1775 TAG_LOGD(AAFwkTag::APPMGR, "HandleIsProcessCacheSupported called");
1776 int32_t pid = data.ReadInt32();
1777 bool isSupported = false;
1778 auto ret = IsProcessCacheSupported(pid, isSupported);
1779 if (!reply.WriteBool(isSupported)) {
1780 TAG_LOGE(AAFwkTag::APPMGR, "Write isSupported error.");
1781 return AAFwk::ERR_WRITE_BOOL_FAILED;
1782 }
1783 if (!reply.WriteInt32(ret)) {
1784 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1785 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
1786 }
1787 return NO_ERROR;
1788 }
1789
HandleSetProcessCacheEnable(MessageParcel & data,MessageParcel & reply)1790 int32_t AppMgrStub::HandleSetProcessCacheEnable(MessageParcel &data, MessageParcel &reply)
1791 {
1792 TAG_LOGD(AAFwkTag::APPMGR, "HandleSetProcessCacheEnable called");
1793 int32_t pid = data.ReadInt32();
1794 bool enable = data.ReadBool();
1795 auto ret = SetProcessCacheEnable(pid, enable);
1796 if (!reply.WriteInt32(ret)) {
1797 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1798 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
1799 }
1800 return NO_ERROR;
1801 }
1802
HandleSetAppAssertionPauseState(MessageParcel & data,MessageParcel & reply)1803 int32_t AppMgrStub::HandleSetAppAssertionPauseState(MessageParcel &data, MessageParcel &reply)
1804 {
1805 TAG_LOGD(AAFwkTag::APPMGR, "called");
1806 bool flag = data.ReadBool();
1807 SetAppAssertionPauseState(flag);
1808 return NO_ERROR;
1809 }
1810
HandleSetSupportedProcessCacheSelf(MessageParcel & data,MessageParcel & reply)1811 int32_t AppMgrStub::HandleSetSupportedProcessCacheSelf(MessageParcel &data, MessageParcel &reply)
1812 {
1813 TAG_LOGD(AAFwkTag::APPMGR, "called");
1814 bool isSupport = data.ReadBool();
1815 auto ret = SetSupportedProcessCacheSelf(isSupport);
1816 if (!reply.WriteInt32(ret)) {
1817 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1818 return IPC_STUB_ERR;
1819 }
1820 return NO_ERROR;
1821 }
1822
HandleCheckCallingIsUserTestMode(MessageParcel & data,MessageParcel & reply)1823 int32_t AppMgrStub::HandleCheckCallingIsUserTestMode(MessageParcel &data, MessageParcel &reply)
1824 {
1825 TAG_LOGD(AAFwkTag::APPMGR, "called");
1826 pid_t pid = data.ReadInt32();
1827 bool isUserTest = false;
1828 int32_t ret = CheckCallingIsUserTestMode(pid, isUserTest);
1829 if (!reply.WriteBool(isUserTest)) {
1830 TAG_LOGE(AAFwkTag::APPMGR, "Write isUserTest error.");
1831 return IPC_STUB_ERR;
1832 }
1833 if (!reply.WriteInt32(ret)) {
1834 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1835 return IPC_STUB_ERR;
1836 }
1837 return NO_ERROR;
1838 }
1839
1840 #ifdef SUPPORT_CHILD_PROCESS
HandleCreateNativeChildProcess(MessageParcel & data,MessageParcel & reply)1841 int32_t AppMgrStub::HandleCreateNativeChildProcess(MessageParcel &data, MessageParcel &reply)
1842 {
1843 TAG_LOGD(AAFwkTag::APPMGR, "called");
1844 std::string libName = data.ReadString();
1845 int32_t childCount = data.ReadInt32();
1846 sptr<IRemoteObject> callback = data.ReadRemoteObject();
1847 std::string customProcessName = data.ReadString();
1848 int32_t result = CreateNativeChildProcess(libName, childCount, callback, customProcessName);
1849 if (!reply.WriteInt32(result)) {
1850 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1851 return IPC_STUB_ERR;
1852 }
1853
1854 return NO_ERROR;
1855 }
1856 #endif // SUPPORT_CHILD_PROCESS
1857
HandleNotifyProcessDependedOnWeb(MessageParcel & data,MessageParcel & reply)1858 int32_t AppMgrStub::HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply)
1859 {
1860 TAG_LOGD(AAFwkTag::APPMGR, "call");
1861 int32_t ret = NotifyProcessDependedOnWeb();
1862 if (!reply.WriteInt32(ret)) {
1863 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1864 return IPC_STUB_ERR;
1865 }
1866
1867 return NO_ERROR;
1868 }
1869
HandleKillProcessDependedOnWeb(MessageParcel & data,MessageParcel & reply)1870 int32_t AppMgrStub::HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply)
1871 {
1872 TAG_LOGD(AAFwkTag::APPMGR, "call");
1873 KillProcessDependedOnWeb();
1874 return NO_ERROR;
1875 }
1876
HandleRestartResidentProcessDependedOnWeb(MessageParcel & data,MessageParcel & reply)1877 int32_t AppMgrStub::HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply)
1878 {
1879 TAG_LOGD(AAFwkTag::APPMGR, "call");
1880 RestartResidentProcessDependedOnWeb();
1881 return NO_ERROR;
1882 }
1883
HandleGetSupportedProcessCachePids(MessageParcel & data,MessageParcel & reply)1884 int32_t AppMgrStub::HandleGetSupportedProcessCachePids(MessageParcel &data, MessageParcel &reply)
1885 {
1886 HITRACE_METER(HITRACE_TAG_APP);
1887 std::string bundleName = data.ReadString();
1888 std::vector<int32_t> pidList;
1889 auto result = GetSupportedProcessCachePids(bundleName, pidList);
1890 reply.WriteInt32(pidList.size());
1891 for (auto it : pidList) {
1892 if (!reply.WriteInt32(it)) {
1893 return ERR_INVALID_VALUE;
1894 }
1895 }
1896 if (!reply.WriteInt32(result)) {
1897 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1898 return ERR_INVALID_VALUE;
1899 }
1900 return NO_ERROR;
1901 }
1902
GetSupportedProcessCachePids(const std::string & bundleName,std::vector<int32_t> & pidList)1903 int32_t AppMgrStub::GetSupportedProcessCachePids(const std::string &bundleName,
1904 std::vector<int32_t> &pidList)
1905 {
1906 return NO_ERROR;
1907 }
1908
HandleRegisterKiaInterceptor(MessageParcel & data,MessageParcel & reply)1909 int32_t AppMgrStub::HandleRegisterKiaInterceptor(MessageParcel &data, MessageParcel &reply)
1910 {
1911 TAG_LOGD(AAFwkTag::APPMGR, "call");
1912 sptr<IKiaInterceptor> interceptor = iface_cast<IKiaInterceptor>(data.ReadRemoteObject());
1913 if (interceptor == nullptr) {
1914 TAG_LOGE(AAFwkTag::APPMGR, "interceptor is nullptr.");
1915 return ERR_INVALID_VALUE;
1916 }
1917
1918 reply.WriteInt32(RegisterKiaInterceptor(interceptor));
1919 return NO_ERROR;
1920 }
1921
HandleCheckIsKiaProcess(MessageParcel & data,MessageParcel & reply)1922 int32_t AppMgrStub::HandleCheckIsKiaProcess(MessageParcel &data, MessageParcel &reply)
1923 {
1924 TAG_LOGD(AAFwkTag::APPMGR, "call");
1925 int pid = data.ReadInt32();
1926 bool isKia = false;
1927 int result = CheckIsKiaProcess(pid, isKia);
1928 reply.WriteInt32(result);
1929 if (result != ERR_OK) {
1930 TAG_LOGE(AAFwkTag::APPMGR, "failed,result=%{public}d.", result);
1931 return result;
1932 }
1933 reply.WriteBool(isKia);
1934 return NO_ERROR;
1935 }
1936
HandleKillAppSelfWithInstanceKey(MessageParcel & data,MessageParcel & reply)1937 int32_t AppMgrStub::HandleKillAppSelfWithInstanceKey(MessageParcel &data, MessageParcel &reply)
1938 {
1939 TAG_LOGD(AAFwkTag::APPMGR, "call");
1940 auto instanceKey = data.ReadString();
1941 auto clearPageStack = data.ReadBool();
1942 auto reason = data.ReadString();
1943 auto result = KillAppSelfWithInstanceKey(instanceKey, clearPageStack, reason);
1944 if (!reply.WriteInt32(result)) {
1945 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1946 return ERR_INVALID_VALUE;
1947 }
1948 return NO_ERROR;
1949 }
1950
HandleUpdateInstanceKeyBySpecifiedId(MessageParcel & data,MessageParcel & reply)1951 int32_t AppMgrStub::HandleUpdateInstanceKeyBySpecifiedId(MessageParcel &data, MessageParcel &reply)
1952 {
1953 auto specifiedId = data.ReadInt32();
1954 auto instanceKey = data.ReadString();
1955 UpdateInstanceKeyBySpecifiedId(specifiedId, instanceKey);
1956 return NO_ERROR;
1957 }
1958
HandleIsSpecifiedModuleLoaded(MessageParcel & data,MessageParcel & reply)1959 int32_t AppMgrStub::HandleIsSpecifiedModuleLoaded(MessageParcel &data, MessageParcel &reply)
1960 {
1961 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1962 if (want == nullptr) {
1963 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
1964 return ERR_INVALID_VALUE;
1965 }
1966 std::unique_ptr<AbilityInfo> abilityInfo(data.ReadParcelable<AbilityInfo>());
1967 if (abilityInfo == nullptr) {
1968 TAG_LOGE(AAFwkTag::APPMGR, "abilityInfo is nullptr");
1969 return ERR_INVALID_VALUE;
1970 }
1971
1972 bool exist = false;
1973 bool isDebug = false;
1974 auto ret = IsSpecifiedModuleLoaded(*want, *abilityInfo, exist, isDebug);
1975 if (ret == ERR_OK) {
1976 reply.WriteBool(exist);
1977 reply.WriteBool(isDebug);
1978 }
1979 return ret;
1980 }
1981
HandleUpdateProcessMemoryState(MessageParcel & data,MessageParcel & reply)1982 ErrCode AppMgrStub::HandleUpdateProcessMemoryState(MessageParcel &data, MessageParcel &reply)
1983 {
1984 HITRACE_METER(HITRACE_TAG_APP);
1985 TAG_LOGD(AAFwkTag::APPMGR, "HandleUpdateProcessMemoryState,callingPid=%{public}d", IPCSkeleton::GetCallingPid());
1986 std::vector<ProcessMemoryState> states;
1987 auto size = data.ReadUint32();
1988 if (size <= 0 || size > MAX_PROCESS_STATE_COUNT) {
1989 TAG_LOGE(AAFwkTag::APPMGR, "Invalid size");
1990 return ERR_INVALID_VALUE;
1991 }
1992 for (uint32_t i = 0; i < size; i++) {
1993 std::unique_ptr<ProcessMemoryState> tmpState(data.ReadParcelable<ProcessMemoryState>());
1994 if (tmpState == nullptr) {
1995 TAG_LOGE(AAFwkTag::APPMGR, "tmpState is nullptr.");
1996 return ERR_INVALID_VALUE;
1997 }
1998 states.emplace_back(*tmpState);
1999 }
2000 auto ret = UpdateProcessMemoryState(states);
2001 reply.WriteInt32(ret);
2002 return NO_ERROR;
2003 }
2004
HandleLaunchAbility(MessageParcel & data,MessageParcel & reply)2005 int32_t AppMgrStub::HandleLaunchAbility(MessageParcel &data, MessageParcel &reply)
2006 {
2007 sptr token = data.ReadRemoteObject();
2008 if (token == nullptr) {
2009 TAG_LOGE(AAFwkTag::APPMGR, "read data failed.");
2010 return ERR_INVALID_VALUE;
2011 }
2012 auto result = LaunchAbility(token);
2013 if (!reply.WriteInt32(result)) {
2014 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
2015 return ERR_INVALID_VALUE;
2016 }
2017 return NO_ERROR;
2018 }
2019
HandlePromoteCurrentToCandidateMasterProcess(MessageParcel & data,MessageParcel & reply)2020 int32_t AppMgrStub::HandlePromoteCurrentToCandidateMasterProcess(MessageParcel &data, MessageParcel &reply)
2021 {
2022 TAG_LOGD(AAFwkTag::APPMGR, "called");
2023 bool isInsertToHead = data.ReadBool();
2024 auto ret = PromoteCurrentToCandidateMasterProcess(isInsertToHead);
2025 if (!reply.WriteInt32(ret)) {
2026 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
2027 return IPC_STUB_ERR;
2028 }
2029 return NO_ERROR;
2030 }
2031
HandleDemoteCurrentFromCandidateMasterProcess(MessageParcel & data,MessageParcel & reply)2032 int32_t AppMgrStub::HandleDemoteCurrentFromCandidateMasterProcess(MessageParcel &data, MessageParcel &reply)
2033 {
2034 TAG_LOGD(AAFwkTag::APPMGR, "call");
2035 int32_t ret = DemoteCurrentFromCandidateMasterProcess();
2036 if (!reply.WriteInt32(ret)) {
2037 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
2038 return IPC_STUB_ERR;
2039 }
2040
2041 return NO_ERROR;
2042 }
2043
HandleQueryRunningSharedBundles(MessageParcel & data,MessageParcel & reply)2044 int32_t AppMgrStub::HandleQueryRunningSharedBundles(MessageParcel &data, MessageParcel &reply)
2045 {
2046 TAG_LOGD(AAFwkTag::APPMGR, "HandleQueryRunningSharedBundles call");
2047 pid_t pid = data.ReadInt32();
2048 std::map<std::string, uint32_t> sharedBundles;
2049
2050 int32_t result = QueryRunningSharedBundles(pid, sharedBundles);
2051 if (!reply.WriteInt32(result)) {
2052 TAG_LOGE(AAFwkTag::APPMGR, "write result fail");
2053 return AAFwk::ERR_WRITE_RESULT_CODE_FAILED;
2054 }
2055 if (result != ERR_OK) {
2056 return NO_ERROR;
2057 }
2058
2059 if (!reply.WriteInt32(static_cast<int32_t>(sharedBundles.size()))) {
2060 TAG_LOGE(AAFwkTag::APPMGR, "write size fail");
2061 return IPC_STUB_ERR;
2062 }
2063 for (const auto &item : sharedBundles) {
2064 if (!reply.WriteString(item.first) || !reply.WriteUint32(item.second)) {
2065 TAG_LOGE(AAFwkTag::APPMGR, "write item fail");
2066 return IPC_STUB_ERR;
2067 }
2068 }
2069 return NO_ERROR;
2070 }
2071 } // namespace AppExecFwk
2072 } // namespace OHOS
2073