1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "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_malloc_info.h"
22 #include "app_mgr_proxy.h"
23 #include "app_scheduler_interface.h"
24 #include "appexecfwk_errors.h"
25 #include "bundle_info.h"
26 #include "child_process_request.h"
27 #include "hilog_tag_wrapper.h"
28 #include "hitrace_meter.h"
29 #include "iapp_state_callback.h"
30 #include "ipc_skeleton.h"
31 #include "ipc_types.h"
32 #include "iremote_object.h"
33 #include "memory_level_info.h"
34 #include "running_process_info.h"
35 #include "want.h"
36
37 namespace OHOS {
38 namespace AppExecFwk {
39 constexpr int32_t CYCLE_LIMIT = 1000;
40
AppMgrStub()41 AppMgrStub::AppMgrStub() {}
42
~AppMgrStub()43 AppMgrStub::~AppMgrStub() {}
44
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)45 int AppMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
46 {
47 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code,
48 option.GetFlags());
49 std::u16string descriptor = AppMgrStub::GetDescriptor();
50 std::u16string remoteDescriptor = data.ReadInterfaceToken();
51 if (descriptor != remoteDescriptor) {
52 TAG_LOGE(AAFwkTag::APPMGR, "local descriptor is not equal to remote");
53 return ERR_INVALID_STATE;
54 }
55 return OnRemoteRequestInner(code, data, reply, option);
56 }
57
OnRemoteRequestInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)58 int32_t AppMgrStub::OnRemoteRequestInner(uint32_t code, MessageParcel &data,
59 MessageParcel &reply, MessageOption &option)
60 {
61 int retCode = ERR_OK;
62 retCode = OnRemoteRequestInnerFirst(code, data, reply, option);
63 if (retCode != INVALID_FD) {
64 return retCode;
65 }
66 retCode = OnRemoteRequestInnerSecond(code, data, reply, option);
67 if (retCode != INVALID_FD) {
68 return retCode;
69 }
70 retCode = OnRemoteRequestInnerThird(code, data, reply, option);
71 if (retCode != INVALID_FD) {
72 return retCode;
73 }
74 retCode = OnRemoteRequestInnerFourth(code, data, reply, option);
75 if (retCode != INVALID_FD) {
76 return retCode;
77 }
78 retCode = OnRemoteRequestInnerFifth(code, data, reply, option);
79 if (retCode != INVALID_FD) {
80 return retCode;
81 }
82 retCode = OnRemoteRequestInnerSixth(code, data, reply, option);
83 if (retCode != INVALID_FD) {
84 return retCode;
85 }
86 retCode = OnRemoteRequestInnerSeventh(code, data, reply, option);
87 if (retCode != INVALID_FD) {
88 return retCode;
89 }
90 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::OnRemoteRequest end");
91 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
92 }
93
OnRemoteRequestInnerFirst(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)94 int32_t AppMgrStub::OnRemoteRequestInnerFirst(uint32_t code, MessageParcel &data,
95 MessageParcel &reply, MessageOption &option)
96 {
97 switch (static_cast<uint32_t>(code)) {
98 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_ATTACH_APPLICATION):
99 return HandleAttachApplication(data, reply);
100 case static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION):
101 return HandlePreloadApplication(data, reply);
102 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED):
103 return HandleApplicationForegrounded(data, reply);
104 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED):
105 return HandleApplicationBackgrounded(data, reply);
106 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_TERMINATED):
107 return HandleApplicationTerminated(data, reply);
108 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_ABILITY_CLEANED):
109 return HandleAbilityCleaned(data, reply);
110 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_MGR_INSTANCE):
111 return HandleGetAmsMgr(data, reply);
112 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA):
113 return HandleClearUpApplicationData(data, reply);
114 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RUNNING_PROCESSES):
115 return HandleGetAllRunningProcesses(data, reply);
116 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_NOTIFY_MEMORY_LEVEL):
117 return HandleNotifyMemoryLevel(data, reply);
118 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_NOTIFY_PROC_MEMORY_LEVEL):
119 return HandleNotifyProcMemoryLevel(data, reply);
120 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID):
121 return HandleGetProcessRunningInfosByUserId(data, reply);
122 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_ADD_ABILITY_STAGE_INFO_DONE):
123 return HandleAddAbilityStageDone(data, reply);
124 case static_cast<uint32_t>(AppMgrInterfaceCode::STARTUP_RESIDENT_PROCESS):
125 return HandleStartupResidentProcess(data, reply);
126 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APPLICATION_STATE_OBSERVER):
127 return HandleRegisterApplicationStateObserver(data, reply);
128 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APPLICATION_STATE_OBSERVER):
129 return HandleUnregisterApplicationStateObserver(data, reply);
130 }
131 return INVALID_FD;
132 }
133
OnRemoteRequestInnerSecond(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)134 int32_t AppMgrStub::OnRemoteRequestInnerSecond(uint32_t code, MessageParcel &data,
135 MessageParcel &reply, MessageOption &option)
136 {
137 switch (static_cast<uint32_t>(code)) {
138 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_FOREGROUND_APPLICATIONS):
139 return HandleGetForegroundApplications(data, reply);
140 case static_cast<uint32_t>(AppMgrInterfaceCode::START_USER_TEST_PROCESS):
141 return HandleStartUserTestProcess(data, reply);
142 case static_cast<uint32_t>(AppMgrInterfaceCode::FINISH_USER_TEST):
143 return HandleFinishUserTest(data, reply);
144 case static_cast<uint32_t>(AppMgrInterfaceCode::SCHEDULE_ACCEPT_WANT_DONE):
145 return HandleScheduleAcceptWantDone(data, reply);
146 case static_cast<uint32_t>(AppMgrInterfaceCode::SCHEDULE_NEW_PROCESS_REQUEST_DONE):
147 return HandleScheduleNewProcessRequestDone(data, reply);
148 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID):
149 return HandleGetAbilityRecordsByProcessID(data, reply);
150 case static_cast<uint32_t>(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS):
151 return HandlePreStartNWebSpawnProcess(data, reply);
152 case static_cast<uint32_t>(AppMgrInterfaceCode::START_RENDER_PROCESS):
153 return HandleStartRenderProcess(data, reply);
154 case static_cast<uint32_t>(AppMgrInterfaceCode::ATTACH_RENDER_PROCESS):
155 return HandleAttachRenderProcess(data, reply);
156 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RENDER_PROCESS_TERMINATION_STATUS):
157 return HandleGetRenderProcessTerminationStatus(data, reply);
158 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_CONFIGURATION):
159 return HandleGetConfiguration(data, reply);
160 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION):
161 return HandleUpdateConfiguration(data, reply);
162 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER):
163 return HandleRegisterConfigurationObserver(data, reply);
164 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_CONFIGURATION_OBSERVER):
165 return HandleUnregisterConfigurationObserver(data, reply);
166 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_PROCESS_RUNNING_INFORMATION):
167 return HandleGetProcessRunningInformation(data, reply);
168 case static_cast<uint32_t>(AppMgrInterfaceCode::DUMP_HEAP_MEMORY_PROCESS):
169 return HandleDumpHeapMemory(data, reply);
170 case static_cast<uint32_t>(AppMgrInterfaceCode::DUMP_JSHEAP_MEMORY_PROCESS):
171 return HandleDumpJsHeapMemory(data, reply);
172 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME):
173 return HandleGetRunningMultiAppInfoByBundleName(data, reply);
174 }
175 return INVALID_FD;
176 }
177
OnRemoteRequestInnerThird(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)178 int32_t AppMgrStub::OnRemoteRequestInnerThird(uint32_t code, MessageParcel &data,
179 MessageParcel &reply, MessageOption &option)
180 {
181 switch (static_cast<uint32_t>(code)) {
182 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_STATE):
183 return HandleGetAppRunningStateByBundleName(data, reply);
184 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_LOAD_REPAIR_PATCH):
185 return HandleNotifyLoadRepairPatch(data, reply);
186 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_HOT_RELOAD_PAGE):
187 return HandleNotifyHotReloadPage(data, reply);
188 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
189 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
190 return HandleSetContinuousTaskProcess(data, reply);
191 #endif
192 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH):
193 return HandleNotifyUnLoadRepairPatch(data, reply);
194 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_SHARED_BUNDLE_RUNNING):
195 return HandleIsSharedBundleRunning(data, reply);
196 case static_cast<uint32_t>(AppMgrInterfaceCode::START_NATIVE_PROCESS_FOR_DEBUGGER):
197 return HandleStartNativeProcessForDebugger(data, reply);
198 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT):
199 return HandleNotifyFault(data, reply);
200 }
201 return INVALID_FD;
202 }
203
OnRemoteRequestInnerFourth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)204 int32_t AppMgrStub::OnRemoteRequestInnerFourth(uint32_t code, MessageParcel &data,
205 MessageParcel &reply, MessageOption &option)
206 {
207 switch (static_cast<uint32_t>(code)) {
208 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
209 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
210 return HandleSetContinuousTaskProcess(data, reply);
211 #endif
212 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA):
213 return HandleNotifyFaultBySA(data, reply);
214 case static_cast<uint32_t>(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID):
215 return HandleJudgeSandboxByPid(data, reply);
216 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_APPFREEZE_FILTER):
217 return HandleSetAppFreezeFilter(data, reply);
218 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID):
219 return HandleGetBundleNameByPid(data, reply);
220 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_PROCESS_INFO_BY_PID):
221 return HandleGetRunningProcessInfoByPid(data, reply);
222 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RENDER_PROCESSES):
223 return HandleGetAllRenderProcesses(data, reply);
224 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID):
225 return HandleGetProcessMemoryByPid(data, reply);
226 }
227 return INVALID_FD;
228 }
229
OnRemoteRequestInnerFifth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)230 int32_t AppMgrStub::OnRemoteRequestInnerFifth(uint32_t code, MessageParcel &data,
231 MessageParcel &reply, MessageOption &option)
232 {
233 switch (static_cast<uint32_t>(code)) {
234 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
235 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
236 return HandleSetContinuousTaskProcess(data, reply);
237 #endif
238 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_PIDS_BY_BUNDLENAME):
239 return HandleGetRunningProcessInformation(data, reply);
240 case static_cast<uint32_t>(AppMgrInterfaceCode::CHANGE_APP_GC_STATE):
241 return HandleChangeAppGcState(data, reply);
242 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_PAGE_SHOW):
243 return HandleNotifyPageShow(data, reply);
244 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_PAGE_HIDE):
245 return HandleNotifyPageHide(data, reply);
246 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APP_RUNNING_STATUS_LISTENER):
247 return HandleRegisterAppRunningStatusListener(data, reply);
248 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APP_RUNNING_STATUS_LISTENER):
249 return HandleUnregisterAppRunningStatusListener(data, reply);
250 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APP_FOREGROUND_STATE_OBSERVER):
251 return HandleRegisterAppForegroundStateObserver(data, reply);
252 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APP_FOREGROUND_STATE_OBSERVER):
253 return HandleUnregisterAppForegroundStateObserver(data, reply);
254 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER):
255 return HandleRegisterAbilityForegroundStateObserver(data, reply);
256 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER):
257 return HandleUnregisterAbilityForegroundStateObserver(data, reply);
258 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_APPLICATION_RUNNING):
259 return HandleIsApplicationRunning(data, reply);
260 case static_cast<uint32_t>(AppMgrInterfaceCode::START_CHILD_PROCESS):
261 return HandleStartChildProcess(data, reply);
262 }
263 return INVALID_FD;
264 }
265
OnRemoteRequestInnerSixth(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)266 int32_t AppMgrStub::OnRemoteRequestInnerSixth(uint32_t code, MessageParcel &data,
267 MessageParcel &reply, MessageOption &option)
268 {
269 switch (static_cast<uint32_t>(code)) {
270 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
271 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
272 return HandleSetContinuousTaskProcess(data, reply);
273 #endif
274 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_CHILD_PROCCESS_INFO_FOR_SELF):
275 return HandleGetChildProcessInfoForSelf(data, reply);
276 case static_cast<uint32_t>(AppMgrInterfaceCode::ATTACH_CHILD_PROCESS):
277 return HandleAttachChildProcess(data, reply);
278 case static_cast<uint32_t>(AppMgrInterfaceCode::EXIT_CHILD_PROCESS_SAFELY):
279 return HandleExitChildProcessSafely(data, reply);
280 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_FINAL_APP_PROCESS):
281 return HandleIsFinalAppProcess(data, reply);
282 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA_BY_SELF):
283 return HandleClearUpApplicationDataBySelf(data, reply);
284 case static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_RENDER_STATUS_OBSERVER):
285 return HandleRegisterRenderStateObserver(data, reply);
286 case static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_RENDER_STATUS_OBSERVER):
287 return HandleUnregisterRenderStateObserver(data, reply);
288 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_RENDER_STATUS):
289 return HandleUpdateRenderState(data, reply);
290 case static_cast<uint32_t>(AppMgrInterfaceCode::SIGN_RESTART_APP_FLAG):
291 return HandleSignRestartAppFlag(data, reply);
292 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_UNIQUE_ID_BY_PID):
293 return HandleGetAppRunningUniqueIdByPid(data, reply);
294 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_ROOT_HOST_PID):
295 return HandleGetAllUIExtensionRootHostPid(data, reply);
296 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_PROVIDER_PID):
297 return HandleGetAllUIExtensionProviderPid(data, reply);
298 }
299 return INVALID_FD;
300 }
301
OnRemoteRequestInnerSeventh(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)302 int32_t AppMgrStub::OnRemoteRequestInnerSeventh(uint32_t code, MessageParcel &data,
303 MessageParcel &reply, MessageOption &option)
304 {
305 switch (static_cast<uint32_t>(code)) {
306 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
307 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS):
308 return HandleSetContinuousTaskProcess(data, reply);
309 #endif
310 case static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION_BY_BUNDLE_NAME):
311 return HandleUpdateConfigurationByBundleName(data, reply);
312 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_MEMORY_SIZE_STATE_CHANGED):
313 return HandleNotifyMemorySizeStateChanged(data, reply);
314 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF):
315 return HandleSetSupportedProcessCacheSelf(data, reply);
316 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE):
317 return HandleSetSupportedProcessCache(data, reply);
318 case static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_BUNDLE_TYPE):
319 return HandleGetRunningProcessesByBundleType(data, reply);
320 case static_cast<uint32_t>(AppMgrInterfaceCode::SET_APP_ASSERT_PAUSE_STATE_SELF):
321 return HandleSetAppAssertionPauseState(data, reply);
322 case static_cast<uint32_t>(AppMgrInterfaceCode::START_NATIVE_CHILD_PROCESS):
323 return HandleStartNativeChildProcess(data, reply);
324 case static_cast<uint32_t>(AppMgrInterfaceCode::SAVE_BROWSER_CHANNEL):
325 return HandleSaveBrowserChannel(data, reply);
326 case static_cast<uint32_t>(AppMgrInterfaceCode::IS_APP_RUNNING):
327 return HandleIsAppRunning(data, reply);
328 case static_cast<uint32_t>(AppMgrInterfaceCode::CHECK_CALLING_IS_USER_TEST_MODE):
329 return HandleCheckCallingIsUserTestMode(data, reply);
330 case static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_PROCESS_DEPENDED_ON_WEB):
331 return HandleNotifyProcessDependedOnWeb(data, reply);
332 case static_cast<uint32_t>(AppMgrInterfaceCode::KILL_PROCESS_DEPENDED_ON_WEB):
333 return HandleKillProcessDependedOnWeb(data, reply);
334 case static_cast<uint32_t>(AppMgrInterfaceCode::RESTART_RESIDENT_PROCESS_DEPENDED_ON_WEB):
335 return HandleRestartResidentProcessDependedOnWeb(data, reply);
336 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES):
337 return HandleGetAllChildrenProcesses(data, reply);
338 case static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_INDEX_BY_PID):
339 return HandleGetAppIndexByPid(data, reply);
340 }
341 return INVALID_FD;
342 }
343
HandleAttachApplication(MessageParcel & data,MessageParcel & reply)344 int32_t AppMgrStub::HandleAttachApplication(MessageParcel &data, MessageParcel &reply)
345 {
346 HITRACE_METER(HITRACE_TAG_APP);
347 sptr<IRemoteObject> client = data.ReadRemoteObject();
348 if (client == nullptr) {
349 TAG_LOGE(AAFwkTag::APPMGR, "remote object null");
350 }
351 AttachApplication(client);
352 return NO_ERROR;
353 }
354
HandlePreloadApplication(MessageParcel & data,MessageParcel & reply)355 int32_t AppMgrStub::HandlePreloadApplication(MessageParcel &data, MessageParcel &reply)
356 {
357 HITRACE_METER(HITRACE_TAG_APP);
358 TAG_LOGD(AAFwkTag::APPMGR, "called");
359 std::string bundleName = Str16ToStr8(data.ReadString16());
360 int32_t userId = data.ReadInt32();
361 int32_t preloadMode = data.ReadInt32();
362 int32_t appIndex = data.ReadInt32();
363 auto result = PreloadApplication(bundleName, userId, static_cast<AppExecFwk::PreloadMode>(preloadMode), appIndex);
364 if (!reply.WriteInt32(result)) {
365 TAG_LOGE(AAFwkTag::APPMGR, "Stub HandlePreloadApplication Write result failed.");
366 return ERR_APPEXECFWK_PARCEL_ERROR;
367 }
368 return NO_ERROR;
369 }
370
HandleApplicationForegrounded(MessageParcel & data,MessageParcel & reply)371 int32_t AppMgrStub::HandleApplicationForegrounded(MessageParcel &data, MessageParcel &reply)
372 {
373 HITRACE_METER(HITRACE_TAG_APP);
374 ApplicationForegrounded(data.ReadInt32());
375 return NO_ERROR;
376 }
377
HandleApplicationBackgrounded(MessageParcel & data,MessageParcel & reply)378 int32_t AppMgrStub::HandleApplicationBackgrounded(MessageParcel &data, MessageParcel &reply)
379 {
380 HITRACE_METER(HITRACE_TAG_APP);
381 ApplicationBackgrounded(data.ReadInt32());
382 return NO_ERROR;
383 }
384
HandleApplicationTerminated(MessageParcel & data,MessageParcel & reply)385 int32_t AppMgrStub::HandleApplicationTerminated(MessageParcel &data, MessageParcel &reply)
386 {
387 HITRACE_METER(HITRACE_TAG_APP);
388 ApplicationTerminated(data.ReadInt32());
389 return NO_ERROR;
390 }
391
HandleAbilityCleaned(MessageParcel & data,MessageParcel & reply)392 int32_t AppMgrStub::HandleAbilityCleaned(MessageParcel &data, MessageParcel &reply)
393 {
394 HITRACE_METER(HITRACE_TAG_APP);
395 sptr<IRemoteObject> token = data.ReadRemoteObject();
396 AbilityCleaned(token);
397 return NO_ERROR;
398 }
399
HandleGetAmsMgr(MessageParcel & data,MessageParcel & reply)400 int32_t AppMgrStub::HandleGetAmsMgr(MessageParcel &data, MessageParcel &reply)
401 {
402 HITRACE_METER(HITRACE_TAG_APP);
403 int32_t result = NO_ERROR;
404 sptr<IAmsMgr> amsMgr = GetAmsMgr();
405 if (!amsMgr) {
406 TAG_LOGE(AAFwkTag::APPMGR, "abilitymgr instance is nullptr");
407 result = ERR_NO_INIT;
408 } else {
409 if (!reply.WriteRemoteObject(amsMgr->AsObject())) {
410 TAG_LOGE(AAFwkTag::APPMGR, "failed to reply abilitymgr instance to client, for write parcel error");
411 result = ERR_APPEXECFWK_PARCEL_ERROR;
412 }
413 }
414 reply.WriteInt32(result);
415 return NO_ERROR;
416 }
417
HandleClearUpApplicationData(MessageParcel & data,MessageParcel & reply)418 int32_t AppMgrStub::HandleClearUpApplicationData(MessageParcel &data, MessageParcel &reply)
419 {
420 HITRACE_METER(HITRACE_TAG_APP);
421 std::string bundleName = data.ReadString();
422 int32_t appCloneIndex = data.ReadInt32();
423 int32_t userId = data.ReadInt32();
424 int32_t result = ClearUpApplicationData(bundleName, appCloneIndex, userId);
425 reply.WriteInt32(result);
426 return NO_ERROR;
427 }
428
HandleClearUpApplicationDataBySelf(MessageParcel & data,MessageParcel & reply)429 int32_t AppMgrStub::HandleClearUpApplicationDataBySelf(MessageParcel &data, MessageParcel &reply)
430 {
431 HITRACE_METER(HITRACE_TAG_APP);
432 int32_t userId = data.ReadInt32();
433 int32_t result = ClearUpApplicationDataBySelf(userId);
434 reply.WriteInt32(result);
435 return NO_ERROR;
436 }
437
HandleGetAllRunningProcesses(MessageParcel & data,MessageParcel & reply)438 int32_t AppMgrStub::HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply)
439 {
440 HITRACE_METER(HITRACE_TAG_APP);
441 std::vector<RunningProcessInfo> info;
442 auto result = GetAllRunningProcesses(info);
443 reply.WriteInt32(info.size());
444 for (auto &it : info) {
445 if (!reply.WriteParcelable(&it)) {
446 return ERR_INVALID_VALUE;
447 }
448 }
449 if (!reply.WriteInt32(result)) {
450 return ERR_INVALID_VALUE;
451 }
452 return NO_ERROR;
453 }
454
HandleGetRunningMultiAppInfoByBundleName(MessageParcel & data,MessageParcel & reply)455 int32_t AppMgrStub::HandleGetRunningMultiAppInfoByBundleName(MessageParcel &data, MessageParcel &reply)
456 {
457 std::string bundleName = data.ReadString();
458 RunningMultiAppInfo info;
459 int32_t result = GetRunningMultiAppInfoByBundleName(bundleName, info);
460 if (!reply.WriteParcelable(&info)) {
461 return ERR_INVALID_VALUE;
462 }
463 if (!reply.WriteInt32(result)) {
464 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
465 return ERR_INVALID_VALUE;
466 }
467 return NO_ERROR;
468 }
469
HandleGetRunningProcessesByBundleType(MessageParcel & data,MessageParcel & reply)470 int32_t AppMgrStub::HandleGetRunningProcessesByBundleType(MessageParcel &data, MessageParcel &reply)
471 {
472 HITRACE_METER(HITRACE_TAG_APP);
473 int32_t bundleType = data.ReadInt32();
474 std::vector<RunningProcessInfo> info;
475 auto result = GetRunningProcessesByBundleType(static_cast<BundleType>(bundleType), info);
476 reply.WriteInt32(info.size());
477 for (auto &it : info) {
478 if (!reply.WriteParcelable(&it)) {
479 return ERR_INVALID_VALUE;
480 }
481 }
482 if (!reply.WriteInt32(result)) {
483 return ERR_INVALID_VALUE;
484 }
485 return NO_ERROR;
486 }
487
HandleGetProcessRunningInfosByUserId(MessageParcel & data,MessageParcel & reply)488 int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply)
489 {
490 HITRACE_METER(HITRACE_TAG_APP);
491 int32_t userId = data.ReadInt32();
492 std::vector<RunningProcessInfo> info;
493 auto result = GetProcessRunningInfosByUserId(info, userId);
494 reply.WriteInt32(info.size());
495 for (auto &it : info) {
496 if (!reply.WriteParcelable(&it)) {
497 return ERR_INVALID_VALUE;
498 }
499 }
500 if (!reply.WriteInt32(result)) {
501 return ERR_INVALID_VALUE;
502 }
503 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleGetAllRunningProcesses end");
504 return NO_ERROR;
505 }
506
HandleGetAllRenderProcesses(MessageParcel & data,MessageParcel & reply)507 int32_t AppMgrStub::HandleGetAllRenderProcesses(MessageParcel &data, MessageParcel &reply)
508 {
509 HITRACE_METER(HITRACE_TAG_APP);
510 std::vector<RenderProcessInfo> info;
511 auto result = GetAllRenderProcesses(info);
512 reply.WriteInt32(info.size());
513 for (auto &it : info) {
514 if (!reply.WriteParcelable(&it)) {
515 return ERR_INVALID_VALUE;
516 }
517 }
518 if (!reply.WriteInt32(result)) {
519 return ERR_INVALID_VALUE;
520 }
521 return NO_ERROR;
522 }
523
HandleGetAllChildrenProcesses(MessageParcel & data,MessageParcel & reply)524 int32_t AppMgrStub::HandleGetAllChildrenProcesses(MessageParcel &data, MessageParcel &reply)
525 {
526 HITRACE_METER(HITRACE_TAG_APP);
527 std::vector<ChildProcessInfo> info;
528 auto result = GetAllChildrenProcesses(info);
529 reply.WriteInt32(info.size());
530 for (auto &it : info) {
531 if (!reply.WriteParcelable(&it)) {
532 TAG_LOGE(AAFwkTag::APPMGR, "Write ChildProcessInfo faild, child pid=%{public}d", it.pid);
533 return ERR_INVALID_VALUE;
534 }
535 }
536 if (!reply.WriteInt32(result)) {
537 TAG_LOGE(AAFwkTag::APPMGR, "Write result faild");
538 return ERR_INVALID_VALUE;
539 }
540 return NO_ERROR;
541 }
542
HandleJudgeSandboxByPid(MessageParcel & data,MessageParcel & reply)543 int32_t AppMgrStub::HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply)
544 {
545 HITRACE_METER(HITRACE_TAG_APP);
546 int32_t pid = data.ReadInt32();
547 bool isSandbox = false;
548 auto result = JudgeSandboxByPid(pid, isSandbox);
549 if (!reply.WriteBool(isSandbox)) {
550 return ERR_INVALID_VALUE;
551 }
552 if (!reply.WriteInt32(result)) {
553 return ERR_INVALID_VALUE;
554 }
555 return NO_ERROR;
556 }
557
HandleGetProcessRunningInformation(MessageParcel & data,MessageParcel & reply)558 int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply)
559 {
560 HITRACE_METER(HITRACE_TAG_APP);
561 RunningProcessInfo info;
562 auto result = GetProcessRunningInformation(info);
563 if (!reply.WriteParcelable(&info)) {
564 return ERR_INVALID_VALUE;
565 }
566 if (!reply.WriteInt32(result)) {
567 return ERR_INVALID_VALUE;
568 }
569 return NO_ERROR;
570 }
571
HandleAddAbilityStageDone(MessageParcel & data,MessageParcel & reply)572 int32_t AppMgrStub::HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply)
573 {
574 int32_t recordId = data.ReadInt32();
575 AddAbilityStageDone(recordId);
576 return NO_ERROR;
577 }
578
HandleNotifyMemoryLevel(MessageParcel & data,MessageParcel & reply)579 int32_t AppMgrStub::HandleNotifyMemoryLevel(MessageParcel &data, MessageParcel &reply)
580 {
581 HITRACE_METER(HITRACE_TAG_APP);
582 int32_t level = data.ReadInt32();
583 auto result = NotifyMemoryLevel(level);
584 if (!reply.WriteInt32(result)) {
585 return ERR_INVALID_VALUE;
586 }
587 return NO_ERROR;
588 }
589
HandleNotifyProcMemoryLevel(MessageParcel & data,MessageParcel & reply)590 int32_t AppMgrStub::HandleNotifyProcMemoryLevel(MessageParcel &data, MessageParcel &reply)
591 {
592 HITRACE_METER(HITRACE_TAG_APP);
593 std::unique_ptr<MemoryLevelInfo> memoryLevelInfo(data.ReadParcelable<MemoryLevelInfo>());
594 if (memoryLevelInfo.get() == nullptr) {
595 return ERR_INVALID_VALUE;
596 }
597 auto result = NotifyProcMemoryLevel(memoryLevelInfo->GetProcLevelMap());
598 if (!reply.WriteInt32(result)) {
599 return ERR_INVALID_VALUE;
600 }
601 return NO_ERROR;
602 }
603
HandleDumpHeapMemory(MessageParcel & data,MessageParcel & reply)604 int32_t AppMgrStub::HandleDumpHeapMemory(MessageParcel &data, MessageParcel &reply)
605 {
606 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleDumpHeapMemory.");
607 HITRACE_METER(HITRACE_TAG_APP);
608 int32_t pid = data.ReadInt32();
609 struct OHOS::AppExecFwk::MallocInfo mallocInfo;
610 auto result = DumpHeapMemory(pid, mallocInfo);
611 if (result != NO_ERROR) {
612 return result;
613 }
614 reply.WriteParcelable(&mallocInfo);
615 return NO_ERROR;
616 }
617
HandleDumpJsHeapMemory(MessageParcel & data,MessageParcel & reply)618 int32_t AppMgrStub::HandleDumpJsHeapMemory(MessageParcel &data, MessageParcel &reply)
619 {
620 TAG_LOGD(AAFwkTag::APPMGR, "AppMgrStub::HandleDumpJsHeapMemory.");
621 HITRACE_METER(HITRACE_TAG_APP);
622 std::unique_ptr<JsHeapDumpInfo> info(data.ReadParcelable<JsHeapDumpInfo>());
623 if (info == nullptr) {
624 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
625 return ERR_INVALID_VALUE;
626 }
627 auto result = DumpJsHeapMemory(*info);
628 if (!reply.WriteInt32(result)) {
629 TAG_LOGE(AAFwkTag::APPMGR, "write result error");
630 return ERR_INVALID_VALUE;
631 }
632 return NO_ERROR;
633 }
634
HandleStartupResidentProcess(MessageParcel & data,MessageParcel & reply)635 int32_t AppMgrStub::HandleStartupResidentProcess(MessageParcel &data, MessageParcel &reply)
636 {
637 HITRACE_METER(HITRACE_TAG_APP);
638 std::vector<AppExecFwk::BundleInfo> bundleInfos;
639 int32_t infoSize = data.ReadInt32();
640 if (infoSize > CYCLE_LIMIT) {
641 TAG_LOGE(AAFwkTag::APPMGR, "infoSize is too large");
642 return ERR_INVALID_VALUE;
643 }
644 for (int32_t i = 0; i < infoSize; i++) {
645 std::unique_ptr<AppExecFwk::BundleInfo> bundleInfo(data.ReadParcelable<AppExecFwk::BundleInfo>());
646 if (!bundleInfo) {
647 TAG_LOGE(AAFwkTag::APPMGR, "Read Parcelable infos failed.");
648 return ERR_INVALID_VALUE;
649 }
650 bundleInfos.emplace_back(*bundleInfo);
651 }
652 StartupResidentProcess(bundleInfos);
653 return NO_ERROR;
654 }
655
HandleRegisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)656 int32_t AppMgrStub::HandleRegisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
657 {
658 std::vector<std::string> bundleNameList;
659 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
660 if (callback == nullptr) {
661 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
662 return ERR_INVALID_VALUE;
663 }
664 data.ReadStringVector(&bundleNameList);
665 int32_t result = RegisterApplicationStateObserver(callback, bundleNameList);
666 reply.WriteInt32(result);
667 return NO_ERROR;
668 }
669
HandleUnregisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)670 int32_t AppMgrStub::HandleUnregisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
671 {
672 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
673 if (callback == nullptr) {
674 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
675 return ERR_INVALID_VALUE;
676 }
677 int32_t result = UnregisterApplicationStateObserver(callback);
678 reply.WriteInt32(result);
679 return NO_ERROR;
680 }
681
HandleRegisterAbilityForegroundStateObserver(MessageParcel & data,MessageParcel & reply)682 int32_t AppMgrStub::HandleRegisterAbilityForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
683 {
684 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
685 auto callback = iface_cast<AppExecFwk::IAbilityForegroundStateObserver>(data.ReadRemoteObject());
686 if (callback == nullptr) {
687 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
688 return ERR_INVALID_VALUE;
689 }
690 int32_t result = RegisterAbilityForegroundStateObserver(callback);
691 if (!reply.WriteInt32(result)) {
692 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
693 return ERR_INVALID_VALUE;
694 }
695 return NO_ERROR;
696 }
697
HandleUnregisterAbilityForegroundStateObserver(MessageParcel & data,MessageParcel & reply)698 int32_t AppMgrStub::HandleUnregisterAbilityForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
699 {
700 auto callback = iface_cast<AppExecFwk::IAbilityForegroundStateObserver>(data.ReadRemoteObject());
701 int32_t result = UnregisterAbilityForegroundStateObserver(callback);
702 if (!reply.WriteInt32(result)) {
703 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
704 return ERR_INVALID_VALUE;
705 }
706 return NO_ERROR;
707 }
708
HandleGetForegroundApplications(MessageParcel & data,MessageParcel & reply)709 int32_t AppMgrStub::HandleGetForegroundApplications(MessageParcel &data, MessageParcel &reply)
710 {
711 std::vector<AppStateData> appStateDatas;
712 int32_t result = GetForegroundApplications(appStateDatas);
713 reply.WriteInt32(appStateDatas.size());
714 for (auto &it : appStateDatas) {
715 if (!reply.WriteParcelable(&it)) {
716 return ERR_INVALID_VALUE;
717 }
718 }
719 if (!reply.WriteInt32(result)) {
720 return ERR_INVALID_VALUE;
721 }
722 return result;
723 }
724
HandleStartUserTestProcess(MessageParcel & data,MessageParcel & reply)725 int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply)
726 {
727 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
728 if (want == nullptr) {
729 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
730 return ERR_INVALID_VALUE;
731 }
732 std::unique_ptr<BundleInfo> bundleInfo(data.ReadParcelable<BundleInfo>());
733 if (bundleInfo == nullptr) {
734 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
735 return ERR_INVALID_VALUE;
736 }
737 auto observer = data.ReadRemoteObject();
738 int32_t userId = data.ReadInt32();
739 int32_t result = StartUserTestProcess(*want, observer, *bundleInfo, userId);
740 reply.WriteInt32(result);
741 return result;
742 }
743
HandleFinishUserTest(MessageParcel & data,MessageParcel & reply)744 int32_t AppMgrStub::HandleFinishUserTest(MessageParcel &data, MessageParcel &reply)
745 {
746 std::string msg = data.ReadString();
747 int64_t resultCode = data.ReadInt64();
748 std::string bundleName = data.ReadString();
749 int32_t result = FinishUserTest(msg, resultCode, bundleName);
750 reply.WriteInt32(result);
751 return result;
752 }
753
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)754 int32_t AppMgrStub::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
755 const std::vector<std::string> &bundleNameList)
756 {
757 return NO_ERROR;
758 }
759
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)760 int32_t AppMgrStub::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
761 {
762 return NO_ERROR;
763 }
764
GetForegroundApplications(std::vector<AppStateData> & list)765 int32_t AppMgrStub::GetForegroundApplications(std::vector<AppStateData> &list)
766 {
767 return NO_ERROR;
768 }
769
HandleScheduleAcceptWantDone(MessageParcel & data,MessageParcel & reply)770 int32_t AppMgrStub::HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply)
771 {
772 auto recordId = data.ReadInt32();
773 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
774 if (want == nullptr) {
775 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
776 return ERR_INVALID_VALUE;
777 }
778 auto flag = data.ReadString();
779
780 ScheduleAcceptWantDone(recordId, *want, flag);
781 delete want;
782 return NO_ERROR;
783 }
784
HandleScheduleNewProcessRequestDone(MessageParcel & data,MessageParcel & reply)785 int32_t AppMgrStub::HandleScheduleNewProcessRequestDone(MessageParcel &data, MessageParcel &reply)
786 {
787 auto recordId = data.ReadInt32();
788 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
789 if (want == nullptr) {
790 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
791 return ERR_INVALID_VALUE;
792 }
793 auto flag = data.ReadString();
794
795 ScheduleNewProcessRequestDone(recordId, *want, flag);
796 delete want;
797 return NO_ERROR;
798 }
799
HandleGetAbilityRecordsByProcessID(MessageParcel & data,MessageParcel & reply)800 int32_t AppMgrStub::HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply)
801 {
802 HITRACE_METER(HITRACE_TAG_APP);
803 int32_t pid = data.ReadInt32();
804 std::vector<sptr<IRemoteObject>> tokens;
805 auto result = GetAbilityRecordsByProcessID(pid, tokens);
806 reply.WriteInt32(tokens.size());
807 for (auto &it : tokens) {
808 if (!reply.WriteRemoteObject(it)) {
809 TAG_LOGE(AAFwkTag::APPMGR, "failed to write query result.");
810 return ERR_FLATTEN_OBJECT;
811 }
812 }
813 if (!reply.WriteInt32(result)) {
814 return ERR_INVALID_VALUE;
815 }
816 return NO_ERROR;
817 }
818
HandlePreStartNWebSpawnProcess(MessageParcel & data,MessageParcel & reply)819 int32_t AppMgrStub::HandlePreStartNWebSpawnProcess(MessageParcel &data, MessageParcel &reply)
820 {
821 TAG_LOGI(AAFwkTag::APPMGR, "HandlePreNWebSpawnProcess");
822 int32_t result = PreStartNWebSpawnProcess();
823 if (!reply.WriteInt32(result)) {
824 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
825 return ERR_INVALID_VALUE;
826 }
827 return result;
828 }
829
HandleStartRenderProcess(MessageParcel & data,MessageParcel & reply)830 int32_t AppMgrStub::HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply)
831 {
832 std::string renderParam = data.ReadString();
833 int32_t ipcFd = data.ReadFileDescriptor();
834 int32_t sharedFd = data.ReadFileDescriptor();
835 int32_t crashFd = data.ReadFileDescriptor();
836 int32_t renderPid = 0;
837 bool isGPU = data.ReadBool();
838 int32_t result =
839 StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd, renderPid, isGPU);
840 if (!reply.WriteInt32(result)) {
841 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
842 return ERR_INVALID_VALUE;
843 }
844 if (!reply.WriteInt32(renderPid)) {
845 TAG_LOGE(AAFwkTag::APPMGR, "write renderPid error.");
846 return ERR_INVALID_VALUE;
847 }
848 return result;
849 }
850
HandleAttachRenderProcess(MessageParcel & data,MessageParcel & reply)851 int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply)
852 {
853 sptr<IRemoteObject> scheduler = data.ReadRemoteObject();
854 AttachRenderProcess(scheduler);
855 return NO_ERROR;
856 }
857
HandleSaveBrowserChannel(MessageParcel & data,MessageParcel & reply)858 int32_t AppMgrStub::HandleSaveBrowserChannel(MessageParcel &data, MessageParcel &reply)
859 {
860 sptr<IRemoteObject> browser = data.ReadRemoteObject();
861 SaveBrowserChannel(browser);
862 return NO_ERROR;
863 }
864
HandleGetRenderProcessTerminationStatus(MessageParcel & data,MessageParcel & reply)865 int32_t AppMgrStub::HandleGetRenderProcessTerminationStatus(MessageParcel &data, MessageParcel &reply)
866 {
867 int32_t renderPid = data.ReadInt32();
868 if (renderPid <= 0) {
869 TAG_LOGE(AAFwkTag::APPMGR, "invalid renderPid value");
870 return ERR_INVALID_VALUE;
871 }
872 int status = 0;
873 int32_t result = GetRenderProcessTerminationStatus(renderPid, status);
874 if (!reply.WriteInt32(result)) {
875 TAG_LOGE(AAFwkTag::APPMGR, "write result error.");
876 return ERR_INVALID_VALUE;
877 }
878 if (!reply.WriteInt32(status)) {
879 TAG_LOGE(AAFwkTag::APPMGR, "write status error.");
880 return ERR_INVALID_VALUE;
881 }
882 return result;
883 }
884
HandleGetConfiguration(MessageParcel & data,MessageParcel & reply)885 int32_t AppMgrStub::HandleGetConfiguration(MessageParcel &data, MessageParcel &reply)
886 {
887 Configuration config;
888 int ret = GetConfiguration(config);
889 if (ret != ERR_OK) {
890 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub GetConfiguration error");
891 return ERR_INVALID_VALUE;
892 }
893 if (!reply.WriteParcelable(&config)) {
894 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub GetConfiguration error");
895 return ERR_INVALID_VALUE;
896 }
897 if (!reply.WriteInt32(ret)) {
898 return ERR_INVALID_VALUE;
899 }
900 return NO_ERROR;
901 }
902
HandleUpdateConfiguration(MessageParcel & data,MessageParcel & reply)903 int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel &reply)
904 {
905 std::unique_ptr<Configuration> config(data.ReadParcelable<Configuration>());
906 if (!config) {
907 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
908 return ERR_INVALID_VALUE;
909 }
910 int32_t userId = data.ReadInt32();
911 int32_t ret = UpdateConfiguration(*config, userId);
912 if (!reply.WriteInt32(ret)) {
913 return ERR_INVALID_VALUE;
914 }
915 return NO_ERROR;
916 }
917
HandleUpdateConfigurationByBundleName(MessageParcel & data,MessageParcel & reply)918 int32_t AppMgrStub::HandleUpdateConfigurationByBundleName(MessageParcel &data, MessageParcel &reply)
919 {
920 std::unique_ptr<Configuration> config(data.ReadParcelable<Configuration>());
921 if (!config) {
922 TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
923 return ERR_INVALID_VALUE;
924 }
925 std::string name = data.ReadString();
926 int32_t ret = UpdateConfigurationByBundleName(*config, name);
927 if (!reply.WriteInt32(ret)) {
928 return ERR_INVALID_VALUE;
929 }
930 return NO_ERROR;
931 }
932
HandleRegisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)933 int32_t AppMgrStub::HandleRegisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
934 {
935 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
936 if (observer == nullptr) {
937 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
938 return ERR_INVALID_VALUE;
939 }
940 int32_t result = RegisterConfigurationObserver(observer);
941 reply.WriteInt32(result);
942 return NO_ERROR;
943 }
944
HandleUnregisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)945 int32_t AppMgrStub::HandleUnregisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
946 {
947 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
948 if (observer == nullptr) {
949 TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
950 return ERR_INVALID_VALUE;
951 }
952 int32_t result = UnregisterConfigurationObserver(observer);
953 reply.WriteInt32(result);
954 return NO_ERROR;
955 }
956
HandleGetAppRunningStateByBundleName(MessageParcel & data,MessageParcel & reply)957 int32_t AppMgrStub::HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply)
958 {
959 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
960 TAG_LOGD(AAFwkTag::APPMGR, "called");
961 std::string bundleName = data.ReadString();
962 auto ret = GetAppRunningStateByBundleName(bundleName);
963 if (!reply.WriteBool(ret)) {
964 return ERR_INVALID_VALUE;
965 }
966 return NO_ERROR;
967 }
968
HandleNotifyLoadRepairPatch(MessageParcel & data,MessageParcel & reply)969 int32_t AppMgrStub::HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
970 {
971 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
972 TAG_LOGD(AAFwkTag::APPMGR, "called");
973 std::string bundleName = data.ReadString();
974 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
975 if (callback == nullptr) {
976 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
977 return ERR_INVALID_VALUE;
978 }
979 auto ret = NotifyLoadRepairPatch(bundleName, callback);
980 if (!reply.WriteInt32(ret)) {
981 return ERR_INVALID_VALUE;
982 }
983 return NO_ERROR;
984 }
985
HandleNotifyHotReloadPage(MessageParcel & data,MessageParcel & reply)986 int32_t AppMgrStub::HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply)
987 {
988 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
989 TAG_LOGD(AAFwkTag::APPMGR, "called");
990 std::string bundleName = data.ReadString();
991 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
992 if (callback == nullptr) {
993 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
994 return ERR_INVALID_VALUE;
995 }
996 auto ret = NotifyHotReloadPage(bundleName, callback);
997 if (!reply.WriteInt32(ret)) {
998 return ERR_INVALID_VALUE;
999 }
1000 return NO_ERROR;
1001 }
1002
1003 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
HandleSetContinuousTaskProcess(MessageParcel & data,MessageParcel & reply)1004 int32_t AppMgrStub::HandleSetContinuousTaskProcess(MessageParcel &data, MessageParcel &reply)
1005 {
1006 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1007 TAG_LOGD(AAFwkTag::APPMGR, "called");
1008 int32_t pid = data.ReadInt32();
1009 bool isContinuousTask = data.ReadBool();
1010 auto ret = SetContinuousTaskProcess(pid, isContinuousTask);
1011 if (!reply.WriteInt32(ret)) {
1012 return ERR_INVALID_VALUE;
1013 }
1014 return NO_ERROR;
1015 }
1016 #endif
1017
HandleNotifyUnLoadRepairPatch(MessageParcel & data,MessageParcel & reply)1018 int32_t AppMgrStub::HandleNotifyUnLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
1019 {
1020 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1021 TAG_LOGD(AAFwkTag::APPMGR, "called");
1022 std::string bundleName = data.ReadString();
1023 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
1024 if (callback == nullptr) {
1025 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1026 return ERR_INVALID_VALUE;
1027 }
1028 auto ret = NotifyUnLoadRepairPatch(bundleName, callback);
1029 if (!reply.WriteInt32(ret)) {
1030 return ERR_INVALID_VALUE;
1031 }
1032 return NO_ERROR;
1033 }
1034
HandleIsSharedBundleRunning(MessageParcel & data,MessageParcel & reply)1035 int32_t AppMgrStub::HandleIsSharedBundleRunning(MessageParcel &data, MessageParcel &reply)
1036 {
1037 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1038 TAG_LOGD(AAFwkTag::APPMGR, "called");
1039 std::string bundleName = data.ReadString();
1040 uint32_t versionCode = data.ReadUint32();
1041 bool result = IsSharedBundleRunning(bundleName, versionCode);
1042 if (!reply.WriteBool(result)) {
1043 return ERR_INVALID_VALUE;
1044 }
1045 return NO_ERROR;
1046 }
1047
HandleStartNativeProcessForDebugger(MessageParcel & data,MessageParcel & reply)1048 int32_t AppMgrStub::HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply)
1049 {
1050 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1051 TAG_LOGD(AAFwkTag::APPMGR, "called");
1052 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
1053 if (want == nullptr) {
1054 TAG_LOGE(AAFwkTag::APPMGR, "want is nullptr");
1055 return ERR_INVALID_VALUE;
1056 }
1057 auto result = StartNativeProcessForDebugger(*want);
1058 if (!reply.WriteInt32(result)) {
1059 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1060 return ERR_INVALID_VALUE;
1061 }
1062 return NO_ERROR;
1063 }
1064
HandleGetBundleNameByPid(MessageParcel & data,MessageParcel & reply)1065 int32_t AppMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply)
1066 {
1067 int32_t pid = data.ReadInt32();
1068 std::string bundleName;
1069 int32_t uid;
1070 auto result = GetBundleNameByPid(pid, bundleName, uid);
1071 if (result != ERR_OK) {
1072 return result;
1073 }
1074
1075 if (!reply.WriteString(bundleName)) {
1076 return ERR_INVALID_VALUE;
1077 }
1078
1079 if (!reply.WriteInt32(uid)) {
1080 return ERR_INVALID_VALUE;
1081 }
1082 return NO_ERROR;
1083 }
1084
HandleGetRunningProcessInfoByPid(MessageParcel & data,MessageParcel & reply)1085 int32_t AppMgrStub::HandleGetRunningProcessInfoByPid(MessageParcel &data, MessageParcel &reply)
1086 {
1087 RunningProcessInfo processInfo;
1088 auto pid = static_cast<pid_t>(data.ReadInt32());
1089 auto result = GetRunningProcessInfoByPid(pid, processInfo);
1090 if (reply.WriteParcelable(&processInfo)) {
1091 TAG_LOGE(AAFwkTag::APPMGR, "failed");
1092 return ERR_INVALID_VALUE;
1093 }
1094 if (!reply.WriteInt32(result)) {
1095 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1096 return ERR_INVALID_VALUE;
1097 }
1098 return NO_ERROR;
1099 }
1100
HandleNotifyFault(MessageParcel & data,MessageParcel & reply)1101 int32_t AppMgrStub::HandleNotifyFault(MessageParcel &data, MessageParcel &reply)
1102 {
1103 std::unique_ptr<FaultData> faultData(data.ReadParcelable<FaultData>());
1104 if (faultData == nullptr) {
1105 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<FaultData> failed");
1106 return ERR_INVALID_VALUE;
1107 }
1108
1109 int32_t result = NotifyAppFault(*faultData);
1110 if (!reply.WriteInt32(result)) {
1111 TAG_LOGE(AAFwkTag::APPMGR, "reply write failed.");
1112 return ERR_INVALID_VALUE;
1113 }
1114 return NO_ERROR;
1115 }
1116
HandleNotifyFaultBySA(MessageParcel & data,MessageParcel & reply)1117 int32_t AppMgrStub::HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &reply)
1118 {
1119 std::unique_ptr<AppFaultDataBySA> faultData(data.ReadParcelable<AppFaultDataBySA>());
1120 if (faultData == nullptr) {
1121 TAG_LOGE(AAFwkTag::APPMGR, "ReadParcelable<AppFaultDataBySA> failed");
1122 return ERR_INVALID_VALUE;
1123 }
1124
1125 int32_t result = NotifyAppFaultBySA(*faultData);
1126 if (!reply.WriteInt32(result)) {
1127 TAG_LOGE(AAFwkTag::APPMGR, "reply write failed.");
1128 return ERR_INVALID_VALUE;
1129 }
1130 return NO_ERROR;
1131 }
1132
HandleSetAppFreezeFilter(MessageParcel & data,MessageParcel & reply)1133 int32_t AppMgrStub::HandleSetAppFreezeFilter(MessageParcel &data, MessageParcel &reply)
1134 {
1135 int32_t pid = data.ReadInt32();
1136 bool result = SetAppFreezeFilter(pid);
1137 if (!reply.WriteBool(result)) {
1138 TAG_LOGE(AAFwkTag::APPMGR, "reply write failed.");
1139 return ERR_INVALID_VALUE;
1140 }
1141 return NO_ERROR;
1142 }
1143
HandleGetProcessMemoryByPid(MessageParcel & data,MessageParcel & reply)1144 int32_t AppMgrStub::HandleGetProcessMemoryByPid(MessageParcel &data, MessageParcel &reply)
1145 {
1146 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1147 int32_t pid = data.ReadInt32();
1148 int32_t memorySize = 0;
1149 auto result = GetProcessMemoryByPid(pid, memorySize);
1150 if (!reply.WriteInt32(memorySize)) {
1151 TAG_LOGE(AAFwkTag::APPMGR, "Memory size write failed.");
1152 return ERR_INVALID_VALUE;
1153 }
1154 if (!reply.WriteInt32(result)) {
1155 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1156 return ERR_INVALID_VALUE;
1157 }
1158 return NO_ERROR;
1159 }
1160
HandleGetRunningProcessInformation(MessageParcel & data,MessageParcel & reply)1161 int32_t AppMgrStub::HandleGetRunningProcessInformation(MessageParcel &data, MessageParcel &reply)
1162 {
1163 HITRACE_METER(HITRACE_TAG_APP);
1164 std::string bundleName = data.ReadString();
1165 int32_t userId = data.ReadInt32();
1166 std::vector<RunningProcessInfo> info;
1167 auto result = GetRunningProcessInformation(bundleName, userId, info);
1168 reply.WriteInt32(info.size());
1169 for (auto &it : info) {
1170 if (!reply.WriteParcelable(&it)) {
1171 return ERR_INVALID_VALUE;
1172 }
1173 }
1174 if (!reply.WriteInt32(result)) {
1175 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1176 return ERR_INVALID_VALUE;
1177 }
1178 return NO_ERROR;
1179 }
1180
HandleChangeAppGcState(MessageParcel & data,MessageParcel & reply)1181 int32_t AppMgrStub::HandleChangeAppGcState(MessageParcel &data, MessageParcel &reply)
1182 {
1183 HITRACE_METER(HITRACE_TAG_APP);
1184 int32_t pid = data.ReadInt32();
1185 int32_t state = data.ReadInt32();
1186 int32_t ret = ChangeAppGcState(pid, state);
1187 reply.WriteInt32(ret);
1188 return NO_ERROR;
1189 }
1190
HandleNotifyPageShow(MessageParcel & data,MessageParcel & reply)1191 int32_t AppMgrStub::HandleNotifyPageShow(MessageParcel &data, MessageParcel &reply)
1192 {
1193 sptr<IRemoteObject> token = data.ReadRemoteObject();
1194 std::unique_ptr<PageStateData> pageStateData(data.ReadParcelable<PageStateData>());
1195 if (token == nullptr || pageStateData == nullptr) {
1196 TAG_LOGE(AAFwkTag::APPMGR, "read data failed");
1197 return ERR_INVALID_VALUE;
1198 }
1199
1200 auto result = NotifyPageShow(token, *pageStateData);
1201 if (!reply.WriteInt32(result)) {
1202 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1203 return ERR_INVALID_VALUE;
1204 }
1205 return NO_ERROR;
1206 }
1207
HandleNotifyPageHide(MessageParcel & data,MessageParcel & reply)1208 int32_t AppMgrStub::HandleNotifyPageHide(MessageParcel &data, MessageParcel &reply)
1209 {
1210 sptr<IRemoteObject> token = data.ReadRemoteObject();
1211 std::unique_ptr<PageStateData> pageStateData(data.ReadParcelable<PageStateData>());
1212 if (token == nullptr || pageStateData == nullptr) {
1213 TAG_LOGE(AAFwkTag::APPMGR, "read data failed");
1214 return ERR_INVALID_VALUE;
1215 }
1216
1217 auto result = NotifyPageHide(token, *pageStateData);
1218 if (!reply.WriteInt32(result)) {
1219 TAG_LOGE(AAFwkTag::APPMGR, "fail to write result.");
1220 return ERR_INVALID_VALUE;
1221 }
1222 return NO_ERROR;
1223 }
1224
HandleRegisterAppRunningStatusListener(MessageParcel & data,MessageParcel & reply)1225 int32_t AppMgrStub::HandleRegisterAppRunningStatusListener(MessageParcel &data, MessageParcel &reply)
1226 {
1227 auto listener = data.ReadRemoteObject();
1228 if (listener == nullptr) {
1229 TAG_LOGE(AAFwkTag::APPMGR, "Read data failed.");
1230 return ERR_INVALID_VALUE;
1231 }
1232
1233 auto result = RegisterAppRunningStatusListener(listener);
1234 if (!reply.WriteInt32(result)) {
1235 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1236 return ERR_INVALID_VALUE;
1237 }
1238 return NO_ERROR;
1239 }
1240
HandleUnregisterAppRunningStatusListener(MessageParcel & data,MessageParcel & reply)1241 int32_t AppMgrStub::HandleUnregisterAppRunningStatusListener(MessageParcel &data, MessageParcel &reply)
1242 {
1243 auto listener = data.ReadRemoteObject();
1244 if (listener == nullptr) {
1245 TAG_LOGE(AAFwkTag::APPMGR, "Read data failed.");
1246 return ERR_INVALID_VALUE;
1247 }
1248
1249 auto result = UnregisterAppRunningStatusListener(listener);
1250 if (!reply.WriteInt32(result)) {
1251 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1252 return ERR_INVALID_VALUE;
1253 }
1254 return NO_ERROR;
1255 }
1256
HandleRegisterAppForegroundStateObserver(MessageParcel & data,MessageParcel & reply)1257 int32_t AppMgrStub::HandleRegisterAppForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
1258 {
1259 auto callback = iface_cast<AppExecFwk::IAppForegroundStateObserver>(data.ReadRemoteObject());
1260 if (callback == nullptr) {
1261 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1262 return ERR_INVALID_VALUE;
1263 }
1264 int32_t result = RegisterAppForegroundStateObserver(callback);
1265 if (!reply.WriteInt32(result)) {
1266 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1267 return ERR_INVALID_VALUE;
1268 }
1269 return NO_ERROR;
1270 }
1271
HandleUnregisterAppForegroundStateObserver(MessageParcel & data,MessageParcel & reply)1272 int32_t AppMgrStub::HandleUnregisterAppForegroundStateObserver(MessageParcel &data, MessageParcel &reply)
1273 {
1274 auto callback = iface_cast<AppExecFwk::IAppForegroundStateObserver>(data.ReadRemoteObject());
1275 if (callback == nullptr) {
1276 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1277 return ERR_INVALID_VALUE;
1278 }
1279 int32_t result = UnregisterAppForegroundStateObserver(callback);
1280 if (!reply.WriteInt32(result)) {
1281 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1282 return ERR_INVALID_VALUE;
1283 }
1284 return NO_ERROR;
1285 }
1286
HandleIsApplicationRunning(MessageParcel & data,MessageParcel & reply)1287 int32_t AppMgrStub::HandleIsApplicationRunning(MessageParcel &data, MessageParcel &reply)
1288 {
1289 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1290 TAG_LOGD(AAFwkTag::APPMGR, "called");
1291 std::string bundleName = data.ReadString();
1292 bool isRunning = false;
1293 int32_t result = IsApplicationRunning(bundleName, isRunning);
1294 if (!reply.WriteBool(isRunning)) {
1295 return ERR_INVALID_VALUE;
1296 }
1297 if (!reply.WriteInt32(result)) {
1298 return ERR_INVALID_VALUE;
1299 }
1300 return NO_ERROR;
1301 }
1302
HandleIsAppRunning(MessageParcel & data,MessageParcel & reply)1303 int32_t AppMgrStub::HandleIsAppRunning(MessageParcel &data, MessageParcel &reply)
1304 {
1305 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1306 TAG_LOGD(AAFwkTag::APPMGR, "called");
1307 std::string bundleName = data.ReadString();
1308 bool isRunning = false;
1309 int32_t appCloneIndex = data.ReadInt32();
1310 int32_t result = IsAppRunning(bundleName, appCloneIndex, isRunning);
1311 if (!reply.WriteBool(isRunning)) {
1312 return ERR_INVALID_VALUE;
1313 }
1314 if (!reply.WriteInt32(result)) {
1315 return ERR_INVALID_VALUE;
1316 }
1317 return NO_ERROR;
1318 }
1319
HandleStartChildProcess(MessageParcel & data,MessageParcel & reply)1320 int32_t AppMgrStub::HandleStartChildProcess(MessageParcel &data, MessageParcel &reply)
1321 {
1322 TAG_LOGD(AAFwkTag::APPMGR, "called");
1323 std::unique_ptr<ChildProcessRequest> request(data.ReadParcelable<ChildProcessRequest>());
1324 if (!request) {
1325 return IPC_STUB_ERR;
1326 }
1327 int32_t childPid = 0;
1328 int32_t result = StartChildProcess(childPid, *request);
1329 if (!reply.WriteInt32(result)) {
1330 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1331 return IPC_STUB_ERR;
1332 }
1333 if (result == ERR_OK && !reply.WriteInt32(childPid)) {
1334 TAG_LOGE(AAFwkTag::APPMGR, "Write childPid error.");
1335 return IPC_STUB_ERR;
1336 }
1337 return NO_ERROR;
1338 }
1339
HandleGetChildProcessInfoForSelf(MessageParcel & data,MessageParcel & reply)1340 int32_t AppMgrStub::HandleGetChildProcessInfoForSelf(MessageParcel &data, MessageParcel &reply)
1341 {
1342 TAG_LOGD(AAFwkTag::APPMGR, "called");
1343 ChildProcessInfo info;
1344 auto result = GetChildProcessInfoForSelf(info);
1345 if (!reply.WriteInt32(result)) {
1346 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1347 return ERR_INVALID_VALUE;
1348 }
1349 if (result == ERR_OK && !reply.WriteParcelable(&info)) {
1350 return ERR_INVALID_VALUE;
1351 }
1352 return NO_ERROR;
1353 }
1354
HandleAttachChildProcess(MessageParcel & data,MessageParcel & reply)1355 int32_t AppMgrStub::HandleAttachChildProcess(MessageParcel &data, MessageParcel &reply)
1356 {
1357 TAG_LOGD(AAFwkTag::APPMGR, "called");
1358 sptr<IRemoteObject> scheduler = data.ReadRemoteObject();
1359 AttachChildProcess(scheduler);
1360 return NO_ERROR;
1361 }
1362
HandleExitChildProcessSafely(MessageParcel & data,MessageParcel & reply)1363 int32_t AppMgrStub::HandleExitChildProcessSafely(MessageParcel &data, MessageParcel &reply)
1364 {
1365 TAG_LOGD(AAFwkTag::APPMGR, "called");
1366 ExitChildProcessSafely();
1367 return NO_ERROR;
1368 }
1369
HandleIsFinalAppProcess(MessageParcel & data,MessageParcel & reply)1370 int32_t AppMgrStub::HandleIsFinalAppProcess(MessageParcel &data, MessageParcel &reply)
1371 {
1372 TAG_LOGD(AAFwkTag::APPMGR, "called");
1373 if (!reply.WriteBool(IsFinalAppProcess())) {
1374 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write bool result.");
1375 return ERR_INVALID_VALUE;
1376 }
1377 return NO_ERROR;
1378 }
1379
HandleRegisterRenderStateObserver(MessageParcel & data,MessageParcel & reply)1380 int32_t AppMgrStub::HandleRegisterRenderStateObserver(MessageParcel &data, MessageParcel &reply)
1381 {
1382 TAG_LOGD(AAFwkTag::APPMGR, "called");
1383 auto callback = iface_cast<AppExecFwk::IRenderStateObserver>(data.ReadRemoteObject());
1384 if (callback == nullptr) {
1385 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1386 return ERR_INVALID_VALUE;
1387 }
1388 int32_t result = RegisterRenderStateObserver(callback);
1389 if (!reply.WriteInt32(result)) {
1390 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1391 return ERR_INVALID_VALUE;
1392 }
1393 return NO_ERROR;
1394 }
1395
HandleUnregisterRenderStateObserver(MessageParcel & data,MessageParcel & reply)1396 int32_t AppMgrStub::HandleUnregisterRenderStateObserver(MessageParcel &data, MessageParcel &reply)
1397 {
1398 TAG_LOGD(AAFwkTag::APPMGR, "called");
1399 auto callback = iface_cast<AppExecFwk::IRenderStateObserver>(data.ReadRemoteObject());
1400 if (callback == nullptr) {
1401 TAG_LOGE(AAFwkTag::APPMGR, "Callback is null.");
1402 return ERR_INVALID_VALUE;
1403 }
1404 int32_t result = UnregisterRenderStateObserver(callback);
1405 if (!reply.WriteInt32(result)) {
1406 TAG_LOGE(AAFwkTag::APPMGR, "Fail to write result.");
1407 return ERR_INVALID_VALUE;
1408 }
1409 return NO_ERROR;
1410 }
1411
HandleUpdateRenderState(MessageParcel & data,MessageParcel & reply)1412 int32_t AppMgrStub::HandleUpdateRenderState(MessageParcel &data, MessageParcel &reply)
1413 {
1414 TAG_LOGD(AAFwkTag::APPMGR, "called");
1415 int32_t pid = data.ReadInt32();
1416 int32_t state = data.ReadInt32();
1417 int32_t result = UpdateRenderState(pid, state);
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
HandleSignRestartAppFlag(MessageParcel & data,MessageParcel & reply)1425 int32_t AppMgrStub::HandleSignRestartAppFlag(MessageParcel &data, MessageParcel &reply)
1426 {
1427 TAG_LOGD(AAFwkTag::APPMGR, "called");
1428 auto uid = data.ReadInt32();
1429 auto ret = SignRestartAppFlag(uid);
1430 if (!reply.WriteInt32(ret)) {
1431 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1432 return IPC_STUB_ERR;
1433 }
1434 return NO_ERROR;
1435 }
1436
HandleGetAppRunningUniqueIdByPid(MessageParcel & data,MessageParcel & reply)1437 int32_t AppMgrStub::HandleGetAppRunningUniqueIdByPid(MessageParcel &data, MessageParcel &reply)
1438 {
1439 TAG_LOGD(AAFwkTag::APPMGR, "called");
1440 int32_t pid = data.ReadInt32();
1441 std::string appRunningUniqueId;
1442 int32_t result = GetAppRunningUniqueIdByPid(pid, appRunningUniqueId);
1443 if (!reply.WriteInt32(result)) {
1444 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1445 return IPC_STUB_ERR;
1446 }
1447 if (result == ERR_OK && !reply.WriteString(appRunningUniqueId)) {
1448 TAG_LOGE(AAFwkTag::APPMGR, "GetAppRunningUniqueIdByPid err or Write appRunningUniqueId error.");
1449 return IPC_STUB_ERR;
1450 }
1451
1452 return NO_ERROR;
1453 }
1454
HandleGetAllUIExtensionRootHostPid(MessageParcel & data,MessageParcel & reply)1455 int32_t AppMgrStub::HandleGetAllUIExtensionRootHostPid(MessageParcel &data, MessageParcel &reply)
1456 {
1457 pid_t pid = data.ReadInt32();
1458 std::vector<pid_t> hostPids;
1459 auto result = GetAllUIExtensionRootHostPid(pid, hostPids);
1460 reply.WriteInt32(hostPids.size());
1461 for (auto &it : hostPids) {
1462 if (!reply.WriteInt32(it)) {
1463 TAG_LOGE(AAFwkTag::APPMGR, "Write host pid failed.");
1464 return ERR_INVALID_VALUE;
1465 }
1466 }
1467
1468 if (!reply.WriteInt32(result)) {
1469 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
1470 return ERR_INVALID_VALUE;
1471 }
1472
1473 return NO_ERROR;
1474 }
1475
HandleGetAllUIExtensionProviderPid(MessageParcel & data,MessageParcel & reply)1476 int32_t AppMgrStub::HandleGetAllUIExtensionProviderPid(MessageParcel &data, MessageParcel &reply)
1477 {
1478 pid_t hostPid = data.ReadInt32();
1479 std::vector<pid_t> providerPids;
1480 auto result = GetAllUIExtensionProviderPid(hostPid, providerPids);
1481 reply.WriteInt32(providerPids.size());
1482 for (auto &it : providerPids) {
1483 if (!reply.WriteInt32(it)) {
1484 TAG_LOGE(AAFwkTag::APPMGR, "Write provider pid failed.");
1485 return ERR_INVALID_VALUE;
1486 }
1487 }
1488
1489 if (!reply.WriteInt32(result)) {
1490 TAG_LOGE(AAFwkTag::APPMGR, "Write result failed.");
1491 return ERR_INVALID_VALUE;
1492 }
1493
1494 return NO_ERROR;
1495 }
1496
HandleNotifyMemorySizeStateChanged(MessageParcel & data,MessageParcel & reply)1497 int32_t AppMgrStub::HandleNotifyMemorySizeStateChanged(MessageParcel &data, MessageParcel &reply)
1498 {
1499 bool isMemorySizeSufficent = data.ReadBool();
1500 int result = NotifyMemorySizeStateChanged(isMemorySizeSufficent);
1501 if (!reply.WriteInt32(result)) {
1502 TAG_LOGE(AAFwkTag::APPMGR, "Write result error.");
1503 return ERR_INVALID_VALUE;
1504 }
1505 return NO_ERROR;
1506 }
1507
HandleSetSupportedProcessCache(MessageParcel & data,MessageParcel & reply)1508 int32_t AppMgrStub::HandleSetSupportedProcessCache(MessageParcel &data, MessageParcel &reply)
1509 {
1510 TAG_LOGD(AAFwkTag::APPMGR, "called");
1511 bool isSupport = data.ReadBool();
1512 int32_t pid = data.ReadInt32();
1513 auto ret = SetSupportedProcessCache(pid, isSupport);
1514 if (!reply.WriteInt32(ret)) {
1515 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1516 return IPC_STUB_ERR;
1517 }
1518 return NO_ERROR;
1519 }
1520
HandleSetAppAssertionPauseState(MessageParcel & data,MessageParcel & reply)1521 int32_t AppMgrStub::HandleSetAppAssertionPauseState(MessageParcel &data, MessageParcel &reply)
1522 {
1523 TAG_LOGD(AAFwkTag::APPMGR, "called");
1524 bool flag = data.ReadBool();
1525 SetAppAssertionPauseState(flag);
1526 return NO_ERROR;
1527 }
1528
HandleSetSupportedProcessCacheSelf(MessageParcel & data,MessageParcel & reply)1529 int32_t AppMgrStub::HandleSetSupportedProcessCacheSelf(MessageParcel &data, MessageParcel &reply)
1530 {
1531 TAG_LOGD(AAFwkTag::APPMGR, "called");
1532 bool isSupport = data.ReadBool();
1533 auto ret = SetSupportedProcessCacheSelf(isSupport);
1534 if (!reply.WriteInt32(ret)) {
1535 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1536 return IPC_STUB_ERR;
1537 }
1538 return NO_ERROR;
1539 }
1540
HandleCheckCallingIsUserTestMode(MessageParcel & data,MessageParcel & reply)1541 int32_t AppMgrStub::HandleCheckCallingIsUserTestMode(MessageParcel &data, MessageParcel &reply)
1542 {
1543 TAG_LOGD(AAFwkTag::APPMGR, "called");
1544 pid_t pid = data.ReadInt32();
1545 bool isUserTest = false;
1546 int32_t ret = CheckCallingIsUserTestMode(pid, isUserTest);
1547 if (!reply.WriteBool(isUserTest)) {
1548 TAG_LOGE(AAFwkTag::APPMGR, "Write isUserTest error.");
1549 return IPC_STUB_ERR;
1550 }
1551 if (!reply.WriteInt32(ret)) {
1552 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1553 return IPC_STUB_ERR;
1554 }
1555 return NO_ERROR;
1556 }
1557
HandleStartNativeChildProcess(MessageParcel & data,MessageParcel & reply)1558 int32_t AppMgrStub::HandleStartNativeChildProcess(MessageParcel &data, MessageParcel &reply)
1559 {
1560 TAG_LOGD(AAFwkTag::APPMGR, "Called.");
1561 std::string libName = data.ReadString();
1562 int32_t childCount = data.ReadInt32();
1563 sptr<IRemoteObject> callback = data.ReadRemoteObject();
1564 int32_t result = StartNativeChildProcess(libName, childCount, callback);
1565 if (!reply.WriteInt32(result)) {
1566 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1567 return IPC_STUB_ERR;
1568 }
1569
1570 return NO_ERROR;
1571 }
1572
HandleNotifyProcessDependedOnWeb(MessageParcel & data,MessageParcel & reply)1573 int32_t AppMgrStub::HandleNotifyProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply)
1574 {
1575 TAG_LOGD(AAFwkTag::APPMGR, "call");
1576 int32_t ret = NotifyProcessDependedOnWeb();
1577 if (!reply.WriteInt32(ret)) {
1578 TAG_LOGE(AAFwkTag::APPMGR, "Write ret error.");
1579 return IPC_STUB_ERR;
1580 }
1581
1582 return NO_ERROR;
1583 }
1584
HandleKillProcessDependedOnWeb(MessageParcel & data,MessageParcel & reply)1585 int32_t AppMgrStub::HandleKillProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply)
1586 {
1587 TAG_LOGD(AAFwkTag::APPMGR, "call");
1588 KillProcessDependedOnWeb();
1589 return NO_ERROR;
1590 }
1591
HandleRestartResidentProcessDependedOnWeb(MessageParcel & data,MessageParcel & reply)1592 int32_t AppMgrStub::HandleRestartResidentProcessDependedOnWeb(MessageParcel &data, MessageParcel &reply)
1593 {
1594 TAG_LOGD(AAFwkTag::APPMGR, "call");
1595 RestartResidentProcessDependedOnWeb();
1596 return NO_ERROR;
1597 }
1598
HandleGetAppIndexByPid(MessageParcel & data,MessageParcel & reply)1599 int32_t AppMgrStub::HandleGetAppIndexByPid(MessageParcel &data, MessageParcel &reply)
1600 {
1601 TAG_LOGD(AAFwkTag::APPMGR, "call");
1602 auto pid = data.ReadInt32();
1603 int32_t appIndex = -1;
1604 int32_t result = GetAppIndexByPid(pid, appIndex);
1605 if (!reply.WriteInt32(result)) {
1606 TAG_LOGE(AAFwkTag::APPMGR, "fail to write GetAppIndexByPid result.");
1607 return IPC_STUB_ERR;
1608 }
1609 if (!reply.WriteInt32(appIndex)) {
1610 TAG_LOGE(AAFwkTag::APPMGR, "fail to write appIndex.");
1611 return IPC_STUB_ERR;
1612 }
1613 return NO_ERROR;
1614 }
1615 } // namespace AppExecFwk
1616 } // namespace OHOS
1617