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