1 /*
2 * Copyright (c) 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_manager_access_proxy.h"
17 #include "accesstoken_log.h"
18
19 namespace OHOS {
20 namespace Security {
21 namespace AccessToken {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ACCESSTOKEN, "AmsManagerAccessProxy"};
24 static constexpr int32_t ERROR = -1;
25 }
KillProcessesByAccessTokenId(const uint32_t accessTokenId)26 int32_t AmsManagerAccessProxy::KillProcessesByAccessTokenId(const uint32_t accessTokenId)
27 {
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option(MessageOption::TF_SYNC);
31 if (!data.WriteInterfaceToken(GetDescriptor())) {
32 ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed.");
33 return ERROR;
34 }
35
36 if (!data.WriteInt32(accessTokenId)) {
37 ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInt32 failed.");
38 return ERROR;
39 }
40 sptr<IRemoteObject> remote = Remote();
41 if (remote == nullptr) {
42 ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
43 return ERROR;
44 }
45 int32_t error = remote->SendRequest(
46 static_cast<uint32_t>(IAmsMgr::Message::FORCE_KILL_APPLICATION_BY_ACCESS_TOKEN_ID), data, reply, option);
47 if (error != ERR_NONE) {
48 ACCESSTOKEN_LOG_ERROR(LABEL, "KillProcessesByAccessTokenId failed, error: %{public}d", error);
49 return ERROR;
50 }
51 return reply.ReadInt32();
52 }
53 } // namespace AccessToken
54 } // namespace Security
55 } // namespace OHOS
56