• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "account_error_no.h"
17 
18 namespace OHOS {
AppAccountConvertOtherJSErrCode(int32_t errCode)19 int32_t AppAccountConvertOtherJSErrCode(int32_t errCode)
20 {
21     switch (errCode) {
22         case ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST:
23         case ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID:
24             return ERR_JS_ACCOUNT_NOT_FOUND;
25         case ERR_APPACCOUNT_SERVICE_ADD_EXISTING_ACCOUNT:
26             return ERR_JS_ACCOUNT_ALREADY_EXIST;
27         case ERR_APPACCOUNT_SERVICE_ACCOUNT_MAX_SIZE:
28             return ERR_JS_ACCOUNT_NUMBER_REACH_LIMIT;
29         case ERR_APPACCOUNT_SUBSCRIBER_ALREADY_REGISTERED:
30             return ERR_JS_LISTENER_ALREADY_REGISTERED;
31         case ERR_APPACCOUNT_SERVICE_ASSOCIATED_DATA_OVER_SIZE:
32             return ERR_JS_CUSTOM_DATA_NUMBER_REACH_LIMIT;
33         case ERR_APPACCOUNT_SERVICE_ASSOCIATED_DATA_KEY_NOT_EXIST:
34             return ERR_JS_CUSTOM_DATA_NOT_FOUND;
35         case ERR_APPACCOUNT_SERVICE_ACCOUNT_CREDENTIAL_NOT_EXIST:
36             return ERR_JS_CREDENTIAL_NOT_EXIST;
37         case ERR_APPACCOUNT_KIT_NO_SPECIFIED_SUBSCRIBER_HAS_BEEN_REGISTERED:
38             return ERR_JS_LISTENER_NOT_REGISTERED;
39         case ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST:
40             return ERR_JS_ACCOUNT_AUTHENTICATOR_NOT_EXIST;
41         case ERR_APPACCOUNT_SERVICE_OAUTH_BUSY:
42             return ERR_JS_ACCOUNT_SERVICE_BUSY;
43         case ERR_APPACCOUNT_SERVICE_OAUTH_LIST_MAX_SIZE:
44             return ERR_JS_AUTHORIZATION_LIST_TOO_LARGE;
45         case ERR_APPACCOUNT_SERVICE_OAUTH_SESSION_NOT_EXIST:
46         case ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_CALLBACK_NOT_EXIST:
47             return ERR_JS_SESSION_NOT_EXIST;
48         case ERR_APPACCOUNT_SERVICE_OAUTH_TYPE_NOT_EXIST:
49         case ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST:
50             return ERR_JS_AUTH_TYPE_NOT_FOUND;
51         case ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_MAX_SIZE:
52             return ERR_JS_TOKEN_NUMBER_REACH_LIMIT;
53         default:
54             return ERR_JS_SYSTEM_SERVICE_EXCEPTION;
55     }
56 }
57 
AppAccountConvertToJSErrCode(int32_t errCode)58 int32_t AppAccountConvertToJSErrCode(int32_t errCode)
59 {
60     if ((errCode >= ERR_APPACCOUNT_KIT_NAME_IS_EMPTY && errCode <= ERR_APPACCOUNT_KIT_INVALID_PARAMETER) ||
61         (errCode >= ERR_APPACCOUNT_SERVICE_NAME_IS_EMPTY && errCode <= ERR_APPACCOUNT_SERVICE_INVALID_PARAMETER)) {
62         return ERR_JS_INVALID_PARAMETER;
63     } else if (errCode == ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED ||
64         errCode == ERR_APPACCOUNT_SERVICE_SUBSCRIBE_PERMISSION_DENIED) {
65         return ERR_JS_PERMISSION_DENIED;
66     } else if (errCode == ERR_APPACCOUNT_SERVICE_GET_BUNDLE_NAME ||
67         errCode == ERR_APPACCOUNT_SERVICE_GET_BUNDLE_INFO ||
68         errCode == ERR_APPACCOUNT_SERVICE_DISABLE_APP_ACCESS_NOT_EXISTED) {
69         return ERR_JS_APPLICATION_NOT_EXIST;
70     } else if (errCode == ERR_APPACCOUNT_SERVICE_AUTHENTICATOR_MANAGER_PTR_IS_NULLPTR ||
71         errCode == ERR_APPACCOUNT_SERVICE_OAUTH_SERVICE_EXCEPTION) {
72         return ERR_JS_ACCOUNT_AUTHENTICATOR_SERVICE_EXCEPTION;
73     } else {
74         return AppAccountConvertOtherJSErrCode(errCode);
75     }
76 }
77 
OsAccountConvertToJSErrCode(int32_t errCode)78 int32_t OsAccountConvertToJSErrCode(int32_t errCode)
79 {
80     if ((errCode >= ERR_OSACCOUNT_KIT_LOCAL_NAME_OUTFLOW_ERROR && errCode <= ERR_OSACCOUNT_KIT_TYPE_ERROR) ||
81         (errCode >= ERR_OSACCOUNT_SERVICE_MANAGER_NAME_SIZE_EMPTY_ERROR &&
82         errCode <= ERR_OSACCOUNT_SERVICE_MANAGER_DOMAIN_SIZE_OVERFLOW_ERROR)) {
83         return ERR_JS_INVALID_PARAMETER;
84     }
85     if (errCode == ERR_ACCOUNT_COMMON_INVALID_PARAMTER) {
86         return ERR_JS_INVALID_PARAMETER;
87     }
88     switch (errCode) {
89         case ERR_OSACCOUNT_SERVICE_CONTROL_SELECT_OS_ACCOUNT_ERROR:
90         case ERR_OSACCOUNT_SERVICE_INNER_CANNOT_FIND_OSACCOUNT_ERROR:
91         case ERR_OSACCOUNT_SERVICE_INNER_SELECT_OSACCOUNT_BYID_ERROR:
92             return ERR_JS_ACCOUNT_NOT_FOUND;
93         case ERR_OSACCOUNT_SERVICE_INNER_DOMAIN_ALREADY_BIND_ERROR:
94             return ERR_JS_ACCOUNT_ALREADY_EXIST;
95         case ERR_OSACCOUNT_SERVICE_INNER_ACCOUNT_ALREADY_ACTIVE_ERROR:
96             return ERR_JS_ACCOUNT_ALREADY_ACTIVATED;
97         case ERR_OSACCOUNT_SERVICE_CONTROL_MAX_CAN_CREATE_ERROR:
98             return ERR_JS_ACCOUNT_NUMBER_REACH_LIMIT;
99         case ERR_OSACCOUNT_SERVICE_MANAGER_NOT_ENABLE_MULTI_ERROR:
100             return ERR_JS_MULTI_USER_NOT_SUPPORT;
101         case ERR_OSACCOUNT_SERVICE_MANAGER_CREATE_OSACCOUNT_TYPE_ERROR:
102             return ERR_JS_ACCOUNT_TYPE_NOT_SUPPORT;
103         case ERR_OSACCOUNT_SERVICE_MANAGER_ID_ERROR:
104         case ERR_OSACCOUNT_SERVICE_CONTROL_CANNOT_DELETE_ID_ERROR:
105         case ERR_OSACCOUNT_SERVICE_CONTROL_ID_CANNOT_CREATE_ERROR:
106             return ERR_JS_ACCOUNT_RESTRICTED;
107         case ERR_OSACCOUNT_SERVICE_MANAGER_PHOTO_SIZE_OVERFLOW_ERROR:
108         case ERR_OSACCOUNT_KIT_PHOTO_OUTFLOW_ERROR:
109         case ERR_OSACCOUNT_SERVICE_CONTROL_PHOTO_STR_ERROR:
110         case ERR_OSACCOUNT_SERVICE_MANAGER_BAD_UID_ERROR:
111             return ERR_JS_INVALID_PARAMETER;
112         case ERR_OSACCOUNT_KIT_NO_SPECIFIED_SUBSCRIBER_HAS_BEEN_REGISTERED:
113             return ERR_JS_LISTENER_NOT_REGISTERED;
114         case ERR_OSACCOUNT_SERVICE_PERMISSION_DENIED:
115             return ERR_JS_PERMISSION_DENIED;
116         default:
117             return ERR_JS_SYSTEM_SERVICE_EXCEPTION;
118     }
119 }
120 
DomainAccountConvertToJSErrCode(int32_t errCode)121 static int32_t DomainAccountConvertToJSErrCode(int32_t errCode)
122 {
123     switch (errCode) {
124         case ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_ALREADY_EXIST:
125             return ERR_JS_DOMAIN_PLUGIN_ALREADY_REGISTERED;
126         default:
127             return ERR_JS_SYSTEM_SERVICE_EXCEPTION;
128     }
129 }
130 
IsAppAccountKitError(int32_t errCode)131 static bool IsAppAccountKitError(int32_t errCode)
132 {
133     return (errCode >= ERR_APPACCOUNT_KIT_GET_SYSTEM_ABILITY_MANAGER &&
134         errCode <= ERR_APPACCOUNT_KIT_READ_PARCELABLE_VECTOR_ACCOUNT_INFO);
135 }
136 
IsAppAccountServiceError(int32_t errCode)137 static bool IsAppAccountServiceError(int32_t errCode)
138 {
139     return (errCode >= ERR_APPACCOUNT_SERVICE_NAME_IS_EMPTY && errCode <= ERR_APPACCOUNT_SERVICE_OTHER);
140 }
141 
IsOsAccountKitError(int32_t errCode)142 static bool IsOsAccountKitError(int32_t errCode)
143 {
144     return (errCode >= ERR_OSACCOUNT_KIT_WRITE_LOCALNAME_ERROR &&
145         errCode <= ERR_OSACCOUNT_KIT_QUERY_ACTIVE_OS_ACCOUNT_IDS_ERROR);
146 }
147 
IsOsAccountServiceError(int32_t errCode)148 static bool IsOsAccountServiceError(int32_t errCode)
149 {
150     return (errCode >= ERR_OSACCOUNT_SERVICE_MANAGER_BAD_UID_ERROR &&
151         errCode <= ERR_OSACCOUNT_SERVICE_GET_DATA_FROM_SPECIFIC_CONSTRAINTS_FILE_EMPTY);
152 }
153 
IsDomainAccountServiceError(int32_t errCode)154 static bool IsDomainAccountServiceError(int32_t errCode)
155 {
156     return (errCode >= ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_ALREADY_EXIST) &&
157         (errCode <= ERR_DOMAIN_ACCOUNT_SERVICE_PLUGIN_NOT_EXIST);
158 }
159 
ConvertToJSErrCode(int32_t nativeErrCode)160 int32_t ConvertToJSErrCode(int32_t nativeErrCode)
161 {
162     if (nativeErrCode == ERR_OK) {
163         return ERR_JS_SUCCESS;
164     }
165     if (nativeErrCode == ERR_ACCOUNT_COMMON_INVALID_PARAMTER) {
166         return ERR_JS_INVALID_PARAMETER;
167     }
168     if (IsAppAccountKitError(nativeErrCode) || IsAppAccountServiceError(nativeErrCode)) {
169         return AppAccountConvertToJSErrCode(nativeErrCode);
170     } else if (IsOsAccountKitError(nativeErrCode) || IsOsAccountServiceError(nativeErrCode)) {
171         return OsAccountConvertToJSErrCode(nativeErrCode);
172     } else if (IsDomainAccountServiceError(nativeErrCode)) {
173         return DomainAccountConvertToJSErrCode(nativeErrCode);
174     } else if (nativeErrCode == ERR_ACCOUNT_ZIDL_CHECK_PERMISSION_ERROR) {
175         return ERR_JS_PERMISSION_DENIED;
176     } else {
177         return ERR_JS_SYSTEM_SERVICE_EXCEPTION;
178     }
179 }
180 }  // namespace OHOS