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 "privacy_window_manager_proxy.h"
17 #include "accesstoken_log.h"
18 #include "privacy_error.h"
19
20 namespace OHOS {
21 namespace Security {
22 namespace AccessToken {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_PRIVACY, "PrivacyWindowManagerProxy"};
25 }
26
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)27 int32_t PrivacyWindowManagerProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
28 const sptr<IWindowManagerAgent>& windowManagerAgent)
29 {
30 MessageParcel data;
31 MessageParcel reply;
32 MessageOption option;
33 if (!data.WriteInterfaceToken(GetDescriptor())) {
34 ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
35 return ERR_WRITE_PARCEL_FAILED;
36 }
37
38 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
39 ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed");
40 return ERR_WRITE_PARCEL_FAILED;
41 }
42
43 if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
44 ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed");
45 return ERR_WRITE_PARCEL_FAILED;
46 }
47 sptr<IRemoteObject> remote = Remote();
48 if (remote == nullptr) {
49 ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
50 return ERR_REMOTE_CONNECTION;
51 }
52 int32_t error = remote->SendRequest(
53 static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
54 data, reply, option);
55 if (error != ERR_NONE) {
56 ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed");
57 return error;
58 }
59 return reply.ReadInt32();
60 }
61
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)62 int32_t PrivacyWindowManagerProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
63 const sptr<IWindowManagerAgent>& windowManagerAgent)
64 {
65 MessageParcel data;
66 MessageParcel reply;
67 MessageOption option;
68 if (!data.WriteInterfaceToken(GetDescriptor())) {
69 ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
70 return ERR_WRITE_PARCEL_FAILED;
71 }
72
73 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
74 ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed");
75 return ERR_WRITE_PARCEL_FAILED;
76 }
77
78 if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
79 ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed");
80 return ERR_WRITE_PARCEL_FAILED;
81 }
82
83 sptr<IRemoteObject> remote = Remote();
84 if (remote == nullptr) {
85 ACCESSTOKEN_LOG_ERROR(LABEL, "Remote service is null.");
86 return ERR_REMOTE_CONNECTION;
87 }
88 int32_t error = remote->SendRequest(
89 static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
90 data, reply, option);
91 if (error != ERR_NONE) {
92 ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed");
93 return error;
94 }
95
96 return reply.ReadInt32();
97 }
98 } // namespace AccessToken
99 } // namespace Security
100 } // namespace OHOS
101