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