1 /*
2 * Copyright (c) 2021-2023 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 "ipc_skeleton.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21
22 #include "ability_info.h"
23 #include "app_mgr_proxy.h"
24 #include "app_scheduler_interface.h"
25 #include "appexecfwk_errors.h"
26 #include "hitrace_meter.h"
27 #include "hilog_wrapper.h"
28 #include "iapp_state_callback.h"
29 #include "want.h"
30 #include "bundle_info.h"
31 #include "app_malloc_info.h"
32
33 namespace OHOS {
34 namespace AppExecFwk {
35 constexpr int32_t CYCLE_LIMIT = 1000;
AppMgrStub()36 AppMgrStub::AppMgrStub()
37 {
38 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_ATTACH_APPLICATION)] =
39 &AppMgrStub::HandleAttachApplication;
40 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_FOREGROUNDED)] =
41 &AppMgrStub::HandleApplicationForegrounded;
42 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_BACKGROUNDED)] =
43 &AppMgrStub::HandleApplicationBackgrounded;
44 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_APPLICATION_TERMINATED)] =
45 &AppMgrStub::HandleApplicationTerminated;
46 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_CHECK_PERMISSION)] =
47 &AppMgrStub::HandleCheckPermission;
48 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_ABILITY_CLEANED)] =
49 &AppMgrStub::HandleAbilityCleaned;
50 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_MGR_INSTANCE)] = &AppMgrStub::HandleGetAmsMgr;
51 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_CLEAR_UP_APPLICATION_DATA)] =
52 &AppMgrStub::HandleClearUpApplicationData;
53 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RUNNING_PROCESSES)] =
54 &AppMgrStub::HandleGetAllRunningProcesses;
55 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_NOTIFY_MEMORY_LEVEL)] =
56 &AppMgrStub::HandleNotifyMemoryLevel;
57 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID)] =
58 &AppMgrStub::HandleGetProcessRunningInfosByUserId;
59 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_ADD_ABILITY_STAGE_INFO_DONE)] =
60 &AppMgrStub::HandleAddAbilityStageDone;
61 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::STARTUP_RESIDENT_PROCESS)] =
62 &AppMgrStub::HandleStartupResidentProcess;
63 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_APPLICATION_STATE_OBSERVER)] =
64 &AppMgrStub::HandleRegisterApplicationStateObserver;
65 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_APPLICATION_STATE_OBSERVER)] =
66 &AppMgrStub::HandleUnregisterApplicationStateObserver;
67 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::GET_FOREGROUND_APPLICATIONS)] =
68 &AppMgrStub::HandleGetForegroundApplications;
69 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::START_USER_TEST_PROCESS)] =
70 &AppMgrStub::HandleStartUserTestProcess;
71 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::FINISH_USER_TEST)] =
72 &AppMgrStub::HandleFinishUserTest;
73 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::SCHEDULE_ACCEPT_WANT_DONE)] =
74 &AppMgrStub::HandleScheduleAcceptWantDone;
75 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID)] =
76 &AppMgrStub::HandleGetAbilityRecordsByProcessID;
77 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS)] =
78 &AppMgrStub::HandlePreStartNWebSpawnProcess;
79 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::START_RENDER_PROCESS)] =
80 &AppMgrStub::HandleStartRenderProcess;
81 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::ATTACH_RENDER_PROCESS)] =
82 &AppMgrStub::HandleAttachRenderProcess;
83 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::GET_RENDER_PROCESS_TERMINATION_STATUS)] =
84 &AppMgrStub::HandleGetRenderProcessTerminationStatus;
85 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::GET_CONFIGURATION)] =
86 &AppMgrStub::HandleGetConfiguration;
87 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::UPDATE_CONFIGURATION)] =
88 &AppMgrStub::HandleUpdateConfiguration;
89 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER)] =
90 &AppMgrStub::HandleRegisterConfigurationObserver;
91 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_CONFIGURATION_OBSERVER)] =
92 &AppMgrStub::HandleUnregisterConfigurationObserver;
93 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_PROCESS_RUNNING_INFORMATION)] =
94 &AppMgrStub::HandleGetProcessRunningInformation;
95 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::DUMP_HEAP_MEMORY_PROCESS)] =
96 &AppMgrStub::HandleDumpHeapMemory;
97 #ifdef ABILITY_COMMAND_FOR_TEST
98 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::BLOCK_APP_SERVICE)] =
99 &AppMgrStub::HandleBlockAppServiceDone;
100 #endif
101 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_STATE)] =
102 &AppMgrStub::HandleGetAppRunningStateByBundleName;
103 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_LOAD_REPAIR_PATCH)] =
104 &AppMgrStub::HandleNotifyLoadRepairPatch;
105 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_HOT_RELOAD_PAGE)] =
106 &AppMgrStub::HandleNotifyHotReloadPage;
107 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
108 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::SET_CONTINUOUSTASK_PROCESS)] =
109 &AppMgrStub::HandleSetContinuousTaskProcess;
110 #endif
111 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH)] =
112 &AppMgrStub::HandleNotifyUnLoadRepairPatch;
113 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::IS_SHARED_BUNDLE_RUNNING)] =
114 &AppMgrStub::HandleIsSharedBundleRunning;
115 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::START_NATIVE_PROCESS_FOR_DEBUGGER)] =
116 &AppMgrStub::HandleStartNativeProcessForDebugger;
117 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT)] =
118 &AppMgrStub::HandleNotifyFault;
119 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA)] =
120 &AppMgrStub::HandleNotifyFaultBySA;
121 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::JUDGE_SANDBOX_BY_PID)] =
122 &AppMgrStub::HandleJudgeSandboxByPid;
123 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::GET_BUNDLE_NAME_BY_PID)] =
124 &AppMgrStub::HandleGetBundleNameByPid;
125 memberFuncMap_[static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RENDER_PROCESSES)] =
126 &AppMgrStub::HandleGetAllRenderProcesses;
127 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::GET_PROCESS_MEMORY_BY_PID)] =
128 &AppMgrStub::HandleGetProcessMemoryByPid;
129 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::GET_PIDS_BY_BUNDLENAME)] =
130 &AppMgrStub::HandleGetRunningProcessInformation;
131 }
132
~AppMgrStub()133 AppMgrStub::~AppMgrStub()
134 {
135 memberFuncMap_.clear();
136 }
137
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)138 int AppMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
139 {
140 HILOG_DEBUG("AppMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
141 std::u16string descriptor = AppMgrStub::GetDescriptor();
142 std::u16string remoteDescriptor = data.ReadInterfaceToken();
143 if (descriptor != remoteDescriptor) {
144 HILOG_ERROR("local descriptor is not equal to remote");
145 return ERR_INVALID_STATE;
146 }
147
148 auto itFunc = memberFuncMap_.find(code);
149 if (itFunc != memberFuncMap_.end()) {
150 auto memberFunc = itFunc->second;
151 if (memberFunc != nullptr) {
152 return (this->*memberFunc)(data, reply);
153 }
154 }
155 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
156 }
157
HandleAttachApplication(MessageParcel & data,MessageParcel & reply)158 int32_t AppMgrStub::HandleAttachApplication(MessageParcel &data, MessageParcel &reply)
159 {
160 HITRACE_METER(HITRACE_TAG_APP);
161 sptr<IRemoteObject> client = data.ReadRemoteObject();
162 AttachApplication(client);
163 return NO_ERROR;
164 }
165
HandleApplicationForegrounded(MessageParcel & data,MessageParcel & reply)166 int32_t AppMgrStub::HandleApplicationForegrounded(MessageParcel &data, MessageParcel &reply)
167 {
168 HITRACE_METER(HITRACE_TAG_APP);
169 ApplicationForegrounded(data.ReadInt32());
170 return NO_ERROR;
171 }
172
HandleApplicationBackgrounded(MessageParcel & data,MessageParcel & reply)173 int32_t AppMgrStub::HandleApplicationBackgrounded(MessageParcel &data, MessageParcel &reply)
174 {
175 HITRACE_METER(HITRACE_TAG_APP);
176 ApplicationBackgrounded(data.ReadInt32());
177 return NO_ERROR;
178 }
179
HandleApplicationTerminated(MessageParcel & data,MessageParcel & reply)180 int32_t AppMgrStub::HandleApplicationTerminated(MessageParcel &data, MessageParcel &reply)
181 {
182 HITRACE_METER(HITRACE_TAG_APP);
183 ApplicationTerminated(data.ReadInt32());
184 return NO_ERROR;
185 }
186
HandleCheckPermission(MessageParcel & data,MessageParcel & reply)187 int32_t AppMgrStub::HandleCheckPermission(MessageParcel &data, MessageParcel &reply)
188 {
189 HITRACE_METER(HITRACE_TAG_APP);
190 int32_t recordId = data.ReadInt32();
191 std::string permission = data.ReadString();
192 int32_t result = CheckPermission(recordId, permission);
193 reply.WriteInt32(result);
194 return NO_ERROR;
195 }
196
HandleAbilityCleaned(MessageParcel & data,MessageParcel & reply)197 int32_t AppMgrStub::HandleAbilityCleaned(MessageParcel &data, MessageParcel &reply)
198 {
199 HITRACE_METER(HITRACE_TAG_APP);
200 sptr<IRemoteObject> token = data.ReadRemoteObject();
201 AbilityCleaned(token);
202 return NO_ERROR;
203 }
204
HandleGetAmsMgr(MessageParcel & data,MessageParcel & reply)205 int32_t AppMgrStub::HandleGetAmsMgr(MessageParcel &data, MessageParcel &reply)
206 {
207 HITRACE_METER(HITRACE_TAG_APP);
208 int32_t result = NO_ERROR;
209 sptr<IAmsMgr> amsMgr = GetAmsMgr();
210 if (!amsMgr) {
211 HILOG_ERROR("abilitymgr instance is nullptr");
212 result = ERR_NO_INIT;
213 } else {
214 if (!reply.WriteRemoteObject(amsMgr->AsObject())) {
215 HILOG_ERROR("failed to reply abilitymgr instance to client, for write parcel error");
216 result = ERR_APPEXECFWK_PARCEL_ERROR;
217 }
218 }
219 reply.WriteInt32(result);
220 return NO_ERROR;
221 }
222
HandleClearUpApplicationData(MessageParcel & data,MessageParcel & reply)223 int32_t AppMgrStub::HandleClearUpApplicationData(MessageParcel &data, MessageParcel &reply)
224 {
225 HITRACE_METER(HITRACE_TAG_APP);
226 std::string bundleName = data.ReadString();
227 int32_t result = ClearUpApplicationData(bundleName);
228 reply.WriteInt32(result);
229 return NO_ERROR;
230 }
231
HandleGetAllRunningProcesses(MessageParcel & data,MessageParcel & reply)232 int32_t AppMgrStub::HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply)
233 {
234 HITRACE_METER(HITRACE_TAG_APP);
235 std::vector<RunningProcessInfo> info;
236 auto result = GetAllRunningProcesses(info);
237 reply.WriteInt32(info.size());
238 for (auto &it : info) {
239 if (!reply.WriteParcelable(&it)) {
240 return ERR_INVALID_VALUE;
241 }
242 }
243 if (!reply.WriteInt32(result)) {
244 return ERR_INVALID_VALUE;
245 }
246 return NO_ERROR;
247 }
248
HandleGetProcessRunningInfosByUserId(MessageParcel & data,MessageParcel & reply)249 int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply)
250 {
251 HITRACE_METER(HITRACE_TAG_APP);
252 int32_t userId = data.ReadInt32();
253 std::vector<RunningProcessInfo> info;
254 auto result = GetProcessRunningInfosByUserId(info, userId);
255 reply.WriteInt32(info.size());
256 for (auto &it : info) {
257 if (!reply.WriteParcelable(&it)) {
258 return ERR_INVALID_VALUE;
259 }
260 }
261 if (!reply.WriteInt32(result)) {
262 return ERR_INVALID_VALUE;
263 }
264 return NO_ERROR;
265 }
266
HandleGetAllRenderProcesses(MessageParcel & data,MessageParcel & reply)267 int32_t AppMgrStub::HandleGetAllRenderProcesses(MessageParcel &data, MessageParcel &reply)
268 {
269 HITRACE_METER(HITRACE_TAG_APP);
270 std::vector<RenderProcessInfo> info;
271 auto result = GetAllRenderProcesses(info);
272 reply.WriteInt32(info.size());
273 for (auto &it : info) {
274 if (!reply.WriteParcelable(&it)) {
275 return ERR_INVALID_VALUE;
276 }
277 }
278 if (!reply.WriteInt32(result)) {
279 return ERR_INVALID_VALUE;
280 }
281 return NO_ERROR;
282 }
283
HandleJudgeSandboxByPid(MessageParcel & data,MessageParcel & reply)284 int32_t AppMgrStub::HandleJudgeSandboxByPid(MessageParcel &data, MessageParcel &reply)
285 {
286 HITRACE_METER(HITRACE_TAG_APP);
287 int32_t pid = data.ReadInt32();
288 bool isSandbox = false;
289 auto result = JudgeSandboxByPid(pid, isSandbox);
290 if (!reply.WriteBool(isSandbox)) {
291 return ERR_INVALID_VALUE;
292 }
293 if (!reply.WriteInt32(result)) {
294 return ERR_INVALID_VALUE;
295 }
296 return NO_ERROR;
297 }
298
HandleGetProcessRunningInformation(MessageParcel & data,MessageParcel & reply)299 int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply)
300 {
301 HITRACE_METER(HITRACE_TAG_APP);
302 RunningProcessInfo info;
303 auto result = GetProcessRunningInformation(info);
304 if (!reply.WriteParcelable(&info)) {
305 return ERR_INVALID_VALUE;
306 }
307 if (!reply.WriteInt32(result)) {
308 return ERR_INVALID_VALUE;
309 }
310 return NO_ERROR;
311 }
312
HandleAddAbilityStageDone(MessageParcel & data,MessageParcel & reply)313 int32_t AppMgrStub::HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply)
314 {
315 int32_t recordId = data.ReadInt32();
316 AddAbilityStageDone(recordId);
317 return NO_ERROR;
318 }
319
HandleNotifyMemoryLevel(MessageParcel & data,MessageParcel & reply)320 int32_t AppMgrStub::HandleNotifyMemoryLevel(MessageParcel &data, MessageParcel &reply)
321 {
322 HITRACE_METER(HITRACE_TAG_APP);
323 int32_t level = data.ReadInt32();
324 auto result = NotifyMemoryLevel(level);
325 if (!reply.WriteInt32(result)) {
326 return ERR_INVALID_VALUE;
327 }
328 return NO_ERROR;
329 }
330
HandleDumpHeapMemory(MessageParcel & data,MessageParcel & reply)331 int32_t AppMgrStub::HandleDumpHeapMemory(MessageParcel &data, MessageParcel &reply)
332 {
333 HILOG_DEBUG("AppMgrStub::HandleDumpHeapMemory.");
334 HITRACE_METER(HITRACE_TAG_APP);
335 int32_t pid = data.ReadInt32();
336 struct OHOS::AppExecFwk::MallocInfo mallocInfo;
337 auto result = DumpHeapMemory(pid, mallocInfo);
338 if (result != NO_ERROR) {
339 return result;
340 }
341 reply.WriteParcelable(&mallocInfo);
342 return NO_ERROR;
343 }
344
HandleStartupResidentProcess(MessageParcel & data,MessageParcel & reply)345 int32_t AppMgrStub::HandleStartupResidentProcess(MessageParcel &data, MessageParcel &reply)
346 {
347 HITRACE_METER(HITRACE_TAG_APP);
348 std::vector<AppExecFwk::BundleInfo> bundleInfos;
349 int32_t infoSize = data.ReadInt32();
350 if (infoSize > CYCLE_LIMIT) {
351 HILOG_ERROR("infoSize is too large");
352 return ERR_INVALID_VALUE;
353 }
354 for (int32_t i = 0; i < infoSize; i++) {
355 std::unique_ptr<AppExecFwk::BundleInfo> bundleInfo(data.ReadParcelable<AppExecFwk::BundleInfo>());
356 if (!bundleInfo) {
357 HILOG_ERROR("Read Parcelable infos failed.");
358 return ERR_INVALID_VALUE;
359 }
360 bundleInfos.emplace_back(*bundleInfo);
361 }
362 StartupResidentProcess(bundleInfos);
363 return NO_ERROR;
364 }
365
HandleRegisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)366 int32_t AppMgrStub::HandleRegisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
367 {
368 std::vector<std::string> bundleNameList;
369 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
370 data.ReadStringVector(&bundleNameList);
371 int32_t result = RegisterApplicationStateObserver(callback, bundleNameList);
372 reply.WriteInt32(result);
373 return NO_ERROR;
374 }
375
HandleUnregisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)376 int32_t AppMgrStub::HandleUnregisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
377 {
378 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
379 int32_t result = UnregisterApplicationStateObserver(callback);
380 reply.WriteInt32(result);
381 return NO_ERROR;
382 }
383
384
HandleGetForegroundApplications(MessageParcel & data,MessageParcel & reply)385 int32_t AppMgrStub::HandleGetForegroundApplications(MessageParcel &data, MessageParcel &reply)
386 {
387 std::vector<AppStateData> appStateDatas;
388 int32_t result = GetForegroundApplications(appStateDatas);
389 reply.WriteInt32(appStateDatas.size());
390 for (auto &it : appStateDatas) {
391 if (!reply.WriteParcelable(&it)) {
392 return ERR_INVALID_VALUE;
393 }
394 }
395 if (!reply.WriteInt32(result)) {
396 return ERR_INVALID_VALUE;
397 }
398 return result;
399 }
400
HandleStartUserTestProcess(MessageParcel & data,MessageParcel & reply)401 int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply)
402 {
403 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
404 if (want == nullptr) {
405 HILOG_ERROR("want is nullptr");
406 return ERR_INVALID_VALUE;
407 }
408 std::unique_ptr<BundleInfo> bundleInfo(data.ReadParcelable<BundleInfo>());
409 if (bundleInfo == nullptr) {
410 HILOG_ERROR("want is nullptr");
411 return ERR_INVALID_VALUE;
412 }
413 auto observer = data.ReadRemoteObject();
414 int32_t userId = data.ReadInt32();
415 int32_t result = StartUserTestProcess(*want, observer, *bundleInfo, userId);
416 reply.WriteInt32(result);
417 return result;
418 }
419
HandleFinishUserTest(MessageParcel & data,MessageParcel & reply)420 int32_t AppMgrStub::HandleFinishUserTest(MessageParcel &data, MessageParcel &reply)
421 {
422 std::string msg = data.ReadString();
423 int64_t resultCode = data.ReadInt64();
424 std::string bundleName = data.ReadString();
425 int32_t result = FinishUserTest(msg, resultCode, bundleName);
426 reply.WriteInt32(result);
427 return result;
428 }
429
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)430 int32_t AppMgrStub::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
431 const std::vector<std::string> &bundleNameList)
432 {
433 return NO_ERROR;
434 }
435
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)436 int32_t AppMgrStub::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
437 {
438 return NO_ERROR;
439 }
440
GetForegroundApplications(std::vector<AppStateData> & list)441 int32_t AppMgrStub::GetForegroundApplications(std::vector<AppStateData> &list)
442 {
443 return NO_ERROR;
444 }
445
HandleScheduleAcceptWantDone(MessageParcel & data,MessageParcel & reply)446 int32_t AppMgrStub::HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply)
447 {
448 auto recordId = data.ReadInt32();
449 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
450 if (want == nullptr) {
451 HILOG_ERROR("want is nullptr");
452 return ERR_INVALID_VALUE;
453 }
454 auto flag = data.ReadString();
455
456 ScheduleAcceptWantDone(recordId, *want, flag);
457 delete want;
458 return NO_ERROR;
459 }
460
HandleGetAbilityRecordsByProcessID(MessageParcel & data,MessageParcel & reply)461 int32_t AppMgrStub::HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply)
462 {
463 HITRACE_METER(HITRACE_TAG_APP);
464 int32_t pid = data.ReadInt32();
465 std::vector<sptr<IRemoteObject>> tokens;
466 auto result = GetAbilityRecordsByProcessID(pid, tokens);
467 reply.WriteInt32(tokens.size());
468 for (auto &it : tokens) {
469 if (!reply.WriteRemoteObject(it)) {
470 HILOG_ERROR("failed to write query result.");
471 return ERR_FLATTEN_OBJECT;
472 }
473 }
474 if (!reply.WriteInt32(result)) {
475 return ERR_INVALID_VALUE;
476 }
477 return NO_ERROR;
478 }
479
HandlePreStartNWebSpawnProcess(MessageParcel & data,MessageParcel & reply)480 int32_t AppMgrStub::HandlePreStartNWebSpawnProcess(MessageParcel &data, MessageParcel &reply)
481 {
482 HILOG_INFO("HandlePreNWebSpawnProcess");
483 int32_t result = PreStartNWebSpawnProcess();
484 if (!reply.WriteInt32(result)) {
485 HILOG_ERROR("write result error.");
486 return ERR_INVALID_VALUE;
487 }
488 return result;
489 }
490
HandleStartRenderProcess(MessageParcel & data,MessageParcel & reply)491 int32_t AppMgrStub::HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply)
492 {
493 std::string renderParam = data.ReadString();
494 int32_t ipcFd = data.ReadFileDescriptor();
495 int32_t sharedFd = data.ReadFileDescriptor();
496 int32_t crashFd = data.ReadFileDescriptor();
497 int32_t renderPid = 0;
498 int32_t result =
499 StartRenderProcess(renderParam, ipcFd, sharedFd, crashFd, renderPid);
500 if (!reply.WriteInt32(result)) {
501 HILOG_ERROR("write result error.");
502 return ERR_INVALID_VALUE;
503 }
504 if (!reply.WriteInt32(renderPid)) {
505 HILOG_ERROR("write renderPid error.");
506 return ERR_INVALID_VALUE;
507 }
508 return result;
509 }
510
HandleAttachRenderProcess(MessageParcel & data,MessageParcel & reply)511 int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply)
512 {
513 sptr<IRemoteObject> scheduler = data.ReadRemoteObject();
514 AttachRenderProcess(scheduler);
515 return NO_ERROR;
516 }
517
HandleGetRenderProcessTerminationStatus(MessageParcel & data,MessageParcel & reply)518 int32_t AppMgrStub::HandleGetRenderProcessTerminationStatus(MessageParcel &data, MessageParcel &reply)
519 {
520 int32_t renderPid = data.ReadInt32();
521 if (renderPid <= 0) {
522 HILOG_ERROR("invalid renderPid value");
523 return ERR_INVALID_VALUE;
524 }
525 int status = 0;
526 int32_t result = GetRenderProcessTerminationStatus(renderPid, status);
527 if (!reply.WriteInt32(result)) {
528 HILOG_ERROR("write result error.");
529 return ERR_INVALID_VALUE;
530 }
531 if (!reply.WriteInt32(status)) {
532 HILOG_ERROR("write status error.");
533 return ERR_INVALID_VALUE;
534 }
535 return result;
536 }
537
HandleGetConfiguration(MessageParcel & data,MessageParcel & reply)538 int32_t AppMgrStub::HandleGetConfiguration(MessageParcel &data, MessageParcel &reply)
539 {
540 Configuration config;
541 int ret = GetConfiguration(config);
542 if (ret != ERR_OK) {
543 HILOG_ERROR("AppMgrStub GetConfiguration error");
544 return ERR_INVALID_VALUE;
545 }
546 if (!reply.WriteParcelable(&config)) {
547 HILOG_ERROR("AppMgrStub GetConfiguration error");
548 return ERR_INVALID_VALUE;
549 }
550 if (!reply.WriteInt32(ret)) {
551 return ERR_INVALID_VALUE;
552 }
553 return NO_ERROR;
554 }
555
HandleUpdateConfiguration(MessageParcel & data,MessageParcel & reply)556 int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel &reply)
557 {
558 std::unique_ptr<Configuration> config(data.ReadParcelable<Configuration>());
559 if (!config) {
560 HILOG_ERROR("AppMgrStub read configuration error");
561 return ERR_INVALID_VALUE;
562 }
563 int32_t ret = UpdateConfiguration(*config);
564 if (!reply.WriteInt32(ret)) {
565 return ERR_INVALID_VALUE;
566 }
567 return NO_ERROR;
568 }
569
HandleRegisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)570 int32_t AppMgrStub::HandleRegisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
571 {
572 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
573 int32_t result = RegisterConfigurationObserver(observer);
574 reply.WriteInt32(result);
575 return NO_ERROR;
576 }
577
HandleUnregisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)578 int32_t AppMgrStub::HandleUnregisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
579 {
580 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
581 int32_t result = UnregisterConfigurationObserver(observer);
582 reply.WriteInt32(result);
583 return NO_ERROR;
584 }
585
586 #ifdef ABILITY_COMMAND_FOR_TEST
HandleBlockAppServiceDone(MessageParcel & data,MessageParcel & reply)587 int32_t AppMgrStub::HandleBlockAppServiceDone(MessageParcel &data, MessageParcel &reply)
588 {
589 HILOG_INFO("%{public}s", __func__);
590 int32_t result = BlockAppService();
591 reply.WriteInt32(result);
592 return result;
593 }
594 #endif
595
HandleGetAppRunningStateByBundleName(MessageParcel & data,MessageParcel & reply)596 int32_t AppMgrStub::HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply)
597 {
598 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
599 HILOG_DEBUG("function called.");
600 std::string bundleName = data.ReadString();
601 auto ret = GetAppRunningStateByBundleName(bundleName);
602 if (!reply.WriteBool(ret)) {
603 return ERR_INVALID_VALUE;
604 }
605 return NO_ERROR;
606 }
607
HandleNotifyLoadRepairPatch(MessageParcel & data,MessageParcel & reply)608 int32_t AppMgrStub::HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
609 {
610 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
611 HILOG_DEBUG("function called.");
612 std::string bundleName = data.ReadString();
613 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
614 auto ret = NotifyLoadRepairPatch(bundleName, callback);
615 if (!reply.WriteInt32(ret)) {
616 return ERR_INVALID_VALUE;
617 }
618 return NO_ERROR;
619 }
620
HandleNotifyHotReloadPage(MessageParcel & data,MessageParcel & reply)621 int32_t AppMgrStub::HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply)
622 {
623 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
624 HILOG_DEBUG("function called.");
625 std::string bundleName = data.ReadString();
626 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
627 auto ret = NotifyHotReloadPage(bundleName, callback);
628 if (!reply.WriteInt32(ret)) {
629 return ERR_INVALID_VALUE;
630 }
631 return NO_ERROR;
632 }
633
634 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
HandleSetContinuousTaskProcess(MessageParcel & data,MessageParcel & reply)635 int32_t AppMgrStub::HandleSetContinuousTaskProcess(MessageParcel &data, MessageParcel &reply)
636 {
637 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
638 HILOG_DEBUG("function called.");
639 int32_t pid = data.ReadInt32();
640 bool isContinuousTask = data.ReadBool();
641 auto ret = SetContinuousTaskProcess(pid, isContinuousTask);
642 if (!reply.WriteInt32(ret)) {
643 return ERR_INVALID_VALUE;
644 }
645 return NO_ERROR;
646 }
647 #endif
648
HandleNotifyUnLoadRepairPatch(MessageParcel & data,MessageParcel & reply)649 int32_t AppMgrStub::HandleNotifyUnLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
650 {
651 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
652 HILOG_DEBUG("function called.");
653 std::string bundleName = data.ReadString();
654 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
655 auto ret = NotifyUnLoadRepairPatch(bundleName, callback);
656 if (!reply.WriteInt32(ret)) {
657 return ERR_INVALID_VALUE;
658 }
659 return NO_ERROR;
660 }
661
HandleIsSharedBundleRunning(MessageParcel & data,MessageParcel & reply)662 int32_t AppMgrStub::HandleIsSharedBundleRunning(MessageParcel &data, MessageParcel &reply)
663 {
664 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
665 HILOG_DEBUG("function called.");
666 std::string bundleName = data.ReadString();
667 uint32_t versionCode = data.ReadUint32();
668 bool result = IsSharedBundleRunning(bundleName, versionCode);
669 if (!reply.WriteBool(result)) {
670 return ERR_INVALID_VALUE;
671 }
672 return NO_ERROR;
673 }
674
HandleStartNativeProcessForDebugger(MessageParcel & data,MessageParcel & reply)675 int32_t AppMgrStub::HandleStartNativeProcessForDebugger(MessageParcel &data, MessageParcel &reply)
676 {
677 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
678 HILOG_DEBUG("function called.");
679 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
680 if (want == nullptr) {
681 HILOG_ERROR("want is nullptr");
682 return ERR_INVALID_VALUE;
683 }
684 auto result = StartNativeProcessForDebugger(*want);
685 if (!reply.WriteInt32(result)) {
686 HILOG_ERROR("fail to write result.");
687 return ERR_INVALID_VALUE;
688 }
689 return NO_ERROR;
690 }
691
HandleGetBundleNameByPid(MessageParcel & data,MessageParcel & reply)692 int32_t AppMgrStub::HandleGetBundleNameByPid(MessageParcel &data, MessageParcel &reply)
693 {
694 int32_t pid = data.ReadInt32();
695 std::string bundleName;
696 int32_t uid;
697 auto result = GetBundleNameByPid(pid, bundleName, uid);
698 if (result != ERR_OK) {
699 return result;
700 }
701
702 if (!reply.WriteString(bundleName)) {
703 return ERR_INVALID_VALUE;
704 }
705
706 if (!reply.WriteInt32(uid)) {
707 return ERR_INVALID_VALUE;
708 }
709 return NO_ERROR;
710 }
711
HandleNotifyFault(MessageParcel & data,MessageParcel & reply)712 int32_t AppMgrStub::HandleNotifyFault(MessageParcel &data, MessageParcel &reply)
713 {
714 std::unique_ptr<FaultData> faultData(data.ReadParcelable<FaultData>());
715 if (faultData == nullptr) {
716 HILOG_ERROR("ReadParcelable<FaultData> failed");
717 return ERR_INVALID_VALUE;
718 }
719
720 int32_t result = NotifyAppFault(*faultData);
721 if (!reply.WriteInt32(result)) {
722 HILOG_ERROR("reply write failed.");
723 return ERR_INVALID_VALUE;
724 }
725 return NO_ERROR;
726 }
727
HandleNotifyFaultBySA(MessageParcel & data,MessageParcel & reply)728 int32_t AppMgrStub::HandleNotifyFaultBySA(MessageParcel &data, MessageParcel &reply)
729 {
730 std::unique_ptr<AppFaultDataBySA> faultData(data.ReadParcelable<AppFaultDataBySA>());
731 if (faultData == nullptr) {
732 HILOG_ERROR("ReadParcelable<AppFaultDataBySA> failed");
733 return ERR_INVALID_VALUE;
734 }
735
736 int32_t result = NotifyAppFaultBySA(*faultData);
737 if (!reply.WriteInt32(result)) {
738 HILOG_ERROR("reply write failed.");
739 return ERR_INVALID_VALUE;
740 }
741 return NO_ERROR;
742 }
743
HandleGetProcessMemoryByPid(MessageParcel & data,MessageParcel & reply)744 int32_t AppMgrStub::HandleGetProcessMemoryByPid(MessageParcel &data, MessageParcel &reply)
745 {
746 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
747 int32_t pid = data.ReadInt32();
748 int32_t memorySize = 0;
749 auto result = GetProcessMemoryByPid(pid, memorySize);
750 if (!reply.WriteInt32(memorySize)) {
751 HILOG_ERROR("Memory size write failed.");
752 return ERR_INVALID_VALUE;
753 }
754 if (!reply.WriteInt32(result)) {
755 HILOG_ERROR("fail to write result.");
756 return ERR_INVALID_VALUE;
757 }
758 return NO_ERROR;
759 }
760
HandleGetRunningProcessInformation(MessageParcel & data,MessageParcel & reply)761 int32_t AppMgrStub::HandleGetRunningProcessInformation(MessageParcel &data, MessageParcel &reply)
762 {
763 HITRACE_METER(HITRACE_TAG_APP);
764 std::string bundleName = data.ReadString();
765 int32_t userId = data.ReadInt32();
766 std::vector<RunningProcessInfo> info;
767 auto result = GetRunningProcessInformation(bundleName, userId, info);
768 reply.WriteInt32(info.size());
769 for (auto &it : info) {
770 if (!reply.WriteParcelable(&it)) {
771 return ERR_INVALID_VALUE;
772 }
773 }
774 if (!reply.WriteInt32(result)) {
775 HILOG_ERROR("fail to write result.");
776 return ERR_INVALID_VALUE;
777 }
778 return NO_ERROR;
779 }
780 } // namespace AppExecFwk
781 } // namespace OHOS
782