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_service_state_stub.h"
17 #include "hilog_wrapper.h"
18 #include "ipc_skeleton.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 #include "accessibility_system_ability_client.h"
22
23 namespace OHOS {
24 namespace Accessibility {
AccessibleAbilityManagerServiceStateStub()25 AccessibleAbilityManagerServiceStateStub::AccessibleAbilityManagerServiceStateStub()
26 {
27 HILOG_DEBUG("start");
28 }
29
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)30 int AccessibleAbilityManagerServiceStateStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
31 MessageParcel &reply, MessageOption &option)
32 {
33 HILOG_DEBUG("AccessibleAbilityManagerServiceStateStub::OnRemoteRequest, cmd = %{public}d, flags= %{public}d",
34 code, option.GetFlags());
35 std::u16string descriptor = AccessibleAbilityManagerServiceStateStub::GetDescriptor();
36 std::u16string remoteDescriptor = data.ReadInterfaceToken();
37 if (descriptor != remoteDescriptor) {
38 HILOG_INFO("local descriptor is not equal to remote");
39 return ERR_INVALID_STATE;
40 }
41
42 if (code == static_cast<uint32_t>(IAccessibleAbilityManagerServiceState::Message::ON_STATE_CHANGED)) {
43 return HandleOnStateChanged(data, reply);
44 }
45 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
46 }
47
HandleOnStateChanged(MessageParcel & data,MessageParcel & reply)48 ErrCode AccessibleAbilityManagerServiceStateStub::HandleOnStateChanged(MessageParcel &data,
49 MessageParcel &reply)
50 {
51 HILOG_DEBUG("start");
52 uint32_t stateType = data.ReadUint32();
53 OnStateChanged(stateType);
54
55 return NO_ERROR;
56 }
57
OnStateChanged(const uint32_t stateType)58 void AccessibleAbilityManagerServiceStateStub::OnStateChanged(const uint32_t stateType)
59 {
60 HILOG_DEBUG("stateType[%{public}d}", stateType);
61 std::shared_ptr<AccessibilitySystemAbilityClient> instance = AccessibilitySystemAbilityClient::GetInstance();
62 if (!instance) {
63 HILOG_DEBUG("Can't get asac instance");
64 return;
65 }
66 if (stateType & AccessibilitySystemAbilityClient::STATE_ACCESSIBILITY_ENABLED) {
67 instance->SetEnabled(true);
68 } else {
69 instance->SetEnabled(false);
70 }
71
72 if (stateType & AccessibilitySystemAbilityClient::STATE_EXPLORATION_ENABLED) {
73 instance->UpdateTouchExplorationEnabled(true);
74 } else {
75 instance->UpdateTouchExplorationEnabled(false);
76 }
77
78 if (stateType & AccessibilitySystemAbilityClient::STATE_CAPTION_ENABLED) {
79 instance->SetCaptionEnabled(true);
80 } else {
81 instance->SetCaptionEnabled(false);
82 }
83
84 if (stateType & AccessibilitySystemAbilityClient::STATE_KEYEVENT_ENABLED) {
85 instance->SetKeyEventObserverState(true);
86 } else {
87 instance->SetKeyEventObserverState(false);
88 }
89
90 if (stateType & AccessibilitySystemAbilityClient::STATE_GESTURE_ENABLED) {
91 instance->SetGestureState(true);
92 } else {
93 instance->SetGestureState(false);
94 }
95 }
96 } // namespace Accessibility
97 } // namespace OHOS