• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
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         case SCHEDULE_ABILITY_REQUEST_FAILURE:
160             return ScheduleAbilityRequestFailureInner(data);
161         case SCHEDULE_ABILITY_REQUEST_SUCCESS:
162             return ScheduleAbilityRequestSuccessInner(data);
163         case SCHEDULE_ABILITIES_REQUEST_DONE:
164             return ScheduleAbilitiesRequestDoneInner(data);
165     }
166     return ERR_CODE_NOT_EXIST;
167 }
168 
AbilityTransactionInner(MessageParcel & data,MessageParcel & reply)169 int AbilitySchedulerStub::AbilityTransactionInner(MessageParcel &data, MessageParcel &reply)
170 {
171     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
172     if (want == nullptr) {
173         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
174         return ERR_INVALID_VALUE;
175     }
176     std::unique_ptr<LifeCycleStateInfo> stateInfo(data.ReadParcelable<LifeCycleStateInfo>());
177     if (!stateInfo) {
178         TAG_LOGE(AAFwkTag::ABILITYMGR, "ReadParcelable<LifeCycleStateInfo> failed");
179         return ERR_INVALID_VALUE;
180     }
181     sptr<SessionInfo> sessionInfo = nullptr;
182     if (data.ReadBool()) {
183         sessionInfo = data.ReadParcelable<SessionInfo>();
184     }
185     ScheduleAbilityTransaction(*want, *stateInfo, sessionInfo);
186     return NO_ERROR;
187 }
188 
ShareDataInner(MessageParcel & data,MessageParcel & reply)189 int AbilitySchedulerStub::ShareDataInner(MessageParcel &data, MessageParcel &reply)
190 {
191     int32_t requestCode = data.ReadInt32();
192     TAG_LOGI(AAFwkTag::ABILITYMGR, "requestCode:%{public}d", requestCode);
193     ScheduleShareData(requestCode);
194     return NO_ERROR;
195 }
196 
SendResultInner(MessageParcel & data,MessageParcel & reply)197 int AbilitySchedulerStub::SendResultInner(MessageParcel &data, MessageParcel &reply)
198 {
199     int requestCode = data.ReadInt32();
200     int resultCode = data.ReadInt32();
201     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
202     if (want == nullptr) {
203         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
204         return ERR_INVALID_VALUE;
205     }
206     SendResult(requestCode, resultCode, *want);
207     return NO_ERROR;
208 }
209 
ConnectAbilityInner(MessageParcel & data,MessageParcel & reply)210 int AbilitySchedulerStub::ConnectAbilityInner(MessageParcel &data, MessageParcel &reply)
211 {
212     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
213     if (want == nullptr) {
214         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
215         return ERR_INVALID_VALUE;
216     }
217     ScheduleConnectAbility(*want);
218     return NO_ERROR;
219 }
220 
DisconnectAbilityInner(MessageParcel & data,MessageParcel & reply)221 int AbilitySchedulerStub::DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply)
222 {
223     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
224     if (want == nullptr) {
225         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
226         return ERR_INVALID_VALUE;
227     }
228     ScheduleDisconnectAbility(*want);
229     return NO_ERROR;
230 }
231 
CommandAbilityInner(MessageParcel & data,MessageParcel & reply)232 int AbilitySchedulerStub::CommandAbilityInner(MessageParcel &data, MessageParcel &reply)
233 {
234     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
235     if (want == nullptr) {
236         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
237         return ERR_INVALID_VALUE;
238     }
239     bool reStart = data.ReadBool();
240     int startId = data.ReadInt32();
241     TAG_LOGD(AAFwkTag::ABILITYMGR, "ReadInt32, startId:%{public}d", startId);
242     ScheduleCommandAbility(*want, reStart, startId);
243     return NO_ERROR;
244 }
245 
PrepareTerminateAbilityInner(MessageParcel & data,MessageParcel & reply)246 int AbilitySchedulerStub::PrepareTerminateAbilityInner(MessageParcel &data, MessageParcel &reply)
247 {
248     TAG_LOGI(AAFwkTag::ABILITYMGR, "prepare terminate call");
249     bool ret = SchedulePrepareTerminateAbility();
250     if (!reply.WriteInt32(ret)) {
251         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to write ret");
252         return ERR_INVALID_VALUE;
253     }
254     return NO_ERROR;
255 }
256 
CommandAbilityWindowInner(MessageParcel & data,MessageParcel & reply)257 int AbilitySchedulerStub::CommandAbilityWindowInner(MessageParcel &data, MessageParcel &reply)
258 {
259     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
260     if (want == nullptr) {
261         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
262         return ERR_INVALID_VALUE;
263     }
264     sptr<SessionInfo> sessionInfo(data.ReadParcelable<SessionInfo>());
265     int32_t winCmd = data.ReadInt32();
266     ScheduleCommandAbilityWindow(*want, sessionInfo, static_cast<WindowCommand>(winCmd));
267     return NO_ERROR;
268 }
269 
SaveAbilityStateInner(MessageParcel & data,MessageParcel & reply)270 int AbilitySchedulerStub::SaveAbilityStateInner(MessageParcel &data, MessageParcel &reply)
271 {
272     ScheduleSaveAbilityState();
273     return NO_ERROR;
274 }
275 
RestoreAbilityStateInner(MessageParcel & data,MessageParcel & reply)276 int AbilitySchedulerStub::RestoreAbilityStateInner(MessageParcel &data, MessageParcel &reply)
277 {
278     std::shared_ptr<PacMap> pacMap(data.ReadParcelable<PacMap>());
279     if (pacMap == nullptr) {
280         TAG_LOGE(AAFwkTag::ABILITYMGR, "null pacMap");
281         return ERR_INVALID_VALUE;
282     }
283     ScheduleRestoreAbilityState(*pacMap);
284     return NO_ERROR;
285 }
286 
GetFileTypesInner(MessageParcel & data,MessageParcel & reply)287 int AbilitySchedulerStub::GetFileTypesInner(MessageParcel &data, MessageParcel &reply)
288 {
289     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
290     if (uri == nullptr) {
291         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
292         return ERR_INVALID_VALUE;
293     }
294     std::string mimeTypeFilter = data.ReadString();
295     if (mimeTypeFilter.empty()) {
296         TAG_LOGE(AAFwkTag::ABILITYMGR, "null mimeTypeFilter");
297         return ERR_INVALID_VALUE;
298     }
299     std::vector<std::string> types = GetFileTypes(*uri, mimeTypeFilter);
300     if (!reply.WriteStringVector(types)) {
301         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteStringVector types");
302         return ERR_INVALID_VALUE;
303     }
304     return NO_ERROR;
305 }
306 
OpenFileInner(MessageParcel & data,MessageParcel & reply)307 int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &reply)
308 {
309     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
310     if (uri == nullptr) {
311         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
312         return ERR_INVALID_VALUE;
313     }
314     std::string mode = data.ReadString();
315     if (mode.empty()) {
316         TAG_LOGE(AAFwkTag::ABILITYMGR, "null mode");
317         return ERR_INVALID_VALUE;
318     }
319     int fd = OpenFile(*uri, mode);
320     if (fd < 0) {
321         TAG_LOGE(AAFwkTag::ABILITYMGR, "openFile fail, fd: %{pubilc}d", fd);
322         return ERR_INVALID_VALUE;
323     }
324     if (!reply.WriteFileDescriptor(fd)) {
325         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteFileDescriptor fd");
326         return ERR_INVALID_VALUE;
327     }
328     return NO_ERROR;
329 }
330 
OpenRawFileInner(MessageParcel & data,MessageParcel & reply)331 int AbilitySchedulerStub::OpenRawFileInner(MessageParcel &data, MessageParcel &reply)
332 {
333     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
334     if (uri == nullptr) {
335         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
336         return ERR_INVALID_VALUE;
337     }
338     std::string mode = data.ReadString();
339     if (mode.empty()) {
340         TAG_LOGE(AAFwkTag::ABILITYMGR, "null mode");
341         return ERR_INVALID_VALUE;
342     }
343     int fd = OpenRawFile(*uri, mode);
344     if (!reply.WriteInt32(fd)) {
345         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 fd");
346         return ERR_INVALID_VALUE;
347     }
348     return NO_ERROR;
349 }
350 
InsertInner(MessageParcel & data,MessageParcel & reply)351 int AbilitySchedulerStub::InsertInner(MessageParcel &data, MessageParcel &reply)
352 {
353     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
354     if (uri == nullptr) {
355         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
356         return ERR_INVALID_VALUE;
357     }
358     int index = Insert(*uri, NativeRdb::ValuesBucket::Unmarshalling(data));
359     if (!reply.WriteInt32(index)) {
360         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 index");
361         return ERR_INVALID_VALUE;
362     }
363     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
364     return NO_ERROR;
365 }
366 
CallInner(MessageParcel & data,MessageParcel & reply)367 int AbilitySchedulerStub::CallInner(MessageParcel &data, MessageParcel &reply)
368 {
369     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
370     if (uri == nullptr) {
371         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
372         return ERR_INVALID_VALUE;
373     }
374     std::string method = data.ReadString();
375     if (method.empty()) {
376         TAG_LOGE(AAFwkTag::ABILITYMGR, "null method");
377         return ERR_INVALID_VALUE;
378     }
379     std::string arg = data.ReadString();
380     if (arg.empty()) {
381         TAG_LOGE(AAFwkTag::ABILITYMGR, "null arg");
382         return ERR_INVALID_VALUE;
383     }
384 
385     std::shared_ptr<AppExecFwk::PacMap> pacMap(data.ReadParcelable<AppExecFwk::PacMap>());
386     if (pacMap == nullptr) {
387         TAG_LOGE(AAFwkTag::ABILITYMGR, "null pacMap");
388         return ERR_INVALID_VALUE;
389     }
390     std::shared_ptr<AppExecFwk::PacMap> result = Call(*uri, method, arg, *pacMap);
391     if (!reply.WriteParcelable(result.get())) {
392         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable pacMap error");
393         return ERR_INVALID_VALUE;
394     }
395     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
396     return NO_ERROR;
397 }
398 
UpdatetInner(MessageParcel & data,MessageParcel & reply)399 int AbilitySchedulerStub::UpdatetInner(MessageParcel &data, MessageParcel &reply)
400 {
401     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
402     if (uri == nullptr) {
403         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
404         return ERR_INVALID_VALUE;
405     }
406     auto value = NativeRdb::ValuesBucket::Unmarshalling(data);
407     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
408         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
409     if (predicates == nullptr) {
410         TAG_LOGE(AAFwkTag::ABILITYMGR, "null predicates");
411         return ERR_INVALID_VALUE;
412     }
413     int index = Update(*uri, std::move(value), *predicates);
414     if (!reply.WriteInt32(index)) {
415         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 index");
416         return ERR_INVALID_VALUE;
417     }
418     return NO_ERROR;
419 }
420 
DeleteInner(MessageParcel & data,MessageParcel & reply)421 int AbilitySchedulerStub::DeleteInner(MessageParcel &data, MessageParcel &reply)
422 {
423     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
424     if (uri == nullptr) {
425         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
426         return ERR_INVALID_VALUE;
427     }
428     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
429         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
430     if (predicates == nullptr) {
431         TAG_LOGE(AAFwkTag::ABILITYMGR, "null predicates");
432         return ERR_INVALID_VALUE;
433     }
434     int index = Delete(*uri, *predicates);
435     if (!reply.WriteInt32(index)) {
436         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 index");
437         return ERR_INVALID_VALUE;
438     }
439     return NO_ERROR;
440 }
441 
QueryInner(MessageParcel & data,MessageParcel & reply)442 int AbilitySchedulerStub::QueryInner(MessageParcel &data, MessageParcel &reply)
443 {
444     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
445     if (uri == nullptr) {
446         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
447         return ERR_INVALID_VALUE;
448     }
449     std::vector<std::string> columns;
450     if (!data.ReadStringVector(&columns)) {
451         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadStringVector columns");
452         return ERR_INVALID_VALUE;
453     }
454     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
455         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
456     if (predicates == nullptr) {
457         TAG_LOGE(AAFwkTag::ABILITYMGR, "null predicates");
458         return ERR_INVALID_VALUE;
459     }
460     auto resultSet = Query(*uri, columns, *predicates);
461     if (resultSet == nullptr) {
462         TAG_LOGE(AAFwkTag::ABILITYMGR, "null resultSet");
463         return ERR_INVALID_VALUE;
464     }
465     auto result = NativeRdb::ISharedResultSet::WriteToParcel(std::move(resultSet), reply);
466     if (result == nullptr) {
467         TAG_LOGE(AAFwkTag::ABILITYMGR, "null result");
468         return ERR_INVALID_VALUE;
469     }
470     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
471     return NO_ERROR;
472 }
473 
GetTypeInner(MessageParcel & data,MessageParcel & reply)474 int AbilitySchedulerStub::GetTypeInner(MessageParcel &data, MessageParcel &reply)
475 {
476     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
477     if (uri == nullptr) {
478         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
479         return ERR_INVALID_VALUE;
480     }
481     std::string type = GetType(*uri);
482     if (!reply.WriteString(type)) {
483         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteString type");
484         return ERR_INVALID_VALUE;
485     }
486     return NO_ERROR;
487 }
488 
ReloadInner(MessageParcel & data,MessageParcel & reply)489 int AbilitySchedulerStub::ReloadInner(MessageParcel &data, MessageParcel &reply)
490 {
491     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
492     if (uri == nullptr) {
493         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
494         return ERR_INVALID_VALUE;
495     }
496 
497     std::shared_ptr<PacMap> extras(data.ReadParcelable<PacMap>());
498     if (extras == nullptr) {
499         TAG_LOGE(AAFwkTag::ABILITYMGR, "null extras");
500         return ERR_INVALID_VALUE;
501     }
502     bool ret = Reload(*uri, *extras);
503     if (!reply.WriteBool(ret)) {
504         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to writeBool ret");
505         return ERR_INVALID_VALUE;
506     }
507     return NO_ERROR;
508 }
509 
BatchInsertInner(MessageParcel & data,MessageParcel & reply)510 int AbilitySchedulerStub::BatchInsertInner(MessageParcel &data, MessageParcel &reply)
511 {
512     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
513     if (uri == nullptr) {
514         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
515         return ERR_INVALID_VALUE;
516     }
517 
518     int count = 0;
519     if (!data.ReadInt32(count)) {
520         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 index");
521         return ERR_INVALID_VALUE;
522     }
523 
524     if (count > CYCLE_LIMIT) {
525         TAG_LOGE(AAFwkTag::ABILITYMGR, "count too large");
526         return ERR_INVALID_VALUE;
527     }
528     std::vector<NativeRdb::ValuesBucket> values;
529     for (int i = 0; i < count; i++) {
530         values.emplace_back(NativeRdb::ValuesBucket::Unmarshalling(data));
531     }
532 
533     int ret = BatchInsert(*uri, values);
534     if (!reply.WriteInt32(ret)) {
535         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
536         return ERR_INVALID_VALUE;
537     }
538     return NO_ERROR;
539 }
540 
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)541 int AbilitySchedulerStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
542 {
543     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
544     if (uri == nullptr) {
545         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
546         return ERR_INVALID_VALUE;
547     }
548     auto obServer = iface_cast<IDataAbilityObserver>(data.ReadRemoteObject());
549     if (obServer == nullptr) {
550         TAG_LOGE(AAFwkTag::ABILITYMGR, "null obServer");
551         return ERR_INVALID_VALUE;
552     }
553 
554     bool ret = ScheduleRegisterObserver(*uri, obServer);
555     if (!reply.WriteInt32(ret)) {
556         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
557         return ERR_INVALID_VALUE;
558     }
559     return NO_ERROR;
560 }
561 
UnregisterObserverInner(MessageParcel & data,MessageParcel & reply)562 int AbilitySchedulerStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)
563 {
564     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
565     if (uri == nullptr) {
566         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
567         return ERR_INVALID_VALUE;
568     }
569     auto obServer = iface_cast<IDataAbilityObserver>(data.ReadRemoteObject());
570     if (obServer == nullptr) {
571         TAG_LOGE(AAFwkTag::ABILITYMGR, "null obServer");
572         return ERR_INVALID_VALUE;
573     }
574 
575     bool ret = ScheduleUnregisterObserver(*uri, obServer);
576     if (!reply.WriteInt32(ret)) {
577         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
578         return ERR_INVALID_VALUE;
579     }
580     return NO_ERROR;
581 }
582 
NotifyChangeInner(MessageParcel & data,MessageParcel & reply)583 int AbilitySchedulerStub::NotifyChangeInner(MessageParcel &data, MessageParcel &reply)
584 {
585     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
586     if (uri == nullptr) {
587         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
588         return ERR_INVALID_VALUE;
589     }
590 
591     bool ret = ScheduleNotifyChange(*uri);
592     if (!reply.WriteInt32(ret)) {
593         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
594         return ERR_INVALID_VALUE;
595     }
596     return NO_ERROR;
597 }
598 
NormalizeUriInner(MessageParcel & data,MessageParcel & reply)599 int AbilitySchedulerStub::NormalizeUriInner(MessageParcel &data, MessageParcel &reply)
600 {
601     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
602     if (uri == nullptr) {
603         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
604         return ERR_INVALID_VALUE;
605     }
606 
607     Uri ret("");
608     ret = NormalizeUri(*uri);
609     if (!reply.WriteParcelable(&ret)) {
610         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable type");
611         return ERR_INVALID_VALUE;
612     }
613     return NO_ERROR;
614 }
615 
DenormalizeUriInner(MessageParcel & data,MessageParcel & reply)616 int AbilitySchedulerStub::DenormalizeUriInner(MessageParcel &data, MessageParcel &reply)
617 {
618     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
619     if (uri == nullptr) {
620         TAG_LOGE(AAFwkTag::ABILITYMGR, "null uri");
621         return ERR_INVALID_VALUE;
622     }
623 
624     Uri ret("");
625     ret = DenormalizeUri(*uri);
626     if (!reply.WriteParcelable(&ret)) {
627         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteParcelable type");
628         return ERR_INVALID_VALUE;
629     }
630     return NO_ERROR;
631 }
632 
ExecuteBatchInner(MessageParcel & data,MessageParcel & reply)633 int AbilitySchedulerStub::ExecuteBatchInner(MessageParcel &data, MessageParcel &reply)
634 {
635     TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
636     int count = 0;
637     if (!data.ReadInt32(count)) {
638         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to ReadInt32 count");
639         return ERR_INVALID_VALUE;
640     }
641     TAG_LOGI(AAFwkTag::ABILITYMGR, "count:%{public}d", count);
642     if (count > CYCLE_LIMIT) {
643         TAG_LOGE(AAFwkTag::ABILITYMGR, "count too large");
644         return ERR_INVALID_VALUE;
645     }
646     std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> operations;
647     for (int i = 0; i < count; i++) {
648         std::shared_ptr<AppExecFwk::DataAbilityOperation> dataAbilityOperation(
649             data.ReadParcelable<AppExecFwk::DataAbilityOperation>());
650         if (dataAbilityOperation == nullptr) {
651             TAG_LOGE(AAFwkTag::ABILITYMGR, "null dataAbilityOperation, index: %{public}d", i);
652             return ERR_INVALID_VALUE;
653         }
654         operations.push_back(dataAbilityOperation);
655     }
656 
657     std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> results = ExecuteBatch(operations);
658     int total = (int)results.size();
659     if (!reply.WriteInt32(total)) {
660         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
661         return ERR_INVALID_VALUE;
662     }
663     TAG_LOGI(AAFwkTag::ABILITYMGR, "total:%{public}d", total);
664     for (int i = 0; i < total; i++) {
665         if (results[i] == nullptr) {
666             TAG_LOGE(AAFwkTag::ABILITYMGR,
667                 "null results[i], index: %{public}d", i);
668             return ERR_INVALID_VALUE;
669         }
670         if (!reply.WriteParcelable(results[i].get())) {
671             TAG_LOGE(AAFwkTag::ABILITYMGR,
672                 "fail to WriteParcelable operation, index: %{public}d", i);
673             return ERR_INVALID_VALUE;
674         }
675     }
676     TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
677     return NO_ERROR;
678 }
679 
ContinueAbilityInner(MessageParcel & data,MessageParcel & reply)680 int AbilitySchedulerStub::ContinueAbilityInner(MessageParcel &data, MessageParcel &reply)
681 {
682     std::string deviceId = data.ReadString();
683     uint32_t versionCode = data.ReadUint32();
684     ContinueAbility(deviceId, versionCode);
685     return NO_ERROR;
686 }
687 
NotifyContinuationResultInner(MessageParcel & data,MessageParcel & reply)688 int AbilitySchedulerStub::NotifyContinuationResultInner(MessageParcel &data, MessageParcel &reply)
689 {
690     int32_t result = data.ReadInt32();
691     NotifyContinuationResult(result);
692     return NO_ERROR;
693 }
694 
DumpAbilityInfoInner(MessageParcel & data,MessageParcel & reply)695 int AbilitySchedulerStub::DumpAbilityInfoInner(MessageParcel &data, MessageParcel &reply)
696 {
697     std::vector<std::string> infos;
698     std::vector<std::string> params;
699     if (!data.ReadStringVector(&params)) {
700         TAG_LOGI(AAFwkTag::ABILITYMGR, "DumpAbilityInfoInner read params error");
701         return ERR_INVALID_VALUE;
702     }
703 
704     DumpAbilityInfo(params, infos);
705 
706     return NO_ERROR;
707 }
708 
CallRequestInner(MessageParcel & data,MessageParcel & reply)709 int AbilitySchedulerStub::CallRequestInner(MessageParcel &data, MessageParcel &reply)
710 {
711     CallRequest();
712     return NO_ERROR;
713 }
714 
OnExecuteIntentInner(MessageParcel & data,MessageParcel & reply)715 int AbilitySchedulerStub::OnExecuteIntentInner(MessageParcel &data, MessageParcel &reply)
716 {
717     TAG_LOGI(AAFwkTag::INTENT, "on execute intent stub");
718     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
719     if (want == nullptr) {
720         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
721         return ERR_INVALID_VALUE;
722     }
723     OnExecuteIntent(*want);
724     return NO_ERROR;
725 }
726 
CreateModalUIExtensionInner(MessageParcel & data,MessageParcel & reply)727 int AbilitySchedulerStub::CreateModalUIExtensionInner(MessageParcel &data, MessageParcel &reply)
728 {
729     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
730     if (want == nullptr) {
731         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
732         return ERR_INVALID_VALUE;
733     }
734     int ret = CreateModalUIExtension(*want);
735     if (!reply.WriteInt32(ret)) {
736         TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to WriteInt32 ret");
737         return ERR_INVALID_VALUE;
738     }
739     return NO_ERROR;
740 }
741 
UpdateSessionTokenInner(MessageParcel & data,MessageParcel & reply)742 int AbilitySchedulerStub::UpdateSessionTokenInner(MessageParcel &data, MessageParcel &reply)
743 {
744     sptr<IRemoteObject> sessionToken = data.ReadRemoteObject();
745     UpdateSessionToken(sessionToken);
746     return NO_ERROR;
747 }
748 
CollaborateDataInner(MessageParcel & data)749 int AbilitySchedulerStub::CollaborateDataInner(MessageParcel &data)
750 {
751     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
752     if (want == nullptr) {
753         TAG_LOGE(AAFwkTag::ABILITYMGR, "null want");
754         return ERR_INVALID_VALUE;
755     }
756     ScheduleCollaborate(*want);
757     return NO_ERROR;
758 }
759 
ScheduleAbilityRequestFailureInner(MessageParcel & data)760 int AbilitySchedulerStub::ScheduleAbilityRequestFailureInner(MessageParcel &data)
761 {
762     std::string requestId = data.ReadString();
763     std::unique_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
764     if (element == nullptr) {
765         TAG_LOGE(AAFwkTag::ABILITYMGR, "null element");
766         return ERR_INVALID_VALUE;
767     }
768     std::string message = data.ReadString();
769     int32_t resultCode = data.ReadInt32();
770     ScheduleAbilityRequestFailure(requestId, *element, message, resultCode);
771     return NO_ERROR;
772 }
773 
ScheduleAbilityRequestSuccessInner(MessageParcel & data)774 int AbilitySchedulerStub::ScheduleAbilityRequestSuccessInner(MessageParcel &data)
775 {
776     std::string requestId = data.ReadString();
777     std::unique_ptr<AppExecFwk::ElementName> element(data.ReadParcelable<AppExecFwk::ElementName>());
778     if (element == nullptr) {
779         TAG_LOGE(AAFwkTag::ABILITYMGR, "null element");
780         return ERR_INVALID_VALUE;
781     }
782     ScheduleAbilityRequestSuccess(requestId, *element);
783     return NO_ERROR;
784 }
785 
ScheduleAbilitiesRequestDoneInner(MessageParcel & data)786 int AbilitySchedulerStub::ScheduleAbilitiesRequestDoneInner(MessageParcel &data)
787 {
788     std::string requestKey = data.ReadString();
789     int32_t resultCode = data.ReadInt32();
790     ScheduleAbilitiesRequestDone(requestKey, resultCode);
791     return NO_ERROR;
792 }
793 
OnRemoteDied(const wptr<IRemoteObject> & remote)794 void AbilitySchedulerRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
795 {
796     TAG_LOGE(AAFwkTag::ABILITYMGR, "call");
797 
798     if (handler_) {
799         handler_(remote);
800     }
801 }
802 
AbilitySchedulerRecipient(RemoteDiedHandler handler)803 AbilitySchedulerRecipient::AbilitySchedulerRecipient(RemoteDiedHandler handler) : handler_(handler)
804 {}
805 
~AbilitySchedulerRecipient()806 AbilitySchedulerRecipient::~AbilitySchedulerRecipient()
807 {}
808 }  // namespace AAFwk
809 }  // namespace OHOS
810