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