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