• 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 "session/container/include/zidl/session_stage_stub.h"
17 
18 #include <ipc_types.h>
19 
20 #include "window_manager_hilog.h"
21 
22 namespace OHOS::Rosen {
23 namespace {
24 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SessionStageStub"};
25 }
26 
27 const std::map<uint32_t, SessionStageStubFunc> SessionStageStub::stubFuncMap_{
28     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_SET_ACTIVE),
29         &SessionStageStub::HandleSetActive),
30     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_SIZE_CHANGE),
31         &SessionStageStub::HandleUpdateRect),
32     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_HANDLE_BACK_EVENT),
33         &SessionStageStub::HandleBackEventInner),
34     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_FOCUS_CHANGE),
35         &SessionStageStub::HandleUpdateFocus),
36     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_DESTROY),
37         &SessionStageStub::HandleNotifyDestroy),
38     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_TOUCH_DIALOG_TARGET),
39         &SessionStageStub::HandleNotifyTouchDialogTarget),
40     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_TRANSFER_COMPONENT_DATA),
41         &SessionStageStub::HandleNotifyTransferComponentData),
42     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_OCCUPIED_AREA_CHANGE_INFO),
43         &SessionStageStub::HandleNotifyOccupiedAreaChange),
44     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_UPDATE_AVOID_AREA),
45         &SessionStageStub::HandleUpdateAvoidArea),
46     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_SCREEN_SHOT),
47         &SessionStageStub::HandleNotifyScreenshot),
48     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_DUMP_SESSSION_ELEMENT_INFO),
49         &SessionStageStub::HandleDumpSessionElementInfo),
50     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_TOUCH_OUTSIDE),
51         &SessionStageStub::HandleNotifyTouchOutside),
52     std::make_pair(static_cast<uint32_t>(SessionStageMessage::TRANS_ID_NOTIFY_WINDOW_MODE_CHANGE),
53         &SessionStageStub::HandleUpdateWindowMode),
54 };
55 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)56 int SessionStageStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
57 {
58     WLOGFD("Scene session stage on remote request!, code: %{public}u", code);
59     if (data.ReadInterfaceToken() != GetDescriptor()) {
60         WLOGFE("Failed to check interface token!");
61         return ERR_INVALID_STATE;
62     }
63 
64     const auto func = stubFuncMap_.find(code);
65     if (func == stubFuncMap_.end()) {
66         WLOGFE("Failed to find function handler!");
67         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
68     }
69 
70     return (this->*(func->second))(data, reply);
71 }
72 
HandleSetActive(MessageParcel & data,MessageParcel & reply)73 int SessionStageStub::HandleSetActive(MessageParcel& data, MessageParcel& reply)
74 {
75     WLOGFD("SetActive!");
76     bool active = data.ReadBool();
77     WSError errCode = SetActive(active);
78     reply.WriteUint32(static_cast<uint32_t>(errCode));
79     return ERR_NONE;
80 }
81 
HandleUpdateRect(MessageParcel & data,MessageParcel & reply)82 int SessionStageStub::HandleUpdateRect(MessageParcel& data, MessageParcel& reply)
83 {
84     WLOGFD("UpdateRect!");
85     WSRect rect = { data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() };
86     SizeChangeReason reason = static_cast<SizeChangeReason>(data.ReadUint32());
87     WSError errCode = UpdateRect(rect, reason);
88     reply.WriteUint32(static_cast<uint32_t>(errCode));
89     return ERR_NONE;
90 }
91 
HandleBackEventInner(MessageParcel & data,MessageParcel & reply)92 int SessionStageStub::HandleBackEventInner(MessageParcel& data, MessageParcel& reply)
93 {
94     WLOGFD("HandleBackEventInner!");
95     WSError errCode = HandleBackEvent();
96     reply.WriteUint32(static_cast<uint32_t>(errCode));
97     return ERR_NONE;
98 }
99 
HandleUpdateFocus(MessageParcel & data,MessageParcel & reply)100 int SessionStageStub::HandleUpdateFocus(MessageParcel& data, MessageParcel& reply)
101 {
102     WLOGFD("UpdateFocus!");
103     bool isFocused = data.ReadBool();
104     WSError errCode = UpdateFocus(isFocused);
105     reply.WriteUint32(static_cast<uint32_t>(errCode));
106     return ERR_NONE;
107 }
108 
HandleNotifyDestroy(MessageParcel & data,MessageParcel & reply)109 int SessionStageStub::HandleNotifyDestroy(MessageParcel& data, MessageParcel& reply)
110 {
111     WLOGFD("Notify Destroy");
112     WSError errCode = NotifyDestroy();
113     reply.WriteUint32(static_cast<uint32_t>(errCode));
114     return ERR_NONE;
115 }
116 
HandleNotifyTouchDialogTarget(MessageParcel & data,MessageParcel & reply)117 int SessionStageStub::HandleNotifyTouchDialogTarget(MessageParcel& data, MessageParcel& reply)
118 {
119     WLOGFD("Notify touch dialog target");
120     NotifyTouchDialogTarget();
121     return ERR_NONE;
122 }
123 
HandleNotifyTransferComponentData(MessageParcel & data,MessageParcel & reply)124 int SessionStageStub::HandleNotifyTransferComponentData(MessageParcel& data, MessageParcel& reply)
125 {
126     WLOGFD("HandleNotifyTransferComponentData!");
127     std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
128     if (wantParams == nullptr) {
129         WLOGFE("wantParams is nullptr");
130         return ERR_INVALID_VALUE;
131     }
132     WSError errCode = NotifyTransferComponentData(*wantParams);
133     reply.WriteUint32(static_cast<uint32_t>(errCode));
134     return ERR_NONE;
135 }
136 
HandleNotifyOccupiedAreaChange(MessageParcel & data,MessageParcel & reply)137 int SessionStageStub::HandleNotifyOccupiedAreaChange(MessageParcel& data, MessageParcel& reply)
138 {
139     WLOGFD("HandleNotifyOccupiedAreaChangeInfo!");
140     sptr<OccupiedAreaChangeInfo> info(data.ReadParcelable<OccupiedAreaChangeInfo>());
141     if (info == nullptr) {
142         WLOGFE("Occupied info is nullptr");
143         return ERR_INVALID_VALUE;
144     }
145     NotifyOccupiedAreaChangeInfo(info);
146     return ERR_NONE;
147 }
148 
HandleUpdateAvoidArea(MessageParcel & data,MessageParcel & reply)149 int SessionStageStub::HandleUpdateAvoidArea(MessageParcel& data, MessageParcel& reply)
150 {
151     WLOGFD("HandleUpdateAvoidArea!");
152     sptr<AvoidArea> avoidArea = data.ReadStrongParcelable<AvoidArea>();
153     uint32_t type;
154     if (!data.ReadUint32(type)) {
155         return ERR_INVALID_VALUE;
156     }
157     UpdateAvoidArea(avoidArea, static_cast<AvoidAreaType>(type));
158     return ERR_NONE;
159 }
160 
HandleNotifyScreenshot(MessageParcel & data,MessageParcel & reply)161 int SessionStageStub::HandleNotifyScreenshot(MessageParcel& data, MessageParcel& reply)
162 {
163     WLOGFD("Notify Screen shot!");
164     NotifyScreenshot();
165     return ERR_NONE;
166 }
167 
HandleDumpSessionElementInfo(MessageParcel & data,MessageParcel & reply)168 int SessionStageStub::HandleDumpSessionElementInfo(MessageParcel& data, MessageParcel& reply)
169 {
170     WLOGFD("HandleDumpSessionElementInfo!");
171     std::vector<std::string> params;
172     if (!data.ReadStringVector(&params)) {
173         WLOGFE("Fail to read params");
174         return -1;
175     }
176     DumpSessionElementInfo(params);
177     return ERR_NONE;
178 }
179 
HandleNotifyTouchOutside(MessageParcel & data,MessageParcel & reply)180 int SessionStageStub::HandleNotifyTouchOutside(MessageParcel& data, MessageParcel& reply)
181 {
182     WLOGFD("HandleNotifyTouchOutside!");
183     NotifyTouchOutside();
184     return ERR_NONE;
185 }
186 
HandleUpdateWindowMode(MessageParcel & data,MessageParcel & reply)187 int SessionStageStub::HandleUpdateWindowMode(MessageParcel& data, MessageParcel& reply)
188 {
189     WLOGFD("HandleUpdateWindowMode!");
190     WindowMode mode = static_cast<WindowMode>(data.ReadUint32());
191     WSError errCode = UpdateWindowMode(mode);
192     reply.WriteInt32(static_cast<int32_t>(errCode));
193     return ERR_NONE;
194 }
195 } // namespace OHOS::Rosen
196