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