• 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 
16 #include "ability_scheduler_stub.h"
17 
18 #include "ability_manager_errors.h"
19 #include "data_ability_observer_interface.h"
20 #include "data_ability_operation.h"
21 #include "data_ability_predicates.h"
22 #include "data_ability_result.h"
23 #include "hilog_tag_wrapper.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 constexpr int CYCLE_LIMIT = 2000;
AbilitySchedulerStub()31 AbilitySchedulerStub::AbilitySchedulerStub()
32 {}
33 
~AbilitySchedulerStub()34 AbilitySchedulerStub::~AbilitySchedulerStub()
35 {}
36 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)37 int AbilitySchedulerStub::OnRemoteRequest(
38     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
39 {
40     std::u16string descriptor = AbilitySchedulerStub::GetDescriptor();
41     std::u16string remoteDescriptor = data.ReadInterfaceToken();
42     if (descriptor != remoteDescriptor) {
43         TAG_LOGE(AAFwkTag::ABILITYMGR, "descriptor not equal to remote");
44         return ERR_INVALID_STATE;
45     }
46     return OnRemoteRequestInner(code, data, reply, option);
47 }
48 
OnRemoteRequestInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)49 int AbilitySchedulerStub::OnRemoteRequestInner(
50     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
51 {
52     int retCode = ERR_OK;
53     retCode = OnRemoteRequestInnerFirst(code, data, reply, option);
54     if (retCode != ERR_CODE_NOT_EXIST) {
55         return retCode;
56     }
57     retCode = OnRemoteRequestInnerSecond(code, data, reply, option);
58     if (retCode != ERR_CODE_NOT_EXIST) {
59         return retCode;
60     }
61     retCode = OnRemoteRequestInnerThird(code, data, reply, option);
62     if (retCode != ERR_CODE_NOT_EXIST) {
63         return retCode;
64     }
65     TAG_LOGW(AAFwkTag::ABILITYMGR, "default case, need check");
66     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67 }
68 
OnRemoteRequestInnerFirst(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)69 int AbilitySchedulerStub::OnRemoteRequestInnerFirst(
70     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
71 {
72     switch (code) {
73         case SCHEDULE_ABILITY_TRANSACTION:
74             return AbilityTransactionInner(data, reply);
75         case SEND_RESULT:
76             return SendResultInner(data, reply);
77         case SCHEDULE_ABILITY_CONNECT:
78             return ConnectAbilityInner(data, reply);
79         case SCHEDULE_ABILITY_DISCONNECT:
80             return DisconnectAbilityInner(data, reply);
81         case SCHEDULE_ABILITY_COMMAND:
82             return CommandAbilityInner(data, reply);
83         case SCHEDULE_ABILITY_PREPARE_TERMINATE:
84             return PrepareTerminateAbilityInner(data, reply);
85         case SCHEDULE_ABILITY_COMMAND_WINDOW:
86             return CommandAbilityWindowInner(data, reply);
87         case SCHEDULE_SAVE_ABILITY_STATE:
88             return SaveAbilityStateInner(data, reply);
89         case SCHEDULE_RESTORE_ABILITY_STATE:
90             return RestoreAbilityStateInner(data, reply);
91         case SCHEDULE_GETFILETYPES:
92             return GetFileTypesInner(data, reply);
93         case SCHEDULE_OPENFILE:
94             return OpenFileInner(data, reply);
95         case SCHEDULE_OPENRAWFILE:
96             return OpenRawFileInner(data, reply);
97         case SCHEDULE_INSERT:
98             return InsertInner(data, reply);
99         case SCHEDULE_UPDATE:
100             return UpdatetInner(data, reply);
101         case SCHEDULE_DELETE:
102             return DeleteInner(data, reply);
103     }
104     return ERR_CODE_NOT_EXIST;
105 }
106 
OnRemoteRequestInnerSecond(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)107 int AbilitySchedulerStub::OnRemoteRequestInnerSecond(
108     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
109 {
110     switch (code) {
111         case SCHEDULE_QUERY:
112             return QueryInner(data, reply);
113         case SCHEDULE_CALL:
114             return CallInner(data, reply);
115         case SCHEDULE_GETTYPE:
116             return GetTypeInner(data, reply);
117         case SCHEDULE_RELOAD:
118             return ReloadInner(data, reply);
119         case SCHEDULE_BATCHINSERT:
120             return BatchInsertInner(data, reply);
121         case SCHEDULE_REGISTEROBSERVER:
122             return RegisterObserverInner(data, reply);
123         case SCHEDULE_UNREGISTEROBSERVER:
124             return UnregisterObserverInner(data, reply);
125         case SCHEDULE_NOTIFYCHANGE:
126             return NotifyChangeInner(data, reply);
127         case SCHEDULE_NORMALIZEURI:
128             return NormalizeUriInner(data, reply);
129         case SCHEDULE_DENORMALIZEURI:
130             return DenormalizeUriInner(data, reply);
131         case SCHEDULE_EXECUTEBATCH:
132             return ExecuteBatchInner(data, reply);
133         case NOTIFY_CONTINUATION_RESULT:
134             return NotifyContinuationResultInner(data, reply);
135         case REQUEST_CALL_REMOTE:
136             return CallRequestInner(data, reply);
137         case CONTINUE_ABILITY:
138             return ContinueAbilityInner(data, reply);
139         case DUMP_ABILITY_RUNNER_INNER:
140             return DumpAbilityInfoInner(data, reply);
141     }
142     return ERR_CODE_NOT_EXIST;
143 }
144 
OnRemoteRequestInnerThird(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)145 int AbilitySchedulerStub::OnRemoteRequestInnerThird(
146     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
147 {
148     switch (code) {
149         case SCHEDULE_SHARE_DATA:
150             return ShareDataInner(data, reply);
151         case SCHEDULE_ONEXECUTE_INTENT:
152             return OnExecuteIntentInner(data, reply);
153         case CREATE_MODAL_UI_EXTENSION:
154             return CreateModalUIExtensionInner(data, reply);
155         case UPDATE_SESSION_TOKEN:
156             return UpdateSessionTokenInner(data, reply);
157         case SCHEDULE_COLLABORATE_DATA:
158             return CollaborateDataInner(data);
159     }
160     return ERR_CODE_NOT_EXIST;
161 }
162 
AbilityTransactionInner(MessageParcel & data,MessageParcel & reply)163 int AbilitySchedulerStub::AbilityTransactionInner(MessageParcel &data, MessageParcel &reply)
164 {
165     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
166     if (want == nullptr) {
167         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
168         return ERR_INVALID_VALUE;
169     }
170     std::unique_ptr<LifeCycleStateInfo> stateInfo(data.ReadParcelable<LifeCycleStateInfo>());
171     if (!stateInfo) {
172         TAG_LOGE(AAFwkTag::ABILITYMGR, "ReadParcelable<LifeCycleStateInfo> failed");
173         return ERR_INVALID_VALUE;
174     }
175     sptr<SessionInfo> sessionInfo = nullptr;
176     if (data.ReadBool()) {
177         sessionInfo = data.ReadParcelable<SessionInfo>();
178     }
179     ScheduleAbilityTransaction(*want, *stateInfo, sessionInfo);
180     return NO_ERROR;
181 }
182 
ShareDataInner(MessageParcel & data,MessageParcel & reply)183 int AbilitySchedulerStub::ShareDataInner(MessageParcel &data, MessageParcel &reply)
184 {
185     int32_t requestCode = data.ReadInt32();
186     TAG_LOGI(AAFwkTag::ABILITYMGR, "requestCode:%{public}d", requestCode);
187     ScheduleShareData(requestCode);
188     return NO_ERROR;
189 }
190 
SendResultInner(MessageParcel & data,MessageParcel & reply)191 int AbilitySchedulerStub::SendResultInner(MessageParcel &data, MessageParcel &reply)
192 {
193     int requestCode = data.ReadInt32();
194     int resultCode = data.ReadInt32();
195     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
196     if (want == nullptr) {
197         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
198         return ERR_INVALID_VALUE;
199     }
200     SendResult(requestCode, resultCode, *want);
201     return NO_ERROR;
202 }
203 
ConnectAbilityInner(MessageParcel & data,MessageParcel & reply)204 int AbilitySchedulerStub::ConnectAbilityInner(MessageParcel &data, MessageParcel &reply)
205 {
206     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
207     if (want == nullptr) {
208         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
209         return ERR_INVALID_VALUE;
210     }
211     ScheduleConnectAbility(*want);
212     return NO_ERROR;
213 }
214 
DisconnectAbilityInner(MessageParcel & data,MessageParcel & reply)215 int AbilitySchedulerStub::DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply)
216 {
217     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
218     if (want == nullptr) {
219         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
220         return ERR_INVALID_VALUE;
221     }
222     ScheduleDisconnectAbility(*want);
223     return NO_ERROR;
224 }
225 
CommandAbilityInner(MessageParcel & data,MessageParcel & reply)226 int AbilitySchedulerStub::CommandAbilityInner(MessageParcel &data, MessageParcel &reply)
227 {
228     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
229     if (want == nullptr) {
230         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
231         return ERR_INVALID_VALUE;
232     }
233     bool reStart = data.ReadBool();
234     int startId = data.ReadInt32();
235     TAG_LOGD(AAFwkTag::ABILITYMGR, "ReadInt32, startId:%{public}d", startId);
236     ScheduleCommandAbility(*want, reStart, startId);
237     return NO_ERROR;
238 }
239 
PrepareTerminateAbilityInner(MessageParcel & data,MessageParcel & reply)240 int AbilitySchedulerStub::PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
241 {
242     TAG_LOGI(AAFwkTag::ABILITYMGR, "prepare terminate call");
243     bool ret = SchedulePrepareTerminateAbility();
244     if (!reply.WriteInt32(ret)) {
245         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to write ret");
246         return ERR_INVALID_VALUE;
247     }
248     return NO_ERROR;
249 }
250 
CommandAbilityWindowInner(MessageParcel & data,MessageParcel & reply)251 int AbilitySchedulerStub::CommandAbilityWindowInner(MessageParcel &data, MessageParcel &reply)
252 {
253     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
254     if (want == nullptr) {
255         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
256         return ERR_INVALID_VALUE;
257     }
258     sptr<SessionInfo> sessionInfo(data.ReadParcelable<SessionInfo>());
259     int32_t winCmd = data.ReadInt32();
260     ScheduleCommandAbilityWindow(*want, sessionInfo, static_cast<WindowCommand>(winCmd));
261     return NO_ERROR;
262 }
263 
SaveAbilityStateInner(MessageParcel & data,MessageParcel & reply)264 int AbilitySchedulerStub::SaveAbilityStateInner(MessageParcel &data, MessageParcel &reply)
265 {
266     ScheduleSaveAbilityState();
267     return NO_ERROR;
268 }
269 
RestoreAbilityStateInner(MessageParcel & data,MessageParcel & reply)270 int AbilitySchedulerStub::RestoreAbilityStateInner(MessageParcel &data, MessageParcel &reply)
271 {
272     std::shared_ptr<PacMap> pacMap(data.ReadParcelable<PacMap>());
273     if (pacMap == nullptr) {
274         TAG_LOGE(AAFwkTag::ABILITYMGR, "null pacMap");
275         return ERR_INVALID_VALUE;
276     }
277     ScheduleRestoreAbilityState(*pacMap);
278     return NO_ERROR;
279 }
280 
GetFileTypesInner(MessageParcel & data,MessageParcel & reply)281 int AbilitySchedulerStub::GetFileTypesInner(MessageParcel &data, MessageParcel &reply)
282 {
283     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
284     if (uri == nullptr) {
285         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
286         return ERR_INVALID_VALUE;
287     }
288     std::string mimeTypeFilter = data.ReadString();
289     if (mimeTypeFilter.empty()) {
290         TAG_LOGE(AAFwkTag::ABILITYMGR, "null mimeTypeFilter");
291         return ERR_INVALID_VALUE;
292     }
293     std::vector<std::string> types = GetFileTypes(*uri, mimeTypeFilter);
294     if (!reply.WriteStringVector(types)) {
295         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteStringVector types");
296         return ERR_INVALID_VALUE;
297     }
298     return NO_ERROR;
299 }
300 
OpenFileInner(MessageParcel & data,MessageParcel & reply)301 int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &reply)
302 {
303     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
304     if (uri == nullptr) {
305         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
306         return ERR_INVALID_VALUE;
307     }
308     std::string mode = data.ReadString();
309     if (mode.empty()) {
310         TAG_LOGE(AAFwkTag::ABILITYMGR, "null mode");
311         return ERR_INVALID_VALUE;
312     }
313     int fd = OpenFile(*uri, mode);
314     if (fd < 0) {
315         TAG_LOGE(AAFwkTag::ABILITYMGR, "openFile fail, fd: %{pubilc}d", fd);
316         return ERR_INVALID_VALUE;
317     }
318     if (!reply.WriteFileDescriptor(fd)) {
319         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteFileDescriptor fd");
320         return ERR_INVALID_VALUE;
321     }
322     return NO_ERROR;
323 }
324 
OpenRawFileInner(MessageParcel & data,MessageParcel & reply)325 int AbilitySchedulerStub::OpenRawFileInner(MessageParcel &data, MessageParcel &reply)
326 {
327     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
328     if (uri == nullptr) {
329         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
330         return ERR_INVALID_VALUE;
331     }
332     std::string mode = data.ReadString();
333     if (mode.empty()) {
334         TAG_LOGE(AAFwkTag::ABILITYMGR, "null mode");
335         return ERR_INVALID_VALUE;
336     }
337     int fd = OpenRawFile(*uri, mode);
338     if (!reply.WriteInt32(fd)) {
339         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 fd");
340         return ERR_INVALID_VALUE;
341     }
342     return NO_ERROR;
343 }
344 
InsertInner(MessageParcel & data,MessageParcel & reply)345 int AbilitySchedulerStub::InsertInner(MessageParcel &data, MessageParcel &reply)
346 {
347     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
348     if (uri == nullptr) {
349         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
350         return ERR_INVALID_VALUE;
351     }
352     int index = Insert(*uri, NativeRdb::ValuesBucket::Unmarshalling(data));
353     if (!reply.WriteInt32(index)) {
354         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 index");
355         return ERR_INVALID_VALUE;
356     }
357     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
358     return NO_ERROR;
359 }
360 
CallInner(MessageParcel & data,MessageParcel & reply)361 int AbilitySchedulerStub::CallInner(MessageParcel &data, MessageParcel &reply)
362 {
363     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
364     if (uri == nullptr) {
365         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
366         return ERR_INVALID_VALUE;
367     }
368     std::string method = data.ReadString();
369     if (method.empty()) {
370         TAG_LOGE(AAFwkTag::ABILITYMGR, "null method");
371         return ERR_INVALID_VALUE;
372     }
373     std::string arg = data.ReadString();
374     if (arg.empty()) {
375         TAG_LOGE(AAFwkTag::ABILITYMGR, "null arg");
376         return ERR_INVALID_VALUE;
377     }
378 
379     std::shared_ptr<AppExecFwk::PacMap> pacMap(data.ReadParcelable<AppExecFwk::PacMap>());
380     if (pacMap == nullptr) {
381         TAG_LOGE(AAFwkTag::ABILITYMGR, "null pacMap");
382         return ERR_INVALID_VALUE;
383     }
384     std::shared_ptr<AppExecFwk::PacMap> result = Call(*uri, method, arg, *pacMap);
385     if (!reply.WriteParcelable(result.get())) {
386         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable pacMap error");
387         return ERR_INVALID_VALUE;
388     }
389     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
390     return NO_ERROR;
391 }
392 
UpdatetInner(MessageParcel & data,MessageParcel & reply)393 int AbilitySchedulerStub::UpdatetInner(MessageParcel &data, MessageParcel &reply)
394 {
395     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
396     if (uri == nullptr) {
397         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
398         return ERR_INVALID_VALUE;
399     }
400     auto value = NativeRdb::ValuesBucket::Unmarshalling(data);
401     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
402         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
403     if (predicates == nullptr) {
404         TAG_LOGE(AAFwkTag::ABILITYMGR, "null predicates");
405         return ERR_INVALID_VALUE;
406     }
407     int index = Update(*uri, std::move(value), *predicates);
408     if (!reply.WriteInt32(index)) {
409         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 index");
410         return ERR_INVALID_VALUE;
411     }
412     return NO_ERROR;
413 }
414 
DeleteInner(MessageParcel & data,MessageParcel & reply)415 int AbilitySchedulerStub::DeleteInner(MessageParcel &data, MessageParcel &reply)
416 {
417     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
418     if (uri == nullptr) {
419         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
420         return ERR_INVALID_VALUE;
421     }
422     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
423         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
424     if (predicates == nullptr) {
425         TAG_LOGE(AAFwkTag::ABILITYMGR, "null predicates");
426         return ERR_INVALID_VALUE;
427     }
428     int index = Delete(*uri, *predicates);
429     if (!reply.WriteInt32(index)) {
430         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 index");
431         return ERR_INVALID_VALUE;
432     }
433     return NO_ERROR;
434 }
435 
QueryInner(MessageParcel & data,MessageParcel & reply)436 int AbilitySchedulerStub::QueryInner(MessageParcel &data, MessageParcel &reply)
437 {
438     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
439     if (uri == nullptr) {
440         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
441         return ERR_INVALID_VALUE;
442     }
443     std::vector<std::string> columns;
444     if (!data.ReadStringVector(&columns)) {
445         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadStringVector columns");
446         return ERR_INVALID_VALUE;
447     }
448     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
449         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
450     if (predicates == nullptr) {
451         TAG_LOGE(AAFwkTag::ABILITYMGR, "null predicates");
452         return ERR_INVALID_VALUE;
453     }
454     auto resultSet = Query(*uri, columns, *predicates);
455     if (resultSet == nullptr) {
456         TAG_LOGE(AAFwkTag::ABILITYMGR, "null resultSet");
457         return ERR_INVALID_VALUE;
458     }
459     auto result = NativeRdb::ISharedResultSet::WriteToParcel(std::move(resultSet), reply);
460     if (result == nullptr) {
461         TAG_LOGE(AAFwkTag::ABILITYMGR, "null result");
462         return ERR_INVALID_VALUE;
463     }
464     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
465     return NO_ERROR;
466 }
467 
GetTypeInner(MessageParcel & data,MessageParcel & reply)468 int AbilitySchedulerStub::GetTypeInner(MessageParcel &data, MessageParcel &reply)
469 {
470     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
471     if (uri == nullptr) {
472         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
473         return ERR_INVALID_VALUE;
474     }
475     std::string type = GetType(*uri);
476     if (!reply.WriteString(type)) {
477         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString type");
478         return ERR_INVALID_VALUE;
479     }
480     return NO_ERROR;
481 }
482 
ReloadInner(MessageParcel & data,MessageParcel & reply)483 int AbilitySchedulerStub::ReloadInner(MessageParcel &data, MessageParcel &reply)
484 {
485     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
486     if (uri == nullptr) {
487         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
488         return ERR_INVALID_VALUE;
489     }
490 
491     std::shared_ptr<PacMap> extras(data.ReadParcelable<PacMap>());
492     if (extras == nullptr) {
493         TAG_LOGE(AAFwkTag::ABILITYMGR, "null extras");
494         return ERR_INVALID_VALUE;
495     }
496     bool ret = Reload(*uri, *extras);
497     if (!reply.WriteBool(ret)) {
498         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to writeBool ret");
499         return ERR_INVALID_VALUE;
500     }
501     return NO_ERROR;
502 }
503 
BatchInsertInner(MessageParcel & data,MessageParcel & reply)504 int AbilitySchedulerStub::BatchInsertInner(MessageParcel &data, MessageParcel &reply)
505 {
506     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
507     if (uri == nullptr) {
508         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
509         return ERR_INVALID_VALUE;
510     }
511 
512     int count = 0;
513     if (!data.ReadInt32(count)) {
514         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 index");
515         return ERR_INVALID_VALUE;
516     }
517 
518     if (count > CYCLE_LIMIT) {
519         TAG_LOGE(AAFwkTag::ABILITYMGR, "count too large");
520         return ERR_INVALID_VALUE;
521     }
522     std::vector<NativeRdb::ValuesBucket> values;
523     for (int i = 0; i < count; i++) {
524         values.emplace_back(NativeRdb::ValuesBucket::Unmarshalling(data));
525     }
526 
527     int ret = BatchInsert(*uri, values);
528     if (!reply.WriteInt32(ret)) {
529         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
530         return ERR_INVALID_VALUE;
531     }
532     return NO_ERROR;
533 }
534 
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)535 int AbilitySchedulerStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
536 {
537     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
538     if (uri == nullptr) {
539         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
540         return ERR_INVALID_VALUE;
541     }
542     auto obServer = iface_cast<IDataAbilityObserver>(data.ReadRemoteObject());
543     if (obServer == nullptr) {
544         TAG_LOGE(AAFwkTag::ABILITYMGR, "null obServer");
545         return ERR_INVALID_VALUE;
546     }
547 
548     bool ret = ScheduleRegisterObserver(*uri, obServer);
549     if (!reply.WriteInt32(ret)) {
550         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
551         return ERR_INVALID_VALUE;
552     }
553     return NO_ERROR;
554 }
555 
UnregisterObserverInner(MessageParcel & data,MessageParcel & reply)556 int AbilitySchedulerStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)
557 {
558     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
559     if (uri == nullptr) {
560         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
561         return ERR_INVALID_VALUE;
562     }
563     auto obServer = iface_cast<IDataAbilityObserver>(data.ReadRemoteObject());
564     if (obServer == nullptr) {
565         TAG_LOGE(AAFwkTag::ABILITYMGR, "null obServer");
566         return ERR_INVALID_VALUE;
567     }
568 
569     bool ret = ScheduleUnregisterObserver(*uri, obServer);
570     if (!reply.WriteInt32(ret)) {
571         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
572         return ERR_INVALID_VALUE;
573     }
574     return NO_ERROR;
575 }
576 
NotifyChangeInner(MessageParcel & data,MessageParcel & reply)577 int AbilitySchedulerStub::NotifyChangeInner(MessageParcel &data, MessageParcel &reply)
578 {
579     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
580     if (uri == nullptr) {
581         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
582         return ERR_INVALID_VALUE;
583     }
584 
585     bool ret = ScheduleNotifyChange(*uri);
586     if (!reply.WriteInt32(ret)) {
587         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
588         return ERR_INVALID_VALUE;
589     }
590     return NO_ERROR;
591 }
592 
NormalizeUriInner(MessageParcel & data,MessageParcel & reply)593 int AbilitySchedulerStub::NormalizeUriInner(MessageParcel &data, MessageParcel &reply)
594 {
595     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
596     if (uri == nullptr) {
597         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
598         return ERR_INVALID_VALUE;
599     }
600 
601     Uri ret("");
602     ret = NormalizeUri(*uri);
603     if (!reply.WriteParcelable(&ret)) {
604         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable type");
605         return ERR_INVALID_VALUE;
606     }
607     return NO_ERROR;
608 }
609 
DenormalizeUriInner(MessageParcel & data,MessageParcel & reply)610 int AbilitySchedulerStub::DenormalizeUriInner(MessageParcel &data, MessageParcel &reply)
611 {
612     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
613     if (uri == nullptr) {
614         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
615         return ERR_INVALID_VALUE;
616     }
617 
618     Uri ret("");
619     ret = DenormalizeUri(*uri);
620     if (!reply.WriteParcelable(&ret)) {
621         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable type");
622         return ERR_INVALID_VALUE;
623     }
624     return NO_ERROR;
625 }
626 
ExecuteBatchInner(MessageParcel & data,MessageParcel & reply)627 int AbilitySchedulerStub::ExecuteBatchInner(MessageParcel &data, MessageParcel &reply)
628 {
629     TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
630     int count = 0;
631     if (!data.ReadInt32(count)) {
632         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 count");
633         return ERR_INVALID_VALUE;
634     }
635     TAG_LOGI(AAFwkTag::ABILITYMGR, "count:%{public}d", count);
636     if (count > CYCLE_LIMIT) {
637         TAG_LOGE(AAFwkTag::ABILITYMGR, "count too large");
638         return ERR_INVALID_VALUE;
639     }
640     std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> operations;
641     for (int i = 0; i < count; i++) {
642         std::shared_ptr<AppExecFwk::DataAbilityOperation> dataAbilityOperation(
643             data.ReadParcelable<AppExecFwk::DataAbilityOperation>());
644         if (dataAbilityOperation == nullptr) {
645             TAG_LOGE(AAFwkTag::ABILITYMGR, "null dataAbilityOperation, index: %{public}d", i);
646             return ERR_INVALID_VALUE;
647         }
648         operations.push_back(dataAbilityOperation);
649     }
650 
651     std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> results = ExecuteBatch(operations);
652     int total = (int)results.size();
653     if (!reply.WriteInt32(total)) {
654         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
655         return ERR_INVALID_VALUE;
656     }
657     TAG_LOGI(AAFwkTag::ABILITYMGR, "total:%{public}d", total);
658     for (int i = 0; i < total; i++) {
659         if (results[i] == nullptr) {
660             TAG_LOGE(AAFwkTag::ABILITYMGR,
661                 "null results[i], index: %{public}d", i);
662             return ERR_INVALID_VALUE;
663         }
664         if (!reply.WriteParcelable(results[i].get())) {
665             TAG_LOGE(AAFwkTag::ABILITYMGR,
666                 "fail to WriteParcelable operation, index: %{public}d", i);
667             return ERR_INVALID_VALUE;
668         }
669     }
670     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
671     return NO_ERROR;
672 }
673 
ContinueAbilityInner(MessageParcel & data,MessageParcel & reply)674 int AbilitySchedulerStub::ContinueAbilityInner(MessageParcel &data, MessageParcel &reply)
675 {
676     std::string deviceId = data.ReadString();
677     uint32_t versionCode = data.ReadUint32();
678     ContinueAbility(deviceId, versionCode);
679     return NO_ERROR;
680 }
681 
NotifyContinuationResultInner(MessageParcel & data,MessageParcel & reply)682 int AbilitySchedulerStub::NotifyContinuationResultInner(MessageParcel &data, MessageParcel &reply)
683 {
684     int32_t result = data.ReadInt32();
685     NotifyContinuationResult(result);
686     return NO_ERROR;
687 }
688 
DumpAbilityInfoInner(MessageParcel & data,MessageParcel & reply)689 int AbilitySchedulerStub::DumpAbilityInfoInner(MessageParcel &data, MessageParcel &reply)
690 {
691     std::vector<std::string> infos;
692     std::vector<std::string> params;
693     if (!data.ReadStringVector(&params)) {
694         TAG_LOGI(AAFwkTag::ABILITYMGR, "DumpAbilityInfoInner read params error");
695         return ERR_INVALID_VALUE;
696     }
697 
698     DumpAbilityInfo(params, infos);
699 
700     return NO_ERROR;
701 }
702 
CallRequestInner(MessageParcel & data,MessageParcel & reply)703 int AbilitySchedulerStub::CallRequestInner(MessageParcel &data, MessageParcel &reply)
704 {
705     CallRequest();
706     return NO_ERROR;
707 }
708 
OnExecuteIntentInner(MessageParcel & data,MessageParcel & reply)709 int AbilitySchedulerStub::OnExecuteIntentInner(MessageParcel &data, MessageParcel &reply)
710 {
711     TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
712     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
713     if (want == nullptr) {
714         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
715         return ERR_INVALID_VALUE;
716     }
717     OnExecuteIntent(*want);
718     return NO_ERROR;
719 }
720 
CreateModalUIExtensionInner(MessageParcel & data,MessageParcel & reply)721 int AbilitySchedulerStub::CreateModalUIExtensionInner(MessageParcel &data, MessageParcel &reply)
722 {
723     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
724     if (want == nullptr) {
725         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
726         return ERR_INVALID_VALUE;
727     }
728     int ret = CreateModalUIExtension(*want);
729     if (!reply.WriteInt32(ret)) {
730         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
731         return ERR_INVALID_VALUE;
732     }
733     return NO_ERROR;
734 }
735 
UpdateSessionTokenInner(MessageParcel & data,MessageParcel & reply)736 int AbilitySchedulerStub::UpdateSessionTokenInner(MessageParcel &data, MessageParcel &reply)
737 {
738     sptr<IRemoteObject> sessionToken = data.ReadRemoteObject();
739     UpdateSessionToken(sessionToken);
740     return NO_ERROR;
741 }
742 
CollaborateDataInner(MessageParcel & data)743 int AbilitySchedulerStub::CollaborateDataInner(MessageParcel &data)
744 {
745     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
746     if (want == nullptr) {
747         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
748         return ERR_INVALID_VALUE;
749     }
750     ScheduleCollaborate(*want);
751     return NO_ERROR;
752 }
753 
OnRemoteDied(const wptr<IRemoteObject> & remote)754 void AbilitySchedulerRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
755 {
756     TAG_LOGE(AAFwkTag::ABILITYMGR, "call");
757 
758     if (handler_) {
759         handler_(remote);
760     }
761 }
762 
AbilitySchedulerRecipient(RemoteDiedHandler handler)763 AbilitySchedulerRecipient::AbilitySchedulerRecipient(RemoteDiedHandler handler) : handler_(handler)
764 {}
765 
~AbilitySchedulerRecipient()766 AbilitySchedulerRecipient::~AbilitySchedulerRecipient()
767 {}
768 }  // namespace AAFwk
769 }  // namespace OHOS
770