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