• 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 "accessibility_ability_info_parcel.h"
17 #include "hilog_wrapper.h"
18 #include "parcel_util.h"
19 
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityAbilityInfoParcel(const AccessibilityAbilityInfo & accessibilityAbilityInfo)22 AccessibilityAbilityInfoParcel::AccessibilityAbilityInfoParcel(
23     const AccessibilityAbilityInfo &accessibilityAbilityInfo)
24 {
25     HILOG_DEBUG();
26     AccessibilityAbilityInfo *self = this;
27     *self = accessibilityAbilityInfo;
28 }
29 
ReadFromParcel(Parcel & parcel)30 bool AccessibilityAbilityInfoParcel::ReadFromParcel(Parcel &parcel)
31 {
32     HILOG_DEBUG();
33     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_);
34     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleName_);
35     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, name_);
36     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_);
37 
38     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, capabilities_);
39     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, staticCapabilities_);
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, rationale_);
41     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, abilityTypes_);
42     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, eventTypes_);
43     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, settingsAbility_);
44     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, &targetBundleNames_);
45 
46     return true;
47 }
48 
Marshalling(Parcel & parcel) const49 bool AccessibilityAbilityInfoParcel::Marshalling(Parcel &parcel) const
50 {
51     HILOG_DEBUG();
52     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_);
53     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, moduleName_);
54     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, name_);
55     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description_);
56 
57     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, capabilities_);
58     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, staticCapabilities_);
59     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, rationale_);
60     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, abilityTypes_);
61     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, eventTypes_);
62     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, settingsAbility_);
63     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, targetBundleNames_);
64 
65     return true;
66 }
67 
Unmarshalling(Parcel & parcel)68 sptr<AccessibilityAbilityInfoParcel> AccessibilityAbilityInfoParcel::Unmarshalling(Parcel &parcel)
69 {
70     HILOG_DEBUG();
71     sptr<AccessibilityAbilityInfoParcel> info = new(std::nothrow) AccessibilityAbilityInfoParcel();
72     if (!info) {
73         HILOG_ERROR("Failed to create info.");
74         return nullptr;
75     }
76     if (!info->ReadFromParcel(parcel)) {
77         HILOG_ERROR("ReadFromParcel AccessibilityAbilityInfo failed.");
78         info = nullptr;
79         return nullptr;
80     }
81     return info;
82 }
83 } // namespace Accessibility
84 } // namespace OHOS