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_stub.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 {
AccessibleAbilityManagerCaptionObserverStub()23 AccessibleAbilityManagerCaptionObserverStub::AccessibleAbilityManagerCaptionObserverStub()
24 {
25     HILOG_DEBUG();
26 }
27 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int AccessibleAbilityManagerCaptionObserverStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
29     MessageParcel &reply, MessageOption &option)
30 {
31     HILOG_DEBUG("cmd = %{public}d, flags = %{public}d", code, option.GetFlags());
32     std::u16string descriptor = AccessibleAbilityManagerCaptionObserverStub::GetDescriptor();
33     std::u16string remoteDescriptor = data.ReadInterfaceToken();
34     if (descriptor != remoteDescriptor) {
35         HILOG_INFO("local descriptor is not equal to remote");
36         return ERR_INVALID_STATE;
37     }
38 
39     if (code ==
40         static_cast<uint32_t>(AccessibilityInterfaceCode::ON_PROPERTY_CHANGED)) {
41         return HandleOnCaptionPropertyChanged(data, reply);
42     }
43     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
44 }
45 
HandleOnCaptionPropertyChanged(MessageParcel & data,MessageParcel & reply)46 ErrCode AccessibleAbilityManagerCaptionObserverStub::HandleOnCaptionPropertyChanged(MessageParcel &data,
47     MessageParcel &reply)
48 {
49     HILOG_DEBUG();
50     sptr<CaptionPropertyParcel> property = data.ReadStrongParcelable<CaptionPropertyParcel>();
51     if (property == nullptr) {
52         HILOG_ERROR("ReadStrongParcelable<CaptionProperty> failed");
53         return ERR_TRANSACTION_FAILED;
54     }
55     OnPropertyChanged(*property);
56 
57     return NO_ERROR;
58 }
59 } // namespace Accessibility
60 } // namespace OHOS