• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 OHOS_USERAUTH_COMMON_H
17 #define OHOS_USERAUTH_COMMON_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "napi/native_api.h"
24 #include "napi/native_common.h"
25 
26 #include "iam_common_defines.h"
27 
28 namespace OHOS {
29 namespace UserIam {
30 namespace UserAuth {
31 constexpr size_t ARGS_ZERO = 0;
32 constexpr size_t ARGS_ONE = 1;
33 constexpr size_t ARGS_TWO = 2;
34 constexpr size_t ARGS_THREE = 3;
35 constexpr size_t ARGS_FOUR = 4;
36 
37 constexpr size_t PARAM0 = 0;
38 constexpr size_t PARAM1 = 1;
39 constexpr size_t PARAM2 = 2;
40 constexpr size_t PARAM3 = 3;
41 
42 constexpr int32_t API_VERSION_6 = 6;
43 constexpr int32_t API_VERSION_8 = 8;
44 constexpr int32_t API_VERSION_9 = 9;
45 constexpr int32_t API_VERSION_10 = 10;
46 constexpr int32_t API_VERSION_12 = 12;
47 
48 constexpr const char *NOTICE_EVENT_AUTH_READY = "EVENT_AUTH_TYPE_READY";
49 constexpr const char *NOTICE_EVENT_CANCEL_AUTH = "EVENT_AUTH_USER_CANCEL";
50 constexpr const char *NOTICE_EVENT_USER_NAVIGATION = "EVENT_AUTH_USER_NAVIGATION";
51 constexpr const char *NOTICE_EVENT_WIDGET_PARA_INVALID = "EVENT_AUTH_WIDGET_PARA_INVALID";
52 constexpr const char *NOTICE_EVENT_END = "EVENT_AUTH_END";
53 constexpr const char *NOTICE_EVENT_RELOAD = "EVENT_AUTH_RELOAD";
54 constexpr const char *NOTICE_EVENT_AUTH_WIDGET_LOADED = "EVENT_AUTH_WIDGET_LOADED";
55 constexpr const char *NOTICE_EVENT_AUTH_WIDGET_RELEASED = "EVENT_AUTH_WIDGET_RELEASED";
56 constexpr const char *NOTICE_EVENT_PROCESS_TERMINATE = "EVENT_AUTH_PROCESS_TERMINATE";
57 constexpr const char *NOTICE_EVENT_AUTH_SEND_TIP = "EVENT_AUTH_SEND_TIP";
58 
59 // For API6
60 enum class AuthenticationResult : int32_t {
61     NO_SUPPORT = -1,
62     SUCCESS = 0,
63     COMPARE_FAILURE = 1,
64     CANCELED = 2,
65     TIMEOUT = 3,
66     CAMERA_FAIL = 4,
67     BUSY = 5,
68     INVALID_PARAMETERS = 6,
69     LOCKED = 7,
70     NOT_ENROLLED = 8,
71     GENERAL_ERROR = 100,
72 };
73 
74 enum class UserAuthResultCode : int32_t {
75     OHOS_CHECK_PERMISSION_FAILED = 201,
76     OHOS_CHECK_SYSTEM_APP_FAILED = 202,
77     OHOS_INVALID_PARAM = 401,
78     RESULT_CODE_V9_MIN = 12500000,
79     RESULT_CODE_V10_MIN = 12500000,
80     RESULT_CODE_V16_MIN = 12500000,
81     SUCCESS = 12500000,
82     FAIL = 12500001,
83     GENERAL_ERROR = 12500002,
84     CANCELED = 12500003,
85     TIMEOUT = 12500004,
86     TYPE_NOT_SUPPORT = 12500005,
87     TRUST_LEVEL_NOT_SUPPORT = 12500006,
88     BUSY = 12500007,
89     PARAM_VERIFIED_FAILED = 12500008,
90     LOCKED = 12500009,
91     NOT_ENROLLED = 12500010,
92     RESULT_CODE_V9_MAX = 12500010,
93     CANCELED_FROM_WIDGET = 12500011,
94     PIN_EXPIRED = 12500013,
95     RESULT_CODE_V10_MAX = 12500013,
96     AUTH_TOKEN_CHECK_FAILED = 12500015,
97     AUTH_TOKEN_EXPIRED = 12500016,
98     REUSE_AUTH_RESULT_FAILED = 12500017,
99     RESULT_CODE_V16_MAX = 12500017,
100 };
101 
102 enum FaceTipsCode {
103     FACE_AUTH_TIP_TOO_BRIGHT = 1,
104     FACE_AUTH_TIP_TOO_DARK = 2,
105     FACE_AUTH_TIP_TOO_CLOSE = 3,
106     FACE_AUTH_TIP_TOO_FAR = 4,
107     FACE_AUTH_TIP_TOO_HIGH = 5,
108     FACE_AUTH_TIP_TOO_LOW = 6,
109     FACE_AUTH_TIP_TOO_RIGHT = 7,
110     FACE_AUTH_TIP_TOO_LEFT = 8,
111     FACE_AUTH_TIP_TOO_MUCH_MOTION = 9,
112     FACE_AUTH_TIP_POOR_GAZE = 10,
113     FACE_AUTH_TIP_NOT_DETECTED = 11,
114     FACE_AUTH_TIP_MAX = FACE_AUTH_TIP_NOT_DETECTED,
115 };
116 
117 enum FingerprintTips {
118     FINGERPRINT_AUTH_TIP_GOOD = 0,
119     FINGERPRINT_AUTH_TIP_IMAGER_DIRTY = 1,
120     FINGERPRINT_AUTH_TIP_INSUFFICIENT = 2,
121     FINGERPRINT_AUTH_TIP_PARTIAL = 3,
122     FINGERPRINT_AUTH_TIP_TOO_FAST = 4,
123     FINGERPRINT_AUTH_TIP_TOO_SLOW = 5,
124     FINGERPRINT_AUTH_TIP_MAX = FINGERPRINT_AUTH_TIP_TOO_SLOW,
125 };
126 
127 enum UserAuthTipCode {
128     TIP_CODE_FAIL = 1,
129     TIP_CODE_TIMEOUT = 2,
130     TIP_CODE_TEMPORARILY_LOCKED = 3,
131     TIP_CODE_PERMANENTLY_LOCKED = 4,
132     TIP_CODE_WIDGET_LOADED = 5,
133     TIP_CODE_WIDGET_RELEASED = 6,
134     TIP_CODE_COMPARE_FAIL_WITH_FROZEN = 7,
135 };
136 
137 const std::map<UserAuthResultCode, std::string> g_resultV92Str = {
138     {UserAuthResultCode::OHOS_INVALID_PARAM, "Parameter error."},
139     {UserAuthResultCode::OHOS_CHECK_PERMISSION_FAILED, "Permission denied."},
140     {UserAuthResultCode::OHOS_CHECK_SYSTEM_APP_FAILED, "Permission denied. Called by non-system application."},
141     {UserAuthResultCode::SUCCESS, "Authentication succeeded."},
142     {UserAuthResultCode::FAIL, "Authentication failed."},
143     {UserAuthResultCode::GENERAL_ERROR, "Unknown errors."},
144     {UserAuthResultCode::CANCELED, "Authentication canceled."},
145     {UserAuthResultCode::TIMEOUT, "Authentication timeout."},
146     {UserAuthResultCode::TYPE_NOT_SUPPORT, "Unsupport authentication type."},
147     {UserAuthResultCode::TRUST_LEVEL_NOT_SUPPORT, "Unsupport authentication trust level."},
148     {UserAuthResultCode::BUSY, "Authentication service is busy."},
149     {UserAuthResultCode::PARAM_VERIFIED_FAILED, "The parameter is out of range."},
150     {UserAuthResultCode::LOCKED, "Authentication is lockout."},
151     {UserAuthResultCode::NOT_ENROLLED, "Authentication template has not been enrolled."},
152     {UserAuthResultCode::CANCELED_FROM_WIDGET, "Authentication is canceled from widget."},
153     {UserAuthResultCode::PIN_EXPIRED, "Operation failed because of PIN expired."},
154     {UserAuthResultCode::AUTH_TOKEN_CHECK_FAILED, "Operation failed because of authToken integrity check failed."},
155     {UserAuthResultCode::AUTH_TOKEN_EXPIRED, "Operation failed because of authToken has expired."},
156     {UserAuthResultCode::REUSE_AUTH_RESULT_FAILED, "Failed to reuse authentication result."}
157 };
158 } // namespace UserAuth
159 } // namespace UserIam
160 } // namespace OHOS
161 #endif /* OHOS_USERAUTH_COMMON_H */
162