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 #include "accessible_ability_manager_service_caption_property_stub.h"
16 #include "hilog_wrapper.h"
17 #include "ipc_skeleton.h"
18 #include "ipc_types.h"
19 #include "iremote_object.h"
20 #include "accessibility_system_ability_client.h"
21
22 namespace OHOS {
23 namespace Accessibility {
AccessibleAbilityManagerServiceCaptionPropertyStub()24 AccessibleAbilityManagerServiceCaptionPropertyStub::AccessibleAbilityManagerServiceCaptionPropertyStub()
25 {
26 HILOG_DEBUG("start");
27 }
28
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int AccessibleAbilityManagerServiceCaptionPropertyStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
30 MessageParcel &reply, MessageOption &option)
31 {
32 HILOG_DEBUG("AccessibleAbilityManagerServiceCaptionPropertyStub::OnRemoteRequest,\
33 cmd = %{public}d, flags = %{public}d", code, option.GetFlags());
34 std::u16string descriptor = AccessibleAbilityManagerServiceCaptionPropertyStub::GetDescriptor();
35 std::u16string remoteDescriptor = data.ReadInterfaceToken();
36 if (descriptor != remoteDescriptor) {
37 HILOG_INFO("local descriptor is not equal to remote");
38 return ERR_INVALID_STATE;
39 }
40
41 if (code ==
42 static_cast<uint32_t>(IAccessibleAbilityManagerServiceCaptionProperty::Message::ON_CAPTION_PROPERTY_CHANGED)) {
43 return HandleOnCaptionPropertyChanged(data, reply);
44 }
45 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
46 }
47
HandleOnCaptionPropertyChanged(MessageParcel & data,MessageParcel & reply)48 ErrCode AccessibleAbilityManagerServiceCaptionPropertyStub::HandleOnCaptionPropertyChanged(MessageParcel &data,
49 MessageParcel &reply)
50 {
51 HILOG_DEBUG("start");
52 CaptionProperty* caption = data.ReadParcelable<CaptionProperty>();
53 if (!caption) {
54 HILOG_ERROR("ReadParcelable<CaptionProperty> failed");
55 return ERROR;
56 }
57 OnCaptionPropertyChanged(*caption);
58
59 return NO_ERROR;
60 }
61
OnCaptionPropertyChanged(const CaptionProperty & caption)62 void AccessibleAbilityManagerServiceCaptionPropertyStub::OnCaptionPropertyChanged(const CaptionProperty& caption)
63 {
64 HILOG_DEBUG("start");
65 std::shared_ptr<AccessibilitySystemAbilityClient> instance = AccessibilitySystemAbilityClient::GetInstance();
66 if (!instance) {
67 HILOG_DEBUG("Can't get asac instance");
68 return;
69 }
70 instance->UpdatecaptionProperty(caption);
71 }
72 } // namespace Accessibility
73 } // namespace OHOS