• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
79 enum TipPosition {
80     ABOVE_BOTTOM = 0,
81     BELOW_TOP,
82 };
83 
84 enum NotifyType {
85     DIALOG = 0,
86     TOAST,
87 };
88 
IsComponentTypeValid(int32_t type)89 inline bool IsComponentTypeValid(int32_t type)
90 {
91     return (type > UNKNOWN_SC_TYPE && type < MAX_SC_TYPE);
92 }
93 
GreatOrEqual(double left,double right)94 inline bool GreatOrEqual(double left, double right)
95 {
96     constexpr double epsilon = -0.001;
97     return (left - right) > epsilon;
98 }
99 
GreatNotEqual(double left,double right)100 inline bool GreatNotEqual(double left, double right)
101 {
102     constexpr double epsilon = 0.001;
103     return (left - right) > epsilon;
104 }
105 
IsEqual(double left,double right)106 inline bool IsEqual(double left, double right)
107 {
108     constexpr double epsilon = 0.001;
109     if (left > right) {
110         return (left - right) < epsilon;
111     } else if (right > left) {
112         return (right - left) < epsilon;
113     } else {
114         return true;
115     }
116 }
117 
118 class SecCompRect {
119 public:
120     SecCompRect() = default;
121     ~SecCompRect() = default;
122 
IsInRect(double x,double y)123     bool IsInRect(double x, double y) const
124     {
125         return (GreatOrEqual(x, x_ - 1.0) && GreatOrEqual((x_ + width_), x - 1.0) &&
126             GreatOrEqual(y, y_ - 1.0) && GreatOrEqual((y_ + height_), y - 1.0));
127     };
128 
129     bool operator==(const SecCompRect& other) const
130     {
131         return (IsEqual(x_, other.x_)) && (IsEqual(y_, other.y_)) &&
132             (IsEqual(width_, other.width_)) && (IsEqual(height_, other.height_));
133     }
134 
135     DimensionT x_ = 0.0;
136     DimensionT y_ = 0.0;
137     DimensionT width_ = 0.0;
138     DimensionT height_ = 0.0;
139     BorderRadius borderRadius_;
140 };
141 
142 struct ExtraInfo {
143     uint32_t dataSize;
144     uint8_t* data;
145 };
146 
147 enum class ClickEventType : int32_t {
148     UNKNOWN_EVENT_TYPE,
149     POINT_EVENT_TYPE,
150     KEY_EVENT_TYPE,
151     ACCESSIBILITY_EVENT_TYPE
152 };
153 
154 struct SecCompPointEvent {
155     double touchX;
156     double touchY;
157     uint64_t timestamp;
158 };
159 
160 struct SecCompKeyEvent {
161     uint64_t timestamp;
162     int32_t keyCode;
163 };
164 
165 struct SecCompAccessibilityEvent {
166     int64_t timestamp = 0;
167     int64_t componentId = 0;
168 };
169 
170 struct SecCompClickEvent {
171     ClickEventType type;
172     union {
173         SecCompPointEvent point;
174         SecCompKeyEvent key;
175         SecCompAccessibilityEvent accessibility;
176     };
177     ExtraInfo extraInfo;
178 };
179 
180 struct SecCompInfo {
181     int32_t scId;
182     std::string componentInfo;
183     SecCompClickEvent clickInfo;
184 };
185 }  // namespace SecurityComponent
186 }  // namespace Security
187 }  // namespace OHOS
188 #endif  // SECURITY_COMPONENT_INFO_H
189