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