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