• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "ability_business_error_utils.h"
17 
18 #include <unordered_map>
19 
20 #include "ability_manager_errors.h"
21 #include "hilog_tag_wrapper.h"
22 
23 std::unordered_map<int32_t, AbilityRuntime_ErrorCode> g_innerToBusinessErrorCommonMap {
24     { OHOS::ERR_OK, ABILITY_RUNTIME_ERROR_CODE_NO_ERROR },
25     { OHOS::AAFwk::CHECK_PERMISSION_FAILED, ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED },
26     { OHOS::ERR_PERMISSION_DENIED, ABILITY_RUNTIME_ERROR_CODE_PERMISSION_DENIED },
27     { OHOS::AAFwk::ERR_CAPABILITY_NOT_SUPPORT, ABILITY_RUNTIME_ERROR_CODE_NOT_SUPPORTED },
28     { OHOS::AAFwk::RESOLVE_ABILITY_ERR, ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY },
29     { OHOS::AAFwk::TARGET_BUNDLE_NOT_EXIST, ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY },
30     { OHOS::AAFwk::ERR_NOT_ALLOW_IMPLICIT_START, ABILITY_RUNTIME_ERROR_CODE_NO_SUCH_ABILITY },
31     { OHOS::AAFwk::ERR_WRONG_INTERFACE_CALL, ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE },
32     { OHOS::AAFwk::TARGET_ABILITY_NOT_SERVICE, ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE },
33     { OHOS::AAFwk::RESOLVE_CALL_ABILITY_TYPE_ERR, ABILITY_RUNTIME_ERROR_CODE_INCORRECT_ABILITY_TYPE },
34     { OHOS::AAFwk::ERR_CROWDTEST_EXPIRED, ABILITY_RUNTIME_ERROR_CODE_CROWDTEST_EXPIRED },
35     { OHOS::ERR_WOULD_BLOCK, ABILITY_RUNTIME_ERROR_CODE_WUKONG_MODE },
36     { OHOS::AAFwk::ERR_APP_CONTROLLED, ABILITY_RUNTIME_ERROR_CODE_CONTROLLED },
37     { OHOS::AAFwk::ERR_EDM_APP_CONTROLLED, ABILITY_RUNTIME_ERROR_CODE_EDM_CONTROLLED },
38     { OHOS::AAFwk::ERR_START_OTHER_APP_FAILED, ABILITY_RUNTIME_ERROR_CODE_CROSS_APP },
39     { OHOS::AAFwk::NOT_TOP_ABILITY, ABILITY_RUNTIME_ERROR_CODE_NOT_TOP_ABILITY },
40     { OHOS::AAFwk::ERR_START_OPTIONS_CHECK_FAILED, ABILITY_RUNTIME_ERROR_VISIBILITY_SETTING_DISABLED },
41     { OHOS::AAFwk::ERR_UPPER_LIMIT, ABILITY_RUNTIME_ERROR_CODE_UPPER_LIMIT_REACHED },
42     { OHOS::AAFwk::ERR_APP_INSTANCE_KEY_NOT_SUPPORT, ABILITY_RUNTIME_ERROR_CODE_APP_INSTANCE_KEY_NOT_SUPPORTED },
43     { OHOS::AAFwk::ERR_NOT_SELF_APPLICATION, ABILITY_RUNTIME_ERROR_CODE_CROSS_APP },
44     };
45 
46 std::unordered_map<int32_t, AbilityRuntime_ErrorCode> g_innerToBusinessErrorApi18Map {
47 { OHOS::AAFwk::ERR_MULTI_APP_NOT_SUPPORTED, ABILITY_RUNTIME_ERROR_CODE_MULTI_APP_NOT_SUPPORTED },
48 { OHOS::AAFwk::ERR_INVALID_APP_INSTANCE_KEY, ABILITY_RUNTIME_ERROR_CODE_INVALID_APP_INSTANCE_KEY },
49 { OHOS::AAFwk::ERR_MULTI_INSTANCE_NOT_SUPPORTED, ABILITY_RUNTIME_ERROR_MULTI_INSTANCE_NOT_SUPPORTED },
50 };
51 
ConvertToCommonBusinessErrorCode(int32_t abilityManagerErrorCode)52 AbilityRuntime_ErrorCode ConvertToCommonBusinessErrorCode(int32_t abilityManagerErrorCode)
53 {
54     TAG_LOGI(AAFwkTag::APPKIT, "ability errCode:%{public}d", abilityManagerErrorCode);
55     auto it = g_innerToBusinessErrorCommonMap.find(abilityManagerErrorCode);
56     if (it != g_innerToBusinessErrorCommonMap.end()) {
57         return it->second;
58     }
59 
60     return ABILITY_RUNTIME_ERROR_CODE_INTERNAL;
61 }
62 
ConvertToAPI18BusinessErrorCode(int32_t abilityManagerErrorCode)63 AbilityRuntime_ErrorCode ConvertToAPI18BusinessErrorCode(int32_t abilityManagerErrorCode)
64 {
65     TAG_LOGI(AAFwkTag::APPKIT, "ability errCode:%{public}d", abilityManagerErrorCode);
66     auto errCode = ConvertToCommonBusinessErrorCode(abilityManagerErrorCode);
67     if (errCode != ABILITY_RUNTIME_ERROR_CODE_INTERNAL) {
68         return errCode;
69     }
70 
71     auto it = g_innerToBusinessErrorApi18Map.find(abilityManagerErrorCode);
72     if (it != g_innerToBusinessErrorApi18Map.end()) {
73         return it->second;
74     }
75 
76     return ABILITY_RUNTIME_ERROR_CODE_INTERNAL;
77 }
78