1 /*
2 * Copyright (c) 2021-2022 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 "abs_shared_result_set.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_wrapper.h"
24 #include "ipc_types.h"
25 #include "ishared_result_set.h"
26 #include "pac_map.h"
27 #include "values_bucket.h"
28 #include "want.h"
29
30 namespace OHOS {
31 namespace AAFwk {
32 constexpr int CYCLE_LIMIT = 2000;
AbilitySchedulerStub()33 AbilitySchedulerStub::AbilitySchedulerStub()
34 {
35 requestFuncMap_[SCHEDULE_ABILITY_TRANSACTION] = &AbilitySchedulerStub::AbilityTransactionInner;
36 requestFuncMap_[SEND_RESULT] = &AbilitySchedulerStub::SendResultInner;
37 requestFuncMap_[SCHEDULE_ABILITY_CONNECT] = &AbilitySchedulerStub::ConnectAbilityInner;
38 requestFuncMap_[SCHEDULE_ABILITY_DISCONNECT] = &AbilitySchedulerStub::DisconnectAbilityInner;
39 requestFuncMap_[SCHEDULE_ABILITY_COMMAND] = &AbilitySchedulerStub::CommandAbilityInner;
40 requestFuncMap_[SCHEDULE_SAVE_ABILITY_STATE] = &AbilitySchedulerStub::SaveAbilityStateInner;
41 requestFuncMap_[SCHEDULE_RESTORE_ABILITY_STATE] = &AbilitySchedulerStub::RestoreAbilityStateInner;
42 requestFuncMap_[SCHEDULE_GETFILETYPES] = &AbilitySchedulerStub::GetFileTypesInner;
43 requestFuncMap_[SCHEDULE_OPENFILE] = &AbilitySchedulerStub::OpenFileInner;
44 requestFuncMap_[SCHEDULE_OPENRAWFILE] = &AbilitySchedulerStub::OpenRawFileInner;
45 requestFuncMap_[SCHEDULE_INSERT] = &AbilitySchedulerStub::InsertInner;
46 requestFuncMap_[SCHEDULE_UPDATE] = &AbilitySchedulerStub::UpdatetInner;
47 requestFuncMap_[SCHEDULE_DELETE] = &AbilitySchedulerStub::DeleteInner;
48 requestFuncMap_[SCHEDULE_QUERY] = &AbilitySchedulerStub::QueryInner;
49 requestFuncMap_[SCHEDULE_CALL] = &AbilitySchedulerStub::CallInner;
50 requestFuncMap_[SCHEDULE_GETTYPE] = &AbilitySchedulerStub::GetTypeInner;
51 requestFuncMap_[SCHEDULE_RELOAD] = &AbilitySchedulerStub::ReloadInner;
52 requestFuncMap_[SCHEDULE_BATCHINSERT] = &AbilitySchedulerStub::BatchInsertInner;
53 requestFuncMap_[SCHEDULE_REGISTEROBSERVER] = &AbilitySchedulerStub::RegisterObserverInner;
54 requestFuncMap_[SCHEDULE_UNREGISTEROBSERVER] = &AbilitySchedulerStub::UnregisterObserverInner;
55 requestFuncMap_[SCHEDULE_NOTIFYCHANGE] = &AbilitySchedulerStub::NotifyChangeInner;
56 requestFuncMap_[SCHEDULE_NORMALIZEURI] = &AbilitySchedulerStub::NormalizeUriInner;
57 requestFuncMap_[SCHEDULE_DENORMALIZEURI] = &AbilitySchedulerStub::DenormalizeUriInner;
58 requestFuncMap_[SCHEDULE_EXECUTEBATCH] = &AbilitySchedulerStub::ExecuteBatchInner;
59 requestFuncMap_[NOTIFY_CONTINUATION_RESULT] = &AbilitySchedulerStub::NotifyContinuationResultInner;
60 requestFuncMap_[REQUEST_CALL_REMOTE] = &AbilitySchedulerStub::CallRequestInner;
61 requestFuncMap_[CONTINUE_ABILITY] = &AbilitySchedulerStub::ContinueAbilityInner;
62 requestFuncMap_[DUMP_ABILITY_RUNNER_INNER] = &AbilitySchedulerStub::DumpAbilityInfoInner;
63 #ifdef ABILITY_COMMAND_FOR_TEST
64 requestFuncMap_[BLOCK_ABILITY_INNER] = &AbilitySchedulerStub::BlockAbilityInner;
65 #endif
66 }
67
~AbilitySchedulerStub()68 AbilitySchedulerStub::~AbilitySchedulerStub()
69 {
70 requestFuncMap_.clear();
71 }
72
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)73 int AbilitySchedulerStub::OnRemoteRequest(
74 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
75 {
76 std::u16string descriptor = AbilitySchedulerStub::GetDescriptor();
77 std::u16string remoteDescriptor = data.ReadInterfaceToken();
78 if (descriptor != remoteDescriptor) {
79 HILOG_ERROR("local descriptor is not equal to remote");
80 return ERR_INVALID_STATE;
81 }
82
83 auto itFunc = requestFuncMap_.find(code);
84 if (itFunc != requestFuncMap_.end()) {
85 auto requestFunc = itFunc->second;
86 if (requestFunc != nullptr) {
87 return (this->*requestFunc)(data, reply);
88 }
89 }
90 HILOG_WARN("AbilitySchedulerStub::OnRemoteRequest, default case, need check.");
91 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
92 }
93
AbilityTransactionInner(MessageParcel & data,MessageParcel & reply)94 int AbilitySchedulerStub::AbilityTransactionInner(MessageParcel &data, MessageParcel &reply)
95 {
96 std::shared_ptr<Want> want(data.ReadParcelable<Want>());
97 if (want == nullptr) {
98 HILOG_ERROR("AbilitySchedulerStub want is nullptr");
99 return ERR_INVALID_VALUE;
100 }
101 std::unique_ptr<LifeCycleStateInfo> stateInfo(data.ReadParcelable<LifeCycleStateInfo>());
102 if (!stateInfo) {
103 HILOG_ERROR("ReadParcelable<LifeCycleStateInfo> failed");
104 return ERR_INVALID_VALUE;
105 }
106 ScheduleAbilityTransaction(*want, *stateInfo);
107 return NO_ERROR;
108 }
109
SendResultInner(MessageParcel & data,MessageParcel & reply)110 int AbilitySchedulerStub::SendResultInner(MessageParcel &data, MessageParcel &reply)
111 {
112 int requestCode = data.ReadInt32();
113 int resultCode = data.ReadInt32();
114 std::shared_ptr<Want> want(data.ReadParcelable<Want>());
115 if (want == nullptr) {
116 HILOG_ERROR("AbilitySchedulerStub want is nullptr");
117 return ERR_INVALID_VALUE;
118 }
119 SendResult(requestCode, resultCode, *want);
120 return NO_ERROR;
121 }
122
ConnectAbilityInner(MessageParcel & data,MessageParcel & reply)123 int AbilitySchedulerStub::ConnectAbilityInner(MessageParcel &data, MessageParcel &reply)
124 {
125 std::shared_ptr<Want> want(data.ReadParcelable<Want>());
126 if (want == nullptr) {
127 HILOG_ERROR("AbilitySchedulerStub want is nullptr");
128 return ERR_INVALID_VALUE;
129 }
130 ScheduleConnectAbility(*want);
131 return NO_ERROR;
132 }
133
DisconnectAbilityInner(MessageParcel & data,MessageParcel & reply)134 int AbilitySchedulerStub::DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply)
135 {
136 std::shared_ptr<Want> want(data.ReadParcelable<Want>());
137 if (want == nullptr) {
138 HILOG_ERROR("AbilitySchedulerStub want is nullptr");
139 return ERR_INVALID_VALUE;
140 }
141 ScheduleDisconnectAbility(*want);
142 return NO_ERROR;
143 }
144
CommandAbilityInner(MessageParcel & data,MessageParcel & reply)145 int AbilitySchedulerStub::CommandAbilityInner(MessageParcel &data, MessageParcel &reply)
146 {
147 std::shared_ptr<Want> want(data.ReadParcelable<Want>());
148 if (want == nullptr) {
149 HILOG_ERROR("AbilitySchedulerStub want is nullptr");
150 return ERR_INVALID_VALUE;
151 }
152 bool reStart = data.ReadBool();
153 int startId = data.ReadInt32();
154 HILOG_INFO("ReadInt32, startId:%{public}d", startId);
155 ScheduleCommandAbility(*want, reStart, startId);
156 return NO_ERROR;
157 }
158
SaveAbilityStateInner(MessageParcel & data,MessageParcel & reply)159 int AbilitySchedulerStub::SaveAbilityStateInner(MessageParcel &data, MessageParcel &reply)
160 {
161 ScheduleSaveAbilityState();
162 return NO_ERROR;
163 }
164
RestoreAbilityStateInner(MessageParcel & data,MessageParcel & reply)165 int AbilitySchedulerStub::RestoreAbilityStateInner(MessageParcel &data, MessageParcel &reply)
166 {
167 std::shared_ptr<PacMap> pacMap(data.ReadParcelable<PacMap>());
168 if (pacMap == nullptr) {
169 HILOG_ERROR("AbilitySchedulerStub RestoreAbilityState is nullptr");
170 return ERR_INVALID_VALUE;
171 }
172 ScheduleRestoreAbilityState(*pacMap);
173 return NO_ERROR;
174 }
175
GetFileTypesInner(MessageParcel & data,MessageParcel & reply)176 int AbilitySchedulerStub::GetFileTypesInner(MessageParcel &data, MessageParcel &reply)
177 {
178 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
179 if (uri == nullptr) {
180 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
181 return ERR_INVALID_VALUE;
182 }
183 std::string mimeTypeFilter = data.ReadString();
184 if (mimeTypeFilter.empty()) {
185 HILOG_ERROR("AbilitySchedulerStub mimeTypeFilter is nullptr");
186 return ERR_INVALID_VALUE;
187 }
188 std::vector<std::string> types = GetFileTypes(*uri, mimeTypeFilter);
189 if (!reply.WriteStringVector(types)) {
190 HILOG_ERROR("fail to WriteStringVector types");
191 return ERR_INVALID_VALUE;
192 }
193 return NO_ERROR;
194 }
195
OpenFileInner(MessageParcel & data,MessageParcel & reply)196 int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &reply)
197 {
198 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
199 if (uri == nullptr) {
200 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
201 return ERR_INVALID_VALUE;
202 }
203 std::string mode = data.ReadString();
204 if (mode.empty()) {
205 HILOG_ERROR("AbilitySchedulerStub mode is nullptr");
206 return ERR_INVALID_VALUE;
207 }
208 int fd = OpenFile(*uri, mode);
209 if (fd < 0) {
210 HILOG_ERROR("OpenFile fail, fd is %{pubilc}d", fd);
211 return ERR_INVALID_VALUE;
212 }
213 if (!reply.WriteFileDescriptor(fd)) {
214 HILOG_ERROR("fail to WriteFileDescriptor fd");
215 return ERR_INVALID_VALUE;
216 }
217 return NO_ERROR;
218 }
219
OpenRawFileInner(MessageParcel & data,MessageParcel & reply)220 int AbilitySchedulerStub::OpenRawFileInner(MessageParcel &data, MessageParcel &reply)
221 {
222 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
223 if (uri == nullptr) {
224 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
225 return ERR_INVALID_VALUE;
226 }
227 std::string mode = data.ReadString();
228 if (mode.empty()) {
229 HILOG_ERROR("AbilitySchedulerStub mode is nullptr");
230 return ERR_INVALID_VALUE;
231 }
232 int fd = OpenRawFile(*uri, mode);
233 if (!reply.WriteInt32(fd)) {
234 HILOG_ERROR("fail to WriteInt32 fd");
235 return ERR_INVALID_VALUE;
236 }
237 return NO_ERROR;
238 }
239
InsertInner(MessageParcel & data,MessageParcel & reply)240 int AbilitySchedulerStub::InsertInner(MessageParcel &data, MessageParcel &reply)
241 {
242 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
243 if (uri == nullptr) {
244 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
245 return ERR_INVALID_VALUE;
246 }
247 std::shared_ptr<NativeRdb::ValuesBucket> value(data.ReadParcelable<NativeRdb::ValuesBucket>());
248 if (value == nullptr) {
249 HILOG_ERROR("ReadParcelable value is nullptr");
250 return ERR_INVALID_VALUE;
251 }
252 int index = Insert(*uri, *value);
253 if (!reply.WriteInt32(index)) {
254 HILOG_ERROR("fail to WriteInt32 index");
255 return ERR_INVALID_VALUE;
256 }
257 HILOG_INFO("AbilitySchedulerStub::InsertInner end");
258 return NO_ERROR;
259 }
260
CallInner(MessageParcel & data,MessageParcel & reply)261 int AbilitySchedulerStub::CallInner(MessageParcel &data, MessageParcel &reply)
262 {
263 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
264 if (uri == nullptr) {
265 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
266 return ERR_INVALID_VALUE;
267 }
268 std::string method = data.ReadString();
269 if (method.empty()) {
270 HILOG_ERROR("ReadParcelable method is nullptr");
271 return ERR_INVALID_VALUE;
272 }
273 std::string arg = data.ReadString();
274 if (arg.empty()) {
275 HILOG_ERROR("ReadParcelable arg is nullptr");
276 return ERR_INVALID_VALUE;
277 }
278
279 std::shared_ptr<AppExecFwk::PacMap> pacMap(data.ReadParcelable<AppExecFwk::PacMap>());
280 if (pacMap == nullptr) {
281 HILOG_ERROR("ReadParcelable pacMap is nullptr");
282 return ERR_INVALID_VALUE;
283 }
284 std::shared_ptr<AppExecFwk::PacMap> result = Call(*uri, method, arg, *pacMap);
285 if (!reply.WriteParcelable(result.get())) {
286 HILOG_ERROR("fail to WriteParcelable pacMap error");
287 return ERR_INVALID_VALUE;
288 }
289 HILOG_INFO("AbilitySchedulerStub::CallInner end");
290 return NO_ERROR;
291 }
292
UpdatetInner(MessageParcel & data,MessageParcel & reply)293 int AbilitySchedulerStub::UpdatetInner(MessageParcel &data, MessageParcel &reply)
294 {
295 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
296 if (uri == nullptr) {
297 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
298 return ERR_INVALID_VALUE;
299 }
300 std::shared_ptr<NativeRdb::ValuesBucket> value(data.ReadParcelable<NativeRdb::ValuesBucket>());
301 if (value == nullptr) {
302 HILOG_ERROR("ReadParcelable value is nullptr");
303 return ERR_INVALID_VALUE;
304 }
305 std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
306 data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
307 if (predicates == nullptr) {
308 HILOG_ERROR("ReadParcelable predicates is nullptr");
309 return ERR_INVALID_VALUE;
310 }
311 int index = Update(*uri, *value, *predicates);
312 if (!reply.WriteInt32(index)) {
313 HILOG_ERROR("fail to WriteInt32 index");
314 return ERR_INVALID_VALUE;
315 }
316 return NO_ERROR;
317 }
318
DeleteInner(MessageParcel & data,MessageParcel & reply)319 int AbilitySchedulerStub::DeleteInner(MessageParcel &data, MessageParcel &reply)
320 {
321 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
322 if (uri == nullptr) {
323 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
324 return ERR_INVALID_VALUE;
325 }
326 std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
327 data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
328 if (predicates == nullptr) {
329 HILOG_ERROR("ReadParcelable predicates is nullptr");
330 return ERR_INVALID_VALUE;
331 }
332 int index = Delete(*uri, *predicates);
333 if (!reply.WriteInt32(index)) {
334 HILOG_ERROR("fail to WriteInt32 index");
335 return ERR_INVALID_VALUE;
336 }
337 return NO_ERROR;
338 }
339
QueryInner(MessageParcel & data,MessageParcel & reply)340 int AbilitySchedulerStub::QueryInner(MessageParcel &data, MessageParcel &reply)
341 {
342 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
343 if (uri == nullptr) {
344 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
345 return ERR_INVALID_VALUE;
346 }
347 std::vector<std::string> columns;
348 if (!data.ReadStringVector(&columns)) {
349 HILOG_ERROR("fail to ReadStringVector columns");
350 return ERR_INVALID_VALUE;
351 }
352 std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
353 data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
354 if (predicates == nullptr) {
355 HILOG_ERROR("ReadParcelable predicates is nullptr");
356 return ERR_INVALID_VALUE;
357 }
358 auto resultSet = Query(*uri, columns, *predicates);
359 if (resultSet == nullptr) {
360 HILOG_ERROR("fail to WriteParcelable resultSet");
361 return ERR_INVALID_VALUE;
362 }
363 auto result = NativeRdb::ISharedResultSet::WriteToParcel(std::move(resultSet), reply);
364 if (result == nullptr) {
365 HILOG_ERROR("!resultSet->Marshalling(reply)");
366 return ERR_INVALID_VALUE;
367 }
368 HILOG_INFO("AbilitySchedulerStub::QueryInner end");
369 return NO_ERROR;
370 }
371
GetTypeInner(MessageParcel & data,MessageParcel & reply)372 int AbilitySchedulerStub::GetTypeInner(MessageParcel &data, MessageParcel &reply)
373 {
374 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
375 if (uri == nullptr) {
376 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
377 return ERR_INVALID_VALUE;
378 }
379 std::string type = GetType(*uri);
380 if (!reply.WriteString(type)) {
381 HILOG_ERROR("fail to WriteString type");
382 return ERR_INVALID_VALUE;
383 }
384 return NO_ERROR;
385 }
386
ReloadInner(MessageParcel & data,MessageParcel & reply)387 int AbilitySchedulerStub::ReloadInner(MessageParcel &data, MessageParcel &reply)
388 {
389 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
390 if (uri == nullptr) {
391 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
392 return ERR_INVALID_VALUE;
393 }
394
395 std::shared_ptr<PacMap> extras(data.ReadParcelable<PacMap>());
396 if (extras == nullptr) {
397 HILOG_ERROR("AbilitySchedulerStub extras is nullptr");
398 return ERR_INVALID_VALUE;
399 }
400 bool ret = Reload(*uri, *extras);
401 if (!reply.WriteBool(ret)) {
402 HILOG_ERROR("fail to writeBool ret");
403 return ERR_INVALID_VALUE;
404 }
405 return NO_ERROR;
406 }
407
BatchInsertInner(MessageParcel & data,MessageParcel & reply)408 int AbilitySchedulerStub::BatchInsertInner(MessageParcel &data, MessageParcel &reply)
409 {
410 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
411 if (uri == nullptr) {
412 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
413 return ERR_INVALID_VALUE;
414 }
415
416 int count = 0;
417 if (!data.ReadInt32(count)) {
418 HILOG_ERROR("fail to ReadInt32 index");
419 return ERR_INVALID_VALUE;
420 }
421
422 if (count > CYCLE_LIMIT) {
423 HILOG_ERROR("count is too large");
424 return ERR_INVALID_VALUE;
425 }
426 std::vector<NativeRdb::ValuesBucket> values;
427 for (int i = 0; i < count; i++) {
428 std::unique_ptr<NativeRdb::ValuesBucket> value(data.ReadParcelable<NativeRdb::ValuesBucket>());
429 if (value == nullptr) {
430 HILOG_ERROR("AbilitySchedulerStub value is nullptr, index = %{public}d", i);
431 return ERR_INVALID_VALUE;
432 }
433 values.emplace_back(*value);
434 }
435
436 int ret = BatchInsert(*uri, values);
437 if (!reply.WriteInt32(ret)) {
438 HILOG_ERROR("fail to WriteInt32 ret");
439 return ERR_INVALID_VALUE;
440 }
441 return NO_ERROR;
442 }
443
RegisterObserverInner(MessageParcel & data,MessageParcel & reply)444 int AbilitySchedulerStub::RegisterObserverInner(MessageParcel &data, MessageParcel &reply)
445 {
446 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
447 if (uri == nullptr) {
448 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
449 return ERR_INVALID_VALUE;
450 }
451 auto obServer = iface_cast<IDataAbilityObserver>(data.ReadRemoteObject());
452 if (obServer == nullptr) {
453 HILOG_ERROR("AbilitySchedulerStub obServer is nullptr");
454 return ERR_INVALID_VALUE;
455 }
456
457 bool ret = ScheduleRegisterObserver(*uri, obServer);
458 if (!reply.WriteInt32(ret)) {
459 HILOG_ERROR("fail to WriteInt32 ret");
460 return ERR_INVALID_VALUE;
461 }
462 return NO_ERROR;
463 }
464
UnregisterObserverInner(MessageParcel & data,MessageParcel & reply)465 int AbilitySchedulerStub::UnregisterObserverInner(MessageParcel &data, MessageParcel &reply)
466 {
467 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
468 if (uri == nullptr) {
469 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
470 return ERR_INVALID_VALUE;
471 }
472 auto obServer = iface_cast<IDataAbilityObserver>(data.ReadRemoteObject());
473 if (obServer == nullptr) {
474 HILOG_ERROR("AbilitySchedulerStub obServer is nullptr");
475 return ERR_INVALID_VALUE;
476 }
477
478 bool ret = ScheduleUnregisterObserver(*uri, obServer);
479 if (!reply.WriteInt32(ret)) {
480 HILOG_ERROR("fail to WriteInt32 ret");
481 return ERR_INVALID_VALUE;
482 }
483 return NO_ERROR;
484 }
485
NotifyChangeInner(MessageParcel & data,MessageParcel & reply)486 int AbilitySchedulerStub::NotifyChangeInner(MessageParcel &data, MessageParcel &reply)
487 {
488 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
489 if (uri == nullptr) {
490 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
491 return ERR_INVALID_VALUE;
492 }
493
494 bool ret = ScheduleNotifyChange(*uri);
495 if (!reply.WriteInt32(ret)) {
496 HILOG_ERROR("fail to WriteInt32 ret");
497 return ERR_INVALID_VALUE;
498 }
499 return NO_ERROR;
500 }
501
NormalizeUriInner(MessageParcel & data,MessageParcel & reply)502 int AbilitySchedulerStub::NormalizeUriInner(MessageParcel &data, MessageParcel &reply)
503 {
504 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
505 if (uri == nullptr) {
506 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
507 return ERR_INVALID_VALUE;
508 }
509
510 Uri ret("");
511 ret = NormalizeUri(*uri);
512 if (!reply.WriteParcelable(&ret)) {
513 HILOG_ERROR("fail to WriteParcelable type");
514 return ERR_INVALID_VALUE;
515 }
516 return NO_ERROR;
517 }
518
DenormalizeUriInner(MessageParcel & data,MessageParcel & reply)519 int AbilitySchedulerStub::DenormalizeUriInner(MessageParcel &data, MessageParcel &reply)
520 {
521 std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
522 if (uri == nullptr) {
523 HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
524 return ERR_INVALID_VALUE;
525 }
526
527 Uri ret("");
528 ret = DenormalizeUri(*uri);
529 if (!reply.WriteParcelable(&ret)) {
530 HILOG_ERROR("fail to WriteParcelable type");
531 return ERR_INVALID_VALUE;
532 }
533 return NO_ERROR;
534 }
535
ExecuteBatchInner(MessageParcel & data,MessageParcel & reply)536 int AbilitySchedulerStub::ExecuteBatchInner(MessageParcel &data, MessageParcel &reply)
537 {
538 HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner start");
539 int count = 0;
540 if (!data.ReadInt32(count)) {
541 HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner fail to ReadInt32 count");
542 return ERR_INVALID_VALUE;
543 }
544 HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner count:%{public}d", count);
545 if (count > CYCLE_LIMIT) {
546 HILOG_ERROR("count is too large");
547 return ERR_INVALID_VALUE;
548 }
549 std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> operations;
550 for (int i = 0; i < count; i++) {
551 AppExecFwk::DataAbilityOperation *operation = data.ReadParcelable<AppExecFwk::DataAbilityOperation>();
552 if (operation == nullptr) {
553 HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner operation is nullptr, index = %{public}d", i);
554 return ERR_INVALID_VALUE;
555 }
556 std::shared_ptr<AppExecFwk::DataAbilityOperation> dataAbilityOperation(operation);
557 operations.push_back(dataAbilityOperation);
558 }
559
560 std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> results = ExecuteBatch(operations);
561 int total = (int)results.size();
562 if (!reply.WriteInt32(total)) {
563 HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner fail to WriteInt32 ret");
564 return ERR_INVALID_VALUE;
565 }
566 HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner total:%{public}d", total);
567 for (int i = 0; i < total; i++) {
568 if (results[i] == nullptr) {
569 HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner results[i] is nullptr, index = %{public}d", i);
570 return ERR_INVALID_VALUE;
571 }
572 if (!reply.WriteParcelable(results[i].get())) {
573 HILOG_ERROR(
574 "AbilitySchedulerStub::ExecuteBatchInner fail to WriteParcelable operation, index = %{public}d", i);
575 return ERR_INVALID_VALUE;
576 }
577 }
578 HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner end");
579 return NO_ERROR;
580 }
581
ContinueAbilityInner(MessageParcel & data,MessageParcel & reply)582 int AbilitySchedulerStub::ContinueAbilityInner(MessageParcel &data, MessageParcel &reply)
583 {
584 std::string deviceId = data.ReadString();
585 uint32_t versionCode = data.ReadUint32();
586 ContinueAbility(deviceId, versionCode);
587 return NO_ERROR;
588 }
589
NotifyContinuationResultInner(MessageParcel & data,MessageParcel & reply)590 int AbilitySchedulerStub::NotifyContinuationResultInner(MessageParcel &data, MessageParcel &reply)
591 {
592 int32_t result = data.ReadInt32();
593 NotifyContinuationResult(result);
594 return NO_ERROR;
595 }
596
DumpAbilityInfoInner(MessageParcel & data,MessageParcel & reply)597 int AbilitySchedulerStub::DumpAbilityInfoInner(MessageParcel &data, MessageParcel &reply)
598 {
599 std::vector<std::string> infos;
600 std::vector<std::string> params;
601 if (!data.ReadStringVector(¶ms)) {
602 HILOG_INFO("DumpAbilityInfoInner read params error");
603 return ERR_INVALID_VALUE;
604 }
605
606 DumpAbilityInfo(params, infos);
607
608 return NO_ERROR;
609 }
CallRequestInner(MessageParcel & data,MessageParcel & reply)610 int AbilitySchedulerStub::CallRequestInner(MessageParcel &data, MessageParcel &reply)
611 {
612 CallRequest();
613 return NO_ERROR;
614 }
615
616 #ifdef ABILITY_COMMAND_FOR_TEST
BlockAbilityInner(MessageParcel & data,MessageParcel & reply)617 int AbilitySchedulerStub::BlockAbilityInner(MessageParcel &data, MessageParcel &reply)
618 {
619 HILOG_INFO("AbilitySchedulerStub::BlockAbilityInner start");
620
621 auto result = BlockAbility();
622 if (!reply.WriteInt32(result)) {
623 HILOG_ERROR("fail to WriteInt32 result");
624 return ERR_INVALID_VALUE;
625 }
626 return NO_ERROR;
627 }
628 #endif
629
OnRemoteDied(const wptr<IRemoteObject> & remote)630 void AbilitySchedulerRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
631 {
632 HILOG_ERROR("recv AbilitySchedulerRecipient death notice");
633
634 if (handler_) {
635 handler_(remote);
636 }
637 }
638
AbilitySchedulerRecipient(RemoteDiedHandler handler)639 AbilitySchedulerRecipient::AbilitySchedulerRecipient(RemoteDiedHandler handler) : handler_(handler)
640 {}
641
~AbilitySchedulerRecipient()642 AbilitySchedulerRecipient::~AbilitySchedulerRecipient()
643 {}
644 } // namespace AAFwk
645 } // namespace OHOS
646