1 /*
2 * Copyright (c) 2023-2025 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_manager_proxy.h"
17
18 #include "ability_scheduler_stub.h"
19 #include "ability_util.h"
20 #include "app_utils.h"
21 #include "freeze_util.h"
22 #include "hitrace_chain_utils.h"
23 #include "hitrace_meter.h"
24 #include "ipc_capacity_wrap.h"
25 #include "server_constant.h"
26 #include "status_bar_delegate_interface.h"
27 #include "mission_listener_interface.h"
28 #include "mission_snapshot.h"
29 #include "snapshot.h"
30 #ifdef SUPPORT_SCREEN
31 #include "pixel_map.h"
32 #endif //SUPPORT_SCREEN
33
34 namespace OHOS {
35 namespace AAFwk {
36 namespace {
37 #define PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(messageParcel, type, value) \
38 do { \
39 if (!(messageParcel).Write##type(value)) { \
40 TAG_LOGE(AAFwkTag::ABILITYMGR, \
41 "failed write %{public}s", #value); \
42 return INNER_ERR; \
43 } \
44 } while (0)
45 }
46 using AutoStartupInfo = AbilityRuntime::AutoStartupInfo;
47 constexpr int32_t CYCLE_LIMIT = 1000;
48 constexpr int32_t INDEX_ONE = 1;
49 constexpr int32_t MAX_AUTO_STARTUP_COUNT = 100;
50 constexpr int32_t MAX_UPDATE_CONFIG_SIZE = 100;
51 constexpr int32_t MAX_WANT_LIST_SIZE = 4;
52 constexpr int32_t MAX_IPC_CAPACITY_FOR_WANT_LIST = 4 * 216 * 1024;
WriteInterfaceToken(MessageParcel & data)53 bool AbilityManagerProxy::WriteInterfaceToken(MessageParcel &data)
54 {
55 if (!data.WriteInterfaceToken(AbilityManagerProxy::GetDescriptor())) {
56 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
57 return false;
58 }
59 return true;
60 }
61
ExtendMaxIpcCapacityForWant(const Want & want,MessageParcel & data)62 bool AbilityManagerProxy::ExtendMaxIpcCapacityForWant(const Want &want, MessageParcel &data)
63 {
64 auto isCallBySCB = want.GetBoolParam(AbilityRuntime::ServerConstant::IS_CALL_BY_SCB, true);
65 TAG_LOGD(AAFwkTag::ABILITYMGR, "isCallBySCB:%{public}d", isCallBySCB);
66 if (!isCallBySCB) {
67 AAFwk::ExtendMaxIpcCapacityForInnerWant(data);
68 return true;
69 }
70 return false;
71 }
72
StartAbility(const Want & want,int32_t userId,int requestCode)73 int AbilityManagerProxy::StartAbility(const Want &want, int32_t userId, int requestCode)
74 {
75 if (AppUtils::GetInstance().IsForbidStart()) {
76 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
77 return INNER_ERR;
78 }
79 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbility", HITRACE_FLAG_INCLUDE_ASYNC);
80 int error;
81 MessageParcel data;
82 MessageParcel reply;
83 MessageOption option;
84
85 if (!WriteInterfaceToken(data)) {
86 return INNER_ERR;
87 }
88 if (!data.WriteParcelable(&want)) {
89 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
90 return INNER_ERR;
91 }
92
93 if (!data.WriteInt32(userId)) {
94 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
95 return INNER_ERR;
96 }
97
98 if (!data.WriteInt32(requestCode)) {
99 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
100 return INNER_ERR;
101 }
102
103 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY, data, reply, option);
104 if (error != NO_ERROR) {
105 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
106 return error;
107 }
108 return reply.ReadInt32();
109 }
110
GetTopAbility(bool isNeedLocalDeviceId)111 AppExecFwk::ElementName AbilityManagerProxy::GetTopAbility(bool isNeedLocalDeviceId)
112 {
113 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
114 MessageParcel data;
115 MessageParcel reply;
116 MessageOption option;
117 if (!WriteInterfaceToken(data)) {
118 return {};
119 }
120 if (!data.WriteBool(isNeedLocalDeviceId)) {
121 return {};
122 }
123
124 int error = SendRequest(AbilityManagerInterfaceCode::GET_TOP_ABILITY, data, reply, option);
125 if (error != NO_ERROR) {
126 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
127 return {};
128 }
129 std::unique_ptr<AppExecFwk::ElementName> name(reply.ReadParcelable<AppExecFwk::ElementName>());
130 if (!name) {
131 TAG_LOGE(AAFwkTag::ABILITYMGR, "read info fail");
132 return {};
133 }
134 AppExecFwk::ElementName result = *name;
135 return result;
136 }
137
GetElementNameByToken(sptr<IRemoteObject> token,bool isNeedLocalDeviceId)138 AppExecFwk::ElementName AbilityManagerProxy::GetElementNameByToken(sptr<IRemoteObject> token,
139 bool isNeedLocalDeviceId)
140 {
141 MessageParcel data;
142 MessageParcel reply;
143 MessageOption option;
144 if (!WriteInterfaceToken(data)) {
145 return {};
146 }
147 if (!data.WriteRemoteObject(token)) {
148 return {};
149 }
150 if (!data.WriteBool(isNeedLocalDeviceId)) {
151 return {};
152 }
153 int error = SendRequest(AbilityManagerInterfaceCode::GET_ELEMENT_NAME_BY_TOKEN, data, reply, option);
154 if (error != NO_ERROR) {
155 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
156 return {};
157 }
158 std::unique_ptr<AppExecFwk::ElementName> name(reply.ReadParcelable<AppExecFwk::ElementName>());
159 if (!name) {
160 TAG_LOGE(AAFwkTag::ABILITYMGR, "read info fail");
161 return {};
162 }
163 AppExecFwk::ElementName result = *name;
164 return result;
165 }
166
StartAbility(const Want & want,const AbilityStartSetting & abilityStartSetting,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)167 int AbilityManagerProxy::StartAbility(const Want &want, const AbilityStartSetting &abilityStartSetting,
168 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
169 {
170 if (AppUtils::GetInstance().IsForbidStart()) {
171 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
172 return INNER_ERR;
173 }
174 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbility", HITRACE_FLAG_INCLUDE_ASYNC);
175 int error;
176 MessageParcel data;
177 MessageParcel reply;
178 MessageOption option;
179 if (!WriteInterfaceToken(data)) {
180 return INNER_ERR;
181 }
182 if (!data.WriteParcelable(&want)) {
183 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
184 return INNER_ERR;
185 }
186 if (!data.WriteParcelable(&abilityStartSetting)) {
187 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityStartSetting write fail");
188 return INNER_ERR;
189 }
190 if (callerToken) {
191 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
192 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write fail");
193 return INNER_ERR;
194 }
195 } else {
196 if (!data.WriteBool(false)) {
197 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
198 return INNER_ERR;
199 }
200 }
201 if (!data.WriteInt32(userId)) {
202 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
203 return INNER_ERR;
204 }
205 if (!data.WriteInt32(requestCode)) {
206 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
207 return INNER_ERR;
208 }
209 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_SETTINGS, data, reply, option);
210 if (error != NO_ERROR) {
211 TAG_LOGE(AAFwkTag::ABILITYMGR, "send request error: %{public}d", error);
212 return error;
213 }
214 return reply.ReadInt32();
215 }
216
StartAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)217 int AbilityManagerProxy::StartAbility(
218 const Want &want, const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
219 {
220 if (AppUtils::GetInstance().IsForbidStart()) {
221 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
222 return INNER_ERR;
223 }
224 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbility", HITRACE_FLAG_INCLUDE_ASYNC);
225 int error;
226 MessageParcel data;
227 MessageParcel reply;
228 MessageOption option;
229
230 if (!WriteInterfaceToken(data)) {
231 return INNER_ERR;
232 }
233 if (!data.WriteParcelable(&want)) {
234 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
235 return INNER_ERR;
236 }
237 if (callerToken) {
238 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
239 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write fail");
240 return INNER_ERR;
241 }
242 } else {
243 if (!data.WriteBool(false)) {
244 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
245 return INNER_ERR;
246 }
247 }
248 if (!data.WriteInt32(userId)) {
249 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
250 return INNER_ERR;
251 }
252 if (!data.WriteInt32(requestCode)) {
253 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
254 return INNER_ERR;
255 }
256 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_ADD_CALLER, data, reply, option);
257 if (error != NO_ERROR) {
258 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
259 return error;
260 }
261 return reply.ReadInt32();
262 }
263
StartAbilityWithSpecifyTokenId(const Want & want,const sptr<IRemoteObject> & callerToken,uint32_t specifyTokenId,int32_t userId,int requestCode)264 int AbilityManagerProxy::StartAbilityWithSpecifyTokenId(
265 const Want &want, const sptr<IRemoteObject> &callerToken, uint32_t specifyTokenId, int32_t userId, int requestCode)
266 {
267 if (AppUtils::GetInstance().IsForbidStart()) {
268 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
269 return INNER_ERR;
270 }
271 int error;
272 MessageParcel data;
273 MessageParcel reply;
274 MessageOption option;
275
276 if (!WriteInterfaceToken(data)) {
277 return INNER_ERR;
278 }
279 if (!data.WriteParcelable(&want)) {
280 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
281 return INNER_ERR;
282 }
283 if (callerToken) {
284 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
285 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write fail");
286 return INNER_ERR;
287 }
288 } else {
289 if (!data.WriteBool(false)) {
290 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
291 return INNER_ERR;
292 }
293 }
294 if (!data.WriteInt32(specifyTokenId)) {
295 TAG_LOGE(AAFwkTag::ABILITYMGR, "specifyTokenId write fail");
296 return INNER_ERR;
297 }
298 if (!data.WriteInt32(userId)) {
299 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
300 return INNER_ERR;
301 }
302 if (!data.WriteInt32(requestCode)) {
303 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
304 return INNER_ERR;
305 }
306 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_WITH_SPECIFY_TOKENID, data, reply, option);
307 if (error != NO_ERROR) {
308 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
309 return error;
310 }
311 return reply.ReadInt32();
312 }
313
StartAbilityByInsightIntent(const Want & want,const sptr<IRemoteObject> & callerToken,uint64_t intentId,int32_t userId)314 int32_t AbilityManagerProxy::StartAbilityByInsightIntent(const Want &want, const sptr<IRemoteObject> &callerToken,
315 uint64_t intentId, int32_t userId)
316 {
317 if (AppUtils::GetInstance().IsForbidStart()) {
318 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
319 return INNER_ERR;
320 }
321 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityByInsightIntent", HITRACE_FLAG_INCLUDE_ASYNC);
322 MessageParcel data;
323 if (callerToken == nullptr) {
324 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid callertoken");
325 return INNER_ERR;
326 }
327
328 if (!WriteInterfaceToken(data)) {
329 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
330 return INNER_ERR;
331 }
332
333 if (!data.WriteParcelable(&want)) {
334 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
335 return INNER_ERR;
336 }
337
338 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
339 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write fail");
340 return INNER_ERR;
341 }
342
343 if (!data.WriteUint64(intentId)) {
344 TAG_LOGE(AAFwkTag::ABILITYMGR, "intentId write fail");
345 return INNER_ERR;
346 }
347
348 if (!data.WriteInt32(userId)) {
349 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
350 return INNER_ERR;
351 }
352
353 MessageParcel reply;
354 MessageOption option;
355 int32_t error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_BY_INSIGHT_INTENT, data, reply, option);
356 if (error != NO_ERROR) {
357 TAG_LOGE(AAFwkTag::ABILITYMGR, "start err:%{public}d", error);
358 return error;
359 }
360 return reply.ReadInt32();
361 }
362
StartAbility(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int32_t userId,int requestCode)363 int AbilityManagerProxy::StartAbility(const Want &want, const StartOptions &startOptions,
364 const sptr<IRemoteObject> &callerToken, int32_t userId, int requestCode)
365 {
366 if (AppUtils::GetInstance().IsForbidStart()) {
367 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
368 return INNER_ERR;
369 }
370 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbility", HITRACE_FLAG_INCLUDE_ASYNC);
371 int error;
372 MessageParcel data;
373 MessageParcel reply;
374 MessageOption option;
375 if (!WriteInterfaceToken(data)) {
376 return INNER_ERR;
377 }
378 if (!data.WriteParcelable(&want)) {
379 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
380 return INNER_ERR;
381 }
382 if (!data.WriteParcelable(&startOptions)) {
383 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeParcelable fail");
384 return INNER_ERR;
385 }
386 if (callerToken) {
387 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
388 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write fail");
389 return INNER_ERR;
390 }
391 } else {
392 if (!data.WriteBool(false)) {
393 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
394 return INNER_ERR;
395 }
396 }
397 if (!data.WriteInt32(userId)) {
398 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
399 return INNER_ERR;
400 }
401 if (!data.WriteInt32(requestCode)) {
402 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
403 return INNER_ERR;
404 }
405 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_OPTIONS, data, reply, option);
406 if (error != NO_ERROR) {
407 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
408 return error;
409 }
410 return reply.ReadInt32();
411 }
412
StartAbilityAsCaller(const Want & want,const sptr<IRemoteObject> & callerToken,sptr<IRemoteObject> asCallerSourceToken,int32_t userId,int requestCode)413 int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const sptr<IRemoteObject> &callerToken,
414 sptr<IRemoteObject> asCallerSourceToken, int32_t userId, int requestCode)
415 {
416 if (AppUtils::GetInstance().IsForbidStart()) {
417 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
418 return INNER_ERR;
419 }
420 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityAsCaller", HITRACE_FLAG_INCLUDE_ASYNC);
421 MessageParcel data;
422 MessageParcel reply;
423 MessageOption option;
424 if (!WriteInterfaceToken(data)) {
425 return INNER_ERR;
426 }
427 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
428 if (callerToken) {
429 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
430 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
431 } else {
432 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
433 }
434 if (asCallerSourceToken) {
435 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
436 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, asCallerSourceToken);
437 } else {
438 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
439 }
440 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
441 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
442 int error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_BY_TOKEN, data, reply, option);
443 if (error != NO_ERROR) {
444 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
445 return error;
446 }
447 return reply.ReadInt32();
448 }
449
StartAbilityAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,sptr<IRemoteObject> asCallerSourceToken,int32_t userId,int requestCode)450 int AbilityManagerProxy::StartAbilityAsCaller(const Want &want, const StartOptions &startOptions,
451 const sptr<IRemoteObject> &callerToken, sptr<IRemoteObject> asCallerSourceToken,
452 int32_t userId, int requestCode)
453 {
454 if (AppUtils::GetInstance().IsForbidStart()) {
455 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
456 return INNER_ERR;
457 }
458 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityAsCaller", HITRACE_FLAG_INCLUDE_ASYNC);
459 int error;
460 MessageParcel data;
461 MessageParcel reply;
462 MessageOption option;
463 if (!WriteInterfaceToken(data)) {
464 return INNER_ERR;
465 }
466 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
467 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &startOptions);
468 if (callerToken) {
469 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
470 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
471 } else {
472 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
473 }
474 if (asCallerSourceToken) {
475 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
476 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, asCallerSourceToken);
477 } else {
478 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
479 }
480 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
481 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
482
483 error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_AS_CALLER_FOR_OPTIONS, data, reply, option);
484 if (error != NO_ERROR) {
485 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
486 return error;
487 }
488 return reply.ReadInt32();
489 }
490
StartAbilityForResultAsCaller(const Want & want,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)491 int AbilityManagerProxy::StartAbilityForResultAsCaller(
492 const Want &want, const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
493 {
494 if (AppUtils::GetInstance().IsForbidStart()) {
495 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
496 return INNER_ERR;
497 }
498 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityForResultAsCaller", HITRACE_FLAG_INCLUDE_ASYNC);
499 MessageParcel data;
500 if (!WriteInterfaceToken(data)) {
501 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
502 return INNER_ERR;
503 }
504 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
505 if (callerToken) {
506 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
507 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
508 } else {
509 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
510 }
511 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
512 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
513 MessageParcel reply;
514 MessageOption option;
515 int error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER, data, reply, option);
516 if (error != NO_ERROR) {
517 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
518 return error;
519 }
520 return reply.ReadInt32();
521 }
522
StartAbilityForResultAsCaller(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,int requestCode,int32_t userId)523 int AbilityManagerProxy::StartAbilityForResultAsCaller(const Want &want, const StartOptions &startOptions,
524 const sptr<IRemoteObject> &callerToken, int requestCode, int32_t userId)
525 {
526 if (AppUtils::GetInstance().IsForbidStart()) {
527 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
528 return INNER_ERR;
529 }
530 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityForResultAsCaller", HITRACE_FLAG_INCLUDE_ASYNC);
531 MessageParcel data;
532 if (!WriteInterfaceToken(data)) {
533 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token failed");
534 return INNER_ERR;
535 }
536 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
537 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &startOptions);
538 if (callerToken) {
539 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
540 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
541 } else {
542 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
543 }
544 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestCode);
545 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
546 MessageParcel reply;
547 MessageOption option;
548 int error =
549 SendRequest(AbilityManagerInterfaceCode::START_ABILITY_FOR_RESULT_AS_CALLER_FOR_OPTIONS, data, reply, option);
550 if (error != NO_ERROR) {
551 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
552 return error;
553 }
554 return reply.ReadInt32();
555 }
556
StartUIAbilities(const std::vector<AAFwk::Want> & wantList,const std::string & requestKey,sptr<IRemoteObject> callerToken)557 ErrCode AbilityManagerProxy::StartUIAbilities(const std::vector<AAFwk::Want> &wantList,
558 const std::string &requestKey, sptr<IRemoteObject> callerToken)
559 {
560 if (AppUtils::GetInstance().IsForbidStart()) {
561 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start abilities");
562 return INNER_ERR;
563 }
564 MessageParcel data;
565 MessageParcel reply;
566 MessageOption option;
567 if (callerToken == nullptr) {
568 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
569 return INVALID_CALLER_TOKEN;
570 }
571 if (!WriteInterfaceToken(data)) {
572 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
573 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
574 }
575
576 int32_t size = static_cast<int32_t>(wantList.size());
577 if (size < INDEX_ONE || size > MAX_WANT_LIST_SIZE) {
578 TAG_LOGE(AAFwkTag::ABILITYMGR, "vector size error");
579 return START_UI_ABILITIES_WANT_LIST_SIZE_ERROR;
580 }
581
582 (data).SetMaxCapacity(MAX_IPC_CAPACITY_FOR_WANT_LIST);
583
584 if (!data.WriteInt32(size)) {
585 TAG_LOGE(AAFwkTag::ABILITYMGR, "write size fail");
586 return ERR_WRITE_INT32_FAILED;
587 }
588 for (const Want &item : wantList) {
589 if (!data.WriteParcelable(&item)) {
590 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail");
591 return ERR_WRITE_WANT;
592 }
593 }
594
595 if (!data.WriteString(requestKey)) {
596 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestKey fail");
597 return ERR_WRITE_STRING_FAILED;
598 }
599
600 if (!data.WriteRemoteObject(callerToken)) {
601 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail");
602 return ERR_WRITE_CALLER_TOKEN_FAILED;
603 }
604
605 auto error = SendRequest(AbilityManagerInterfaceCode::START_UI_ABILITIES, data, reply, option);
606 if (error != NO_ERROR) {
607 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
608 return error;
609 }
610 return reply.ReadInt32();
611 }
612
CheckUISessionParams(MessageParcel & data,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)613 int AbilityManagerProxy::CheckUISessionParams(MessageParcel &data, const sptr<IRemoteObject> &callerToken,
614 const sptr<SessionInfo> &sessionInfo, int32_t userId, int requestCode)
615 {
616 if (callerToken) {
617 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
618 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write fail");
619 return INNER_ERR;
620 }
621 } else {
622 if (!data.WriteBool(false)) {
623 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
624 return INNER_ERR;
625 }
626 }
627 if (sessionInfo) {
628 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
629 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
630 return INNER_ERR;
631 }
632 } else {
633 if (!data.WriteBool(false)) {
634 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
635 return INNER_ERR;
636 }
637 }
638 if (!data.WriteInt32(userId)) {
639 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
640 return INNER_ERR;
641 }
642 if (!data.WriteInt32(requestCode)) {
643 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
644 return INNER_ERR;
645 }
646 return ERR_OK;
647 }
648
StartAbilityByUIContentSession(const Want & want,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)649 int AbilityManagerProxy::StartAbilityByUIContentSession(const Want &want,
650 const sptr<IRemoteObject> &callerToken, const sptr<SessionInfo> &sessionInfo,
651 int32_t userId, int requestCode)
652 {
653 if (AppUtils::GetInstance().IsForbidStart()) {
654 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
655 return INNER_ERR;
656 }
657 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityByUIContentSession", HITRACE_FLAG_INCLUDE_ASYNC);
658 int error;
659 MessageParcel data;
660 MessageParcel reply;
661 MessageOption option;
662 if (!WriteInterfaceToken(data)) {
663 return INNER_ERR;
664 }
665 if (!data.WriteParcelable(&want)) {
666 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
667 return INNER_ERR;
668 }
669 if (CheckUISessionParams(data, callerToken, sessionInfo, userId, requestCode) == INNER_ERR) {
670 return INNER_ERR;
671 }
672 error = SendRequest(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_ADD_CALLER, data, reply, option);
673 if (error != NO_ERROR) {
674 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
675 return error;
676 }
677 return reply.ReadInt32();
678 }
679
StartAbilityByUIContentSession(const Want & want,const StartOptions & startOptions,const sptr<IRemoteObject> & callerToken,const sptr<SessionInfo> & sessionInfo,int32_t userId,int requestCode)680 int AbilityManagerProxy::StartAbilityByUIContentSession(const Want &want, const StartOptions &startOptions,
681 const sptr<IRemoteObject> &callerToken, const sptr<SessionInfo> &sessionInfo,
682 int32_t userId, int requestCode)
683 {
684 if (AppUtils::GetInstance().IsForbidStart()) {
685 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
686 return INNER_ERR;
687 }
688 Ability_MANAGER_HITRACE_CHAIN_NAME("StartAbilityByUIContentSession", HITRACE_FLAG_INCLUDE_ASYNC);
689 int error;
690 MessageParcel data;
691 MessageParcel reply;
692 MessageOption option;
693 if (!WriteInterfaceToken(data)) {
694 return INNER_ERR;
695 }
696 if (!data.WriteParcelable(&want)) {
697 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
698 return INNER_ERR;
699 }
700 if (!data.WriteParcelable(&startOptions)) {
701 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeParcelable fail");
702 return INNER_ERR;
703 }
704 if (CheckUISessionParams(data, callerToken, sessionInfo, userId, requestCode) == INNER_ERR) {
705 return INNER_ERR;
706 }
707 error = SendRequest(AbilityManagerInterfaceCode::START_UI_SESSION_ABILITY_FOR_OPTIONS, data, reply, option);
708 if (error != NO_ERROR) {
709 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
710 return error;
711 }
712 return reply.ReadInt32();
713 }
714
StartAbilityOnlyUIAbility(const Want & want,const sptr<IRemoteObject> & callerToken,uint32_t specifyTokenId)715 int AbilityManagerProxy::StartAbilityOnlyUIAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
716 uint32_t specifyTokenId)
717 {
718 if (AppUtils::GetInstance().IsForbidStart()) {
719 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
720 return INNER_ERR;
721 }
722 MessageParcel data;
723 if (callerToken == nullptr) {
724 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid callertoken");
725 return INNER_ERR;
726 }
727
728 if (!WriteInterfaceToken(data)) {
729 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
730 return INNER_ERR;
731 }
732
733 if (!data.WriteParcelable(&want)) {
734 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
735 return INNER_ERR;
736 }
737
738 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
739 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken and flag write fail");
740 return INNER_ERR;
741 }
742
743 if (!data.WriteUint32(specifyTokenId)) {
744 TAG_LOGE(AAFwkTag::ABILITYMGR, "specifyTokenId write fail");
745 return INNER_ERR;
746 }
747
748 MessageParcel reply;
749 MessageOption option;
750 int32_t error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_ONLY_UI_ABILITY, data, reply, option);
751 if (error != NO_ERROR) {
752 TAG_LOGE(AAFwkTag::ABILITYMGR, "send err:%{public}d", error);
753 return error;
754 }
755 return reply.ReadInt32();
756 }
757
StartExtensionAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,AppExecFwk::ExtensionAbilityType extensionType)758 int32_t AbilityManagerProxy::StartExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
759 int32_t userId, AppExecFwk::ExtensionAbilityType extensionType)
760 {
761 if (AppUtils::GetInstance().IsForbidStart()) {
762 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
763 return INNER_ERR;
764 }
765 Ability_MANAGER_HITRACE_CHAIN_NAME("StartExtensionAbility", HITRACE_FLAG_INCLUDE_ASYNC);
766 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
767 int error;
768 MessageParcel data;
769 MessageParcel reply;
770 MessageOption option;
771 if (!WriteInterfaceToken(data)) {
772 return INNER_ERR;
773 }
774 if (!data.WriteParcelable(&want)) {
775 TAG_LOGE(AAFwkTag::SERVICE_EXT, "want write fail");
776 return INNER_ERR;
777 }
778 if (callerToken) {
779 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
780 TAG_LOGE(AAFwkTag::SERVICE_EXT, "flag and callerToken write fail");
781 return INNER_ERR;
782 }
783 } else {
784 if (!data.WriteBool(false)) {
785 TAG_LOGE(AAFwkTag::SERVICE_EXT, "flag write fail");
786 return INNER_ERR;
787 }
788 }
789 if (!data.WriteInt32(userId)) {
790 TAG_LOGE(AAFwkTag::SERVICE_EXT, "userId write failed");
791 return INNER_ERR;
792 }
793 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
794 TAG_LOGE(AAFwkTag::SERVICE_EXT, "extensionType write failed");
795 return INNER_ERR;
796 }
797 error = SendRequest(AbilityManagerInterfaceCode::START_EXTENSION_ABILITY, data, reply, option);
798 if (error != NO_ERROR) {
799 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
800 return error;
801 }
802 return reply.ReadInt32();
803 }
804
RequestModalUIExtension(const Want & want)805 int AbilityManagerProxy::RequestModalUIExtension(const Want &want)
806 {
807 if (AppUtils::GetInstance().IsForbidStart()) {
808 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
809 return INNER_ERR;
810 }
811 MessageParcel data;
812 if (!WriteInterfaceToken(data)) {
813 return INNER_ERR;
814 }
815 if (!data.WriteParcelable(&want)) {
816 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
817 return INNER_ERR;
818 }
819
820 int error;
821 MessageParcel reply;
822 MessageOption option;
823 error = SendRequest(AbilityManagerInterfaceCode::REQUESET_MODAL_UIEXTENSION, data, reply, option);
824 if (error != NO_ERROR) {
825 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
826 return error;
827 }
828 return reply.ReadInt32();
829 }
830
PreloadUIExtensionAbility(const Want & want,std::string & hostBundleName,int32_t userId,int32_t hostPid)831 int AbilityManagerProxy::PreloadUIExtensionAbility(const Want &want, std::string &hostBundleName,
832 int32_t userId, int32_t hostPid)
833 {
834 if (AppUtils::GetInstance().IsForbidStart()) {
835 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
836 return INNER_ERR;
837 }
838 MessageParcel data;
839 if (!WriteInterfaceToken(data)) {
840 return INNER_ERR;
841 }
842
843 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
844
845 if (!data.WriteString16(Str8ToStr16(hostBundleName))) {
846 TAG_LOGE(AAFwkTag::ABILITYMGR, "hostBundleName write fail");
847 return ERR_INVALID_VALUE;
848 }
849
850 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
851 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, hostPid);
852 int error;
853 MessageParcel reply;
854 MessageOption option;
855 error = SendRequest(AbilityManagerInterfaceCode::PRELOAD_UIEXTENSION_ABILITY, data, reply, option);
856 if (error != NO_ERROR) {
857 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
858 return error;
859 }
860 return reply.ReadInt32();
861 }
862
ChangeAbilityVisibility(sptr<IRemoteObject> token,bool isShow)863 int AbilityManagerProxy::ChangeAbilityVisibility(sptr<IRemoteObject> token, bool isShow)
864 {
865 MessageParcel data;
866 MessageParcel reply;
867 MessageOption option;
868 if (!WriteInterfaceToken(data)) {
869 return ERR_NATIVE_IPC_PARCEL_FAILED;
870 }
871 if (!data.WriteRemoteObject(token)) {
872 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
873 return ERR_NATIVE_IPC_PARCEL_FAILED;
874 }
875 if (!data.WriteBool(isShow)) {
876 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isShow fail");
877 return ERR_NATIVE_IPC_PARCEL_FAILED;
878 }
879 auto error = SendRequest(AbilityManagerInterfaceCode::CHANGE_ABILITY_VISIBILITY, data, reply, option);
880 if (error != NO_ERROR) {
881 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
882 return error;
883 }
884 return reply.ReadInt32();
885 }
886
ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo,bool isShow)887 int AbilityManagerProxy::ChangeUIAbilityVisibilityBySCB(sptr<SessionInfo> sessionInfo, bool isShow)
888 {
889 MessageParcel data;
890 MessageParcel reply;
891 MessageOption option;
892 if (!WriteInterfaceToken(data)) {
893 return ERR_NATIVE_IPC_PARCEL_FAILED;
894 }
895 if (!data.WriteParcelable(sessionInfo)) {
896 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo fail");
897 return ERR_NATIVE_IPC_PARCEL_FAILED;
898 }
899 if (!data.WriteBool(isShow)) {
900 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isShow fail");
901 return ERR_NATIVE_IPC_PARCEL_FAILED;
902 }
903 auto error = SendRequest(AbilityManagerInterfaceCode::CHANGE_UI_ABILITY_VISIBILITY_BY_SCB, data, reply, option);
904 if (error != NO_ERROR) {
905 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
906 return error;
907 }
908 return reply.ReadInt32();
909 }
910
StartUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,int32_t userId)911 int AbilityManagerProxy::StartUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, int32_t userId)
912 {
913 if (AppUtils::GetInstance().IsForbidStart()) {
914 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start uiext");
915 return INNER_ERR;
916 }
917 Ability_MANAGER_HITRACE_CHAIN_NAME("StartUIExtensionAbility", HITRACE_FLAG_INCLUDE_ASYNC);
918 int error;
919 MessageParcel data;
920 MessageParcel reply;
921 MessageOption option;
922 if (!WriteInterfaceToken(data)) {
923 return INNER_ERR;
924 }
925
926 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
927 "connect fail, null extensionSessionInfo");
928 if (extensionSessionInfo) {
929 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
930 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and extensionSessionInfo write fail");
931 return INNER_ERR;
932 }
933 } else {
934 if (!data.WriteBool(false)) {
935 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
936 return INNER_ERR;
937 }
938 }
939
940 if (!data.WriteInt32(userId)) {
941 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write failed");
942 return INNER_ERR;
943 }
944
945 if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::EMBEDDED) {
946 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY_EMBEDDED, data, reply, option);
947 } else if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::MODAL) {
948 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_ABILITY, data, reply, option);
949 } else if (extensionSessionInfo->uiExtensionUsage == UIExtensionUsage::PRE_VIEW_EMBEDDED) {
950 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_PRE_VIEW_EMBEDDED, data, reply, option);
951 } else {
952 error = SendRequest(AbilityManagerInterfaceCode::START_UI_EXTENSION_CONSTRAINED_EMBEDDED, data, reply, option);
953 }
954
955 if (error != NO_ERROR) {
956 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
957 return error;
958 }
959 return reply.ReadInt32();
960 }
961
StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo,bool & isColdStart,uint32_t sceneFlag)962 int AbilityManagerProxy::StartUIAbilityBySCB(sptr<SessionInfo> sessionInfo, bool &isColdStart, uint32_t sceneFlag)
963 {
964 if (AppUtils::GetInstance().IsForbidStart()) {
965 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start by scb");
966 return INNER_ERR;
967 }
968 Ability_MANAGER_HITRACE_CHAIN_NAME("StartUIAbilityBySCB", HITRACE_FLAG_INCLUDE_ASYNC);
969 MessageParcel data;
970 MessageParcel reply;
971 MessageOption option;
972 if (!WriteInterfaceToken(data)) {
973 return INNER_ERR;
974 }
975 if (sessionInfo) {
976 ExtendMaxIpcCapacityForWant(sessionInfo->want, data);
977 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
978 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
979 return INNER_ERR;
980 }
981 } else {
982 if (!data.WriteBool(false)) {
983 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
984 return INNER_ERR;
985 }
986 }
987 if (!data.WriteUint32(sceneFlag)) {
988 TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneFlag write fail");
989 return INNER_ERR;
990 }
991 auto error = SendRequest(AbilityManagerInterfaceCode::START_UI_ABILITY_BY_SCB, data, reply, option);
992 if (error != NO_ERROR) {
993 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
994 return error;
995 }
996 isColdStart = reply.ReadBool();
997 return reply.ReadInt32();
998 }
999
StopExtensionAbility(const Want & want,const sptr<IRemoteObject> & callerToken,int32_t userId,AppExecFwk::ExtensionAbilityType extensionType)1000 int AbilityManagerProxy::StopExtensionAbility(const Want &want, const sptr<IRemoteObject> &callerToken,
1001 int32_t userId, AppExecFwk::ExtensionAbilityType extensionType)
1002 {
1003 if (AppUtils::GetInstance().IsForbidStart()) {
1004 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
1005 return INNER_ERR;
1006 }
1007 int error;
1008 MessageParcel data;
1009 MessageParcel reply;
1010 MessageOption option;
1011 if (!WriteInterfaceToken(data)) {
1012 return INNER_ERR;
1013 }
1014 if (!data.WriteParcelable(&want)) {
1015 TAG_LOGE(AAFwkTag::SERVICE_EXT, "want write fail");
1016 return INNER_ERR;
1017 }
1018 if (callerToken) {
1019 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
1020 TAG_LOGE(AAFwkTag::SERVICE_EXT, "flag and callerToken write fail");
1021 return INNER_ERR;
1022 }
1023 } else {
1024 if (!data.WriteBool(false)) {
1025 TAG_LOGE(AAFwkTag::SERVICE_EXT, "flag write fail");
1026 return INNER_ERR;
1027 }
1028 }
1029 if (!data.WriteInt32(userId)) {
1030 TAG_LOGE(AAFwkTag::SERVICE_EXT, "userId write fail");
1031 return INNER_ERR;
1032 }
1033 if (!data.WriteInt32(static_cast<int32_t>(extensionType))) {
1034 TAG_LOGE(AAFwkTag::SERVICE_EXT, "writeInt32 fail");
1035 return INNER_ERR;
1036 }
1037 error = SendRequest(AbilityManagerInterfaceCode::STOP_EXTENSION_ABILITY, data, reply, option);
1038 if (error != NO_ERROR) {
1039 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
1040 return error;
1041 }
1042 return reply.ReadInt32();
1043 }
1044
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)1045 int AbilityManagerProxy::TerminateAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)
1046 {
1047 return TerminateAbility(token, resultCode, resultWant, true);
1048 }
1049
TerminateAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant,bool flag)1050 int AbilityManagerProxy::TerminateAbility(const sptr<IRemoteObject> &token,
1051 int resultCode, const Want *resultWant, bool flag)
1052 {
1053 Ability_MANAGER_HITRACE_CHAIN_NAME("TerminateAbility", HITRACE_FLAG_INCLUDE_ASYNC);
1054 int error;
1055 MessageParcel data;
1056 MessageParcel reply;
1057 MessageOption option;
1058
1059 if (!WriteInterfaceToken(data)) {
1060 return INNER_ERR;
1061 }
1062 if (token) {
1063 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1064 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and token write fail");
1065 return INNER_ERR;
1066 }
1067 } else {
1068 if (!data.WriteBool(false)) {
1069 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1070 return INNER_ERR;
1071 }
1072 }
1073 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
1074 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1075 return INNER_ERR;
1076 }
1077 if (!data.WriteBool(flag)) {
1078 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write flag fail");
1079 return INNER_ERR;
1080 }
1081 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_ABILITY, data, reply, option);
1082 if (error != NO_ERROR) {
1083 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1084 return error;
1085 }
1086 return reply.ReadInt32();
1087 }
1088
BackToCallerAbilityWithResult(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant,int64_t callerRequestCode)1089 int AbilityManagerProxy::BackToCallerAbilityWithResult(const sptr<IRemoteObject> &token, int resultCode,
1090 const Want *resultWant, int64_t callerRequestCode)
1091 {
1092 int error;
1093 MessageParcel data;
1094 MessageParcel reply;
1095 MessageOption option;
1096
1097 CHECK_POINTER_AND_RETURN_LOG(token, ERR_INVALID_VALUE, "null token");
1098
1099 if (!WriteInterfaceToken(data)) {
1100 return INNER_ERR;
1101 }
1102
1103 if (token) {
1104 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1105 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write fail");
1106 return INNER_ERR;
1107 }
1108 } else {
1109 if (!data.WriteBool(false)) {
1110 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1111 return INNER_ERR;
1112 }
1113 }
1114 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
1115 TAG_LOGE(AAFwkTag::ABILITYMGR, "write resultCode fail");
1116 return INNER_ERR;
1117 }
1118 if (!data.WriteInt64(callerRequestCode)) {
1119 TAG_LOGE(AAFwkTag::ABILITYMGR, "write requestCode fail");
1120 return INNER_ERR;
1121 }
1122 error = SendRequest(AbilityManagerInterfaceCode::BACK_TO_CALLER_UIABILITY, data, reply, option);
1123 if (error != NO_ERROR) {
1124 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1125 return error;
1126 }
1127 return reply.ReadInt32();
1128 }
1129
TerminateUIServiceExtensionAbility(const sptr<IRemoteObject> & token)1130 int32_t AbilityManagerProxy::TerminateUIServiceExtensionAbility(const sptr<IRemoteObject> &token)
1131 {
1132 int error;
1133 MessageParcel data;
1134 MessageParcel reply;
1135 MessageOption option;
1136
1137 if (!WriteInterfaceToken(data)) {
1138 return INNER_ERR;
1139 }
1140 if (token) {
1141 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1142 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and token write fail");
1143 return INNER_ERR;
1144 }
1145 } else {
1146 if (!data.WriteBool(false)) {
1147 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1148 return INNER_ERR;
1149 }
1150 }
1151
1152 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_UI_SERVICE_EXTENSION_ABILITY, data, reply, option);
1153 if (error != NO_ERROR) {
1154 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1155 return error;
1156 }
1157 return reply.ReadInt32();
1158 }
1159
TerminateUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,int resultCode,const Want * resultWant)1160 int AbilityManagerProxy::TerminateUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo, int resultCode,
1161 const Want *resultWant)
1162 {
1163 Ability_MANAGER_HITRACE_CHAIN_NAME("TerminateUIExtensionAbility", HITRACE_FLAG_INCLUDE_ASYNC);
1164 int error;
1165 MessageParcel data;
1166 MessageParcel reply;
1167 MessageOption option;
1168
1169 if (!WriteInterfaceToken(data)) {
1170 return INNER_ERR;
1171 }
1172
1173 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
1174 "connect fail, null extensionSessionInfo");
1175 if (extensionSessionInfo) {
1176 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
1177 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and extensionSessionInfo write fail");
1178 return INNER_ERR;
1179 }
1180 } else {
1181 if (!data.WriteBool(false)) {
1182 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1183 return INNER_ERR;
1184 }
1185 }
1186
1187 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(resultWant)) {
1188 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1189 return INNER_ERR;
1190 }
1191
1192 error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_UI_EXTENSION_ABILITY, data, reply, option);
1193 if (error != NO_ERROR) {
1194 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1195 return error;
1196 }
1197 return reply.ReadInt32();
1198 }
1199
CloseUIExtensionAbilityBySCB(const sptr<IRemoteObject> token)1200 int AbilityManagerProxy::CloseUIExtensionAbilityBySCB(const sptr<IRemoteObject> token)
1201 {
1202 if (token == nullptr) {
1203 TAG_LOGE(AAFwkTag::ABILITYMGR, "input invalid");
1204 return ERR_INVALID_VALUE;
1205 }
1206
1207 MessageParcel data;
1208 if (!WriteInterfaceToken(data)) {
1209 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail");
1210 return INNER_ERR;
1211 }
1212
1213 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1214 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and token fail");
1215 return INNER_ERR;
1216 }
1217
1218 MessageParcel reply;
1219 MessageOption option;
1220 auto error = SendRequest(AbilityManagerInterfaceCode::CLOSE_UI_EXTENSION_ABILITY_BY_SCB, data, reply, option);
1221 if (error != NO_ERROR) {
1222 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1223 return error;
1224 }
1225 return reply.ReadInt32();
1226 }
1227
CloseUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool isUserRequestedExit,uint32_t sceneFlag)1228 int AbilityManagerProxy::CloseUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool isUserRequestedExit,
1229 uint32_t sceneFlag)
1230 {
1231 Ability_MANAGER_HITRACE_CHAIN_NAME("CloseUIAbilityBySCB", HITRACE_FLAG_INCLUDE_ASYNC);
1232 int error;
1233 MessageParcel data;
1234 MessageParcel reply;
1235 MessageOption option;
1236
1237 if (!WriteInterfaceToken(data)) {
1238 return INNER_ERR;
1239 }
1240
1241 if (sessionInfo) {
1242 ExtendMaxIpcCapacityForWant(sessionInfo->want, data);
1243 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
1244 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
1245 return INNER_ERR;
1246 }
1247 } else {
1248 if (!data.WriteBool(false)) {
1249 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1250 return INNER_ERR;
1251 }
1252 }
1253 if (!data.WriteUint32(sceneFlag)) {
1254 TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneFlag write fail");
1255 return INNER_ERR;
1256 }
1257
1258 if (!data.WriteBool(isUserRequestedExit)) {
1259 TAG_LOGE(AAFwkTag::ABILITYMGR, "isUserRequestedExit write fail");
1260 return ERR_IPC_PROXY_WRITE_FAILED;
1261 }
1262 error = SendRequest(AbilityManagerInterfaceCode::CLOSE_UI_ABILITY_BY_SCB, data, reply, option);
1263 if (error != NO_ERROR) {
1264 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1265 return error;
1266 }
1267 return reply.ReadInt32();
1268 }
1269
SendResultToAbility(int32_t requestCode,int32_t resultCode,Want & resultWant)1270 int AbilityManagerProxy::SendResultToAbility(int32_t requestCode, int32_t resultCode, Want& resultWant)
1271 {
1272 int error;
1273 MessageParcel data;
1274 MessageParcel reply;
1275 MessageOption option;
1276
1277 if (!WriteInterfaceToken(data)) {
1278 return INNER_ERR;
1279 }
1280 if (!data.WriteInt32(requestCode)) {
1281 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
1282 return INNER_ERR;
1283 }
1284 if (!data.WriteInt32(resultCode) || !data.WriteParcelable(&resultWant)) {
1285 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1286 return INNER_ERR;
1287 }
1288 error = SendRequest(AbilityManagerInterfaceCode::SEND_RESULT_TO_ABILITY, data, reply, option);
1289 if (error != NO_ERROR) {
1290 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1291 return error;
1292 }
1293 return reply.ReadInt32();
1294 }
1295
MoveAbilityToBackground(const sptr<IRemoteObject> & token)1296 int AbilityManagerProxy::MoveAbilityToBackground(const sptr<IRemoteObject> &token)
1297 {
1298 Ability_MANAGER_HITRACE_CHAIN_NAME("MoveAbilityToBackground", HITRACE_FLAG_INCLUDE_ASYNC);
1299 int error;
1300 MessageParcel data;
1301 MessageParcel reply;
1302 MessageOption option;
1303
1304 if (!WriteInterfaceToken(data)) {
1305 return INNER_ERR;
1306 }
1307 if (token) {
1308 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1309 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and token write fail");
1310 return INNER_ERR;
1311 }
1312 } else {
1313 if (!data.WriteBool(false)) {
1314 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1315 return INNER_ERR;
1316 }
1317 }
1318 error = SendRequest(AbilityManagerInterfaceCode::MOVE_ABILITY_TO_BACKGROUND, data, reply, option);
1319 if (error != NO_ERROR) {
1320 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1321 return error;
1322 }
1323 return reply.ReadInt32();
1324 }
1325
MoveUIAbilityToBackground(const sptr<IRemoteObject> token)1326 int32_t AbilityManagerProxy::MoveUIAbilityToBackground(const sptr<IRemoteObject> token)
1327 {
1328 CHECK_POINTER_AND_RETURN_LOG(token, ERR_INVALID_VALUE, "move fail, null token");
1329 MessageParcel data;
1330 MessageParcel reply;
1331 MessageOption option;
1332
1333 if (!WriteInterfaceToken(data)) {
1334 TAG_LOGE(AAFwkTag::ABILITYMGR, "write Token fail");
1335 return IPC_PROXY_ERR;
1336 }
1337 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, token);
1338 int32_t error = SendRequest(AbilityManagerInterfaceCode::MOVE_UI_ABILITY_TO_BACKGROUND, data, reply, option);
1339 if (error != NO_ERROR) {
1340 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1341 return error;
1342 }
1343 return reply.ReadInt32();
1344 }
1345
CloseAbility(const sptr<IRemoteObject> & token,int resultCode,const Want * resultWant)1346 int AbilityManagerProxy::CloseAbility(const sptr<IRemoteObject> &token, int resultCode, const Want *resultWant)
1347 {
1348 return TerminateAbility(token, resultCode, resultWant, false);
1349 }
1350
ConnectAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t userId)1351 int AbilityManagerProxy::ConnectAbility(
1352 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken, int32_t userId)
1353 {
1354 return ConnectAbilityCommon(want, connect, callerToken, AppExecFwk::ExtensionAbilityType::SERVICE, userId);
1355 }
1356
ConnectAbilityCommon(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,AppExecFwk::ExtensionAbilityType extensionType,int32_t userId,bool isQueryExtensionOnly)1357 int AbilityManagerProxy::ConnectAbilityCommon(
1358 const Want &want, const sptr<IAbilityConnection> &connect, const sptr<IRemoteObject> &callerToken,
1359 AppExecFwk::ExtensionAbilityType extensionType, int32_t userId, bool isQueryExtensionOnly)
1360 {
1361 if (AppUtils::GetInstance().IsForbidStart()) {
1362 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
1363 return INNER_ERR;
1364 }
1365 Ability_MANAGER_HITRACE_CHAIN_NAME("ConnectAbilityCommon", HITRACE_FLAG_INCLUDE_ASYNC);
1366 MessageParcel data;
1367 MessageParcel reply;
1368 MessageOption option;
1369 if (!WriteInterfaceToken(data)) {
1370 return INNER_ERR;
1371 }
1372 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
1373 CHECK_POINTER_AND_RETURN_LOG(connect, ERR_INVALID_VALUE, "fail, null connect");
1374 if (connect->AsObject()) {
1375 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1376 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, connect->AsObject());
1377 } else {
1378 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1379 }
1380 if (callerToken) {
1381 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1382 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
1383 } else {
1384 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1385 }
1386 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
1387 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, static_cast<int32_t>(extensionType));
1388 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, isQueryExtensionOnly);
1389 int error = SendRequest(AbilityManagerInterfaceCode::CONNECT_ABILITY_WITH_TYPE, data, reply, option);
1390 if (error != NO_ERROR) {
1391 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s, request error:%{public}d", __func__, error);
1392 return error;
1393 }
1394 return reply.ReadInt32();
1395 }
1396
ConnectUIExtensionAbility(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<SessionInfo> & sessionInfo,int32_t userId,sptr<UIExtensionAbilityConnectInfo> connectInfo)1397 int AbilityManagerProxy::ConnectUIExtensionAbility(const Want &want, const sptr<IAbilityConnection> &connect,
1398 const sptr<SessionInfo> &sessionInfo, int32_t userId, sptr<UIExtensionAbilityConnectInfo> connectInfo)
1399 {
1400 if (AppUtils::GetInstance().IsForbidStart()) {
1401 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
1402 return INNER_ERR;
1403 }
1404 MessageParcel data;
1405 MessageParcel reply;
1406 MessageOption option;
1407
1408 if (!WriteInterfaceToken(data)) {
1409 return INNER_ERR;
1410 }
1411 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
1412 CHECK_POINTER_AND_RETURN_LOG(connect, ERR_INVALID_VALUE, "connect fail, null connect");
1413 if (connect->AsObject()) {
1414 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1415 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, connect->AsObject());
1416 } else {
1417 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1418 }
1419 CHECK_POINTER_AND_RETURN_LOG(sessionInfo, ERR_INVALID_VALUE, "connect fail, null sessionInfo");
1420 if (sessionInfo) {
1421 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1422 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, sessionInfo);
1423 } else {
1424 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1425 }
1426 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, userId);
1427 if (connectInfo != nullptr) {
1428 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, true);
1429 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, connectInfo);
1430 } else {
1431 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Bool, false);
1432 }
1433
1434 int error = SendRequest(AbilityManagerInterfaceCode::CONNECT_UI_EXTENSION_ABILITY, data, reply, option);
1435 if (error != NO_ERROR) {
1436 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1437 return error;
1438 }
1439 if (connectInfo != nullptr) {
1440 sptr<UIExtensionAbilityConnectInfo> replyInfo = reply.ReadParcelable<UIExtensionAbilityConnectInfo>();
1441 if (replyInfo != nullptr) {
1442 connectInfo->uiExtensionAbilityId = replyInfo->uiExtensionAbilityId;
1443 TAG_LOGD(AAFwkTag::ABILITYMGR, "UIExtensionAbilityId is %{public}d.", connectInfo->uiExtensionAbilityId);
1444 }
1445 }
1446 return reply.ReadInt32();
1447 }
1448
DisconnectAbility(sptr<IAbilityConnection> connect)1449 int AbilityManagerProxy::DisconnectAbility(sptr<IAbilityConnection> connect)
1450 {
1451 Ability_MANAGER_HITRACE_CHAIN_NAME("DisconnectAbility", HITRACE_FLAG_INCLUDE_ASYNC);
1452 int error;
1453 MessageParcel data;
1454 MessageParcel reply;
1455 MessageOption option;
1456 if (connect == nullptr) {
1457 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail, connect null");
1458 return ERR_INVALID_VALUE;
1459 }
1460 if (!WriteInterfaceToken(data)) {
1461 return INNER_ERR;
1462 }
1463 if (!data.WriteRemoteObject(connect->AsObject())) {
1464 TAG_LOGE(AAFwkTag::SERVICE_EXT, "connect write failed");
1465 return ERR_INVALID_VALUE;
1466 }
1467
1468 error = SendRequest(AbilityManagerInterfaceCode::DISCONNECT_ABILITY, data, reply, option);
1469 if (error != NO_ERROR) {
1470 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
1471 return error;
1472 }
1473 return reply.ReadInt32();
1474 }
1475
AcquireDataAbility(const Uri & uri,bool tryBind,const sptr<IRemoteObject> & callerToken)1476 sptr<IAbilityScheduler> AbilityManagerProxy::AcquireDataAbility(
1477 const Uri &uri, bool tryBind, const sptr<IRemoteObject> &callerToken)
1478 {
1479 if (AppUtils::GetInstance().IsForbidStart()) {
1480 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start acquire data");
1481 return nullptr;
1482 }
1483 int error;
1484 MessageParcel data;
1485 MessageParcel reply;
1486 MessageOption option;
1487
1488 if (!callerToken) {
1489 TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid parameters");
1490 return nullptr;
1491 }
1492 if (!WriteInterfaceToken(data)) {
1493 return nullptr;
1494 }
1495 if (!data.WriteString(uri.ToString()) || !data.WriteBool(tryBind) || !data.WriteRemoteObject(callerToken)) {
1496 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1497 return nullptr;
1498 }
1499
1500 error = SendRequest(AbilityManagerInterfaceCode::ACQUIRE_DATA_ABILITY, data, reply, option);
1501 if (error != NO_ERROR) {
1502 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1503 return nullptr;
1504 }
1505
1506 return iface_cast<IAbilityScheduler>(reply.ReadRemoteObject());
1507 }
1508
ReleaseDataAbility(sptr<IAbilityScheduler> dataAbilityScheduler,const sptr<IRemoteObject> & callerToken)1509 int AbilityManagerProxy::ReleaseDataAbility(
1510 sptr<IAbilityScheduler> dataAbilityScheduler, const sptr<IRemoteObject> &callerToken)
1511 {
1512 int error;
1513 MessageParcel data;
1514 MessageParcel reply;
1515 MessageOption option;
1516
1517 if (!dataAbilityScheduler || !callerToken) {
1518 return ERR_INVALID_VALUE;
1519 }
1520 if (!WriteInterfaceToken(data)) {
1521 return INNER_ERR;
1522 }
1523 if (!data.WriteRemoteObject(dataAbilityScheduler->AsObject()) || !data.WriteRemoteObject(callerToken)) {
1524 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1525 return INNER_ERR;
1526 }
1527
1528 error = SendRequest(AbilityManagerInterfaceCode::RELEASE_DATA_ABILITY, data, reply, option);
1529 if (error != NO_ERROR) {
1530 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1531 return error;
1532 }
1533 return reply.ReadInt32();
1534 }
1535
AttachAbilityThread(const sptr<IAbilityScheduler> & scheduler,const sptr<IRemoteObject> & token)1536 int AbilityManagerProxy::AttachAbilityThread(const sptr<IAbilityScheduler> &scheduler, const sptr<IRemoteObject> &token)
1537 {
1538 int error;
1539 MessageParcel data;
1540 MessageParcel reply;
1541 MessageOption option;
1542 if (scheduler == nullptr) {
1543 return ERR_INVALID_VALUE;
1544 }
1545 if (!WriteInterfaceToken(data)) {
1546 return INNER_ERR;
1547 }
1548 if (!data.WriteRemoteObject(scheduler->AsObject()) || !data.WriteRemoteObject(token)) {
1549 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1550 return ERR_INVALID_VALUE;
1551 }
1552
1553 error = SendRequest(AbilityManagerInterfaceCode::ATTACH_ABILITY_THREAD, data, reply, option);
1554 if (error != NO_ERROR) {
1555 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1556 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
1557 std::string("AttachAbilityThread; ipc error ") + std::to_string(error));
1558 return error;
1559 }
1560 return reply.ReadInt32();
1561 }
1562
AbilityTransitionDone(const sptr<IRemoteObject> & token,int state,const PacMap & saveData)1563 int AbilityManagerProxy::AbilityTransitionDone(const sptr<IRemoteObject> &token, int state, const PacMap &saveData)
1564 {
1565 int error;
1566 MessageParcel data;
1567 MessageParcel reply;
1568 MessageOption option;
1569
1570 if (!WriteInterfaceToken(data)) {
1571 return INNER_ERR;
1572 }
1573 if (!data.WriteRemoteObject(token) || !data.WriteInt32(state)) {
1574 TAG_LOGE(AAFwkTag::ABILITYMGR, "token or state write fail");
1575 return ERR_INVALID_VALUE;
1576 }
1577 if (!data.WriteParcelable(&saveData)) {
1578 TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write fail");
1579 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
1580 "AbilityTransitionDone; write saveData failed");
1581 return INNER_ERR;
1582 }
1583
1584 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_TRANSITION_DONE, data, reply, option);
1585 if (error != NO_ERROR) {
1586 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1587 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
1588 std::string("AbilityTransitionDone; ipc error ") + std::to_string(error));
1589 return error;
1590 }
1591 return reply.ReadInt32();
1592 }
1593
AbilityWindowConfigTransitionDone(const sptr<IRemoteObject> & token,const WindowConfig & windowConfig)1594 int AbilityManagerProxy::AbilityWindowConfigTransitionDone(
1595 const sptr<IRemoteObject> &token, const WindowConfig &windowConfig)
1596 {
1597 int error;
1598 MessageParcel data;
1599 MessageParcel reply;
1600 MessageOption option(MessageOption::TF_ASYNC);
1601
1602 if (!WriteInterfaceToken(data)) {
1603 return INNER_ERR;
1604 }
1605 if (!data.WriteRemoteObject(token)) {
1606 TAG_LOGE(AAFwkTag::ABILITYMGR, "token or state write fail");
1607 return ERR_INVALID_VALUE;
1608 }
1609 if (!data.WriteParcelable(&windowConfig)) {
1610 TAG_LOGE(AAFwkTag::ABILITYMGR, "saveData write fail");
1611 return INNER_ERR;
1612 }
1613
1614 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_WINDOW_CONFIG_TRANSITION_DONE, data, reply, option);
1615 if (error != NO_ERROR) {
1616 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1617 return error;
1618 }
1619 return reply.ReadInt32();
1620 }
1621
ScheduleConnectAbilityDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & remoteObject)1622 int AbilityManagerProxy::ScheduleConnectAbilityDone(
1623 const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &remoteObject)
1624 {
1625 int error;
1626 MessageParcel data;
1627 MessageParcel reply;
1628 MessageOption option;
1629
1630 if (!WriteInterfaceToken(data)) {
1631 return INNER_ERR;
1632 }
1633
1634 if (token) {
1635 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1636 TAG_LOGE(AAFwkTag::SERVICE_EXT, "write flag and token fail");
1637 return ERR_INVALID_VALUE;
1638 }
1639 } else {
1640 if (!data.WriteBool(false)) {
1641 TAG_LOGE(AAFwkTag::SERVICE_EXT, "write flag fail");
1642 return ERR_INVALID_VALUE;
1643 }
1644 }
1645
1646 if (remoteObject) {
1647 if (!data.WriteBool(true) || !data.WriteRemoteObject(remoteObject)) {
1648 TAG_LOGE(AAFwkTag::SERVICE_EXT, "write flag and remoteObject fail");
1649 return ERR_INVALID_VALUE;
1650 }
1651 } else {
1652 if (!data.WriteBool(false)) {
1653 TAG_LOGE(AAFwkTag::SERVICE_EXT, "write flag fail");
1654 return ERR_INVALID_VALUE;
1655 }
1656 }
1657
1658 error = SendRequest(AbilityManagerInterfaceCode::CONNECT_ABILITY_DONE, data, reply, option);
1659 if (error != NO_ERROR) {
1660 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
1661 AbilityRuntime::FreezeUtil::GetInstance().AppendLifecycleEvent(token,
1662 std::string("AbilityManagerProxy::ScheduleConnectAbilityDone; ipc error ") + std::to_string(error));
1663 return error;
1664 }
1665 return reply.ReadInt32();
1666 }
1667
ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> & token)1668 int AbilityManagerProxy::ScheduleDisconnectAbilityDone(const sptr<IRemoteObject> &token)
1669 {
1670 int error;
1671 MessageParcel data;
1672 MessageParcel reply;
1673 MessageOption option;
1674
1675 if (!WriteInterfaceToken(data)) {
1676 return INNER_ERR;
1677 }
1678 if (!data.WriteRemoteObject(token)) {
1679 TAG_LOGE(AAFwkTag::SERVICE_EXT, "token write failed.");
1680 return ERR_INVALID_VALUE;
1681 }
1682
1683 error = SendRequest(AbilityManagerInterfaceCode::DISCONNECT_ABILITY_DONE, data, reply, option);
1684 if (error != NO_ERROR) {
1685 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
1686 return error;
1687 }
1688 return reply.ReadInt32();
1689 }
1690
ScheduleCommandAbilityDone(const sptr<IRemoteObject> & token)1691 int AbilityManagerProxy::ScheduleCommandAbilityDone(const sptr<IRemoteObject> &token)
1692 {
1693 int error;
1694 MessageParcel data;
1695 MessageParcel reply;
1696 MessageOption option;
1697
1698 if (!WriteInterfaceToken(data)) {
1699 return INNER_ERR;
1700 }
1701 if (!data.WriteRemoteObject(token)) {
1702 TAG_LOGE(AAFwkTag::SERVICE_EXT, "token write fail");
1703 return ERR_INVALID_VALUE;
1704 }
1705
1706 error = SendRequest(AbilityManagerInterfaceCode::COMMAND_ABILITY_DONE, data, reply, option);
1707 if (error != NO_ERROR) {
1708 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
1709 return error;
1710 }
1711 return reply.ReadInt32();
1712 }
1713
ScheduleCommandAbilityWindowDone(const sptr<IRemoteObject> & token,const sptr<SessionInfo> & sessionInfo,WindowCommand winCmd,AbilityCommand abilityCmd)1714 int AbilityManagerProxy::ScheduleCommandAbilityWindowDone(
1715 const sptr<IRemoteObject> &token,
1716 const sptr<SessionInfo> &sessionInfo,
1717 WindowCommand winCmd,
1718 AbilityCommand abilityCmd)
1719 {
1720 int error;
1721 MessageParcel data;
1722 MessageParcel reply;
1723 MessageOption option;
1724
1725 if (!WriteInterfaceToken(data)) {
1726 return INNER_ERR;
1727 }
1728 if (!data.WriteRemoteObject(token)) {
1729 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write fail");
1730 return ERR_INVALID_VALUE;
1731 }
1732 if (!data.WriteParcelable(sessionInfo)) {
1733 TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionInfo write fail");
1734 return ERR_INVALID_VALUE;
1735 }
1736 if (!data.WriteInt32(winCmd)) {
1737 TAG_LOGE(AAFwkTag::ABILITYMGR, "winCmd write fail");
1738 return ERR_INVALID_VALUE;
1739 }
1740 if (!data.WriteInt32(abilityCmd)) {
1741 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityCmd write fail");
1742 return ERR_INVALID_VALUE;
1743 }
1744
1745 error = SendRequest(AbilityManagerInterfaceCode::COMMAND_ABILITY_WINDOW_DONE, data, reply, option);
1746 if (error != NO_ERROR) {
1747 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1748 return error;
1749 }
1750 return reply.ReadInt32();
1751 }
1752
DumpSysState(const std::string & args,std::vector<std::string> & state,bool isClient,bool isUserId,int UserId)1753 void AbilityManagerProxy::DumpSysState(
1754 const std::string& args, std::vector<std::string>& state, bool isClient, bool isUserId, int UserId)
1755 {
1756 int error;
1757 MessageParcel data;
1758 MessageParcel reply;
1759 MessageOption option;
1760
1761 if (!WriteInterfaceToken(data)) {
1762 return;
1763 }
1764 data.WriteString16(Str8ToStr16(args));
1765
1766 if (!data.WriteBool(isClient)) {
1767 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1768 return ;
1769 }
1770 if (!data.WriteBool(isUserId)) {
1771 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1772 return ;
1773 }
1774 if (!data.WriteInt32(UserId)) {
1775 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1776 return ;
1777 }
1778
1779 error = SendRequest(AbilityManagerInterfaceCode::DUMPSYS_STATE, data, reply, option);
1780 if (error != NO_ERROR) {
1781 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1782 return;
1783 }
1784 int32_t stackNum = reply.ReadInt32();
1785 for (int i = 0; i < stackNum; i++) {
1786 std::string stac = Str16ToStr8(reply.ReadString16());
1787 state.emplace_back(stac);
1788 }
1789 }
1790
DumpState(const std::string & args,std::vector<std::string> & state)1791 void AbilityManagerProxy::DumpState(const std::string &args, std::vector<std::string> &state)
1792 {
1793 int error;
1794 MessageParcel data;
1795 MessageParcel reply;
1796 MessageOption option;
1797
1798 if (!WriteInterfaceToken(data)) {
1799 return;
1800 }
1801 data.WriteString16(Str8ToStr16(args));
1802
1803 error = SendRequest(AbilityManagerInterfaceCode::DUMP_STATE, data, reply, option);
1804 if (error != NO_ERROR) {
1805 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1806 return;
1807 }
1808 int32_t stackNum = reply.ReadInt32();
1809 for (int i = 0; i < stackNum; i++) {
1810 std::string stac = Str16ToStr8(reply.ReadString16());
1811 state.emplace_back(stac);
1812 }
1813 }
1814
MinimizeAbility(const sptr<IRemoteObject> & token,bool fromUser)1815 int AbilityManagerProxy::MinimizeAbility(const sptr<IRemoteObject> &token, bool fromUser)
1816 {
1817 Ability_MANAGER_HITRACE_CHAIN_NAME("MinimizeAbility", HITRACE_FLAG_INCLUDE_ASYNC);
1818 int error;
1819 MessageParcel data;
1820 MessageParcel reply;
1821 MessageOption option;
1822
1823 if (!WriteInterfaceToken(data)) {
1824 return INNER_ERR;
1825 }
1826 if (!data.WriteRemoteObject(token)) {
1827 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write fail");
1828 return ERR_INVALID_VALUE;
1829 }
1830 if (!data.WriteBool(fromUser)) {
1831 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1832 return ERR_INVALID_VALUE;
1833 }
1834
1835 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_ABILITY, data, reply, option);
1836 if (error != NO_ERROR) {
1837 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1838 return error;
1839 }
1840 return reply.ReadInt32();
1841 }
1842
MinimizeUIExtensionAbility(const sptr<SessionInfo> & extensionSessionInfo,bool fromUser)1843 int AbilityManagerProxy::MinimizeUIExtensionAbility(const sptr<SessionInfo> &extensionSessionInfo,
1844 bool fromUser)
1845 {
1846 Ability_MANAGER_HITRACE_CHAIN_NAME("MinimizeUIExtensionAbility", HITRACE_FLAG_INCLUDE_ASYNC);
1847 int error;
1848 MessageParcel data;
1849 MessageParcel reply;
1850 MessageOption option;
1851
1852 if (!WriteInterfaceToken(data)) {
1853 return INNER_ERR;
1854 }
1855 CHECK_POINTER_AND_RETURN_LOG(extensionSessionInfo, ERR_INVALID_VALUE,
1856 "connect fail, null extensionSessionInfo");
1857 if (extensionSessionInfo) {
1858 if (!data.WriteBool(true) || !data.WriteParcelable(extensionSessionInfo)) {
1859 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and extensionSessionInfo write fail");
1860 return INNER_ERR;
1861 }
1862 } else {
1863 if (!data.WriteBool(false)) {
1864 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1865 return INNER_ERR;
1866 }
1867 }
1868 if (!data.WriteBool(fromUser)) {
1869 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
1870 return ERR_INVALID_VALUE;
1871 }
1872
1873 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_UI_EXTENSION_ABILITY, data, reply, option);
1874 if (error != NO_ERROR) {
1875 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1876 return error;
1877 }
1878 return reply.ReadInt32();
1879 }
1880
MinimizeUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool fromUser,uint32_t sceneFlag)1881 int AbilityManagerProxy::MinimizeUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool fromUser, uint32_t sceneFlag)
1882 {
1883 int error;
1884 MessageParcel data;
1885 MessageParcel reply;
1886 MessageOption option;
1887
1888 if (!WriteInterfaceToken(data)) {
1889 return INNER_ERR;
1890 }
1891 if (sessionInfo) {
1892 ExtendMaxIpcCapacityForWant(sessionInfo->want, data);
1893 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
1894 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
1895 return INNER_ERR;
1896 }
1897 } else {
1898 if (!data.WriteBool(false)) {
1899 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
1900 return INNER_ERR;
1901 }
1902 }
1903 if (!data.WriteBool(fromUser)) {
1904 TAG_LOGE(AAFwkTag::ABILITYMGR, "fromUser write fail");
1905 return INNER_ERR;
1906 }
1907 if (!data.WriteUint32(sceneFlag)) {
1908 TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneFlag write fail");
1909 return INNER_ERR;
1910 }
1911
1912 error = SendRequest(AbilityManagerInterfaceCode::MINIMIZE_UI_ABILITY_BY_SCB, data, reply, option);
1913 if (error != NO_ERROR) {
1914 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1915 return error;
1916 }
1917 return reply.ReadInt32();
1918 }
1919
StopServiceAbility(const Want & want,int32_t userId,const sptr<IRemoteObject> & token)1920 int AbilityManagerProxy::StopServiceAbility(const Want &want, int32_t userId, const sptr<IRemoteObject> &token)
1921 {
1922 int error;
1923 MessageParcel data;
1924 MessageParcel reply;
1925 MessageOption option;
1926
1927 if (!WriteInterfaceToken(data)) {
1928 return INNER_ERR;
1929 }
1930 if (!data.WriteParcelable(&want)) {
1931 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
1932 return INNER_ERR;
1933 }
1934 if (!data.WriteInt32(userId)) {
1935 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
1936 return INNER_ERR;
1937 }
1938 if (token) {
1939 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
1940 TAG_LOGE(AAFwkTag::ABILITYMGR, "failedwrite flag and token fail");
1941 return ERR_INVALID_VALUE;
1942 }
1943 } else {
1944 if (!data.WriteBool(false)) {
1945 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
1946 return ERR_INVALID_VALUE;
1947 }
1948 }
1949 error = SendRequest(AbilityManagerInterfaceCode::STOP_SERVICE_ABILITY, data, reply, option);
1950 if (error != NO_ERROR) {
1951 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
1952 return error;
1953 }
1954 return reply.ReadInt32();
1955 }
1956
1957 template <typename T>
GetParcelableInfos(MessageParcel & reply,std::vector<T> & parcelableInfos)1958 int AbilityManagerProxy::GetParcelableInfos(MessageParcel &reply, std::vector<T> &parcelableInfos)
1959 {
1960 int32_t infoSize = reply.ReadInt32();
1961 if (infoSize > CYCLE_LIMIT) {
1962 TAG_LOGE(AAFwkTag::ABILITYMGR, "infoSize large");
1963 return ERR_INVALID_VALUE;
1964 }
1965
1966 for (int32_t i = 0; i < infoSize; i++) {
1967 std::unique_ptr<T> info(reply.ReadParcelable<T>());
1968 if (!info) {
1969 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelableInfos fail");
1970 return ERR_INVALID_VALUE;
1971 }
1972 parcelableInfos.emplace_back(*info);
1973 }
1974 return NO_ERROR;
1975 }
1976
GetMissionSnapshot(const std::string & deviceId,int32_t missionId,MissionSnapshot & snapshot,bool isLowResolution)1977 int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t missionId,
1978 MissionSnapshot& snapshot, bool isLowResolution)
1979 {
1980 int error;
1981 MessageParcel data;
1982 MessageParcel reply;
1983 MessageOption option;
1984
1985 if (!WriteInterfaceToken(data)) {
1986 return INNER_ERR;
1987 }
1988 if (!data.WriteString(deviceId)) {
1989 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write fail");
1990 return INNER_ERR;
1991 }
1992 if (!data.WriteInt32(missionId)) {
1993 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
1994 return ERR_INVALID_VALUE;
1995 }
1996 if (!data.WriteBool(isLowResolution)) {
1997 TAG_LOGE(AAFwkTag::ABILITYMGR, "isLowResolution write fail");
1998 return ERR_INVALID_VALUE;
1999 }
2000 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_SNAPSHOT_INFO, data, reply, option);
2001 if (error != NO_ERROR) {
2002 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2003 return error;
2004 }
2005 std::unique_ptr<MissionSnapshot> info(reply.ReadParcelable<MissionSnapshot>());
2006 if (!info) {
2007 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelableInfo fail");
2008 auto errorCode = reply.ReadInt32();
2009 return errorCode ? errorCode : ERR_UNKNOWN_OBJECT;
2010 }
2011 snapshot = *info;
2012 return reply.ReadInt32();
2013 }
2014 #ifdef SUPPORT_SCREEN
UpdateMissionSnapShot(const sptr<IRemoteObject> & token,const std::shared_ptr<Media::PixelMap> & pixelMap)2015 void AbilityManagerProxy::UpdateMissionSnapShot(const sptr<IRemoteObject> &token,
2016 const std::shared_ptr<Media::PixelMap> &pixelMap)
2017 {
2018 MessageParcel data;
2019 MessageParcel reply;
2020 MessageOption option(MessageOption::TF_ASYNC);
2021
2022 if (!WriteInterfaceToken(data)) {
2023 return;
2024 }
2025 if (!data.WriteRemoteObject(token)) {
2026 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
2027 return;
2028 }
2029 if (!data.WriteParcelable(pixelMap.get())) {
2030 TAG_LOGE(AAFwkTag::ABILITYMGR, "write pixelMap fail");
2031 return;
2032 }
2033 auto error = SendRequest(AbilityManagerInterfaceCode::UPDATE_MISSION_SNAPSHOT_FROM_WMS,
2034 data, reply, option);
2035 if (error != NO_ERROR) {
2036 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2037 }
2038 }
2039 #endif // SUPPORT_SCREEN
EnableRecoverAbility(const sptr<IRemoteObject> & token)2040 void AbilityManagerProxy::EnableRecoverAbility(const sptr<IRemoteObject>& token)
2041 {
2042 int error;
2043 MessageParcel data;
2044 MessageParcel reply;
2045 MessageOption option(MessageOption::TF_ASYNC);
2046
2047 if (!WriteInterfaceToken(data)) {
2048 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
2049 return;
2050 }
2051
2052 if (!data.WriteRemoteObject(token)) {
2053 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeRemoteObject fail");
2054 return;
2055 }
2056
2057 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY_ENABLE, data, reply, option);
2058 if (error != NO_ERROR) {
2059 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2060 return;
2061 }
2062 return;
2063 }
2064
ScheduleRecoverAbility(const sptr<IRemoteObject> & token,int32_t reason,const Want * want)2065 void AbilityManagerProxy::ScheduleRecoverAbility(const sptr<IRemoteObject>& token, int32_t reason, const Want *want)
2066 {
2067 int error;
2068 MessageParcel data;
2069 MessageParcel reply;
2070 MessageOption option(MessageOption::TF_ASYNC);
2071
2072 if (!WriteInterfaceToken(data)) {
2073 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
2074 return;
2075 }
2076
2077 if (!data.WriteRemoteObject(token)) {
2078 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeRemoteObject fail");
2079 return;
2080 }
2081
2082 data.WriteInt32(reason);
2083
2084 if (!data.WriteParcelable(want)) {
2085 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail");
2086 return;
2087 }
2088
2089 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY, data, reply, option);
2090 if (error != NO_ERROR) {
2091 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2092 return;
2093 }
2094 return;
2095 }
2096
SubmitSaveRecoveryInfo(const sptr<IRemoteObject> & token)2097 void AbilityManagerProxy::SubmitSaveRecoveryInfo(const sptr<IRemoteObject>& token)
2098 {
2099 int error;
2100 MessageParcel data;
2101 MessageParcel reply;
2102 MessageOption option(MessageOption::TF_ASYNC);
2103
2104 if (!WriteInterfaceToken(data)) {
2105 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
2106 return;
2107 }
2108
2109 if (!data.WriteRemoteObject(token)) {
2110 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeRemoteObject fail");
2111 return;
2112 }
2113
2114 error = SendRequest(AbilityManagerInterfaceCode::ABILITY_RECOVERY_SUBMITINFO, data, reply, option);
2115 if (error != NO_ERROR) {
2116 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2117 return;
2118 }
2119 return;
2120 }
2121
KillProcess(const std::string & bundleName,bool clearPageStack,int32_t appIndex)2122 int AbilityManagerProxy::KillProcess(const std::string &bundleName, bool clearPageStack, int32_t appIndex)
2123 {
2124 MessageParcel data;
2125 MessageParcel reply;
2126 MessageOption option;
2127
2128 if (!WriteInterfaceToken(data)) {
2129 return INNER_ERR;
2130 }
2131 if (!data.WriteString16(Str8ToStr16(bundleName))) {
2132 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
2133 return ERR_INVALID_VALUE;
2134 }
2135 if (!data.WriteBool(clearPageStack)) {
2136 TAG_LOGE(AAFwkTag::ABILITYMGR, "clearPageStack write fail");
2137 return ERR_INVALID_VALUE;
2138 }
2139 if (!data.WriteInt32(appIndex)) {
2140 TAG_LOGE(AAFwkTag::ABILITYMGR, "appIndex write fail");
2141 return ERR_INVALID_VALUE;
2142 }
2143 int error = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS, data, reply, option);
2144 if (error != NO_ERROR) {
2145 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2146 return error;
2147 }
2148 return reply.ReadInt32();
2149 }
2150
ScheduleClearRecoveryPageStack()2151 void AbilityManagerProxy::ScheduleClearRecoveryPageStack()
2152 {
2153 MessageParcel data;
2154 MessageParcel reply;
2155 MessageOption option;
2156
2157 if (!WriteInterfaceToken(data)) {
2158 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
2159 return;
2160 }
2161
2162 int error = SendRequest(AbilityManagerInterfaceCode::CLEAR_RECOVERY_PAGE_STACK, data, reply, option);
2163 if (error != NO_ERROR) {
2164 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2165 return;
2166 }
2167 return;
2168 }
2169
2170 #ifdef ABILITY_COMMAND_FOR_TEST
ForceTimeoutForTest(const std::string & abilityName,const std::string & state)2171 int AbilityManagerProxy::ForceTimeoutForTest(const std::string &abilityName, const std::string &state)
2172 {
2173 MessageParcel data;
2174 MessageParcel reply;
2175 MessageOption option;
2176
2177 if (!WriteInterfaceToken(data)) {
2178 return INNER_ERR;
2179 }
2180 if (!data.WriteString16(Str8ToStr16(abilityName))) {
2181 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityName write fail");
2182 return ERR_INVALID_VALUE;
2183 }
2184 if (!data.WriteString16(Str8ToStr16(state))) {
2185 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityName write fail");
2186 return ERR_INVALID_VALUE;
2187 }
2188 int error = SendRequest(AbilityManagerInterfaceCode::FORCE_TIMEOUT, data, reply, option);
2189 if (error != NO_ERROR) {
2190 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2191 return error;
2192 }
2193 return reply.ReadInt32();
2194 }
2195 #endif
2196
UninstallApp(const std::string & bundleName,int32_t uid)2197 int AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid)
2198 {
2199 return UninstallApp(bundleName, uid, 0);
2200 }
2201
UninstallApp(const std::string & bundleName,int32_t uid,int32_t appIndex)2202 int32_t AbilityManagerProxy::UninstallApp(const std::string &bundleName, int32_t uid, int32_t appIndex)
2203 {
2204 MessageParcel data;
2205 MessageParcel reply;
2206 MessageOption option;
2207
2208 if (!WriteInterfaceToken(data)) {
2209 return INNER_ERR;
2210 }
2211 if (!data.WriteString16(Str8ToStr16(bundleName))) {
2212 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
2213 return ERR_INVALID_VALUE;
2214 }
2215 if (!data.WriteInt32(uid)) {
2216 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write fail");
2217 return ERR_INVALID_VALUE;
2218 }
2219 if (!data.WriteInt32(appIndex)) {
2220 TAG_LOGE(AAFwkTag::ABILITYMGR, "appIndex write fail");
2221 return ERR_INVALID_VALUE;
2222 }
2223 int error = SendRequest(AbilityManagerInterfaceCode::UNINSTALL_APP, data, reply, option);
2224 if (error != NO_ERROR) {
2225 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2226 return error;
2227 }
2228 return reply.ReadInt32();
2229 }
2230
UpgradeApp(const std::string & bundleName,const int32_t uid,const std::string & exitMsg,int32_t appIndex)2231 int32_t AbilityManagerProxy::UpgradeApp(const std::string &bundleName, const int32_t uid, const std::string &exitMsg,
2232 int32_t appIndex)
2233 {
2234 MessageParcel data;
2235 MessageParcel reply;
2236 MessageOption option;
2237
2238 if (!WriteInterfaceToken(data)) {
2239 return INNER_ERR;
2240 }
2241 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(bundleName));
2242 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, uid);
2243 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, String16, Str8ToStr16(exitMsg));
2244 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, appIndex);
2245 int error = SendRequest(AbilityManagerInterfaceCode::UPGRADE_APP, data, reply, option);
2246 if (error != NO_ERROR) {
2247 TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest error: %{public}d", error);
2248 return error;
2249 }
2250 return reply.ReadInt32();
2251 }
2252
GetWantSender(const WantSenderInfo & wantSenderInfo,const sptr<IRemoteObject> & callerToken,int32_t uid)2253 sptr<IWantSender> AbilityManagerProxy::GetWantSender(
2254 const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken, int32_t uid)
2255 {
2256 MessageParcel data;
2257 MessageParcel reply;
2258 MessageOption option;
2259 if (!WriteInterfaceToken(data)) {
2260 return nullptr;
2261 }
2262 if (!data.WriteParcelable(&wantSenderInfo)) {
2263 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeParcelable fail");
2264 return nullptr;
2265 }
2266 if (callerToken) {
2267 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
2268 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write fail");
2269 return nullptr;
2270 }
2271 } else {
2272 if (!data.WriteBool(false)) {
2273 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
2274 return nullptr;
2275 }
2276 }
2277
2278 if (!data.WriteInt32(uid)) {
2279 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write fail");
2280 return nullptr;
2281 }
2282
2283 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER, data, reply, option);
2284 if (error != NO_ERROR) {
2285 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2286 return nullptr;
2287 }
2288 sptr<IWantSender> wantSender = iface_cast<IWantSender>(reply.ReadRemoteObject());
2289 if (!wantSender) {
2290 return nullptr;
2291 }
2292 return wantSender;
2293 }
2294
SendWantSender(sptr<IWantSender> target,SenderInfo & senderInfo)2295 int AbilityManagerProxy::SendWantSender(sptr<IWantSender> target, SenderInfo &senderInfo)
2296 {
2297 MessageParcel data;
2298 MessageParcel reply;
2299 MessageOption option;
2300 if (!WriteInterfaceToken(data)) {
2301 return INNER_ERR;
2302 }
2303 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2304 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2305 return INNER_ERR;
2306 }
2307 if (!data.WriteParcelable(&senderInfo)) {
2308 TAG_LOGE(AAFwkTag::ABILITYMGR, "senderInfo write fail");
2309 return INNER_ERR;
2310 }
2311 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_PENDING_WANT_SENDER, data, reply, option);
2312 if (error != NO_ERROR) {
2313 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2314 return error;
2315 }
2316 std::unique_ptr<SenderInfo> completedDataReply(reply.ReadParcelable<SenderInfo>());
2317 if (!completedDataReply) {
2318 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelableInfo fail");
2319 return INNER_ERR;
2320 }
2321 senderInfo = *completedDataReply;
2322 return reply.ReadInt32();
2323 }
2324
SendLocalWantSender(const SenderInfo & senderInfo)2325 int AbilityManagerProxy::SendLocalWantSender(const SenderInfo &senderInfo)
2326 {
2327 MessageParcel data;
2328 MessageParcel reply;
2329 MessageOption option;
2330 if (!WriteInterfaceToken(data)) {
2331 return INNER_ERR;
2332 }
2333 if (!data.WriteParcelable(&senderInfo)) {
2334 TAG_LOGE(AAFwkTag::ABILITYMGR, "senderInfo write fail");
2335 return INNER_ERR;
2336 }
2337 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_LOCAL_PENDING_WANT_SENDER, data, reply, option);
2338 if (error != NO_ERROR) {
2339 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2340 return error;
2341 }
2342 return reply.ReadInt32();
2343 }
2344
CancelWantSender(const sptr<IWantSender> & sender)2345 void AbilityManagerProxy::CancelWantSender(const sptr<IWantSender> &sender)
2346 {
2347 MessageParcel data;
2348 MessageParcel reply;
2349 MessageOption option;
2350 if (!WriteInterfaceToken(data)) {
2351 return;
2352 }
2353 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
2354 TAG_LOGE(AAFwkTag::ABILITYMGR, "sender write fail");
2355 return;
2356 }
2357 auto error = SendRequest(AbilityManagerInterfaceCode::CANCEL_PENDING_WANT_SENDER, data, reply, option);
2358 if (error != NO_ERROR) {
2359 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2360 return;
2361 }
2362 }
2363
GetPendingWantUid(const sptr<IWantSender> & target)2364 int AbilityManagerProxy::GetPendingWantUid(const sptr<IWantSender> &target)
2365 {
2366 MessageParcel data;
2367 MessageParcel reply;
2368 MessageOption option;
2369 if (!WriteInterfaceToken(data)) {
2370 return INNER_ERR;
2371 }
2372 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2373 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2374 return ERR_INVALID_VALUE;
2375 }
2376 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_UID, data, reply, option);
2377 if (error != NO_ERROR) {
2378 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2379 return INNER_ERR;
2380 }
2381 return reply.ReadInt32();
2382 }
2383
GetPendingWantUserId(const sptr<IWantSender> & target)2384 int AbilityManagerProxy::GetPendingWantUserId(const sptr<IWantSender> &target)
2385 {
2386 MessageParcel data;
2387 MessageParcel reply;
2388 MessageOption option;
2389 if (!WriteInterfaceToken(data)) {
2390 return INNER_ERR;
2391 }
2392 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2393 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2394 return ERR_INVALID_VALUE;
2395 }
2396 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_USERID, data, reply, option);
2397 if (error != NO_ERROR) {
2398 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2399 return INNER_ERR;
2400 }
2401 return reply.ReadInt32();
2402 }
2403
GetPendingWantBundleName(const sptr<IWantSender> & target)2404 std::string AbilityManagerProxy::GetPendingWantBundleName(const sptr<IWantSender> &target)
2405 {
2406 MessageParcel data;
2407 MessageParcel reply;
2408 MessageOption option;
2409 if (!WriteInterfaceToken(data)) {
2410 return "";
2411 }
2412 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2413 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2414 return "";
2415 }
2416 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_BUNDLENAME, data, reply, option);
2417 if (error != NO_ERROR) {
2418 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2419 return "";
2420 }
2421 return Str16ToStr8(reply.ReadString16());
2422 }
2423
GetPendingWantCode(const sptr<IWantSender> & target)2424 int AbilityManagerProxy::GetPendingWantCode(const sptr<IWantSender> &target)
2425 {
2426 MessageParcel data;
2427 MessageParcel reply;
2428 MessageOption option;
2429 if (!WriteInterfaceToken(data)) {
2430 return INNER_ERR;
2431 }
2432 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2433 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2434 return ERR_INVALID_VALUE;
2435 }
2436 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_CODE, data, reply, option);
2437 if (error != NO_ERROR) {
2438 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2439 return INNER_ERR;
2440 }
2441 return reply.ReadInt32();
2442 }
2443
GetPendingWantType(const sptr<IWantSender> & target)2444 int AbilityManagerProxy::GetPendingWantType(const sptr<IWantSender> &target)
2445 {
2446 MessageParcel data;
2447 MessageParcel reply;
2448 MessageOption option;
2449 if (!WriteInterfaceToken(data)) {
2450 return INNER_ERR;
2451 }
2452 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2453 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2454 return ERR_INVALID_VALUE;
2455 }
2456 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_TYPE, data, reply, option);
2457 if (error != NO_ERROR) {
2458 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2459 return INNER_ERR;
2460 }
2461 return reply.ReadInt32();
2462 }
2463
RegisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)2464 void AbilityManagerProxy::RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
2465 {
2466 MessageParcel data;
2467 MessageParcel reply;
2468 MessageOption option;
2469 if (!WriteInterfaceToken(data)) {
2470 return;
2471 }
2472 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
2473 TAG_LOGE(AAFwkTag::ABILITYMGR, "sender write fail");
2474 return;
2475 }
2476 if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) {
2477 TAG_LOGE(AAFwkTag::ABILITYMGR, "receiver write fail");
2478 return;
2479 }
2480 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_CANCEL_LISTENER, data, reply, option);
2481 if (error != NO_ERROR) {
2482 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2483 return;
2484 }
2485 }
2486
UnregisterCancelListener(const sptr<IWantSender> & sender,const sptr<IWantReceiver> & receiver)2487 void AbilityManagerProxy::UnregisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
2488 {
2489 MessageParcel data;
2490 MessageParcel reply;
2491 MessageOption option;
2492 if (!WriteInterfaceToken(data)) {
2493 return;
2494 }
2495 if (sender == nullptr || !data.WriteRemoteObject(sender->AsObject())) {
2496 TAG_LOGE(AAFwkTag::ABILITYMGR, "sender write fail");
2497 return;
2498 }
2499 if (receiver == nullptr || !data.WriteRemoteObject(receiver->AsObject())) {
2500 TAG_LOGE(AAFwkTag::ABILITYMGR, "receiver write fail");
2501 return;
2502 }
2503 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_CANCEL_LISTENER, data, reply, option);
2504 if (error != NO_ERROR) {
2505 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2506 return;
2507 }
2508 }
2509
GetPendingRequestWant(const sptr<IWantSender> & target,std::shared_ptr<Want> & want)2510 int AbilityManagerProxy::GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want)
2511 {
2512 MessageParcel data;
2513 MessageParcel reply;
2514 MessageOption option;
2515 if (!WriteInterfaceToken(data)) {
2516 return INNER_ERR;
2517 }
2518 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2519 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2520 return INNER_ERR;
2521 }
2522 if (want == nullptr || !data.WriteParcelable(want.get())) {
2523 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
2524 return INNER_ERR;
2525 }
2526 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_REQUEST_WANT, data, reply, option);
2527 if (error != NO_ERROR) {
2528 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2529 return error;
2530 }
2531 std::unique_ptr<Want> wantInfo(reply.ReadParcelable<Want>());
2532 if (!wantInfo) {
2533 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelableInfo fail");
2534 return INNER_ERR;
2535 }
2536 want = std::move(wantInfo);
2537
2538 return NO_ERROR;
2539 }
2540
GetWantSenderInfo(const sptr<IWantSender> & target,std::shared_ptr<WantSenderInfo> & info)2541 int AbilityManagerProxy::GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info)
2542 {
2543 MessageParcel data;
2544 MessageParcel reply;
2545 MessageOption option;
2546 if (!WriteInterfaceToken(data)) {
2547 return INNER_ERR;
2548 }
2549 if (target == nullptr || !data.WriteRemoteObject(target->AsObject())) {
2550 TAG_LOGE(AAFwkTag::ABILITYMGR, "target write fail");
2551 return INNER_ERR;
2552 }
2553 if (info == nullptr || !data.WriteParcelable(info.get())) {
2554 TAG_LOGE(AAFwkTag::ABILITYMGR, "info write fail");
2555 return INNER_ERR;
2556 }
2557 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PENDING_WANT_SENDER_INFO, data, reply, option);
2558 if (error != NO_ERROR) {
2559 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2560 return error;
2561 }
2562 std::unique_ptr<WantSenderInfo> wantSenderInfo(reply.ReadParcelable<WantSenderInfo>());
2563 if (!wantSenderInfo) {
2564 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable Info fail");
2565 return INNER_ERR;
2566 }
2567 info = std::move(wantSenderInfo);
2568
2569 return NO_ERROR;
2570 }
2571
GetAppMemorySize()2572 int AbilityManagerProxy::GetAppMemorySize()
2573 {
2574 MessageParcel data;
2575 MessageParcel reply;
2576 MessageOption option;
2577 if (!WriteInterfaceToken(data)) {
2578 TAG_LOGE(AAFwkTag::ABILITYMGR, "write Token fail");
2579 return INNER_ERR;
2580 }
2581 auto error = SendRequest(AbilityManagerInterfaceCode::GET_APP_MEMORY_SIZE, data, reply, option);
2582 if (error != NO_ERROR) {
2583 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2584 return error;
2585 }
2586 return reply.ReadInt32();
2587 }
2588
IsRamConstrainedDevice()2589 bool AbilityManagerProxy::IsRamConstrainedDevice()
2590 {
2591 MessageParcel data;
2592 MessageParcel reply;
2593 MessageOption option;
2594 if (!WriteInterfaceToken(data)) {
2595 TAG_LOGE(AAFwkTag::ABILITYMGR, "write Token faile");
2596 return false;
2597 }
2598 auto error = SendRequest(AbilityManagerInterfaceCode::IS_RAM_CONSTRAINED_DEVICE, data, reply, option);
2599 if (error != NO_ERROR) {
2600 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2601 return false;
2602 }
2603 return reply.ReadBool();
2604 }
2605
ContinueMission(const std::string & srcDeviceId,const std::string & dstDeviceId,int32_t missionId,const sptr<IRemoteObject> & callBack,AAFwk::WantParams & wantParams)2606 int AbilityManagerProxy::ContinueMission(const std::string &srcDeviceId, const std::string &dstDeviceId,
2607 int32_t missionId, const sptr<IRemoteObject> &callBack, AAFwk::WantParams &wantParams)
2608 {
2609 TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
2610 MessageParcel data;
2611 MessageParcel reply;
2612 MessageOption option;
2613 if (!WriteInterfaceToken(data)) {
2614 return INNER_ERR;
2615 }
2616 if (!data.WriteString(srcDeviceId)) {
2617 TAG_LOGE(AAFwkTag::ABILITYMGR, "srcDeviceId write fail");
2618 return INNER_ERR;
2619 }
2620 if (!data.WriteString(dstDeviceId)) {
2621 TAG_LOGE(AAFwkTag::ABILITYMGR, "dstDeviceId write fail");
2622 return INNER_ERR;
2623 }
2624 if (!data.WriteInt32(missionId)) {
2625 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
2626 return INNER_ERR;
2627 }
2628 if (!data.WriteRemoteObject(callBack)) {
2629 TAG_LOGE(AAFwkTag::ABILITYMGR, "callBack write fail");
2630 return INNER_ERR;
2631 }
2632 if (!data.WriteParcelable(&wantParams)) {
2633 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParams write fail");
2634 return INNER_ERR;
2635 }
2636
2637 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_MISSION, data, reply, option);
2638 if (error != NO_ERROR) {
2639 TAG_LOGE(AAFwkTag::ABILITYMGR, "sendRequest error: %{public}d", error);
2640 return error;
2641 }
2642 return reply.ReadInt32();
2643 }
2644
ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo,const sptr<IRemoteObject> & callback)2645 int AbilityManagerProxy::ContinueMission(AAFwk::ContinueMissionInfo continueMissionInfo,
2646 const sptr<IRemoteObject> &callback)
2647 {
2648 MessageParcel data;
2649 MessageParcel reply;
2650 MessageOption option;
2651 if (!WriteInterfaceToken(data)) {
2652 return INNER_ERR;
2653 }
2654 if (!data.WriteString(continueMissionInfo.srcDeviceId)) {
2655 TAG_LOGE(AAFwkTag::ABILITYMGR, "srcDeviceId write fail");
2656 return INNER_ERR;
2657 }
2658 if (!data.WriteString(continueMissionInfo.dstDeviceId)) {
2659 TAG_LOGE(AAFwkTag::ABILITYMGR, "dstDeviceId write fail");
2660 return INNER_ERR;
2661 }
2662 if (!data.WriteString(continueMissionInfo.bundleName)) {
2663 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
2664 return INNER_ERR;
2665 }
2666 if (!data.WriteRemoteObject(callback)) {
2667 TAG_LOGE(AAFwkTag::ABILITYMGR, "callBack write fail");
2668 return INNER_ERR;
2669 }
2670 if (!data.WriteParcelable(&continueMissionInfo.wantParams)) {
2671 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParams write fail");
2672 return INNER_ERR;
2673 }
2674 if (!data.WriteString(continueMissionInfo.srcBundleName)) {
2675 TAG_LOGE(AAFwkTag::ABILITYMGR, "srcBundleName write fail");
2676 return INNER_ERR;
2677 }
2678 if (!data.WriteString(continueMissionInfo.continueType)) {
2679 TAG_LOGE(AAFwkTag::ABILITYMGR, "continueType write fail");
2680 return INNER_ERR;
2681 }
2682 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME, data, reply, option);
2683 if (error != NO_ERROR) {
2684 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2685 return error;
2686 }
2687 return reply.ReadInt32();
2688 }
2689
ContinueAbility(const std::string & deviceId,int32_t missionId,uint32_t versionCode)2690 int AbilityManagerProxy::ContinueAbility(const std::string &deviceId, int32_t missionId, uint32_t versionCode)
2691 {
2692 MessageParcel data;
2693 MessageParcel reply;
2694 MessageOption option;
2695 if (!WriteInterfaceToken(data)) {
2696 return INNER_ERR;
2697 }
2698 if (!data.WriteString(deviceId)) {
2699 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write fail");
2700 return INNER_ERR;
2701 }
2702 if (!data.WriteInt32(missionId)) {
2703 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
2704 return INNER_ERR;
2705 }
2706 if (!data.WriteUint32(versionCode)) {
2707 TAG_LOGE(AAFwkTag::ABILITYMGR, "versionCode write fail");
2708 return INNER_ERR;
2709 }
2710
2711 auto error = SendRequest(AbilityManagerInterfaceCode::CONTINUE_ABILITY, data, reply, option);
2712 if (error != NO_ERROR) {
2713 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2714 return error;
2715 }
2716 return reply.ReadInt32();
2717 }
2718
StartContinuation(const Want & want,const sptr<IRemoteObject> & abilityToken,int32_t status)2719 int AbilityManagerProxy::StartContinuation(const Want &want, const sptr<IRemoteObject> &abilityToken, int32_t status)
2720 {
2721 MessageParcel data;
2722 MessageParcel reply;
2723 MessageOption option = {MessageOption::TF_ASYNC};
2724 if (!WriteInterfaceToken(data)) {
2725 return INNER_ERR;
2726 }
2727 if (!data.WriteParcelable(&want)) {
2728 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
2729 return INNER_ERR;
2730 }
2731 if (!data.WriteRemoteObject(abilityToken)) {
2732 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityToken write fail");
2733 return INNER_ERR;
2734 }
2735 if (!data.WriteInt32(status)) {
2736 TAG_LOGE(AAFwkTag::ABILITYMGR, "status write fail");
2737 return INNER_ERR;
2738 }
2739
2740 auto error = SendRequest(AbilityManagerInterfaceCode::START_CONTINUATION, data, reply, option);
2741 if (error != NO_ERROR) {
2742 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2743 return error;
2744 }
2745 return reply.ReadInt32();
2746 }
2747
NotifyCompleteContinuation(const std::string & deviceId,int32_t sessionId,bool isSuccess)2748 void AbilityManagerProxy::NotifyCompleteContinuation(const std::string &deviceId, int32_t sessionId, bool isSuccess)
2749 {
2750 MessageParcel data;
2751 MessageParcel reply;
2752 MessageOption option = {MessageOption::TF_ASYNC};
2753 if (!WriteInterfaceToken(data)) {
2754 return;
2755 }
2756 if (!data.WriteString(deviceId)) {
2757 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write fail");
2758 return;
2759 }
2760 if (!data.WriteInt32(sessionId)) {
2761 TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionId write fail");
2762 return;
2763 }
2764 if (!data.WriteBool(isSuccess)) {
2765 TAG_LOGE(AAFwkTag::ABILITYMGR, "result write fail");
2766 return;
2767 }
2768 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_COMPLETE_CONTINUATION, data, reply, option);
2769 if (error != NO_ERROR) {
2770 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2771 return;
2772 }
2773 }
2774
NotifyContinuationResult(int32_t missionId,int32_t result)2775 int AbilityManagerProxy::NotifyContinuationResult(int32_t missionId, int32_t result)
2776 {
2777 MessageParcel data;
2778 MessageParcel reply;
2779 MessageOption option;
2780 if (!WriteInterfaceToken(data)) {
2781 return INNER_ERR;
2782 }
2783 if (!data.WriteInt32(missionId)) {
2784 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
2785 return INNER_ERR;
2786 }
2787 if (!data.WriteInt32(result)) {
2788 TAG_LOGE(AAFwkTag::ABILITYMGR, "result write fail");
2789 return INNER_ERR;
2790 }
2791
2792 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_CONTINUATION_RESULT, data, reply, option);
2793 if (error != NO_ERROR) {
2794 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2795 return error;
2796 }
2797 return reply.ReadInt32();
2798 }
2799
LockMissionForCleanup(int32_t missionId)2800 int AbilityManagerProxy::LockMissionForCleanup(int32_t missionId)
2801 {
2802 int error;
2803 MessageParcel data;
2804 MessageParcel reply;
2805 MessageOption option;
2806
2807 if (!WriteInterfaceToken(data)) {
2808 return INNER_ERR;
2809 }
2810 if (!data.WriteInt32(missionId)) {
2811 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
2812 return ERR_INVALID_VALUE;
2813 }
2814
2815 error = SendRequest(AbilityManagerInterfaceCode::LOCK_MISSION_FOR_CLEANUP, data, reply, option);
2816 if (error != NO_ERROR) {
2817 TAG_LOGE(AAFwkTag::ABILITYMGR, "send error:%{public}d", error);
2818 return error;
2819 }
2820 return reply.ReadInt32();
2821 }
2822
UnlockMissionForCleanup(int32_t missionId)2823 int AbilityManagerProxy::UnlockMissionForCleanup(int32_t missionId)
2824 {
2825 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
2826 int error;
2827 MessageParcel data;
2828 MessageParcel reply;
2829 MessageOption option;
2830
2831 if (!WriteInterfaceToken(data)) {
2832 return INNER_ERR;
2833 }
2834 if (!data.WriteInt32(missionId)) {
2835 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 fail");
2836 return ERR_INVALID_VALUE;
2837 }
2838 error = SendRequest(AbilityManagerInterfaceCode::UNLOCK_MISSION_FOR_CLEANUP, data, reply, option);
2839 if (error != NO_ERROR) {
2840 TAG_LOGE(AAFwkTag::ABILITYMGR, "unlock mission,error:%{public}d", error);
2841 return error;
2842 }
2843 return reply.ReadInt32();
2844 }
2845
SetLockedState(int32_t sessionId,bool lockedState)2846 void AbilityManagerProxy::SetLockedState(int32_t sessionId, bool lockedState)
2847 {
2848 MessageParcel data;
2849
2850 if (!WriteInterfaceToken(data)) {
2851 return;
2852 }
2853
2854 if (!data.WriteInt32(sessionId)) {
2855 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 fail");
2856 return;
2857 }
2858
2859 if (!data.WriteBool(lockedState)) {
2860 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeBool fail");
2861 return;
2862 }
2863
2864 MessageParcel reply;
2865 MessageOption option(MessageOption::TF_ASYNC);
2866 auto error = SendRequest(AbilityManagerInterfaceCode::SET_SESSION_LOCKED_STATE, data, reply, option);
2867 if (error != NO_ERROR) {
2868 TAG_LOGE(AAFwkTag::ABILITYMGR, "error: %{public}d", error);
2869 return;
2870 }
2871 return;
2872 }
2873
RegisterMissionListener(const sptr<IMissionListener> & listener)2874 int AbilityManagerProxy::RegisterMissionListener(const sptr<IMissionListener> &listener)
2875 {
2876 int error;
2877 MessageParcel data;
2878 MessageParcel reply;
2879 MessageOption option;
2880 if (!listener) {
2881 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener null");
2882 return ERR_INVALID_VALUE;
2883 }
2884
2885 if (!WriteInterfaceToken(data)) {
2886 return INNER_ERR;
2887 }
2888 if (!data.WriteRemoteObject(listener->AsObject())) {
2889 TAG_LOGE(AAFwkTag::ABILITYMGR, "write missionListener fail");
2890 return ERR_INVALID_VALUE;
2891 }
2892
2893 error = SendRequest(AbilityManagerInterfaceCode::REGISTER_MISSION_LISTENER, data, reply, option);
2894 if (error != NO_ERROR) {
2895 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error);
2896 return error;
2897 }
2898 return reply.ReadInt32();
2899 }
2900
RegisterSessionHandler(const sptr<IRemoteObject> & object)2901 int AbilityManagerProxy::RegisterSessionHandler(const sptr<IRemoteObject> &object)
2902 {
2903 if (!object) {
2904 TAG_LOGE(AAFwkTag::ABILITYMGR, "handler null");
2905 return ERR_INVALID_VALUE;
2906 }
2907 MessageParcel data;
2908 MessageParcel reply;
2909 MessageOption option;
2910 if (!WriteInterfaceToken(data)) {
2911 return INNER_ERR;
2912 }
2913 if (!data.WriteRemoteObject(object)) {
2914 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionHandler fail");
2915 return ERR_INVALID_VALUE;
2916 }
2917 int error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SESSION_HANDLER, data, reply, option);
2918 if (error != NO_ERROR) {
2919 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2920 return error;
2921 }
2922 return reply.ReadInt32();
2923 }
2924
RegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)2925 int AbilityManagerProxy::RegisterMissionListener(const std::string &deviceId,
2926 const sptr<IRemoteMissionListener> &listener)
2927 {
2928 MessageParcel data;
2929 MessageParcel reply;
2930 MessageOption option;
2931 if (!WriteInterfaceToken(data)) {
2932 return INNER_ERR;
2933 }
2934 if (!data.WriteString(deviceId)) {
2935 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write fail");
2936 return INNER_ERR;
2937 }
2938 if (!data.WriteRemoteObject(listener->AsObject())) {
2939 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write fail");
2940 return INNER_ERR;
2941 }
2942
2943 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_MISSION_LISTENER,
2944 data, reply, option);
2945 if (error != NO_ERROR) {
2946 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2947 return error;
2948 }
2949 return reply.ReadInt32();
2950 }
2951
RegisterOnListener(const std::string & type,const sptr<IRemoteOnListener> & listener)2952 int AbilityManagerProxy::RegisterOnListener(const std::string &type,
2953 const sptr<IRemoteOnListener> &listener)
2954 {
2955 MessageParcel data;
2956 MessageParcel reply;
2957 MessageOption option;
2958 if (!WriteInterfaceToken(data)) {
2959 return INNER_ERR;
2960 }
2961 if (!data.WriteString(type)) {
2962 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write fail");
2963 return INNER_ERR;
2964 }
2965 if (!data.WriteRemoteObject(listener->AsObject())) {
2966 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write fail");
2967 return INNER_ERR;
2968 }
2969
2970 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_ON_LISTENER, data, reply, option);
2971 if (error != NO_ERROR) {
2972 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2973 return error;
2974 }
2975 return reply.ReadInt32();
2976 }
2977
RegisterOffListener(const std::string & type,const sptr<IRemoteOnListener> & listener)2978 int AbilityManagerProxy::RegisterOffListener(const std::string &type,
2979 const sptr<IRemoteOnListener> &listener)
2980 {
2981 MessageParcel data;
2982 MessageParcel reply;
2983 MessageOption option;
2984 if (!WriteInterfaceToken(data)) {
2985 return INNER_ERR;
2986 }
2987 if (!data.WriteString(type)) {
2988 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write fail");
2989 return INNER_ERR;
2990 }
2991 if (!data.WriteRemoteObject(listener->AsObject())) {
2992 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write fail");
2993 return INNER_ERR;
2994 }
2995
2996 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_REMOTE_OFF_LISTENER, data, reply, option);
2997 if (error != NO_ERROR) {
2998 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
2999 return error;
3000 }
3001 return reply.ReadInt32();
3002 }
3003
UnRegisterMissionListener(const sptr<IMissionListener> & listener)3004 int AbilityManagerProxy::UnRegisterMissionListener(const sptr<IMissionListener> &listener)
3005 {
3006 int error;
3007 MessageParcel data;
3008 MessageParcel reply;
3009 MessageOption option;
3010 if (!listener) {
3011 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener null");
3012 return ERR_INVALID_VALUE;
3013 }
3014
3015 if (!WriteInterfaceToken(data)) {
3016 return INNER_ERR;
3017 }
3018 if (!data.WriteRemoteObject(listener->AsObject())) {
3019 TAG_LOGE(AAFwkTag::ABILITYMGR, "write missionListener fail");
3020 return ERR_INVALID_VALUE;
3021 }
3022
3023 error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_MISSION_LISTENER, data, reply, option);
3024 if (error != NO_ERROR) {
3025 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3026 return error;
3027 }
3028 return reply.ReadInt32();
3029 }
3030
GetMissionInfos(const std::string & deviceId,int32_t numMax,std::vector<MissionInfo> & missionInfos)3031 int AbilityManagerProxy::GetMissionInfos(const std::string& deviceId, int32_t numMax,
3032 std::vector<MissionInfo> &missionInfos)
3033 {
3034 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
3035 int error;
3036 MessageParcel data;
3037 MessageParcel reply;
3038 MessageOption option;
3039 if (!WriteInterfaceToken(data)) {
3040 return INNER_ERR;
3041 }
3042 if (!data.WriteString16(Str8ToStr16(deviceId))) {
3043 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId fail");
3044 return ERR_INVALID_VALUE;
3045 }
3046 if (!data.WriteInt32(numMax)) {
3047 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 fail");
3048 return ERR_INVALID_VALUE;
3049 }
3050 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_INFOS, data, reply, option);
3051 if (error != NO_ERROR) {
3052 TAG_LOGE(AAFwkTag::ABILITYMGR, " request error:%{public}d", error);
3053 return error;
3054 }
3055 error = GetParcelableInfos<MissionInfo>(reply, missionInfos);
3056 if (error != NO_ERROR) {
3057 TAG_LOGE(AAFwkTag::ABILITYMGR, "getMissionInfos error: %{public}d", error);
3058 return error;
3059 }
3060 return reply.ReadInt32();
3061 }
3062
GetMissionInfo(const std::string & deviceId,int32_t missionId,MissionInfo & missionInfo)3063 int AbilityManagerProxy::GetMissionInfo(const std::string& deviceId, int32_t missionId,
3064 MissionInfo &missionInfo)
3065 {
3066 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
3067 int error;
3068 MessageParcel data;
3069 MessageParcel reply;
3070 MessageOption option;
3071 if (!WriteInterfaceToken(data)) {
3072 return INNER_ERR;
3073 }
3074 if (!data.WriteString16(Str8ToStr16(deviceId))) {
3075 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId failed");
3076 return ERR_INVALID_VALUE;
3077 }
3078 if (!data.WriteInt32(missionId)) {
3079 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 failed");
3080 return ERR_INVALID_VALUE;
3081 }
3082 error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_INFO_BY_ID, data, reply, option);
3083 if (error != NO_ERROR) {
3084 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3085 return error;
3086 }
3087
3088 std::unique_ptr<MissionInfo> info(reply.ReadParcelable<MissionInfo>());
3089 if (!info) {
3090 TAG_LOGE(AAFwkTag::ABILITYMGR, "read missioninfo fail");
3091 return ERR_UNKNOWN_OBJECT;
3092 }
3093 missionInfo = *info;
3094 return reply.ReadInt32();
3095 }
3096
CleanMission(int32_t missionId)3097 int AbilityManagerProxy::CleanMission(int32_t missionId)
3098 {
3099 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
3100 int error;
3101 MessageParcel data;
3102 MessageParcel reply;
3103 MessageOption option;
3104
3105 if (!WriteInterfaceToken(data)) {
3106 return INNER_ERR;
3107 }
3108 if (!data.WriteInt32(missionId)) {
3109 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 fail");
3110 return ERR_INVALID_VALUE;
3111 }
3112 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_MISSION, data, reply, option);
3113 if (error != NO_ERROR) {
3114 TAG_LOGE(AAFwkTag::ABILITYMGR, "clean mission, error: %{public}d", error);
3115 return error;
3116 }
3117 return reply.ReadInt32();
3118 }
3119
CleanAllMissions()3120 int AbilityManagerProxy::CleanAllMissions()
3121 {
3122 Ability_MANAGER_HITRACE_CHAIN_NAME("CleanAllMissions", HITRACE_FLAG_INCLUDE_ASYNC);
3123 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
3124 int error;
3125 MessageParcel data;
3126 MessageParcel reply;
3127 MessageOption option;
3128
3129 if (!WriteInterfaceToken(data)) {
3130 return INNER_ERR;
3131 }
3132 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_ALL_MISSIONS, data, reply, option);
3133 if (error != NO_ERROR) {
3134 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3135 return error;
3136 }
3137 return reply.ReadInt32();
3138 }
3139
MoveMissionToFront(int32_t missionId)3140 int AbilityManagerProxy::MoveMissionToFront(int32_t missionId)
3141 {
3142 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
3143 int error;
3144 MessageParcel data;
3145 MessageParcel reply;
3146 MessageOption option;
3147
3148 if (!WriteInterfaceToken(data)) {
3149 return INNER_ERR;
3150 }
3151 if (!data.WriteInt32(missionId)) {
3152 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 fail");
3153 return ERR_INVALID_VALUE;
3154 }
3155 error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT, data, reply, option);
3156 if (error != NO_ERROR) {
3157 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3158 return error;
3159 }
3160 return reply.ReadInt32();
3161 }
3162
MoveMissionToFront(int32_t missionId,const StartOptions & startOptions)3163 int AbilityManagerProxy::MoveMissionToFront(int32_t missionId, const StartOptions &startOptions)
3164 {
3165 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
3166 int error;
3167 MessageParcel data;
3168 MessageParcel reply;
3169 MessageOption option;
3170
3171 if (!WriteInterfaceToken(data)) {
3172 return INNER_ERR;
3173 }
3174 if (!data.WriteInt32(missionId)) {
3175 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt32 fail");
3176 return ERR_INVALID_VALUE;
3177 }
3178 if (!data.WriteParcelable(&startOptions)) {
3179 TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions write fail");
3180 return INNER_ERR;
3181 }
3182 error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSION_TO_FRONT_BY_OPTIONS, data, reply, option);
3183 if (error != NO_ERROR) {
3184 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3185 return error;
3186 }
3187 return reply.ReadInt32();
3188 }
3189
MoveMissionsToForeground(const std::vector<int32_t> & missionIds,int32_t topMissionId)3190 int AbilityManagerProxy::MoveMissionsToForeground(const std::vector<int32_t>& missionIds, int32_t topMissionId)
3191 {
3192 MessageParcel data;
3193 MessageParcel reply;
3194 MessageOption option;
3195 if (!WriteInterfaceToken(data)) {
3196 return INNER_ERR;
3197 }
3198
3199 if (!data.WriteInt32Vector(missionIds)) {
3200 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionIds write fail");
3201 return INNER_ERR;
3202 }
3203
3204 if (!data.WriteInt32(topMissionId)) {
3205 TAG_LOGE(AAFwkTag::ABILITYMGR, "topMissionId write fail");
3206 return INNER_ERR;
3207 }
3208
3209 auto error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_FOREGROUND, data, reply, option);
3210 if (error != NO_ERROR) {
3211 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3212 return error;
3213 }
3214
3215 return reply.ReadInt32();
3216 }
3217
MoveMissionsToBackground(const std::vector<int32_t> & missionIds,std::vector<int32_t> & result)3218 int AbilityManagerProxy::MoveMissionsToBackground(const std::vector<int32_t>& missionIds, std::vector<int32_t>& result)
3219 {
3220 MessageParcel data;
3221 MessageParcel reply;
3222 MessageOption option;
3223 if (!WriteInterfaceToken(data)) {
3224 return INNER_ERR;
3225 }
3226
3227 if (!data.WriteInt32Vector(missionIds)) {
3228 TAG_LOGE(AAFwkTag::ABILITYMGR, "mission id write fail");
3229 return INNER_ERR;
3230 }
3231
3232 auto error = SendRequest(AbilityManagerInterfaceCode::MOVE_MISSIONS_TO_BACKGROUND, data, reply, option);
3233 if (error != NO_ERROR) {
3234 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3235 return error;
3236 }
3237
3238 if (!reply.ReadInt32Vector(&result)) {
3239 TAG_LOGE(AAFwkTag::ABILITYMGR, "read result fail");
3240 return INNER_ERR;
3241 }
3242 return reply.ReadInt32();
3243 }
3244
StartUser(int userId,sptr<IUserCallback> callback,bool isAppRecovery)3245 int AbilityManagerProxy::StartUser(int userId, sptr<IUserCallback> callback, bool isAppRecovery)
3246 {
3247 Ability_MANAGER_HITRACE_CHAIN_NAME("StartUser", HITRACE_FLAG_INCLUDE_ASYNC);
3248 MessageParcel data;
3249 if (!WriteInterfaceToken(data)) {
3250 return INNER_ERR;
3251 }
3252 if (!data.WriteInt32(userId)) {
3253 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail");
3254 return ERR_INVALID_VALUE;
3255 }
3256 if (!callback) {
3257 data.WriteBool(false);
3258 } else {
3259 data.WriteBool(true);
3260 if (!data.WriteRemoteObject(callback->AsObject())) {
3261 TAG_LOGE(AAFwkTag::ABILITYMGR, "write IUserCallback fail");
3262 return ERR_INVALID_VALUE;
3263 }
3264 }
3265 if (!data.WriteBool(isAppRecovery)) {
3266 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isAppRecovery fail");
3267 return IPC_PROXY_ERR;
3268 }
3269 MessageParcel reply;
3270 MessageOption option(MessageOption::TF_ASYNC);
3271 auto error = SendRequest(AbilityManagerInterfaceCode::START_USER, data, reply, option);
3272 if (error != NO_ERROR) {
3273 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3274 return error;
3275 }
3276 return reply.ReadInt32();
3277 }
3278
SetMissionContinueState(const sptr<IRemoteObject> & token,const AAFwk::ContinueState & state)3279 int AbilityManagerProxy::SetMissionContinueState(const sptr<IRemoteObject> &token, const AAFwk::ContinueState &state)
3280 {
3281 MessageParcel data;
3282 MessageParcel reply;
3283 MessageOption option;
3284 if (!WriteInterfaceToken(data)) {
3285 return INNER_ERR;
3286 }
3287 if (!data.WriteRemoteObject(token)) {
3288 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
3289 return ERR_INVALID_VALUE;
3290 }
3291 if (!data.WriteInt32(static_cast<int32_t>(state))) {
3292 TAG_LOGE(AAFwkTag::ABILITYMGR, "write state fail");
3293 return ERR_INVALID_VALUE;
3294 }
3295 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_CONTINUE_STATE, data, reply, option);
3296 if (error != NO_ERROR) {
3297 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3298 return error;
3299 }
3300 return reply.ReadInt32();
3301 }
3302
StopUser(int userId,const sptr<IUserCallback> & callback)3303 int AbilityManagerProxy::StopUser(int userId, const sptr<IUserCallback> &callback)
3304 {
3305 Ability_MANAGER_HITRACE_CHAIN_NAME("StopUser", HITRACE_FLAG_INCLUDE_ASYNC);
3306 MessageParcel data;
3307 if (!WriteInterfaceToken(data)) {
3308 return INNER_ERR;
3309 }
3310 if (!data.WriteInt32(userId)) {
3311 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail");
3312 return ERR_INVALID_VALUE;
3313 }
3314
3315 if (!callback) {
3316 data.WriteBool(false);
3317 } else {
3318 data.WriteBool(true);
3319 if (!data.WriteRemoteObject(callback->AsObject())) {
3320 TAG_LOGE(AAFwkTag::ABILITYMGR, "write IUserCallback fail");
3321 return ERR_INVALID_VALUE;
3322 }
3323 }
3324 MessageParcel reply;
3325 MessageOption option(MessageOption::TF_ASYNC);
3326 auto error = SendRequest(AbilityManagerInterfaceCode::STOP_USER, data, reply, option);
3327 if (error != NO_ERROR) {
3328 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3329 return error;
3330 }
3331 return reply.ReadInt32();
3332 }
3333
LogoutUser(int32_t userId,sptr<IUserCallback> callback)3334 int AbilityManagerProxy::LogoutUser(int32_t userId, sptr<IUserCallback> callback)
3335 {
3336 Ability_MANAGER_HITRACE_CHAIN_NAME("LogoutUser", HITRACE_FLAG_INCLUDE_ASYNC);
3337 MessageParcel data;
3338 MessageParcel reply;
3339 MessageOption option;
3340
3341 if (!WriteInterfaceToken(data)) {
3342 return INNER_ERR;
3343 }
3344 if (!data.WriteInt32(userId)) {
3345 TAG_LOGE(AAFwkTag::ABILITYMGR, "fail");
3346 return ERR_INVALID_VALUE;
3347 }
3348 if (callback == nullptr) {
3349 TAG_LOGD(AAFwkTag::ABILITYMGR, "callback is nullptr");
3350 data.WriteBool(false);
3351 } else {
3352 data.WriteBool(true);
3353 if (!data.WriteRemoteObject(callback->AsObject())) {
3354 TAG_LOGE(AAFwkTag::ABILITYMGR, "write IUserCallback fail");
3355 return ERR_INVALID_VALUE;
3356 }
3357 }
3358 int error = SendRequest(AbilityManagerInterfaceCode::LOGOUT_USER, data, reply, option);
3359 if (error != NO_ERROR) {
3360 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3361 return error;
3362 }
3363 return reply.ReadInt32();
3364 }
3365
3366 #ifdef SUPPORT_SCREEN
SetMissionLabel(const sptr<IRemoteObject> & token,const std::string & label)3367 int AbilityManagerProxy::SetMissionLabel(const sptr<IRemoteObject> &token, const std::string &label)
3368 {
3369 MessageParcel data;
3370 MessageParcel reply;
3371 MessageOption option;
3372 if (!WriteInterfaceToken(data)) {
3373 return INNER_ERR;
3374 }
3375 if (!data.WriteRemoteObject(token)) {
3376 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
3377 return ERR_INVALID_VALUE;
3378 }
3379 if (!data.WriteString16(Str8ToStr16(label))) {
3380 TAG_LOGE(AAFwkTag::ABILITYMGR, "write label fail");
3381 return ERR_INVALID_VALUE;
3382 }
3383 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_LABEL, data, reply, option);
3384 if (error != NO_ERROR) {
3385 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3386 return error;
3387 }
3388 return reply.ReadInt32();
3389 }
3390
SetMissionIcon(const sptr<IRemoteObject> & token,const std::shared_ptr<OHOS::Media::PixelMap> & icon)3391 int AbilityManagerProxy::SetMissionIcon(const sptr<IRemoteObject> &token,
3392 const std::shared_ptr<OHOS::Media::PixelMap> &icon)
3393 {
3394 if (!token || !icon) {
3395 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilitytoken or icon invalid");
3396 return ERR_INVALID_VALUE;
3397 }
3398
3399 MessageParcel data;
3400 MessageParcel reply;
3401 MessageOption option;
3402 if (!WriteInterfaceToken(data)) {
3403 return INNER_ERR;
3404 }
3405 if (!data.WriteRemoteObject(token)) {
3406 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
3407 return ERR_INVALID_VALUE;
3408 }
3409
3410 if (!data.WriteParcelable(icon.get())) {
3411 TAG_LOGE(AAFwkTag::ABILITYMGR, "write icon fail");
3412 return ERR_INVALID_VALUE;
3413 }
3414
3415 auto error = SendRequest(AbilityManagerInterfaceCode::SET_MISSION_ICON, data, reply, option);
3416 if (error != NO_ERROR) {
3417 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3418 return error;
3419 }
3420 return reply.ReadInt32();
3421 }
3422
RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler> & handler,bool animationEnabled)3423 int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr<IWindowManagerServiceHandler>& handler,
3424 bool animationEnabled)
3425 {
3426 if (!handler) {
3427 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: handler null", __func__);
3428 return INNER_ERR;
3429 }
3430 MessageParcel data;
3431 if (!WriteInterfaceToken(data)) {
3432 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: writeInterfaceToken failed", __func__);
3433 return INNER_ERR;
3434 }
3435 if (!data.WriteRemoteObject(handler->AsObject())) {
3436 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: handler write fail", __func__);
3437 return INNER_ERR;
3438 }
3439 if (!data.WriteBool(animationEnabled)) {
3440 TAG_LOGE(AAFwkTag::ABILITYMGR, "write animationEnabled fail");
3441 return ERR_INVALID_VALUE;
3442 }
3443 MessageOption option;
3444 MessageParcel reply;
3445 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_WMS_HANDLER, data, reply, option);
3446 if (error != NO_ERROR) {
3447 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s:request error:%{public}d", __func__, error);
3448 return error;
3449 }
3450 return reply.ReadInt32();
3451 }
3452
CompleteFirstFrameDrawing(const sptr<IRemoteObject> & abilityToken)3453 void AbilityManagerProxy::CompleteFirstFrameDrawing(const sptr<IRemoteObject> &abilityToken)
3454 {
3455 MessageParcel data;
3456 if (!WriteInterfaceToken(data)) {
3457 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: writeInterfaceToken fail", __func__);
3458 return;
3459 }
3460 if (!data.WriteRemoteObject(abilityToken)) {
3461 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: abilityToken write fail", __func__);
3462 return;
3463 }
3464 MessageOption option;
3465 MessageParcel reply;
3466 auto error = SendRequest(AbilityManagerInterfaceCode::COMPLETEFIRSTFRAMEDRAWING, data, reply, option);
3467 if (error != NO_ERROR) {
3468 TAG_LOGE(AAFwkTag::ABILITYMGR, "%{public}s: request error:%{public}d", __func__, error);
3469 }
3470 }
3471
PrepareTerminateAbility(const sptr<IRemoteObject> & token,sptr<IPrepareTerminateCallback> & callback)3472 int AbilityManagerProxy::PrepareTerminateAbility(const sptr<IRemoteObject> &token,
3473 sptr<IPrepareTerminateCallback> &callback)
3474 {
3475 if (!callback) {
3476 TAG_LOGE(AAFwkTag::ABILITYMGR, "callback null");
3477 return INNER_ERR;
3478 }
3479 int error = 0;
3480 MessageParcel data;
3481 MessageParcel reply;
3482 MessageOption option(MessageOption::TF_SYNC);
3483 if (!WriteInterfaceToken(data)) {
3484 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
3485 return INNER_ERR;
3486 }
3487 if (token) {
3488 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
3489 TAG_LOGE(AAFwkTag::ABILITYMGR, "write fail");
3490 return INNER_ERR;
3491 }
3492 } else {
3493 if (!data.WriteBool(false)) {
3494 TAG_LOGE(AAFwkTag::ABILITYMGR, "write fail");
3495 return INNER_ERR;
3496 }
3497 }
3498 if (!data.WriteRemoteObject(callback->AsObject())) {
3499 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite callback fail");
3500 return INNER_ERR;
3501 }
3502
3503 error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY, data, reply, option);
3504 if (error != NO_ERROR) {
3505 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3506 return error;
3507 }
3508
3509 return reply.ReadInt32();
3510 }
3511
GetDialogSessionInfo(const std::string & dialogSessionId,sptr<DialogSessionInfo> & info)3512 int AbilityManagerProxy::GetDialogSessionInfo(const std::string &dialogSessionId, sptr<DialogSessionInfo> &info)
3513 {
3514 MessageParcel data;
3515 MessageParcel reply;
3516 MessageOption option;
3517 if (!WriteInterfaceToken(data)) {
3518 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface fail");
3519 return INNER_ERR;
3520 }
3521 if (!data.WriteString(dialogSessionId)) {
3522 TAG_LOGE(AAFwkTag::ABILITYMGR, "write dialogSessionId fail");
3523 return ERR_INVALID_VALUE;
3524 }
3525 auto error = SendRequest(AbilityManagerInterfaceCode::GET_DIALOG_SESSION_INFO, data, reply, option);
3526 if (error != NO_ERROR) {
3527 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3528 return error;
3529 }
3530 info = reply.ReadParcelable<DialogSessionInfo>();
3531 if (!info) {
3532 TAG_LOGE(AAFwkTag::ABILITYMGR, "readParcelable fail");
3533 return ERR_UNKNOWN_OBJECT;
3534 }
3535 return reply.ReadInt32();
3536 }
3537
SendDialogResult(const Want & want,const std::string & dialogSessionId,const bool isAllow)3538 int AbilityManagerProxy::SendDialogResult(const Want &want, const std::string &dialogSessionId, const bool isAllow)
3539 {
3540 MessageParcel data;
3541 MessageParcel reply;
3542 MessageOption option;
3543 if (!WriteInterfaceToken(data)) {
3544 return INNER_ERR;
3545 }
3546 if (!data.WriteParcelable(&want)) {
3547 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
3548 return ERR_INVALID_VALUE;
3549 }
3550 if (!data.WriteString(dialogSessionId)) {
3551 TAG_LOGE(AAFwkTag::ABILITYMGR, "write dialogSessionId fail");
3552 return ERR_INVALID_VALUE;
3553 }
3554 if (!data.WriteBool(isAllow)) {
3555 TAG_LOGE(AAFwkTag::ABILITYMGR, "write dialogSessionId fail");
3556 return ERR_INVALID_VALUE;
3557 }
3558 auto error = SendRequest(AbilityManagerInterfaceCode::SEND_DIALOG_RESULT, data, reply, option);
3559 if (error != NO_ERROR) {
3560 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error);
3561 return error;
3562 }
3563 return reply.ReadInt32();
3564 }
3565
RegisterAbilityFirstFrameStateObserver(const sptr<IAbilityFirstFrameStateObserver> & observer,const std::string & targetBundleName)3566 int32_t AbilityManagerProxy::RegisterAbilityFirstFrameStateObserver(
3567 const sptr<IAbilityFirstFrameStateObserver> &observer, const std::string &targetBundleName)
3568 {
3569 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
3570 MessageParcel data;
3571 if (!WriteInterfaceToken(data)) {
3572 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
3573 return INNER_ERR;
3574 }
3575
3576 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
3577 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer null or write remote fail");
3578 return ERR_INVALID_VALUE;
3579 }
3580 if (!data.WriteString(targetBundleName)) {
3581 TAG_LOGE(AAFwkTag::ABILITYMGR, "write target bundleName fail");
3582 return ERR_INVALID_VALUE;
3583 }
3584
3585 MessageParcel reply;
3586 MessageOption option;
3587 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER,
3588 data, reply, option);
3589 if (ret != NO_ERROR) {
3590 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
3591 return ret;
3592 }
3593 return reply.ReadInt32();
3594 }
3595
UnregisterAbilityFirstFrameStateObserver(const sptr<IAbilityFirstFrameStateObserver> & observer)3596 int32_t AbilityManagerProxy::UnregisterAbilityFirstFrameStateObserver(
3597 const sptr<IAbilityFirstFrameStateObserver> &observer)
3598 {
3599 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
3600 MessageParcel data;
3601 if (!WriteInterfaceToken(data)) {
3602 TAG_LOGE(AAFwkTag::ABILITYMGR, "write Token fail");
3603 return INNER_ERR;
3604 }
3605 if (observer == nullptr || !data.WriteRemoteObject(observer->AsObject())) {
3606 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer null or write remote fail");
3607 return ERR_INVALID_VALUE;
3608 }
3609
3610 MessageParcel reply;
3611 MessageOption option;
3612 auto ret =
3613 SendRequest(AbilityManagerInterfaceCode::UNREGISTER_ABILITY_FIRST_FRAME_STATE_OBSERVER, data, reply, option);
3614 if (ret != NO_ERROR) {
3615 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
3616 return ret;
3617 }
3618 return reply.ReadInt32();
3619 }
3620
CompleteFirstFrameDrawing(int32_t sessionId)3621 void AbilityManagerProxy::CompleteFirstFrameDrawing(int32_t sessionId)
3622 {
3623 MessageParcel data;
3624 if (!WriteInterfaceToken(data)) {
3625 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
3626 return;
3627 }
3628 if (!data.WriteInt32(sessionId)) {
3629 TAG_LOGE(AAFwkTag::ABILITYMGR, "sessionId write failed");
3630 return;
3631 }
3632 MessageOption option;
3633 MessageParcel reply;
3634 auto error = SendRequest(AbilityManagerInterfaceCode::COMPLETE_FIRST_FRAME_DRAWING_BY_SCB, data, reply, option);
3635 if (error != NO_ERROR) {
3636 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3637 }
3638 }
3639 #endif
3640
GetAbilityRunningInfos(std::vector<AbilityRunningInfo> & info)3641 int AbilityManagerProxy::GetAbilityRunningInfos(std::vector<AbilityRunningInfo> &info)
3642 {
3643 MessageParcel data;
3644 MessageParcel reply;
3645 MessageOption option;
3646
3647 if (!WriteInterfaceToken(data)) {
3648 return INNER_ERR;
3649 }
3650
3651 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_RUNNING_INFO, data, reply, option);
3652 if (error != NO_ERROR) {
3653 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3654 return error;
3655 }
3656 error = GetParcelableInfos<AbilityRunningInfo>(reply, info);
3657 if (error != NO_ERROR) {
3658 TAG_LOGE(AAFwkTag::ABILITYMGR, "getParcelableInfos fail, error:%{public}d", error);
3659 return error;
3660 }
3661 return reply.ReadInt32();
3662 }
3663
GetExtensionRunningInfos(int upperLimit,std::vector<ExtensionRunningInfo> & info)3664 int AbilityManagerProxy::GetExtensionRunningInfos(int upperLimit, std::vector<ExtensionRunningInfo> &info)
3665 {
3666 MessageParcel data;
3667 MessageParcel reply;
3668 MessageOption option;
3669
3670 if (!WriteInterfaceToken(data)) {
3671 return INNER_ERR;
3672 }
3673
3674 if (!data.WriteInt32(upperLimit)) {
3675 TAG_LOGE(AAFwkTag::ABILITYMGR, "upperLimit write fail");
3676 return INNER_ERR;
3677 }
3678
3679 auto error = SendRequest(AbilityManagerInterfaceCode::GET_EXTENSION_RUNNING_INFO, data, reply, option);
3680 if (error != NO_ERROR) {
3681 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3682 return error;
3683 }
3684 error = GetParcelableInfos<ExtensionRunningInfo>(reply, info);
3685 if (error != NO_ERROR) {
3686 TAG_LOGE(AAFwkTag::ABILITYMGR, "getParcelableInfos fail, error: %{public}d", error);
3687 return error;
3688 }
3689 return reply.ReadInt32();
3690 }
3691
GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> & info)3692 int AbilityManagerProxy::GetProcessRunningInfos(std::vector<AppExecFwk::RunningProcessInfo> &info)
3693 {
3694 MessageParcel data;
3695 MessageParcel reply;
3696 MessageOption option;
3697
3698 if (!WriteInterfaceToken(data)) {
3699 return INNER_ERR;
3700 }
3701
3702 auto error = SendRequest(AbilityManagerInterfaceCode::GET_PROCESS_RUNNING_INFO, data, reply, option);
3703 if (error != NO_ERROR) {
3704 TAG_LOGE(AAFwkTag::ABILITYMGR, "request, error:%{public}d", error);
3705 return error;
3706 }
3707 error = GetParcelableInfos<AppExecFwk::RunningProcessInfo>(reply, info);
3708 if (error != NO_ERROR) {
3709 TAG_LOGE(AAFwkTag::ABILITYMGR, "getParcelable error:%{public}d", error);
3710 return error;
3711 }
3712 return reply.ReadInt32();
3713 }
3714
GetAllIntentExemptionInfo(std::vector<AppExecFwk::IntentExemptionInfo> & info)3715 int AbilityManagerProxy::GetAllIntentExemptionInfo(std::vector<AppExecFwk::IntentExemptionInfo> &info)
3716 {
3717 MessageParcel data;
3718 MessageParcel reply;
3719 MessageOption option;
3720
3721 if (!WriteInterfaceToken(data)) {
3722 return INNER_ERR;
3723 }
3724
3725 auto error = SendRequest(AbilityManagerInterfaceCode::GET_INTENT_EXEMPTION_INFO, data, reply, option);
3726 if (error != NO_ERROR) {
3727 TAG_LOGE(AAFwkTag::ABILITYMGR, "request, error:%{public}d", error);
3728 return error;
3729 }
3730 error = GetParcelableInfos<AppExecFwk::IntentExemptionInfo>(reply, info);
3731 if (error != NO_ERROR) {
3732 TAG_LOGE(AAFwkTag::ABILITYMGR, "getParcelable error:%{public}d", error);
3733 return error;
3734 }
3735 return reply.ReadInt32();
3736 }
3737
StartSyncRemoteMissions(const std::string & devId,bool fixConflict,int64_t tag)3738 int AbilityManagerProxy::StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag)
3739 {
3740 TAG_LOGI(AAFwkTag::ABILITYMGR, "called");
3741 MessageParcel data;
3742 MessageParcel reply;
3743 MessageOption option;
3744
3745 if (!WriteInterfaceToken(data)) {
3746 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
3747 return ERR_INVALID_VALUE;
3748 }
3749 if (!data.WriteString(devId)) {
3750 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId fail");
3751 return ERR_INVALID_VALUE;
3752 }
3753
3754 if (!data.WriteBool(fixConflict)) {
3755 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeBool fail");
3756 return ERR_INVALID_VALUE;
3757 }
3758
3759 if (!data.WriteInt64(tag)) {
3760 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInt64 fail");
3761 return ERR_INVALID_VALUE;
3762 }
3763
3764 auto error = SendRequest(AbilityManagerInterfaceCode::START_SYNC_MISSIONS, data, reply, option);
3765 if (error != NO_ERROR) {
3766 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3767 return error;
3768 }
3769 return reply.ReadInt32();
3770 }
3771
StopSyncRemoteMissions(const std::string & devId)3772 int32_t AbilityManagerProxy::StopSyncRemoteMissions(const std::string& devId)
3773 {
3774 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
3775 MessageParcel data;
3776 MessageParcel reply;
3777 MessageOption option;
3778
3779 if (!WriteInterfaceToken(data)) {
3780 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
3781 return ERR_INVALID_VALUE;
3782 }
3783 if (!data.WriteString(devId)) {
3784 TAG_LOGE(AAFwkTag::ABILITYMGR, "write deviceId fail");
3785 return ERR_INVALID_VALUE;
3786 }
3787 auto error = SendRequest(AbilityManagerInterfaceCode::STOP_SYNC_MISSIONS, data, reply, option);
3788 if (error != NO_ERROR) {
3789 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3790 return error;
3791 }
3792 return reply.ReadInt32();
3793 }
3794
UnRegisterMissionListener(const std::string & deviceId,const sptr<IRemoteMissionListener> & listener)3795 int AbilityManagerProxy::UnRegisterMissionListener(const std::string &deviceId,
3796 const sptr<IRemoteMissionListener> &listener)
3797 {
3798 MessageParcel data;
3799 MessageParcel reply;
3800 MessageOption option;
3801 if (!WriteInterfaceToken(data)) {
3802 return INNER_ERR;
3803 }
3804 if (!data.WriteString(deviceId)) {
3805 TAG_LOGE(AAFwkTag::ABILITYMGR, "deviceId write fail");
3806 return INNER_ERR;
3807 }
3808 if (!data.WriteRemoteObject(listener->AsObject())) {
3809 TAG_LOGE(AAFwkTag::ABILITYMGR, "listener write fail");
3810 return INNER_ERR;
3811 }
3812
3813 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_REMOTE_MISSION_LISTENER,
3814 data, reply, option);
3815 if (error != NO_ERROR) {
3816 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3817 return error;
3818 }
3819 return reply.ReadInt32();
3820 }
3821
StartAbilityByCall(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId,bool isSilent)3822 int AbilityManagerProxy::StartAbilityByCall(const Want &want, const sptr<IAbilityConnection> &connect,
3823 const sptr<IRemoteObject> &callerToken, int32_t accountId, bool isSilent)
3824 {
3825 std::string errMsg;
3826 return StartAbilityByCallWithErrMsg(want, connect, callerToken, accountId, errMsg, isSilent);
3827 }
3828
StartAbilityByCallWithErrMsg(const Want & want,const sptr<IAbilityConnection> & connect,const sptr<IRemoteObject> & callerToken,int32_t accountId,std::string & errMsg,bool isSilent)3829 int AbilityManagerProxy::StartAbilityByCallWithErrMsg(const Want &want, const sptr<IAbilityConnection> &connect,
3830 const sptr<IRemoteObject> &callerToken, int32_t accountId, std::string &errMsg, bool isSilent)
3831 {
3832 if (AppUtils::GetInstance().IsForbidStart()) {
3833 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
3834 return INNER_ERR;
3835 }
3836 TAG_LOGD(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::StartAbilityByCall begin.");
3837 int error;
3838 MessageParcel data;
3839 MessageParcel reply;
3840 MessageOption option;
3841
3842 if (!WriteInterfaceToken(data)) {
3843 errMsg = "WriteInterfaceToken error";
3844 return INNER_ERR;
3845 }
3846 if (!data.WriteParcelable(&want)) {
3847 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
3848 errMsg = "want write fail";
3849 return ERR_INVALID_VALUE;
3850 }
3851 if (connect == nullptr) {
3852 TAG_LOGE(AAFwkTag::ABILITYMGR, "resolve fail, null connect");
3853 errMsg = "null connect";
3854 return ERR_INVALID_VALUE;
3855 }
3856 if (!data.WriteRemoteObject(connect->AsObject())) {
3857 TAG_LOGE(AAFwkTag::ABILITYMGR, "resolve write fail");
3858 errMsg = "resolve write fail";
3859 return ERR_INVALID_VALUE;
3860 }
3861 if (callerToken) {
3862 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
3863 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and callerToken failed");
3864 errMsg = "callerToken write fail";
3865 return ERR_INVALID_VALUE;
3866 }
3867 } else {
3868 if (!data.WriteBool(false)) {
3869 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag failed");
3870 errMsg = "write flag failed";
3871 return ERR_INVALID_VALUE;
3872 }
3873 }
3874 if (!data.WriteInt32(accountId)) {
3875 TAG_LOGE(AAFwkTag::ABILITYMGR, "accountId write fail");
3876 errMsg = "accountId write fail";
3877 return ERR_INVALID_VALUE;
3878 }
3879
3880 if (!data.WriteBool(isSilent)) {
3881 TAG_LOGE(AAFwkTag::ABILITYMGR, "isSilent write fail");
3882 errMsg = "isSilent write fail";
3883 return ERR_INVALID_VALUE;
3884 }
3885
3886 error = SendRequest(AbilityManagerInterfaceCode::START_CALL_ABILITY, data, reply, option);
3887 if (error != NO_ERROR) {
3888 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3889 return error;
3890 }
3891 TAG_LOGD(AAFwkTag::ABILITYMGR, "AbilityManagerProxy::StartAbilityByCall end.");
3892 errMsg = reply.ReadString();
3893 return reply.ReadInt32();
3894 }
3895
CallRequestDone(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callStub)3896 void AbilityManagerProxy::CallRequestDone(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callStub)
3897 {
3898 MessageParcel data;
3899 MessageParcel reply;
3900 MessageOption option(MessageOption::TF_ASYNC);
3901
3902 if (token == nullptr) {
3903 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail, null token ");
3904 return;
3905 }
3906 if (callStub == nullptr) {
3907 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail, null callStub");
3908 return;
3909 }
3910
3911 if (!WriteInterfaceToken(data)) {
3912 return;
3913 }
3914 if (!data.WriteRemoteObject(token)) {
3915 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail, write token fail");
3916 return;
3917 }
3918 if (!data.WriteRemoteObject(callStub)) {
3919 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail, write callStub fail");
3920 return;
3921 }
3922 auto error = SendRequest(AbilityManagerInterfaceCode::CALL_REQUEST_DONE, data, reply, option);
3923 if (error != NO_ERROR) {
3924 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3925 return;
3926 }
3927 }
3928
ReleaseCall(const sptr<IAbilityConnection> & connect,const AppExecFwk::ElementName & element)3929 int AbilityManagerProxy::ReleaseCall(
3930 const sptr<IAbilityConnection> &connect, const AppExecFwk::ElementName &element)
3931 {
3932 int error;
3933 MessageParcel data;
3934 MessageParcel reply;
3935 MessageOption option;
3936 if (connect == nullptr) {
3937 TAG_LOGE(AAFwkTag::ABILITYMGR, "release fail, null connect");
3938 return ERR_INVALID_VALUE;
3939 }
3940 if (!WriteInterfaceToken(data)) {
3941 return INNER_ERR;
3942 }
3943 if (!data.WriteRemoteObject(connect->AsObject())) {
3944 TAG_LOGE(AAFwkTag::ABILITYMGR, "release connect write fail");
3945 return ERR_INVALID_VALUE;
3946 }
3947 if (!data.WriteParcelable(&element)) {
3948 TAG_LOGE(AAFwkTag::ABILITYMGR, "element error");
3949 return ERR_INVALID_VALUE;
3950 }
3951
3952 error = SendRequest(AbilityManagerInterfaceCode::RELEASE_CALL_ABILITY, data, reply, option);
3953 if (error != NO_ERROR) {
3954 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3955 return error;
3956 }
3957 return reply.ReadInt32();
3958 }
3959
GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> & callStub,sptr<IRemoteObject> & token)3960 void AbilityManagerProxy::GetAbilityTokenByCalleeObj(const sptr<IRemoteObject> &callStub, sptr<IRemoteObject> &token)
3961 {
3962 MessageParcel data;
3963 MessageParcel reply;
3964 MessageOption option;
3965 if (!WriteInterfaceToken(data)) {
3966 return;
3967 }
3968 if (!data.WriteRemoteObject(callStub)) {
3969 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeRemoteObject fail, write callStub fail");
3970 return;
3971 }
3972
3973 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_TOKEN, data, reply, option);
3974 if (error != NO_ERROR) {
3975 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3976 return;
3977 }
3978 token = sptr<IRemoteObject>(reply.ReadRemoteObject());
3979 }
3980
RegisterSnapshotHandler(const sptr<ISnapshotHandler> & handler)3981 int AbilityManagerProxy::RegisterSnapshotHandler(const sptr<ISnapshotHandler>& handler)
3982 {
3983 MessageParcel data;
3984 MessageParcel reply;
3985 MessageOption option;
3986 if (!WriteInterfaceToken(data)) {
3987 return INNER_ERR;
3988 }
3989 if (!data.WriteRemoteObject(handler->AsObject())) {
3990 TAG_LOGE(AAFwkTag::ABILITYMGR, "handler write failed");
3991 return INNER_ERR;
3992 }
3993 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SNAPSHOT_HANDLER, data, reply, option);
3994 if (error != NO_ERROR) {
3995 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
3996 return error;
3997 }
3998 return reply.ReadInt32();
3999 }
4000
SetAbilityController(const sptr<AppExecFwk::IAbilityController> & abilityController,bool imAStabilityTest)4001 int AbilityManagerProxy::SetAbilityController(const sptr<AppExecFwk::IAbilityController> &abilityController,
4002 bool imAStabilityTest)
4003 {
4004 if (!abilityController) {
4005 TAG_LOGE(AAFwkTag::ABILITYMGR, "null abilityController");
4006 return ERR_INVALID_VALUE;
4007 }
4008 MessageParcel data;
4009 MessageParcel reply;
4010 MessageOption option;
4011 if (!WriteInterfaceToken(data)) {
4012 return INNER_ERR;
4013 }
4014 if (!data.WriteRemoteObject(abilityController->AsObject())) {
4015 TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityController write fail");
4016 return ERR_INVALID_VALUE;
4017 }
4018 if (!data.WriteBool(imAStabilityTest)) {
4019 TAG_LOGE(AAFwkTag::ABILITYMGR, "imAStabilityTest write fail");
4020 return ERR_INVALID_VALUE;
4021 }
4022 auto error = SendRequest(AbilityManagerInterfaceCode::SET_ABILITY_CONTROLLER, data, reply, option);
4023 if (error != NO_ERROR) {
4024 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4025 return error;
4026 }
4027 return reply.ReadInt32();
4028 }
4029
IsRunningInStabilityTest()4030 bool AbilityManagerProxy::IsRunningInStabilityTest()
4031 {
4032 MessageParcel data;
4033 MessageParcel reply;
4034 MessageOption option;
4035 if (!WriteInterfaceToken(data)) {
4036 return false;
4037 }
4038 auto error = SendRequest(AbilityManagerInterfaceCode::IS_USER_A_STABILITY_TEST, data, reply, option);
4039 if (error != NO_ERROR) {
4040 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4041 return false;
4042 }
4043 return reply.ReadBool();
4044 }
4045
StartUserTest(const Want & want,const sptr<IRemoteObject> & observer)4046 int AbilityManagerProxy::StartUserTest(const Want &want, const sptr<IRemoteObject> &observer)
4047 {
4048 MessageParcel data;
4049 MessageParcel reply;
4050 MessageOption option;
4051
4052 if (!WriteInterfaceToken(data)) {
4053 return INNER_ERR;
4054 }
4055 if (!data.WriteParcelable(&want)) {
4056 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
4057 return INNER_ERR;
4058 }
4059 if (!data.WriteRemoteObject(observer)) {
4060 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write fail");
4061 return INNER_ERR;
4062 }
4063 auto error = SendRequest(AbilityManagerInterfaceCode::START_USER_TEST, data, reply, option);
4064 if (error != NO_ERROR) {
4065 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4066 return error;
4067 }
4068 return reply.ReadInt32();
4069 }
4070
FinishUserTest(const std::string & msg,const int64_t & resultCode,const std::string & bundleName)4071 int AbilityManagerProxy::FinishUserTest(
4072 const std::string &msg, const int64_t &resultCode, const std::string &bundleName)
4073 {
4074 MessageParcel data;
4075 MessageParcel reply;
4076 MessageOption option;
4077
4078 if (!WriteInterfaceToken(data)) {
4079 return INNER_ERR;
4080 }
4081 if (!data.WriteString(msg)) {
4082 TAG_LOGE(AAFwkTag::ABILITYMGR, "msg write fail");
4083 return ERR_INVALID_VALUE;
4084 }
4085 if (!data.WriteInt64(resultCode)) {
4086 TAG_LOGE(AAFwkTag::ABILITYMGR, "resultCode write fail");
4087 return ERR_INVALID_VALUE;
4088 }
4089 if (!data.WriteString(bundleName)) {
4090 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
4091 return ERR_INVALID_VALUE;
4092 }
4093
4094 auto error = SendRequest(AbilityManagerInterfaceCode::FINISH_USER_TEST, data, reply, option);
4095 if (error != NO_ERROR) {
4096 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4097 return error;
4098 }
4099 return reply.ReadInt32();
4100 }
4101
GetTopAbility(sptr<IRemoteObject> & token)4102 int AbilityManagerProxy::GetTopAbility(sptr<IRemoteObject> &token)
4103 {
4104 MessageParcel data;
4105 MessageParcel reply;
4106 MessageOption option;
4107
4108 if (!WriteInterfaceToken(data)) {
4109 return INNER_ERR;
4110 }
4111
4112 auto error = SendRequest(AbilityManagerInterfaceCode::GET_TOP_ABILITY_TOKEN, data, reply, option);
4113 if (error != NO_ERROR) {
4114 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4115 return error;
4116 }
4117
4118 token = sptr<IRemoteObject>(reply.ReadRemoteObject());
4119 if (!token) {
4120 TAG_LOGE(AAFwkTag::ABILITYMGR, "read IRemoteObject fail");
4121 return ERR_UNKNOWN_OBJECT;
4122 }
4123
4124 return reply.ReadInt32();
4125 }
4126
CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId,bool & isFocused)4127 int AbilityManagerProxy::CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId, bool& isFocused)
4128 {
4129 MessageParcel data;
4130 MessageParcel reply;
4131 MessageOption option;
4132
4133 if (!WriteInterfaceToken(data)) {
4134 return INNER_ERR;
4135 }
4136
4137 if (!data.WriteUint32(uiExtensionTokenId)) {
4138 TAG_LOGE(AAFwkTag::ABILITYMGR, "uiExtensionTokenId write fail");
4139 return ERR_INVALID_VALUE;
4140 }
4141
4142 auto error = SendRequest(AbilityManagerInterfaceCode::CHECK_UI_EXTENSION_IS_FOCUSED, data, reply, option);
4143 if (error != NO_ERROR) {
4144 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4145 return error;
4146 }
4147
4148 isFocused = reply.ReadBool();
4149 return NO_ERROR;
4150 }
4151
DelegatorDoAbilityForeground(const sptr<IRemoteObject> & token)4152 int AbilityManagerProxy::DelegatorDoAbilityForeground(const sptr<IRemoteObject> &token)
4153 {
4154 MessageParcel data;
4155 MessageParcel reply;
4156 MessageOption option;
4157
4158 if (!WriteInterfaceToken(data)) {
4159 return INNER_ERR;
4160 }
4161
4162 if (!data.WriteRemoteObject(token)) {
4163 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
4164 return ERR_INVALID_VALUE;
4165 }
4166
4167 auto error = SendRequest(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_FOREGROUND,
4168 data, reply, option);
4169 if (error != NO_ERROR) {
4170 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4171 return error;
4172 }
4173
4174 return reply.ReadInt32();
4175 }
4176
DelegatorDoAbilityBackground(const sptr<IRemoteObject> & token)4177 int AbilityManagerProxy::DelegatorDoAbilityBackground(const sptr<IRemoteObject> &token)
4178 {
4179 MessageParcel data;
4180 MessageParcel reply;
4181 MessageOption option;
4182
4183 if (!WriteInterfaceToken(data)) {
4184 return INNER_ERR;
4185 }
4186
4187 if (!data.WriteRemoteObject(token)) {
4188 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
4189 return ERR_INVALID_VALUE;
4190 }
4191
4192 auto error = SendRequest(AbilityManagerInterfaceCode::DELEGATOR_DO_ABILITY_BACKGROUND,
4193 data, reply, option);
4194 if (error != NO_ERROR) {
4195 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4196 return error;
4197 }
4198
4199 return reply.ReadInt32();
4200 }
4201
DoAbilityForeground(const sptr<IRemoteObject> & token,uint32_t flag)4202 int AbilityManagerProxy::DoAbilityForeground(const sptr<IRemoteObject> &token, uint32_t flag)
4203 {
4204 MessageParcel data;
4205 MessageParcel reply;
4206 MessageOption option;
4207
4208 if (!WriteInterfaceToken(data)) {
4209 return INNER_ERR;
4210 }
4211
4212 if (!data.WriteRemoteObject(token)) {
4213 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
4214 return ERR_INVALID_VALUE;
4215 }
4216
4217 if (!data.WriteUint32(flag)) {
4218 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
4219 return ERR_INVALID_VALUE;
4220 }
4221
4222 auto error = SendRequest(AbilityManagerInterfaceCode::DO_ABILITY_FOREGROUND, data, reply, option);
4223 if (error != NO_ERROR) {
4224 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4225 return error;
4226 }
4227
4228 return reply.ReadInt32();
4229 }
4230
DoAbilityBackground(const sptr<IRemoteObject> & token,uint32_t flag)4231 int AbilityManagerProxy::DoAbilityBackground(const sptr<IRemoteObject> &token, uint32_t flag)
4232 {
4233 MessageParcel data;
4234 MessageParcel reply;
4235 MessageOption option;
4236
4237 if (!WriteInterfaceToken(data)) {
4238 return INNER_ERR;
4239 }
4240
4241 if (!data.WriteRemoteObject(token)) {
4242 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
4243 return ERR_INVALID_VALUE;
4244 }
4245
4246 if (!data.WriteUint32(flag)) {
4247 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
4248 return ERR_INVALID_VALUE;
4249 }
4250
4251 auto error = SendRequest(AbilityManagerInterfaceCode::DO_ABILITY_BACKGROUND, data, reply, option);
4252 if (error != NO_ERROR) {
4253 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4254 return error;
4255 }
4256
4257 return reply.ReadInt32();
4258 }
4259
GetMissionIdByToken(const sptr<IRemoteObject> & token)4260 int32_t AbilityManagerProxy::GetMissionIdByToken(const sptr<IRemoteObject> &token)
4261 {
4262 if (!token) {
4263 TAG_LOGE(AAFwkTag::ABILITYMGR, "token null");
4264 return -1;
4265 }
4266
4267 MessageParcel data;
4268 MessageParcel reply;
4269 MessageOption option;
4270 if (!WriteInterfaceToken(data)) {
4271 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4272 return -1;
4273 }
4274
4275 if (!data.WriteRemoteObject(token)) {
4276 TAG_LOGE(AAFwkTag::ABILITYMGR, "data write fail");
4277 return -1;
4278 }
4279
4280 auto error = SendRequest(AbilityManagerInterfaceCode::GET_MISSION_ID_BY_ABILITY_TOKEN,
4281 data, reply, option);
4282 if (error != NO_ERROR) {
4283 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4284 return -1;
4285 }
4286
4287 return reply.ReadInt32();
4288 }
4289
FreeInstallAbilityFromRemote(const Want & want,const sptr<IRemoteObject> & callback,int32_t userId,int requestCode)4290 int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sptr<IRemoteObject> &callback,
4291 int32_t userId, int requestCode)
4292 {
4293 MessageParcel data;
4294 MessageParcel reply;
4295 MessageOption option;
4296 if (!WriteInterfaceToken(data)) {
4297 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4298 return INNER_ERR;
4299 }
4300
4301 if (!data.WriteParcelable(&want)) {
4302 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
4303 return INNER_ERR;
4304 }
4305
4306 if (!data.WriteRemoteObject(callback)) {
4307 TAG_LOGE(AAFwkTag::ABILITYMGR, "callback write fail");
4308 return INNER_ERR;
4309 }
4310
4311 if (!data.WriteInt32(userId)) {
4312 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
4313 return INNER_ERR;
4314 }
4315
4316 if (!data.WriteInt32(requestCode)) {
4317 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
4318 return INNER_ERR;
4319 }
4320
4321 auto error = SendRequest(AbilityManagerInterfaceCode::FREE_INSTALL_ABILITY_FROM_REMOTE,
4322 data, reply, option);
4323 if (error != NO_ERROR) {
4324 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4325 return error;
4326 }
4327
4328 return reply.ReadInt32();
4329 }
4330
AddFreeInstallObserver(const sptr<IRemoteObject> & callerToken,const sptr<AbilityRuntime::IFreeInstallObserver> & observer)4331 int AbilityManagerProxy::AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
4332 const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
4333 {
4334 MessageParcel data;
4335 MessageParcel reply;
4336 MessageOption option;
4337 if (observer == nullptr) {
4338 TAG_LOGE(AAFwkTag::ABILITYMGR, "null observer");
4339 return INNER_ERR;
4340 }
4341
4342 if (!WriteInterfaceToken(data)) {
4343 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4344 return INNER_ERR;
4345 }
4346
4347 if (callerToken) {
4348 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
4349 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and callerToken fail");
4350 return INNER_ERR;
4351 }
4352 } else {
4353 if (!data.WriteBool(false)) {
4354 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
4355 return INNER_ERR;
4356 }
4357 }
4358
4359 if (!data.WriteRemoteObject(observer->AsObject())) {
4360 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write fail");
4361 return INNER_ERR;
4362 }
4363
4364 auto error = SendRequest(AbilityManagerInterfaceCode::ADD_FREE_INSTALL_OBSERVER, data, reply, option);
4365 if (error != NO_ERROR) {
4366 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4367 return error;
4368 }
4369 return reply.ReadInt32();
4370 }
4371
DumpAbilityInfoDone(std::vector<std::string> & infos,const sptr<IRemoteObject> & callerToken)4372 int AbilityManagerProxy::DumpAbilityInfoDone(std::vector<std::string> &infos, const sptr<IRemoteObject> &callerToken)
4373 {
4374 MessageParcel data;
4375 MessageParcel reply;
4376 MessageOption option;
4377 if (!WriteInterfaceToken(data)) {
4378 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4379 return INNER_ERR;
4380 }
4381
4382 if (!data.WriteStringVector(infos)) {
4383 TAG_LOGE(AAFwkTag::ABILITYMGR, "infos write fail");
4384 return INNER_ERR;
4385 }
4386
4387 if (!data.WriteRemoteObject(callerToken)) {
4388 TAG_LOGE(AAFwkTag::ABILITYMGR, "infos write fail");
4389 return INNER_ERR;
4390 }
4391
4392 auto error = SendRequest(AbilityManagerInterfaceCode::DUMP_ABILITY_INFO_DONE, data, reply, option);
4393 if (error != NO_ERROR) {
4394 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4395 return error;
4396 }
4397
4398 return reply.ReadInt32();
4399 }
4400
IsValidMissionIds(const std::vector<int32_t> & missionIds,std::vector<MissionValidResult> & results)4401 int32_t AbilityManagerProxy::IsValidMissionIds(
4402 const std::vector<int32_t> &missionIds, std::vector<MissionValidResult> &results)
4403 {
4404 TAG_LOGI(AAFwkTag::ABILITYMGR, "call, quert size:%{public}zu", missionIds.size());
4405 MessageParcel data;
4406 MessageParcel reply;
4407 MessageOption option;
4408 if (!WriteInterfaceToken(data)) {
4409 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4410 return INNER_ERR;
4411 }
4412
4413 constexpr int32_t MAX_COUNT = 20;
4414 int32_t num = static_cast<int32_t>(missionIds.size() > MAX_COUNT ? MAX_COUNT : missionIds.size());
4415 if (!data.WriteInt32(num)) {
4416 TAG_LOGE(AAFwkTag::ABILITYMGR, "write num fail");
4417 return INNER_ERR;
4418 }
4419 for (auto i = 0; i < num; ++i) {
4420 if (!data.WriteInt32(missionIds.at(i))) {
4421 TAG_LOGE(AAFwkTag::ABILITYMGR, "write missionId fail");
4422 return INNER_ERR;
4423 }
4424 }
4425
4426 auto error = SendRequest(AbilityManagerInterfaceCode::QUERY_MISSION_VAILD, data, reply, option);
4427 if (error != NO_ERROR) {
4428 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4429 return error;
4430 }
4431
4432 auto resultCode = reply.ReadInt32();
4433 if (resultCode != ERR_OK) {
4434 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", resultCode);
4435 return resultCode;
4436 }
4437
4438 auto infoSize = reply.ReadInt32();
4439 for (auto i = 0; i < infoSize && i < MAX_COUNT; ++i) {
4440 std::unique_ptr<MissionValidResult> info(reply.ReadParcelable<MissionValidResult>());
4441 if (!info) {
4442 TAG_LOGE(AAFwkTag::ABILITYMGR, "read result fail");
4443 return INNER_ERR;
4444 }
4445 results.emplace_back(*info);
4446 }
4447
4448 return resultCode;
4449 }
4450
VerifyPermission(const std::string & permission,int pid,int uid)4451 int AbilityManagerProxy::VerifyPermission(const std::string &permission, int pid, int uid)
4452 {
4453 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
4454 MessageParcel data;
4455 MessageParcel reply;
4456 MessageOption option;
4457 if (!WriteInterfaceToken(data)) {
4458 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4459 return INNER_ERR;
4460 }
4461
4462 if (!data.WriteString(permission)) {
4463 TAG_LOGE(AAFwkTag::ABILITYMGR, "permission write fail");
4464 return INNER_ERR;
4465 }
4466
4467 if (!data.WriteInt32(pid)) {
4468 TAG_LOGE(AAFwkTag::ABILITYMGR, "pid write fail");
4469 return INNER_ERR;
4470 }
4471
4472 if (!data.WriteInt32(uid)) {
4473 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write fail");
4474 return INNER_ERR;
4475 }
4476
4477 auto error = SendRequest(AbilityManagerInterfaceCode::VERIFY_PERMISSION, data, reply, option);
4478 if (error != NO_ERROR) {
4479 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4480 return error;
4481 }
4482
4483 return reply.ReadInt32();
4484 }
4485
RequestDialogService(const Want & want,const sptr<IRemoteObject> & callerToken)4486 int32_t AbilityManagerProxy::RequestDialogService(const Want &want, const sptr<IRemoteObject> &callerToken)
4487 {
4488 TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
4489 if (!callerToken) {
4490 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken invalid");
4491 return ERR_INVALID_CALLER;
4492 }
4493
4494 MessageParcel data;
4495 MessageParcel reply;
4496 MessageOption option;
4497 if (!WriteInterfaceToken(data)) {
4498 return INNER_ERR;
4499 }
4500
4501 if (!data.WriteParcelable(&want)) {
4502 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
4503 return INNER_ERR;
4504 }
4505
4506 if (!data.WriteRemoteObject(callerToken)) {
4507 TAG_LOGE(AAFwkTag::ABILITYMGR, "infos write fail");
4508 return INNER_ERR;
4509 }
4510
4511 auto error = SendRequest(AbilityManagerInterfaceCode::REQUEST_DIALOG_SERVICE, data, reply, option);
4512 if (error != NO_ERROR) {
4513 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4514 return error;
4515 }
4516 return reply.ReadInt32();
4517 }
4518
ReportDrawnCompleted(const sptr<IRemoteObject> & callerToken)4519 int32_t AbilityManagerProxy::ReportDrawnCompleted(const sptr<IRemoteObject> &callerToken)
4520 {
4521 Ability_MANAGER_HITRACE_CHAIN_NAME("ReportDrawnCompleted", HITRACE_FLAG_INCLUDE_ASYNC);
4522 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
4523 if (callerToken == nullptr) {
4524 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
4525 return INNER_ERR;
4526 }
4527
4528 MessageParcel data;
4529 MessageParcel reply;
4530 MessageOption option;
4531 if (!WriteInterfaceToken(data)) {
4532 return INNER_ERR;
4533 }
4534
4535 if (!data.WriteRemoteObject(callerToken)) {
4536 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken write fail");
4537 return INNER_ERR;
4538 }
4539
4540 auto error = SendRequest(AbilityManagerInterfaceCode::REPORT_DRAWN_COMPLETED, data, reply, option);
4541 if (error != NO_ERROR) {
4542 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4543 return error;
4544 }
4545 return reply.ReadInt32();
4546 }
4547
AcquireShareData(const int32_t & missionId,const sptr<IAcquireShareDataCallback> & shareData)4548 int32_t AbilityManagerProxy::AcquireShareData(
4549 const int32_t &missionId, const sptr<IAcquireShareDataCallback> &shareData)
4550 {
4551 TAG_LOGI(AAFwkTag::ABILITYMGR, "start");
4552 MessageParcel data;
4553 MessageParcel reply;
4554 MessageOption option;
4555
4556 if (!WriteInterfaceToken(data)) {
4557 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4558 return INNER_ERR;
4559 }
4560
4561 if (!data.WriteInt32(missionId)) {
4562 TAG_LOGE(AAFwkTag::ABILITYMGR, "missionId write fail");
4563 return INNER_ERR;
4564 }
4565
4566 if (shareData == nullptr || !data.WriteRemoteObject(shareData->AsObject())) {
4567 TAG_LOGE(AAFwkTag::ABILITYMGR, "shareData write fail");
4568 return INNER_ERR;
4569 }
4570
4571 int32_t error = SendRequest(AbilityManagerInterfaceCode::ACQUIRE_SHARE_DATA, data, reply, option);
4572 if (error != NO_ERROR) {
4573 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error);
4574 return INNER_ERR;
4575 }
4576 TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
4577 return reply.ReadInt32();
4578 }
4579
ShareDataDone(const sptr<IRemoteObject> & token,const int32_t & resultCode,const int32_t & uniqueId,WantParams & wantParam)4580 int32_t AbilityManagerProxy::ShareDataDone(
4581 const sptr<IRemoteObject> &token, const int32_t &resultCode, const int32_t &uniqueId, WantParams &wantParam)
4582 {
4583 TAG_LOGI(AAFwkTag::ABILITYMGR, "start");
4584 MessageParcel data;
4585 MessageParcel reply;
4586 MessageOption option(MessageOption::TF_ASYNC);
4587
4588 if (!WriteInterfaceToken(data)) {
4589 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4590 return INNER_ERR;
4591 }
4592
4593 if (!data.WriteRemoteObject(token)) {
4594 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write fail");
4595 return INNER_ERR;
4596 }
4597
4598 if (!data.WriteInt32(resultCode)) {
4599 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
4600 return INNER_ERR;
4601 }
4602
4603 if (!data.WriteInt32(uniqueId)) {
4604 TAG_LOGE(AAFwkTag::ABILITYMGR, "uniqueId write fail");
4605 return INNER_ERR;
4606 }
4607
4608 if (!data.WriteParcelable(&wantParam)) {
4609 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParam write fail");
4610 return INNER_ERR;
4611 }
4612
4613 int32_t error = SendRequest(AbilityManagerInterfaceCode::SHARE_DATA_DONE, data, reply, option);
4614 if (error != NO_ERROR) {
4615 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err: %{public}d", error);
4616 return error;
4617 }
4618 TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
4619 return reply.ReadInt32();
4620 }
4621
ForceExitApp(const int32_t pid,const ExitReason & exitReason)4622 int32_t AbilityManagerProxy::ForceExitApp(const int32_t pid, const ExitReason &exitReason)
4623 {
4624 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4625 MessageParcel data;
4626 MessageParcel reply;
4627 MessageOption option(MessageOption::TF_ASYNC);
4628
4629 if (!WriteInterfaceToken(data)) {
4630 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4631 return INNER_ERR;
4632 }
4633 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, pid);
4634 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4635
4636 int32_t error = SendRequest(AbilityManagerInterfaceCode::FORCE_EXIT_APP, data, reply, option);
4637 if (error != NO_ERROR) {
4638 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
4639 return error;
4640 }
4641
4642 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4643 return reply.ReadInt32();
4644 }
4645
RecordAppExitReason(const ExitReason & exitReason)4646 int32_t AbilityManagerProxy::RecordAppExitReason(const ExitReason &exitReason)
4647 {
4648 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4649 MessageParcel data;
4650 MessageParcel reply;
4651 MessageOption option;
4652
4653 if (!WriteInterfaceToken(data)) {
4654 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token fail");
4655 return INNER_ERR;
4656 }
4657 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4658
4659 int32_t error = SendRequest(AbilityManagerInterfaceCode::RECORD_APP_EXIT_REASON, data, reply, option);
4660 if (error != NO_ERROR) {
4661 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
4662 return error;
4663 }
4664
4665 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4666 return reply.ReadInt32();
4667 }
4668
RecordProcessExitReason(const int32_t pid,const ExitReason & exitReason)4669 int32_t AbilityManagerProxy::RecordProcessExitReason(const int32_t pid, const ExitReason &exitReason)
4670 {
4671 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4672 MessageParcel data;
4673 MessageParcel reply;
4674 MessageOption option;
4675
4676 if (!WriteInterfaceToken(data)) {
4677 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4678 return INNER_ERR;
4679 }
4680 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, pid);
4681 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4682
4683 int32_t error = SendRequest(AbilityManagerInterfaceCode::RECORD_PROCESS_EXIT_REASON, data, reply, option);
4684 if (error != NO_ERROR) {
4685 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
4686 return error;
4687 }
4688
4689 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4690 return reply.ReadInt32();
4691 }
4692
RecordProcessExitReason(int32_t pid,int32_t uid,const ExitReason & exitReason)4693 int32_t AbilityManagerProxy::RecordProcessExitReason(int32_t pid, int32_t uid, const ExitReason &exitReason)
4694 {
4695 TAG_LOGD(AAFwkTag::ABILITYMGR, "start.");
4696 MessageParcel data;
4697 MessageParcel reply;
4698 MessageOption option;
4699
4700 if (!WriteInterfaceToken(data)) {
4701 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4702 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
4703 }
4704 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, pid);
4705 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, uid);
4706 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &exitReason);
4707
4708 int32_t error = SendRequest(AbilityManagerInterfaceCode::RECORD_PROCESS_EXIT_REASON_PLUS, data, reply, option);
4709 if (error != NO_ERROR) {
4710 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
4711 return error;
4712 }
4713
4714 TAG_LOGD(AAFwkTag::ABILITYMGR, "end.");
4715 return reply.ReadInt32();
4716 }
4717
SetRootSceneSession(const sptr<IRemoteObject> & rootSceneSession)4718 void AbilityManagerProxy::SetRootSceneSession(const sptr<IRemoteObject> &rootSceneSession)
4719 {
4720 MessageParcel data;
4721 if (!WriteInterfaceToken(data)) {
4722 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4723 return;
4724 }
4725 if (!data.WriteRemoteObject(rootSceneSession)) {
4726 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail");
4727 return;
4728 }
4729
4730 MessageParcel reply;
4731 MessageOption option(MessageOption::TF_ASYNC);
4732 auto error = SendRequest(AbilityManagerInterfaceCode::SET_ROOT_SCENE_SESSION, data, reply, option);
4733 if (error != NO_ERROR) {
4734 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4735 }
4736 }
4737
CallUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool & isColdStart)4738 void AbilityManagerProxy::CallUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isColdStart)
4739 {
4740 MessageParcel data;
4741 if (!WriteInterfaceToken(data)) {
4742 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4743 return;
4744 }
4745 if (sessionInfo) {
4746 ExtendMaxIpcCapacityForWant(sessionInfo->want, data);
4747 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
4748 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
4749 return;
4750 }
4751 } else {
4752 if (!data.WriteBool(false)) {
4753 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
4754 return;
4755 }
4756 }
4757
4758 MessageParcel reply;
4759 MessageOption option;
4760 auto error = SendRequest(AbilityManagerInterfaceCode::CALL_ABILITY_BY_SCB, data, reply, option);
4761 if (error != NO_ERROR) {
4762 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4763 return;
4764 }
4765 isColdStart = reply.ReadBool();
4766 }
4767
StartSpecifiedAbilityBySCB(const Want & want)4768 int32_t AbilityManagerProxy::StartSpecifiedAbilityBySCB(const Want &want)
4769 {
4770 if (AppUtils::GetInstance().IsForbidStart()) {
4771 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
4772 return INNER_ERR;
4773 }
4774 MessageParcel data;
4775 if (!WriteInterfaceToken(data)) {
4776 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4777 return ERR_NATIVE_IPC_PARCEL_FAILED;
4778 }
4779
4780 if (!data.WriteParcelable(&want)) {
4781 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
4782 return ERR_NATIVE_IPC_PARCEL_FAILED;
4783 }
4784
4785 MessageParcel reply;
4786 MessageOption option(MessageOption::TF_SYNC);
4787 auto error = SendRequest(AbilityManagerInterfaceCode::START_SPECIFIED_ABILITY_BY_SCB, data, reply, option);
4788 if (error != NO_ERROR) {
4789 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4790 return error;
4791 }
4792 return reply.ReadInt32();
4793 }
4794
NotifySaveAsResult(const Want & want,int resultCode,int requestCode)4795 int32_t AbilityManagerProxy::NotifySaveAsResult(const Want &want, int resultCode, int requestCode)
4796 {
4797 MessageParcel data;
4798 if (!WriteInterfaceToken(data)) {
4799 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4800 return INNER_ERR;
4801 }
4802 if (!data.WriteParcelable(&want)) {
4803 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeWantObject fail");
4804 return INNER_ERR;
4805 }
4806
4807 if (!data.WriteInt32(resultCode)) {
4808 TAG_LOGE(AAFwkTag::ABILITYMGR, "resultCode write fail");
4809 return INNER_ERR;
4810 }
4811
4812 if (!data.WriteInt32(requestCode)) {
4813 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
4814 return INNER_ERR;
4815 }
4816
4817 MessageParcel reply;
4818 MessageOption option;
4819 auto error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_SAVE_AS_RESULT, data, reply, option);
4820 if (error != NO_ERROR) {
4821 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4822 }
4823
4824 return reply.ReadInt32();
4825 }
4826
SetSessionManagerService(const sptr<IRemoteObject> & sessionManagerService)4827 int32_t AbilityManagerProxy::SetSessionManagerService(const sptr<IRemoteObject> &sessionManagerService)
4828 {
4829 TAG_LOGI(AAFwkTag::ABILITYMGR, "start");
4830 MessageParcel data;
4831 MessageParcel reply;
4832 MessageOption option;
4833
4834 if (!WriteInterfaceToken(data)) {
4835 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4836 return INNER_ERR;
4837 }
4838
4839 if (!data.WriteRemoteObject(sessionManagerService)) {
4840 TAG_LOGE(AAFwkTag::ABILITYMGR, "token write fail");
4841 return INNER_ERR;
4842 }
4843
4844 int32_t error = SendRequest(AbilityManagerInterfaceCode::SET_SESSIONMANAGERSERVICE, data, reply, option);
4845 if (error != NO_ERROR) {
4846 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
4847 return error;
4848 }
4849 TAG_LOGI(AAFwkTag::ABILITYMGR, "end");
4850 return reply.ReadInt32();
4851 }
4852
RegisterIAbilityManagerCollaborator(int32_t type,const sptr<IAbilityManagerCollaborator> & impl)4853 int32_t AbilityManagerProxy::RegisterIAbilityManagerCollaborator(
4854 int32_t type, const sptr<IAbilityManagerCollaborator> &impl)
4855 {
4856 if (!impl) {
4857 TAG_LOGE(AAFwkTag::ABILITYMGR, "null impl");
4858 return ERR_INVALID_VALUE;
4859 }
4860 MessageParcel data;
4861 MessageParcel reply;
4862 MessageOption option;
4863
4864 if (!WriteInterfaceToken(data)) {
4865 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4866 return INNER_ERR;
4867 }
4868 if (!data.WriteInt32(type)) {
4869 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write fail");
4870 return INNER_ERR;
4871 }
4872 if (!data.WriteRemoteObject(impl->AsObject())) {
4873 TAG_LOGE(AAFwkTag::ABILITYMGR, "impl write fail");
4874 return INNER_ERR;
4875 }
4876
4877 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_COLLABORATOR, data, reply, option);
4878 if (ret != NO_ERROR) {
4879 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
4880 return ret;
4881 }
4882 return reply.ReadInt32();
4883 }
4884
UnregisterIAbilityManagerCollaborator(int32_t type)4885 int32_t AbilityManagerProxy::UnregisterIAbilityManagerCollaborator(int32_t type)
4886 {
4887 MessageParcel data;
4888 MessageParcel reply;
4889 MessageOption option;
4890
4891 if (!WriteInterfaceToken(data)) {
4892 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4893 return INNER_ERR;
4894 }
4895 if (!data.WriteInt32(type)) {
4896 TAG_LOGE(AAFwkTag::ABILITYMGR, "type write fail");
4897 return INNER_ERR;
4898 }
4899
4900 auto ret = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_COLLABORATOR, data, reply, option);
4901 if (ret != NO_ERROR) {
4902 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
4903 return ret;
4904 }
4905 return reply.ReadInt32();
4906 }
4907
GetAbilityManagerCollaborator()4908 sptr<IAbilityManagerCollaborator> AbilityManagerProxy::GetAbilityManagerCollaborator()
4909 {
4910 MessageParcel data;
4911 MessageParcel reply;
4912 MessageOption option;
4913
4914 if (!WriteInterfaceToken(data)) {
4915 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4916 return nullptr;
4917 }
4918
4919 auto ret = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_MANAGER_COLLABORATOR, data, reply, option);
4920 if (ret != NO_ERROR) {
4921 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
4922 return nullptr;
4923 }
4924 auto remoteObj = reply.ReadRemoteObject();
4925 if (!remoteObj) {
4926 TAG_LOGE(AAFwkTag::ABILITYMGR, "remote object null");
4927 return nullptr;
4928 }
4929 sptr<IAbilityManagerCollaborator> collaborator = iface_cast<IAbilityManagerCollaborator>(remoteObj);
4930 return collaborator;
4931 }
4932
RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate)4933 int32_t AbilityManagerProxy::RegisterStatusBarDelegate(sptr<AbilityRuntime::IStatusBarDelegate> delegate)
4934 {
4935 MessageParcel data;
4936 MessageParcel reply;
4937 MessageOption option;
4938
4939 if (delegate == nullptr) {
4940 TAG_LOGE(AAFwkTag::ABILITYMGR, "null delegate");
4941 return ERR_NULL_OBJECT;
4942 }
4943
4944 if (!WriteInterfaceToken(data)) {
4945 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4946 return ERR_NATIVE_IPC_PARCEL_FAILED;
4947 }
4948 if (!data.WriteRemoteObject(delegate->AsObject())) {
4949 TAG_LOGE(AAFwkTag::ABILITYMGR, "write delegate fail");
4950 return ERR_NATIVE_IPC_PARCEL_FAILED;
4951 }
4952
4953 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_STATUS_BAR_DELEGATE, data, reply, option);
4954 if (ret != NO_ERROR) {
4955 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
4956 return ret;
4957 }
4958 return reply.ReadInt32();
4959 }
4960
KillProcessWithPrepareTerminate(const std::vector<int32_t> & pids)4961 int32_t AbilityManagerProxy::KillProcessWithPrepareTerminate(const std::vector<int32_t>& pids)
4962 {
4963 MessageParcel data;
4964 MessageParcel reply;
4965 MessageOption option(MessageOption::TF_ASYNC);
4966
4967 if (!WriteInterfaceToken(data)) {
4968 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
4969 return ERR_NATIVE_IPC_PARCEL_FAILED;
4970 }
4971 if (!data.WriteUint32(pids.size())) {
4972 TAG_LOGE(AAFwkTag::ABILITYMGR, "write size fail");
4973 return ERR_NATIVE_IPC_PARCEL_FAILED;
4974 }
4975 for (const auto &pid : pids) {
4976 if (!data.WriteInt32(pid)) {
4977 TAG_LOGE(AAFwkTag::ABILITYMGR, "write pid fail");
4978 return ERR_NATIVE_IPC_PARCEL_FAILED;
4979 }
4980 }
4981
4982 auto ret = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS_WITH_PREPARE_TERMINATE, data, reply, option);
4983 if (ret != NO_ERROR) {
4984 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
4985 }
4986 return ret;
4987 }
4988
KillProcessWithReason(int32_t pid,const ExitReason & reason)4989 int32_t AbilityManagerProxy::KillProcessWithReason(int32_t pid, const ExitReason &reason)
4990 {
4991 MessageParcel data;
4992 MessageParcel reply;
4993 MessageOption option;
4994 if (!WriteInterfaceToken(data)) {
4995 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
4996 return ERR_NATIVE_IPC_PARCEL_FAILED;
4997 }
4998 if (!data.WriteInt32(pid)) {
4999 TAG_LOGE(AAFwkTag::APPMGR, "parcel pid failed");
5000 return ERR_NATIVE_IPC_PARCEL_FAILED;
5001 }
5002 if (!data.WriteParcelable(&reason)) {
5003 TAG_LOGE(AAFwkTag::APPMGR, "Write reason failed");
5004 return ERR_NATIVE_IPC_PARCEL_FAILED;
5005 }
5006 int32_t ret =
5007 SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS_WITH_REASON, data, reply, option);
5008 if (ret != NO_ERROR) {
5009 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
5010 return ret;
5011 }
5012 return reply.ReadInt32();
5013 }
5014
RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> & callback)5015 int32_t AbilityManagerProxy::RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
5016 {
5017 MessageParcel data;
5018 MessageParcel reply;
5019 MessageOption option;
5020
5021 if (!WriteInterfaceToken(data)) {
5022 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5023 return INNER_ERR;
5024 }
5025 if (!data.WriteRemoteObject(callback)) {
5026 TAG_LOGE(AAFwkTag::ABILITYMGR, "callback write fail");
5027 return INNER_ERR;
5028 }
5029
5030 auto ret = SendRequest(AbilityManagerInterfaceCode::REGISTER_AUTO_STARTUP_SYSTEM_CALLBACK, data, reply, option);
5031 if (ret != NO_ERROR) {
5032 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5033 return ret;
5034 }
5035 return reply.ReadInt32();
5036 }
5037
UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> & callback)5038 int32_t AbilityManagerProxy::UnregisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
5039 {
5040 MessageParcel data;
5041 MessageParcel reply;
5042 MessageOption option;
5043
5044 if (!WriteInterfaceToken(data)) {
5045 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5046 return INNER_ERR;
5047 }
5048 if (!data.WriteRemoteObject(callback)) {
5049 TAG_LOGE(AAFwkTag::ABILITYMGR, "callback write fail");
5050 return INNER_ERR;
5051 }
5052
5053 auto ret = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_AUTO_STARTUP_SYSTEM_CALLBACK, data, reply, option);
5054 if (ret != NO_ERROR) {
5055 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5056 return ret;
5057 }
5058 return reply.ReadInt32();
5059 }
5060
SetApplicationAutoStartup(const AutoStartupInfo & info)5061 int32_t AbilityManagerProxy::SetApplicationAutoStartup(const AutoStartupInfo &info)
5062 {
5063 MessageParcel data;
5064 MessageParcel reply;
5065 MessageOption option;
5066
5067 if (!WriteInterfaceToken(data)) {
5068 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5069 return INNER_ERR;
5070 }
5071 if (!data.WriteParcelable(&info)) {
5072 TAG_LOGE(AAFwkTag::ABILITYMGR, "write autoStartupInfo fail");
5073 return INNER_ERR;
5074 }
5075
5076 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP, data, reply, option);
5077 if (ret != NO_ERROR) {
5078 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5079 return ret;
5080 }
5081 return reply.ReadInt32();
5082 }
5083
CancelApplicationAutoStartup(const AutoStartupInfo & info)5084 int32_t AbilityManagerProxy::CancelApplicationAutoStartup(const AutoStartupInfo &info)
5085 {
5086 MessageParcel data;
5087 MessageParcel reply;
5088 MessageOption option;
5089
5090 if (!WriteInterfaceToken(data)) {
5091 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5092 return INNER_ERR;
5093 }
5094 if (!data.WriteParcelable(&info)) {
5095 TAG_LOGE(AAFwkTag::ABILITYMGR, "write autoStartupInfo fail");
5096 return INNER_ERR;
5097 }
5098
5099 auto ret = SendRequest(AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP, data, reply, option);
5100 if (ret != NO_ERROR) {
5101 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5102 return ret;
5103 }
5104 return reply.ReadInt32();
5105 }
5106
QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> & infoList)5107 int32_t AbilityManagerProxy::QueryAllAutoStartupApplications(std::vector<AutoStartupInfo> &infoList)
5108 {
5109 MessageParcel data;
5110 MessageParcel reply;
5111 MessageOption option;
5112
5113 if (!WriteInterfaceToken(data)) {
5114 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5115 return INNER_ERR;
5116 }
5117
5118 auto ret = SendRequest(AbilityManagerInterfaceCode::QUERY_ALL_AUTO_STARTUP_APPLICATION, data, reply, option);
5119 if (ret != NO_ERROR) {
5120 TAG_LOGE(AAFwkTag::ABILITYMGR, "send request error:%{public}d", ret);
5121 return ret;
5122 }
5123
5124 auto resultCode = reply.ReadInt32();
5125 if (resultCode != ERR_OK) {
5126 TAG_LOGE(AAFwkTag::ABILITYMGR, "reply error:%{public}d", resultCode);
5127 return resultCode;
5128 }
5129
5130 auto infoSize = reply.ReadInt32();
5131 for (auto i = 0; i < infoSize && i < MAX_AUTO_STARTUP_COUNT; ++i) {
5132 std::unique_ptr<AutoStartupInfo> info(reply.ReadParcelable<AutoStartupInfo>());
5133 if (!info) {
5134 TAG_LOGE(AAFwkTag::ABILITYMGR, "read result fail");
5135 return INNER_ERR;
5136 }
5137 infoList.emplace_back(*info);
5138 }
5139 return ERR_OK;
5140 }
5141
PrepareTerminateAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool & isPrepareTerminate)5142 int AbilityManagerProxy::PrepareTerminateAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool &isPrepareTerminate)
5143 {
5144 MessageParcel data;
5145 MessageParcel reply;
5146 MessageOption option;
5147
5148 if (!WriteInterfaceToken(data)) {
5149 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5150 return INNER_ERR;
5151 }
5152 if (sessionInfo) {
5153 ExtendMaxIpcCapacityForWant(sessionInfo->want, data);
5154 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
5155 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and sessionInfo write fail");
5156 return INNER_ERR;
5157 }
5158 } else {
5159 if (!data.WriteBool(false)) {
5160 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
5161 return INNER_ERR;
5162 }
5163 }
5164
5165 auto error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_BY_SCB,
5166 data, reply, option);
5167 if (error != NO_ERROR) {
5168 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5169 return error;
5170 }
5171
5172 isPrepareTerminate = reply.ReadBool();
5173 return NO_ERROR;
5174 }
5175
RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)5176 int32_t AbilityManagerProxy::RegisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)
5177 {
5178 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
5179 MessageParcel data;
5180 if (!WriteInterfaceToken(data)) {
5181 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5182 return INNER_ERR;
5183 }
5184
5185 if (listener == nullptr || !data.WriteRemoteObject(listener->AsObject())) {
5186 TAG_LOGE(AAFwkTag::ABILITYMGR, "write listener fail");
5187 return INNER_ERR;
5188 }
5189
5190 MessageParcel reply;
5191 MessageOption option(MessageOption::TF_SYNC);
5192 int32_t error = SendRequest(AbilityManagerInterfaceCode::REGISTER_APP_DEBUG_LISTENER, data, reply, option);
5193 if (error != NO_ERROR) {
5194 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
5195 return error;
5196 }
5197 return reply.ReadInt32();
5198 }
5199
UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)5200 int32_t AbilityManagerProxy::UnregisterAppDebugListener(sptr<AppExecFwk::IAppDebugListener> listener)
5201 {
5202 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
5203 MessageParcel data;
5204 if (!WriteInterfaceToken(data)) {
5205 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5206 return INNER_ERR;
5207 }
5208
5209 if (listener == nullptr || !data.WriteRemoteObject(listener->AsObject())) {
5210 TAG_LOGE(AAFwkTag::ABILITYMGR, "write listener fail");
5211 return INNER_ERR;
5212 }
5213
5214 MessageParcel reply;
5215 MessageOption option(MessageOption::TF_SYNC);
5216 int32_t error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_APP_DEBUG_LISTENER, data, reply, option);
5217 if (error != NO_ERROR) {
5218 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
5219 return error;
5220 }
5221 return reply.ReadInt32();
5222 }
5223
AttachAppDebug(const std::string & bundleName,bool isDebugFromLocal)5224 int32_t AbilityManagerProxy::AttachAppDebug(const std::string &bundleName, bool isDebugFromLocal)
5225 {
5226 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
5227 MessageParcel data;
5228 if (!WriteInterfaceToken(data)) {
5229 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5230 return INNER_ERR;
5231 }
5232
5233 if (!data.WriteString(bundleName)) {
5234 TAG_LOGE(AAFwkTag::ABILITYMGR, "bundleName write fail");
5235 return INNER_ERR;
5236 }
5237
5238 if (!data.WriteBool(isDebugFromLocal)) {
5239 TAG_LOGE(AAFwkTag::ABILITYMGR, "isDebugFromLocal write fail");
5240 return INNER_ERR;
5241 }
5242
5243 MessageParcel reply;
5244 MessageOption option;
5245 int32_t error = SendRequest(AbilityManagerInterfaceCode::ATTACH_APP_DEBUG, data, reply, option);
5246 if (error != NO_ERROR) {
5247 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
5248 return error;
5249 }
5250 return reply.ReadInt32();
5251 }
5252
DetachAppDebug(const std::string & bundleName,bool isDebugFromLocal)5253 int32_t AbilityManagerProxy::DetachAppDebug(const std::string &bundleName, bool isDebugFromLocal)
5254 {
5255 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
5256 MessageParcel data;
5257 if (!WriteInterfaceToken(data)) {
5258 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5259 return INNER_ERR;
5260 }
5261
5262 if (!data.WriteString(bundleName)) {
5263 TAG_LOGE(AAFwkTag::ABILITYMGR, "write bundleName fail");
5264 return INNER_ERR;
5265 }
5266
5267 if (!data.WriteBool(isDebugFromLocal)) {
5268 TAG_LOGE(AAFwkTag::ABILITYMGR, "isDebugFromLocal write fail");
5269 return INNER_ERR;
5270 }
5271
5272 MessageParcel reply;
5273 MessageOption option;
5274 int32_t error = SendRequest(AbilityManagerInterfaceCode::DETACH_APP_DEBUG, data, reply, option);
5275 if (error != NO_ERROR) {
5276 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
5277 return error;
5278 }
5279 return reply.ReadInt32();
5280 }
5281
ExecuteIntent(uint64_t key,const sptr<IRemoteObject> & callerToken,const InsightIntentExecuteParam & param)5282 int32_t AbilityManagerProxy::ExecuteIntent(uint64_t key, const sptr<IRemoteObject> &callerToken,
5283 const InsightIntentExecuteParam ¶m)
5284 {
5285 Ability_MANAGER_HITRACE_CHAIN_NAME("ExecuteIntent", HITRACE_FLAG_INCLUDE_ASYNC);
5286 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
5287 MessageParcel data;
5288 MessageParcel reply;
5289 MessageOption option;
5290 if (!WriteInterfaceToken(data)) {
5291 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5292 return INNER_ERR;
5293 }
5294
5295 if (!data.WriteUint64(key)) {
5296 TAG_LOGE(AAFwkTag::ABILITYMGR, "write key fail");
5297 return INNER_ERR;
5298 }
5299
5300 if (!data.WriteRemoteObject(callerToken)) {
5301 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken failed.");
5302 return INNER_ERR;
5303 }
5304
5305 if (!data.WriteParcelable(¶m)) {
5306 TAG_LOGE(AAFwkTag::ABILITYMGR, "write param fail");
5307 return INNER_ERR;
5308 }
5309
5310 TAG_LOGI(AAFwkTag::ABILITYMGR, "send execute intent.");
5311 int32_t error = SendRequest(AbilityManagerInterfaceCode::EXECUTE_INTENT, data, reply, option);
5312 if (error != NO_ERROR) {
5313 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err:%{public}d", error);
5314 return error;
5315 }
5316
5317 return reply.ReadInt32();
5318 }
5319
IsAbilityControllerStart(const Want & want)5320 bool AbilityManagerProxy::IsAbilityControllerStart(const Want &want)
5321 {
5322 MessageParcel data;
5323 MessageParcel reply;
5324 MessageOption option;
5325
5326 if (!WriteInterfaceToken(data)) {
5327 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5328 return true;
5329 }
5330 if (!data.WriteParcelable(&want)) {
5331 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeWantObject fail");
5332 return true;
5333 }
5334
5335 auto error = SendRequest(AbilityManagerInterfaceCode::IS_ABILITY_CONTROLLER_START,
5336 data, reply, option);
5337 if (error != NO_ERROR) {
5338 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5339 return true;
5340 }
5341 return reply.ReadBool();
5342 }
5343
ExecuteInsightIntentDone(const sptr<IRemoteObject> & token,uint64_t intentId,const InsightIntentExecuteResult & result)5344 int32_t AbilityManagerProxy::ExecuteInsightIntentDone(const sptr<IRemoteObject> &token, uint64_t intentId,
5345 const InsightIntentExecuteResult &result)
5346 {
5347 TAG_LOGI(AAFwkTag::INTENT, "execute insight intent done proxy, intentId:%{public}" PRIu64"", intentId);
5348 MessageParcel data;
5349 if (!WriteInterfaceToken(data)) {
5350 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail");
5351 return INNER_ERR;
5352 }
5353
5354 if (!data.WriteRemoteObject(token)) {
5355 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5356 return INNER_ERR;
5357 }
5358
5359 if (!data.WriteInt64(intentId) || !data.WriteParcelable(&result)) {
5360 TAG_LOGE(AAFwkTag::ABILITYMGR, "write params fail");
5361 return INNER_ERR;
5362 }
5363
5364 MessageParcel reply;
5365 MessageOption option(MessageOption::TF_ASYNC);
5366 auto ret = SendRequest(AbilityManagerInterfaceCode::EXECUTE_INSIGHT_INTENT_DONE, data, reply, option);
5367 if (ret != NO_ERROR) {
5368 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail:%{public}d", ret);
5369 return ret;
5370 }
5371 return reply.ReadInt32();
5372 }
5373
GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> & list)5374 int32_t AbilityManagerProxy::GetForegroundUIAbilities(std::vector<AppExecFwk::AbilityStateData> &list)
5375 {
5376 TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
5377 MessageParcel data;
5378 if (!WriteInterfaceToken(data)) {
5379 return ERR_FLATTEN_OBJECT;
5380 }
5381
5382 MessageParcel reply;
5383 MessageOption option;
5384 auto error = SendRequest(AbilityManagerInterfaceCode::GET_FOREGROUND_UI_ABILITIES, data, reply, option);
5385 if (error != NO_ERROR) {
5386 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5387 return error;
5388 }
5389
5390 auto errorCode = GetParcelableInfos<AppExecFwk::AbilityStateData>(reply, list);
5391 if (errorCode != NO_ERROR) {
5392 TAG_LOGE(AAFwkTag::ABILITYMGR, "get abilities error:%{public}d", errorCode);
5393 return errorCode;
5394 }
5395 return reply.ReadInt32();
5396 }
5397
OpenFile(const Uri & uri,uint32_t flag)5398 int32_t AbilityManagerProxy::OpenFile(const Uri& uri, uint32_t flag)
5399 {
5400 MessageParcel data;
5401 MessageParcel reply;
5402 MessageOption option;
5403 if (!WriteInterfaceToken(data)) {
5404 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5405 return false;
5406 }
5407 if (!data.WriteParcelable(&uri)) {
5408 TAG_LOGE(AAFwkTag::ABILITYMGR, "write uri fail");
5409 return false;
5410 }
5411 if (!data.WriteInt32(flag)) {
5412 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
5413 return false;
5414 }
5415
5416 auto ret = SendRequest(AbilityManagerInterfaceCode::OPEN_FILE, data, reply, option);
5417 if (ret != NO_ERROR) {
5418 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail:%{public}d", ret);
5419 return ret;
5420 }
5421 return reply.ReadFileDescriptor();
5422 }
5423
RequestAssertFaultDialog(const sptr<IRemoteObject> & callback,const AAFwk::WantParams & wantParams)5424 int32_t AbilityManagerProxy::RequestAssertFaultDialog(
5425 const sptr<IRemoteObject> &callback, const AAFwk::WantParams &wantParams)
5426 {
5427 TAG_LOGD(AAFwkTag::ABILITYMGR, "Request to display assert fault dialog.");
5428 if (callback == nullptr) {
5429 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callback");
5430 return INNER_ERR;
5431 }
5432
5433 MessageParcel data;
5434 if (!WriteInterfaceToken(data)) {
5435 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5436 return INNER_ERR;
5437 }
5438
5439 if (!data.WriteRemoteObject(callback)) {
5440 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callback fail");
5441 return INNER_ERR;
5442 }
5443
5444 if (!data.WriteParcelable(&wantParams)) {
5445 TAG_LOGE(AAFwkTag::ABILITYMGR, "wantParams write fail");
5446 return INNER_ERR;
5447 }
5448
5449 MessageParcel reply;
5450 MessageOption option;
5451 auto ret = SendRequest(AbilityManagerInterfaceCode::REQUEST_ASSERT_FAULT_DIALOG, data, reply, option);
5452 if (ret != NO_ERROR) {
5453 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail:%{public}d", ret);
5454 return ret;
5455 }
5456
5457 return reply.ReadInt32();
5458 }
5459
NotifyDebugAssertResult(uint64_t assertFaultSessionId,AAFwk::UserStatus userStatus)5460 int32_t AbilityManagerProxy::NotifyDebugAssertResult(uint64_t assertFaultSessionId, AAFwk::UserStatus userStatus)
5461 {
5462 TAG_LOGD(AAFwkTag::ABILITYMGR, "Notify user action result to assert fault callback.");
5463 MessageParcel data;
5464 if (!WriteInterfaceToken(data)) {
5465 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5466 return INNER_ERR;
5467 }
5468
5469 if (!data.WriteUint64(assertFaultSessionId)) {
5470 TAG_LOGE(AAFwkTag::ABILITYMGR, "write assertFaultSessionId fail");
5471 return INNER_ERR;
5472 }
5473
5474 if (!data.WriteInt32(static_cast<int32_t>(userStatus))) {
5475 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userStatus fail");
5476 return INNER_ERR;
5477 }
5478
5479 MessageParcel reply;
5480 MessageOption option;
5481 auto ret = SendRequest(AbilityManagerInterfaceCode::NOTIFY_DEBUG_ASSERT_RESULT, data, reply, option);
5482 if (ret != NO_ERROR) {
5483 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail:%{public}d", ret);
5484 return ret;
5485 }
5486
5487 return reply.ReadInt32();
5488 }
5489
UpdateSessionInfoBySCB(std::list<SessionInfo> & sessionInfos,int32_t userId,std::vector<int32_t> & sessionIds)5490 int32_t AbilityManagerProxy::UpdateSessionInfoBySCB(std::list<SessionInfo> &sessionInfos, int32_t userId,
5491 std::vector<int32_t> &sessionIds)
5492 {
5493 MessageParcel data;
5494 if (!WriteInterfaceToken(data)) {
5495 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5496 return ERR_NATIVE_IPC_PARCEL_FAILED;
5497 }
5498 auto size = static_cast<int32_t>(sessionInfos.size());
5499 int32_t threshold = 512;
5500 if (size > threshold) {
5501 TAG_LOGE(AAFwkTag::ABILITYMGR, "vector too large");
5502 return ERR_NATIVE_IPC_PARCEL_FAILED;
5503 }
5504 if (!data.WriteInt32(size)) {
5505 TAG_LOGE(AAFwkTag::ABILITYMGR, "write size fail");
5506 return ERR_NATIVE_IPC_PARCEL_FAILED;
5507 }
5508 for (const auto &info : sessionInfos) {
5509 if (!data.WriteParcelable(&info)) {
5510 TAG_LOGE(AAFwkTag::ABILITYMGR, "write sessionInfo fail");
5511 return ERR_NATIVE_IPC_PARCEL_FAILED;
5512 }
5513 }
5514 if (!data.WriteInt32(userId)) {
5515 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId fail");
5516 return ERR_NATIVE_IPC_PARCEL_FAILED;
5517 }
5518
5519 MessageParcel reply;
5520 MessageOption option;
5521 auto ret = SendRequest(AbilityManagerInterfaceCode::UPDATE_SESSION_INFO, data, reply, option);
5522 if (ret != NO_ERROR) {
5523 TAG_LOGE(AAFwkTag::ABILITYMGR, "request fail:%{public}d", ret);
5524 return ret;
5525 }
5526 size = reply.ReadInt32();
5527 if (size > threshold) {
5528 TAG_LOGE(AAFwkTag::ABILITYMGR, "vector too large");
5529 return ERR_NATIVE_IPC_PARCEL_FAILED;
5530 }
5531 sessionIds.clear();
5532 for (auto index = 0; index < size; index++) {
5533 sessionIds.emplace_back(reply.ReadInt32());
5534 }
5535 return NO_ERROR;
5536 }
5537
SendRequest(AbilityManagerInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)5538 ErrCode AbilityManagerProxy::SendRequest(AbilityManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply,
5539 MessageOption& option)
5540 {
5541 HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
5542 sptr<IRemoteObject> remote = Remote();
5543 if (remote == nullptr) {
5544 TAG_LOGE(AAFwkTag::ABILITYMGR, "null remote");
5545 return INNER_ERR;
5546 }
5547
5548 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
5549 }
5550
SetApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)5551 int32_t AbilityManagerProxy::SetApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag)
5552 {
5553 MessageParcel data;
5554 if (!WriteInterfaceToken(data)) {
5555 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5556 return INNER_ERR;
5557 }
5558 if (!data.WriteParcelable(&info)) {
5559 TAG_LOGE(AAFwkTag::ABILITYMGR, "write AutoStartupInfo fail");
5560 return INNER_ERR;
5561 }
5562 if (!data.WriteBool(flag)) {
5563 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
5564 return INNER_ERR;
5565 }
5566
5567 MessageParcel reply;
5568 MessageOption option;
5569 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_AUTO_STARTUP_BY_EDM, data, reply, option);
5570 if (ret != NO_ERROR) {
5571 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5572 return ret;
5573 }
5574 return reply.ReadInt32();
5575 }
5576
CancelApplicationAutoStartupByEDM(const AutoStartupInfo & info,bool flag)5577 int32_t AbilityManagerProxy::CancelApplicationAutoStartupByEDM(const AutoStartupInfo &info, bool flag)
5578 {
5579 MessageParcel data;
5580 if (!WriteInterfaceToken(data)) {
5581 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5582 return INNER_ERR;
5583 }
5584 if (!data.WriteParcelable(&info)) {
5585 TAG_LOGE(AAFwkTag::ABILITYMGR, "write info fail");
5586 return INNER_ERR;
5587 }
5588 if (!data.WriteBool(flag)) {
5589 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
5590 return INNER_ERR;
5591 }
5592
5593 MessageParcel reply;
5594 MessageOption option;
5595 auto ret = SendRequest(AbilityManagerInterfaceCode::CANCEL_APPLICATION_AUTO_STARTUP_BY_EDM, data, reply, option);
5596 if (ret != NO_ERROR) {
5597 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5598 return ret;
5599 }
5600 return reply.ReadInt32();
5601 }
5602
RestartApp(const AAFwk::Want & want,bool isAppRecovery)5603 int32_t AbilityManagerProxy::RestartApp(const AAFwk::Want &want, bool isAppRecovery)
5604 {
5605 MessageParcel data;
5606 MessageParcel reply;
5607 MessageOption option;
5608 if (!WriteInterfaceToken(data)) {
5609 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5610 return IPC_PROXY_ERR;
5611 }
5612 if (!data.WriteParcelable(&want)) {
5613 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
5614 return IPC_PROXY_ERR;
5615 }
5616 if (!data.WriteBool(isAppRecovery)) {
5617 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isAppRecovery fail");
5618 return IPC_PROXY_ERR;
5619 }
5620 auto ret = SendRequest(AbilityManagerInterfaceCode::RESTART_APP, data, reply, option);
5621 if (ret != NO_ERROR) {
5622 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5623 return ret;
5624 }
5625 return reply.ReadInt32();
5626 }
5627
GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token,UIExtensionHostInfo & hostInfo,int32_t userId)5628 int32_t AbilityManagerProxy::GetUIExtensionRootHostInfo(const sptr<IRemoteObject> token,
5629 UIExtensionHostInfo &hostInfo, int32_t userId)
5630 {
5631 if (token == nullptr) {
5632 TAG_LOGE(AAFwkTag::ABILITYMGR, "input invalid");
5633 return ERR_INVALID_VALUE;
5634 }
5635
5636 MessageParcel data;
5637 if (!WriteInterfaceToken(data)) {
5638 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail");
5639 return INNER_ERR;
5640 }
5641
5642 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
5643 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and token fail");
5644 return INNER_ERR;
5645 }
5646
5647 if (!data.WriteInt32(userId)) {
5648 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId fail");
5649 return INNER_ERR;
5650 }
5651
5652 MessageParcel reply;
5653 MessageOption option;
5654 auto error = SendRequest(AbilityManagerInterfaceCode::GET_UI_EXTENSION_ROOT_HOST_INFO, data, reply, option);
5655 if (error != NO_ERROR) {
5656 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5657 return error;
5658 }
5659
5660 std::unique_ptr<UIExtensionHostInfo> info(reply.ReadParcelable<UIExtensionHostInfo>());
5661 if (info == nullptr) {
5662 TAG_LOGE(AAFwkTag::ABILITYMGR, "get host fail");
5663 return INNER_ERR;
5664 }
5665 hostInfo = *info;
5666 return reply.ReadInt32();
5667 }
5668
GetUIExtensionSessionInfo(const sptr<IRemoteObject> token,UIExtensionSessionInfo & uiExtensionSessionInfo,int32_t userId)5669 int32_t AbilityManagerProxy::GetUIExtensionSessionInfo(const sptr<IRemoteObject> token,
5670 UIExtensionSessionInfo &uiExtensionSessionInfo, int32_t userId)
5671 {
5672 if (token == nullptr) {
5673 TAG_LOGE(AAFwkTag::ABILITYMGR, "input invalid");
5674 return ERR_INVALID_VALUE;
5675 }
5676
5677 MessageParcel data;
5678 if (!WriteInterfaceToken(data)) {
5679 TAG_LOGE(AAFwkTag::ABILITYMGR, "write object fail");
5680 return INNER_ERR;
5681 }
5682
5683 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
5684 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and token fail");
5685 return INNER_ERR;
5686 }
5687
5688 if (!data.WriteInt32(userId)) {
5689 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId fail");
5690 return INNER_ERR;
5691 }
5692
5693 MessageParcel reply;
5694 MessageOption option;
5695 auto error = SendRequest(AbilityManagerInterfaceCode::GET_UI_EXTENSION_SESSION_INFO, data, reply, option);
5696 if (error != NO_ERROR) {
5697 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5698 return error;
5699 }
5700
5701 std::unique_ptr<UIExtensionSessionInfo> info(reply.ReadParcelable<UIExtensionSessionInfo>());
5702 if (info == nullptr) {
5703 TAG_LOGE(AAFwkTag::ABILITYMGR, "get host info fail");
5704 return INNER_ERR;
5705 }
5706 uiExtensionSessionInfo = *info;
5707 return reply.ReadInt32();
5708 }
5709
OpenAtomicService(Want & want,const StartOptions & options,sptr<IRemoteObject> callerToken,int32_t requestCode,int32_t userId)5710 int32_t AbilityManagerProxy::OpenAtomicService(Want& want, const StartOptions &options,
5711 sptr<IRemoteObject> callerToken, int32_t requestCode, int32_t userId)
5712 {
5713 Ability_MANAGER_HITRACE_CHAIN_NAME("OpenAtomicService", HITRACE_FLAG_INCLUDE_ASYNC);
5714 MessageParcel data;
5715 if (!WriteInterfaceToken(data)) {
5716 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5717 return INNER_ERR;
5718 }
5719 if (!data.WriteParcelable(&want)) {
5720 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail");
5721 return INNER_ERR;
5722 }
5723 if (!data.WriteParcelable(&options)) {
5724 TAG_LOGE(AAFwkTag::ABILITYMGR, "options write fail");
5725 return INNER_ERR;
5726 }
5727 if (callerToken != nullptr) {
5728 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
5729 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag and callerToken write fail");
5730 return INNER_ERR;
5731 }
5732 } else {
5733 if (!data.WriteBool(false)) {
5734 TAG_LOGE(AAFwkTag::ABILITYMGR, "flag write fail");
5735 return INNER_ERR;
5736 }
5737 }
5738 if (!data.WriteInt32(requestCode)) {
5739 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
5740 return INNER_ERR;
5741 }
5742 if (!data.WriteInt32(userId)) {
5743 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
5744 return INNER_ERR;
5745 }
5746
5747 MessageParcel reply;
5748 MessageOption option;
5749 auto ret = SendRequest(AbilityManagerInterfaceCode::OPEN_ATOMIC_SERVICE, data, reply, option);
5750 if (ret != NO_ERROR) {
5751 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5752 return ret;
5753 }
5754 return reply.ReadInt32();
5755 }
5756
SetResidentProcessEnabled(const std::string & bundleName,bool enable)5757 int32_t AbilityManagerProxy::SetResidentProcessEnabled(const std::string &bundleName, bool enable)
5758 {
5759 MessageParcel data;
5760 if (!WriteInterfaceToken(data)) {
5761 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5762 return INNER_ERR;
5763 }
5764 if (!data.WriteString(bundleName)) {
5765 TAG_LOGE(AAFwkTag::ABILITYMGR, "write bundleName fail");
5766 return INNER_ERR;
5767 }
5768 if (!data.WriteBool(enable)) {
5769 TAG_LOGE(AAFwkTag::ABILITYMGR, "write enable fail");
5770 return INNER_ERR;
5771 }
5772 MessageParcel reply;
5773 MessageOption option;
5774 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_RESIDENT_PROCESS_ENABLE, data, reply, option);
5775 if (ret != NO_ERROR) {
5776 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", ret);
5777 return ret;
5778 }
5779
5780 return reply.ReadInt32();
5781 }
5782
IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken,const std::string & appId)5783 bool AbilityManagerProxy::IsEmbeddedOpenAllowed(sptr<IRemoteObject> callerToken, const std::string &appId)
5784 {
5785 if (callerToken == nullptr) {
5786 TAG_LOGE(AAFwkTag::ABILITYMGR, "input invalid");
5787 return false;
5788 }
5789
5790 MessageParcel data;
5791 if (!WriteInterfaceToken (data)) {
5792 TAG_LOGE(AAFwkTag::ABILITYMGR, "write remote object fail");
5793 return false;
5794 }
5795
5796 if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
5797 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag and callerToken fail");
5798 return false;
5799 }
5800
5801 if (!data.WriteString(appId)) {
5802 TAG_LOGE(AAFwkTag::ABILITYMGR, "write userId fail");
5803 return false;
5804 }
5805
5806 MessageParcel reply;
5807 MessageOption option;
5808 auto error = SendRequest(AbilityManagerInterfaceCode::IS_EMBEDDED_OPEN_ALLOWED, data, reply, option);
5809 if (error != NO_ERROR) {
5810 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5811 return false;
5812 }
5813 return reply.ReadBool();
5814 }
5815
StartShortcut(const Want & want,const StartOptions & startOptions)5816 int32_t AbilityManagerProxy::StartShortcut(const Want &want, const StartOptions &startOptions)
5817 {
5818 if (AppUtils::GetInstance().IsForbidStart()) {
5819 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
5820 return INNER_ERR;
5821 }
5822 MessageParcel data;
5823 MessageParcel reply;
5824 MessageOption option;
5825 if (!WriteInterfaceToken(data)) {
5826 return INNER_ERR;
5827 }
5828 if (!data.WriteParcelable(&want)) {
5829 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
5830 return INNER_ERR;
5831 }
5832 if (!data.WriteParcelable(&startOptions)) {
5833 TAG_LOGE(AAFwkTag::ABILITYMGR, "startOptions write fail");
5834 return INNER_ERR;
5835 }
5836
5837 auto error = SendRequest(AbilityManagerInterfaceCode::START_SHORTCUT, data, reply, option);
5838 if (error != NO_ERROR) {
5839 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5840 return error;
5841 }
5842 return reply.ReadInt32();
5843 }
5844
GetAbilityStateByPersistentId(int32_t persistentId,bool & state)5845 int32_t AbilityManagerProxy::GetAbilityStateByPersistentId(int32_t persistentId, bool &state)
5846 {
5847 MessageParcel data;
5848 MessageParcel reply;
5849 MessageOption option;
5850 if (!WriteInterfaceToken(data)) {
5851 return IPC_PROXY_ERR;
5852 }
5853 if (!data.WriteInt32(persistentId)) {
5854 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write failed");
5855 return IPC_PROXY_ERR;
5856 }
5857 auto error = SendRequest(AbilityManagerInterfaceCode::GET_ABILITY_STATE_BY_PERSISTENT_ID, data, reply, option);
5858 if (error != NO_ERROR) {
5859 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5860 return error;
5861 }
5862 state = reply.ReadBool();
5863 return NO_ERROR;
5864 }
5865
5866
TransferAbilityResultForExtension(const sptr<IRemoteObject> & callerToken,int32_t resultCode,const Want & want)5867 int32_t AbilityManagerProxy::TransferAbilityResultForExtension(const sptr<IRemoteObject> &callerToken,
5868 int32_t resultCode, const Want &want)
5869 {
5870 Ability_MANAGER_HITRACE_CHAIN_NAME("TransferAbilityResultForExtension", HITRACE_FLAG_INCLUDE_ASYNC);
5871 if (callerToken == nullptr) {
5872 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
5873 return INNER_ERR;
5874 }
5875 MessageParcel data;
5876 MessageParcel reply;
5877 MessageOption option;
5878 if (!WriteInterfaceToken(data)) {
5879 return IPC_PROXY_ERR;
5880 }
5881 if (!data.WriteRemoteObject(callerToken) || !data.WriteInt32(resultCode)) {
5882 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken or resultCode write fail");
5883 return INNER_ERR;
5884 }
5885 if (!data.WriteParcelable(&want)) {
5886 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
5887 return INNER_ERR;
5888 }
5889 auto error = SendRequest(AbilityManagerInterfaceCode::TRANSFER_ABILITY_RESULT, data, reply, option);
5890 if (error != NO_ERROR) {
5891 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5892 return error;
5893 }
5894 return NO_ERROR;
5895 }
5896
NotifyFrozenProcessByRSS(const std::vector<int32_t> & pidList,int32_t uid)5897 void AbilityManagerProxy::NotifyFrozenProcessByRSS(const std::vector<int32_t> &pidList, int32_t uid)
5898 {
5899 MessageParcel data;
5900 MessageParcel reply;
5901 MessageOption option(MessageOption::TF_ASYNC);
5902
5903 if (!WriteInterfaceToken(data)) {
5904 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
5905 return;
5906 }
5907 if (!data.WriteInt32Vector(pidList)) {
5908 TAG_LOGE(AAFwkTag::ABILITYMGR, "list write fail");
5909 return;
5910 }
5911 if (!data.WriteInt32(uid)) {
5912 TAG_LOGE(AAFwkTag::ABILITYMGR, "uid write fail");
5913 return;
5914 }
5915
5916 int error = SendRequest(AbilityManagerInterfaceCode::NOTIFY_FROZEN_PROCESS_BY_RSS, data, reply, option);
5917 if (error != NO_ERROR) {
5918 TAG_LOGE(AAFwkTag::ABILITYMGR, "request err %{public}d", error);
5919 }
5920 }
5921
CleanUIAbilityBySCB(const sptr<SessionInfo> & sessionInfo,bool isUserRequestedExit,uint32_t sceneFlag)5922 int AbilityManagerProxy::CleanUIAbilityBySCB(const sptr<SessionInfo> &sessionInfo, bool isUserRequestedExit,
5923 uint32_t sceneFlag)
5924 {
5925 int error;
5926 MessageParcel data;
5927 MessageParcel reply;
5928 MessageOption option;
5929 if (!WriteInterfaceToken(data)) {
5930 return INNER_ERR;
5931 }
5932
5933 if (sessionInfo) {
5934 ExtendMaxIpcCapacityForWant(sessionInfo->want, data);
5935 if (!data.WriteBool(true) || !data.WriteParcelable(sessionInfo)) {
5936 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag or sessionInfo fail");
5937 return INNER_ERR;
5938 }
5939 } else {
5940 if (!data.WriteBool(false)) {
5941 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
5942 return INNER_ERR;
5943 }
5944 }
5945 if (!data.WriteUint32(sceneFlag)) {
5946 TAG_LOGE(AAFwkTag::ABILITYMGR, "sceneFlag write fail");
5947 return INNER_ERR;
5948 }
5949 if (!data.WriteBool(isUserRequestedExit)) {
5950 TAG_LOGE(AAFwkTag::ABILITYMGR, "write isUserRequestedExit fail");
5951 return ERR_IPC_PROXY_WRITE_FAILED;
5952 }
5953
5954 error = SendRequest(AbilityManagerInterfaceCode::CLEAN_UI_ABILITY_BY_SCB, data, reply, option);
5955 if (error != NO_ERROR) {
5956 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5957 return error;
5958 }
5959 return reply.ReadInt32();
5960 }
5961
PreStartMission(const std::string & bundleName,const std::string & moduleName,const std::string & abilityName,const std::string & startTime)5962 int32_t AbilityManagerProxy::PreStartMission(const std::string& bundleName, const std::string& moduleName,
5963 const std::string& abilityName, const std::string& startTime)
5964 {
5965 MessageParcel data;
5966 MessageParcel reply;
5967 MessageOption option;
5968 if (!WriteInterfaceToken(data)) {
5969 return IPC_PROXY_ERR;
5970 }
5971 if (!data.WriteString(bundleName)) {
5972 TAG_LOGE(AAFwkTag::ABILITYMGR, "write bundleName fail");
5973 return INNER_ERR;
5974 }
5975 if (!data.WriteString(moduleName)) {
5976 TAG_LOGE(AAFwkTag::ABILITYMGR, "write moduleName fail");
5977 return INNER_ERR;
5978 }
5979 if (!data.WriteString(abilityName)) {
5980 TAG_LOGE(AAFwkTag::ABILITYMGR, "write abilityName fail");
5981 return INNER_ERR;
5982 }
5983 if (!data.WriteString(startTime)) {
5984 TAG_LOGE(AAFwkTag::ABILITYMGR, "write startTime fail");
5985 return INNER_ERR;
5986 }
5987 auto error = SendRequest(AbilityManagerInterfaceCode::PRE_START_MISSION, data, reply, option);
5988 if (error != NO_ERROR) {
5989 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
5990 return error;
5991 }
5992 return reply.ReadInt32();
5993 }
5994
OpenLink(const Want & want,sptr<IRemoteObject> callerToken,int32_t userId,int requestCode)5995 ErrCode AbilityManagerProxy::OpenLink(const Want& want, sptr<IRemoteObject> callerToken,
5996 int32_t userId, int requestCode)
5997 {
5998 if (AppUtils::GetInstance().IsForbidStart()) {
5999 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
6000 return INNER_ERR;
6001 }
6002 Ability_MANAGER_HITRACE_CHAIN_NAME("OpenLink", HITRACE_FLAG_INCLUDE_ASYNC);
6003 if (callerToken == nullptr) {
6004 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
6005 return INNER_ERR;
6006 }
6007 MessageParcel data;
6008 MessageParcel reply;
6009 MessageOption option;
6010 if (!WriteInterfaceToken(data)) {
6011 return IPC_PROXY_ERR;
6012 }
6013 if (!data.WriteParcelable(&want)) {
6014 TAG_LOGE(AAFwkTag::ABILITYMGR, "want write fail");
6015 return INNER_ERR;
6016 }
6017 if (!data.WriteRemoteObject(callerToken)) {
6018 TAG_LOGE(AAFwkTag::ABILITYMGR, "callerToken write fail");
6019 return INNER_ERR;
6020 }
6021 if (!data.WriteInt32(userId)) {
6022 TAG_LOGE(AAFwkTag::ABILITYMGR, "userId write fail");
6023 return INNER_ERR;
6024 }
6025 if (!data.WriteInt32(requestCode)) {
6026 TAG_LOGE(AAFwkTag::ABILITYMGR, "requestCode write fail");
6027 return INNER_ERR;
6028 }
6029 auto error = SendRequest(AbilityManagerInterfaceCode::OPEN_LINK, data, reply, option);
6030 if (error != NO_ERROR) {
6031 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6032 return error;
6033 }
6034 return reply.ReadInt32();
6035 }
6036
TerminateMission(int32_t missionId)6037 int32_t AbilityManagerProxy::TerminateMission(int32_t missionId)
6038 {
6039 MessageParcel data;
6040 MessageParcel reply;
6041 MessageOption option;
6042 if (!WriteInterfaceToken(data)) {
6043 return IPC_PROXY_ERR;
6044 }
6045 if (!data.WriteInt32(missionId)) {
6046 TAG_LOGE(AAFwkTag::ABILITYMGR, "appCloneIndex write fail");
6047 return INNER_ERR;
6048 }
6049
6050 auto error = SendRequest(AbilityManagerInterfaceCode::TERMINATE_MISSION,
6051 data, reply, option);
6052 if (error != NO_ERROR) {
6053 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error);
6054 return error;
6055 }
6056
6057 return reply.ReadInt32();
6058 }
6059
BlockAllAppStart(bool flag)6060 int32_t AbilityManagerProxy::BlockAllAppStart(bool flag)
6061 {
6062 MessageParcel data;
6063 MessageParcel reply;
6064 MessageOption option;
6065 if (!WriteInterfaceToken(data)) {
6066 return IPC_PROXY_ERR;
6067 }
6068 if (!data.WriteBool(flag)) {
6069 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag failed.");
6070 return INNER_ERR;
6071 }
6072
6073 auto error = SendRequest(AbilityManagerInterfaceCode::BLOCK_ALL_APP_START,
6074 data, reply, option);
6075 if (error != NO_ERROR) {
6076 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
6077 return error;
6078 }
6079
6080 return reply.ReadInt32();
6081 }
6082
UpdateAssociateConfigList(const std::map<std::string,std::list<std::string>> & configs,const std::list<std::string> & exportConfigs,int32_t flag)6083 int32_t AbilityManagerProxy::UpdateAssociateConfigList(const std::map<std::string, std::list<std::string>>& configs,
6084 const std::list<std::string>& exportConfigs, int32_t flag)
6085 {
6086 MessageParcel data;
6087 MessageParcel reply;
6088 MessageOption option;
6089 if (!WriteInterfaceToken(data)) {
6090 return IPC_PROXY_ERR;
6091 }
6092
6093 if (!UpdateAssociateConfigInner(configs, data)) {
6094 return INNER_ERR;
6095 }
6096
6097 int32_t size = static_cast<int32_t>(exportConfigs.size());
6098 if (size > MAX_UPDATE_CONFIG_SIZE) {
6099 TAG_LOGE(AAFwkTag::ABILITYMGR, "export configs size too large");
6100 return INNER_ERR;
6101 }
6102 if (!data.WriteInt32(size)) {
6103 TAG_LOGE(AAFwkTag::ABILITYMGR, "write export configs size fail");
6104 return INNER_ERR;
6105 }
6106 for (const auto& config : exportConfigs) {
6107 if (!data.WriteString(config)) {
6108 TAG_LOGE(AAFwkTag::ABILITYMGR, "write export config item fail");
6109 return INNER_ERR;
6110 }
6111 }
6112 if (!data.WriteInt32(flag)) {
6113 TAG_LOGE(AAFwkTag::ABILITYMGR, "write flag fail");
6114 return INNER_ERR;
6115 }
6116 auto error = SendRequest(AbilityManagerInterfaceCode::UPDATE_ASSOCIATE_CONFIG_LIST, data, reply, option);
6117 if (error != NO_ERROR) {
6118 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", error);
6119 return error;
6120 }
6121 return reply.ReadInt32();
6122 }
6123
UpdateAssociateConfigInner(const std::map<std::string,std::list<std::string>> & configs,MessageParcel & data)6124 bool AbilityManagerProxy::UpdateAssociateConfigInner(const std::map<std::string, std::list<std::string>>& configs,
6125 MessageParcel& data)
6126 {
6127 int32_t size = static_cast<int32_t>(configs.size());
6128 if (size > MAX_UPDATE_CONFIG_SIZE) {
6129 TAG_LOGE(AAFwkTag::ABILITYMGR, "configs size too large");
6130 return false;
6131 }
6132 if (!data.WriteInt32(size)) {
6133 TAG_LOGE(AAFwkTag::ABILITYMGR, "write configs size fail");
6134 return false;
6135 }
6136 for (const auto& config : configs) {
6137 if (!data.WriteString(config.first)) {
6138 TAG_LOGE(AAFwkTag::ABILITYMGR, "write config key fail");
6139 return false;
6140 }
6141 size = static_cast<int32_t>(config.second.size());
6142 if (size > MAX_UPDATE_CONFIG_SIZE) {
6143 TAG_LOGE(AAFwkTag::ABILITYMGR, "config size too large");
6144 return false;
6145 }
6146 if (!data.WriteInt32(size)) {
6147 TAG_LOGE(AAFwkTag::ABILITYMGR, "write config item size fail");
6148 return false;
6149 }
6150 for (const auto& item : config.second) {
6151 if (!data.WriteString(item)) {
6152 TAG_LOGE(AAFwkTag::ABILITYMGR, "write config item fail");
6153 return false;
6154 }
6155 }
6156 }
6157 return true;
6158 }
6159
SetApplicationKeepAlive(const std::string & bundleName,int32_t userId,bool flag)6160 int32_t AbilityManagerProxy::SetApplicationKeepAlive(const std::string &bundleName, int32_t userId, bool flag)
6161 {
6162 MessageParcel data;
6163 if (!WriteInterfaceToken(data)) {
6164 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
6165 return INNER_ERR;
6166 }
6167
6168 if (!data.WriteString(bundleName)) {
6169 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write bundleName");
6170 return ERR_INVALID_VALUE;
6171 }
6172
6173 if (!data.WriteInt32(userId)) {
6174 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write userID");
6175 return ERR_INVALID_VALUE;
6176 }
6177
6178 if (!data.WriteBool(flag)) {
6179 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write flag");
6180 return ERR_INVALID_VALUE;
6181 }
6182
6183 MessageParcel reply;
6184 MessageOption option;
6185 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_KEEP_ALLIVE,
6186 data, reply, option);
6187 if (ret != NO_ERROR) {
6188 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
6189 return ret;
6190 }
6191 return reply.ReadInt32();
6192 }
6193
QueryKeepAliveApplications(int32_t appType,int32_t userId,std::vector<KeepAliveInfo> & list)6194 int32_t AbilityManagerProxy::QueryKeepAliveApplications(int32_t appType, int32_t userId,
6195 std::vector<KeepAliveInfo> &list)
6196 {
6197 MessageParcel data;
6198 if (!WriteInterfaceToken(data)) {
6199 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
6200 return INNER_ERR;
6201 }
6202
6203 if (!data.WriteInt32(appType)) {
6204 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write appType");
6205 return ERR_INVALID_VALUE;
6206 }
6207
6208 if (!data.WriteInt32(userId)) {
6209 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write userID");
6210 return ERR_INVALID_VALUE;
6211 }
6212
6213 MessageParcel reply;
6214 MessageOption option;
6215 auto ret = SendRequest(AbilityManagerInterfaceCode::GET_APPLICATIONS_KEEP_ALIVE,
6216 data, reply, option);
6217 if (ret != NO_ERROR) {
6218 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
6219 return ret;
6220 }
6221
6222 ret = GetParcelableInfos<KeepAliveInfo>(reply, list);
6223 if (ret != NO_ERROR) {
6224 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos error: %{public}d", ret);
6225 return ret;
6226 }
6227
6228 return reply.ReadInt32();
6229 }
6230
SetApplicationKeepAliveByEDM(const std::string & bundleName,int32_t userId,bool flag,bool isAllowUserToCancel)6231 int32_t AbilityManagerProxy::SetApplicationKeepAliveByEDM(const std::string &bundleName, int32_t userId,
6232 bool flag, bool isAllowUserToCancel)
6233 {
6234 MessageParcel data;
6235 if (!WriteInterfaceToken(data)) {
6236 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
6237 return INNER_ERR;
6238 }
6239
6240 if (!data.WriteString(bundleName)) {
6241 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write bundleName");
6242 return ERR_INVALID_VALUE;
6243 }
6244
6245 if (!data.WriteInt32(userId)) {
6246 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write userID");
6247 return ERR_INVALID_VALUE;
6248 }
6249
6250 if (!data.WriteBool(flag)) {
6251 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write flag");
6252 return ERR_INVALID_VALUE;
6253 }
6254
6255 if (!data.WriteBool(isAllowUserToCancel)) {
6256 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write isAllowUserToCancel");
6257 return ERR_INVALID_VALUE;
6258 }
6259
6260 MessageParcel reply;
6261 MessageOption option;
6262 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APPLICATION_KEEP_ALLIVE_BY_EDM,
6263 data, reply, option);
6264 if (ret != NO_ERROR) {
6265 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
6266 return ret;
6267 }
6268 return reply.ReadInt32();
6269 }
6270
QueryKeepAliveApplicationsByEDM(int32_t appType,int32_t userId,std::vector<KeepAliveInfo> & list)6271 int32_t AbilityManagerProxy::QueryKeepAliveApplicationsByEDM(int32_t appType, int32_t userId,
6272 std::vector<KeepAliveInfo> &list)
6273 {
6274 MessageParcel data;
6275 if (!WriteInterfaceToken(data)) {
6276 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
6277 return INNER_ERR;
6278 }
6279
6280 if (!data.WriteInt32(appType)) {
6281 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write appType");
6282 return ERR_INVALID_VALUE;
6283 }
6284
6285 if (!data.WriteInt32(userId)) {
6286 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write userID");
6287 return ERR_INVALID_VALUE;
6288 }
6289
6290 MessageParcel reply;
6291 MessageOption option;
6292 auto ret = SendRequest(AbilityManagerInterfaceCode::GET_APPLICATIONS_KEEP_ALIVE_BY_EDM,
6293 data, reply, option);
6294 if (ret != NO_ERROR) {
6295 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
6296 return ret;
6297 }
6298
6299 ret = GetParcelableInfos<KeepAliveInfo>(reply, list);
6300 if (ret != NO_ERROR) {
6301 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos error: %{public}d", ret);
6302 return ret;
6303 }
6304
6305 return reply.ReadInt32();
6306 }
6307
AddQueryERMSObserver(sptr<IRemoteObject> callerToken,sptr<AbilityRuntime::IQueryERMSObserver> observer)6308 int32_t AbilityManagerProxy::AddQueryERMSObserver(sptr<IRemoteObject> callerToken,
6309 sptr<AbilityRuntime::IQueryERMSObserver> observer)
6310 {
6311 MessageParcel data;
6312 MessageParcel reply;
6313 MessageOption option;
6314 if (callerToken == nullptr) {
6315 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
6316 return ERR_INVALID_VALUE;
6317 }
6318
6319 if (observer == nullptr) {
6320 TAG_LOGE(AAFwkTag::ABILITYMGR, "null observer");
6321 return ERR_INVALID_VALUE;
6322 }
6323
6324 if (!WriteInterfaceToken(data)) {
6325 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6326 return INNER_ERR;
6327 }
6328
6329 if (!data.WriteRemoteObject(callerToken)) {
6330 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail");
6331 return INNER_ERR;
6332 }
6333
6334 if (!data.WriteRemoteObject(observer->AsObject())) {
6335 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write fail");
6336 return INNER_ERR;
6337 }
6338
6339 auto error = SendRequest(AbilityManagerInterfaceCode::ADD_QUERY_ERMS_OBSERVER, data, reply, option);
6340 if (error != NO_ERROR) {
6341 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6342 return error;
6343 }
6344 return reply.ReadInt32();
6345 }
6346
QueryAtomicServiceStartupRule(sptr<IRemoteObject> callerToken,const std::string & appId,const std::string & startTime,AtomicServiceStartupRule & rule)6347 int32_t AbilityManagerProxy::QueryAtomicServiceStartupRule(sptr<IRemoteObject> callerToken,
6348 const std::string &appId, const std::string &startTime, AtomicServiceStartupRule &rule)
6349 {
6350 MessageParcel data;
6351 MessageParcel reply;
6352 MessageOption option;
6353 if (callerToken == nullptr) {
6354 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
6355 return ERR_INVALID_VALUE;
6356 }
6357
6358 if (!WriteInterfaceToken(data)) {
6359 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6360 return INNER_ERR;
6361 }
6362
6363 if (!data.WriteRemoteObject(callerToken)) {
6364 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail");
6365 return INNER_ERR;
6366 }
6367
6368 if (!data.WriteString(appId)) {
6369 TAG_LOGE(AAFwkTag::ABILITYMGR, "write appId fail");
6370 return INNER_ERR;
6371 }
6372
6373 if (!data.WriteString(startTime)) {
6374 TAG_LOGE(AAFwkTag::ABILITYMGR, "write startTime fail");
6375 return INNER_ERR;
6376 }
6377
6378 auto error = SendRequest(AbilityManagerInterfaceCode::QUERY_ATOMIC_SERVICE_STARTUP_RULE, data, reply, option);
6379 if (error != NO_ERROR) {
6380 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6381 return error;
6382 }
6383 rule.isOpenAllowed = reply.ReadBool();
6384 rule.isEmbeddedAllowed = reply.ReadBool();
6385 return reply.ReadInt32();
6386 }
6387
StartSelfUIAbility(const Want & want)6388 int32_t AbilityManagerProxy::StartSelfUIAbility(const Want &want)
6389 {
6390 if (AppUtils::GetInstance().IsForbidStart()) {
6391 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
6392 return INNER_ERR;
6393 }
6394 MessageParcel data;
6395 MessageParcel reply;
6396 MessageOption option;
6397
6398 if (!WriteInterfaceToken(data)) {
6399 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6400 return INNER_ERR;
6401 }
6402
6403 if (!data.WriteParcelable(&want)) {
6404 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail");
6405 return INNER_ERR;
6406 }
6407
6408 auto error = SendRequest(AbilityManagerInterfaceCode::NDK_START_SELF_UI_ABILITY, data, reply, option);
6409 if (error != NO_ERROR) {
6410 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6411 return error;
6412 }
6413 return reply.ReadInt32();
6414 }
6415
StartSelfUIAbilityWithStartOptions(const Want & want,const StartOptions & options)6416 int32_t AbilityManagerProxy::StartSelfUIAbilityWithStartOptions(const Want &want, const StartOptions &options)
6417 {
6418 if (AppUtils::GetInstance().IsForbidStart()) {
6419 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
6420 return INNER_ERR;
6421 }
6422 MessageParcel data;
6423 MessageParcel reply;
6424 MessageOption option;
6425
6426 if (!WriteInterfaceToken(data)) {
6427 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6428 return ERR_WRITE_INTERFACE_CODE;
6429 }
6430
6431 if (!data.WriteParcelable(&want)) {
6432 TAG_LOGE(AAFwkTag::ABILITYMGR, "write want fail");
6433 return ERR_WRITE_WANT;
6434 }
6435
6436 if (!data.WriteParcelable(&options)) {
6437 TAG_LOGE(AAFwkTag::ABILITYMGR, "write startOptions fail");
6438 return ERR_WRITE_START_OPTIONS;
6439 }
6440
6441 auto error = SendRequest(AbilityManagerInterfaceCode::START_SELF_UI_ABILITY_WITH_START_OPTIONS,
6442 data, reply, option);
6443 if (error != NO_ERROR) {
6444 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6445 return error;
6446 }
6447 return reply.ReadInt32();
6448 }
6449
PrepareTerminateAbilityDone(const sptr<IRemoteObject> & token,bool isTerminate)6450 void AbilityManagerProxy::PrepareTerminateAbilityDone(const sptr<IRemoteObject> &token, bool isTerminate)
6451 {
6452 MessageParcel data;
6453 MessageParcel reply;
6454 MessageOption option(MessageOption::TF_SYNC);
6455 if (!WriteInterfaceToken(data)) {
6456 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token fail");
6457 return;
6458 }
6459 if (token) {
6460 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
6461 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6462 return;
6463 }
6464 } else {
6465 TAG_LOGE(AAFwkTag::ABILITYMGR, "null token");
6466 if (!data.WriteBool(false)) {
6467 TAG_LOGE(AAFwkTag::ABILITYMGR, "write fail");
6468 return;
6469 }
6470 }
6471 if (!data.WriteBool(isTerminate)) {
6472 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite isTerminate fail");
6473 return;
6474 }
6475
6476 auto error = SendRequest(AbilityManagerInterfaceCode::PREPARE_TERMINATE_ABILITY_DONE, data, reply, option);
6477 if (error != NO_ERROR) {
6478 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6479 }
6480 }
6481
KillProcessWithPrepareTerminateDone(const std::string & moduleName,int32_t prepareTermination,bool isExist)6482 void AbilityManagerProxy::KillProcessWithPrepareTerminateDone(const std::string &moduleName,
6483 int32_t prepareTermination, bool isExist)
6484 {
6485 MessageParcel data;
6486 MessageParcel reply;
6487 MessageOption option(MessageOption::TF_SYNC);
6488 if (!WriteInterfaceToken(data)) {
6489 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token fail");
6490 return;
6491 }
6492 if (!data.WriteString(moduleName)) {
6493 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite moduleName fail");
6494 return;
6495 }
6496 if (!data.WriteInt32(prepareTermination)) {
6497 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite prepareTermination fail");
6498 return;
6499 }
6500 if (!data.WriteBool(isExist)) {
6501 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite isExist fail");
6502 return;
6503 }
6504
6505 auto error = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS_WITH_PREPARE_TERMINATE_DONE,
6506 data, reply, option);
6507 if (error != NO_ERROR) {
6508 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6509 }
6510 }
6511
KillProcessForPermissionUpdate(uint32_t accessTokenId)6512 int32_t AbilityManagerProxy::KillProcessForPermissionUpdate(uint32_t accessTokenId)
6513 {
6514 MessageParcel data;
6515 MessageParcel reply;
6516 MessageOption option;
6517 if (!WriteInterfaceToken(data)) {
6518 TAG_LOGE(AAFwkTag::ABILITYMGR, "write interface token fail");
6519 return ERR_FLATTEN_OBJECT;
6520 }
6521 if (!data.WriteUint32(accessTokenId)) {
6522 TAG_LOGE(AAFwkTag::ABILITYMGR, "weite accessTokenId fail");
6523 return IPC_PROXY_WRITE_PARCEL_ERR;
6524 }
6525
6526 auto error = SendRequest(AbilityManagerInterfaceCode::KILL_PROCESS_FOR_PERMISSION_UPDATE,
6527 data, reply, option);
6528 if (error != NO_ERROR) {
6529 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6530 return IPC_PROXY_ERR;
6531 }
6532 return reply.ReadInt32();
6533 }
6534
RegisterHiddenStartObserver(const sptr<IHiddenStartObserver> & observer)6535 int32_t AbilityManagerProxy::RegisterHiddenStartObserver(const sptr<IHiddenStartObserver> &observer)
6536 {
6537 if (!observer) {
6538 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer null");
6539 return ERR_INVALID_VALUE;
6540 }
6541 TAG_LOGD(AAFwkTag::ABILITYMGR, "RegisterHiddenStartObserver start");
6542 MessageParcel data;
6543 MessageParcel reply;
6544 MessageOption option;
6545 if (!WriteInterfaceToken(data)) {
6546 return ERR_FLATTEN_OBJECT;
6547 }
6548 if (!data.WriteRemoteObject(observer->AsObject())) {
6549 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write failed.");
6550 return ERR_FLATTEN_OBJECT;
6551 }
6552
6553 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_HIDDEN_START_OBSERVER,
6554 data, reply, option);
6555 if (error != NO_ERROR) {
6556 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
6557 return error;
6558 }
6559 return reply.ReadInt32();
6560 }
6561
UnregisterHiddenStartObserver(const sptr<IHiddenStartObserver> & observer)6562 int32_t AbilityManagerProxy::UnregisterHiddenStartObserver(const sptr<IHiddenStartObserver> &observer)
6563 {
6564 if (!observer) {
6565 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer null");
6566 return ERR_INVALID_VALUE;
6567 }
6568 TAG_LOGD(AAFwkTag::ABILITYMGR, "UnregisterHiddenStartObserver start");
6569 MessageParcel data;
6570 MessageParcel reply;
6571 MessageOption option;
6572 if (!WriteInterfaceToken(data)) {
6573 return ERR_FLATTEN_OBJECT;
6574 }
6575 if (!data.WriteRemoteObject(observer->AsObject())) {
6576 TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write failed.");
6577 return ERR_FLATTEN_OBJECT;
6578 }
6579
6580 auto error = SendRequest(AbilityManagerInterfaceCode::UNREGISTER_HIDDEN_START_OBSERVER,
6581 data, reply, option);
6582 if (error != NO_ERROR) {
6583 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
6584 return error;
6585 }
6586 return reply.ReadInt32();
6587 }
6588
QueryPreLoadUIExtensionRecord(const AppExecFwk::ElementName & element,const std::string & moduleName,const std::string & hostBundleName,int32_t & recordNum,int32_t userId)6589 int32_t AbilityManagerProxy::QueryPreLoadUIExtensionRecord(const AppExecFwk::ElementName &element,
6590 const std::string &moduleName,
6591 const std::string &hostBundleName,
6592 int32_t &recordNum,
6593 int32_t userId)
6594 {
6595 MessageParcel data;
6596 MessageParcel reply;
6597 MessageOption option;
6598
6599 if (!WriteInterfaceToken(data)) {
6600 TAG_LOGE(AAFwkTag::UI_EXT, "write token fail");
6601 return INNER_ERR;
6602 }
6603
6604 if (!data.WriteParcelable(&element)) {
6605 TAG_LOGE(AAFwkTag::UI_EXT, "write element fail");
6606 return ERR_INVALID_VALUE;
6607 }
6608
6609 if (!data.WriteString(moduleName)) {
6610 TAG_LOGE(AAFwkTag::UI_EXT, "write moduleName fail");
6611 return ERR_INVALID_VALUE;
6612 }
6613
6614 if (!data.WriteString(hostBundleName)) {
6615 TAG_LOGE(AAFwkTag::UI_EXT, "write hostBundleName fail");
6616 return INNER_ERR;
6617 }
6618
6619 if (!data.WriteInt32(userId)) {
6620 TAG_LOGE(AAFwkTag::UI_EXT, "write userId fail");
6621 return INNER_ERR;
6622 }
6623
6624 auto error =
6625 SendRequest(AbilityManagerInterfaceCode::QUERY_PRELOAD_UIEXTENSION_RECORD,
6626 data, reply, option);
6627 if (error != NO_ERROR) {
6628 TAG_LOGE(AAFwkTag::UI_EXT, "request error:%{public}d", error);
6629 return error;
6630 }
6631 recordNum = reply.ReadInt32();
6632 return NO_ERROR;
6633 }
6634
RevokeDelegator(sptr<IRemoteObject> token)6635 int32_t AbilityManagerProxy::RevokeDelegator(sptr<IRemoteObject> token)
6636 {
6637 MessageParcel data;
6638 MessageParcel reply;
6639 MessageOption option;
6640
6641 if (token == nullptr) {
6642 TAG_LOGE(AAFwkTag::ABILITYMGR, "null token");
6643 return ERR_INVALID_CONTEXT;
6644 }
6645
6646 if (!WriteInterfaceToken(data)) {
6647 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
6648 return INNER_ERR;
6649 }
6650
6651 if (!data.WriteRemoteObject(token)) {
6652 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6653 return ERR_INVALID_VALUE;
6654 }
6655
6656 int error = SendRequest(AbilityManagerInterfaceCode::REVOKE_DELEGATOR, data, reply, option);
6657 if (error != NO_ERROR) {
6658 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6659 return error;
6660 }
6661 return reply.ReadInt32();
6662 }
6663
StartAbilityWithWait(Want & want,sptr<IAbilityStartWithWaitObserver> & observer)6664 int32_t AbilityManagerProxy::StartAbilityWithWait(Want &want, sptr<IAbilityStartWithWaitObserver> &observer)
6665 {
6666 if (AppUtils::GetInstance().IsForbidStart()) {
6667 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", want.GetElement().GetBundleName().c_str());
6668 return INNER_ERR;
6669 }
6670 CHECK_POINTER_AND_RETURN_LOG(observer, ERR_NULL_OBJECT, "null observer");
6671
6672 MessageParcel data;
6673 MessageParcel reply;
6674 MessageOption option;
6675
6676 if (!WriteInterfaceToken(data)) {
6677 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
6678 return INNER_ERR;
6679 }
6680
6681 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Parcelable, &want);
6682 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, observer->AsObject());
6683 int32_t error = SendRequest(AbilityManagerInterfaceCode::START_ABILITY_WITH_WAIT, data, reply, option);
6684 if (error != NO_ERROR) {
6685 TAG_LOGE(AAFwkTag::ABILITYMGR, "send err:%{public}d", error);
6686 return error;
6687 }
6688 return reply.ReadInt32();
6689 }
6690
GetAllInsightIntentInfo(AbilityRuntime::GetInsightIntentFlag flag,std::vector<InsightIntentInfoForQuery> & infos)6691 int32_t AbilityManagerProxy::GetAllInsightIntentInfo(
6692 AbilityRuntime::GetInsightIntentFlag flag,
6693 std::vector<InsightIntentInfoForQuery> &infos)
6694 {
6695 MessageParcel data;
6696 MessageParcel reply;
6697 MessageOption option;
6698
6699 TAG_LOGI(AAFwkTag::INTENT, "GetAllInsightIntentInfo");
6700 if (!WriteInterfaceToken(data)) {
6701 TAG_LOGE(AAFwkTag::INTENT, "writeInterfaceToken failed");
6702 return INNER_ERR;
6703 }
6704
6705 if (!data.WriteUint32(static_cast<uint32_t>(flag))) {
6706 TAG_LOGE(AAFwkTag::INTENT, "write flag fail");
6707 return ERR_INVALID_VALUE;
6708 }
6709
6710 int error = SendRequest(
6711 AbilityManagerInterfaceCode::GET_ALL_INSIGHT_INTENT_INFO, data, reply, option);
6712 if (error != NO_ERROR) {
6713 TAG_LOGE(AAFwkTag::INTENT, "request error:%{public}d", error);
6714 return error;
6715 }
6716 int32_t infoSize = reply.ReadInt32();
6717 infos.clear();
6718 for (int32_t i = 0; i < infoSize; i++) {
6719 std::unique_ptr<InsightIntentInfoForQuery> info(reply.ReadParcelable<InsightIntentInfoForQuery>());
6720 if (info == nullptr) {
6721 return false;
6722 }
6723 infos.emplace_back(*info);
6724 }
6725 return reply.ReadInt32();
6726 }
6727
GetInsightIntentInfoByBundleName(AbilityRuntime::GetInsightIntentFlag flag,const std::string & bundleName,std::vector<InsightIntentInfoForQuery> & infos)6728 int32_t AbilityManagerProxy::GetInsightIntentInfoByBundleName(
6729 AbilityRuntime::GetInsightIntentFlag flag,
6730 const std::string &bundleName,
6731 std::vector<InsightIntentInfoForQuery> &infos)
6732 {
6733 MessageParcel data;
6734 MessageParcel reply;
6735 MessageOption option;
6736
6737 if (!WriteInterfaceToken(data)) {
6738 TAG_LOGE(AAFwkTag::INTENT, "writeInterfaceToken failed");
6739 return INNER_ERR;
6740 }
6741
6742 if (!data.WriteUint32(static_cast<uint32_t>(flag))) {
6743 TAG_LOGE(AAFwkTag::INTENT, "write flag fail");
6744 return ERR_INVALID_VALUE;
6745 }
6746
6747 if (!data.WriteString(bundleName)) {
6748 TAG_LOGE(AAFwkTag::INTENT, "write bundleName fail");
6749 return ERR_INVALID_VALUE;
6750 }
6751
6752 int error = SendRequest(
6753 AbilityManagerInterfaceCode::GET_INSIGHT_INTENT_INFO_BY_BUNDLE_NAME, data, reply, option);
6754 if (error != NO_ERROR) {
6755 TAG_LOGE(AAFwkTag::INTENT, "request error:%{public}d", error);
6756 return error;
6757 }
6758 int32_t infoSize = reply.ReadInt32();
6759 infos.clear();
6760 for (int32_t i = 0; i < infoSize; i++) {
6761 std::unique_ptr<InsightIntentInfoForQuery> info(reply.ReadParcelable<InsightIntentInfoForQuery>());
6762 if (info == nullptr) {
6763 return false;
6764 }
6765 infos.emplace_back(*info);
6766 }
6767 return reply.ReadInt32();
6768 }
6769
GetInsightIntentInfoByIntentName(AbilityRuntime::GetInsightIntentFlag flag,const std::string & bundleName,const std::string & moduleName,const std::string & intentName,InsightIntentInfoForQuery & info)6770 int32_t AbilityManagerProxy::GetInsightIntentInfoByIntentName(
6771 AbilityRuntime::GetInsightIntentFlag flag,
6772 const std::string &bundleName,
6773 const std::string &moduleName,
6774 const std::string &intentName,
6775 InsightIntentInfoForQuery &info)
6776 {
6777 MessageParcel data;
6778 MessageParcel reply;
6779 MessageOption option;
6780
6781 if (!WriteInterfaceToken(data)) {
6782 TAG_LOGE(AAFwkTag::INTENT, "writeInterfaceToken failed");
6783 return INNER_ERR;
6784 }
6785
6786 if (!data.WriteUint32(static_cast<uint32_t>(flag))) {
6787 TAG_LOGE(AAFwkTag::INTENT, "write flag fail");
6788 return ERR_INVALID_VALUE;
6789 }
6790
6791 if (!data.WriteString(bundleName)) {
6792 TAG_LOGE(AAFwkTag::INTENT, "write bundleName fail");
6793 return ERR_INVALID_VALUE;
6794 }
6795
6796 if (!data.WriteString(moduleName)) {
6797 TAG_LOGE(AAFwkTag::INTENT, "write moduleName fail");
6798 return ERR_INVALID_VALUE;
6799 }
6800
6801 if (!data.WriteString(intentName)) {
6802 TAG_LOGE(AAFwkTag::INTENT, "write intentName fail");
6803 return ERR_INVALID_VALUE;
6804 }
6805
6806 int error = SendRequest(
6807 AbilityManagerInterfaceCode::GET_INSIGHT_INTENT_INFO_BY_INTENT_NAME, data, reply, option);
6808 if (error != NO_ERROR) {
6809 TAG_LOGE(AAFwkTag::INTENT, "request error:%{public}d", error);
6810 return error;
6811 }
6812 std::unique_ptr<InsightIntentInfoForQuery> intentInfo(reply.ReadParcelable<InsightIntentInfoForQuery>());
6813 if (intentInfo == nullptr) {
6814 return false;
6815 }
6816 info = *intentInfo;
6817 return reply.ReadInt32();
6818 }
6819
6820
SuspendExtensionAbility(sptr<IAbilityConnection> connect)6821 int32_t AbilityManagerProxy::SuspendExtensionAbility(sptr<IAbilityConnection> connect)
6822 {
6823 MessageParcel data;
6824 MessageParcel reply;
6825 MessageOption option;
6826 if (connect == nullptr) {
6827 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail, connect null");
6828 return ERR_INVALID_VALUE;
6829 }
6830 if (!WriteInterfaceToken(data)) {
6831 return INNER_ERR;
6832 }
6833 if (!data.WriteRemoteObject(connect->AsObject())) {
6834 TAG_LOGE(AAFwkTag::SERVICE_EXT, "connect write failed");
6835 return ERR_INVALID_VALUE;
6836 }
6837
6838 int32_t error = SendRequest(AbilityManagerInterfaceCode::SUSPEND_EXTENSION_ABILITY, data, reply, option);
6839 if (error != NO_ERROR) {
6840 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
6841 return error;
6842 }
6843 return reply.ReadInt32();
6844 }
6845
ResumeExtensionAbility(sptr<IAbilityConnection> connect)6846 int32_t AbilityManagerProxy::ResumeExtensionAbility(sptr<IAbilityConnection> connect)
6847 {
6848 MessageParcel data;
6849 MessageParcel reply;
6850 MessageOption option;
6851 if (connect == nullptr) {
6852 TAG_LOGE(AAFwkTag::SERVICE_EXT, "fail, connect null");
6853 return ERR_INVALID_VALUE;
6854 }
6855 if (!WriteInterfaceToken(data)) {
6856 return INNER_ERR;
6857 }
6858 if (!data.WriteRemoteObject(connect->AsObject())) {
6859 TAG_LOGE(AAFwkTag::SERVICE_EXT, "connect write failed");
6860 return ERR_INVALID_VALUE;
6861 }
6862
6863 int32_t error = SendRequest(AbilityManagerInterfaceCode::RESUME_EXTENSION_ABILITY, data, reply, option);
6864 if (error != NO_ERROR) {
6865 TAG_LOGE(AAFwkTag::SERVICE_EXT, "request error:%{public}d", error);
6866 return error;
6867 }
6868 return reply.ReadInt32();
6869 }
6870
RestartSelfAtomicService(sptr<IRemoteObject> callerToken)6871 int32_t AbilityManagerProxy::RestartSelfAtomicService(sptr<IRemoteObject> callerToken)
6872 {
6873 MessageParcel data;
6874 MessageParcel reply;
6875 MessageOption option;
6876 if (callerToken == nullptr) {
6877 TAG_LOGE(AAFwkTag::ABILITYMGR, "null callerToken");
6878 return INVALID_CALLER_TOKEN;
6879 }
6880
6881 if (!WriteInterfaceToken(data)) {
6882 TAG_LOGE(AAFwkTag::ABILITYMGR, "write token fail");
6883 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
6884 }
6885
6886 if (!data.WriteRemoteObject(callerToken)) {
6887 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail");
6888 return ERR_WRITE_CALLER_TOKEN_FAILED;
6889 }
6890
6891 auto error = SendRequest(AbilityManagerInterfaceCode::RESTART_SELF_ATOMIC_SERVICE, data, reply, option);
6892 if (error != NO_ERROR) {
6893 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6894 return error;
6895 }
6896 return reply.ReadInt32();
6897 }
6898
UpdateKioskApplicationList(const std::vector<std::string> & appList)6899 int32_t AbilityManagerProxy::UpdateKioskApplicationList(const std::vector<std::string> &appList)
6900 {
6901 MessageParcel data;
6902 MessageParcel reply;
6903 MessageOption option;
6904
6905 if (!WriteInterfaceToken(data)) {
6906 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
6907 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
6908 }
6909
6910 if (!data.WriteStringVector(appList)) {
6911 TAG_LOGE(AAFwkTag::ABILITYMGR, "appList write fail");
6912 return ERR_WRITE_KIOSK_UPDATE_APP_LIST_FAILED;
6913 }
6914
6915 auto error =
6916 SendRequest(AbilityManagerInterfaceCode::UPDATE_KIOSK_APP_LIST, data, reply, option);
6917 if (error != NO_ERROR) {
6918 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6919 return error;
6920 }
6921
6922 return reply.ReadInt32();
6923 }
6924
EnterKioskMode(sptr<IRemoteObject> callerToken)6925 int32_t AbilityManagerProxy::EnterKioskMode(sptr<IRemoteObject> callerToken)
6926 {
6927 MessageParcel data;
6928 MessageParcel reply;
6929 MessageOption option;
6930
6931 if (callerToken == nullptr) {
6932 TAG_LOGE(AAFwkTag::ABILITYMGR, "null token");
6933 return ERR_INVALID_CONTEXT;
6934 }
6935
6936 if (!WriteInterfaceToken(data)) {
6937 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
6938 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
6939 }
6940
6941 if (!data.WriteRemoteObject(callerToken)) {
6942 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail");
6943 return ERR_WRITE_CALLER_TOKEN_FAILED;
6944 }
6945
6946 auto error = SendRequest(AbilityManagerInterfaceCode::ENTER_KIOSK_MODE, data, reply, option);
6947 if (error != NO_ERROR) {
6948 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6949 return error;
6950 }
6951
6952 return reply.ReadInt32();
6953 }
6954
ExitKioskMode(sptr<IRemoteObject> callerToken)6955 int32_t AbilityManagerProxy::ExitKioskMode(sptr<IRemoteObject> callerToken)
6956 {
6957 MessageParcel data;
6958 MessageParcel reply;
6959 MessageOption option;
6960
6961 if (callerToken == nullptr) {
6962 TAG_LOGE(AAFwkTag::ABILITYMGR, "null token");
6963 return ERR_INVALID_CONTEXT;
6964 }
6965
6966 if (!WriteInterfaceToken(data)) {
6967 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
6968 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
6969 }
6970
6971 if (!data.WriteRemoteObject(callerToken)) {
6972 TAG_LOGE(AAFwkTag::ABILITYMGR, "write callerToken fail");
6973 return ERR_WRITE_CALLER_TOKEN_FAILED;
6974 }
6975
6976 auto error = SendRequest(AbilityManagerInterfaceCode::EXIT_KIOSK_MODE, data, reply, option);
6977 if (error != NO_ERROR) {
6978 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6979 return error;
6980 }
6981
6982 return reply.ReadInt32();
6983 }
6984
GetKioskStatus(KioskStatus & kioskStatus)6985 int32_t AbilityManagerProxy::GetKioskStatus(KioskStatus &kioskStatus)
6986 {
6987 MessageParcel data;
6988 MessageParcel reply;
6989 MessageOption option;
6990
6991 if (!WriteInterfaceToken(data)) {
6992 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
6993 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
6994 }
6995
6996 auto error = SendRequest(AbilityManagerInterfaceCode::GET_KIOSK_INFO, data, reply, option);
6997 if (error != NO_ERROR) {
6998 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error:%{public}d", error);
6999 return error;
7000 }
7001
7002 std::unique_ptr<KioskStatus> info(reply.ReadParcelable<KioskStatus>());
7003 if (!info) {
7004 TAG_LOGE(AAFwkTag::ABILITYMGR, "read KioskStatus fail");
7005 return ERR_READ_RESULT_PARCEL_FAILED;
7006 }
7007 kioskStatus = *info;
7008 sptr<IRemoteObject> token = reply.ReadRemoteObject();
7009 if (token != nullptr) {
7010 kioskStatus.kioskToken_ = token;
7011 }
7012 return reply.ReadInt32();
7013 }
7014
RegisterSAInterceptor(sptr<AbilityRuntime::ISAInterceptor> interceptor)7015 ErrCode AbilityManagerProxy::RegisterSAInterceptor(sptr<AbilityRuntime::ISAInterceptor> interceptor)
7016 {
7017 TAG_LOGD(AAFwkTag::ABILITYMGR, "call RegisterSAInterceptor");
7018 if (!interceptor) {
7019 TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptor null");
7020 return ERR_NULL_SA_INTERCEPTOR_EXECUTER;
7021 }
7022
7023 MessageParcel data;
7024 MessageParcel reply;
7025 MessageOption option;
7026
7027 if (!WriteInterfaceToken(data)) {
7028 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
7029 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
7030 }
7031 if (!data.WriteRemoteObject(interceptor->AsObject())) {
7032 TAG_LOGE(AAFwkTag::ABILITYMGR, "interceptor write failed.");
7033 return ERR_WRITE_SA_INTERCEPTOR_FAILED;
7034 }
7035
7036 auto error = SendRequest(AbilityManagerInterfaceCode::REGISTER_SA_INTERCEPTOR, data, reply, option);
7037 if (error != NO_ERROR) {
7038 TAG_LOGE(AAFwkTag::ABILITYMGR, "Send request error: %{public}d", error);
7039 return error;
7040 }
7041 return reply.ReadInt32();
7042 }
7043
SetAppServiceExtensionKeepAlive(const std::string & bundleName,bool flag)7044 int32_t AbilityManagerProxy::SetAppServiceExtensionKeepAlive(const std::string &bundleName, bool flag)
7045 {
7046 MessageParcel data;
7047 if (!WriteInterfaceToken(data)) {
7048 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
7049 return INNER_ERR;
7050 }
7051
7052 if (!data.WriteString(bundleName)) {
7053 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write bundleName");
7054 return ERR_INVALID_VALUE;
7055 }
7056
7057 if (!data.WriteBool(flag)) {
7058 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write flag");
7059 return ERR_INVALID_VALUE;
7060 }
7061
7062 MessageParcel reply;
7063 MessageOption option;
7064 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_APP_SERVICE_EXTENSION_KEEP_ALIVE,
7065 data, reply, option);
7066 if (ret != NO_ERROR) {
7067 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
7068 return ret;
7069 }
7070 return reply.ReadInt32();
7071 }
7072
QueryKeepAliveAppServiceExtensions(std::vector<KeepAliveInfo> & list)7073 int32_t AbilityManagerProxy::QueryKeepAliveAppServiceExtensions(std::vector<KeepAliveInfo> &list)
7074 {
7075 MessageParcel data;
7076 if (!WriteInterfaceToken(data)) {
7077 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
7078 return INNER_ERR;
7079 }
7080
7081 MessageParcel reply;
7082 MessageOption option;
7083 auto ret = SendRequest(AbilityManagerInterfaceCode::GET_APP_SERVICE_EXTENSIONS_KEEP_ALIVE,
7084 data, reply, option);
7085 if (ret != NO_ERROR) {
7086 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
7087 return ret;
7088 }
7089
7090 ret = GetParcelableInfos<KeepAliveInfo>(reply, list);
7091 if (ret != NO_ERROR) {
7092 TAG_LOGE(AAFwkTag::ABILITYMGR, "GetParcelableInfos error: %{public}d", ret);
7093 return ret;
7094 }
7095
7096 return reply.ReadInt32();
7097 }
7098
SetOnNewWantSkipScenarios(sptr<IRemoteObject> callerToken,int32_t scenarios)7099 int32_t AbilityManagerProxy::SetOnNewWantSkipScenarios(sptr<IRemoteObject> callerToken, int32_t scenarios)
7100 {
7101 if (callerToken == nullptr) {
7102 TAG_LOGE(AAFwkTag::ABILITYMGR, "null token");
7103 return ERR_INVALID_CONTEXT;
7104 }
7105
7106 MessageParcel data;
7107 if (!WriteInterfaceToken(data)) {
7108 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
7109 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
7110 }
7111 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, RemoteObject, callerToken);
7112 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, scenarios);
7113
7114 MessageParcel reply;
7115 MessageOption option;
7116 auto ret = SendRequest(AbilityManagerInterfaceCode::SET_ON_NEW_WANT_SKIP_SCENARIOS, data, reply, option);
7117 if (ret != NO_ERROR) {
7118 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
7119 return ret;
7120 }
7121 return reply.ReadInt32();
7122 }
7123
NotifyStartupExceptionBySCB(int32_t requestId)7124 int32_t AbilityManagerProxy::NotifyStartupExceptionBySCB(int32_t requestId)
7125 {
7126 MessageParcel data;
7127 if (!WriteInterfaceToken(data)) {
7128 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken failed");
7129 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
7130 }
7131 PROXY_WRITE_PARCEL_AND_RETURN_IF_FAIL(data, Int32, requestId);
7132
7133 MessageParcel reply;
7134 MessageOption option;
7135 auto ret = SendRequest(AbilityManagerInterfaceCode::NOTIFY_STARTUP_EXCEPTION_BY_SCB, data, reply, option);
7136 if (ret != NO_ERROR) {
7137 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
7138 return ret;
7139 }
7140
7141 return reply.ReadInt32();
7142 }
7143
PreloadApplication(const std::string & bundleName,int32_t userId,int32_t appIndex)7144 int32_t AbilityManagerProxy::PreloadApplication(const std::string &bundleName, int32_t userId, int32_t appIndex)
7145 {
7146 if (AppUtils::GetInstance().IsForbidStart()) {
7147 TAG_LOGW(AAFwkTag::ABILITYMGR, "forbid start: %{public}s", bundleName.c_str());
7148 return INNER_ERR;
7149 }
7150 MessageParcel data;
7151 if (!WriteInterfaceToken(data)) {
7152 TAG_LOGE(AAFwkTag::ABILITYMGR, "writeInterfaceToken fail");
7153 return ERR_WRITE_INTERFACE_TOKEN_FAILED;
7154 }
7155
7156 MessageParcel reply;
7157 MessageOption option;
7158
7159 if (!data.WriteString(bundleName)) {
7160 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write bundleName");
7161 return ERR_WRITE_STRING_FAILED;
7162 }
7163
7164 if (!data.WriteInt32(userId)) {
7165 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write userId");
7166 return ERR_WRITE_INT_FAILED;
7167 }
7168
7169 if (!data.WriteInt32(appIndex)) {
7170 TAG_LOGE(AAFwkTag::ABILITYMGR, "failed to write appIndex");
7171 return ERR_WRITE_INT_FAILED;
7172 }
7173
7174 auto ret = SendRequest(AbilityManagerInterfaceCode::PRELOAD_APPLICATION, data, reply, option);
7175 if (ret != NO_ERROR) {
7176 TAG_LOGE(AAFwkTag::ABILITYMGR, "request error: %{public}d", ret);
7177 return ret;
7178 }
7179
7180 return reply.ReadInt32();
7181 }
7182 } // namespace AAFwk
7183 } // namespace OHOS
7184