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