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