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_callback_stub.h"
17 #include "accessibility_element_info_parcel.h"
18 #include "hilog_wrapper.h"
19
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityElementOperatorCallbackStub()22 AccessibilityElementOperatorCallbackStub::AccessibilityElementOperatorCallbackStub()
23 {
24 memberFuncMap_[static_cast<uint32_t>(
25 IAccessibilityElementOperatorCallback::Message::SET_RESULT_BY_ACCESSIBILITY_ID)] =
26 &AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByAccessibilityIdResult;
27 memberFuncMap_[static_cast<uint32_t>(IAccessibilityElementOperatorCallback::Message::SET_RESULT_BY_TEXT)] =
28 &AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByTextResult;
29 memberFuncMap_[static_cast<uint32_t>(
30 IAccessibilityElementOperatorCallback::Message::SET_RESULT_FOCUSED_INFO)] =
31 &AccessibilityElementOperatorCallbackStub::HandleSetFindFocusedElementInfoResult;
32 memberFuncMap_[static_cast<uint32_t>(IAccessibilityElementOperatorCallback::Message::SET_RESULT_FOCUS_MOVE)] =
33 &AccessibilityElementOperatorCallbackStub::HandleSetFocusMoveSearchResult;
34 memberFuncMap_[static_cast<uint32_t>(
35 IAccessibilityElementOperatorCallback::Message::SET_RESULT_PERFORM_ACTION)] =
36 &AccessibilityElementOperatorCallbackStub::HandleSetExecuteActionResult;
37 }
38
~AccessibilityElementOperatorCallbackStub()39 AccessibilityElementOperatorCallbackStub::~AccessibilityElementOperatorCallbackStub()
40 {
41 HILOG_DEBUG();
42 memberFuncMap_.clear();
43 }
44
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)45 int AccessibilityElementOperatorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
46 MessageParcel &reply, MessageOption &option)
47 {
48 HILOG_DEBUG("cmd = %{public}u, flags= %{public}d", code, option.GetFlags());
49 std::u16string descriptor = AccessibilityElementOperatorCallbackStub::GetDescriptor();
50 std::u16string remoteDescriptor = data.ReadInterfaceToken();
51 if (descriptor != remoteDescriptor) {
52 HILOG_ERROR("local descriptor is not equal to remote");
53 return ERR_INVALID_STATE;
54 }
55
56 auto memFunc = memberFuncMap_.find(code);
57 if (memFunc != memberFuncMap_.end()) {
58 auto func = memFunc->second;
59 if (func != nullptr) {
60 return (this->*func)(data, reply);
61 }
62 }
63 HILOG_WARN("AccessibilityElementOperatorCallbackStub::OnRemoteRequest, default case, need check.");
64 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
65 }
66
HandleSetSearchElementInfoByAccessibilityIdResult(MessageParcel & data,MessageParcel & reply)67 ErrCode AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByAccessibilityIdResult(
68 MessageParcel &data, MessageParcel &reply)
69 {
70 HILOG_DEBUG();
71 std::vector<AccessibilityElementInfo> infos {};
72 int32_t accessibilityInfosize = data.ReadInt32();
73 for (int32_t i = 0; i < accessibilityInfosize; i++) {
74 sptr<AccessibilityElementInfoParcel> accessibilityInfo =
75 data.ReadStrongParcelable<AccessibilityElementInfoParcel>();
76 if (!accessibilityInfo) {
77 HILOG_ERROR("ReadStrongParcelable<accessibilityInfo> failed");
78 return TRANSACTION_ERR;
79 }
80 infos.emplace_back(*accessibilityInfo);
81 }
82 int32_t requestId = data.ReadInt32();
83
84 SetSearchElementInfoByAccessibilityIdResult(infos, requestId);
85 return NO_ERROR;
86 }
87
HandleSetSearchElementInfoByTextResult(MessageParcel & data,MessageParcel & reply)88 ErrCode AccessibilityElementOperatorCallbackStub::HandleSetSearchElementInfoByTextResult(
89 MessageParcel &data, MessageParcel &reply)
90 {
91 HILOG_DEBUG();
92 std::vector<AccessibilityElementInfo> infos {};
93 int32_t accessibilityInfosize = data.ReadInt32();
94 for (int32_t i = 0; i < accessibilityInfosize; i++) {
95 sptr<AccessibilityElementInfoParcel> accessibilityInfo =
96 data.ReadStrongParcelable<AccessibilityElementInfoParcel>();
97 if (!accessibilityInfo) {
98 HILOG_ERROR("ReadStrongParcelable<accessibilityInfo> failed");
99 return TRANSACTION_ERR;
100 }
101 infos.emplace_back(*accessibilityInfo);
102 }
103 int32_t requestId = data.ReadInt32();
104
105 SetSearchElementInfoByTextResult(infos, requestId);
106
107 return NO_ERROR;
108 }
109
HandleSetFindFocusedElementInfoResult(MessageParcel & data,MessageParcel & reply)110 ErrCode AccessibilityElementOperatorCallbackStub::HandleSetFindFocusedElementInfoResult(MessageParcel &data,
111 MessageParcel &reply)
112 {
113 HILOG_DEBUG();
114 sptr<AccessibilityElementInfoParcel> info = data.ReadStrongParcelable<AccessibilityElementInfoParcel>();
115 if (!info) {
116 HILOG_ERROR("ReadStrongParcelable<AccessibilityElementInfo> failed");
117 return TRANSACTION_ERR;
118 }
119
120 int32_t requestId = data.ReadInt32();
121
122 SetFindFocusedElementInfoResult(*info, requestId);
123
124 return NO_ERROR;
125 }
126
HandleSetFocusMoveSearchResult(MessageParcel & data,MessageParcel & reply)127 ErrCode AccessibilityElementOperatorCallbackStub::HandleSetFocusMoveSearchResult(MessageParcel &data,
128 MessageParcel &reply)
129 {
130 HILOG_DEBUG();
131 sptr<AccessibilityElementInfoParcel> info = data.ReadStrongParcelable<AccessibilityElementInfoParcel>();
132 if (!info) {
133 HILOG_ERROR("ReadStrongParcelable<AccessibilityElementInfo> failed");
134 return TRANSACTION_ERR;
135 }
136
137 int32_t requestId = data.ReadInt32();
138
139 SetFocusMoveSearchResult(*info, requestId);
140
141 return NO_ERROR;
142 }
143
HandleSetExecuteActionResult(MessageParcel & data,MessageParcel & reply)144 ErrCode AccessibilityElementOperatorCallbackStub::HandleSetExecuteActionResult(MessageParcel &data,
145 MessageParcel &reply)
146 {
147 HILOG_DEBUG();
148
149 bool succeeded = data.ReadBool();
150 int32_t requestId = data.ReadInt32();
151
152 SetExecuteActionResult(succeeded, requestId);
153
154 return NO_ERROR;
155 }
156 } // namespace Accessibility
157 } // namespace OHOS