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 /** This class provides all the configs needed if we want to use {@link android.app.StatsManager} */ 25 public class StatsManagerConfig { 26 /** 27 * The key that represents the anomaly config. This value is used in {@link 28 * android.app.StatsManager#addConfig(long, byte[])} 29 */ 30 public static final long ANOMALY_CONFIG_KEY = 1; 31 32 /** The key that represents subscriber, which is settings app. */ 33 public static final long SUBSCRIBER_ID = 1; 34 35 @Retention(RetentionPolicy.SOURCE) 36 @IntDef({ 37 AnomalyType.NULL, 38 AnomalyType.UNKNOWN_REASON, 39 AnomalyType.EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF, 40 AnomalyType.EXCESSIVE_WAKEUPS_IN_BACKGROUND, 41 AnomalyType.EXCESSIVE_UNOPTIMIZED_BLE_SCAN, 42 AnomalyType.EXCESSIVE_BACKGROUND_SERVICE, 43 AnomalyType.EXCESSIVE_WIFI_SCAN, 44 AnomalyType.EXCESSIVE_FLASH_WRITES, 45 AnomalyType.EXCESSIVE_MEMORY_IN_BACKGROUND, 46 AnomalyType.EXCESSIVE_DAVEY_RATE, 47 AnomalyType.EXCESSIVE_JANKY_FRAMES, 48 AnomalyType.SLOW_COLD_START_TIME, 49 AnomalyType.SLOW_HOT_START_TIME, 50 AnomalyType.SLOW_WARM_START_TIME, 51 AnomalyType.EXCESSIVE_BACKGROUND_SYNCS, 52 AnomalyType.EXCESSIVE_GPS_SCANS_IN_BACKGROUND, 53 AnomalyType.EXCESSIVE_JOB_SCHEDULING, 54 AnomalyType.EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND, 55 AnomalyType.EXCESSIVE_WIFI_LOCK_TIME, 56 AnomalyType.JOB_TIMED_OUT, 57 AnomalyType.LONG_UNOPTIMIZED_BLE_SCAN, 58 AnomalyType.BACKGROUND_ANR, 59 AnomalyType.BACKGROUND_CRASH_RATE, 60 AnomalyType.EXCESSIVE_ANR_LOOPING, 61 AnomalyType.EXCESSIVE_ANRS, 62 AnomalyType.EXCESSIVE_CRASH_RATE, 63 AnomalyType.EXCESSIVE_CRASH_LOOPING, 64 AnomalyType.NUMBER_OF_OPEN_FILES, 65 AnomalyType.EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND, 66 AnomalyType.EXCESSIVE_CONTACT_ACCESS, 67 AnomalyType.EXCESSIVE_AUDIO_IN_BACKGROUND, 68 AnomalyType.EXCESSIVE_CRASH_ANR_IN_BACKGROUND, 69 AnomalyType.BATTERY_DRAIN_FROM_UNUSED_APP, 70 }) 71 public @interface AnomalyType { 72 /** This represents an error condition in the anomaly detection. */ 73 int NULL = -1; 74 75 /** The anomaly type does not match any other defined type. */ 76 int UNKNOWN_REASON = 0; 77 78 /** 79 * The application held a partial (screen off) wake lock for a period of time that exceeded 80 * the threshold with the screen off when not charging. 81 */ 82 int EXCESSIVE_WAKELOCK_ALL_SCREEN_OFF = 1; 83 84 /** 85 * The application exceeded the maximum number of wakeups while in the background when not 86 * charging. 87 */ 88 int EXCESSIVE_WAKEUPS_IN_BACKGROUND = 2; 89 90 /** The application did unoptimized Bluetooth scans too frequently when not charging. */ 91 int EXCESSIVE_UNOPTIMIZED_BLE_SCAN = 3; 92 93 /** 94 * The application ran in the background for a period of time that exceeded the threshold. 95 */ 96 int EXCESSIVE_BACKGROUND_SERVICE = 4; 97 98 /** The application exceeded the maximum number of wifi scans when not charging. */ 99 int EXCESSIVE_WIFI_SCAN = 5; 100 101 /** The application exceed the maximum number of flash writes */ 102 int EXCESSIVE_FLASH_WRITES = 6; 103 104 /** 105 * The application used more than the maximum memory, while not spending any time in the 106 * foreground. 107 */ 108 int EXCESSIVE_MEMORY_IN_BACKGROUND = 7; 109 110 /** 111 * The application exceeded the maximum percentage of frames with a render rate of greater 112 * than 700ms. 113 */ 114 int EXCESSIVE_DAVEY_RATE = 8; 115 116 /** 117 * The application exceeded the maximum percentage of frames with a render rate greater than 118 * 16ms. 119 */ 120 int EXCESSIVE_JANKY_FRAMES = 9; 121 122 /** 123 * The application exceeded the maximum cold start time - the app has not been launched 124 * since last system start, died or was killed. 125 */ 126 int SLOW_COLD_START_TIME = 10; 127 128 /** 129 * The application exceeded the maximum hot start time - the app and activity are already in 130 * memory. 131 */ 132 int SLOW_HOT_START_TIME = 11; 133 134 /** 135 * The application exceeded the maximum warm start time - the app was already in memory but 136 * the activity wasn’t created yet or was removed from memory. 137 */ 138 int SLOW_WARM_START_TIME = 12; 139 140 /** The application exceeded the maximum number of syncs while in the background. */ 141 int EXCESSIVE_BACKGROUND_SYNCS = 13; 142 143 /** The application exceeded the maximum number of gps scans while in the background. */ 144 int EXCESSIVE_GPS_SCANS_IN_BACKGROUND = 14; 145 146 /** The application scheduled more than the maximum number of jobs while not charging. */ 147 int EXCESSIVE_JOB_SCHEDULING = 15; 148 149 /** 150 * The application exceeded the maximum amount of mobile network traffic while in the 151 * background. 152 */ 153 int EXCESSIVE_MOBILE_NETWORK_IN_BACKGROUND = 16; 154 155 /** 156 * The application held the WiFi lock for more than the maximum amount of time while not 157 * charging. 158 */ 159 int EXCESSIVE_WIFI_LOCK_TIME = 17; 160 161 /** The application scheduled a job that ran longer than the maximum amount of time. */ 162 int JOB_TIMED_OUT = 18; 163 164 /** 165 * The application did an unoptimized Bluetooth scan that exceeded the maximum time while in 166 * the background. 167 */ 168 int LONG_UNOPTIMIZED_BLE_SCAN = 19; 169 170 /** The application exceeded the maximum ANR rate while in the background. */ 171 int BACKGROUND_ANR = 20; 172 173 /** The application exceeded the maximum crash rate while in the background. */ 174 int BACKGROUND_CRASH_RATE = 21; 175 176 /** The application exceeded the maximum ANR-looping rate. */ 177 int EXCESSIVE_ANR_LOOPING = 22; 178 179 /** The application exceeded the maximum ANR rate. */ 180 int EXCESSIVE_ANRS = 23; 181 182 /** The application exceeded the maximum crash rate. */ 183 int EXCESSIVE_CRASH_RATE = 24; 184 185 /** The application exceeded the maximum crash-looping rate. */ 186 int EXCESSIVE_CRASH_LOOPING = 25; 187 188 /** The application crashed because no more file descriptors were available. */ 189 int NUMBER_OF_OPEN_FILES = 26; 190 191 /** The application used an excessive amount of CPU while in a background process state. */ 192 int EXCESSIVE_CPU_USAGE_IN_BACKGROUND = 27; 193 194 /** 195 * The application kept the camera open for an excessive amount of time while in a bckground 196 * process state. 197 */ 198 int EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND = 28; 199 200 /** The application has accessed the contacts content provider an excessive amount. */ 201 int EXCESSIVE_CONTACT_ACCESS = 29; 202 203 /** The application has played too much audio while in a background process state. */ 204 int EXCESSIVE_AUDIO_IN_BACKGROUND = 30; 205 206 /** 207 * The application has crashed or ANRed too many times while in a background process state. 208 */ 209 int EXCESSIVE_CRASH_ANR_IN_BACKGROUND = 31; 210 211 /** 212 * An application which has not been used by the user recently was detected to cause an 213 * excessive amount of battery drain. 214 */ 215 int BATTERY_DRAIN_FROM_UNUSED_APP = 32; 216 } 217 } 218