1 /* 2 * Copyright (c) 2025 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 INTERFACES_ETS_ANI_COMMON_ANI_ERROR_H 17 #define INTERFACES_ETS_ANI_COMMON_ANI_ERROR_H 18 19 #include <ani.h> 20 #include <string> 21 #include "access_token.h" 22 23 namespace OHOS { 24 namespace Security { 25 namespace AccessToken { 26 typedef enum { 27 STS_OK = 0, 28 STS_ERROR_PERMISSION_DENIED = 201, 29 STS_ERROR_NOT_SYSTEM_APP = 202, 30 STS_ERROR_PARAM_ILLEGAL = 401, 31 STS_ERROR_SYSTEM_CAPABILITY_NOT_SUPPORT = 801, 32 STS_ERROR_START_ABILITY_FAIL = 1011, 33 STS_ERROR_BACKGROUND_FAIL = 1012, 34 STS_ERROR_TERMINATE_FAIL = 1013, 35 STS_ERROR_PARAM_INVALID = 12100001, 36 STS_ERROR_TOKENID_NOT_EXIST, 37 STS_ERROR_PERMISSION_NOT_EXIST, 38 STS_ERROR_NOT_USE_TOGETHER, 39 STS_ERROR_REGISTERS_EXCEED_LIMITATION, 40 STS_ERROR_PERMISSION_OPERATION_NOT_ALLOWED, 41 STS_ERROR_SERVICE_NOT_RUNNING, 42 STS_ERROR_OUT_OF_MEMORY, 43 STS_ERROR_INNER, 44 STS_ERROR_REQUEST_IS_ALREADY_EXIST = 12100010, 45 STS_ERROR_ALL_PERM_GRANTED = 12100011, 46 STS_ERROR_PERM_NOT_REVOKE_BY_USER = 12100012, 47 STS_ERROR_GLOBAL_SWITCH_IS_ALREADY_OPEN = 12100013, 48 } STSErrorCode; 49 50 struct AtmResult { 51 int32_t errorCode = 0; 52 std::string errorMsg = ""; 53 }; 54 55 std::string GetParamErrorMsg(const std::string& param, const std::string& errMsg); 56 std::string GetErrorMessage(int32_t errCode, const std::string& extendMsg = ""); 57 class BusinessErrorAni { 58 public: 59 static ani_object CreateError(ani_env* env, ani_int code, const std::string& msg); 60 static void ThrowParameterTypeError(ani_env* env, int32_t err, const std::string& errMsg); 61 static void ThrowError(ani_env* env, int32_t err, const std::string& errMsg = ""); 62 static int32_t GetStsErrorCode(int32_t errCode); 63 static bool ValidateTokenIDWithThrowError(ani_env* env, AccessTokenID tokenID); 64 static bool ValidatePermissionWithThrowError(ani_env* env, const std::string& permission); 65 static bool ValidatePermissionFlagWithThrowError(ani_env* env, uint32_t flag); 66 67 private: 68 static void ThrowError(ani_env* env, ani_object err); 69 }; 70 } // namespace AccessToken 71 } // namespace Security 72 } // namespace OHOS 73 #endif /* INTERFACES_ETS_ANI_COMMON_ANI_ERROR_H */ 74