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