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