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