1 /*
2 * Copyright (c) 2021-2022 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
32 namespace OHOS {
33 namespace AppExecFwk {
34 constexpr int32_t CYCLE_LIMIT = 1000;
AppMgrStub()35 AppMgrStub::AppMgrStub()
36 {
37 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_ATTACH_APPLICATION)] =
38 &AppMgrStub::HandleAttachApplication;
39 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_APPLICATION_FOREGROUNDED)] =
40 &AppMgrStub::HandleApplicationForegrounded;
41 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_APPLICATION_BACKGROUNDED)] =
42 &AppMgrStub::HandleApplicationBackgrounded;
43 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_APPLICATION_TERMINATED)] =
44 &AppMgrStub::HandleApplicationTerminated;
45 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_CHECK_PERMISSION)] =
46 &AppMgrStub::HandleCheckPermission;
47 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_ABILITY_CLEANED)] =
48 &AppMgrStub::HandleAbilityCleaned;
49 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_GET_MGR_INSTANCE)] = &AppMgrStub::HandleGetAmsMgr;
50 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_CLEAR_UP_APPLICATION_DATA)] =
51 &AppMgrStub::HandleClearUpApplicationData;
52 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_GET_ALL_RUNNING_PROCESSES)] =
53 &AppMgrStub::HandleGetAllRunningProcesses;
54 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_NOTIFY_MEMORY_LEVEL)] =
55 &AppMgrStub::HandleNotifyMemoryLevel;
56 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_GET_RUNNING_PROCESSES_BY_USER_ID)] =
57 &AppMgrStub::HandleGetProcessRunningInfosByUserId;
58 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_ADD_ABILITY_STAGE_INFO_DONE)] =
59 &AppMgrStub::HandleAddAbilityStageDone;
60 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::STARTUP_RESIDENT_PROCESS)] =
61 &AppMgrStub::HandleStartupResidentProcess;
62 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::REGISTER_APPLICATION_STATE_OBSERVER)] =
63 &AppMgrStub::HandleRegisterApplicationStateObserver;
64 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::UNREGISTER_APPLICATION_STATE_OBSERVER)] =
65 &AppMgrStub::HandleUnregisterApplicationStateObserver;
66 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::GET_FOREGROUND_APPLICATIONS)] =
67 &AppMgrStub::HandleGetForegroundApplications;
68 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::START_USER_TEST_PROCESS)] =
69 &AppMgrStub::HandleStartUserTestProcess;
70 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::FINISH_USER_TEST)] =
71 &AppMgrStub::HandleFinishUserTest;
72 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::SCHEDULE_ACCEPT_WANT_DONE)] =
73 &AppMgrStub::HandleScheduleAcceptWantDone;
74 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_GET_ABILITY_RECORDS_BY_PROCESS_ID)] =
75 &AppMgrStub::HandleGetAbilityRecordsByProcessID;
76 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::PRE_START_NWEBSPAWN_PROCESS)] =
77 &AppMgrStub::HandlePreStartNWebSpawnProcess;
78 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::START_RENDER_PROCESS)] =
79 &AppMgrStub::HandleStartRenderProcess;
80 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::ATTACH_RENDER_PROCESS)] =
81 &AppMgrStub::HandleAttachRenderProcess;
82 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::GET_RENDER_PROCESS_TERMINATION_STATUS)] =
83 &AppMgrStub::HandleGetRenderProcessTerminationStatus;
84 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::GET_CONFIGURATION)] =
85 &AppMgrStub::HandleGetConfiguration;
86 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::UPDATE_CONFIGURATION)] =
87 &AppMgrStub::HandleUpdateConfiguration;
88 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::REGISTER_CONFIGURATION_OBSERVER)] =
89 &AppMgrStub::HandleRegisterConfigurationObserver;
90 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::UNREGISTER_CONFIGURATION_OBSERVER)] =
91 &AppMgrStub::HandleUnregisterConfigurationObserver;
92 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::APP_GET_PROCESS_RUNNING_INFORMATION)] =
93 &AppMgrStub::HandleGetProcessRunningInformation;
94 #ifdef ABILITY_COMMAND_FOR_TEST
95 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::BLOCK_APP_SERVICE)] =
96 &AppMgrStub::HandleBlockAppServiceDone;
97 #endif
98 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::GET_APP_RUNNING_STATE)] =
99 &AppMgrStub::HandleGetAppRunningStateByBundleName;
100 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::NOTIFY_LOAD_REPAIR_PATCH)] =
101 &AppMgrStub::HandleNotifyLoadRepairPatch;
102 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::NOTIFY_HOT_RELOAD_PAGE)] =
103 &AppMgrStub::HandleNotifyHotReloadPage;
104 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
105 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::SET_CONTINUOUSTASK_PROCESS)] =
106 &AppMgrStub::HandleSetContinuousTaskProcess;
107 #endif
108 memberFuncMap_[static_cast<uint32_t>(IAppMgr::Message::NOTIFY_UNLOAD_REPAIR_PATCH)] =
109 &AppMgrStub::HandleNotifyUnLoadRepairPatch;
110 }
111
~AppMgrStub()112 AppMgrStub::~AppMgrStub()
113 {
114 memberFuncMap_.clear();
115 }
116
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)117 int AppMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
118 {
119 HILOG_INFO("AppMgrStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
120 std::u16string descriptor = AppMgrStub::GetDescriptor();
121 std::u16string remoteDescriptor = data.ReadInterfaceToken();
122 if (descriptor != remoteDescriptor) {
123 HILOG_ERROR("local descriptor is not equal to remote");
124 return ERR_INVALID_STATE;
125 }
126
127 auto itFunc = memberFuncMap_.find(code);
128 if (itFunc != memberFuncMap_.end()) {
129 auto memberFunc = itFunc->second;
130 if (memberFunc != nullptr) {
131 return (this->*memberFunc)(data, reply);
132 }
133 }
134 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
135 }
136
HandleAttachApplication(MessageParcel & data,MessageParcel & reply)137 int32_t AppMgrStub::HandleAttachApplication(MessageParcel &data, MessageParcel &reply)
138 {
139 HITRACE_METER(HITRACE_TAG_APP);
140 sptr<IRemoteObject> client = data.ReadRemoteObject();
141 AttachApplication(client);
142 return NO_ERROR;
143 }
144
HandleApplicationForegrounded(MessageParcel & data,MessageParcel & reply)145 int32_t AppMgrStub::HandleApplicationForegrounded(MessageParcel &data, MessageParcel &reply)
146 {
147 HITRACE_METER(HITRACE_TAG_APP);
148 ApplicationForegrounded(data.ReadInt32());
149 return NO_ERROR;
150 }
151
HandleApplicationBackgrounded(MessageParcel & data,MessageParcel & reply)152 int32_t AppMgrStub::HandleApplicationBackgrounded(MessageParcel &data, MessageParcel &reply)
153 {
154 HITRACE_METER(HITRACE_TAG_APP);
155 ApplicationBackgrounded(data.ReadInt32());
156 return NO_ERROR;
157 }
158
HandleApplicationTerminated(MessageParcel & data,MessageParcel & reply)159 int32_t AppMgrStub::HandleApplicationTerminated(MessageParcel &data, MessageParcel &reply)
160 {
161 HITRACE_METER(HITRACE_TAG_APP);
162 ApplicationTerminated(data.ReadInt32());
163 return NO_ERROR;
164 }
165
HandleCheckPermission(MessageParcel & data,MessageParcel & reply)166 int32_t AppMgrStub::HandleCheckPermission(MessageParcel &data, MessageParcel &reply)
167 {
168 HITRACE_METER(HITRACE_TAG_APP);
169 int32_t recordId = data.ReadInt32();
170 std::string permission = data.ReadString();
171 int32_t result = CheckPermission(recordId, permission);
172 reply.WriteInt32(result);
173 return NO_ERROR;
174 }
175
HandleAbilityCleaned(MessageParcel & data,MessageParcel & reply)176 int32_t AppMgrStub::HandleAbilityCleaned(MessageParcel &data, MessageParcel &reply)
177 {
178 HITRACE_METER(HITRACE_TAG_APP);
179 sptr<IRemoteObject> token = data.ReadRemoteObject();
180 AbilityCleaned(token);
181 return NO_ERROR;
182 }
183
HandleGetAmsMgr(MessageParcel & data,MessageParcel & reply)184 int32_t AppMgrStub::HandleGetAmsMgr(MessageParcel &data, MessageParcel &reply)
185 {
186 HITRACE_METER(HITRACE_TAG_APP);
187 int32_t result = NO_ERROR;
188 sptr<IAmsMgr> amsMgr = GetAmsMgr();
189 if (!amsMgr) {
190 HILOG_ERROR("abilitymgr instance is nullptr");
191 result = ERR_NO_INIT;
192 } else {
193 if (!reply.WriteRemoteObject(amsMgr->AsObject())) {
194 HILOG_ERROR("failed to reply abilitymgr instance to client, for write parcel error");
195 result = ERR_APPEXECFWK_PARCEL_ERROR;
196 }
197 }
198 reply.WriteInt32(result);
199 return NO_ERROR;
200 }
201
HandleClearUpApplicationData(MessageParcel & data,MessageParcel & reply)202 int32_t AppMgrStub::HandleClearUpApplicationData(MessageParcel &data, MessageParcel &reply)
203 {
204 HITRACE_METER(HITRACE_TAG_APP);
205 std::string bundleName = data.ReadString();
206 int32_t result = ClearUpApplicationData(bundleName);
207 reply.WriteInt32(result);
208 return NO_ERROR;
209 }
210
HandleGetAllRunningProcesses(MessageParcel & data,MessageParcel & reply)211 int32_t AppMgrStub::HandleGetAllRunningProcesses(MessageParcel &data, MessageParcel &reply)
212 {
213 HITRACE_METER(HITRACE_TAG_APP);
214 std::vector<RunningProcessInfo> info;
215 auto result = GetAllRunningProcesses(info);
216 reply.WriteInt32(info.size());
217 for (auto &it : info) {
218 if (!reply.WriteParcelable(&it)) {
219 return ERR_INVALID_VALUE;
220 }
221 }
222 if (!reply.WriteInt32(result)) {
223 return ERR_INVALID_VALUE;
224 }
225 return NO_ERROR;
226 }
227
HandleGetProcessRunningInfosByUserId(MessageParcel & data,MessageParcel & reply)228 int32_t AppMgrStub::HandleGetProcessRunningInfosByUserId(MessageParcel &data, MessageParcel &reply)
229 {
230 HITRACE_METER(HITRACE_TAG_APP);
231 int32_t userId = data.ReadInt32();
232 std::vector<RunningProcessInfo> info;
233 auto result = GetProcessRunningInfosByUserId(info, userId);
234 reply.WriteInt32(info.size());
235 for (auto &it : info) {
236 if (!reply.WriteParcelable(&it)) {
237 return ERR_INVALID_VALUE;
238 }
239 }
240 if (!reply.WriteInt32(result)) {
241 return ERR_INVALID_VALUE;
242 }
243 return NO_ERROR;
244 }
245
HandleGetProcessRunningInformation(MessageParcel & data,MessageParcel & reply)246 int32_t AppMgrStub::HandleGetProcessRunningInformation(MessageParcel &data, MessageParcel &reply)
247 {
248 HITRACE_METER(HITRACE_TAG_APP);
249 RunningProcessInfo info;
250 auto result = GetProcessRunningInformation(info);
251 if (!reply.WriteParcelable(&info)) {
252 return ERR_INVALID_VALUE;
253 }
254 if (!reply.WriteInt32(result)) {
255 return ERR_INVALID_VALUE;
256 }
257 return NO_ERROR;
258 }
259
HandleAddAbilityStageDone(MessageParcel & data,MessageParcel & reply)260 int32_t AppMgrStub::HandleAddAbilityStageDone(MessageParcel &data, MessageParcel &reply)
261 {
262 int32_t recordId = data.ReadInt32();
263 AddAbilityStageDone(recordId);
264 return NO_ERROR;
265 }
266
HandleNotifyMemoryLevel(MessageParcel & data,MessageParcel & reply)267 int32_t AppMgrStub::HandleNotifyMemoryLevel(MessageParcel &data, MessageParcel &reply)
268 {
269 HITRACE_METER(HITRACE_TAG_APP);
270 int32_t level = data.ReadInt32();
271 auto result = NotifyMemoryLevel(level);
272 if (!reply.WriteInt32(result)) {
273 return ERR_INVALID_VALUE;
274 }
275 return NO_ERROR;
276 }
277
HandleStartupResidentProcess(MessageParcel & data,MessageParcel & reply)278 int32_t AppMgrStub::HandleStartupResidentProcess(MessageParcel &data, MessageParcel &reply)
279 {
280 HITRACE_METER(HITRACE_TAG_APP);
281 std::vector<AppExecFwk::BundleInfo> bundleInfos;
282 int32_t infoSize = data.ReadInt32();
283 if (infoSize > CYCLE_LIMIT) {
284 HILOG_ERROR("infoSize is too large");
285 return ERR_INVALID_VALUE;
286 }
287 for (int32_t i = 0; i < infoSize; i++) {
288 std::unique_ptr<AppExecFwk::BundleInfo> bundleInfo(data.ReadParcelable<AppExecFwk::BundleInfo>());
289 if (!bundleInfo) {
290 HILOG_ERROR("Read Parcelable infos failed.");
291 return ERR_INVALID_VALUE;
292 }
293 bundleInfos.emplace_back(*bundleInfo);
294 }
295 StartupResidentProcess(bundleInfos);
296 return NO_ERROR;
297 }
298
HandleRegisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)299 int32_t AppMgrStub::HandleRegisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
300 {
301 std::vector<std::string> bundleNameList;
302 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
303 data.ReadStringVector(&bundleNameList);
304 int32_t result = RegisterApplicationStateObserver(callback, bundleNameList);
305 reply.WriteInt32(result);
306 return NO_ERROR;
307 }
308
HandleUnregisterApplicationStateObserver(MessageParcel & data,MessageParcel & reply)309 int32_t AppMgrStub::HandleUnregisterApplicationStateObserver(MessageParcel &data, MessageParcel &reply)
310 {
311 auto callback = iface_cast<AppExecFwk::IApplicationStateObserver>(data.ReadRemoteObject());
312 int32_t result = UnregisterApplicationStateObserver(callback);
313 reply.WriteInt32(result);
314 return NO_ERROR;
315 }
316
317
HandleGetForegroundApplications(MessageParcel & data,MessageParcel & reply)318 int32_t AppMgrStub::HandleGetForegroundApplications(MessageParcel &data, MessageParcel &reply)
319 {
320 std::vector<AppStateData> appStateDatas;
321 int32_t result = GetForegroundApplications(appStateDatas);
322 reply.WriteInt32(appStateDatas.size());
323 for (auto &it : appStateDatas) {
324 if (!reply.WriteParcelable(&it)) {
325 return ERR_INVALID_VALUE;
326 }
327 }
328 if (!reply.WriteInt32(result)) {
329 return ERR_INVALID_VALUE;
330 }
331 return result;
332 }
333
HandleStartUserTestProcess(MessageParcel & data,MessageParcel & reply)334 int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply)
335 {
336 std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
337 if (want == nullptr) {
338 HILOG_ERROR("want is nullptr");
339 return ERR_INVALID_VALUE;
340 }
341 std::unique_ptr<BundleInfo> bundleInfo(data.ReadParcelable<BundleInfo>());
342 if (bundleInfo == nullptr) {
343 HILOG_ERROR("want is nullptr");
344 return ERR_INVALID_VALUE;
345 }
346 auto observer = data.ReadRemoteObject();
347 int32_t userId = data.ReadInt32();
348 int32_t result = StartUserTestProcess(*want, observer, *bundleInfo, userId);
349 reply.WriteInt32(result);
350 return result;
351 }
352
HandleFinishUserTest(MessageParcel & data,MessageParcel & reply)353 int32_t AppMgrStub::HandleFinishUserTest(MessageParcel &data, MessageParcel &reply)
354 {
355 std::string msg = data.ReadString();
356 int64_t resultCode = data.ReadInt64();
357 std::string bundleName = data.ReadString();
358 int32_t result = FinishUserTest(msg, resultCode, bundleName);
359 reply.WriteInt32(result);
360 return result;
361 }
362
RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer,const std::vector<std::string> & bundleNameList)363 int32_t AppMgrStub::RegisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer,
364 const std::vector<std::string> &bundleNameList)
365 {
366 return NO_ERROR;
367 }
368
UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> & observer)369 int32_t AppMgrStub::UnregisterApplicationStateObserver(const sptr<IApplicationStateObserver> &observer)
370 {
371 return NO_ERROR;
372 }
373
GetForegroundApplications(std::vector<AppStateData> & list)374 int32_t AppMgrStub::GetForegroundApplications(std::vector<AppStateData> &list)
375 {
376 return NO_ERROR;
377 }
378
HandleScheduleAcceptWantDone(MessageParcel & data,MessageParcel & reply)379 int32_t AppMgrStub::HandleScheduleAcceptWantDone(MessageParcel &data, MessageParcel &reply)
380 {
381 auto recordId = data.ReadInt32();
382 AAFwk::Want *want = data.ReadParcelable<AAFwk::Want>();
383 if (want == nullptr) {
384 HILOG_ERROR("want is nullptr");
385 return ERR_INVALID_VALUE;
386 }
387 auto flag = data.ReadString();
388
389 ScheduleAcceptWantDone(recordId, *want, flag);
390 delete want;
391 return NO_ERROR;
392 }
393
HandleGetAbilityRecordsByProcessID(MessageParcel & data,MessageParcel & reply)394 int32_t AppMgrStub::HandleGetAbilityRecordsByProcessID(MessageParcel &data, MessageParcel &reply)
395 {
396 HITRACE_METER(HITRACE_TAG_APP);
397 int32_t pid = data.ReadInt32();
398 std::vector<sptr<IRemoteObject>> tokens;
399 auto result = GetAbilityRecordsByProcessID(pid, tokens);
400 reply.WriteInt32(tokens.size());
401 for (auto &it : tokens) {
402 if (!reply.WriteRemoteObject(it)) {
403 HILOG_ERROR("failed to write query result.");
404 return ERR_FLATTEN_OBJECT;
405 }
406 }
407 if (!reply.WriteInt32(result)) {
408 return ERR_INVALID_VALUE;
409 }
410 return NO_ERROR;
411 }
412
HandlePreStartNWebSpawnProcess(MessageParcel & data,MessageParcel & reply)413 int32_t AppMgrStub::HandlePreStartNWebSpawnProcess(MessageParcel &data, MessageParcel &reply)
414 {
415 HILOG_INFO("HandlePreNWebSpawnProcess");
416 int32_t result = PreStartNWebSpawnProcess();
417 if (!reply.WriteInt32(result)) {
418 HILOG_ERROR("write result error.");
419 return ERR_INVALID_VALUE;
420 }
421 return result;
422 }
423
HandleStartRenderProcess(MessageParcel & data,MessageParcel & reply)424 int32_t AppMgrStub::HandleStartRenderProcess(MessageParcel &data, MessageParcel &reply)
425 {
426 std::string renderParam = data.ReadString();
427 int32_t ipcFd = data.ReadFileDescriptor();
428 int32_t sharedFd = data.ReadFileDescriptor();
429 int32_t renderPid = 0;
430 int32_t result = StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid);
431 if (!reply.WriteInt32(result)) {
432 HILOG_ERROR("write result error.");
433 return ERR_INVALID_VALUE;
434 }
435 if (!reply.WriteInt32(renderPid)) {
436 HILOG_ERROR("write renderPid error.");
437 return ERR_INVALID_VALUE;
438 }
439 return result;
440 }
441
HandleAttachRenderProcess(MessageParcel & data,MessageParcel & reply)442 int32_t AppMgrStub::HandleAttachRenderProcess(MessageParcel &data, MessageParcel &reply)
443 {
444 sptr<IRemoteObject> scheduler = data.ReadRemoteObject();
445 AttachRenderProcess(scheduler);
446 return NO_ERROR;
447 }
448
HandleGetRenderProcessTerminationStatus(MessageParcel & data,MessageParcel & reply)449 int32_t AppMgrStub::HandleGetRenderProcessTerminationStatus(MessageParcel &data, MessageParcel &reply)
450 {
451 int32_t renderPid = data.ReadInt32();
452 if (renderPid <= 0) {
453 HILOG_ERROR("invalid renderPid value");
454 return ERR_INVALID_VALUE;
455 }
456 int status = 0;
457 int32_t result = GetRenderProcessTerminationStatus(renderPid, status);
458 if (!reply.WriteInt32(result)) {
459 HILOG_ERROR("write result error.");
460 return ERR_INVALID_VALUE;
461 }
462 if (!reply.WriteInt32(status)) {
463 HILOG_ERROR("write status error.");
464 return ERR_INVALID_VALUE;
465 }
466 return result;
467 }
468
HandleGetConfiguration(MessageParcel & data,MessageParcel & reply)469 int32_t AppMgrStub::HandleGetConfiguration(MessageParcel &data, MessageParcel &reply)
470 {
471 Configuration config;
472 int ret = GetConfiguration(config);
473 if (ret != ERR_OK) {
474 HILOG_ERROR("AppMgrStub GetConfiguration error");
475 return ERR_INVALID_VALUE;
476 }
477 if (!reply.WriteParcelable(&config)) {
478 HILOG_ERROR("AppMgrStub GetConfiguration error");
479 return ERR_INVALID_VALUE;
480 }
481 if (!reply.WriteInt32(ret)) {
482 return ERR_INVALID_VALUE;
483 }
484 return NO_ERROR;
485 }
486
HandleUpdateConfiguration(MessageParcel & data,MessageParcel & reply)487 int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel &reply)
488 {
489 std::unique_ptr<Configuration> config(data.ReadParcelable<Configuration>());
490 if (!config) {
491 HILOG_ERROR("AppMgrStub read configuration error");
492 return ERR_INVALID_VALUE;
493 }
494 int32_t ret = UpdateConfiguration(*config);
495 if (!reply.WriteInt32(ret)) {
496 return ERR_INVALID_VALUE;
497 }
498 return NO_ERROR;
499 }
500
HandleRegisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)501 int32_t AppMgrStub::HandleRegisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
502 {
503 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
504 int32_t result = RegisterConfigurationObserver(observer);
505 reply.WriteInt32(result);
506 return NO_ERROR;
507 }
508
HandleUnregisterConfigurationObserver(MessageParcel & data,MessageParcel & reply)509 int32_t AppMgrStub::HandleUnregisterConfigurationObserver(MessageParcel &data, MessageParcel &reply)
510 {
511 auto observer = iface_cast<AppExecFwk::IConfigurationObserver>(data.ReadRemoteObject());
512 int32_t result = UnregisterConfigurationObserver(observer);
513 reply.WriteInt32(result);
514 return NO_ERROR;
515 }
516
517 #ifdef ABILITY_COMMAND_FOR_TEST
HandleBlockAppServiceDone(MessageParcel & data,MessageParcel & reply)518 int32_t AppMgrStub::HandleBlockAppServiceDone(MessageParcel &data, MessageParcel &reply)
519 {
520 HILOG_INFO("%{public}s", __func__);
521 int32_t result = BlockAppService();
522 reply.WriteInt32(result);
523 return result;
524 }
525 #endif
526
HandleGetAppRunningStateByBundleName(MessageParcel & data,MessageParcel & reply)527 int32_t AppMgrStub::HandleGetAppRunningStateByBundleName(MessageParcel &data, MessageParcel &reply)
528 {
529 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
530 HILOG_DEBUG("function called.");
531 std::string bundleName = data.ReadString();
532 auto ret = GetAppRunningStateByBundleName(bundleName);
533 if (!reply.WriteBool(ret)) {
534 return ERR_INVALID_VALUE;
535 }
536 return NO_ERROR;
537 }
538
HandleNotifyLoadRepairPatch(MessageParcel & data,MessageParcel & reply)539 int32_t AppMgrStub::HandleNotifyLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
540 {
541 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
542 HILOG_DEBUG("function called.");
543 std::string bundleName = data.ReadString();
544 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
545 auto ret = NotifyLoadRepairPatch(bundleName, callback);
546 if (!reply.WriteInt32(ret)) {
547 return ERR_INVALID_VALUE;
548 }
549 return NO_ERROR;
550 }
551
HandleNotifyHotReloadPage(MessageParcel & data,MessageParcel & reply)552 int32_t AppMgrStub::HandleNotifyHotReloadPage(MessageParcel &data, MessageParcel &reply)
553 {
554 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
555 HILOG_DEBUG("function called.");
556 std::string bundleName = data.ReadString();
557 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
558 auto ret = NotifyHotReloadPage(bundleName, callback);
559 if (!reply.WriteInt32(ret)) {
560 return ERR_INVALID_VALUE;
561 }
562 return NO_ERROR;
563 }
564
565 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE
HandleSetContinuousTaskProcess(MessageParcel & data,MessageParcel & reply)566 int32_t AppMgrStub::HandleSetContinuousTaskProcess(MessageParcel &data, MessageParcel &reply)
567 {
568 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
569 HILOG_DEBUG("function called.");
570 int32_t pid = data.ReadInt32();
571 bool isContinuousTask = data.ReadBool();
572 auto ret = SetContinuousTaskProcess(pid, isContinuousTask);
573 if (!reply.WriteInt32(ret)) {
574 return ERR_INVALID_VALUE;
575 }
576 return NO_ERROR;
577 }
578 #endif
579
HandleNotifyUnLoadRepairPatch(MessageParcel & data,MessageParcel & reply)580 int32_t AppMgrStub::HandleNotifyUnLoadRepairPatch(MessageParcel &data, MessageParcel &reply)
581 {
582 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
583 HILOG_DEBUG("function called.");
584 std::string bundleName = data.ReadString();
585 auto callback = iface_cast<IQuickFixCallback>(data.ReadRemoteObject());
586 auto ret = NotifyUnLoadRepairPatch(bundleName, callback);
587 if (!reply.WriteInt32(ret)) {
588 return ERR_INVALID_VALUE;
589 }
590 return NO_ERROR;
591 }
592 } // namespace AppExecFwk
593 } // namespace OHOS
594