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