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 #ifndef FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_COMMON_INCLUDE_BGTASKMGR_INNER_ERRORS_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_COMMON_INCLUDE_BGTASKMGR_INNER_ERRORS_H
18 
19 #include "errors.h"
20 #include <map>
21 
22 namespace OHOS {
23 namespace BackgroundTaskMgr {
24 /**
25  * ErrCode layout
26  *
27  * +--+--+--+--+--+--+--+--+---+---+
28  * |09|08|07|06|05|04|03|02| 01| 00|
29  * +--+--+--+--+--+--+--+--+---+---+
30  * | Syscap |      Code    |Subcode|
31  * +--+--+--+--+--+--+--+--+---+---+
32  */
33 const int OFFSET = 100;
34 const int THRESHOLD = 1000;
35 // Bgtask Common Error Code Defined.
36 enum : int32_t {
37     // errcode for common
38     ERR_BGTASK_PERMISSION_DENIED = 201,
39     ERR_BGTASK_NOT_SYSTEM_APP = 202,
40     ERR_BGTASK_INVALID_PARAM = 401,
41     // errcode for Continuous Task
42     ERR_BGTASK_NO_MEMORY = 980000101,
43     ERR_BGTASK_PARCELABLE_FAILED = 980000201,
44     ERR_BGTASK_TRANSACT_FAILED = 980000301,
45     ERR_BGTASK_SYS_NOT_READY = 980000401,
46     ERR_BGTASK_SERVICE_NOT_CONNECTED,
47     ERR_BGTASK_OBJECT_EXISTS = 980000501,
48     ERR_BGTASK_OBJECT_NOT_EXIST,
49     ERR_BGTASK_KEEPING_TASK_VERIFY_ERR,
50     ERR_BGTASK_INVALID_BGMODE,
51     ERR_BGTASK_NOTIFICATION_VERIFY_FAILED = 980000601,
52     ERR_BGTASK_NOTIFICATION_ERR,
53     ERR_BGTASK_CHECK_TASK_PARAM,
54     ERR_BGTASK_CREATE_FILE_ERR = 980000701,
55     ERR_BGTASK_GET_ACTUAL_FILE_ERR,
56     ERR_BGTASK_OPEN_FILE_ERR,
57     // errcode for Transient Task
58     ERR_BGTASK_INVALID_PID_OR_UID = 990000101,
59     ERR_BGTASK_INVALID_BUNDLE_NAME,
60     ERR_BGTASK_INVALID_REQUEST_ID,
61     ERR_BGTASK_INVALID_CALLBACK = 990000201,
62     ERR_BGTASK_CALLBACK_EXISTS,
63     ERR_BGTASK_CALLBACK_NOT_EXIST,
64     ERR_BGTASK_NOT_IN_PRESET_TIME,
65     ERR_BGTASK_EXCEEDS_THRESHOLD,
66     ERR_BGTASK_TIME_INSUFFICIENT,
67     ERR_BGTASK_NOREQUEST_TASK,
68     ERR_BGTASK_FOREGROUND,
69     // errcode for Efficiency Resource
70     ERR_BGTASK_RESOURCES_EXCEEDS_MAX = 1870000101,
71     ERR_BGTASK_RESOURCES_INVALID_PID_OR_UID,
72     // other inner errcode
73     ERR_BGTASK_METHOD_CALLED_FAILED,
74     ERR_BGTASK_DATA_STORAGE_ERR,
75     ERR_BGTASK_SERVICE_INNER_ERROR,
76     ERR_BGTASK_INVALID_PROCESS_NAME,
77 };
78 
79 enum ParamErr: int32_t {
80     ERR_PARAM_NUMBER_ERR = 9800401,
81     ERR_REASON_NULL_OR_TYPE_ERR,
82     ERR_CALLBACK_NULL_OR_TYPE_ERR,
83     ERR_REQUESTID_NULL_OR_ID_TYPE_ERR,
84     ERR_REQUESTID_ILLEGAL,
85     ERR_CONTEXT_NULL_OR_TYPE_ERR,
86     ERR_BGMODE_NULL_OR_TYPE_ERR,
87     ERR_WANTAGENT_NULL_OR_TYPE_ERR,
88     ERR_ABILITY_INFO_EMPTY,
89     ERR_GET_TOKEN_ERR,
90     ERR_BGMODE_RANGE_ERR,
91     ERR_APP_NAME_EMPTY,
92     ERR_RESOURCE_TYPES_INVALID,
93     ERR_ISAPPLY_NULL_OR_TYPE_ERR,
94     ERR_TIMEOUT_INVALID,
95     ERR_ISPERSIST_NULL_OR_TYPE_ERR,
96     ERR_ISPROCESS_NULL_OR_TYPE_ERR,
97 };
98 
99 const inline std::map<int32_t, std::string> saErrCodeMsgMap = {
100     {ERR_BGTASK_PERMISSION_DENIED, "Permission denied."},
101     {ERR_BGTASK_NOT_SYSTEM_APP,
102         "System API verification failed. Only system application can apply."},
103     {ERR_BGTASK_NO_MEMORY, "Memory operation failed. Failed to allocate the memory."},
104     {ERR_BGTASK_SYS_NOT_READY, "System service operation failed. The system service is not ready."},
105     {ERR_BGTASK_SERVICE_NOT_CONNECTED, "System service operation failed. The system service is not connected."},
106     {ERR_BGTASK_PARCELABLE_FAILED, "Parcel operation failed."},
107     {ERR_BGTASK_TRANSACT_FAILED, "Internal transaction failed."},
108     {ERR_BGTASK_OBJECT_EXISTS,
109         "Continuous Task verification failed. The application has applied for a continuous task."},
110     {ERR_BGTASK_OBJECT_NOT_EXIST,
111         "Continuous Task verification failed. The application has not applied for a continuous task."},
112     {ERR_BGTASK_KEEPING_TASK_VERIFY_ERR,
113         "Continuous Task verification failed. TASK_KEEPING background mode only supported in particular device."},
114     {ERR_BGTASK_INVALID_BGMODE, "Continuous Task verification failed. The bgMode is invalid."},
115     {ERR_BGTASK_NOTIFICATION_VERIFY_FAILED, "Notification verification failed for a continuous task."
116         " The title or text of the notification cannot be empty."},
117     {ERR_BGTASK_NOTIFICATION_ERR, "Notification verification failed. Failed to send or cancel the notification."},
118     {ERR_BGTASK_CREATE_FILE_ERR, "Continuous task storage failed. Failed to create the storage task file."},
119     {ERR_BGTASK_GET_ACTUAL_FILE_ERR, "Task storage failed. Failed to get the actual storage task file."},
120     {ERR_BGTASK_OPEN_FILE_ERR, "Task storage failed. Failed to open the file."},
121     {ERR_BGTASK_INVALID_PID_OR_UID,
122         "Caller information verification failed for a transient task. Invalid pid or uid."},
123     {ERR_BGTASK_INVALID_BUNDLE_NAME,
124         "Caller information verification failed for a transient task. The bundleName cannot be found."},
125     {ERR_BGTASK_INVALID_REQUEST_ID,
126         "Caller information verification failed for a transient task. Invalid requestId."},
127     {ERR_BGTASK_INVALID_CALLBACK,
128         "Transient task verification failed. The callback cannot be empty."},
129     {ERR_BGTASK_CALLBACK_EXISTS, "Transient task verification failed. The callback already exists."},
130     {ERR_BGTASK_CALLBACK_NOT_EXIST, "Transient task verification failed. The callback does not exist."},
131     {ERR_BGTASK_NOT_IN_PRESET_TIME,
132         "Transient task verification failed. Request is not allow after the preset time of entering background."},
133     {ERR_BGTASK_EXCEEDS_THRESHOLD, "Transient task verification failed. The number of request exceeds the threshold."},
134     {ERR_BGTASK_TIME_INSUFFICIENT,
135         "Transient task verification failed. The remaining time to run transient task is insufficient."},
136     {ERR_BGTASK_RESOURCES_EXCEEDS_MAX, "Caller information verification failed for an energy"
137         " resource request. The number of resources applied exceeds maximun."},
138     {ERR_BGTASK_SERVICE_INNER_ERROR, "Service inner error."},
139     {ERR_BGTASK_NOREQUEST_TASK, "Transient task verification failed. application no request transient task."},
140     {ERR_BGTASK_FOREGROUND, "Transient task verification failed. application is foreground."},
141     {ERR_BGTASK_INVALID_PROCESS_NAME, "Transient task verification failed. caller process name invaild."},
142 };
143 
144 const inline std::map<int32_t, std::string> paramErrCodeMsgMap = {
145     {ERR_PARAM_NUMBER_ERR, "The number of arguments is wrong."},
146     {ERR_REASON_NULL_OR_TYPE_ERR, "The reason cannot be null and its type must be string."},
147     {ERR_CALLBACK_NULL_OR_TYPE_ERR, "The callback cannot be null and its type must be function."},
148     {ERR_REQUESTID_NULL_OR_ID_TYPE_ERR, "The requestId cannot be null and its type must be integer."},
149     {ERR_REQUESTID_ILLEGAL, "The requestId must be greater than 0."},
150     {ERR_CONTEXT_NULL_OR_TYPE_ERR, "The context cannot be null and its type must be Context."},
151     {ERR_BGMODE_NULL_OR_TYPE_ERR, "The bgMode cannot be null and its type must be BackgroundMode object."},
152     {ERR_WANTAGENT_NULL_OR_TYPE_ERR, "The wantAgent cannot be null and its type must be WantAgent object."},
153     {ERR_ABILITY_INFO_EMPTY, "The abilityInfo of context cannot be null."},
154     {ERR_GET_TOKEN_ERR, "The token of context cannot be null."},
155     {ERR_BGMODE_RANGE_ERR, "The value of bgMode ranges from BG_MODE_ID_BEGIN to BG_MODE_ID_END."},
156     {ERR_APP_NAME_EMPTY, "The app name of abilityInfo in context cannot be null."},
157     {ERR_RESOURCE_TYPES_INVALID, "The resourcesType cannot be null and must be integer greater than 0."},
158     {ERR_ISAPPLY_NULL_OR_TYPE_ERR, "The isApply cannot be null and its type must be boolean."},
159     {ERR_TIMEOUT_INVALID, "The timeOut cannot be null and must be integer greater than 0."},
160     {ERR_ISPERSIST_NULL_OR_TYPE_ERR, "The isPersist cannot be null and must be boolean."},
161     {ERR_ISPROCESS_NULL_OR_TYPE_ERR, "The isProcess cannot be null and must be boolean."},
162     {ERR_BGTASK_INVALID_PARAM, "The input param is invalid."}
163 };
164 
165 }  // namespace BackgroundTaskMgr
166 }  // namespace OHOS
167 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_COMMON_INCLUDE_BGTASKMGR_INNER_ERRORS_H