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 #include <functional>
21 #include <string>
22
23 namespace OHOS {
24 namespace Security {
25 namespace SecurityComponent {
26 static constexpr int32_t INVALID_SC_ID = -1;
27 using DimensionT = double; // unit is vp
28 static constexpr DimensionT DEFAULT_DIMENSION = 0.0;
29 static constexpr DimensionT MIN_FONT_SIZE_WITHOUT_ICON = 12.0;
30 static constexpr DimensionT MIN_FONT_SIZE_WITH_ICON = 10.0;
31 static constexpr DimensionT MIN_ICON_SIZE = 12.0;
32 static constexpr DimensionT MIN_PADDING_SIZE = 0.0;
33 static constexpr DimensionT MIN_PADDING_WITHOUT_BG = 4.0;
34 static constexpr uint32_t MAX_EXTRA_SIZE = 0x1000;
35
36 static constexpr int32_t KEY_SPACE = 2050;
37 static constexpr int32_t KEY_ENTER = 2054;
38 static constexpr int32_t KEY_NUMPAD_ENTER = 2119;
39 using OnFirstUseDialogCloseFunc = std::function<void(int32_t)>;
40
41 struct PaddingSize {
42 DimensionT top = DEFAULT_DIMENSION;
43 DimensionT right = DEFAULT_DIMENSION;
44 DimensionT bottom = DEFAULT_DIMENSION;
45 DimensionT left = DEFAULT_DIMENSION;
46 };
47
48 struct BorderRadius {
49 DimensionT leftTop = DEFAULT_DIMENSION;
50 DimensionT rightTop = DEFAULT_DIMENSION;
51 DimensionT leftBottom = DEFAULT_DIMENSION;
52 DimensionT rightBottom = DEFAULT_DIMENSION;
53 };
54
55 enum SecCompType {
56 UNKNOWN_SC_TYPE = 0,
57 LOCATION_COMPONENT,
58 PASTE_COMPONENT,
59 SAVE_COMPONENT,
60 MAX_SC_TYPE
61 };
62
63 union SecCompColor {
64 struct {
65 uint8_t blue;
66 uint8_t green;
67 uint8_t red;
68 uint8_t alpha;
69 } argb;
70 uint32_t value;
71 };
72
73 enum CrossAxisState {
74 STATE_INVALID = 0,
75 STATE_CROSS,
76 STATE_NO_CROSS,
77 };
78
IsComponentTypeValid(int32_t type)79 inline bool IsComponentTypeValid(int32_t type)
80 {
81 return (type > UNKNOWN_SC_TYPE && type < MAX_SC_TYPE);
82 }
83
GreatOrEqual(double left,double right)84 inline bool GreatOrEqual(double left, double right)
85 {
86 constexpr double epsilon = -0.001;
87 return (left - right) > epsilon;
88 }
89
GreatNotEqual(double left,double right)90 inline bool GreatNotEqual(double left, double right)
91 {
92 constexpr double epsilon = 0.001;
93 return (left - right) > epsilon;
94 }
95
IsEqual(double left,double right)96 inline bool IsEqual(double left, double right)
97 {
98 constexpr double epsilon = 0.001;
99 if (left > right) {
100 return (left - right) < epsilon;
101 } else if (right > left) {
102 return (right - left) < epsilon;
103 } else {
104 return true;
105 }
106 }
107
108 class SecCompRect {
109 public:
110 SecCompRect() = default;
111 ~SecCompRect() = default;
112
IsInRect(double x,double y)113 bool IsInRect(double x, double y) const
114 {
115 return (GreatOrEqual(x, x_) && GreatOrEqual((x_ + width_), x) &&
116 GreatOrEqual(y, y_) && GreatOrEqual((y_ + height_), y));
117 };
118
119 bool operator==(const SecCompRect& other) const
120 {
121 return (IsEqual(x_, other.x_)) && (IsEqual(y_, other.y_)) &&
122 (IsEqual(width_, other.width_)) && (IsEqual(height_, other.height_));
123 }
124
125 DimensionT x_ = 0.0;
126 DimensionT y_ = 0.0;
127 DimensionT width_ = 0.0;
128 DimensionT height_ = 0.0;
129 BorderRadius borderRadius_;
130 };
131
132 struct ExtraInfo {
133 uint32_t dataSize;
134 uint8_t* data;
135 };
136
137 enum class ClickEventType : int32_t {
138 UNKNOWN_EVENT_TYPE,
139 POINT_EVENT_TYPE,
140 KEY_EVENT_TYPE
141 };
142
143 struct SecCompPointEvent {
144 double touchX;
145 double touchY;
146 uint64_t timestamp;
147 };
148
149 struct SecCompKeyEvent {
150 uint64_t timestamp;
151 int32_t keyCode;
152 };
153
154 struct SecCompClickEvent {
155 ClickEventType type;
156 union {
157 SecCompPointEvent point;
158 SecCompKeyEvent key;
159 };
160 ExtraInfo extraInfo;
161 };
162
163 struct SecCompInfo {
164 int32_t scId;
165 std::string componentInfo;
166 SecCompClickEvent clickInfo;
167 };
168 } // namespace SecurityComponent
169 } // namespace Security
170 } // namespace OHOS
171 #endif // SECURITY_COMPONENT_INFO_H
172