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