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