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