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_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_INNER_ERRORS_H
17 #define FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_INNER_ERRORS_H
18 
19 #include "errors.h"
20 
21 namespace OHOS {
22 namespace DeviceUsageStats {
23 /**
24  * ErrCode layout
25  *
26  * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
27  * | Bit |31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|09|08|07|06|05|04|03|02|01|00|
28  * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
29  * |Field|Reserved|        Subsystem      |  Module      |                              Code             |
30  * +-----+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
31  */
32 
33 // DeviceUsageStats's module const defined.
34 enum : int32_t {
35     DEVICE_USAGE_STATS_MODULE_COMMON = 0x01,
36 };
37 
38 // Offset of device usage stats sub-system's errCode base, number : 39911424.
39 constexpr ErrCode DEVICE_USAGE_STATS_COMMON_ERR_OFFSET =
40     ErrCodeOffset(SUBSYS_IAWARE, DEVICE_USAGE_STATS_MODULE_COMMON);
41 // Device Usage Stats Common Error Code Defined.
42 enum : int32_t {
43     ERR_USAGE_STATS_BUNDLENAME_EMPTY = DEVICE_USAGE_STATS_COMMON_ERR_OFFSET + 1,
44     ERR_USAGE_STATS_BUNDLENAME_TYPE,
45     ERR_USAGE_STATS_ASYNC_CALLBACK_NULLPTR,
46     ERR_USAGE_STATS_ASYNC_CALLBACK_INIT_FAILED,
47     ERR_USAGE_STATS_BEGIN_TIME_INVALID,
48     ERR_USAGE_STATS_END_TIME_INVALID,
49     ERR_USAGE_STATS_TIME_INTERVAL,
50     ERR_USAGE_STATS_INTERVAL_TYPE,
51     ERR_USAGE_STATS_INTERVAL_NUMBER,
52     ERR_SERVICE_FAILED,
53     ERR_USAGE_STATS_METHOD_CALLED_FAILED,
54     ERR_USAGE_STATS_INVALID_PARAM,
55 };
56 
57 enum {
58     ERR_PERMISSION_DENIED = 201,
59     ERR_NOT_SYSTEM_APP = 202,
60     ERR_PARAM_ERROR = 401,
61     ERR_MEMORY_OPERATION_FAILED = 10000001,
62     ERR_PARCEL_WRITE_FALIED,
63     ERR_SYSTEM_SERVICE_OPERATION_FAILED,
64     ERR_IPC_COMMUNICATION_FAILED,
65     ERR_APPLICATION_IS_NOT_INSTALLED,
66     ERR_GET_APPLICATION_INFO_FAILED,
67     ERR_TIME_OPERATION_FAILED,
68     ERR_APPLICATION_GROUP_OPERATION_REPEATED = 10100001,
69     ERR_NO_APP_GROUP_INFO_IN_DATABASE,
70 };
71 
72 enum ParamError {
73     ERR_PARAMETERS_NUMBER = 401001,
74     ERR_CALL_BACK_TYPE,
75     ERR_PARAMETERS_EMPTY,
76     ERR_BUNDLE_NAME_TYPE,
77     ERR_BEGIN_TIME_TYPE,
78     ERR_BEGIN_TIME_LESS_THEN_ZERO,
79     ERR_END_TIME_TYPE,
80     ERR_END_TIME_LESS_THEN_BEGIN_TIME,
81     ERR_INTERVAL_TYPE,
82     ERR_INTERVAL_OUT_OF_RANGE,
83     ERR_NEW_GROUP_TYPE,
84     ERR_NEW_GROUP_OUT_OF_RANGE,
85     ERR_MAX_RECORDS_NUM_TYPE,
86     ERR_MAX_RECORDS_NUM_BIGER_THEN_ONE_THOUSAND,
87     ERR_APP_GROUP_OBSERVER_CALLBACK_TYPE,
88     ERR_REPEAT_REGISTER_APP_GROUP_OBSERVER,
89     ERR_APP_GROUP_OBSERVER_IS_NULLPTR,
90     ERR_ASYNC_CALLBACK_NULLPTR,
91     ERR_ASYNC_CALLBACK_INIT_FAILED,
92 };
93 
94 enum ServiceError {
95     ERR_GET_SYSTEM_ABILITY_MANAGER_FAILED = 1000000301,
96     ERR_GET_SYSTEM_ABILITY_FAILED,
97     ERR_CHECK_SYSTEM_ABILITY_FAILED,
98     ERR_SYSTEM_SERVICES_NOT_READY,
99     ERR_REMOTE_OBJECT_IF_CAST_FAILED,
100     ERR_SYSTEM_ABILITY_SUPPORT_FAILED,
101     ERR_FIND_APP_USAGE_RECORDS_FAILED = 1000000601,
102     ERR_NO_RECORDS_INFO_BY_INTERVAL,
103     ERR_QUERY_TIME_OUT_OF_RANGE,
104     ERR_GET_BUNDLE_USED_HISTORY_FAILED,
105     ERR_QUERY_RESULT_TOO_LARGE,
106     ERR_REPEAT_REGISTER_OR_DEREGISTER_GROUP_CALLBACK = 1010000101,
107     ERR_REPEAT_SET_APP_GROUP,
108 };
109 
110 const inline std::map<int32_t, std::string> saErrCodeMsgMap = {
111     {ERR_PERMISSION_DENIED, "Permission denied."},
112     {ERR_NOT_SYSTEM_APP, "Not system app."},
113     {ERR_MEMORY_OPERATION_FAILED, "Memory operation failed. create object failed."},
114     {ERR_PARCEL_WRITE_FALIED, "Parcel operation failed. Failed to write the parcel."},
115     {ERR_GET_SYSTEM_ABILITY_MANAGER_FAILED, "System service operation failed. Failed to get system ability manager."},
116     {ERR_GET_SYSTEM_ABILITY_FAILED, "System service operation failed. Failed to get system ability manager."},
117     {ERR_CHECK_SYSTEM_ABILITY_FAILED, "System service operation failed. Failed to get system ability."},
118     {ERR_SYSTEM_SERVICES_NOT_READY, "System service operation failed. The service is not ready."},
119     {ERR_REMOTE_OBJECT_IF_CAST_FAILED, "System service operation failed. The remote object if cast failed."},
120     {ERR_SYSTEM_ABILITY_SUPPORT_FAILED, "System service operation failed. System ability support failed."},
121     {ERR_IPC_COMMUNICATION_FAILED, "IPC failed. Failed to access the system service."},
122     {ERR_APPLICATION_IS_NOT_INSTALLED, "The application is not installed. Failed to operation the application."},
123     {ERR_FIND_APP_USAGE_RECORDS_FAILED, "Failed to get the application information. Cannot find app usage records."},
124     {ERR_NO_RECORDS_INFO_BY_INTERVAL, "Failed to get the application information."
125         "According to inetrvalType. no information is recorded in the related table."},
126     {ERR_QUERY_TIME_OUT_OF_RANGE,
127         "Failed to get the application information. According to beginTime and endTime. no information is recorded"},
128     {ERR_QUERY_RESULT_TOO_LARGE,
129         "Query events max size is 100000, Query package stats max result size is 1000."
130         "Query result is too large, please narrow query time span."},
131     {ERR_GET_BUNDLE_USED_HISTORY_FAILED,
132         "Failed to get the application information. According to userId、bundleName, no information is recorded"},
133     {ERR_TIME_OPERATION_FAILED, "Get system or actual time operation failed."},
134     {ERR_REPEAT_REGISTER_OR_DEREGISTER_GROUP_CALLBACK, "Repeated operation on the application group."
135         "Repeat to register or deregister, an interception application group"},
136     {ERR_REPEAT_SET_APP_GROUP, "Repeated operation on the application group."
137         "The application group are the the same and do not need te be updated."},
138     {ERR_NO_APP_GROUP_INFO_IN_DATABASE,
139         "Failed to get the application group information. The application group infomation cannot be found."},
140 };
141 
142 const inline std::map<int32_t, std::string> paramErrCodeMsgMap = {
143     {ERR_PARAMETERS_NUMBER, " api interface parameters count is error."},
144     {ERR_PARAMETERS_EMPTY, " cannot be empty."},
145     {ERR_CALL_BACK_TYPE, " Callback type must be function."},
146     {ERR_BUNDLE_NAME_TYPE, "The type of bundleName must be string."},
147     {ERR_BEGIN_TIME_TYPE, "The type of beginTime must be int64."},
148     {ERR_BEGIN_TIME_LESS_THEN_ZERO, "The beginTime value must be greater than or equal to 0."},
149     {ERR_END_TIME_TYPE, "The type of endTime must be int64."},
150     {ERR_END_TIME_LESS_THEN_BEGIN_TIME, "The endTime value must be greater than beginTime."},
151     {ERR_INTERVAL_TYPE, "The type of byInterval must be int32."},
152     {ERR_INTERVAL_OUT_OF_RANGE, "The value of byInterval must range from BY_OPTIMIZED to BY_ANNUALLY."},
153     {ERR_NEW_GROUP_TYPE, "The type of newGroup must be int32."},
154     {ERR_NEW_GROUP_OUT_OF_RANGE, "The type of newGroup must be {10,20,30,40,50,60}."},
155     {ERR_MAX_RECORDS_NUM_TYPE, "The type of maxNum must be int32."},
156     {ERR_MAX_RECORDS_NUM_BIGER_THEN_ONE_THOUSAND, "The maxNum cannot exceed 1000 or less then 1."},
157     {ERR_APP_GROUP_OBSERVER_CALLBACK_TYPE, "The type of callback must be Callback<AppGroupCallbackInfo>."},
158     {ERR_REPEAT_REGISTER_APP_GROUP_OBSERVER, "Repeat register app group observer, one process only hava one observer"},
159     {ERR_APP_GROUP_OBSERVER_IS_NULLPTR, "App observer is nullptr, please register before unRegister."},
160     {ERR_ASYNC_CALLBACK_NULLPTR, "Create async callback info object failed."},
161     {ERR_ASYNC_CALLBACK_INIT_FAILED, "Init async callback info object failed."},
162 };
163 }  // namespace DeviceUsageStats
164 }  // namespace OHOS
165 #endif  // FOUNDATION_RESOURCESCHEDULE_DEVICE_USAGE_STATISTICS_BUNDLE_STATE_INNER_ERRORS_H
166 
167