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