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 "accessible_ability_manager_caption_observer_proxy.h"
17 #include "accessibility_caption_parcel.h"
18 #include "accessibility_ipc_interface_code.h"
19 #include "hilog_wrapper.h"
20
21 namespace OHOS {
22 namespace Accessibility {
AccessibleAbilityManagerCaptionObserverProxy(const sptr<IRemoteObject> & impl)23 AccessibleAbilityManagerCaptionObserverProxy::AccessibleAbilityManagerCaptionObserverProxy(
24 const sptr<IRemoteObject> &impl) : IRemoteProxy<IAccessibleAbilityManagerCaptionObserver>(impl)
25 {}
26
~AccessibleAbilityManagerCaptionObserverProxy()27 AccessibleAbilityManagerCaptionObserverProxy::~AccessibleAbilityManagerCaptionObserverProxy()
28 {}
29
WriteInterfaceToken(MessageParcel & data)30 bool AccessibleAbilityManagerCaptionObserverProxy::WriteInterfaceToken(MessageParcel &data)
31 {
32 HILOG_DEBUG();
33 if (!data.WriteInterfaceToken(AccessibleAbilityManagerCaptionObserverProxy::GetDescriptor())) {
34 HILOG_ERROR("write interface token failed");
35 return false;
36 }
37 return true;
38 }
39
OnPropertyChanged(const AccessibilityConfig::CaptionProperty & property)40 void AccessibleAbilityManagerCaptionObserverProxy::OnPropertyChanged(
41 const AccessibilityConfig::CaptionProperty& property)
42 {
43 HILOG_DEBUG();
44
45 int32_t error = NO_ERROR;
46 MessageParcel data;
47 MessageParcel reply;
48 MessageOption option(MessageOption::TF_ASYNC | MessageOption::TF_ASYNC_WAKEUP_LATER);
49 CaptionPropertyParcel captionParcel(property);
50
51 if (!WriteInterfaceToken(data)) {
52 HILOG_ERROR("fail, connection write Token");
53 return;
54 }
55
56 if (!data.WriteParcelable(&captionParcel)) {
57 HILOG_ERROR("fail, connection write caption property error");
58 return;
59 }
60
61 sptr<IRemoteObject> remote = Remote();
62 if (remote == nullptr) {
63 HILOG_ERROR("fail to send transact cmd due to remote object");
64 return;
65 }
66
67 error = remote->SendRequest(
68 static_cast<uint32_t>(AccessibilityInterfaceCode::ON_PROPERTY_CHANGED),
69 data, reply, option);
70 if (error != NO_ERROR) {
71 HILOG_ERROR("OnPropertyChanged fail, error: %{public}d", error);
72 return;
73 }
74 }
75 } // namespace Accessibility
76 } // namespace OHOS