• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "window_manager_privacy_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_PRIVACY, "WindowManagerPrivacyProxy"};
24 }
25 
RegisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)26 bool WindowManagerPrivacyProxy::RegisterWindowManagerAgent(WindowManagerAgentType type,
27     const sptr<IWindowManagerAgent>& windowManagerAgent)
28 {
29     MessageParcel data;
30     MessageParcel reply;
31     MessageOption option;
32     if (!data.WriteInterfaceToken(GetDescriptor())) {
33         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
34         return false;
35     }
36 
37     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
38         ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed");
39         return false;
40     }
41 
42     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
43         ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed");
44         return false;
45     }
46     if (Remote()->SendRequest(
47         static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_REGISTER_WINDOW_MANAGER_AGENT),
48         data, reply, option) != ERR_NONE) {
49         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed");
50         return false;
51     }
52     return reply.ReadBool();
53 }
54 
UnregisterWindowManagerAgent(WindowManagerAgentType type,const sptr<IWindowManagerAgent> & windowManagerAgent)55 bool WindowManagerPrivacyProxy::UnregisterWindowManagerAgent(WindowManagerAgentType type,
56     const sptr<IWindowManagerAgent>& windowManagerAgent)
57 {
58     MessageParcel data;
59     MessageParcel reply;
60     MessageOption option;
61     if (!data.WriteInterfaceToken(GetDescriptor())) {
62         ACCESSTOKEN_LOG_ERROR(LABEL, "WriteInterfaceToken failed");
63         return false;
64     }
65 
66     if (!data.WriteUint32(static_cast<uint32_t>(type))) {
67         ACCESSTOKEN_LOG_ERROR(LABEL, "Write type failed");
68         return false;
69     }
70 
71     if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
72         ACCESSTOKEN_LOG_ERROR(LABEL, "Write IWindowManagerAgent failed");
73         return false;
74     }
75 
76     if (Remote()->SendRequest(
77         static_cast<uint32_t>(IWindowManager::WindowManagerMessage::TRANS_ID_UNREGISTER_WINDOW_MANAGER_AGENT),
78         data, reply, option) != ERR_NONE) {
79         ACCESSTOKEN_LOG_ERROR(LABEL, "SendRequest failed");
80         return false;
81     }
82 
83     return reply.ReadBool();
84 }
85 } // namespace AccessToken
86 } // namespace Security
87 } // namespace OHOS
88