1 /*
2 * Copyright (c) 2023 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 #ifndef SECURITY_COMPONENT_INFO_H
17 #define SECURITY_COMPONENT_INFO_H
18
19 #include <cstdint>
20
21 namespace OHOS {
22 namespace Security {
23 namespace SecurityComponent {
24 static constexpr int32_t INVALID_SC_ID = -1;
25 using DimensionT = double; // unit is vp
26 static constexpr DimensionT DEFAULT_DIMENSION = 0.0;
27 static constexpr DimensionT MIN_FONT_SIZE = 12.0;
28 static constexpr DimensionT MIN_ICON_SIZE = 12.0;
29 static constexpr DimensionT MIN_PADDING_SIZE = 0.0;
30 static constexpr DimensionT MIN_PADDING_WITHOUT_BG = 4.0;
31 static constexpr uint32_t MAX_EXTRA_SIZE = 0x1000;
32
33 struct PaddingSize {
34 DimensionT top = DEFAULT_DIMENSION;
35 DimensionT right = DEFAULT_DIMENSION;
36 DimensionT bottom = DEFAULT_DIMENSION;
37 DimensionT left = DEFAULT_DIMENSION;
38 };
39
40 enum SecCompType {
41 UNKNOWN_SC_TYPE = 0,
42 LOCATION_COMPONENT,
43 PASTE_COMPONENT,
44 SAVE_COMPONENT,
45 MAX_SC_TYPE
46 };
47
48 union SecCompColor {
49 struct {
50 uint8_t blue;
51 uint8_t green;
52 uint8_t red;
53 uint8_t alpha;
54 } argb;
55 uint32_t value;
56 };
57
IsComponentTypeValid(int32_t type)58 inline bool IsComponentTypeValid(int32_t type)
59 {
60 return (type > UNKNOWN_SC_TYPE && type < MAX_SC_TYPE);
61 }
62
GreatOrEqual(double left,double right)63 inline bool GreatOrEqual(double left, double right)
64 {
65 constexpr double epsilon = -0.001;
66 return (left - right) > epsilon;
67 }
68
GreatNotEqual(double left,double right)69 inline bool GreatNotEqual(double left, double right)
70 {
71 constexpr double epsilon = 0.001;
72 return (left - right) > epsilon;
73 }
74
IsEqual(double left,double right)75 inline bool IsEqual(double left, double right)
76 {
77 constexpr double epsilon = 0.001;
78 if (left > right) {
79 return (left - right) < epsilon;
80 } else if (right > left) {
81 return (right - left) < epsilon;
82 } else {
83 return true;
84 }
85 }
86
87 class SecCompRect {
88 public:
89 SecCompRect() = default;
90 ~SecCompRect() = default;
91
IsInRect(double x,double y)92 bool IsInRect(double x, double y) const
93 {
94 return (GreatOrEqual(x, x_) && GreatOrEqual((x_ + width_), x) &&
95 GreatOrEqual(y, y_) && GreatOrEqual((y_ + height_), y));
96 };
97
98 bool operator==(const SecCompRect& other) const
99 {
100 return (IsEqual(x_, other.x_)) && (IsEqual(y_, other.y_)) &&
101 (IsEqual(width_, other.width_)) && (IsEqual(height_, other.height_));
102 }
103
104 DimensionT x_ = 0.0;
105 DimensionT y_ = 0.0;
106 DimensionT width_ = 0.0;
107 DimensionT height_ = 0.0;
108 };
109
110 struct ExtraInfo {
111 uint32_t dataSize;
112 uint8_t* data;
113 };
114
115 struct SecCompClickEvent {
116 double touchX;
117 double touchY;
118 uint64_t timestamp;
119 ExtraInfo extraInfo;
120 };
121
122 struct SecCompPointEvent {
123 double touchX;
124 double touchY;
125 uint64_t timestamp;
126 };
127 } // namespace SecurityComponent
128 } // namespace Security
129 } // namespace OHOS
130 #endif // SECURITY_COMPONENT_INFO_H
131