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