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_stub.h"
17 #include "dm_common.h"
18 #include <ipc_skeleton.h>
19
20 #include "marshalling_helper.h"
21 #include "window_manager_hilog.h"
22
23 namespace OHOS::Rosen {
24
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)25 int32_t ScreenSessionManagerLiteStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
26 MessageOption& option)
27 {
28 TLOGD(WmsLogTag::DMS, "OnRemoteRequest code is %{public}u", code);
29 if (data.ReadInterfaceToken() != GetDescriptor()) {
30 TLOGE(WmsLogTag::DMS, "InterfaceToken check failed");
31 return ERR_TRANSACTION_FAILED;
32 }
33 ScreenManagerLiteMessage msgId = static_cast<ScreenManagerLiteMessage>(code);
34 switch (msgId) {
35 case ScreenManagerLiteMessage::TRANS_ID_REGISTER_DISPLAY_MANAGER_AGENT: {
36 HandleRegisterDisplayManagerAgent(data, reply);
37 break;
38 }
39 case ScreenManagerLiteMessage::TRANS_ID_UNREGISTER_DISPLAY_MANAGER_AGENT: {
40 HandleUnRegisterDisplayManagerAgent(data, reply);
41 break;
42 }
43 case ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_DISPLAY_MODE: {
44 HandleGetFoldDisplayMode(data, reply);
45 break;
46 }
47 case ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_SET_FOLD_DISPLAY_MODE: {
48 HandleSetFoldDisplayMode(data, reply);
49 break;
50 }
51 case ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_IS_FOLDABLE: {
52 HandleIsFoldable(data, reply);
53 break;
54 }
55 case ScreenManagerLiteMessage::TRANS_ID_SCENE_BOARD_GET_FOLD_STATUS: {
56 HandleGetFoldStatus(data, reply);
57 break;
58 }
59 case ScreenManagerLiteMessage::TRANS_ID_GET_DEFAULT_DISPLAY_INFO: {
60 HandleGetDefaultDisplayInfo(data, reply);
61 break;
62 }
63 case ScreenManagerLiteMessage::TRANS_ID_GET_DISPLAY_BY_ID: {
64 HandleGetDisplayById(data, reply);
65 break;
66 }
67 case ScreenManagerLiteMessage::TRANS_ID_GET_CUTOUT_INFO: {
68 HandleGetCutoutInfo(data, reply);
69 break;
70 }
71 default:
72 TLOGW(WmsLogTag::DMS, "unknown transaction code");
73 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
74 }
75 return 0;
76 }
77
HandleRegisterDisplayManagerAgent(MessageParcel & data,MessageParcel & reply)78 int ScreenSessionManagerLiteStub::HandleRegisterDisplayManagerAgent(MessageParcel &data, MessageParcel &reply)
79 {
80 TLOGD(WmsLogTag::DMS, "run!");
81 auto agent = iface_cast<IDisplayManagerAgent>(data.ReadRemoteObject());
82 if (agent == nullptr) {
83 return ERR_INVALID_DATA;
84 }
85 auto type = static_cast<DisplayManagerAgentType>(data.ReadUint32());
86 DMError ret = RegisterDisplayManagerAgent(agent, type);
87 reply.WriteInt32(static_cast<int32_t>(ret));
88 return ERR_NONE;
89 }
90
HandleUnRegisterDisplayManagerAgent(MessageParcel & data,MessageParcel & reply)91 int ScreenSessionManagerLiteStub::HandleUnRegisterDisplayManagerAgent(MessageParcel &data, MessageParcel &reply)
92 {
93 TLOGD(WmsLogTag::DMS, "run!");
94 auto agent = iface_cast<IDisplayManagerAgent>(data.ReadRemoteObject());
95 if (agent == nullptr) {
96 return ERR_INVALID_DATA;
97 }
98 auto type = static_cast<DisplayManagerAgentType>(data.ReadUint32());
99 DMError ret = UnregisterDisplayManagerAgent(agent, type);
100 reply.WriteInt32(static_cast<int32_t>(ret));
101 return ERR_NONE;
102 }
103
HandleGetFoldDisplayMode(MessageParcel & data,MessageParcel & reply)104 int ScreenSessionManagerLiteStub::HandleGetFoldDisplayMode(MessageParcel &data, MessageParcel &reply)
105 {
106 TLOGD(WmsLogTag::DMS, "run!");
107 FoldDisplayMode displayMode = GetFoldDisplayMode();
108 reply.WriteUint32(static_cast<uint32_t>(displayMode));
109 return ERR_NONE;
110 }
111
HandleSetFoldDisplayMode(MessageParcel & data,MessageParcel & reply)112 int ScreenSessionManagerLiteStub::HandleSetFoldDisplayMode(MessageParcel &data, MessageParcel &reply)
113 {
114 TLOGD(WmsLogTag::DMS, "run!");
115 FoldDisplayMode displayMode = static_cast<FoldDisplayMode>(data.ReadUint32());
116 SetFoldDisplayMode(displayMode);
117 return ERR_NONE;
118 }
119
HandleIsFoldable(MessageParcel & data,MessageParcel & reply)120 int ScreenSessionManagerLiteStub::HandleIsFoldable(MessageParcel &data, MessageParcel &reply)
121 {
122 TLOGD(WmsLogTag::DMS, "run!");
123 reply.WriteBool(IsFoldable());
124 return ERR_NONE;
125 }
126
HandleGetFoldStatus(MessageParcel & data,MessageParcel & reply)127 int ScreenSessionManagerLiteStub::HandleGetFoldStatus(MessageParcel &data, MessageParcel &reply)
128 {
129 TLOGD(WmsLogTag::DMS, "run!");
130 reply.WriteUint32(static_cast<uint32_t>(GetFoldStatus()));
131 return ERR_NONE;
132 }
133
HandleGetDefaultDisplayInfo(MessageParcel & data,MessageParcel & reply)134 int ScreenSessionManagerLiteStub::HandleGetDefaultDisplayInfo(MessageParcel &data, MessageParcel &reply)
135 {
136 TLOGD(WmsLogTag::DMS, "run!");
137 auto info = GetDefaultDisplayInfo();
138 reply.WriteParcelable(info);
139 return ERR_NONE;
140 }
141
HandleGetDisplayById(MessageParcel & data,MessageParcel & reply)142 int ScreenSessionManagerLiteStub::HandleGetDisplayById(MessageParcel &data, MessageParcel &reply)
143 {
144 TLOGD(WmsLogTag::DMS, "run!");
145 DisplayId displayId = data.ReadUint64();
146 auto info = GetDisplayInfoById(displayId);
147 reply.WriteParcelable(info);
148 return ERR_NONE;
149 }
150
HandleGetCutoutInfo(MessageParcel & data,MessageParcel & reply)151 int ScreenSessionManagerLiteStub::HandleGetCutoutInfo(MessageParcel &data, MessageParcel &reply)
152 {
153 TLOGD(WmsLogTag::DMS, "run!");
154 DisplayId displayId = static_cast<DisplayId>(data.ReadUint64());
155 sptr<CutoutInfo> cutoutInfo = GetCutoutInfo(displayId);
156 reply.WriteParcelable(cutoutInfo);
157 return ERR_NONE;
158 }
159 } // namespace OHOS::Rosen
160