• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 "accessibility_element_operator_stub.h"
17 #include "accessibility_element_operator_callback_proxy.h"
18 #include "hilog_wrapper.h"
19 
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityElementOperatorStub()22 AccessibilityElementOperatorStub::AccessibilityElementOperatorStub()
23 {
24     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::SEARCH_BY_ACCESSIBILITY_ID)] =
25         &AccessibilityElementOperatorStub::HandleSearchElementInfoByAccessibilityId;
26     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::SEARCH_BY_TEXT)] =
27         &AccessibilityElementOperatorStub::HandleSearchElementInfosByText;
28     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::FIND_FOCUSED_INFO)] =
29         &AccessibilityElementOperatorStub::HandleFindFocusedElementInfo;
30     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::FOCUS_FIND)] =
31         &AccessibilityElementOperatorStub::HandleFocusFind;
32     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::PERFORM_ACTION_ELEMENT)] =
33         &AccessibilityElementOperatorStub::HandleExecuteAction;
34     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::CLEAR_FOCUS)] =
35         &AccessibilityElementOperatorStub::HandleClearFocus;
36     memberFuncMap_[static_cast<uint32_t>(AccessibilityInterfaceCode::OUTSIDE_TOUCH)] =
37         &AccessibilityElementOperatorStub::HandleOutsideTouch;
38 }
39 
~AccessibilityElementOperatorStub()40 AccessibilityElementOperatorStub::~AccessibilityElementOperatorStub()
41 {
42     HILOG_DEBUG();
43     memberFuncMap_.clear();
44 }
45 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)46 int AccessibilityElementOperatorStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
47     MessageParcel &reply, MessageOption &option)
48 {
49     HILOG_DEBUG("cmd = %{public}u, flags = %{public}d", code, option.GetFlags());
50     std::u16string descriptor = AccessibilityElementOperatorStub::GetDescriptor();
51     std::u16string remoteDescriptor = data.ReadInterfaceToken();
52     if (descriptor != remoteDescriptor) {
53         HILOG_INFO("local descriptor is not equal to remote");
54         return ERR_INVALID_STATE;
55     }
56 
57     auto memFunc = memberFuncMap_.find(code);
58     if (memFunc != memberFuncMap_.end()) {
59         auto func = memFunc->second;
60         if (func != nullptr) {
61             return (this->*func)(data, reply);
62         }
63     }
64     HILOG_WARN("AccessibilityElementOperatorStub::OnRemoteRequest, default case, need check.");
65     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
66 }
67 
HandleSearchElementInfoByAccessibilityId(MessageParcel & data,MessageParcel & reply)68 ErrCode AccessibilityElementOperatorStub::HandleSearchElementInfoByAccessibilityId(MessageParcel &data,
69     MessageParcel &reply)
70 {
71     HILOG_DEBUG();
72 
73     int64_t elementId = data.ReadInt64();
74     int32_t requestId = data.ReadInt32();
75     sptr<IRemoteObject> remote = data.ReadRemoteObject();
76 
77     sptr<IAccessibilityElementOperatorCallback> callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
78     int32_t mode = data.ReadInt32();
79     SearchElementInfoByAccessibilityId(elementId, requestId, callback, mode);
80     return NO_ERROR;
81 }
82 
HandleSearchElementInfosByText(MessageParcel & data,MessageParcel & reply)83 ErrCode AccessibilityElementOperatorStub::HandleSearchElementInfosByText(MessageParcel &data,
84     MessageParcel &reply)
85 {
86     HILOG_DEBUG();
87 
88     int64_t elementId = data.ReadInt64();
89     std::string text = data.ReadString();
90     int32_t requestId = data.ReadInt32();
91     sptr<IRemoteObject> remote = data.ReadRemoteObject();
92 
93     sptr<IAccessibilityElementOperatorCallback> callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
94     SearchElementInfosByText(elementId, text, requestId, callback);
95     return NO_ERROR;
96 }
97 
HandleFindFocusedElementInfo(MessageParcel & data,MessageParcel & reply)98 ErrCode AccessibilityElementOperatorStub::HandleFindFocusedElementInfo(MessageParcel &data,
99     MessageParcel &reply)
100 {
101     HILOG_DEBUG();
102 
103     int64_t elementId = data.ReadInt64();
104     int32_t focusType = data.ReadInt32();
105     int32_t requestId = data.ReadInt32();
106     sptr<IRemoteObject> remote = data.ReadRemoteObject();
107 
108     sptr<IAccessibilityElementOperatorCallback> callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
109     FindFocusedElementInfo(elementId, focusType, requestId, callback);
110     return NO_ERROR;
111 }
112 
HandleFocusFind(MessageParcel & data,MessageParcel & reply)113 ErrCode AccessibilityElementOperatorStub::HandleFocusFind(MessageParcel &data, MessageParcel &reply)
114 {
115     HILOG_DEBUG();
116 
117     int64_t elementId = data.ReadInt64();
118     int32_t direction = data.ReadInt32();
119     int32_t requestId = data.ReadInt32();
120     sptr<IRemoteObject> remote = data.ReadRemoteObject();
121 
122     sptr<IAccessibilityElementOperatorCallback> callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
123     FocusMoveSearch(elementId, direction, requestId, callback);
124     return NO_ERROR;
125 }
126 
HandleExecuteAction(MessageParcel & data,MessageParcel & reply)127 ErrCode AccessibilityElementOperatorStub::HandleExecuteAction(MessageParcel &data, MessageParcel &reply)
128 {
129     HILOG_DEBUG();
130     std::vector<std::string> argumentKey;
131     std::vector<std::string> argumentValue;
132     int64_t elementId = data.ReadInt64();
133     int32_t action = data.ReadInt32();
134     if (!data.ReadStringVector(&argumentKey)) {
135         return ERR_TRANSACTION_FAILED;
136     }
137     if (!data.ReadStringVector(&argumentValue)) {
138         return ERR_TRANSACTION_FAILED;
139     }
140     if (argumentKey.size() != argumentValue.size()) {
141         return ERR_TRANSACTION_FAILED;
142     }
143     std::map<std::string, std::string> arguments;
144     for (size_t i = 0;i < argumentKey.size(); i++) {
145         arguments.insert(std::pair<std::string, std::string>(argumentKey[i], argumentValue[i]));
146     }
147     int32_t requestId = data.ReadInt32();
148     sptr<IRemoteObject> remote = data.ReadRemoteObject();
149 
150     sptr<IAccessibilityElementOperatorCallback> callback = iface_cast<IAccessibilityElementOperatorCallback>(remote);
151     ExecuteAction(elementId, action, arguments, requestId, callback);
152     return NO_ERROR;
153 }
154 
HandleClearFocus(MessageParcel & data,MessageParcel & reply)155 ErrCode AccessibilityElementOperatorStub::HandleClearFocus(MessageParcel &data, MessageParcel &reply)
156 {
157     HILOG_DEBUG();
158 
159     ClearFocus();
160 
161     return NO_ERROR;
162 }
163 
HandleOutsideTouch(MessageParcel & data,MessageParcel & reply)164 ErrCode AccessibilityElementOperatorStub::HandleOutsideTouch(MessageParcel &data, MessageParcel &reply)
165 {
166     HILOG_DEBUG();
167 
168     OutsideTouch();
169 
170     return NO_ERROR;
171 }
172 } // namespace Accessibility
173 } // namespace OHOS