1 /*
2  * Copyright (c) 2023 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_STANDBY_SERVICE_UTILS_INCLUDE_STANDBY_SERVICE_INNER_ERRORS_H
17 #define FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_UTILS_INCLUDE_STANDBY_SERVICE_INNER_ERRORS_H
18 
19 #include <map>
20 #include <string>
21 #include "errors.h"
22 
23 namespace OHOS {
24 namespace DevStandbyMgr {
25 /**
26  * ErrCode layout
27  *
28  * +--+--+--+--+--+--+--+--+---+---+
29  * |09|08|07|06|05|04|03|02| 01| 00|
30  * +--+--+--+--+--+--+--+--+---+---+
31  * | Syscap |      Code    |Subcode|
32  * +--+--+--+--+--+--+--+--+---+---+
33  */
34 const int OFFSET = 100;
35 const int THRESHOLD = 1000;
36 // StrandbyService Common Error Code Defined.
37 enum : int32_t {
38     // errcode for common
39     ERR_STANDBY_PERMISSION_DENIED = 201,
40     ERR_STANDBY_NOT_SYSTEM_APP = 202,
41     ERR_STANDBY_INVALID_PARAM = 401,
42 
43     ERR_STANDBY_NO_MEMORY = 980000101,
44     ERR_STANDBY_PARCELABLE_FAILED = 980000201,
45     ERR_STANDBY_TRANSACT_FAILED = 980000301,
46     ERR_STANDBY_SYS_NOT_READY = 980000401,
47     ERR_STANDBY_GET_SABILITY_FAILED,
48     ERR_STANDBY_SERVICE_NOT_CONNECTED,
49     ERR_STANDBY_DUMP_SAVE_DENIED,
50     ERR_STANDBY_OBJECT_EXISTS = 980000501,
51     ERR_STANDBY_OBJECT_NOT_EXIST,
52     ERR_STANDBY_CONFIG_FILE_LOAD_FAILED = 980000601,
53     ERR_STANDBY_CONFIG_FILE_PARSE_FAILED,
54 
55     ERR_STANDBY_OBSERVER_ALREADY_EXIST = 980000701,
56     ERR_STANDBY_OBSERVER_INIT_FAILED,
57     ERR_STANDBY_OBSERVER_RESET_FAILED,
58     ERR_REGISTER_BACKGROUND_TASK_FAILED,
59     ERR_UNREGISTER_BACKGROUND_TASK_FAILED,
60     ERR_BGTASK_LISTENER_NULL,
61 
62     ERR_STANDBY_PLUGIN_NOT_EXIST = 980000801,
63     ERR_STANDBY_PLUGIN_FUNC_NOT_EXIST,
64     ERR_STANDBY_PLUGIN_NOT_AVAILABLE,
65     ERR_STANDBY_PLUGIN_SINGLETON_NOT_EXIST,
66 
67     ERR_STATE_MANAGER_IS_NULLPTR = 980000901,
68     ERR_STANDBY_STATE_INIT_FAILED,
69     ERR_STANDBY_STATE_TRANSITION_FAILED,
70     ERR_INTER_STATE_CONSTRAINT_NOT_PERMIT,
71     ERR_STANDBY_STATAE_BLOCKED,
72     ERR_STANDBY_STATE_TIMING_SEQ_ERROR,
73     ERR_STANDBY_TIMER_SERVICE_ERROR,
74     ERR_STANDBY_TIMERID_NOT_EXIST,
75     ERR_STANDBY_CURRENT_STATE_NOT_MATCH,
76     ERR_STANDBY_CURRENT_PHASE_NOT_MATCH,
77     ERR_STANDBY_STRATEGY_STATE_REPEAT,
78     ERR_STANDBY_GET_PROCESSNAME_INFO,
79     ERR_STANDBY_STRATEGY_NOT_MATCH,
80     ERR_STANDBY_STRATEGY_NOT_DEPLOY,
81     ERR_STANDBY_START_LISENER_FAILED,
82     ERR_STANDBY_STOP_LISENER_FAILED,
83     ERR_STANDBY_START_SENSOR_FAILED,
84     ERR_STANDBY_SEND_NOTIFICATION_FAILED,
85     ERR_STANDBY_KEY_INFO_NOT_MATCH,
86     ERR_STANDBY_REPAET_INIT,
87 
88     ERR_STRATEGY_DEPENDS_SA_NOT_AVAILABLE = 980001001,
89     ERR_STANDBY_LOAD_DUMP_FAILED,
90     ERR_STANDBY_RESTRICTION_CONDITION_NOT_MATCH,
91     RR_DATASHARE_OBJECT_NULLPTR,
92     RR_DATASHARE_QUERY_FAILED,
93 };
94 
95 enum ParamErr: int32_t {
96     ERR_PARAM_NUMBER_ERR = 9800401,
97     ERR_CALLBACK_NULL_OR_TYPE_ERR,
98     ERR_REASON_NULL_OR_TYPE_ERR,
99     ERR_RESOURCE_TYPES_INVALID,
100     ERR_UID_INVALID,
101     ERR_NAME_INVALID_OR_EMPTY,
102     ERR_DURATION_INVALID,
103     ERR_REASON_INVALID_TYPE_ERR,
104 };
105 
106 inline std::map<int32_t, std::string> saErrCodeMsgMap = {
107     {ERR_STANDBY_PERMISSION_DENIED, "Permission denied."},
108     {ERR_STANDBY_NOT_SYSTEM_APP,
109         "System API verification failed."},
110     {ERR_STANDBY_NO_MEMORY, "Memory operation failed. Failed to allocate the memory."},
111     {ERR_STANDBY_PARCELABLE_FAILED, "Parcel operation failed."},
112     {ERR_STANDBY_TRANSACT_FAILED, "IPC failed."},
113     {ERR_STANDBY_SYS_NOT_READY, "System service operation failed. The system service is not ready."},
114     {ERR_STANDBY_SERVICE_NOT_CONNECTED, "System service operation failed. The system service is not connected."},
115     {ERR_STANDBY_OBJECT_EXISTS,
116         "Standby service verification failed. The application has subscribed standby callback."},
117     {ERR_STANDBY_CONFIG_FILE_LOAD_FAILED,
118         "Config file of standby service load failed, please check the path of the config file."},
119     {ERR_STANDBY_CONFIG_FILE_PARSE_FAILED,
120         "Config file of standby service load failed, please check the format and content of the config file."},
121     {ERR_STANDBY_PLUGIN_NOT_EXIST, "Plugin of standby service doesn't exist."},
122     {ERR_STANDBY_PLUGIN_FUNC_NOT_EXIST, "Export plugin function doesn't exist."},
123     {ERR_STANDBY_PLUGIN_NOT_AVAILABLE, "Plugin of standby service is not available."},
124     {ERR_STANDBY_PLUGIN_SINGLETON_NOT_EXIST, "The singleton object loaded from plugin doesn't exist."},
125     {ERR_STATE_MANAGER_IS_NULLPTR, "The state manager adapter can not be nullptr."},
126 };
127 
128 inline std::map<int32_t, std::string> paramErrCodeMsgMap = {
129     {ERR_STANDBY_INVALID_PARAM, "The input param is invalid."},
130     {ERR_PARAM_NUMBER_ERR, "The number of arguments is wrong."},
131     {ERR_CALLBACK_NULL_OR_TYPE_ERR, "The callback cannot be null and its type must be function."},
132     {ERR_RESOURCE_TYPES_INVALID, "The resourcesType cannot be null and must be integer greater than 0"\
133         "and less than maximum value."},
134     {ERR_UID_INVALID, "The uid can not less than 0"},
135     {ERR_NAME_INVALID_OR_EMPTY, "The name must be valid string and can not be empty"},
136     {ERR_DURATION_INVALID, "The duration must be valid integer and can not less than 0"},
137 
138     {ERR_REASON_INVALID_TYPE_ERR, "The reason cannot be null and its type must be string."},
139 };
140 }  // namespace DevStandbyMgr
141 }  // namespace OHOS
142 #endif  // FOUNDATION_RESOURCESCHEDULE_STANDBY_SERVICE_UTILS_INCLUDE_STANDBY_SERVICE_INNER_ERRORS_H