gkipnis | fcfc13e | 2016-02-11 15:33:30 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (c) 2016, The CyanogenMod Project |
| 3 | * <p/> |
| 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 | * <p/> |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * <p/> |
| 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 | |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 17 | package lineageos.providers; |
gkipnis | fcfc13e | 2016-02-11 15:33:30 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.ContentResolver; |
| 20 | import android.net.Uri; |
| 21 | |
| 22 | /** |
| 23 | * <p> |
| 24 | * The DataUsageProvdier contract containing definitions for the supported URIs and columns |
| 25 | * </p> |
| 26 | */ |
| 27 | |
| 28 | public final class DataUsageContract { |
| 29 | |
| 30 | /** The authority for the DataUsage provider */ |
Sam Mortimer | 542742b | 2017-09-18 19:44:11 -0700 | [diff] [blame] | 31 | public static final String DATAUSAGE_AUTHORITY = "org.lineageos.providers.datausage"; |
gkipnis | fcfc13e | 2016-02-11 15:33:30 -0800 | [diff] [blame] | 32 | public static final String DATAUSAGE_TABLE = "datausage"; |
| 33 | |
| 34 | /** The content URI for the top-level datausage authority */ |
| 35 | public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + DATAUSAGE_AUTHORITY); |
| 36 | |
| 37 | /** The content URI for this table */ |
| 38 | public static final Uri CONTENT_URI = |
| 39 | Uri.withAppendedPath(BASE_CONTENT_URI, DATAUSAGE_TABLE); |
| 40 | |
| 41 | /** Define database columns */ |
| 42 | /** |
| 43 | * The unique ID for a row |
| 44 | * <P>Type: INTEGER </P> |
| 45 | */ |
| 46 | public static final String _ID = "_id"; |
| 47 | |
| 48 | /** |
| 49 | * The UID of the application whose bandwidth is stored in this row |
| 50 | * <P>Type: INTEGER </P> |
| 51 | */ |
| 52 | public static final String UID = "uid"; |
| 53 | |
| 54 | /** |
| 55 | * DataUsage Enable Configuration - statically set by the Settings App |
| 56 | * 0 - no data usage warning are generated |
| 57 | * 1 - data usage algorithm is evaluated and warnings are generated |
| 58 | * <P>Type: INTEGER</P> |
| 59 | */ |
| 60 | public static final String ENABLE = "enable"; |
| 61 | |
| 62 | /** |
| 63 | * DataUsage Active State - dynamically computed by the DataUsage algorithm to |
| 64 | * determine warning type to display to the user |
| 65 | * 0 - first warning type is generated, once a warning generation is triggered |
| 66 | * 1 - Nth warning type is generated, once a warning generation is triggered |
| 67 | * <P>Type: INTEGER</P> |
| 68 | */ |
| 69 | public static final String ACTIVE = "active"; |
| 70 | |
| 71 | /** |
| 72 | * The Name of the Application that corresponds to the uid |
| 73 | * <P>Type: TEXT</P> |
| 74 | */ |
| 75 | public static final String LABEL = "label"; |
| 76 | |
| 77 | /** |
| 78 | * Number of bytes consumed by the App so far. It is used to determine the number |
| 79 | * of bytes consumed between samples |
| 80 | * <P>Type: INTEGER (long) </P> |
| 81 | */ |
| 82 | public static final String BYTES = "bytes"; |
| 83 | |
| 84 | /** |
| 85 | * The slow bandwidth consumption average accumulated over 'SLOW' number of samples |
| 86 | * <P>Type: INTEGER (long)</P> |
| 87 | */ |
| 88 | public static final String SLOW_AVG = "slow_avg"; |
| 89 | |
| 90 | /** |
| 91 | * Number of slow samples accumulated so far, once the number of samples reaches a |
| 92 | * MAX number of samples, the 'slow_samples' pegs at MAX and new samples |
| 93 | * are factored into 'slow_avg' by "taking out" one sample. |
| 94 | * slow_samples < MAX: slow_avg = (slow_avg * slow_samples + new_sample)/(slow_samples+1) |
| 95 | * slow_samples == MAX: slow_avg = (slow_avg * (MAX-1) + new_sample)/MAX |
| 96 | * <P>Type: Integer (long></P> |
| 97 | */ |
| 98 | public static final String SLOW_SAMPLES = "slow_samples"; |
| 99 | |
| 100 | /** |
| 101 | * The fast bandwidth consumption average accumulated over 'fast' number of samples |
| 102 | * <P>Type: INTEGER (long)</P> |
| 103 | */ |
| 104 | public static final String FAST_AVG = "fast_avg"; |
| 105 | |
| 106 | /** |
| 107 | * Number of fast samples accumulated so far, analogous algorithm to 'slow_samples' |
| 108 | * <P>Type: INTEGER (long)</P> |
| 109 | */ |
| 110 | public static final String FAST_SAMPLES = "fast_samples"; |
| 111 | |
| 112 | /** |
| 113 | * Extra information used debugging purposes - collects up to 1000 samples so that |
| 114 | * algorithm can be manually verified |
| 115 | * <P>Type: TEXT</P> |
| 116 | */ |
| 117 | public static final String EXTRA = "extra"; |
| 118 | |
| 119 | /** |
| 120 | * The mime type of a directory of items |
| 121 | */ |
| 122 | public static final String CONTENT_TYPE = |
| 123 | ContentResolver.CURSOR_DIR_BASE_TYPE + "datausage_item"; |
| 124 | |
| 125 | /** |
| 126 | * The mime type of a single item |
| 127 | */ |
| 128 | public static final String CONTENT_ITEM_TYPE = |
| 129 | ContentResolver.CURSOR_ITEM_BASE_TYPE + "datausage_item"; |
| 130 | |
| 131 | /** |
| 132 | * A projection of all columns in the datausage table. |
| 133 | */ |
| 134 | public static final String [] PROJECTION_ALL = { |
| 135 | _ID, |
| 136 | UID, |
| 137 | ENABLE, |
| 138 | ACTIVE, |
| 139 | LABEL, |
| 140 | BYTES, |
| 141 | SLOW_AVG, |
| 142 | SLOW_SAMPLES, |
| 143 | FAST_AVG, |
| 144 | FAST_SAMPLES, |
| 145 | EXTRA |
| 146 | }; |
| 147 | |
| 148 | /** |
| 149 | * Column index for each field in the database row |
| 150 | */ |
| 151 | public static final int COLUMN_OF_ID = 0; |
| 152 | public static final int COLUMN_OF_UID = 1; |
| 153 | public static final int COLUMN_OF_ENABLE = 2; |
| 154 | public static final int COLUMN_OF_ACTIVE = 3; |
| 155 | public static final int COLUMN_OF_LABEL = 4; |
| 156 | public static final int COLUMN_OF_BYTES = 5; |
| 157 | public static final int COLUMN_OF_SLOW_AVG = 6; |
| 158 | public static final int COLUMN_OF_SLOW_SAMPLES = 7; |
| 159 | public static final int COLUMN_OF_FAST_AVG = 8; |
| 160 | public static final int COLUMN_OF_FAST_SAMPLES = 9; |
| 161 | public static final int COLUMN_OF_EXTRA = 10; |
| 162 | |
| 163 | |
| 164 | } |