• 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 
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 {
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_CALL] = &AbilitySchedulerStub::CallInner;
49     requestFuncMap_[SCHEDULE_GETTYPE] = &AbilitySchedulerStub::GetTypeInner;
50     requestFuncMap_[SCHEDULE_RELOAD] = &AbilitySchedulerStub::ReloadInner;
51     requestFuncMap_[SCHEDULE_BATCHINSERT] = &AbilitySchedulerStub::BatchInsertInner;
52     requestFuncMap_[SCHEDULE_REGISTEROBSERVER] = &AbilitySchedulerStub::RegisterObserverInner;
53     requestFuncMap_[SCHEDULE_UNREGISTEROBSERVER] = &AbilitySchedulerStub::UnregisterObserverInner;
54     requestFuncMap_[SCHEDULE_NOTIFYCHANGE] = &AbilitySchedulerStub::NotifyChangeInner;
55 #ifdef SUPPORT_GRAPHICS
56     requestFuncMap_[MULTI_WIN_CHANGED] = &AbilitySchedulerStub::MutiWinModeChangedInner;
57 #endif
58     requestFuncMap_[SCHEDULE_NORMALIZEURI] = &AbilitySchedulerStub::NormalizeUriInner;
59     requestFuncMap_[SCHEDULE_DENORMALIZEURI] = &AbilitySchedulerStub::DenormalizeUriInner;
60     requestFuncMap_[SCHEDULE_UPDATE_CONFIGURATION] = &AbilitySchedulerStub::UpdateConfigurationInner;
61     requestFuncMap_[SCHEDULE_EXECUTEBATCH] = &AbilitySchedulerStub::ExecuteBatchInner;
62 #ifdef SUPPORT_GRAPHICS
63     requestFuncMap_[TOP_ACTIVE_ABILITY_CHANGED] = &AbilitySchedulerStub::TopActiveAbilityChangedInner;
64 #endif
65     requestFuncMap_[NOTIFY_CONTINUATION_RESULT] = &AbilitySchedulerStub::NotifyContinuationResultInner;
66     requestFuncMap_[REQUEST_CALL_REMOTE] = &AbilitySchedulerStub::CallRequestInner;
67     requestFuncMap_[CONTINUE_ABILITY] = &AbilitySchedulerStub::ContinueAbilityInner;
68     requestFuncMap_[DUMP_ABILITY_RUNNER_INNER] = &AbilitySchedulerStub::DumpAbilityInfoInner;
69 }
70 
~AbilitySchedulerStub()71 AbilitySchedulerStub::~AbilitySchedulerStub()
72 {
73     requestFuncMap_.clear();
74 }
75 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)76 int AbilitySchedulerStub::OnRemoteRequest(
77     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
78 {
79     HILOG_DEBUG("AbilitySchedulerStub::OnRemoteRequest, cmd = %d, flags= %d", code, option.GetFlags());
80     std::u16string descriptor = AbilitySchedulerStub::GetDescriptor();
81     std::u16string remoteDescriptor = data.ReadInterfaceToken();
82     if (descriptor != remoteDescriptor) {
83         HILOG_INFO("local descriptor is not equal to remote");
84         return ERR_INVALID_STATE;
85     }
86 
87     auto itFunc = requestFuncMap_.find(code);
88     if (itFunc != requestFuncMap_.end()) {
89         auto requestFunc = itFunc->second;
90         if (requestFunc != nullptr) {
91             return (this->*requestFunc)(data, reply);
92         }
93     }
94     HILOG_WARN("AbilitySchedulerStub::OnRemoteRequest, default case, need check.");
95     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
96 }
97 
AbilityTransactionInner(MessageParcel & data,MessageParcel & reply)98 int AbilitySchedulerStub::AbilityTransactionInner(MessageParcel &data, MessageParcel &reply)
99 {
100     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
101     if (want == nullptr) {
102         HILOG_ERROR("AbilitySchedulerStub want is nullptr");
103         return ERR_INVALID_VALUE;
104     }
105     std::unique_ptr<LifeCycleStateInfo> stateInfo(data.ReadParcelable<LifeCycleStateInfo>());
106     if (!stateInfo) {
107         HILOG_ERROR("ReadParcelable<LifeCycleStateInfo> failed");
108         return ERR_INVALID_VALUE;
109     }
110     ScheduleAbilityTransaction(*want, *stateInfo);
111     return NO_ERROR;
112 }
113 
SendResultInner(MessageParcel & data,MessageParcel & reply)114 int AbilitySchedulerStub::SendResultInner(MessageParcel &data, MessageParcel &reply)
115 {
116     int requestCode = data.ReadInt32();
117     int resultCode = data.ReadInt32();
118     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
119     if (want == nullptr) {
120         HILOG_ERROR("AbilitySchedulerStub want is nullptr");
121         return ERR_INVALID_VALUE;
122     }
123     SendResult(requestCode, resultCode, *want);
124     return NO_ERROR;
125 }
126 
ConnectAbilityInner(MessageParcel & data,MessageParcel & reply)127 int AbilitySchedulerStub::ConnectAbilityInner(MessageParcel &data, MessageParcel &reply)
128 {
129     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
130     if (want == nullptr) {
131         HILOG_ERROR("AbilitySchedulerStub want is nullptr");
132         return ERR_INVALID_VALUE;
133     }
134     ScheduleConnectAbility(*want);
135     return NO_ERROR;
136 }
137 
DisconnectAbilityInner(MessageParcel & data,MessageParcel & reply)138 int AbilitySchedulerStub::DisconnectAbilityInner(MessageParcel &data, MessageParcel &reply)
139 {
140     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
141     if (want == nullptr) {
142         HILOG_ERROR("AbilitySchedulerStub want is nullptr");
143         return ERR_INVALID_VALUE;
144     }
145     ScheduleDisconnectAbility(*want);
146     return NO_ERROR;
147 }
148 
CommandAbilityInner(MessageParcel & data,MessageParcel & reply)149 int AbilitySchedulerStub::CommandAbilityInner(MessageParcel &data, MessageParcel &reply)
150 {
151     std::shared_ptr<Want> want(data.ReadParcelable<Want>());
152     if (want == nullptr) {
153         HILOG_ERROR("AbilitySchedulerStub want is nullptr");
154         return ERR_INVALID_VALUE;
155     }
156     bool reStart = data.ReadBool();
157     int startId = data.ReadInt32();
158     HILOG_INFO("ReadInt32, startId:%{public}d", startId);
159     ScheduleCommandAbility(*want, reStart, startId);
160     return NO_ERROR;
161 }
162 
SaveAbilityStateInner(MessageParcel & data,MessageParcel & reply)163 int AbilitySchedulerStub::SaveAbilityStateInner(MessageParcel &data, MessageParcel &reply)
164 {
165     ScheduleSaveAbilityState();
166     return NO_ERROR;
167 }
168 
RestoreAbilityStateInner(MessageParcel & data,MessageParcel & reply)169 int AbilitySchedulerStub::RestoreAbilityStateInner(MessageParcel &data, MessageParcel &reply)
170 {
171     std::shared_ptr<PacMap> pacMap(data.ReadParcelable<PacMap>());
172     if (pacMap == nullptr) {
173         HILOG_ERROR("AbilitySchedulerStub RestoreAbilityState is nullptr");
174         return ERR_INVALID_VALUE;
175     }
176     ScheduleRestoreAbilityState(*pacMap);
177     return NO_ERROR;
178 }
179 
GetFileTypesInner(MessageParcel & data,MessageParcel & reply)180 int AbilitySchedulerStub::GetFileTypesInner(MessageParcel &data, MessageParcel &reply)
181 {
182     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
183     if (uri == nullptr) {
184         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
185         return ERR_INVALID_VALUE;
186     }
187     std::string mimeTypeFilter = data.ReadString();
188     if (mimeTypeFilter.empty()) {
189         HILOG_ERROR("AbilitySchedulerStub mimeTypeFilter is nullptr");
190         return ERR_INVALID_VALUE;
191     }
192     std::vector<std::string> types = GetFileTypes(*uri, mimeTypeFilter);
193     if (!reply.WriteStringVector(types)) {
194         HILOG_ERROR("fail to WriteStringVector types");
195         return ERR_INVALID_VALUE;
196     }
197     return NO_ERROR;
198 }
199 
OpenFileInner(MessageParcel & data,MessageParcel & reply)200 int AbilitySchedulerStub::OpenFileInner(MessageParcel &data, MessageParcel &reply)
201 {
202     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
203     if (uri == nullptr) {
204         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
205         return ERR_INVALID_VALUE;
206     }
207     std::string mode = data.ReadString();
208     if (mode.empty()) {
209         HILOG_ERROR("AbilitySchedulerStub mode is nullptr");
210         return ERR_INVALID_VALUE;
211     }
212     int fd = OpenFile(*uri, mode);
213     if (fd < 0) {
214         HILOG_ERROR("OpenFile fail, fd is %{pubilc}d", fd);
215         return ERR_INVALID_VALUE;
216     }
217     if (!reply.WriteFileDescriptor(fd)) {
218         HILOG_ERROR("fail to WriteFileDescriptor fd");
219         return ERR_INVALID_VALUE;
220     }
221     return NO_ERROR;
222 }
223 
OpenRawFileInner(MessageParcel & data,MessageParcel & reply)224 int AbilitySchedulerStub::OpenRawFileInner(MessageParcel &data, MessageParcel &reply)
225 {
226     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
227     if (uri == nullptr) {
228         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
229         return ERR_INVALID_VALUE;
230     }
231     std::string mode = data.ReadString();
232     if (mode.empty()) {
233         HILOG_ERROR("AbilitySchedulerStub mode is nullptr");
234         return ERR_INVALID_VALUE;
235     }
236     int fd = OpenRawFile(*uri, mode);
237     if (!reply.WriteInt32(fd)) {
238         HILOG_ERROR("fail to WriteInt32 fd");
239         return ERR_INVALID_VALUE;
240     }
241     return NO_ERROR;
242 }
243 
InsertInner(MessageParcel & data,MessageParcel & reply)244 int AbilitySchedulerStub::InsertInner(MessageParcel &data, MessageParcel &reply)
245 {
246     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
247     if (uri == nullptr) {
248         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
249         return ERR_INVALID_VALUE;
250     }
251     std::shared_ptr<NativeRdb::ValuesBucket> value(data.ReadParcelable<NativeRdb::ValuesBucket>());
252     if (value == nullptr) {
253         HILOG_ERROR("ReadParcelable value is nullptr");
254         return ERR_INVALID_VALUE;
255     }
256     int index = Insert(*uri, *value);
257     if (!reply.WriteInt32(index)) {
258         HILOG_ERROR("fail to WriteInt32 index");
259         return ERR_INVALID_VALUE;
260     }
261     HILOG_INFO("AbilitySchedulerStub::InsertInner end");
262     return NO_ERROR;
263 }
264 
CallInner(MessageParcel & data,MessageParcel & reply)265 int AbilitySchedulerStub::CallInner(MessageParcel &data, MessageParcel &reply)
266 {
267     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
268     if (uri == nullptr) {
269         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
270         return ERR_INVALID_VALUE;
271     }
272     std::string method = data.ReadString();
273     if (method.empty()) {
274         HILOG_ERROR("ReadParcelable method is nullptr");
275         return ERR_INVALID_VALUE;
276     }
277     std::string arg = data.ReadString();
278     if (arg.empty()) {
279         HILOG_ERROR("ReadParcelable arg is nullptr");
280         return ERR_INVALID_VALUE;
281     }
282 
283     std::shared_ptr<AppExecFwk::PacMap> pacMap(data.ReadParcelable<AppExecFwk::PacMap>());
284     if (pacMap == nullptr) {
285         HILOG_ERROR("ReadParcelable pacMap is nullptr");
286         return ERR_INVALID_VALUE;
287     }
288     std::shared_ptr<AppExecFwk::PacMap> result = Call(*uri, method, arg, *pacMap);
289     if (!reply.WriteParcelable(result.get())) {
290         HILOG_ERROR("fail to WriteParcelable pacMap error");
291         return ERR_INVALID_VALUE;
292     }
293     HILOG_INFO("AbilitySchedulerStub::CallInner end");
294     return NO_ERROR;
295 }
296 
UpdatetInner(MessageParcel & data,MessageParcel & reply)297 int AbilitySchedulerStub::UpdatetInner(MessageParcel &data, MessageParcel &reply)
298 {
299     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
300     if (uri == nullptr) {
301         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
302         return ERR_INVALID_VALUE;
303     }
304     std::shared_ptr<NativeRdb::ValuesBucket> value(data.ReadParcelable<NativeRdb::ValuesBucket>());
305     if (value == nullptr) {
306         HILOG_ERROR("ReadParcelable value is nullptr");
307         return ERR_INVALID_VALUE;
308     }
309     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
310         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
311     if (predicates == nullptr) {
312         HILOG_ERROR("ReadParcelable predicates is nullptr");
313         return ERR_INVALID_VALUE;
314     }
315     int index = Update(*uri, *value, *predicates);
316     if (!reply.WriteInt32(index)) {
317         HILOG_ERROR("fail to WriteInt32 index");
318         return ERR_INVALID_VALUE;
319     }
320     return NO_ERROR;
321 }
322 
DeleteInner(MessageParcel & data,MessageParcel & reply)323 int AbilitySchedulerStub::DeleteInner(MessageParcel &data, MessageParcel &reply)
324 {
325     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
326     if (uri == nullptr) {
327         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
328         return ERR_INVALID_VALUE;
329     }
330     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
331         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
332     if (predicates == nullptr) {
333         HILOG_ERROR("ReadParcelable predicates is nullptr");
334         return ERR_INVALID_VALUE;
335     }
336     int index = Delete(*uri, *predicates);
337     if (!reply.WriteInt32(index)) {
338         HILOG_ERROR("fail to WriteInt32 index");
339         return ERR_INVALID_VALUE;
340     }
341     return NO_ERROR;
342 }
343 
QueryInner(MessageParcel & data,MessageParcel & reply)344 int AbilitySchedulerStub::QueryInner(MessageParcel &data, MessageParcel &reply)
345 {
346     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
347     if (uri == nullptr) {
348         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
349         return ERR_INVALID_VALUE;
350     }
351     std::vector<std::string> columns;
352     if (!data.ReadStringVector(&columns)) {
353         HILOG_ERROR("fail to ReadStringVector columns");
354         return ERR_INVALID_VALUE;
355     }
356     std::shared_ptr<NativeRdb::DataAbilityPredicates> predicates(
357         data.ReadParcelable<NativeRdb::DataAbilityPredicates>());
358     if (predicates == nullptr) {
359         HILOG_ERROR("ReadParcelable predicates is nullptr");
360         return ERR_INVALID_VALUE;
361     }
362     auto resultSet = Query(*uri, columns, *predicates);
363     if (resultSet == nullptr) {
364         HILOG_ERROR("fail to WriteParcelable resultSet");
365         return ERR_INVALID_VALUE;
366     }
367     auto result = NativeRdb::ISharedResultSet::WriteToParcel(std::move(resultSet), reply);
368     if (result == nullptr) {
369         HILOG_ERROR("!resultSet->Marshalling(reply)");
370         return ERR_INVALID_VALUE;
371     }
372     HILOG_INFO("AbilitySchedulerStub::QueryInner end");
373     return NO_ERROR;
374 }
375 
GetTypeInner(MessageParcel & data,MessageParcel & reply)376 int AbilitySchedulerStub::GetTypeInner(MessageParcel &data, MessageParcel &reply)
377 {
378     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
379     if (uri == nullptr) {
380         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
381         return ERR_INVALID_VALUE;
382     }
383     std::string type = GetType(*uri);
384     if (!reply.WriteString(type)) {
385         HILOG_ERROR("fail to WriteString type");
386         return ERR_INVALID_VALUE;
387     }
388     return NO_ERROR;
389 }
390 
ReloadInner(MessageParcel & data,MessageParcel & reply)391 int AbilitySchedulerStub::ReloadInner(MessageParcel &data, MessageParcel &reply)
392 {
393     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
394     if (uri == nullptr) {
395         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
396         return ERR_INVALID_VALUE;
397     }
398 
399     std::shared_ptr<PacMap> extras(data.ReadParcelable<PacMap>());
400     if (extras == nullptr) {
401         HILOG_ERROR("AbilitySchedulerStub extras is nullptr");
402         return ERR_INVALID_VALUE;
403     }
404     bool ret = Reload(*uri, *extras);
405     if (!reply.WriteBool(ret)) {
406         HILOG_ERROR("fail to writeBool ret");
407         return ERR_INVALID_VALUE;
408     }
409     return NO_ERROR;
410 }
411 
BatchInsertInner(MessageParcel & data,MessageParcel & reply)412 int AbilitySchedulerStub::BatchInsertInner(MessageParcel &data, MessageParcel &reply)
413 {
414     std::shared_ptr<Uri> uri(data.ReadParcelable<Uri>());
415     if (uri == nullptr) {
416         HILOG_ERROR("AbilitySchedulerStub uri is nullptr");
417         return ERR_INVALID_VALUE;
418     }
419 
420     int count = 0;
421     if (!data.ReadInt32(count)) {
422         HILOG_ERROR("fail to ReadInt32 index");
423         return ERR_INVALID_VALUE;
424     }
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 
UpdateConfigurationInner(MessageParcel & data,MessageParcel & reply)536 int AbilitySchedulerStub::UpdateConfigurationInner(MessageParcel &data, MessageParcel &reply)
537 {
538     std::shared_ptr<AppExecFwk::Configuration> globalConfiguration(data.ReadParcelable<AppExecFwk::Configuration>());
539     if (globalConfiguration == nullptr) {
540         HILOG_ERROR("AbilitySchedulerStub globalConfiguration is nullptr");
541         return ERR_INVALID_VALUE;
542     }
543     ScheduleUpdateConfiguration(*globalConfiguration);
544     return NO_ERROR;
545 }
546 
547 #ifdef SUPPORT_GRAPHICS
MutiWinModeChangedInner(MessageParcel & data,MessageParcel & reply)548 int AbilitySchedulerStub::MutiWinModeChangedInner(MessageParcel &data, MessageParcel &reply)
549 {
550     int32_t winModeKey = data.ReadInt32();
551     bool flag = data.ReadBool();
552     NotifyMultiWinModeChanged(winModeKey, flag);
553     return NO_ERROR;
554 }
555 
TopActiveAbilityChangedInner(MessageParcel & data,MessageParcel & reply)556 int AbilitySchedulerStub::TopActiveAbilityChangedInner(MessageParcel &data, MessageParcel &reply)
557 {
558     bool flag = data.ReadBool();
559     NotifyTopActiveAbilityChanged(flag);
560     return NO_ERROR;
561 }
562 #endif
563 
ExecuteBatchInner(MessageParcel & data,MessageParcel & reply)564 int AbilitySchedulerStub::ExecuteBatchInner(MessageParcel &data, MessageParcel &reply)
565 {
566     HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner start");
567     int count = 0;
568     if (!data.ReadInt32(count)) {
569         HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner fail to ReadInt32 count");
570         return ERR_INVALID_VALUE;
571     }
572     HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner count:%{public}d", count);
573     std::vector<std::shared_ptr<AppExecFwk::DataAbilityOperation>> operations;
574     for (int i = 0; i < count; i++) {
575         AppExecFwk::DataAbilityOperation *operation = data.ReadParcelable<AppExecFwk::DataAbilityOperation>();
576         if (operation == nullptr) {
577             HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner operation is nullptr, index = %{public}d", i);
578             return ERR_INVALID_VALUE;
579         }
580         std::shared_ptr<AppExecFwk::DataAbilityOperation> dataAbilityOperation(operation);
581         operations.push_back(dataAbilityOperation);
582     }
583 
584     std::vector<std::shared_ptr<AppExecFwk::DataAbilityResult>> results = ExecuteBatch(operations);
585     int total = (int)results.size();
586     if (!reply.WriteInt32(total)) {
587         HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner fail to WriteInt32 ret");
588         return ERR_INVALID_VALUE;
589     }
590     HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner total:%{public}d", total);
591     for (int i = 0; i < total; i++) {
592         if (results[i] == nullptr) {
593             HILOG_ERROR("AbilitySchedulerStub::ExecuteBatchInner results[i] is nullptr, index = %{public}d", i);
594             return ERR_INVALID_VALUE;
595         }
596         if (!reply.WriteParcelable(results[i].get())) {
597             HILOG_ERROR(
598                 "AbilitySchedulerStub::ExecuteBatchInner fail to WriteParcelable operation, index = %{public}d", i);
599             return ERR_INVALID_VALUE;
600         }
601     }
602     HILOG_INFO("AbilitySchedulerStub::ExecuteBatchInner end");
603     return NO_ERROR;
604 }
605 
ContinueAbilityInner(MessageParcel & data,MessageParcel & reply)606 int AbilitySchedulerStub::ContinueAbilityInner(MessageParcel &data, MessageParcel &reply)
607 {
608     std::string deviceId = data.ReadString();
609     ContinueAbility(deviceId);
610     return NO_ERROR;
611 }
612 
NotifyContinuationResultInner(MessageParcel & data,MessageParcel & reply)613 int AbilitySchedulerStub::NotifyContinuationResultInner(MessageParcel &data, MessageParcel &reply)
614 {
615     int32_t result = data.ReadInt32();
616     NotifyContinuationResult(result);
617     return NO_ERROR;
618 }
619 
DumpAbilityInfoInner(MessageParcel & data,MessageParcel & reply)620 int AbilitySchedulerStub::DumpAbilityInfoInner(MessageParcel &data, MessageParcel &reply)
621 {
622     std::vector<std::string> infos;
623     std::vector<std::string> params;
624     if (!data.ReadStringVector(&params)) {
625         HILOG_INFO("DumpAbilityInfoInner read params error");
626         return NO_ERROR;
627     }
628     DumpAbilityInfo(params, infos);
629 
630     for (const auto & infostep:infos) {
631         HILOG_INFO("DumpAbilityInfoInner infos = %{public}s", infostep.c_str());
632     }
633 
634     return NO_ERROR;
635 }
CallRequestInner(MessageParcel & data,MessageParcel & reply)636 int AbilitySchedulerStub::CallRequestInner(MessageParcel &data, MessageParcel &reply)
637 {
638     HILOG_INFO("AbilitySchedulerStub::CallRequestInner start");
639 
640     sptr<IRemoteObject> call = CallRequest();
641     if (!call) {
642         HILOG_ERROR("call request return nullptr.");
643         return ERR_INVALID_VALUE;
644     }
645 
646     if (!reply.WriteInt32(NO_ERROR)) {
647         HILOG_ERROR("GetAllStackInfo result error");
648         return ERR_INVALID_VALUE;
649     }
650 
651     if (!reply.WriteRemoteObject(call)) {
652         HILOG_ERROR("Connect done remote object error.");
653         return ERR_INVALID_VALUE;
654     }
655 
656     HILOG_INFO("AbilitySchedulerStub::CallRequestInner end");
657 
658     return NO_ERROR;
659 }
660 
OnRemoteDied(const wptr<IRemoteObject> & remote)661 void AbilitySchedulerRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
662 {
663     HILOG_ERROR("recv AbilitySchedulerRecipient death notice");
664 
665     if (handler_) {
666         handler_(remote);
667     }
668 }
669 
AbilitySchedulerRecipient(RemoteDiedHandler handler)670 AbilitySchedulerRecipient::AbilitySchedulerRecipient(RemoteDiedHandler handler) : handler_(handler)
671 {}
672 
~AbilitySchedulerRecipient()673 AbilitySchedulerRecipient::~AbilitySchedulerRecipient()
674 {}
675 
676 }  // namespace AAFwk
677 }  // namespace OHOS
678