1 /*
2 * Copyright (c) 2021-2025 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 #include "ability_scheduler_proxy.h"
16
17 #include "ability_manager_errors.h"
18 #include "data_ability_observer_interface.h"
19 #include "data_ability_operation.h"
20 #include "data_ability_predicates.h"
21 #include "data_ability_result.h"
22 #include "error_msg_util.h"
23 #include "hilog_tag_wrapper.h"
24 #include "hitrace_meter.h"
25 #include "ipc_capacity_wrap.h"
26 #include "ishared_result_set.h"
27 #include "session_info.h"
28 #include "values_bucket.h"
29
30 namespace OHOS {
31 namespace AAFwk {
32 namespace {
33 const int64_t SCHEDULE_IPC_LOG_TIME = 10000;
34 }
WriteInterfaceToken(MessageParcel & data)35 bool AbilitySchedulerProxy::WriteInterfaceToken(MessageParcel &data)
36 {
37 if (!data.WriteInterfaceToken(AbilitySchedulerProxy::GetDescriptor())) {
38 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
39 return false;
40 }
41 return true;
42 }
43
ScheduleAbilityTransaction(const Want & want,const LifeCycleStateInfo & stateInfo,sptr<SessionInfo> sessionInfo)44 bool AbilitySchedulerProxy::ScheduleAbilityTransaction(const Want &want, const LifeCycleStateInfo &stateInfo,
45 sptr<SessionInfo> sessionInfo)
46 {
47 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
48 TAG_LOGD(AAFwkTag::ABILITYMGR, "begin");
49 auto start = std::chrono::system_clock::now();
50 MessageParcel data;
51 MessageParcel reply;
52 MessageOption option(MessageOption::TF_ASYNC);
53 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
54 if (!WriteInterfaceToken(data)) {
55 return false;
56 }
57 auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
58 "ScheduleAbilityTransaction");
59 if (!data.WriteParcelable(&want)) {
60 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
61 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write want failed");
62 return false;
63 }
64 data.WriteParcelable(&stateInfo);
65 if (sessionInfo) {
66 SessionInfo tmpInfo = *sessionInfo;
67 tmpInfo.want = Want();
68 if (!data.WriteBool(true) || !data.WriteParcelable(&tmpInfo)) {
69 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo failed");
70 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write sessionInfo failed");
71 return false;
72 }
73 } else if (!data.WriteBool(false)) {
74 return false;
75 }
76 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_TRANSACTION, data, reply, option);
77 if (err != NO_ERROR) {
78 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
79 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey,
80 std::string("ScheduleAbilityTransaction ipc error " + std::to_string(err)));
81 return false;
82 }
83 int64_t cost = std::chrono::duration_cast<std::chrono::microseconds>(
84 std::chrono::system_clock::now() - start).count();
85 if (cost > SCHEDULE_IPC_LOG_TIME) {
86 TAG_LOGI(AAFwkTag::ABILITYMGR, "ScheduleAbilityTransaction proxy cost %{public}" PRId64 "mirco seconds,"
87 " data size: %{public}zu", cost, data.GetWritePosition());
88 } else {
89 TAG_LOGD(AAFwkTag::ABILITYMGR, "ScheduleAbilityTransaction proxy cost %{public}" PRId64 "mirco seconds,"
90 " data size: %{public}zu", cost, data.GetWritePosition());
91 }
92 return true;
93 }
94
ScheduleShareData(const int32_t & uniqueId)95 void AbilitySchedulerProxy::ScheduleShareData(const int32_t &uniqueId)
96 {
97 MessageParcel data;
98 MessageParcel reply;
99 MessageOption option(MessageOption::TF_ASYNC);
100 if (!WriteInterfaceToken(data)) {
101 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
102 return;
103 }
104 if (!data.WriteInt32(uniqueId)) {
105 TAG_LOGE(AAFwkTag::ABILITYMGR, "uniqueId write failed");
106 return;
107 }
108 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_SHARE_DATA, data, reply, option);
109 if (err != NO_ERROR) {
110 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
111 }
112 return;
113 }
114
SendResult(int requestCode,int resultCode,const Want & resultWant)115 void AbilitySchedulerProxy::SendResult(int requestCode, int resultCode, const Want &resultWant)
116 {
117 MessageParcel data;
118 MessageParcel reply;
119 MessageOption option(MessageOption::TF_ASYNC);
120 if (!WriteInterfaceToken(data)) {
121 return;
122 }
123 if (!data.WriteInt32(requestCode)) {
124 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestCode failed");
125 return;
126 }
127 if (!data.WriteInt32(resultCode)) {
128 TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed");
129 return;
130 }
131 if (!data.WriteParcelable(&resultWant)) {
132 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable");
133 return;
134 }
135 int32_t err = SendTransactCmd(IAbilityScheduler::SEND_RESULT, data, reply, option);
136 if (err != NO_ERROR) {
137 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
138 }
139 }
140
ScheduleConnectAbility(const Want & want)141 void AbilitySchedulerProxy::ScheduleConnectAbility(const Want &want)
142 {
143 MessageParcel data;
144 MessageParcel reply;
145 MessageOption option(MessageOption::TF_ASYNC);
146 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
147 if (!WriteInterfaceToken(data)) {
148 return;
149 }
150 if (!data.WriteParcelable(&want)) {
151 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail to WriteParcelable");
152 return;
153 }
154 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_CONNECT, data, reply, option);
155 if (err != NO_ERROR) {
156 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail, err: %{public}d", err);
157 }
158 }
159
ScheduleDisconnectAbility(const Want & want)160 void AbilitySchedulerProxy::ScheduleDisconnectAbility(const Want &want)
161 {
162 MessageParcel data;
163 MessageParcel reply;
164 MessageOption option(MessageOption::TF_ASYNC);
165 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
166 if (!WriteInterfaceToken(data)) {
167 return;
168 }
169 if (!data.WriteParcelable(&want)) {
170 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail to WriteParcelable");
171 return;
172 }
173
174 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_DISCONNECT, data, reply, option);
175 if (err != NO_ERROR) {
176 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail, err: %{public}d", err);
177 }
178 }
179
ScheduleCommandAbility(const Want & want,bool restart,int startId)180 void AbilitySchedulerProxy::ScheduleCommandAbility(const Want &want, bool restart, int startId)
181 {
182 MessageParcel data;
183 MessageParcel reply;
184 MessageOption option(MessageOption::TF_ASYNC);
185 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
186 if (!WriteInterfaceToken(data)) {
187 return;
188 }
189 if (!data.WriteParcelable(&want)) {
190 TAG_LOGE(AAFwkTag::SERVICE_EXT, "WriteParcelable failed");
191 return;
192 }
193 if (!data.WriteBool(restart)) {
194 TAG_LOGE(AAFwkTag::SERVICE_EXT, "WriteBool failed");
195 return;
196 }
197 TAG_LOGD(AAFwkTag::SERVICE_EXT, "WriteInt32,startId:%{public}d", startId);
198 if (!data.WriteInt32(startId)) {
199 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail to WriteInt32");
200 return;
201 }
202
203 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_COMMAND, data, reply, option);
204 if (err != NO_ERROR) {
205 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail, err: %{public}d", err);
206 }
207 }
208
SchedulePrepareTerminateAbility()209 bool AbilitySchedulerProxy::SchedulePrepareTerminateAbility()
210 {
211 MessageParcel data;
212 MessageParcel reply;
213 MessageOption option(MessageOption::TF_ASYNC);
214 if (!WriteInterfaceToken(data)) {
215 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to write interface");
216 return false;
217 }
218
219 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_PREPARE_TERMINATE, data, reply, option);
220 if (err != NO_ERROR) {
221 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed, err: %{public}d", err);
222 return false;
223 }
224 return true;
225 }
226
ScheduleCommandAbilityWindow(const Want & want,const sptr<SessionInfo> & sessionInfo,WindowCommand winCmd)227 void AbilitySchedulerProxy::ScheduleCommandAbilityWindow(const Want &want, const sptr<SessionInfo> &sessionInfo,
228 WindowCommand winCmd)
229 {
230 MessageParcel data;
231 MessageParcel reply;
232 MessageOption option(MessageOption::TF_ASYNC);
233 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
234 if (!WriteInterfaceToken(data)) {
235 return;
236 }
237 if (!data.WriteParcelable(&want)) {
238 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeParcelable failed");
239 return;
240 }
241 if (!data.WriteParcelable(sessionInfo)) {
242 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeParcelable failed");
243 return;
244 }
245 if (!data.WriteInt32(winCmd)) {
246 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32");
247 return;
248 }
249
250 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_COMMAND_WINDOW, data, reply, option);
251 if (err != NO_ERROR) {
252 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
253 }
254 }
255
ScheduleSaveAbilityState()256 void AbilitySchedulerProxy::ScheduleSaveAbilityState()
257 {
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option(MessageOption::TF_ASYNC);
261 if (!WriteInterfaceToken(data)) {
262 return;
263 }
264 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_SAVE_ABILITY_STATE, data, reply, option);
265 if (err != NO_ERROR) {
266 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
267 }
268 }
269
ScheduleRestoreAbilityState(const PacMap & inState)270 void AbilitySchedulerProxy::ScheduleRestoreAbilityState(const PacMap &inState)
271 {
272 MessageParcel data;
273 MessageParcel reply;
274 MessageOption option(MessageOption::TF_ASYNC);
275 if (!WriteInterfaceToken(data)) {
276 return;
277 }
278 if (!data.WriteParcelable(&inState)) {
279 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeParcelable err");
280 return;
281 }
282 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_RESTORE_ABILITY_STATE, data, reply, option);
283 if (err != NO_ERROR) {
284 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
285 }
286 }
287
288 /**
289 * @brief Obtains the MIME types of files supported.
290 *
291 * @param uri Indicates the path of the files to obtain.
292 * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null.
293 *
294 * @return Returns the matched MIME types. If there is no match, null is returned.
295 */
GetFileTypes(const Uri & uri,const std::string & mimeTypeFilter)296 std::vector<std::string> AbilitySchedulerProxy::GetFileTypes(const Uri &uri, const std::string &mimeTypeFilter)
297 {
298 std::vector<std::string> types;
299
300 MessageParcel data;
301 MessageParcel reply;
302 MessageOption option;
303
304 if (!WriteInterfaceToken(data)) {
305 return types;
306 }
307
308 if (!data.WriteParcelable(&uri)) {
309 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
310 return types;
311 }
312
313 if (!data.WriteString(mimeTypeFilter)) {
314 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString mimeTypeFilter");
315 return types;
316 }
317
318 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_GETFILETYPES, data, reply, option);
319 if (err != NO_ERROR) {
320 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
321 }
322
323 if (!reply.ReadStringVector(&types)) {
324 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadStringVector types");
325 }
326
327 return types;
328 }
329
330 /**
331 * @brief Opens a file in a specified remote path.
332 *
333 * @param uri Indicates the path of the file to open.
334 * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
335 * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
336 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing data,
337 * or "rwt" for read and write access that truncates any existing file.
338 *
339 * @return Returns the file descriptor.
340 */
OpenFile(const Uri & uri,const std::string & mode)341 int AbilitySchedulerProxy::OpenFile(const Uri &uri, const std::string &mode)
342 {
343 int fd = -1;
344
345 MessageParcel data;
346 MessageParcel reply;
347 MessageOption option;
348
349 if (!WriteInterfaceToken(data)) {
350 return fd;
351 }
352
353 if (!data.WriteParcelable(&uri)) {
354 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
355 return fd;
356 }
357
358 if (!data.WriteString(mode)) {
359 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString mode");
360 return fd;
361 }
362
363 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_OPENFILE, data, reply, option);
364 if (err != NO_ERROR) {
365 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
366 return fd;
367 }
368
369 fd = reply.ReadFileDescriptor();
370 if (fd == -1) {
371 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 fd");
372 return fd;
373 }
374
375 return fd;
376 }
377
378 /**
379 * @brief This is like openFile, open a file that need to be able to return sub-sections of files,often assets
380 * inside of their .hap.
381 *
382 * @param uri Indicates the path of the file to open.
383 * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
384 * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing file,
385 * "wa" for write-only access to append to any existing data, "rw" for read and write access on any existing
386 * data, or "rwt" for read and write access that truncates any existing file.
387 *
388 * @return Returns the RawFileDescriptor object containing file descriptor.
389 */
OpenRawFile(const Uri & uri,const std::string & mode)390 int AbilitySchedulerProxy::OpenRawFile(const Uri &uri, const std::string &mode)
391 {
392 int fd = -1;
393
394 MessageParcel data;
395 MessageParcel reply;
396 MessageOption option;
397
398 if (!WriteInterfaceToken(data)) {
399 return fd;
400 }
401
402 if (!data.WriteParcelable(&uri)) {
403 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
404 return fd;
405 }
406
407 if (!data.WriteString(mode)) {
408 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString mode");
409 return fd;
410 }
411
412 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_OPENRAWFILE, data, reply, option);
413 if (err != NO_ERROR) {
414 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
415 return fd;
416 }
417
418 if (!reply.ReadInt32(fd)) {
419 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 fd");
420 return fd;
421 }
422
423 return fd;
424 }
425
426 /**
427 * @brief Inserts a single data record into the database.
428 *
429 * @param uri Indicates the path of the data to operate.
430 * @param value Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
431 *
432 * @return Returns the index of the inserted data record.
433 */
Insert(const Uri & uri,const NativeRdb::ValuesBucket & value)434 int AbilitySchedulerProxy::Insert(const Uri &uri, const NativeRdb::ValuesBucket &value)
435 {
436 int index = -1;
437
438 MessageParcel data;
439 MessageParcel reply;
440 MessageOption option;
441
442 if (!WriteInterfaceToken(data)) {
443 return index;
444 }
445
446 if (!data.WriteParcelable(&uri)) {
447 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
448 return index;
449 }
450
451 if (!value.Marshalling(data)) {
452 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable value");
453 return index;
454 }
455
456 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_INSERT, data, reply, option);
457 if (err != NO_ERROR) {
458 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
459 return index;
460 }
461
462 if (!reply.ReadInt32(index)) {
463 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 index");
464 return index;
465 }
466
467 return index;
468 }
469
470 /**
471 * @brief Inserts a single data record into the database.
472 *
473 * @param uri Indicates the path of the data to operate.
474 * @param value Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
475 *
476 * @return Returns the index of the inserted data record.
477 */
Call(const Uri & uri,const std::string & method,const std::string & arg,const AppExecFwk::PacMap & pacMap)478 std::shared_ptr<AppExecFwk::PacMap> AbilitySchedulerProxy::Call(
479 const Uri &uri, const std::string &method, const std::string &arg, const AppExecFwk::PacMap &pacMap)
480 {
481 MessageParcel data;
482 MessageParcel reply;
483 MessageOption option;
484
485 if (!WriteInterfaceToken(data)) {
486 return nullptr;
487 }
488
489 if (!data.WriteParcelable(&uri)) {
490 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
491 return nullptr;
492 }
493
494 if (!data.WriteString(method)) {
495 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString method");
496 return nullptr;
497 }
498
499 if (!data.WriteString(arg)) {
500 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString arg");
501 return nullptr;
502 }
503
504 if (!data.WriteParcelable(&pacMap)) {
505 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable pacMap");
506 return nullptr;
507 }
508
509 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_CALL, data, reply, option);
510 if (err != NO_ERROR) {
511 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
512 return nullptr;
513 }
514 std::shared_ptr<AppExecFwk::PacMap> result(reply.ReadParcelable<AppExecFwk::PacMap>());
515 if (!result) {
516 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable value null");
517 return nullptr;
518 }
519 return result;
520 }
521
522 /**
523 * @brief Updates data records in the database.
524 *
525 * @param uri Indicates the path of data to update.
526 * @param value Indicates the data to update. This parameter can be null.
527 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
528 *
529 * @return Returns the number of data records updated.
530 */
Update(const Uri & uri,const NativeRdb::ValuesBucket & value,const NativeRdb::DataAbilityPredicates & predicates)531 int AbilitySchedulerProxy::Update(const Uri &uri, const NativeRdb::ValuesBucket &value,
532 const NativeRdb::DataAbilityPredicates &predicates)
533 {
534 int index = -1;
535
536 MessageParcel data;
537 MessageParcel reply;
538 MessageOption option;
539
540 if (!WriteInterfaceToken(data)) {
541 return index;
542 }
543
544 if (!data.WriteParcelable(&uri)) {
545 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
546 return index;
547 }
548
549 if (!value.Marshalling(data)) {
550 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable value");
551 return index;
552 }
553
554 if (!data.WriteParcelable(&predicates)) {
555 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable predicates");
556 return index;
557 }
558
559 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_UPDATE, data, reply, option);
560 if (err != NO_ERROR) {
561 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
562 return index;
563 }
564
565 if (!reply.ReadInt32(index)) {
566 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 index");
567 return index;
568 }
569
570 return index;
571 }
572
573 /**
574 * @brief Deletes one or more data records from the database.
575 *
576 * @param uri Indicates the path of the data to operate.
577 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
578 *
579 * @return Returns the number of data records deleted.
580 */
Delete(const Uri & uri,const NativeRdb::DataAbilityPredicates & predicates)581 int AbilitySchedulerProxy::Delete(const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates)
582 {
583 int index = -1;
584
585 MessageParcel data;
586 MessageParcel reply;
587 MessageOption option;
588
589 if (!WriteInterfaceToken(data)) {
590 return index;
591 }
592
593 if (!data.WriteParcelable(&uri)) {
594 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
595 return index;
596 }
597
598 if (!data.WriteParcelable(&predicates)) {
599 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable predicates");
600 return index;
601 }
602
603 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_DELETE, data, reply, option);
604 if (err != NO_ERROR) {
605 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
606 return index;
607 }
608
609 if (!reply.ReadInt32(index)) {
610 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 index");
611 return index;
612 }
613
614 return index;
615 }
616
617 /**
618 * @brief Deletes one or more data records from the database.
619 *
620 * @param uri Indicates the path of data to query.
621 * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
622 * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
623 *
624 * @return Returns the query result.
625 */
Query(const Uri & uri,std::vector<std::string> & columns,const NativeRdb::DataAbilityPredicates & predicates)626 std::shared_ptr<NativeRdb::AbsSharedResultSet> AbilitySchedulerProxy::Query(
627 const Uri &uri, std::vector<std::string> &columns, const NativeRdb::DataAbilityPredicates &predicates)
628 {
629 MessageParcel data;
630 MessageParcel reply;
631 MessageOption option;
632
633 if (!WriteInterfaceToken(data)) {
634 return nullptr;
635 }
636
637 if (!data.WriteParcelable(&uri)) {
638 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
639 return nullptr;
640 }
641
642 if (!data.WriteStringVector(columns)) {
643 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteStringVector columns");
644 return nullptr;
645 }
646
647 if (!data.WriteParcelable(&predicates)) {
648 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable predicates");
649 return nullptr;
650 }
651
652 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_QUERY, data, reply, option);
653 if (err != NO_ERROR) {
654 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
655 return nullptr;
656 }
657 return OHOS::NativeRdb::ISharedResultSet::ReadFromParcel(reply);
658 }
659
660 /**
661 * @brief Obtains the MIME type matching the data specified by the URI of the Data ability. This method should be
662 * implemented by a Data ability. Data abilities supports general data types, including text, HTML, and JPEG.
663 *
664 * @param uri Indicates the URI of the data.
665 *
666 * @return Returns the MIME type that matches the data specified by uri.
667 */
GetType(const Uri & uri)668 std::string AbilitySchedulerProxy::GetType(const Uri &uri)
669 {
670 std::string type;
671
672 MessageParcel data;
673 MessageParcel reply;
674 MessageOption option;
675
676 if (!WriteInterfaceToken(data)) {
677 return type;
678 }
679
680 if (!data.WriteParcelable(&uri)) {
681 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
682 return type;
683 }
684
685 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_GETTYPE, data, reply, option);
686 if (err != NO_ERROR) {
687 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
688 return type;
689 }
690
691 type = reply.ReadString();
692 if (type.empty()) {
693 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadString type");
694 return type;
695 }
696
697 return type;
698 }
699
700 /**
701 * @brief Reloads data in the database.
702 *
703 * @param uri Indicates the position where the data is to reload. This parameter is mandatory.
704 * @param extras Indicates the PacMap object containing the additional parameters to be passed in this call. This
705 * parameter can be null. If a custom Sequenceable object is put in the PacMap object and will be transferred across
706 * processes, you must call BasePacMap.setClassLoader(ClassLoader) to set a class loader for the custom object.
707 *
708 * @return Returns true if the data is successfully reloaded; returns false otherwise.
709 */
Reload(const Uri & uri,const PacMap & extras)710 bool AbilitySchedulerProxy::Reload(const Uri &uri, const PacMap &extras)
711 {
712 bool ret = false;
713
714 MessageParcel data;
715 MessageParcel reply;
716 MessageOption option;
717
718 if (!WriteInterfaceToken(data)) {
719 return ret;
720 }
721
722 if (!data.WriteParcelable(&uri)) {
723 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
724 return ret;
725 }
726
727 if (!data.WriteParcelable(&extras)) {
728 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable extras");
729 return ret;
730 }
731
732 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_RELOAD, data, reply, option);
733 if (err != NO_ERROR) {
734 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
735 return ret;
736 }
737
738 ret = reply.ReadBool();
739 if (!ret) {
740 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadBool ret");
741 return ret;
742 }
743
744 return ret;
745 }
746
747 /**
748 * @brief Inserts multiple data records into the database.
749 *
750 * @param uri Indicates the path of the data to operate.
751 * @param values Indicates the data records to insert.
752 *
753 * @return Returns the number of data records inserted.
754 */
BatchInsert(const Uri & uri,const std::vector<NativeRdb::ValuesBucket> & values)755 int AbilitySchedulerProxy::BatchInsert(const Uri &uri, const std::vector<NativeRdb::ValuesBucket> &values)
756 {
757 int ret = -1;
758
759 MessageParcel data;
760 MessageParcel reply;
761 MessageOption option;
762
763 if (!WriteInterfaceToken(data)) {
764 return ret;
765 }
766
767 if (!data.WriteParcelable(&uri)) {
768 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
769 return ret;
770 }
771
772 int count = (int)values.size();
773 if (!data.WriteInt32(count)) {
774 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
775 return ret;
776 }
777
778 for (int i = 0; i < count; i++) {
779 if (!values[i].Marshalling(data)) {
780 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, index: %{public}d", i);
781 return ret;
782 }
783 }
784
785 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_BATCHINSERT, data, reply, option);
786 if (err != NO_ERROR) {
787 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
788 return ret;
789 }
790
791 if (!reply.ReadInt32(ret)) {
792 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 index");
793 return ret;
794 }
795
796 return ret;
797 }
798
799 /**
800 * @brief Registers an observer to DataObsMgr specified by the given Uri.
801 *
802 * @param uri, Indicates the path of the data to operate.
803 * @param dataObserver, Indicates the IDataAbilityObserver object.
804 */
ScheduleRegisterObserver(const Uri & uri,const sptr<IDataAbilityObserver> & dataObserver)805 bool AbilitySchedulerProxy::ScheduleRegisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver)
806 {
807 MessageParcel data;
808 MessageParcel reply;
809 MessageOption option;
810
811 if (!WriteInterfaceToken(data)) {
812 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s WriteInterfaceToken(data) return false", __func__);
813 return false;
814 }
815
816 if (!data.WriteParcelable(&uri)) {
817 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s failed to WriteParcelable uri ", __func__);
818 return false;
819 }
820
821 if (!data.WriteRemoteObject(dataObserver->AsObject())) {
822 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s failed to WriteParcelable dataObserver ", __func__);
823 return false;
824 }
825
826 int32_t result = SendTransactCmd(IAbilityScheduler::SCHEDULE_REGISTEROBSERVER, data, reply, option);
827 if (result == ERR_NONE) {
828 TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s SendRequest ok, retval: %{public}d", __func__, reply.ReadInt32());
829 return true;
830 } else {
831 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s SendRequest error, result=%{public}d", __func__, result);
832 return false;
833 }
834 }
835
836 /**
837 * @brief Deregisters an observer used for DataObsMgr specified by the given Uri.
838 *
839 * @param uri, Indicates the path of the data to operate.
840 * @param dataObserver, Indicates the IDataAbilityObserver object.
841 */
ScheduleUnregisterObserver(const Uri & uri,const sptr<IDataAbilityObserver> & dataObserver)842 bool AbilitySchedulerProxy::ScheduleUnregisterObserver(const Uri &uri, const sptr<IDataAbilityObserver> &dataObserver)
843 {
844 MessageParcel data;
845 MessageParcel reply;
846 MessageOption option;
847
848 if (!WriteInterfaceToken(data)) {
849 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s WriteInterfaceToken(data) return false", __func__);
850 return false;
851 }
852
853 if (!data.WriteParcelable(&uri)) {
854 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s failed to WriteParcelable uri ", __func__);
855 return false;
856 }
857
858 if (!data.WriteRemoteObject(dataObserver->AsObject())) {
859 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s failed to WriteParcelable dataObserver ", __func__);
860 return false;
861 }
862
863 int32_t result = SendTransactCmd(IAbilityScheduler::SCHEDULE_UNREGISTEROBSERVER, data, reply, option);
864 if (result == ERR_NONE) {
865 TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s SendRequest ok, retval is %{public}d", __func__, reply.ReadInt32());
866 return true;
867 } else {
868 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s SendRequest error, result=%{public}d", __func__, result);
869 return false;
870 }
871 }
872
873 /**
874 * @brief Notifies the registered observers of a change to the data resource specified by Uri.
875 *
876 * @param uri, Indicates the path of the data to operate.
877 */
ScheduleNotifyChange(const Uri & uri)878 bool AbilitySchedulerProxy::ScheduleNotifyChange(const Uri &uri)
879 {
880 MessageParcel data;
881 MessageParcel reply;
882 MessageOption option;
883
884 if (!WriteInterfaceToken(data)) {
885 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s WriteInterfaceToken(data) return false", __func__);
886 return false;
887 }
888
889 if (!data.WriteParcelable(&uri)) {
890 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s failed to WriteParcelable uri ", __func__);
891 return false;
892 }
893
894 int32_t result = SendTransactCmd(IAbilityScheduler::SCHEDULE_NOTIFYCHANGE, data, reply, option);
895 if (result == ERR_NONE) {
896 TAG_LOGI(AAFwkTag::ABILITYMGR, "%{public}s SendRequest ok, retval: %{public}d", __func__, reply.ReadInt32());
897 return true;
898 } else {
899 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s SendRequest error, result=%{public}d", __func__, result);
900 return false;
901 }
902 }
903
904 /**
905 * @brief Converts the given uri that refer to the Data ability into a normalized URI. A normalized URI can be used
906 * across devices, persisted, backed up, and restored. It can refer to the same item in the Data ability even if the
907 * context has changed. If you implement URI normalization for a Data ability, you must also implement
908 * denormalizeUri(ohos.utils.net.Uri) to enable URI denormalization. After this feature is enabled, URIs passed to
909 * any method that is called on the Data ability must require normalization verification and denormalization. The
910 * default implementation of this method returns null, indicating that this Data ability does not support URI
911 * normalization.
912 *
913 * @param uri Indicates the Uri object to normalize.
914 *
915 * @return Returns the normalized Uri object if the Data ability supports URI normalization; returns null otherwise.
916 */
NormalizeUri(const Uri & uri)917 Uri AbilitySchedulerProxy::NormalizeUri(const Uri &uri)
918 {
919 Uri urivalue("");
920
921 MessageParcel data;
922 MessageParcel reply;
923 MessageOption option;
924
925 if (!WriteInterfaceToken(data)) {
926 return urivalue;
927 }
928
929 if (!data.WriteParcelable(&uri)) {
930 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
931 return urivalue;
932 }
933
934 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_NORMALIZEURI, data, reply, option);
935 if (err != NO_ERROR) {
936 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
937 return Uri("");
938 }
939
940 std::unique_ptr<Uri> info(reply.ReadParcelable<Uri>());
941 if (!info) {
942 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable value null");
943 return Uri("");
944 }
945 return *info;
946 }
947
948 /**
949 * @brief Converts the given normalized uri generated by normalizeUri(ohos.utils.net.Uri) into a denormalized one.
950 * The default implementation of this method returns the original URI passed to it.
951 *
952 * @param uri uri Indicates the Uri object to denormalize.
953 *
954 * @return Returns the denormalized Uri object if the denormalization is successful; returns the original Uri passed
955 * to this method if there is nothing to do; returns null if the data identified by the original Uri cannot be found
956 * in the current environment.
957 */
DenormalizeUri(const Uri & uri)958 Uri AbilitySchedulerProxy::DenormalizeUri(const Uri &uri)
959 {
960 Uri urivalue("");
961
962 MessageParcel data;
963 MessageParcel reply;
964 MessageOption option;
965
966 if (!WriteInterfaceToken(data)) {
967 return urivalue;
968 }
969
970 if (!data.WriteParcelable(&uri)) {
971 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable uri");
972 return urivalue;
973 }
974
975 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_DENORMALIZEURI, data, reply, option);
976 if (err != NO_ERROR) {
977 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
978 return Uri("");
979 }
980
981 std::unique_ptr<Uri> info(reply.ReadParcelable<Uri>());
982 if (!info) {
983 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable value null");
984 return Uri("");
985 }
986 return *info;
987 }
988
ExecuteBatch(const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> & operations)989 std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> AbilitySchedulerProxy::ExecuteBatch(
990 const std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> &operations)
991 {
992 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
993 MessageParcel data;
994 MessageParcel reply;
995 MessageOption option;
996
997 std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> results;
998 results.clear();
999
1000 if (!WriteInterfaceToken(data)) {
1001 TAG_LOGE(AAFwkTag::ABILITYMGR, "writer token failed");
1002 return results;
1003 }
1004
1005 int count = (int)operations.size();
1006 if (!data.WriteInt32(count)) {
1007 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 ret failed");
1008 return results;
1009 }
1010
1011 for (int i = 0; i < count; i++) {
1012 if (!data.WriteParcelable(operations[i].get())) {
1013 TAG_LOGE(AAFwkTag::ABILITYMGR,
1014 "failed, index: %{public}d", i);
1015 return results;
1016 }
1017 }
1018
1019 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_EXECUTEBATCH, data, reply, option);
1020 if (err != NO_ERROR) {
1021 TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest failed, err: %{public}d", err);
1022 return results;
1023 }
1024
1025 int total = 0;
1026 if (!reply.ReadInt32(total)) {
1027 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 count %{public}d", total);
1028 return results;
1029 }
1030
1031 for (int i = 0; i < total; i++) {
1032 std::shared_ptr<AppExecFwk::DataAbilityResult> dataAbilityResult(
1033 reply.ReadParcelable<AppExecFwk::DataAbilityResult>());
1034 if (dataAbilityResult == nullptr) {
1035 TAG_LOGE(AAFwkTag::ABILITYMGR,
1036 "null dataAbilityResult, index: %{public}d", i);
1037 return results;
1038 }
1039 results.push_back(dataAbilityResult);
1040 }
1041 TAG_LOGI(AAFwkTag::ABILITYMGR, "end %{public}d", total);
1042 return results;
1043 }
1044
ContinueAbility(const std::string & deviceId,uint32_t versionCode)1045 void AbilitySchedulerProxy::ContinueAbility(const std::string& deviceId, uint32_t versionCode)
1046 {
1047 MessageParcel data;
1048 MessageParcel reply;
1049 MessageOption option(MessageOption::TF_ASYNC);
1050 if (!WriteInterfaceToken(data)) {
1051 TAG_LOGE(AAFwkTag::ABILITYMGR, "ContinueAbility fail to write token");
1052 return;
1053 }
1054 if (!data.WriteString(deviceId)) {
1055 TAG_LOGE(AAFwkTag::ABILITYMGR, "ContinueAbility fail to write deviceId");
1056 return;
1057 }
1058 if (!data.WriteUint32(versionCode)) {
1059 TAG_LOGE(AAFwkTag::ABILITYMGR, "ContinueAbility fail to write versionCode");
1060 return;
1061 }
1062
1063 int32_t err = SendTransactCmd(IAbilityScheduler::CONTINUE_ABILITY, data, reply, option);
1064 if (err != NO_ERROR) {
1065 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1066 }
1067 }
1068
NotifyContinuationResult(int32_t result)1069 void AbilitySchedulerProxy::NotifyContinuationResult(int32_t result)
1070 {
1071 MessageParcel data;
1072 MessageParcel reply;
1073 MessageOption option(MessageOption::TF_ASYNC);
1074 if (!WriteInterfaceToken(data)) {
1075 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyContinuationResult fail to write token");
1076 return;
1077 }
1078 if (!data.WriteInt32(result)) {
1079 TAG_LOGE(AAFwkTag::ABILITYMGR, "NotifyContinuationResult fail to write result");
1080 return;
1081 }
1082
1083 int32_t err = SendTransactCmd(IAbilityScheduler::NOTIFY_CONTINUATION_RESULT, data, reply, option);
1084 if (err != NO_ERROR) {
1085 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1086 }
1087 }
1088
DumpAbilityInfo(const std::vector<std::string> & params,std::vector<std::string> & info)1089 void AbilitySchedulerProxy::DumpAbilityInfo(const std::vector<std::string> ¶ms, std::vector<std::string> &info)
1090 {
1091 MessageParcel data;
1092 MessageParcel reply;
1093 MessageOption option(MessageOption::TF_ASYNC);
1094 if (!WriteInterfaceToken(data)) {
1095 TAG_LOGE(AAFwkTag::ABILITYMGR, "DumpAbilityRunner fail to write token");
1096 return;
1097 }
1098
1099 if (!data.WriteStringVector(params)) {
1100 TAG_LOGE(AAFwkTag::ABILITYMGR, "DumpAbilityRunner fail to write params");
1101 return;
1102 }
1103
1104 int32_t err = SendTransactCmd(IAbilityScheduler::DUMP_ABILITY_RUNNER_INNER, data, reply, option);
1105 if (err != NO_ERROR) {
1106 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1107 }
1108 }
1109
CallRequest()1110 void AbilitySchedulerProxy::CallRequest()
1111 {
1112 TAG_LOGD(AAFwkTag::ABILITYMGR, "start");
1113
1114 MessageParcel data;
1115 MessageParcel reply;
1116 MessageOption option(MessageOption::TF_ASYNC);
1117
1118 if (!WriteInterfaceToken(data)) {
1119 return;
1120 }
1121
1122 int32_t err = SendTransactCmd(IAbilityScheduler::REQUEST_CALL_REMOTE, data, reply, option);
1123 if (err != NO_ERROR) {
1124 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1125 return;
1126 }
1127
1128 TAG_LOGD(AAFwkTag::ABILITYMGR, "end");
1129 }
1130
OnExecuteIntent(const Want & want)1131 void AbilitySchedulerProxy::OnExecuteIntent(const Want &want)
1132 {
1133 TAG_LOGI(AAFwkTag::INTENT, "on execute intent proxy");
1134
1135 MessageParcel data;
1136 MessageParcel reply;
1137 MessageOption option(MessageOption::TF_ASYNC);
1138 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
1139 if (!WriteInterfaceToken(data)) {
1140 return;
1141 }
1142 data.WriteParcelable(&want);
1143 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ONEXECUTE_INTENT, data, reply, option);
1144 if (err != NO_ERROR) {
1145 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1146 }
1147
1148 TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
1149 }
1150
CreateModalUIExtension(const Want & want)1151 int32_t AbilitySchedulerProxy::CreateModalUIExtension(const Want &want)
1152 {
1153 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
1154 TAG_LOGD(AAFwkTag::ABILITYMGR, "AbilitySchedulerProxy::CreateModalUIExtension start");
1155 MessageParcel data;
1156 MessageParcel reply;
1157 MessageOption option(MessageOption::TF_ASYNC);
1158 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
1159 if (!WriteInterfaceToken(data)) {
1160 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface fail");
1161 return INNER_ERR;
1162 }
1163 if (!data.WriteParcelable(&want)) {
1164 TAG_LOGE(AAFwkTag::ABILITYMGR, "Write wants fail");
1165 return INNER_ERR;
1166 }
1167 int32_t err = SendTransactCmd(IAbilityScheduler::CREATE_MODAL_UI_EXTENSION, data, reply, option);
1168 if (err != NO_ERROR) {
1169 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1170 return err;
1171 }
1172 return reply.ReadInt32();
1173 }
1174
UpdateSessionToken(sptr<IRemoteObject> sessionToken)1175 void AbilitySchedulerProxy::UpdateSessionToken(sptr<IRemoteObject> sessionToken)
1176 {
1177 MessageParcel data;
1178 if (!WriteInterfaceToken(data)) {
1179 return;
1180 }
1181 if (!data.WriteRemoteObject(sessionToken)) {
1182 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionToken failed");
1183 return;
1184 }
1185 MessageParcel reply;
1186 MessageOption option(MessageOption::TF_ASYNC);
1187 int32_t err = SendTransactCmd(IAbilityScheduler::UPDATE_SESSION_TOKEN, data, reply, option);
1188 if (err != NO_ERROR) {
1189 TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest failed, err: %{public}d", err);
1190 }
1191 }
1192
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1193 int32_t AbilitySchedulerProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
1194 MessageParcel &reply, MessageOption &option)
1195 {
1196 sptr<IRemoteObject> remote = Remote();
1197 if (remote == nullptr) {
1198 TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
1199 return ERR_NULL_OBJECT;
1200 }
1201
1202 int32_t ret = remote->SendRequest(code, data, reply, option);
1203 if (ret != NO_ERROR) {
1204 TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest failed, code: %{public}d, ret: %{public}d", code, ret);
1205 return ret;
1206 }
1207 return NO_ERROR;
1208 }
1209
ScheduleCollaborate(const Want & want)1210 void AbilitySchedulerProxy::ScheduleCollaborate(const Want &want)
1211 {
1212 MessageParcel data;
1213 MessageParcel reply;
1214 MessageOption option(MessageOption::TF_ASYNC);
1215 if (!WriteInterfaceToken(data)) {
1216 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
1217 return;
1218 }
1219 auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
1220 "ScheduleCollaborate");
1221 if (!data.WriteParcelable(&want)) {
1222 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want failed");
1223 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write want failed");
1224 return;
1225 }
1226 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_COLLABORATE_DATA, data, reply, option);
1227 if (err != NO_ERROR) {
1228 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1229 }
1230 return;
1231 }
1232
ScheduleAbilityRequestFailure(const std::string & requestId,const AppExecFwk::ElementName & element,const std::string & message,int32_t resultCode)1233 void AbilitySchedulerProxy::ScheduleAbilityRequestFailure(const std::string &requestId,
1234 const AppExecFwk::ElementName &element, const std::string &message, int32_t resultCode)
1235 {
1236 MessageParcel data;
1237 MessageParcel reply;
1238 MessageOption option(MessageOption::TF_ASYNC);
1239 if (!WriteInterfaceToken(data)) {
1240 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
1241 return;
1242 }
1243 auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
1244 "ScheduleAbilityRequestFailure");
1245 if (!data.WriteString(requestId)) {
1246 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestId failed");
1247 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write requestId failed");
1248 return;
1249 }
1250 if (!data.WriteParcelable(&element)) {
1251 TAG_LOGE(AAFwkTag::ABILITYMGR, "write element failed");
1252 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write want failed");
1253 return;
1254 }
1255 if (!data.WriteString(message)) {
1256 TAG_LOGE(AAFwkTag::ABILITYMGR, "write message failed");
1257 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write message failed");
1258 return;
1259 }
1260 if (!data.WriteInt32(resultCode)) {
1261 TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed");
1262 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write resultCode failed");
1263 return;
1264 }
1265 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_REQUEST_FAILURE, data, reply, option);
1266 if (err != NO_ERROR) {
1267 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1268 }
1269 return;
1270 }
1271
ScheduleAbilityRequestSuccess(const std::string & requestId,const AppExecFwk::ElementName & element)1272 void AbilitySchedulerProxy::ScheduleAbilityRequestSuccess(const std::string &requestId,
1273 const AppExecFwk::ElementName &element)
1274 {
1275 MessageParcel data;
1276 MessageParcel reply;
1277 MessageOption option(MessageOption::TF_ASYNC);
1278 if (!WriteInterfaceToken(data)) {
1279 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
1280 return;
1281 }
1282 auto msgKey = AbilityRuntime::ErrorMgsUtil::BuildErrorKey(reinterpret_cast<uintptr_t>(this),
1283 "ScheduleAbilityRequestSuccess");
1284 if (!data.WriteString(requestId)) {
1285 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestId failed");
1286 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write requestId failed");
1287 return;
1288 }
1289 if (!data.WriteParcelable(&element)) {
1290 TAG_LOGE(AAFwkTag::ABILITYMGR, "write element failed");
1291 AbilityRuntime::ErrorMgsUtil::GetInstance().UpdateErrorMsg(msgKey, "write want failed");
1292 return;
1293 }
1294 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITY_REQUEST_SUCCESS, data, reply, option);
1295 if (err != NO_ERROR) {
1296 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1297 }
1298 return;
1299 }
1300
ScheduleAbilitiesRequestDone(const std::string & requestKey,int32_t resultCode)1301 void AbilitySchedulerProxy::ScheduleAbilitiesRequestDone(const std::string &requestKey, int32_t resultCode)
1302 {
1303 MessageParcel data;
1304 MessageParcel reply;
1305 MessageOption option(MessageOption::TF_ASYNC);
1306 if (!WriteInterfaceToken(data)) {
1307 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token failed");
1308 return;
1309 }
1310
1311 if (!data.WriteString(requestKey)) {
1312 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestKey failed");
1313 return;
1314 }
1315 if (!data.WriteInt32(resultCode)) {
1316 TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode failed");
1317 return;
1318 }
1319
1320 int32_t err = SendTransactCmd(IAbilityScheduler::SCHEDULE_ABILITIES_REQUEST_DONE, data, reply, option);
1321 if (err != NO_ERROR) {
1322 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail, err: %{public}d", err);
1323 }
1324 return;
1325 }
1326 } // namespace AAFwk
1327 } // namespace OHOS
1328