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