1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ams_mgr_proxy.h"
17 #include "ipc_types.h"
18 #include "iremote_object.h"
19 #include "param.h"
20 #include "string_ex.h"
21
22 #include "appexecfwk_errors.h"
23 #include "hilog_tag_wrapper.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
27 namespace {
28 constexpr int32_t MAX_APP_DEBUG_COUNT = 100;
29 }
AmsMgrProxy(const sptr<IRemoteObject> & impl)30 AmsMgrProxy::AmsMgrProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IAmsMgr>(impl)
31 {}
32
IsProcessContainsOnlyUIAbility(const pid_t pid)33 bool AmsMgrProxy::IsProcessContainsOnlyUIAbility(const pid_t pid)
34 {
35 TAG_LOGD(AAFwkTag::APPMGR, "IsProcessContainsOnlyUIAbility start");
36 MessageParcel data;
37 MessageParcel reply;
38 MessageOption option(MessageOption::TF_SYNC);
39 if (!WriteInterfaceToken(data)) {
40 return false;
41 }
42 data.WriteInt32(static_cast<int32_t>(pid));
43 int32_t ret =
44 SendTransactCmd(static_cast<uint32_t>(
45 IAmsMgr::Message::IS_PROCESS_CONTAINS_ONLY_UI_EXTENSION), data, reply, option);
46 if (ret != NO_ERROR) {
47 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
48 return false;
49 }
50 TAG_LOGD(AAFwkTag::APPMGR, "IsProcessContainsOnlyUIAbility end");
51 return reply.ReadBool();
52 }
53
WriteInterfaceToken(MessageParcel & data)54 bool AmsMgrProxy::WriteInterfaceToken(MessageParcel &data)
55 {
56 if (!data.WriteInterfaceToken(AmsMgrProxy::GetDescriptor())) {
57 TAG_LOGE(AAFwkTag::APPMGR, "write token failed");
58 return false;
59 }
60 return true;
61 }
62 namespace {
WriteTokenObject(MessageParcel & data,sptr<IRemoteObject> token)63 bool WriteTokenObject(MessageParcel &data, sptr<IRemoteObject> token)
64 {
65 if (token) {
66 if (!data.WriteBool(true) || !data.WriteRemoteObject(token)) {
67 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag or token");
68 return false;
69 }
70 } else {
71 if (!data.WriteBool(false)) {
72 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
73 return false;
74 }
75 }
76 return true;
77 }
78 }
79
LoadAbility(const std::shared_ptr<AbilityInfo> & abilityInfo,const std::shared_ptr<ApplicationInfo> & appInfo,const std::shared_ptr<AAFwk::Want> & want,std::shared_ptr<AbilityRuntime::LoadParam> loadParam)80 void AmsMgrProxy::LoadAbility(const std::shared_ptr<AbilityInfo> &abilityInfo,
81 const std::shared_ptr<ApplicationInfo> &appInfo,
82 const std::shared_ptr<AAFwk::Want> &want, std::shared_ptr<AbilityRuntime::LoadParam> loadParam)
83 {
84 TAG_LOGD(AAFwkTag::APPMGR, "start");
85 if (!abilityInfo || !appInfo) {
86 TAG_LOGE(AAFwkTag::APPMGR, "param error");
87 return;
88 }
89
90 MessageParcel data;
91 MessageParcel reply;
92 MessageOption option(MessageOption::TF_SYNC);
93 if (!WriteInterfaceToken(data)) {
94 return;
95 }
96
97 data.WriteParcelable(abilityInfo.get());
98 data.WriteParcelable(appInfo.get());
99 if (!data.WriteParcelable(want.get())) {
100 TAG_LOGE(AAFwkTag::APPMGR, "Write want failed");
101 return;
102 }
103 if (!data.WriteParcelable(loadParam.get())) {
104 TAG_LOGE(AAFwkTag::APPMGR, "Write data loadParam failed");
105 return;
106 }
107
108 int32_t ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::LOAD_ABILITY), data, reply, option);
109 if (ret != NO_ERROR) {
110 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
111 }
112 TAG_LOGD(AAFwkTag::APPMGR, "end");
113 }
114
TerminateAbility(const sptr<IRemoteObject> & token,bool clearMissionFlag)115 void AmsMgrProxy::TerminateAbility(const sptr<IRemoteObject> &token, bool clearMissionFlag)
116 {
117 TAG_LOGD(AAFwkTag::APPMGR, "start");
118 MessageParcel data;
119 MessageParcel reply;
120 MessageOption option(MessageOption::TF_SYNC);
121 if (!WriteInterfaceToken(data)) {
122 return;
123 }
124 if (!data.WriteRemoteObject(token.GetRefPtr())) {
125 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
126 return;
127 }
128 if (!data.WriteBool(clearMissionFlag)) {
129 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write clearMissionFlag");
130 return;
131 }
132 int32_t ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::TERMINATE_ABILITY), data, reply, option);
133 if (ret != NO_ERROR) {
134 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
135 }
136 TAG_LOGD(AAFwkTag::APPMGR, "end");
137 }
138
UpdateAbilityState(const sptr<IRemoteObject> & token,const AbilityState state)139 void AmsMgrProxy::UpdateAbilityState(const sptr<IRemoteObject> &token, const AbilityState state)
140 {
141 TAG_LOGD(AAFwkTag::APPMGR, "start");
142 MessageParcel data;
143 MessageParcel reply;
144 MessageOption option(MessageOption::TF_SYNC);
145 if (!WriteInterfaceToken(data)) {
146 return;
147 }
148 if (!data.WriteRemoteObject(token.GetRefPtr())) {
149 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
150 return;
151 }
152 data.WriteInt32(static_cast<int32_t>(state));
153 int32_t ret =
154 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::UPDATE_ABILITY_STATE), data, reply, option);
155 if (ret != NO_ERROR) {
156 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
157 }
158 TAG_LOGD(AAFwkTag::APPMGR, "end");
159 }
160
UpdateExtensionState(const sptr<IRemoteObject> & token,const ExtensionState state)161 void AmsMgrProxy::UpdateExtensionState(const sptr<IRemoteObject> &token, const ExtensionState state)
162 {
163 TAG_LOGD(AAFwkTag::APPMGR, "UpdateExtensionState begin");
164 MessageParcel data;
165 MessageParcel reply;
166 MessageOption option(MessageOption::TF_SYNC);
167 if (!WriteInterfaceToken(data)) {
168 return;
169 }
170 if (!data.WriteRemoteObject(token.GetRefPtr())) {
171 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
172 return;
173 }
174 data.WriteInt32(static_cast<int32_t>(state));
175 int32_t ret =
176 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::UPDATE_EXTENSION_STATE), data, reply, option);
177 if (ret != NO_ERROR) {
178 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
179 }
180 TAG_LOGD(AAFwkTag::APPMGR, "end");
181 }
182
RegisterAppStateCallback(const sptr<IAppStateCallback> & callback)183 void AmsMgrProxy::RegisterAppStateCallback(const sptr<IAppStateCallback> &callback)
184 {
185 TAG_LOGD(AAFwkTag::APPMGR, "begin");
186 if (!callback) {
187 TAG_LOGE(AAFwkTag::APPMGR, "callback null");
188 return;
189 }
190
191 MessageParcel data;
192 MessageParcel reply;
193 MessageOption option(MessageOption::TF_SYNC);
194 if (!WriteInterfaceToken(data)) {
195 return;
196 }
197
198 if (callback->AsObject()) {
199 if (!data.WriteBool(true) || !data.WriteRemoteObject(callback->AsObject())) {
200 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and callback");
201 return;
202 }
203 } else {
204 if (!data.WriteBool(false)) {
205 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
206 return;
207 }
208 }
209
210 int32_t ret = SendTransactCmd(
211 static_cast<uint32_t>(IAmsMgr::Message::REGISTER_APP_STATE_CALLBACK), data, reply, option);
212 if (ret != NO_ERROR) {
213 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
214 }
215 TAG_LOGD(AAFwkTag::APPMGR, "end");
216 }
217
AbilityBehaviorAnalysis(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & preToken,const int32_t visibility,const int32_t perceptibility,const int32_t connectionState)218 void AmsMgrProxy::AbilityBehaviorAnalysis(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken,
219 const int32_t visibility, const int32_t perceptibility, const int32_t connectionState)
220 {
221 TAG_LOGD(AAFwkTag::APPMGR, "start");
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option(MessageOption::TF_SYNC);
225 if (!WriteInterfaceToken(data)) {
226 return;
227 }
228
229 if (!data.WriteRemoteObject(token.GetRefPtr())) {
230 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
231 return;
232 }
233
234 if (preToken) {
235 if (!data.WriteBool(true) || !data.WriteRemoteObject(preToken.GetRefPtr())) {
236 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag and preToken");
237 return;
238 }
239 } else {
240 if (!data.WriteBool(false)) {
241 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write flag");
242 return;
243 }
244 }
245
246 data.WriteInt32(static_cast<int32_t>(visibility));
247 data.WriteInt32(static_cast<int32_t>(perceptibility));
248 data.WriteInt32(static_cast<int32_t>(connectionState));
249 int32_t ret =
250 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::ABILITY_BEHAVIOR_ANALYSIS), data, reply, option);
251 if (ret != NO_ERROR) {
252 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
253 }
254 TAG_LOGD(AAFwkTag::APPMGR, "end");
255 }
256
KillProcessByAbilityToken(const sptr<IRemoteObject> & token)257 void AmsMgrProxy::KillProcessByAbilityToken(const sptr<IRemoteObject> &token)
258 {
259 TAG_LOGI(AAFwkTag::APPMGR, "start");
260 MessageParcel data;
261 MessageParcel reply;
262 MessageOption option(MessageOption::TF_SYNC);
263 if (!WriteInterfaceToken(data)) {
264 return;
265 }
266 if (!data.WriteRemoteObject(token.GetRefPtr())) {
267 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
268 return;
269 }
270 int32_t ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_PEOCESS_BY_ABILITY_TOKEN),
271 data, reply, option);
272 if (ret != NO_ERROR) {
273 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
274 }
275 TAG_LOGD(AAFwkTag::APPMGR, "end");
276 }
277
KillProcessesByUserId(int32_t userId)278 void AmsMgrProxy::KillProcessesByUserId(int32_t userId)
279 {
280 TAG_LOGI(AAFwkTag::APPMGR, "start");
281 MessageParcel data;
282 MessageParcel reply;
283 MessageOption option(MessageOption::TF_SYNC);
284 if (!WriteInterfaceToken(data)) {
285 return;
286 }
287 if (!data.WriteInt32(userId)) {
288 TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteInt32 failed");
289 return;
290 }
291 int32_t ret =
292 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_BY_USERID), data, reply, option);
293 if (ret != NO_ERROR) {
294 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
295 }
296 TAG_LOGD(AAFwkTag::APPMGR, "ending");
297 }
298
KillProcessesByPids(std::vector<int32_t> & pids)299 void AmsMgrProxy::KillProcessesByPids(std::vector<int32_t> &pids)
300 {
301 TAG_LOGI(AAFwkTag::APPMGR, "start");
302 MessageParcel data;
303 MessageParcel reply;
304 MessageOption option;
305
306 if (!WriteInterfaceToken(data)) {
307 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
308 return;
309 }
310 if (!data.WriteUint32(pids.size())) {
311 TAG_LOGE(AAFwkTag::APPMGR, "Write size failed");
312 return;
313 }
314 for (const auto &pid: pids) {
315 if (!data.WriteInt32(pid)) {
316 TAG_LOGE(AAFwkTag::APPMGR, "Write pid failed");
317 return;
318 }
319 }
320 int32_t ret =
321 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESSES_BY_PIDS), data, reply, option);
322 if (ret != NO_ERROR) {
323 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
324 }
325 TAG_LOGD(AAFwkTag::APPMGR, "end");
326 }
327
AttachPidToParent(const sptr<IRemoteObject> & token,const sptr<IRemoteObject> & callerToken)328 void AmsMgrProxy::AttachPidToParent(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &callerToken)
329 {
330 TAG_LOGD(AAFwkTag::APPMGR, "start");
331 MessageParcel data;
332 MessageParcel reply;
333 MessageOption option;
334 if (!WriteInterfaceToken(data)) {
335 return;
336 }
337 if (!data.WriteRemoteObject(token)) {
338 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
339 return;
340 }
341 if (!data.WriteRemoteObject(callerToken)) {
342 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write callerToken");
343 return;
344 }
345 int32_t ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::ATTACH_PID_TO_PARENT),
346 data, reply, option);
347 if (ret != NO_ERROR) {
348 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
349 }
350 TAG_LOGD(AAFwkTag::APPMGR, "end");
351 }
352
KillProcessWithAccount(const std::string & bundleName,const int accountId)353 int32_t AmsMgrProxy::KillProcessWithAccount(const std::string &bundleName, const int accountId)
354 {
355 TAG_LOGI(AAFwkTag::APPMGR, "start");
356
357 MessageParcel data;
358 MessageParcel reply;
359 MessageOption option(MessageOption::TF_SYNC);
360 if (!WriteInterfaceToken(data)) {
361 return ERR_INVALID_DATA;
362 }
363
364 if (!data.WriteString(bundleName)) {
365 TAG_LOGE(AAFwkTag::APPMGR, "WriteString failed");
366 return ERR_FLATTEN_OBJECT;
367 }
368
369 if (!data.WriteInt32(accountId)) {
370 TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteInt32 failed");
371 return ERR_FLATTEN_OBJECT;
372 }
373
374 int32_t ret =
375 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_PROCESS_WITH_ACCOUNT), data, reply, option);
376 if (ret != NO_ERROR) {
377 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
378 return ret;
379 }
380
381 TAG_LOGD(AAFwkTag::APPMGR, "end");
382
383 return reply.ReadInt32();
384 }
385
KillApplication(const std::string & bundleName)386 int32_t AmsMgrProxy::KillApplication(const std::string &bundleName)
387 {
388 TAG_LOGI(AAFwkTag::APPMGR, "start");
389 MessageParcel data;
390 MessageParcel reply;
391 MessageOption option(MessageOption::TF_SYNC);
392 if (!WriteInterfaceToken(data)) {
393 return ERR_INVALID_DATA;
394 }
395 if (!data.WriteString(bundleName)) {
396 TAG_LOGE(AAFwkTag::APPMGR, "WriteString failed");
397 return ERR_FLATTEN_OBJECT;
398 }
399 int32_t ret =
400 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION), data, reply, option);
401 if (ret != NO_ERROR) {
402 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d.", ret);
403 return ret;
404 }
405 return reply.ReadInt32();
406 }
407
ForceKillApplication(const std::string & bundleName,const int userId,const int appIndex)408 int32_t AmsMgrProxy::ForceKillApplication(const std::string &bundleName,
409 const int userId, const int appIndex)
410 {
411 TAG_LOGI(AAFwkTag::APPMGR, "start");
412 MessageParcel data;
413 MessageParcel reply;
414 MessageOption option(MessageOption::TF_SYNC);
415 if (!WriteInterfaceToken(data)) {
416 return ERR_INVALID_DATA;
417 }
418
419 if (!data.WriteString(bundleName)) {
420 TAG_LOGE(AAFwkTag::APPMGR, "parcel bundleName failed.");
421 return ERR_FLATTEN_OBJECT;
422 }
423
424 if (!data.WriteInt32(userId)) {
425 TAG_LOGE(AAFwkTag::APPMGR, "parcel userId failed");
426 return ERR_FLATTEN_OBJECT;
427 }
428
429 if (!data.WriteInt32(appIndex)) {
430 TAG_LOGE(AAFwkTag::APPMGR, "parcel appIndex failed");
431 return ERR_FLATTEN_OBJECT;
432 }
433
434 int32_t ret =
435 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION), data, reply, option);
436 if (ret != NO_ERROR) {
437 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d.", ret);
438 return ret;
439 }
440 return reply.ReadInt32();
441 }
442
KillProcessesByAccessTokenId(const uint32_t accessTokenId)443 int32_t AmsMgrProxy::KillProcessesByAccessTokenId(const uint32_t accessTokenId)
444 {
445 TAG_LOGI(AAFwkTag::APPMGR, "start");
446 MessageParcel data;
447 MessageParcel reply;
448 MessageOption option(MessageOption::TF_SYNC);
449 if (!WriteInterfaceToken(data)) {
450 return ERR_INVALID_DATA;
451 }
452
453 if (!data.WriteInt32(accessTokenId)) {
454 TAG_LOGE(AAFwkTag::APPMGR, "parcel accessTokenId failed");
455 return ERR_FLATTEN_OBJECT;
456 }
457
458 int32_t ret =
459 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID),
460 data, reply, option);
461 if (ret != NO_ERROR) {
462 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d.", ret);
463 return ret;
464 }
465 return reply.ReadInt32();
466 }
467
UpdateApplicationInfoInstalled(const std::string & bundleName,const int uid)468 int32_t AmsMgrProxy::UpdateApplicationInfoInstalled(const std::string &bundleName, const int uid)
469 {
470 TAG_LOGD(AAFwkTag::APPMGR, "start.");
471 MessageParcel data;
472 MessageParcel reply;
473 MessageOption option(MessageOption::TF_SYNC);
474 if (!WriteInterfaceToken(data)) {
475 return ERR_INVALID_DATA;
476 }
477 if (!data.WriteString(bundleName)) {
478 TAG_LOGE(AAFwkTag::APPMGR, "WriteString failed");
479 return ERR_FLATTEN_OBJECT;
480 }
481 if (!data.WriteInt32(uid)) {
482 TAG_LOGE(AAFwkTag::APPMGR, "uid write failed.");
483 return ERR_FLATTEN_OBJECT;
484 }
485 int32_t ret =
486 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::UPDATE_APPLICATION_INFO_INSTALLED),
487 data, reply, option);
488 if (ret != NO_ERROR) {
489 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
490 return ret;
491 }
492 return reply.ReadInt32();
493 }
494
KillApplicationByUid(const std::string & bundleName,const int uid,const std::string & reason)495 int32_t AmsMgrProxy::KillApplicationByUid(const std::string &bundleName, const int uid,
496 const std::string& reason)
497 {
498 TAG_LOGI(AAFwkTag::APPMGR, "start");
499 MessageParcel data;
500 MessageParcel reply;
501 MessageOption option(MessageOption::TF_SYNC);
502 if (!WriteInterfaceToken(data)) {
503 return ERR_INVALID_DATA;
504 }
505 if (!data.WriteString(bundleName)) {
506 TAG_LOGE(AAFwkTag::APPMGR, "failed to write bundle name");
507 return ERR_FLATTEN_OBJECT;
508 }
509 if (!data.WriteInt32(uid)) {
510 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write uid");
511 return ERR_FLATTEN_OBJECT;
512 }
513 if (!data.WriteString(reason)) {
514 TAG_LOGE(AAFwkTag::APPMGR, "failedto write reason");
515 return ERR_FLATTEN_OBJECT;
516 }
517 int32_t ret =
518 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION_BYUID), data, reply, option);
519 if (ret != NO_ERROR) {
520 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
521 return ret;
522 }
523 return reply.ReadInt32();
524 }
525
KillApplicationSelf(const std::string & reason)526 int32_t AmsMgrProxy::KillApplicationSelf(const std::string& reason)
527 {
528 TAG_LOGI(AAFwkTag::APPMGR, "call");
529 MessageParcel data;
530 MessageParcel reply;
531 MessageOption option(MessageOption::TF_SYNC);
532 if (!WriteInterfaceToken(data)) {
533 return ERR_INVALID_DATA;
534 }
535
536 if (!data.WriteString(reason)) {
537 TAG_LOGE(AAFwkTag::APPMGR, "failed to write reason");
538 return ERR_FLATTEN_OBJECT;
539 }
540
541 int32_t ret =
542 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::KILL_APPLICATION_SELF), data, reply, option);
543 if (ret != NO_ERROR) {
544 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
545 return ret;
546 }
547 return reply.ReadInt32();
548 }
549
AbilityAttachTimeOut(const sptr<IRemoteObject> & token)550 void AmsMgrProxy::AbilityAttachTimeOut(const sptr<IRemoteObject> &token)
551 {
552 TAG_LOGD(AAFwkTag::APPMGR, "beginning");
553 MessageParcel data;
554 MessageParcel reply;
555 MessageOption option(MessageOption::TF_SYNC);
556 if (!WriteInterfaceToken(data)) {
557 return;
558 }
559 if (!data.WriteRemoteObject(token.GetRefPtr())) {
560 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
561 return;
562 }
563 int32_t ret =
564 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::ABILITY_ATTACH_TIMEOUT), data, reply, option);
565 if (ret != NO_ERROR) {
566 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
567 }
568 TAG_LOGD(AAFwkTag::APPMGR, "end");
569 }
570
PrepareTerminate(const sptr<IRemoteObject> & token,bool clearMissionFlag)571 void AmsMgrProxy::PrepareTerminate(const sptr<IRemoteObject> &token, bool clearMissionFlag)
572 {
573 TAG_LOGD(AAFwkTag::APPMGR, "start");
574 MessageParcel data;
575 MessageParcel reply;
576 MessageOption option(MessageOption::TF_SYNC);
577 if (!WriteInterfaceToken(data)) {
578 return;
579 }
580 if (!data.WriteRemoteObject(token.GetRefPtr())) {
581 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
582 return;
583 }
584 if (!data.WriteBool(clearMissionFlag)) {
585 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write clearMissionFlag");
586 return;
587 }
588 int32_t ret =
589 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::PREPARE_TERMINATE_ABILITY),
590 data, reply, option);
591 if (ret != NO_ERROR) {
592 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
593 }
594 TAG_LOGD(AAFwkTag::APPMGR, "end");
595 }
596
GetRunningProcessInfoByToken(const sptr<IRemoteObject> & token,AppExecFwk::RunningProcessInfo & info)597 void AmsMgrProxy::GetRunningProcessInfoByToken(
598 const sptr<IRemoteObject> &token, AppExecFwk::RunningProcessInfo &info)
599 {
600 MessageParcel data;
601 MessageParcel reply;
602 MessageOption option(MessageOption::TF_SYNC);
603 if (!WriteInterfaceToken(data)) {
604 return;
605 }
606
607 if (!data.WriteRemoteObject(token.GetRefPtr())) {
608 return;
609 }
610
611 auto ret = SendTransactCmd(
612 static_cast<uint32_t>(IAmsMgr::Message::GET_RUNNING_PROCESS_INFO_BY_TOKEN), data, reply, option);
613 if (ret != NO_ERROR) {
614 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
615 return;
616 }
617
618 std::unique_ptr<AppExecFwk::RunningProcessInfo> processInfo(reply.ReadParcelable<AppExecFwk::RunningProcessInfo>());
619 if (processInfo == nullptr) {
620 TAG_LOGE(AAFwkTag::APPMGR, "recv process info faild");
621 return;
622 }
623
624 info = *processInfo;
625 }
626
SetAbilityForegroundingFlagToAppRecord(const pid_t pid)627 void AmsMgrProxy::SetAbilityForegroundingFlagToAppRecord(const pid_t pid)
628 {
629 TAG_LOGD(AAFwkTag::APPMGR, "calling");
630 MessageParcel data;
631 MessageParcel reply;
632 MessageOption option(MessageOption::TF_SYNC);
633 if (!WriteInterfaceToken(data)) {
634 return;
635 }
636
637 if (!data.WriteInt32(static_cast<int32_t>(pid))) {
638 TAG_LOGE(AAFwkTag::APPMGR, "parcel WriteInt32 failed");
639 return;
640 }
641
642 auto ret = SendTransactCmd(
643 static_cast<uint32_t>(IAmsMgr::Message::SET_ABILITY_FOREGROUNDING_FLAG), data, reply, option);
644 if (ret != NO_ERROR) {
645 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
646 }
647 }
648
StartSpecifiedAbility(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,int32_t requestId)649 void AmsMgrProxy::StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
650 int32_t requestId)
651 {
652 MessageParcel data;
653 MessageParcel reply;
654 MessageOption option(MessageOption::TF_SYNC);
655 if (!WriteInterfaceToken(data)) {
656 return;
657 }
658
659 if (!data.WriteParcelable(&want) || !data.WriteParcelable(&abilityInfo) ||
660 !data.WriteInt32(requestId)) {
661 TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
662 return;
663 }
664
665 auto ret = SendTransactCmd(
666 static_cast<uint32_t>(IAmsMgr::Message::START_SPECIFIED_ABILITY), data, reply, option);
667 if (ret != NO_ERROR) {
668 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
669 }
670 }
671
StartSpecifiedProcess(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo,int32_t requestId)672 void AmsMgrProxy::StartSpecifiedProcess(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo,
673 int32_t requestId)
674
675 {
676 MessageParcel data;
677 MessageParcel reply;
678 MessageOption option(MessageOption::TF_SYNC);
679 if (!WriteInterfaceToken(data)) {
680 TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
681 return;
682 }
683
684 if (!data.WriteParcelable(&want) || !data.WriteParcelable(&abilityInfo) ||
685 data.WriteInt32(requestId)) {
686 TAG_LOGE(AAFwkTag::APPMGR, "Write data failed.");
687 return;
688 }
689
690 sptr<IRemoteObject> remote = Remote();
691 if (remote == nullptr) {
692 TAG_LOGE(AAFwkTag::APPMGR, "Remote is nullptr.");
693 return;
694 }
695 auto ret = remote->SendRequest(
696 static_cast<uint32_t>(IAmsMgr::Message::START_SPECIFIED_PROCESS), data, reply, option);
697 if (ret != NO_ERROR) {
698 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
699 }
700 }
701
RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> & response)702 void AmsMgrProxy::RegisterStartSpecifiedAbilityResponse(const sptr<IStartSpecifiedAbilityResponse> &response)
703 {
704 TAG_LOGD(AAFwkTag::APPMGR, "Register multi instances response by proxy.");
705 if (!response) {
706 TAG_LOGE(AAFwkTag::APPMGR, "response null");
707 return;
708 }
709
710 MessageParcel data;
711 MessageParcel reply;
712 MessageOption option(MessageOption::TF_SYNC);
713 if (!WriteInterfaceToken(data)) {
714 return;
715 }
716 if (!data.WriteRemoteObject(response->AsObject())) {
717 TAG_LOGE(AAFwkTag::APPMGR, "write remote obj failed");
718 return;
719 }
720
721 int32_t ret = SendTransactCmd(
722 static_cast<uint32_t>(IAmsMgr::Message::REGISTER_START_SPECIFIED_ABILITY_RESPONSE), data, reply, option);
723 if (ret != NO_ERROR) {
724 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
725 }
726 }
727
GetApplicationInfoByProcessID(const int pid,AppExecFwk::ApplicationInfo & application,bool & debug)728 int AmsMgrProxy::GetApplicationInfoByProcessID(const int pid, AppExecFwk::ApplicationInfo &application, bool &debug)
729 {
730 MessageParcel data;
731 MessageParcel reply;
732 MessageOption option(MessageOption::TF_SYNC);
733 if (!WriteInterfaceToken(data)) {
734 TAG_LOGE(AAFwkTag::APPMGR, "token write error");
735 return ERR_FLATTEN_OBJECT;
736 }
737 data.WriteInt32(pid);
738 int32_t ret = SendTransactCmd(
739 static_cast<uint32_t>(IAmsMgr::Message::GET_APPLICATION_INFO_BY_PROCESS_ID), data, reply, option);
740 if (ret != NO_ERROR) {
741 TAG_LOGE(AAFwkTag::APPMGR, "send request fail");
742 return ret;
743 }
744 auto result = reply.ReadInt32();
745 if (result != NO_ERROR) {
746 TAG_LOGE(AAFwkTag::APPMGR, "reply result false");
747 return result;
748 }
749 std::unique_ptr<AppExecFwk::ApplicationInfo> info(reply.ReadParcelable<AppExecFwk::ApplicationInfo>());
750 if (!info) {
751 TAG_LOGE(AAFwkTag::APPMGR, "readParcelableInfo failed");
752 return ERR_NAME_NOT_FOUND;
753 }
754 application = *info;
755 debug = reply.ReadBool();
756 TAG_LOGD(AAFwkTag::APPMGR, "get parcelable info success");
757 return NO_ERROR;
758 }
759
NotifyAppMgrRecordExitReason(int32_t pid,int32_t reason,const std::string & exitMsg)760 int32_t AmsMgrProxy::NotifyAppMgrRecordExitReason(int32_t pid, int32_t reason, const std::string &exitMsg)
761 {
762 TAG_LOGD(AAFwkTag::APPMGR, "called");
763 MessageParcel data;
764 MessageParcel reply;
765 MessageOption option(MessageOption::TF_SYNC);
766 if (!WriteInterfaceToken(data)) {
767 TAG_LOGE(AAFwkTag::APPMGR, "token write error");
768 return IPC_PROXY_ERR;
769 }
770 if (!data.WriteInt32(pid)) {
771 TAG_LOGE(AAFwkTag::APPMGR, "Write pid failed");
772 return IPC_PROXY_ERR;
773 }
774 if (!data.WriteInt32(reason)) {
775 TAG_LOGE(AAFwkTag::APPMGR, "Write reason failed");
776 return IPC_PROXY_ERR;
777 }
778 if (!data.WriteString16(Str8ToStr16(exitMsg))) {
779 TAG_LOGE(AAFwkTag::APPMGR, "Write exitMsg failed");
780 return IPC_PROXY_ERR;
781 }
782 int32_t ret = SendTransactCmd(
783 static_cast<uint32_t>(IAmsMgr::Message::NOTIFY_APP_MGR_RECORD_EXIT_REASON), data, reply, option);
784 if (ret != NO_ERROR) {
785 TAG_LOGE(AAFwkTag::APPMGR, "send request fail");
786 return ret;
787 }
788 return reply.ReadInt32();
789 }
790
SetCurrentUserId(const int32_t userId)791 void AmsMgrProxy::SetCurrentUserId(const int32_t userId)
792 {
793 TAG_LOGD(AAFwkTag::APPMGR, "start");
794 MessageParcel data;
795 MessageParcel reply;
796 MessageOption option(MessageOption::TF_SYNC);
797 if (!WriteInterfaceToken(data)) {
798 return;
799 }
800 if (!data.WriteInt32(userId)) {
801 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId");
802 return;
803 }
804 int32_t ret =
805 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_CURRENT_USER_ID),
806 data, reply, option);
807 if (ret != NO_ERROR) {
808 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
809 }
810 TAG_LOGD(AAFwkTag::APPMGR, "end");
811 }
812
SetEnableStartProcessFlagByUserId(int32_t userId,bool enableStartProcess)813 void AmsMgrProxy::SetEnableStartProcessFlagByUserId(int32_t userId, bool enableStartProcess)
814 {
815 TAG_LOGD(AAFwkTag::APPMGR, "called");
816 MessageParcel data;
817 MessageParcel reply;
818 MessageOption option(MessageOption::TF_SYNC);
819 if (!WriteInterfaceToken(data)) {
820 return;
821 }
822 if (!data.WriteInt32(userId)) {
823 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write userId");
824 return;
825 }
826 if (!data.WriteBool(enableStartProcess)) {
827 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write enableStartProcess");
828 return;
829 }
830 int32_t ret =
831 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::ENABLE_START_PROCESS_FLAG_BY_USER_ID),
832 data, reply, option);
833 if (ret != NO_ERROR) {
834 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
835 }
836 }
837
GetBundleNameByPid(const int pid,std::string & bundleName,int32_t & uid)838 int32_t AmsMgrProxy::GetBundleNameByPid(const int pid, std::string &bundleName, int32_t &uid)
839 {
840 MessageParcel data;
841 MessageParcel reply;
842 MessageOption option(MessageOption::TF_SYNC);
843 if (!WriteInterfaceToken(data)) {
844 return ERR_INVALID_DATA;
845 }
846 if (!data.WriteInt32(pid)) {
847 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write pid");
848 return ERR_INVALID_DATA;
849 }
850 int32_t ret =
851 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::Get_BUNDLE_NAME_BY_PID),
852 data, reply, option);
853 if (ret != NO_ERROR) {
854 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
855 }
856 bundleName = reply.ReadString();
857 uid = reply.ReadInt32();
858 return NO_ERROR;
859 }
860
RegisterAppDebugListener(const sptr<IAppDebugListener> & listener)861 int32_t AmsMgrProxy::RegisterAppDebugListener(const sptr<IAppDebugListener> &listener)
862 {
863 TAG_LOGD(AAFwkTag::APPMGR, "called");
864 MessageParcel data;
865 if (!WriteInterfaceToken(data)) {
866 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
867 return ERR_INVALID_DATA;
868 }
869
870 if (listener == nullptr || !data.WriteRemoteObject(listener->AsObject())) {
871 TAG_LOGE(AAFwkTag::APPMGR, "Write listener failed");
872 return ERR_INVALID_DATA;
873 }
874
875 MessageParcel reply;
876 MessageOption option(MessageOption::TF_SYNC);
877 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::REGISTER_APP_DEBUG_LISTENER),
878 data, reply, option);
879 if (ret != NO_ERROR) {
880 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
881 return ret;
882 }
883 return reply.ReadInt32();
884 }
885
UnregisterAppDebugListener(const sptr<IAppDebugListener> & listener)886 int32_t AmsMgrProxy::UnregisterAppDebugListener(const sptr<IAppDebugListener> &listener)
887 {
888 TAG_LOGD(AAFwkTag::APPMGR, "called");
889 MessageParcel data;
890 if (!WriteInterfaceToken(data)) {
891 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
892 return ERR_INVALID_DATA;
893 }
894
895 if (listener == nullptr || !data.WriteRemoteObject(listener->AsObject())) {
896 TAG_LOGE(AAFwkTag::APPMGR, "Write listener failed");
897 return ERR_INVALID_DATA;
898 }
899
900 MessageParcel reply;
901 MessageOption option(MessageOption::TF_SYNC);
902 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::UNREGISTER_APP_DEBUG_LISTENER),
903 data, reply, option);
904 if (ret != NO_ERROR) {
905 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
906 return ret;
907 }
908 return reply.ReadInt32();
909 }
910
AttachAppDebug(const std::string & bundleName)911 int32_t AmsMgrProxy::AttachAppDebug(const std::string &bundleName)
912 {
913 TAG_LOGD(AAFwkTag::APPMGR, "called");
914 MessageParcel data;
915 if (!WriteInterfaceToken(data)) {
916 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
917 return ERR_INVALID_DATA;
918 }
919
920 if (bundleName.empty() || !data.WriteString(bundleName)) {
921 TAG_LOGE(AAFwkTag::APPMGR, "Write bundleName failed");
922 return ERR_INVALID_DATA;
923 }
924
925 MessageParcel reply;
926 MessageOption option(MessageOption::TF_SYNC);
927 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::ATTACH_APP_DEBUG),
928 data, reply, option);
929 if (ret != NO_ERROR) {
930 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
931 return ret;
932 }
933 return reply.ReadInt32();
934 }
935
DetachAppDebug(const std::string & bundleName)936 int32_t AmsMgrProxy::DetachAppDebug(const std::string &bundleName)
937 {
938 TAG_LOGD(AAFwkTag::APPMGR, "called");
939 MessageParcel data;
940 if (!WriteInterfaceToken(data)) {
941 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
942 return ERR_INVALID_DATA;
943 }
944
945 if (bundleName.empty() || !data.WriteString(bundleName)) {
946 TAG_LOGE(AAFwkTag::APPMGR, "Write bundle name failed");
947 return ERR_INVALID_DATA;
948 }
949
950 MessageParcel reply;
951 MessageOption option(MessageOption::TF_SYNC);
952 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::DETACH_APP_DEBUG),
953 data, reply, option);
954 if (ret != NO_ERROR) {
955 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
956 return ret;
957 }
958 return reply.ReadInt32();
959 }
960
SetKeepAliveEnableState(const std::string & bundleName,bool enable,int32_t uid)961 void AmsMgrProxy::SetKeepAliveEnableState(const std::string &bundleName, bool enable, int32_t uid)
962 {
963 TAG_LOGD(AAFwkTag::APPMGR, "called");
964 MessageParcel data;
965 if (!WriteInterfaceToken(data)) {
966 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
967 return;
968 }
969 if (bundleName.empty() || !data.WriteString(bundleName)) {
970 TAG_LOGE(AAFwkTag::APPMGR, "Write bundleName fail");
971 return;
972 }
973 if (!data.WriteBool(enable) || !data.WriteInt32(uid)) {
974 TAG_LOGE(AAFwkTag::APPMGR, "Write flag or uid fail");
975 return;
976 }
977 MessageParcel reply;
978 MessageOption option;
979 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_KEEP_ALIVE_ENABLE_STATE),
980 data, reply, option);
981 if (ret != NO_ERROR) {
982 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
983 }
984 }
985
SetAppWaitingDebug(const std::string & bundleName,bool isPersist)986 int32_t AmsMgrProxy::SetAppWaitingDebug(const std::string &bundleName, bool isPersist)
987 {
988 TAG_LOGD(AAFwkTag::APPMGR, "called");
989 MessageParcel data;
990 if (!WriteInterfaceToken(data)) {
991 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
992 return ERR_INVALID_DATA;
993 }
994
995 if (bundleName.empty() || !data.WriteString(bundleName)) {
996 TAG_LOGE(AAFwkTag::APPMGR, "Write bundleName failed");
997 return ERR_INVALID_DATA;
998 }
999
1000 if (!data.WriteBool(isPersist)) {
1001 TAG_LOGE(AAFwkTag::APPMGR, "Write persist flag failed.");
1002 return ERR_INVALID_DATA;
1003 }
1004
1005 MessageParcel reply;
1006 MessageOption option(MessageOption::TF_SYNC);
1007 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::SET_APP_WAITING_DEBUG), data, reply, option);
1008 if (ret != NO_ERROR) {
1009 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1010 return ret;
1011 }
1012 return reply.ReadInt32();
1013 }
1014
CancelAppWaitingDebug()1015 int32_t AmsMgrProxy::CancelAppWaitingDebug()
1016 {
1017 TAG_LOGD(AAFwkTag::APPMGR, "called");
1018 MessageParcel data;
1019 if (!WriteInterfaceToken(data)) {
1020 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1021 return ERR_INVALID_DATA;
1022 }
1023
1024 MessageParcel reply;
1025 MessageOption option(MessageOption::TF_SYNC);
1026 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::CANCEL_APP_WAITING_DEBUG), data, reply, option);
1027 if (ret != NO_ERROR) {
1028 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1029 return ret;
1030 }
1031 return reply.ReadInt32();
1032 }
1033
GetWaitingDebugApp(std::vector<std::string> & debugInfoList)1034 int32_t AmsMgrProxy::GetWaitingDebugApp(std::vector<std::string> &debugInfoList)
1035 {
1036 TAG_LOGD(AAFwkTag::APPMGR, "called");
1037 MessageParcel data;
1038 if (!WriteInterfaceToken(data)) {
1039 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1040 return ERR_INVALID_DATA;
1041 }
1042
1043 MessageParcel reply;
1044 MessageOption option(MessageOption::TF_SYNC);
1045 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::GET_WAITING_DEBUG_APP), data, reply, option);
1046 if (ret != NO_ERROR) {
1047 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1048 return ret;
1049 }
1050
1051 auto resultCode = reply.ReadInt32();
1052 if (resultCode != ERR_OK) {
1053 TAG_LOGE(AAFwkTag::APPMGR, "Reply err: %{public}d", resultCode);
1054 return resultCode;
1055 }
1056
1057 auto infoSize = reply.ReadInt32();
1058 if (infoSize > MAX_APP_DEBUG_COUNT) {
1059 TAG_LOGE(AAFwkTag::APPMGR, "Max app debug count: %{public}d", infoSize);
1060 return ERR_INVALID_DATA;
1061 }
1062
1063 if (!reply.ReadStringVector(&debugInfoList)) {
1064 TAG_LOGE(AAFwkTag::APPMGR, "ReadStringVector failed");
1065 return ERR_INVALID_DATA;
1066 }
1067
1068 return NO_ERROR;
1069 }
1070
IsWaitingDebugApp(const std::string & bundleName)1071 bool AmsMgrProxy::IsWaitingDebugApp(const std::string &bundleName)
1072 {
1073 TAG_LOGD(AAFwkTag::APPMGR, "called");
1074 MessageParcel data;
1075 if (!WriteInterfaceToken(data)) {
1076 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1077 return false;
1078 }
1079
1080 if (bundleName.empty() || !data.WriteString(bundleName)) {
1081 TAG_LOGE(AAFwkTag::APPMGR, "Write bundleName failed");
1082 return false;
1083 }
1084
1085 MessageParcel reply;
1086 MessageOption option(MessageOption::TF_SYNC);
1087 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_WAITING_DEBUG_APP), data, reply, option);
1088 if (ret != NO_ERROR) {
1089 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1090 return false;
1091 }
1092 return reply.ReadBool();
1093 }
1094
ClearNonPersistWaitingDebugFlag()1095 void AmsMgrProxy::ClearNonPersistWaitingDebugFlag()
1096 {
1097 TAG_LOGD(AAFwkTag::APPMGR, "called");
1098 MessageParcel data;
1099 if (!WriteInterfaceToken(data)) {
1100 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1101 return;
1102 }
1103
1104 MessageParcel reply;
1105 MessageOption option(MessageOption::TF_SYNC);
1106 auto ret = SendTransactCmd(
1107 static_cast<uint32_t>(IAmsMgr::Message::CLEAR_NON_PERSIST_WAITING_DEBUG_FLAG), data, reply, option);
1108 if (ret != NO_ERROR) {
1109 TAG_LOGW(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1110 }
1111 }
1112
RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> & response)1113 int32_t AmsMgrProxy::RegisterAbilityDebugResponse(const sptr<IAbilityDebugResponse> &response)
1114 {
1115 TAG_LOGD(AAFwkTag::APPMGR, "called");
1116 MessageParcel data;
1117 if (!WriteInterfaceToken(data)) {
1118 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1119 return ERR_INVALID_DATA;
1120 }
1121
1122 if (response == nullptr || !data.WriteRemoteObject(response->AsObject())) {
1123 TAG_LOGE(AAFwkTag::APPMGR, "write remote obj failed");
1124 return ERR_INVALID_DATA;
1125 }
1126
1127 MessageParcel reply;
1128 MessageOption option(MessageOption::TF_SYNC);
1129 int32_t ret = SendTransactCmd(
1130 static_cast<uint32_t>(IAmsMgr::Message::REGISTER_ABILITY_DEBUG_RESPONSE), data, reply, option);
1131 if (ret != NO_ERROR) {
1132 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
1133 return ret;
1134 }
1135 return reply.ReadInt32();
1136 }
1137
IsAttachDebug(const std::string & bundleName)1138 bool AmsMgrProxy::IsAttachDebug(const std::string &bundleName)
1139 {
1140 TAG_LOGD(AAFwkTag::APPMGR, "called");
1141 MessageParcel data;
1142 if (!WriteInterfaceToken(data)) {
1143 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1144 return false;
1145 }
1146
1147 if (bundleName.empty() || !data.WriteString(bundleName)) {
1148 TAG_LOGE(AAFwkTag::APPMGR, "Write bundleName fail");
1149 return false;
1150 }
1151
1152 MessageParcel reply;
1153 MessageOption option(MessageOption::TF_SYNC);
1154 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_ATTACH_DEBUG),
1155 data, reply, option);
1156 if (ret != NO_ERROR) {
1157 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1158 return false;
1159 }
1160 return reply.ReadBool();
1161 }
1162
ClearProcessByToken(sptr<IRemoteObject> token)1163 void AmsMgrProxy::ClearProcessByToken(sptr<IRemoteObject> token)
1164 {
1165 MessageParcel data;
1166 if (!WriteInterfaceToken(data)) {
1167 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
1168 return;
1169 }
1170 if (!data.WriteRemoteObject(token)) {
1171 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
1172 return;
1173 }
1174 MessageParcel reply;
1175 MessageOption option;
1176 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::CLEAR_PROCESS_BY_TOKEN), data, reply, option);
1177 if (ret != NO_ERROR) {
1178 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
1179 }
1180 }
1181
IsMemorySizeSufficent()1182 bool AmsMgrProxy::IsMemorySizeSufficent()
1183 {
1184 MessageParcel data;
1185 if (!WriteInterfaceToken(data)) {
1186 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1187 return true;
1188 }
1189
1190 MessageParcel reply;
1191 MessageOption option(MessageOption::TF_SYNC);
1192 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_MEMORY_SIZE_SUFFICIENT), data, reply, option);
1193 if (ret != NO_ERROR) {
1194 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1195 return true;
1196 }
1197 return reply.ReadBool();
1198 }
1199
SendTransactCmd(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)1200 int32_t AmsMgrProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
1201 MessageParcel &reply, MessageOption &option)
1202 {
1203 sptr<IRemoteObject> remote = Remote();
1204 if (remote == nullptr) {
1205 TAG_LOGE(AAFwkTag::APPMGR, "null remote");
1206 return ERR_NULL_OBJECT;
1207 }
1208
1209 int32_t ret = remote->SendRequest(code, data, reply, option);
1210 if (ret != NO_ERROR) {
1211 TAG_LOGE(AAFwkTag::APPMGR, "SendRequest err: %{public}d, ret: %{public}d", code, ret);
1212 return ret;
1213 }
1214 return ret;
1215 }
1216
AttachedToStatusBar(const sptr<IRemoteObject> & token)1217 void AmsMgrProxy::AttachedToStatusBar(const sptr<IRemoteObject> &token)
1218 {
1219 TAG_LOGD(AAFwkTag::APPMGR, "start");
1220 MessageParcel data;
1221 MessageParcel reply;
1222 MessageOption option;
1223 if (!WriteInterfaceToken(data)) {
1224 return;
1225 }
1226 if (!data.WriteRemoteObject(token)) {
1227 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
1228 return;
1229 }
1230 int32_t ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::ATTACHED_TO_STATUS_BAR),
1231 data, reply, option);
1232 if (ret != NO_ERROR) {
1233 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
1234 }
1235 TAG_LOGD(AAFwkTag::APPMGR, "end");
1236 }
1237
BlockProcessCacheByPids(const std::vector<int32_t> & pids)1238 void AmsMgrProxy::BlockProcessCacheByPids(const std::vector<int32_t> &pids)
1239 {
1240 TAG_LOGD(AAFwkTag::APPMGR, "start");
1241 MessageParcel data;
1242 MessageParcel reply;
1243 MessageOption option;
1244
1245 if (!WriteInterfaceToken(data)) {
1246 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1247 return;
1248 }
1249 if (!data.WriteUint32(pids.size())) {
1250 TAG_LOGE(AAFwkTag::APPMGR, "Write size failed");
1251 return;
1252 }
1253 for (const auto &pid: pids) {
1254 if (!data.WriteInt32(pid)) {
1255 TAG_LOGE(AAFwkTag::APPMGR, "Write pid failed");
1256 return;
1257 }
1258 }
1259 int32_t ret =
1260 SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::BLOCK_PROCESS_CACHE_BY_PIDS), data, reply, option);
1261 if (ret != NO_ERROR) {
1262 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
1263 }
1264 TAG_LOGD(AAFwkTag::APPMGR, "end");
1265 }
1266
IsKilledForUpgradeWeb(const std::string & bundleName)1267 bool AmsMgrProxy::IsKilledForUpgradeWeb(const std::string &bundleName)
1268 {
1269 MessageParcel data;
1270 MessageParcel reply;
1271 MessageOption option;
1272 if (!WriteInterfaceToken(data)) {
1273 TAG_LOGE(AAFwkTag::APPMGR, "Write token failed");
1274 return false;
1275 }
1276 if (!data.WriteString(bundleName)) {
1277 TAG_LOGE(AAFwkTag::APPMGR, "WriteString failed");
1278 return false;
1279 }
1280
1281 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_KILLED_FOR_UPGRADE_WEB), data, reply, option);
1282 if (ret != NO_ERROR) {
1283 TAG_LOGE(AAFwkTag::APPMGR, "Send request err: %{public}d", ret);
1284 return false;
1285 }
1286 return reply.ReadBool();
1287 }
1288
CleanAbilityByUserRequest(const sptr<IRemoteObject> & token)1289 bool AmsMgrProxy::CleanAbilityByUserRequest(const sptr<IRemoteObject> &token)
1290 {
1291 MessageParcel data;
1292 MessageParcel reply;
1293 MessageOption option;
1294 if (!WriteInterfaceToken(data)) {
1295 TAG_LOGE(AAFwkTag::APPMGR, "WriteInterfaceToken failed");
1296 return false;
1297 }
1298 if (!data.WriteRemoteObject(token.GetRefPtr())) {
1299 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
1300 return false;
1301 }
1302
1303 int32_t ret = SendTransactCmd(
1304 static_cast<uint32_t>(IAmsMgr::Message::CLEAN_UIABILITY_BY_USER_REQUEST), data, reply, option);
1305 if (ret != NO_ERROR) {
1306 TAG_LOGW(AAFwkTag::APPMGR, "SendRequest err: %{public}d", ret);
1307 }
1308 return reply.ReadBool();
1309 }
1310
IsProcessAttached(sptr<IRemoteObject> token)1311 bool AmsMgrProxy::IsProcessAttached(sptr<IRemoteObject> token)
1312 {
1313 MessageParcel data;
1314 MessageParcel reply;
1315 MessageOption option;
1316 if (!WriteInterfaceToken(data)) {
1317 TAG_LOGE(AAFwkTag::APPMGR, "Write interface token failed.");
1318 return false;
1319 }
1320 if (!data.WriteRemoteObject(token.GetRefPtr())) {
1321 TAG_LOGE(AAFwkTag::APPMGR, "Failed to write token");
1322 return false;
1323 }
1324
1325 auto ret = SendTransactCmd(static_cast<uint32_t>(IAmsMgr::Message::IS_PROCESS_ATTACHED), data, reply, option);
1326 if (ret != NO_ERROR) {
1327 TAG_LOGE(AAFwkTag::APPMGR, "Send request failed, error code is %{public}d.", ret);
1328 return false;
1329 }
1330 return reply.ReadBool();
1331 }
1332 } // namespace AppExecFwk
1333 } // namespace OHOS
1334