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