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_gesture_inject_path_parcel.h"
17 #include "hilog_wrapper.h"
18 #include "parcel_util.h"
19
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityGestureInjectPathParcel(const AccessibilityGestureInjectPath & gesturePath)22 AccessibilityGestureInjectPathParcel::AccessibilityGestureInjectPathParcel(
23 const AccessibilityGestureInjectPath &gesturePath)
24 {
25 AccessibilityGestureInjectPath *self = this;
26 *self = gesturePath;
27 }
28
ReadFromParcel(Parcel & parcel)29 bool AccessibilityGestureInjectPathParcel::ReadFromParcel(Parcel &parcel)
30 {
31 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, durationTime_);
32 int32_t positionSize = 0;
33 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, positionSize);
34 ContainerSecurityVerify(parcel, positionSize, positions_.max_size());
35 for (auto i = 0; i < positionSize; i++) {
36 AccessibilityGesturePosition position;
37 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionX_);
38 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionY_);
39 AddPosition(position);
40 }
41 return true;
42 }
43
Marshalling(Parcel & parcel) const44 bool AccessibilityGestureInjectPathParcel::Marshalling(Parcel &parcel) const
45 {
46 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, durationTime_);
47 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, positions_.size());
48 for (auto &position : positions_) {
49 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionX_);
50 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, position.positionY_);
51 }
52
53 return true;
54 }
55
Unmarshalling(Parcel & parcel)56 sptr<AccessibilityGestureInjectPathParcel> AccessibilityGestureInjectPathParcel::Unmarshalling(Parcel &parcel)
57 {
58 sptr<AccessibilityGestureInjectPathParcel> path = new(std::nothrow) AccessibilityGestureInjectPathParcel();
59 if (!path) {
60 HILOG_ERROR("Failed to create path.");
61 return nullptr;
62 }
63 if (!path->ReadFromParcel(parcel)) {
64 HILOG_ERROR("ReadFromParcel AccessibilityGestureInjectPathParcel failed.");
65 path = nullptr;
66 return nullptr;
67 }
68 return path;
69 }
70 } // namespace Accessibility
71 } // namespace OHOS
72