1 /*
2 * Copyright (c) 2023 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 "zidl/screen_session_manager_lite_proxy.h"
17
18 #include <ipc_types.h>
19 #include <message_option.h>
20 #include <message_parcel.h>
21
22 #include "dm_common.h"
23 #include "marshalling_helper.h"
24 #include "window_manager_hilog.h"
25
26 namespace OHOS::Rosen {
27 namespace {
28 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenSessionManagerLiteProxy" };
29 }
30
RegisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)31 DMError ScreenSessionManagerLiteProxy::RegisterDisplayManagerAgent(
32 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type)
33 {
34 sptr<IRemoteObject> remote = Remote();
35 if (remote == nullptr) {
36 WLOGFW("remote is null");
37 return DMError::DM_ERROR_IPC_FAILED;
38 }
39
40 MessageParcel data;
41 MessageParcel reply;
42 MessageOption option;
43 WLOGFD("ScreenSessionManagerLiteProxy::RegisterDisplayManagerAgent");
44 if (!data.WriteInterfaceToken(GetDescriptor())) {
45 WLOGFE("RegisterDisplayManagerAgent WriteInterfaceToken failed");
46 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
47 }
48
49 if (displayManagerAgent == nullptr) {
50 WLOGFE("IDisplayManagerAgent is null");
51 return DMError::DM_ERROR_INVALID_PARAM;
52 }
53
54 if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
55 WLOGFE("Write IDisplayManagerAgent failed");
56 return DMError::DM_ERROR_IPC_FAILED;
57 }
58
59 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
60 WLOGFE("Write DisplayManagerAgent type failed");
61 return DMError::DM_ERROR_IPC_FAILED;
62 }
63
64 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT),
65 data, reply, option) != ERR_NONE) {
66 WLOGFE("SendRequest failed");
67 return DMError::DM_ERROR_IPC_FAILED;
68 }
69 return static_cast<DMError>(reply.ReadInt32());
70 }
71
UnregisterDisplayManagerAgent(const sptr<IDisplayManagerAgent> & displayManagerAgent,DisplayManagerAgentType type)72 DMError ScreenSessionManagerLiteProxy::UnregisterDisplayManagerAgent(
73 const sptr<IDisplayManagerAgent>& displayManagerAgent, DisplayManagerAgentType type)
74 {
75 sptr<IRemoteObject> remote = Remote();
76 if (remote == nullptr) {
77 WLOGFW("remote is null");
78 return DMError::DM_ERROR_IPC_FAILED;
79 }
80
81 MessageParcel data;
82 MessageParcel reply;
83 MessageOption option;
84 WLOGFD("ScreenSessionManagerLiteProxy::UnregisterDisplayManagerAgent");
85 if (!data.WriteInterfaceToken(GetDescriptor())) {
86 WLOGFE("UnregisterDisplayManagerAgent WriteInterfaceToken failed");
87 return DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED;
88 }
89
90 if (displayManagerAgent == nullptr) {
91 WLOGFE("IDisplayManagerAgent is null");
92 return DMError::DM_ERROR_INVALID_PARAM;
93 }
94
95 if (!data.WriteRemoteObject(displayManagerAgent->AsObject())) {
96 WLOGFE("Write IWindowManagerAgent failed");
97 return DMError::DM_ERROR_IPC_FAILED;
98 }
99
100 if (!data.WriteUint32(static_cast<uint32_t>(type))) {
101 WLOGFE("Write DisplayManagerAgent type failed");
102 return DMError::DM_ERROR_IPC_FAILED;
103 }
104
105 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT),
106 data, reply, option) != ERR_NONE) {
107 WLOGFE("SendRequest failed");
108 return DMError::DM_ERROR_IPC_FAILED;
109 }
110 return static_cast<DMError>(reply.ReadInt32());
111 }
112
GetFoldDisplayMode()113 FoldDisplayMode ScreenSessionManagerLiteProxy::GetFoldDisplayMode()
114 {
115 sptr<IRemoteObject> remote = Remote();
116 if (remote == nullptr) {
117 WLOGFW("remote is null");
118 return FoldDisplayMode::UNKNOWN;
119 }
120 MessageParcel data;
121 MessageParcel reply;
122 MessageOption option;
123 if (!data.WriteInterfaceToken(GetDescriptor())) {
124 WLOGFE("WriteInterfaceToken Failed");
125 return FoldDisplayMode::UNKNOWN;
126 }
127 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE),
128 data, reply, option) != ERR_NONE) {
129 WLOGFE("Send TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE request failed");
130 return FoldDisplayMode::UNKNOWN;
131 }
132 return static_cast<FoldDisplayMode>(reply.ReadUint32());
133 }
134
SetFoldDisplayMode(const FoldDisplayMode displayMode)135 void ScreenSessionManagerLiteProxy::SetFoldDisplayMode(const FoldDisplayMode displayMode)
136 {
137 sptr<IRemoteObject> remote = Remote();
138 if (remote == nullptr) {
139 WLOGFW("remote is null");
140 return;
141 }
142 MessageParcel data;
143 MessageParcel reply;
144 MessageOption option;
145 if (!data.WriteInterfaceToken(GetDescriptor())) {
146 WLOGFE("WriteInterfaceToken Failed");
147 return;
148 }
149 if (!data.WriteUint32(static_cast<uint32_t>(displayMode))) {
150 WLOGFE("Write displayMode failed");
151 return;
152 }
153 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE),
154 data, reply, option) != ERR_NONE) {
155 WLOGFE("Send TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE request failed");
156 }
157 }
158
IsFoldable()159 bool ScreenSessionManagerLiteProxy::IsFoldable()
160 {
161 sptr<IRemoteObject> remote = Remote();
162 if (remote == nullptr) {
163 WLOGFW("remote is null");
164 return false;
165 }
166
167 MessageParcel data;
168 MessageParcel reply;
169 MessageOption option;
170 if (!data.WriteInterfaceToken(GetDescriptor())) {
171 WLOGFE("IsFoldable WriteInterfaceToken failed");
172 return false;
173 }
174 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_IS_FOLDABLE),
175 data, reply, option) != ERR_NONE) {
176 WLOGFE("SendRequest failed");
177 return false;
178 }
179 return reply.ReadBool();
180 }
181
GetFoldStatus()182 FoldStatus ScreenSessionManagerLiteProxy::GetFoldStatus()
183 {
184 sptr<IRemoteObject> remote = Remote();
185 if (remote == nullptr) {
186 WLOGFW("remote is null");
187 return FoldStatus::UNKNOWN;
188 }
189
190 MessageParcel data;
191 MessageParcel reply;
192 MessageOption option;
193 if (!data.WriteInterfaceToken(GetDescriptor())) {
194 WLOGFE("WriteInterfaceToken failed");
195 return FoldStatus::UNKNOWN;
196 }
197 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_STATUS),
198 data, reply, option) != ERR_NONE) {
199 WLOGFE("SendRequest failed");
200 return FoldStatus::UNKNOWN;
201 }
202 return static_cast<FoldStatus>(reply.ReadUint32());
203 }
204
GetDefaultDisplayInfo()205 sptr<DisplayInfo> OHOS::Rosen::ScreenSessionManagerLiteProxy::GetDefaultDisplayInfo()
206 {
207 sptr<IRemoteObject> remote = Remote();
208 if (remote == nullptr) {
209 WLOGFW("remote is null");
210 return nullptr;
211 }
212
213 MessageParcel data;
214 MessageParcel reply;
215 MessageOption option;
216 if (!data.WriteInterfaceToken(GetDescriptor())) {
217 WLOGFE("WriteInterfaceToken failed");
218 return nullptr;
219 }
220 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO),
221 data, reply, option) != ERR_NONE) {
222 WLOGFE("SendRequest failed");
223 return nullptr;
224 }
225
226 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
227 if (info == nullptr) {
228 WLOGFW("read display info failed, info is nullptr.");
229 }
230 return info;
231 }
232
GetDisplayInfoById(DisplayId displayId)233 sptr<DisplayInfo> ScreenSessionManagerLiteProxy::GetDisplayInfoById(DisplayId displayId)
234 {
235 sptr<IRemoteObject> remote = Remote();
236 if (remote == nullptr) {
237 WLOGFW("GetDisplayInfoById: remote is nullptr");
238 return nullptr;
239 }
240
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option;
244 if (!data.WriteInterfaceToken(GetDescriptor())) {
245 WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed");
246 return nullptr;
247 }
248 if (!data.WriteUint64(displayId)) {
249 WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed");
250 return nullptr;
251 }
252 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_GET_DISPLAY_BY_ID),
253 data, reply, option) != ERR_NONE) {
254 WLOGFW("GetDisplayInfoById: SendRequest failed");
255 return nullptr;
256 }
257
258 sptr<DisplayInfo> info = reply.ReadParcelable<DisplayInfo>();
259 if (info == nullptr) {
260 WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr.");
261 return nullptr;
262 }
263 return info;
264 }
265
GetCutoutInfo(DisplayId displayId)266 sptr<CutoutInfo> ScreenSessionManagerLiteProxy::GetCutoutInfo(DisplayId displayId)
267 {
268 sptr<IRemoteObject> remote = Remote();
269 if (remote == nullptr) {
270 WLOGFW("get cutout info : remote is null");
271 return nullptr;
272 }
273 MessageParcel data;
274 MessageParcel reply;
275 MessageOption option;
276 if (!data.WriteInterfaceToken(GetDescriptor())) {
277 WLOGFE("get cutout info : failed");
278 return nullptr;
279 }
280 if (!data.WriteUint64(displayId)) {
281 WLOGFE("get cutout info: write displayId failed");
282 return nullptr;
283 }
284 if (remote->SendRequest(static_cast<uint32_t>(ScreenManagerLiteMessage::TRANS_ID_GET_CUTOUT_INFO),
285 data, reply, option) != ERR_NONE) {
286 WLOGFW("GetCutoutInfo: GetCutoutInfo failed");
287 return nullptr;
288 }
289 sptr<CutoutInfo> info = reply.ReadParcelable<CutoutInfo>();
290 return info;
291 }
292 } // namespace OHOS::Rosen
293