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