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