• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.fuelgauge.batterytip;
18 
19 import androidx.annotation.IntDef;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 
24 /**
25  * This class provides all the configs needed if we want to use {@link android.app.StatsManager}
26  */
27 public class StatsManagerConfig {
28     /**
29      * The key that represents the anomaly config.
30      * This value is used in {@link android.app.StatsManager#addConfig(long, byte[])}
31      */
32     public static final long ANOMALY_CONFIG_KEY = 1;
33 
34     /**
35      * The key that represents subscriber, which is settings app.
36      */
37     public static final long SUBSCRIBER_ID = 1;
38 
39     @Retention(RetentionPolicy.SOURCE)
40     @IntDef({AnomalyType.NULL,
41             AnomalyType.UNKNOWN_REASON,
42             AnomalyType.EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF,
43             AnomalyType.EXCESSIVE_WAKEUPS_IN_BACKGROUND,
44             AnomalyType.EXCESSIVE_UNOPTIMIZED_BLE_SCAN,
45             AnomalyType.EXCESSIVE_BACKGROUND_SERVICE,
46             AnomalyType.EXCESSIVE_WIFI_SCAN,
47             AnomalyType.EXCESSIVE_FLASH_WRITES,
48             AnomalyType.EXCESSIVE_MEMORY_IN_BACKGROUND,
49             AnomalyType.EXCESSIVE_DAVEY_RATE,
50             AnomalyType.EXCESSIVE_JANKY_FRAMES,
51             AnomalyType.SLOW_COLD_START_TIME,
52             AnomalyType.SLOW_HOT_START_TIME,
53             AnomalyType.SLOW_WARM_START_TIME,
54             AnomalyType.EXCESSIVE_BACKGROUND_SYNCS,
55             AnomalyType.EXCESSIVE_GPS_SCANS_IN_BACKGROUND,
56             AnomalyType.EXCESSIVE_JOB_SCHEDULING,
57             AnomalyType.EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND,
58             AnomalyType.EXCESSIVE_WIFI_LOCK_TIME,
59             AnomalyType.JOB_TIMED_OUT,
60             AnomalyType.LONG_UNOPTIMIZED_BLE_SCAN,
61             AnomalyType.BACKGROUND_ANR,
62             AnomalyType.BACKGROUND_CRASH_RATE,
63             AnomalyType.EXCESSIVE_ANR_LOOPING,
64             AnomalyType.EXCESSIVE_ANRS,
65             AnomalyType.EXCESSIVE_CRASH_RATE,
66             AnomalyType.EXCESSIVE_CRASH_LOOPING,
67             AnomalyType.NUMBER_OF_OPEN_FILES,
68             AnomalyType.EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND,
69             AnomalyType.EXCESSIVE_CONTACT_ACCESS,
70             AnomalyType.EXCESSIVE_AUDIO_IN_BACKGROUND,
71             AnomalyType.EXCESSIVE_CRASH_ANR_IN_BACKGROUND,
72             AnomalyType.BATTERY_DRAIN_FROM_UNUSED_APP,
73     })
74     public @interface AnomalyType {
75         /**
76          * This represents an error condition in the anomaly detection.
77          */
78         int NULL = -1;
79 
80         /**
81          * The anomaly type does not match any other defined type.
82          */
83         int UNKNOWN_REASON = 0;
84 
85         /**
86          * The application held a partial (screen off) wake lock for a period of time that
87          * exceeded the threshold with the screen off when not charging.
88          */
89         int EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF = 1;
90 
91         /**
92          * The application exceeded the maximum number of wakeups while in the background
93          * when not charging.
94          */
95         int EXCESSIVE_WAKEUPS_IN_BACKGROUND = 2;
96 
97         /**
98          * The application did unoptimized Bluetooth scans too frequently when not charging.
99          */
100         int EXCESSIVE_UNOPTIMIZED_BLE_SCAN = 3;
101 
102         /**
103          * The application ran in the background for a period of time that exceeded the
104          * threshold.
105          */
106         int EXCESSIVE_BACKGROUND_SERVICE = 4;
107 
108         /**
109          * The application exceeded the maximum number of wifi scans when not charging.
110          */
111         int EXCESSIVE_WIFI_SCAN = 5;
112 
113         /**
114          * The application exceed the maximum number of flash writes
115          */
116         int EXCESSIVE_FLASH_WRITES = 6;
117 
118         /**
119          * The application used more than the maximum memory, while not spending any time
120          * in the foreground.
121          */
122         int EXCESSIVE_MEMORY_IN_BACKGROUND = 7;
123 
124         /**
125          * The application exceeded the maximum percentage of frames with a render rate of
126          * greater than 700ms.
127          */
128         int EXCESSIVE_DAVEY_RATE = 8;
129 
130         /**
131          * The application exceeded the maximum percentage of frames with a render rate
132          * greater than 16ms.
133          */
134         int EXCESSIVE_JANKY_FRAMES = 9;
135 
136         /**
137          * The application exceeded the maximum cold start time - the app has not been
138          * launched since last system start, died or was killed.
139          */
140         int SLOW_COLD_START_TIME = 10;
141 
142         /**
143          * The application exceeded the maximum hot start time - the app and activity are
144          * already in memory.
145          */
146         int SLOW_HOT_START_TIME = 11;
147 
148         /**
149          * The application exceeded the maximum warm start time - the app was already in
150          * memory but the activity wasn’t created yet or was removed from memory.
151          */
152         int SLOW_WARM_START_TIME = 12;
153 
154         /**
155          * The application exceeded the maximum number of syncs while in the background.
156          */
157         int EXCESSIVE_BACKGROUND_SYNCS = 13;
158 
159         /**
160          * The application exceeded the maximum number of gps scans while in the background.
161          */
162         int EXCESSIVE_GPS_SCANS_IN_BACKGROUND = 14;
163 
164         /**
165          * The application scheduled more than the maximum number of jobs while not charging.
166          */
167         int EXCESSIVE_JOB_SCHEDULING = 15;
168 
169         /**
170          * The application exceeded the maximum amount of mobile network traffic while in
171          * the background.
172          */
173         int EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND = 16;
174 
175         /**
176          * The application held the WiFi lock for more than the maximum amount of time while
177          * not charging.
178          */
179         int EXCESSIVE_WIFI_LOCK_TIME = 17;
180 
181         /**
182          * The application scheduled a job that ran longer than the maximum amount of time.
183          */
184         int JOB_TIMED_OUT = 18;
185 
186         /**
187          * The application did an unoptimized Bluetooth scan that exceeded the maximum
188          * time while in the background.
189          */
190         int LONG_UNOPTIMIZED_BLE_SCAN = 19;
191 
192         /**
193          * The application exceeded the maximum ANR rate while in the background.
194          */
195         int BACKGROUND_ANR = 20;
196 
197         /**
198          * The application exceeded the maximum crash rate while in the background.
199          */
200         int BACKGROUND_CRASH_RATE = 21;
201 
202         /**
203          * The application exceeded the maximum ANR-looping rate.
204          */
205         int EXCESSIVE_ANR_LOOPING = 22;
206 
207         /**
208          * The application exceeded the maximum ANR rate.
209          */
210         int EXCESSIVE_ANRS = 23;
211 
212         /**
213          * The application exceeded the maximum crash rate.
214          */
215         int EXCESSIVE_CRASH_RATE = 24;
216 
217         /**
218          * The application exceeded the maximum crash-looping rate.
219          */
220         int EXCESSIVE_CRASH_LOOPING = 25;
221 
222         /**
223          * The application crashed because no more file descriptors were available.
224          */
225         int NUMBER_OF_OPEN_FILES = 26;
226 
227         /**
228          * The application used an excessive amount of CPU while in a
229          * background process state.
230          */
231         int EXCESSIVE_CPU_USAGE_IN_BACKGROUND = 27;
232 
233         /**
234          * The application kept the camera open for an excessive amount
235          * of time while in a bckground process state.
236          */
237         int EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND = 28;
238 
239         /**
240          * The application has accessed the contacts content provider an
241          * excessive amount.
242          */
243         int EXCESSIVE_CONTACT_ACCESS = 29;
244 
245         /**
246          * The application has played too much audio while in a background
247          * process state.
248          */
249         int EXCESSIVE_AUDIO_IN_BACKGROUND = 30;
250 
251         /**
252          * The application has crashed or ANRed too many times while in a
253          * background process state.
254          */
255         int EXCESSIVE_CRASH_ANR_IN_BACKGROUND = 31;
256 
257         /**
258          * An application which has not been used by the user recently
259          * was detected to cause an excessive amount of battery drain.
260          */
261         int BATTERY_DRAIN_FROM_UNUSED_APP = 32;
262     }
263 
264 }
265