• 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 #include "form_renderer_dispatcher_stub.h"
16 #include <transaction/rs_transaction.h>
17 
18 #include "form_renderer_hilog.h"
19 
20 namespace OHOS {
21 namespace Ace {
FormRendererDispatcherStub()22 FormRendererDispatcherStub::FormRendererDispatcherStub()
23 {
24     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_POINTER_EVENT)] =
25         &FormRendererDispatcherStub::HandleDispatchPointerEvent;
26     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_ALLOW_UPDATE)] =
27         &FormRendererDispatcherStub::HandleSetAllowUpdate;
28     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::DISPATCH_SURFACE_CHANGE_EVENT)] =
29         &FormRendererDispatcherStub::HandleDispatchSurfaceChangeEvent;
30     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_OBSCURED)] =
31         &FormRendererDispatcherStub::HandleSetObscured;
32     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_CHILD_TREE_REGISTER)] =
33         &FormRendererDispatcherStub::HandleOnAccessibilityChildTreeRegister;
34     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_CHILD_TREE_DEREGISTER)] =
35         &FormRendererDispatcherStub::HandleOnAccessibilityChildTreeDeregister;
36     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_DUMP_CHILD_INFO)] =
37         &FormRendererDispatcherStub::HandleOnAccessibilityDumpChildInfo;
38     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::ACCESSIBILITY_TRANSFER_HOVER_EVENT)] =
39         &FormRendererDispatcherStub::HandleOnAccessibilityTransferHoverEvent;
40     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::NOTIFY_DUMP_INFO)] =
41         &FormRendererDispatcherStub::HandleOnNotifyDumpInfo;
42     memberFuncMap_[static_cast<uint32_t>(IFormRendererDispatcher::Message::SET_MULTI_INSTANCE_ENABLED)] =
43         &FormRendererDispatcherStub::HandleSetMultiInstanceEnabled;
44 }
45 
~FormRendererDispatcherStub()46 FormRendererDispatcherStub::~FormRendererDispatcherStub()
47 {
48     memberFuncMap_.clear();
49 }
50 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)51 int32_t FormRendererDispatcherStub::OnRemoteRequest(
52     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
53 {
54     HILOG_DEBUG("FormRendererDispatcherStub::OnReceived, code = %{public}u, flags= %{public}d.",
55         code, option.GetFlags());
56     std::u16string descriptor = FormRendererDispatcherStub::GetDescriptor();
57     std::u16string remoteDescriptor = data.ReadInterfaceToken();
58     if (descriptor != remoteDescriptor) {
59         HILOG_ERROR("%{public}s failed, local descriptor is not equal to remote", __func__);
60         return ERR_INVALID_VALUE;
61     }
62 
63     auto itFunc = memberFuncMap_.find(code);
64     if (itFunc != memberFuncMap_.end()) {
65         auto memberFunc = itFunc->second;
66         if (memberFunc != nullptr) {
67             return (this->*memberFunc)(data, reply);
68         }
69     }
70 
71     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
72 }
73 
HandleDispatchPointerEvent(MessageParcel & data,MessageParcel & reply)74 int32_t FormRendererDispatcherStub::HandleDispatchPointerEvent(MessageParcel &data, MessageParcel &reply)
75 {
76     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
77     if (pointerEvent == nullptr) {
78         HILOG_ERROR("%{public}s, Create Pointer Event failed.", __func__);
79         return ERR_INVALID_VALUE;
80     }
81 
82     if (!pointerEvent->ReadFromParcel(data)) {
83         HILOG_ERROR("%{public}s, Read Pointer Event failed.", __func__);
84         return ERR_INVALID_VALUE;
85     }
86     SerializedGesture serializedGesture;
87     DispatchPointerEvent(pointerEvent, serializedGesture);
88     reply.WriteInt32(serializedGesture.data.size());
89     reply.WriteRawData(serializedGesture.data.data(), serializedGesture.data.size());
90     return ERR_OK;
91 }
92 
HandleSetAllowUpdate(MessageParcel & data,MessageParcel & reply)93 int32_t FormRendererDispatcherStub::HandleSetAllowUpdate(MessageParcel &data, MessageParcel &reply)
94 {
95     bool allowUpdate = data.ReadBool();
96     SetAllowUpdate(allowUpdate);
97     reply.WriteInt32(ERR_OK);
98     return ERR_OK;
99 }
100 
HandleDispatchSurfaceChangeEvent(MessageParcel & data,MessageParcel & reply)101 int32_t FormRendererDispatcherStub::HandleDispatchSurfaceChangeEvent(MessageParcel& data, MessageParcel& reply)
102 {
103     float width = data.ReadFloat();
104     float height = data.ReadFloat();
105     uint32_t reason = static_cast<uint32_t>(data.ReadUint32());
106     bool hasRSTransaction = data.ReadBool();
107     std::shared_ptr<Rosen::RSTransaction> transaction = nullptr;
108     if (hasRSTransaction) {
109         std::shared_ptr<Rosen::RSTransaction> transactionTmp(data.ReadParcelable<Rosen::RSTransaction>());
110         transaction = transactionTmp;
111     }
112     float borderWdidth = data.ReadFloat();
113     DispatchSurfaceChangeEvent(width, height, reason, transaction, borderWdidth);
114     reply.WriteInt32(ERR_OK);
115     return ERR_OK;
116 }
117 
118 
HandleSetObscured(MessageParcel & data,MessageParcel & reply)119 int32_t FormRendererDispatcherStub::HandleSetObscured(MessageParcel &data, MessageParcel &reply)
120 {
121     bool isObscured = data.ReadBool();
122     SetObscured(isObscured);
123     reply.WriteInt32(ERR_OK);
124     return ERR_OK;
125 }
126 
HandleOnAccessibilityChildTreeRegister(MessageParcel & data,MessageParcel & reply)127 int32_t FormRendererDispatcherStub::HandleOnAccessibilityChildTreeRegister(MessageParcel &data, MessageParcel &reply)
128 {
129     uint32_t windowId = data.ReadUint32();
130     int32_t treeId = data.ReadInt32();
131     int64_t accessibilityId = data.ReadInt64();
132     OnAccessibilityChildTreeRegister(windowId, treeId, accessibilityId);
133     reply.WriteInt32(ERR_OK);
134     return ERR_OK;
135 }
136 
HandleOnAccessibilityChildTreeDeregister(MessageParcel & data,MessageParcel & reply)137 int32_t FormRendererDispatcherStub::HandleOnAccessibilityChildTreeDeregister(MessageParcel &data, MessageParcel &reply)
138 {
139     OnAccessibilityChildTreeDeregister();
140     reply.WriteInt32(ERR_OK);
141     return ERR_OK;
142 }
143 
HandleOnAccessibilityDumpChildInfo(MessageParcel & data,MessageParcel & reply)144 int32_t FormRendererDispatcherStub::HandleOnAccessibilityDumpChildInfo(MessageParcel &data, MessageParcel &reply)
145 {
146     std::vector<std::string> params;
147     if (!data.ReadStringVector(&params)) {
148         HILOG_ERROR("%{public}s, Read params failed.", __func__);
149         return ERR_INVALID_VALUE;
150     }
151     std::vector<std::string> info;
152     OnAccessibilityDumpChildInfo(params, info);
153     reply.WriteStringVector(info);
154     return ERR_OK;
155 }
156 
HandleOnAccessibilityTransferHoverEvent(MessageParcel & data,MessageParcel & reply)157 int32_t FormRendererDispatcherStub::HandleOnAccessibilityTransferHoverEvent(MessageParcel &data, MessageParcel &reply)
158 {
159     float pointX = 0;
160     float pointY = 0;
161     int32_t sourceType = 0;
162     int32_t eventType = 0;
163     int64_t timeMs = 0;
164     if (!data.ReadFloat(pointX) ||
165         !data.ReadFloat(pointY) ||
166         !data.ReadInt32(sourceType) ||
167         !data.ReadInt32(eventType) ||
168         !data.ReadInt64(timeMs)) {
169         HILOG_ERROR("Read HandleTransferAccessibilityHoverEvent data failed!");
170         return ERR_INVALID_VALUE;
171     };
172     OnAccessibilityTransferHoverEvent(pointX, pointY, sourceType, eventType, timeMs);
173     reply.WriteInt32(ERR_OK);
174     return ERR_OK;
175 }
176 
HandleOnNotifyDumpInfo(MessageParcel & data,MessageParcel & reply)177 int32_t FormRendererDispatcherStub::HandleOnNotifyDumpInfo(MessageParcel &data, MessageParcel &reply)
178 {
179     std::vector<std::string> params;
180     if (!data.ReadStringVector(&params)) {
181         HILOG_ERROR("%{public}s, Read params failed.", __func__);
182         return ERR_INVALID_VALUE;
183     }
184     std::vector<std::string> info;
185     OnNotifyDumpInfo(params, info);
186     if (!reply.WriteStringVector(info)) {
187         HILOG_ERROR("WriteStringVector<dumpInfos> failed");
188         return ERR_INVALID_VALUE;
189     }
190     return ERR_OK;
191 }
192 
HandleSetMultiInstanceEnabled(MessageParcel & data,MessageParcel & reply)193 int32_t FormRendererDispatcherStub::HandleSetMultiInstanceEnabled(MessageParcel &data, MessageParcel &reply)
194 {
195     bool isMultiInstanceEnabled = data.ReadBool();
196     SetMultiInstanceEnabled(isMultiInstanceEnabled);
197     if (!reply.WriteInt32(ERR_OK)) {
198         HILOG_ERROR("Write result failed");
199     }
200     return ERR_OK;
201 }
202 }  // namespace Ace
203 }  // namespace OHOS