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_scheduler_proxy.h"
17
18 #include "freeze_util.h"
19 #include "hilog_tag_wrapper.h"
20 #include "hitrace_meter.h"
21 #include "ipc_types.h"
22 #include "iremote_object.h"
23 #include "app_scheduler_const.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
AppSchedulerProxy(const sptr<IRemoteObject> & impl)27 AppSchedulerProxy::AppSchedulerProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAppScheduler>(impl)
28 {}
29
WriteInterfaceToken(MessageParcel & data)30 bool AppSchedulerProxy::WriteInterfaceToken(MessageParcel &data)
31 {
32 if (!data.WriteInterfaceToken(AppSchedulerProxy::GetDescriptor())) {
33 TAG_LOGE(AAFwkTag::APPMGR, "write interface token failed");
34 return false;
35 }
36 return true;
37 }
38
ScheduleForegroundApplication()39 bool AppSchedulerProxy::ScheduleForegroundApplication()
40 {
41 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleForegroundApplication start");
42 MessageParcel data;
43 MessageParcel reply;
44 MessageOption option(MessageOption::TF_ASYNC);
45 if (!WriteInterfaceToken(data)) {
46 return false;
47 }
48 int32_t ret =
49 SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_FOREGROUND_APPLICATION_TRANSACTION),
50 data,
51 reply,
52 option);
53 if (ret != NO_ERROR) {
54 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
55 return false;
56 }
57 return true;
58 }
59
ScheduleBackgroundApplication()60 void AppSchedulerProxy::ScheduleBackgroundApplication()
61 {
62 MessageParcel data;
63 MessageParcel reply;
64 MessageOption option(MessageOption::TF_ASYNC);
65 if (!WriteInterfaceToken(data)) {
66 return;
67 }
68 int32_t ret =
69 SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_BACKGROUND_APPLICATION_TRANSACTION),
70 data,
71 reply,
72 option);
73 if (ret != NO_ERROR) {
74 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is wrong, error code: %{public}d", ret);
75 }
76 }
77
ScheduleTerminateApplication(bool isLastProcess)78 void AppSchedulerProxy::ScheduleTerminateApplication(bool isLastProcess)
79 {
80 MessageParcel data;
81 MessageParcel reply;
82 MessageOption option(MessageOption::TF_ASYNC);
83 if (!WriteInterfaceToken(data)) {
84 return;
85 }
86 if (!data.WriteBool(isLastProcess)) {
87 TAG_LOGE(AAFwkTag::APPMGR, "Write bool failed.");
88 return;
89 }
90 int32_t ret = SendTransactCmd(
91 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_TERMINATE_APPLICATION_TRANSACTION), data, reply, option);
92 if (ret != NO_ERROR) {
93 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is unsuccessful, error code: %{public}d", ret);
94 }
95 }
96
ScheduleLowMemory()97 void AppSchedulerProxy::ScheduleLowMemory()
98 {
99 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleLowMemory begin");
100 MessageParcel data;
101 MessageParcel reply;
102 MessageOption option(MessageOption::TF_ASYNC);
103 if (!WriteInterfaceToken(data)) {
104 return;
105 }
106 int32_t ret = SendTransactCmd(
107 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LOWMEMORY_APPLICATION_TRANSACTION), data, reply, option);
108 if (ret != NO_ERROR) {
109 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
110 }
111 }
112
ScheduleMemoryLevel(int32_t level)113 void AppSchedulerProxy::ScheduleMemoryLevel(int32_t level)
114 {
115 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_MEMORYLEVEL_APPLICATION_TRANSACTION);
116 ScheduleMemoryCommon(level, operation);
117 }
118
ScheduleHeapMemory(const int32_t pid,OHOS::AppExecFwk::MallocInfo & mallocInfo)119 void AppSchedulerProxy::ScheduleHeapMemory(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)
120 {
121 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleHeapMemory start");
122 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_HEAPMEMORY_APPLICATION_TRANSACTION);
123 MessageParcel data;
124 MessageParcel reply;
125 MessageOption option(MessageOption::TF_SYNC);
126 if (!WriteInterfaceToken(data)) {
127 TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken.");
128 return;
129 }
130 data.WriteInt32(pid);
131 int32_t ret = SendTransactCmd(operation, data, reply, option);
132 if (ret != NO_ERROR) {
133 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
134 return;
135 }
136
137 std::unique_ptr<MallocInfo> info(reply.ReadParcelable<MallocInfo>());
138 if (info == nullptr) {
139 TAG_LOGE(AAFwkTag::APPMGR, "MallocInfo ReadParcelable nullptr");
140 return;
141 }
142 mallocInfo = *info;
143 }
144
ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo & info)145 void AppSchedulerProxy::ScheduleJsHeapMemory(OHOS::AppExecFwk::JsHeapDumpInfo &info)
146 {
147 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleJsHeapMemory start");
148 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_JSHEAP_MEMORY_APPLICATION_TRANSACTION);
149 MessageParcel data;
150 MessageParcel reply;
151 MessageOption option(MessageOption::TF_ASYNC);
152 if (!WriteInterfaceToken(data)) {
153 TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken.");
154 return;
155 }
156 data.WriteParcelable(&info);
157 int32_t ret = SendTransactCmd(operation, data, reply, option);
158 if (ret != NO_ERROR) {
159 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
160 return;
161 }
162 }
163
ScheduleShrinkMemory(const int32_t level)164 void AppSchedulerProxy::ScheduleShrinkMemory(const int32_t level)
165 {
166 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_SHRINK_MEMORY_APPLICATION_TRANSACTION);
167 ScheduleMemoryCommon(level, operation);
168 }
169
ScheduleMemoryCommon(const int32_t level,const uint32_t operation)170 void AppSchedulerProxy::ScheduleMemoryCommon(const int32_t level, const uint32_t operation)
171 {
172 MessageParcel data;
173 MessageParcel reply;
174 MessageOption option(MessageOption::TF_ASYNC);
175 if (!WriteInterfaceToken(data)) {
176 return;
177 }
178 data.WriteInt32(level);
179 int32_t ret = SendTransactCmd(operation, data, reply, option);
180 if (ret != NO_ERROR) {
181 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
182 }
183 }
184
ScheduleLaunchAbility(const AbilityInfo & info,const sptr<IRemoteObject> & token,const std::shared_ptr<AAFwk::Want> & want,int32_t abilityRecordId)185 void AppSchedulerProxy::ScheduleLaunchAbility(const AbilityInfo &info, const sptr<IRemoteObject> &token,
186 const std::shared_ptr<AAFwk::Want> &want, int32_t abilityRecordId)
187 {
188 MessageParcel data;
189 MessageParcel reply;
190 MessageOption option(MessageOption::TF_ASYNC);
191 if (!WriteInterfaceToken(data)) {
192 return;
193 }
194 data.WriteParcelable(&info);
195 AbilityRuntime::FreezeUtil::LifecycleFlow flow = {token, AbilityRuntime::FreezeUtil::TimeoutState::LOAD};
196 if (token) {
197 if (!data.WriteBool(true) || !data.WriteRemoteObject(token.GetRefPtr())) {
198 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and token");
199 return;
200 }
201 } else {
202 if (!data.WriteBool(false)) {
203 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
204 return;
205 }
206 }
207
208 if (!data.WriteParcelable(want.get())) {
209 TAG_LOGE(AAFwkTag::APPMGR, "write want fail.");
210 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
211 "ERROR AppLifeCycleDeal::LaunchAbility; write want fail");
212 return;
213 }
214 if (!data.WriteInt32(abilityRecordId)) {
215 TAG_LOGE(AAFwkTag::APPMGR, "write ability record id fail.");
216 return;
217 }
218 int32_t ret = SendTransactCmd(
219 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LAUNCH_ABILITY_TRANSACTION), data, reply, option);
220 if (ret != NO_ERROR) {
221 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
222 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(flow,
223 std::string("ERROR AppLifeCycleDeal::LaunchAbility; ipc error ") + std::to_string(ret));
224 }
225 }
226
ScheduleCleanAbility(const sptr<IRemoteObject> & token,bool isCacheProcess)227 void AppSchedulerProxy::ScheduleCleanAbility(const sptr<IRemoteObject> &token, bool isCacheProcess)
228 {
229 MessageParcel data;
230 MessageParcel reply;
231 MessageOption option(MessageOption::TF_ASYNC);
232 if (!WriteInterfaceToken(data)) {
233 return;
234 }
235 if (!data.WriteRemoteObject(token.GetRefPtr())) {
236 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
237 return;
238 }
239 if (!data.WriteBool(isCacheProcess)) {
240 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write bool");
241 return;
242 }
243 int32_t ret = SendTransactCmd(
244 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_CLEAN_ABILITY_TRANSACTION), data, reply, option);
245 if (ret != NO_ERROR) {
246 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
247 }
248 }
249
ScheduleLaunchApplication(const AppLaunchData & launchData,const Configuration & config)250 void AppSchedulerProxy::ScheduleLaunchApplication(const AppLaunchData &launchData, const Configuration &config)
251 {
252 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy ScheduleLaunchApplication start");
253 MessageParcel data;
254 MessageParcel reply;
255 MessageOption option(MessageOption::TF_ASYNC);
256 if (!WriteInterfaceToken(data)) {
257 return;
258 }
259
260 if (!data.WriteParcelable(&launchData)) {
261 TAG_LOGE(AAFwkTag::APPMGR, "WriteParcelable launchData failed");
262 return;
263 }
264
265 if (!data.WriteParcelable(&config)) {
266 TAG_LOGE(AAFwkTag::APPMGR, "WriteParcelable config failed");
267 return ;
268 }
269
270 int32_t ret = SendTransactCmd(
271 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_LAUNCH_APPLICATION_TRANSACTION), data, reply, option);
272 if (ret != NO_ERROR) {
273 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
274 }
275 }
276
ScheduleUpdateApplicationInfoInstalled(const ApplicationInfo & appInfo)277 void AppSchedulerProxy::ScheduleUpdateApplicationInfoInstalled(const ApplicationInfo &appInfo)
278 {
279 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy ScheduleUpdateApplicationInfoInstalled begin");
280 MessageParcel data;
281 if (!WriteInterfaceToken(data)) {
282 return;
283 }
284 if (!data.WriteParcelable(&appInfo)) {
285 return ;
286 }
287 MessageParcel reply;
288 MessageOption option(MessageOption::TF_ASYNC);
289 int32_t ret = SendTransactCmd(
290 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_UPDATE_APPLICATION_INFO_INSTALLED), data, reply, option);
291 if (ret != NO_ERROR) {
292 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
293 }
294 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy ScheduleUpdateApplicationInfoInstalled end");
295 }
296
ScheduleAbilityStage(const HapModuleInfo & abilityStage)297 void AppSchedulerProxy::ScheduleAbilityStage(const HapModuleInfo &abilityStage)
298 {
299 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy ScheduleAbilityStage start");
300 MessageParcel data;
301 constexpr int32_t max = 10000;
302 constexpr int32_t large = 60;
303 constexpr int32_t mid = 20;
304 auto abilityInfoSize = static_cast<int32_t>(abilityStage.abilityInfos.size());
305 auto extensionInfoSize = static_cast<int32_t>(abilityStage.extensionInfos.size());
306 if (abilityInfoSize > max || extensionInfoSize > max) {
307 TAG_LOGE(AAFwkTag::APPMGR, "size exceeds max");
308 return;
309 }
310 auto componentSize = abilityInfoSize + extensionInfoSize;
311 if (componentSize > large) {
312 constexpr int32_t size = 2 * 1024 * 1024; // 1.6 M
313 data.SetDataCapacity(size);
314 } else if (componentSize > mid) {
315 constexpr int32_t size = 800 * 1024; // 800 kb
316 data.SetDataCapacity(size);
317 }
318 if (!WriteInterfaceToken(data)) {
319 return;
320 }
321
322 if (!data.WriteParcelable(&abilityStage)) {
323 return ;
324 }
325
326 MessageParcel reply;
327 MessageOption option(MessageOption::TF_ASYNC);
328 int32_t ret = SendTransactCmd(
329 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_ABILITY_STAGE_INFO), data, reply, option);
330 if (ret != NO_ERROR) {
331 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
332 }
333 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy ScheduleAbilityStage end");
334 }
335
ScheduleProfileChanged(const Profile & profile)336 void AppSchedulerProxy::ScheduleProfileChanged(const Profile &profile)
337 {
338 MessageParcel data;
339 MessageParcel reply;
340 MessageOption option(MessageOption::TF_ASYNC);
341 if (!WriteInterfaceToken(data)) {
342 return;
343 }
344 data.WriteParcelable(&profile);
345 int32_t ret = SendTransactCmd(
346 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_PROFILE_CHANGED_TRANSACTION), data, reply, option);
347 if (ret != NO_ERROR) {
348 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
349 }
350 }
351
ScheduleConfigurationUpdated(const Configuration & config)352 void AppSchedulerProxy::ScheduleConfigurationUpdated(const Configuration &config)
353 {
354 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
355 MessageParcel data;
356 MessageParcel reply;
357 MessageOption option(MessageOption::TF_ASYNC);
358 if (!WriteInterfaceToken(data)) {
359 return;
360 }
361 data.WriteParcelable(&config);
362 int32_t ret = SendTransactCmd(
363 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_CONFIGURATION_UPDATED), data, reply, option);
364 if (ret != NO_ERROR) {
365 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
366 }
367 }
368
ScheduleProcessSecurityExit()369 void AppSchedulerProxy::ScheduleProcessSecurityExit()
370 {
371 MessageParcel data;
372 MessageParcel reply;
373 MessageOption option(MessageOption::TF_ASYNC);
374 if (!WriteInterfaceToken(data)) {
375 return;
376 }
377 int32_t ret = SendTransactCmd(
378 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_PROCESS_SECURITY_EXIT_TRANSACTION), data, reply, option);
379 if (ret != NO_ERROR) {
380 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
381 }
382 }
383
ScheduleClearPageStack()384 void AppSchedulerProxy::ScheduleClearPageStack()
385 {
386 MessageParcel data;
387 MessageParcel reply;
388 MessageOption option(MessageOption::TF_ASYNC);
389 if (!WriteInterfaceToken(data)) {
390 return;
391 }
392 int32_t ret = SendTransactCmd(
393 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_CLEAR_PAGE_STACK), data, reply, option);
394 if (ret != NO_ERROR) {
395 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
396 }
397 }
398
ScheduleAcceptWant(const AAFwk::Want & want,const std::string & moduleName)399 void AppSchedulerProxy::ScheduleAcceptWant(const AAFwk::Want &want, const std::string &moduleName)
400 {
401 MessageParcel data;
402 MessageParcel reply;
403 MessageOption option(MessageOption::TF_ASYNC);
404 if (!WriteInterfaceToken(data)) {
405 return;
406 }
407
408 if (!data.WriteParcelable(&want) || !data.WriteString(moduleName)) {
409 return;
410 }
411 int32_t ret = SendTransactCmd(
412 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_ACCEPT_WANT), data, reply, option);
413 if (ret != NO_ERROR) {
414 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
415 }
416 }
417
ScheduleNewProcessRequest(const AAFwk::Want & want,const std::string & moduleName)418 void AppSchedulerProxy::ScheduleNewProcessRequest(const AAFwk::Want &want, const std::string &moduleName)
419 {
420 MessageParcel data;
421 MessageParcel reply;
422 MessageOption option(MessageOption::TF_ASYNC);
423 if (!WriteInterfaceToken(data)) {
424 return;
425 }
426
427 if (!data.WriteParcelable(&want) || !data.WriteString(moduleName)) {
428 return;
429 }
430 sptr<IRemoteObject> remote = Remote();
431 if (remote == nullptr) {
432 TAG_LOGE(AAFwkTag::APPMGR, "Remote() is NULL");
433 return;
434 }
435 int32_t ret = remote->SendRequest(
436 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_NEW_PROCESS_REQUEST), data, reply, option);
437 if (ret != NO_ERROR) {
438 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
439 }
440 }
441
ScheduleNotifyLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback,const int32_t recordId)442 int32_t AppSchedulerProxy::ScheduleNotifyLoadRepairPatch(const std::string &bundleName,
443 const sptr<IQuickFixCallback> &callback, const int32_t recordId)
444 {
445 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
446 MessageParcel data;
447 if (!WriteInterfaceToken(data)) {
448 TAG_LOGE(AAFwkTag::APPMGR, "ScheduleNotifyLoadRepairPatch, Write interface token failed.");
449 return ERR_INVALID_DATA;
450 }
451
452 if (!data.WriteString(bundleName)) {
453 TAG_LOGE(AAFwkTag::APPMGR, "ScheduleNotifyLoadRepairPatch, Write bundle name failed.");
454 return ERR_INVALID_DATA;
455 }
456
457 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
458 TAG_LOGE(AAFwkTag::APPMGR, "Write callback failed.");
459 return ERR_INVALID_DATA;
460 }
461
462 if (!data.WriteInt32(recordId)) {
463 TAG_LOGE(AAFwkTag::APPMGR, "Write record id failed.");
464 return ERR_INVALID_DATA;
465 }
466
467 MessageParcel reply;
468 MessageOption option;
469 int32_t ret = SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_NOTIFY_LOAD_REPAIR_PATCH),
470 data, reply, option);
471 if (ret != 0) {
472 TAG_LOGE(AAFwkTag::APPMGR, "ScheduleNotifyLoadRepairPatch, Send request failed with errno %{public}d.", ret);
473 return ret;
474 }
475
476 return reply.ReadInt32();
477 }
478
ScheduleNotifyHotReloadPage(const sptr<IQuickFixCallback> & callback,const int32_t recordId)479 int32_t AppSchedulerProxy::ScheduleNotifyHotReloadPage(const sptr<IQuickFixCallback> &callback, const int32_t recordId)
480 {
481 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
482 MessageParcel data;
483 if (!WriteInterfaceToken(data)) {
484 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed!");
485 return ERR_INVALID_DATA;
486 }
487
488 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
489 TAG_LOGE(AAFwkTag::APPMGR, "Write callback failed.");
490 return ERR_INVALID_DATA;
491 }
492
493 if (!data.WriteInt32(recordId)) {
494 TAG_LOGE(AAFwkTag::APPMGR, "Write record id failed.");
495 return ERR_INVALID_DATA;
496 }
497
498 MessageParcel reply;
499 MessageOption option;
500 auto ret = SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_NOTIFY_HOT_RELOAD_PAGE),
501 data, reply, option);
502 if (ret != 0) {
503 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with errno %{public}d.", ret);
504 return ret;
505 }
506
507 return reply.ReadInt32();
508 }
509
ScheduleNotifyUnLoadRepairPatch(const std::string & bundleName,const sptr<IQuickFixCallback> & callback,const int32_t recordId)510 int32_t AppSchedulerProxy::ScheduleNotifyUnLoadRepairPatch(const std::string &bundleName,
511 const sptr<IQuickFixCallback> &callback, const int32_t recordId)
512 {
513 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
514 MessageParcel data;
515 if (!WriteInterfaceToken(data)) {
516 TAG_LOGE(AAFwkTag::APPMGR, "Schedule notify unload patch, Write interface token failed.");
517 return ERR_INVALID_DATA;
518 }
519
520 if (!data.WriteString(bundleName)) {
521 TAG_LOGE(AAFwkTag::APPMGR, "Schedule notify unload patch, Write bundle name failed.");
522 return ERR_INVALID_DATA;
523 }
524
525 if (callback == nullptr || !data.WriteRemoteObject(callback->AsObject())) {
526 TAG_LOGE(AAFwkTag::APPMGR, "Write callback failed.");
527 return ERR_INVALID_DATA;
528 }
529
530 if (!data.WriteInt32(recordId)) {
531 TAG_LOGE(AAFwkTag::APPMGR, "Write record id failed.");
532 return ERR_INVALID_DATA;
533 }
534
535 MessageParcel reply;
536 MessageOption option;
537 int32_t ret = SendTransactCmd(
538 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_NOTIFY_UNLOAD_REPAIR_PATCH), data, reply, option);
539 if (ret != 0) {
540 TAG_LOGE(AAFwkTag::APPMGR, "Schedule notify unload patch, Send request failed with errno %{public}d.", ret);
541 return ret;
542 }
543
544 return reply.ReadInt32();
545 }
546
ScheduleNotifyAppFault(const FaultData & faultData)547 int32_t AppSchedulerProxy::ScheduleNotifyAppFault(const FaultData &faultData)
548 {
549 MessageParcel data;
550
551 if (!WriteInterfaceToken(data)) {
552 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
553 return ERR_INVALID_DATA;
554 }
555
556 if (!data.WriteParcelable(&faultData)) {
557 TAG_LOGE(AAFwkTag::APPMGR, "Write FaultData error.");
558 return ERR_FLATTEN_OBJECT;
559 }
560
561 MessageParcel reply;
562 MessageOption option(MessageOption::TF_ASYNC);
563 auto ret = SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_NOTIFY_FAULT),
564 data, reply, option);
565 if (ret != NO_ERROR) {
566 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
567 return ret;
568 }
569
570 return reply.ReadInt32();
571 }
572
ScheduleChangeAppGcState(int32_t state)573 int32_t AppSchedulerProxy::ScheduleChangeAppGcState(int32_t state)
574 {
575 MessageParcel data;
576
577 if (!WriteInterfaceToken(data)) {
578 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed");
579 return ERR_INVALID_DATA;
580 }
581
582 data.WriteInt32(state);
583 MessageParcel reply;
584 MessageOption option(MessageOption::TF_ASYNC);
585 auto ret = SendTransactCmd(static_cast<uint32_t>(IAppScheduler::Message::APP_GC_STATE_CHANGE),
586 data, reply, option);
587 if (ret != NO_ERROR) {
588 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code %{public}d.", ret);
589 return ret;
590 }
591
592 return NO_ERROR;
593 }
594
AttachAppDebug()595 void AppSchedulerProxy::AttachAppDebug()
596 {
597 TAG_LOGD(AAFwkTag::APPMGR, "called");
598 MessageParcel data;
599 if (!WriteInterfaceToken(data)) {
600 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
601 return;
602 }
603
604 MessageParcel reply;
605 MessageOption option(MessageOption::TF_ASYNC);
606 auto ret = SendTransactCmd(
607 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_ATTACH_APP_DEBUG), data, reply, option);
608 if (ret != NO_ERROR) {
609 TAG_LOGE(AAFwkTag::APPMGR, "Failed to send request with error code: %{public}d", ret);
610 }
611 }
612
DetachAppDebug()613 void AppSchedulerProxy::DetachAppDebug()
614 {
615 TAG_LOGD(AAFwkTag::APPMGR, "called");
616 MessageParcel data;
617 if (!WriteInterfaceToken(data)) {
618 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
619 return;
620 }
621
622 MessageParcel reply;
623 MessageOption option(MessageOption::TF_ASYNC);
624 auto ret = SendTransactCmd(
625 static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_DETACH_APP_DEBUG), data, reply, option);
626 if (ret != NO_ERROR) {
627 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code: %{public}d", ret);
628 }
629 }
630
ScheduleDumpIpcStart(std::string & result)631 int32_t AppSchedulerProxy::ScheduleDumpIpcStart(std::string& result)
632 {
633 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleDumpIpcStart start");
634 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_DUMP_IPC_START);
635 MessageParcel data;
636 MessageParcel reply;
637 MessageOption option(MessageOption::TF_SYNC);
638 if (!WriteInterfaceToken(data)) {
639 result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT))
640 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
641 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
642 TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken.");
643 return DumpErrorCode::ERR_INTERNAL_ERROR;
644 }
645 int32_t ret = SendTransactCmd(operation, data, reply, option);
646 if (ret != NO_ERROR) {
647 result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT))
648 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
649 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
650 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
651 return DumpErrorCode::ERR_INTERNAL_ERROR;
652 }
653 if (!reply.ReadString(result)) {
654 result.append(MSG_DUMP_IPC_START_STAT, strlen(MSG_DUMP_IPC_START_STAT))
655 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
656 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
657 TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpIpcStart result");
658 return DumpErrorCode::ERR_INTERNAL_ERROR;
659 }
660 return DumpErrorCode::ERR_OK;
661 }
662
ScheduleDumpIpcStop(std::string & result)663 int32_t AppSchedulerProxy::ScheduleDumpIpcStop(std::string& result)
664 {
665 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleDumpIpcStop start");
666 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_DUMP_IPC_STOP);
667 MessageParcel data;
668 MessageParcel reply;
669 MessageOption option(MessageOption::TF_SYNC);
670 if (!WriteInterfaceToken(data)) {
671 result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT))
672 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
673 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
674 TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken.");
675 return DumpErrorCode::ERR_INTERNAL_ERROR;
676 }
677 int32_t ret = SendTransactCmd(operation, data, reply, option);
678 if (ret != NO_ERROR) {
679 result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT))
680 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
681 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
682 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
683 return DumpErrorCode::ERR_INTERNAL_ERROR;
684 }
685 if (!reply.ReadString(result)) {
686 result.append(MSG_DUMP_IPC_STOP_STAT, strlen(MSG_DUMP_IPC_STOP_STAT))
687 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
688 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
689 TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpIpcStop result");
690 return DumpErrorCode::ERR_INTERNAL_ERROR;
691 }
692 return DumpErrorCode::ERR_OK;
693 }
694
ScheduleDumpIpcStat(std::string & result)695 int32_t AppSchedulerProxy::ScheduleDumpIpcStat(std::string& result)
696 {
697 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleDumpIpcStat start");
698 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_DUMP_IPC_STAT);
699 MessageParcel data;
700 MessageParcel reply;
701 MessageOption option(MessageOption::TF_SYNC);
702 if (!WriteInterfaceToken(data)) {
703 result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT))
704 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
705 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
706 TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken.");
707 return DumpErrorCode::ERR_INTERNAL_ERROR;
708 }
709 int32_t ret = SendTransactCmd(operation, data, reply, option);
710 if (ret != NO_ERROR) {
711 result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT))
712 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
713 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
714 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
715 return DumpErrorCode::ERR_INTERNAL_ERROR;
716 }
717 if (!reply.ReadString(result)) {
718 result.append(MSG_DUMP_IPC_STAT, strlen(MSG_DUMP_IPC_STAT))
719 .append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
720 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
721 TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpIpcStat result");
722 return DumpErrorCode::ERR_INTERNAL_ERROR;
723 }
724 return DumpErrorCode::ERR_OK;
725 }
726
ScheduleDumpFfrt(std::string & result)727 int32_t AppSchedulerProxy::ScheduleDumpFfrt(std::string& result)
728 {
729 TAG_LOGD(AAFwkTag::APPMGR, "AppSchedulerProxy::ScheduleDumpFfrt start");
730 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_DUMP_FFRT);
731 MessageParcel data;
732 MessageParcel reply;
733 reply.SetMaxCapacity(MAX_CAPACITY);
734 MessageOption option(MessageOption::TF_SYNC);
735 if (!WriteInterfaceToken(data)) {
736 result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
737 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
738 TAG_LOGE(AAFwkTag::APPMGR, "AppSchedulerProxy !WriteInterfaceToken.");
739 return DumpErrorCode::ERR_INTERNAL_ERROR;
740 }
741 int32_t ret = SendTransactCmd(operation, data, reply, option);
742 if (ret != NO_ERROR) {
743 result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
744 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
745 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
746 return DumpErrorCode::ERR_INTERNAL_ERROR;
747 }
748 if (!reply.ReadString(result)) {
749 result.append(MSG_DUMP_FAIL, strlen(MSG_DUMP_FAIL))
750 .append(MSG_DUMP_FAIL_REASON_INTERNAL, strlen(MSG_DUMP_FAIL_REASON_INTERNAL));
751 TAG_LOGE(AAFwkTag::APPMGR, "Fail to read string of ScheduleDumpFfrt result");
752 return DumpErrorCode::ERR_INTERNAL_ERROR;
753 }
754 return DumpErrorCode::ERR_OK;
755 }
756
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)757 int32_t AppSchedulerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
758 MessageParcel &reply, MessageOption &option)
759 {
760 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
761 sptr<IRemoteObject> remote = Remote();
762 if (remote == nullptr) {
763 TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
764 return ERR_NULL_OBJECT;
765 }
766
767 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, "remote->SendRequest");
768 auto ret = remote->SendRequest(code, data, reply, option);
769 if (ret != NO_ERROR) {
770 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed with error code: %{public}d", ret);
771 return ret;
772 }
773 return ret;
774 }
775
ScheduleCacheProcess()776 void AppSchedulerProxy::ScheduleCacheProcess()
777 {
778 uint32_t operation = static_cast<uint32_t>(IAppScheduler::Message::SCHEDULE_CACHE_PROCESS);
779 MessageParcel data;
780 MessageParcel reply;
781 MessageOption option(MessageOption::TF_ASYNC);
782 if (!WriteInterfaceToken(data)) {
783 return;
784 }
785 int32_t ret = SendTransactCmd(operation, data, reply, option);
786 if (ret != NO_ERROR) {
787 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
788 }
789 }
790 } // namespace AppExecFwk
791 } // namespace OHOS
792