Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 android.app; |
| 18 | |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 20 | import android.annotation.RequiresPermission; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 21 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 22 | import android.annotation.SystemService; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 23 | import android.app.usage.UsageStatsManager; |
| 24 | import android.content.Context; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 25 | import android.media.AudioAttributes.AttributeUsage; |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 26 | import android.os.Binder; |
| 27 | import android.os.IBinder; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 28 | import android.os.Parcel; |
| 29 | import android.os.Parcelable; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 30 | import android.os.Process; |
| 31 | import android.os.RemoteException; |
Dianne Hackborn | 7b7c58b | 2014-12-02 18:32:20 -0800 | [diff] [blame] | 32 | import android.os.UserHandle; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 33 | import android.os.UserManager; |
| 34 | import android.util.ArrayMap; |
| 35 | |
| 36 | import com.android.internal.app.IAppOpsCallback; |
| 37 | import com.android.internal.app.IAppOpsService; |
| 38 | |
| 39 | import java.util.ArrayList; |
| 40 | import java.util.HashMap; |
| 41 | import java.util.List; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 42 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 43 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 44 | * API for interacting with "application operation" tracking. |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 45 | * |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 46 | * <p>This API is not generally intended for third party application developers; most |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 47 | * features are only available to system applications. |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 48 | */ |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 49 | @SystemService(Context.APP_OPS_SERVICE) |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 50 | public class AppOpsManager { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 51 | /** |
| 52 | * <p>App ops allows callers to:</p> |
| 53 | * |
| 54 | * <ul> |
| 55 | * <li> Note when operations are happening, and find out if they are allowed for the current |
| 56 | * caller.</li> |
| 57 | * <li> Disallow specific apps from doing specific operations.</li> |
| 58 | * <li> Collect all of the current information about operations that have been executed or |
| 59 | * are not being allowed.</li> |
| 60 | * <li> Monitor for changes in whether an operation is allowed.</li> |
| 61 | * </ul> |
| 62 | * |
| 63 | * <p>Each operation is identified by a single integer; these integers are a fixed set of |
| 64 | * operations, enumerated by the OP_* constants. |
| 65 | * |
| 66 | * <p></p>When checking operations, the result is a "mode" integer indicating the current |
| 67 | * setting for the operation under that caller: MODE_ALLOWED, MODE_IGNORED (don't execute |
| 68 | * the operation but fake its behavior enough so that the caller doesn't crash), |
| 69 | * MODE_ERRORED (throw a SecurityException back to the caller; the normal operation calls |
| 70 | * will do this for you). |
| 71 | */ |
| 72 | |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 73 | final Context mContext; |
| 74 | final IAppOpsService mService; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 75 | final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers |
| 76 | = new ArrayMap<OnOpChangedListener, IAppOpsCallback>(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 77 | |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 78 | static IBinder sToken; |
| 79 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 82 | * allowed to perform the given operation. |
| 83 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 84 | public static final int MODE_ALLOWED = 0; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is |
| 88 | * not allowed to perform the given operation, and this attempt should |
| 89 | * <em>silently fail</em> (it should not cause the app to crash). |
| 90 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 91 | public static final int MODE_IGNORED = 1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the |
| 95 | * given caller is not allowed to perform the given operation, and this attempt should |
| 96 | * cause it to have a fatal error, typically a {@link SecurityException}. |
| 97 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 98 | public static final int MODE_ERRORED = 2; |
| 99 | |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should |
| 102 | * use its default security check. This mode is not normally used; it should only be used |
| 103 | * with appop permissions, and callers must explicitly check for it and deal with it. |
| 104 | */ |
| 105 | public static final int MODE_DEFAULT = 3; |
| 106 | |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 107 | // when adding one of these: |
| 108 | // - increment _NUM_OP |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 109 | // - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 110 | // - add descriptive strings to Settings/res/values/arrays.xml |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 111 | // - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app) |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 112 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 113 | /** @hide No operation specified. */ |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 114 | public static final int OP_NONE = -1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 115 | /** @hide Access to coarse location information. */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 116 | public static final int OP_COARSE_LOCATION = 0; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 117 | /** @hide Access to fine location information. */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 118 | public static final int OP_FINE_LOCATION = 1; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 119 | /** @hide Causing GPS to run. */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 120 | public static final int OP_GPS = 2; |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 121 | /** @hide */ |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 122 | public static final int OP_VIBRATE = 3; |
| 123 | /** @hide */ |
| 124 | public static final int OP_READ_CONTACTS = 4; |
| 125 | /** @hide */ |
| 126 | public static final int OP_WRITE_CONTACTS = 5; |
| 127 | /** @hide */ |
| 128 | public static final int OP_READ_CALL_LOG = 6; |
| 129 | /** @hide */ |
| 130 | public static final int OP_WRITE_CALL_LOG = 7; |
| 131 | /** @hide */ |
| 132 | public static final int OP_READ_CALENDAR = 8; |
| 133 | /** @hide */ |
| 134 | public static final int OP_WRITE_CALENDAR = 9; |
| 135 | /** @hide */ |
| 136 | public static final int OP_WIFI_SCAN = 10; |
| 137 | /** @hide */ |
| 138 | public static final int OP_POST_NOTIFICATION = 11; |
| 139 | /** @hide */ |
| 140 | public static final int OP_NEIGHBORING_CELLS = 12; |
| 141 | /** @hide */ |
| 142 | public static final int OP_CALL_PHONE = 13; |
| 143 | /** @hide */ |
| 144 | public static final int OP_READ_SMS = 14; |
| 145 | /** @hide */ |
| 146 | public static final int OP_WRITE_SMS = 15; |
| 147 | /** @hide */ |
| 148 | public static final int OP_RECEIVE_SMS = 16; |
| 149 | /** @hide */ |
| 150 | public static final int OP_RECEIVE_EMERGECY_SMS = 17; |
| 151 | /** @hide */ |
| 152 | public static final int OP_RECEIVE_MMS = 18; |
| 153 | /** @hide */ |
| 154 | public static final int OP_RECEIVE_WAP_PUSH = 19; |
| 155 | /** @hide */ |
| 156 | public static final int OP_SEND_SMS = 20; |
| 157 | /** @hide */ |
| 158 | public static final int OP_READ_ICC_SMS = 21; |
| 159 | /** @hide */ |
| 160 | public static final int OP_WRITE_ICC_SMS = 22; |
| 161 | /** @hide */ |
| 162 | public static final int OP_WRITE_SETTINGS = 23; |
| 163 | /** @hide */ |
| 164 | public static final int OP_SYSTEM_ALERT_WINDOW = 24; |
| 165 | /** @hide */ |
| 166 | public static final int OP_ACCESS_NOTIFICATIONS = 25; |
| 167 | /** @hide */ |
| 168 | public static final int OP_CAMERA = 26; |
| 169 | /** @hide */ |
| 170 | public static final int OP_RECORD_AUDIO = 27; |
| 171 | /** @hide */ |
| 172 | public static final int OP_PLAY_AUDIO = 28; |
| 173 | /** @hide */ |
| 174 | public static final int OP_READ_CLIPBOARD = 29; |
| 175 | /** @hide */ |
| 176 | public static final int OP_WRITE_CLIPBOARD = 30; |
| 177 | /** @hide */ |
| 178 | public static final int OP_TAKE_MEDIA_BUTTONS = 31; |
| 179 | /** @hide */ |
| 180 | public static final int OP_TAKE_AUDIO_FOCUS = 32; |
| 181 | /** @hide */ |
| 182 | public static final int OP_AUDIO_MASTER_VOLUME = 33; |
| 183 | /** @hide */ |
| 184 | public static final int OP_AUDIO_VOICE_VOLUME = 34; |
| 185 | /** @hide */ |
| 186 | public static final int OP_AUDIO_RING_VOLUME = 35; |
| 187 | /** @hide */ |
| 188 | public static final int OP_AUDIO_MEDIA_VOLUME = 36; |
| 189 | /** @hide */ |
| 190 | public static final int OP_AUDIO_ALARM_VOLUME = 37; |
| 191 | /** @hide */ |
| 192 | public static final int OP_AUDIO_NOTIFICATION_VOLUME = 38; |
| 193 | /** @hide */ |
| 194 | public static final int OP_AUDIO_BLUETOOTH_VOLUME = 39; |
| 195 | /** @hide */ |
| 196 | public static final int OP_WAKE_LOCK = 40; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 197 | /** @hide Continually monitoring location data. */ |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 198 | public static final int OP_MONITOR_LOCATION = 41; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 199 | /** @hide Continually monitoring location data with a relatively high power request. */ |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 200 | public static final int OP_MONITOR_HIGH_POWER_LOCATION = 42; |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 201 | /** @hide Retrieve current usage stats via {@link UsageStatsManager}. */ |
| 202 | public static final int OP_GET_USAGE_STATS = 43; |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 203 | /** @hide */ |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 204 | public static final int OP_MUTE_MICROPHONE = 44; |
| 205 | /** @hide */ |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 206 | public static final int OP_TOAST_WINDOW = 45; |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 207 | /** @hide Capture the device's display contents and/or audio */ |
| 208 | public static final int OP_PROJECT_MEDIA = 46; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 209 | /** @hide Activate a VPN connection without user intervention. */ |
| 210 | public static final int OP_ACTIVATE_VPN = 47; |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 211 | /** @hide Access the WallpaperManagerAPI to write wallpapers. */ |
| 212 | public static final int OP_WRITE_WALLPAPER = 48; |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 213 | /** @hide Received the assist structure from an app. */ |
| 214 | public static final int OP_ASSIST_STRUCTURE = 49; |
| 215 | /** @hide Received a screenshot from assist. */ |
| 216 | public static final int OP_ASSIST_SCREENSHOT = 50; |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 217 | /** @hide Read the phone state. */ |
| 218 | public static final int OP_READ_PHONE_STATE = 51; |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 219 | /** @hide Add voicemail messages to the voicemail content provider. */ |
| 220 | public static final int OP_ADD_VOICEMAIL = 52; |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 221 | /** @hide Access APIs for SIP calling over VOIP or WiFi. */ |
| 222 | public static final int OP_USE_SIP = 53; |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 223 | /** @hide Intercept outgoing calls. */ |
| 224 | public static final int OP_PROCESS_OUTGOING_CALLS = 54; |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 225 | /** @hide User the fingerprint API. */ |
| 226 | public static final int OP_USE_FINGERPRINT = 55; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 227 | /** @hide Access to body sensors such as heart rate, etc. */ |
| 228 | public static final int OP_BODY_SENSORS = 56; |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 229 | /** @hide Read previously received cell broadcast messages. */ |
| 230 | public static final int OP_READ_CELL_BROADCASTS = 57; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 231 | /** @hide Inject mock location into the system. */ |
| 232 | public static final int OP_MOCK_LOCATION = 58; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 233 | /** @hide Read external storage. */ |
| 234 | public static final int OP_READ_EXTERNAL_STORAGE = 59; |
| 235 | /** @hide Write external storage. */ |
| 236 | public static final int OP_WRITE_EXTERNAL_STORAGE = 60; |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 237 | /** @hide Turned on the screen. */ |
| 238 | public static final int OP_TURN_SCREEN_ON = 61; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 239 | /** @hide Get device accounts. */ |
| 240 | public static final int OP_GET_ACCOUNTS = 62; |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 241 | /** @hide Control whether an application is allowed to run in the background. */ |
| 242 | public static final int OP_RUN_IN_BACKGROUND = 63; |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 243 | /** @hide */ |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 244 | public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = 64; |
Chad Brubaker | 73ec8f9 | 2016-11-10 11:24:40 -0800 | [diff] [blame] | 245 | /** @hide Read the phone number. */ |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 246 | public static final int OP_READ_PHONE_NUMBERS = 65; |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 247 | /** @hide Request package installs through package installer */ |
| 248 | public static final int OP_REQUEST_INSTALL_PACKAGES = 66; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 249 | /** @hide Enter picture-in-picture. */ |
| 250 | public static final int OP_PICTURE_IN_PICTURE = 67; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 251 | /** @hide Instant app start foreground service. */ |
| 252 | public static final int OP_INSTANT_APP_START_FOREGROUND = 68; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 253 | /** @hide Answer incoming phone calls */ |
| 254 | public static final int OP_ANSWER_PHONE_CALLS = 69; |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 255 | /** @hide */ |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 256 | public static final int _NUM_OP = 70; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 257 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 258 | /** Access to coarse location information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 259 | public static final String OPSTR_COARSE_LOCATION = "android:coarse_location"; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 260 | /** Access to fine location information. */ |
| 261 | public static final String OPSTR_FINE_LOCATION = |
| 262 | "android:fine_location"; |
| 263 | /** Continually monitoring location data. */ |
| 264 | public static final String OPSTR_MONITOR_LOCATION |
| 265 | = "android:monitor_location"; |
| 266 | /** Continually monitoring location data with a relatively high power request. */ |
| 267 | public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION |
| 268 | = "android:monitor_location_high_power"; |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 269 | /** Access to {@link android.app.usage.UsageStatsManager}. */ |
| 270 | public static final String OPSTR_GET_USAGE_STATS |
| 271 | = "android:get_usage_stats"; |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 272 | /** Activate a VPN connection without user intervention. @hide */ |
| 273 | @SystemApi |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 274 | public static final String OPSTR_ACTIVATE_VPN |
| 275 | = "android:activate_vpn"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 276 | /** Allows an application to read the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 277 | public static final String OPSTR_READ_CONTACTS |
| 278 | = "android:read_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 279 | /** Allows an application to write to the user's contacts data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 280 | public static final String OPSTR_WRITE_CONTACTS |
| 281 | = "android:write_contacts"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 282 | /** Allows an application to read the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 283 | public static final String OPSTR_READ_CALL_LOG |
| 284 | = "android:read_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 285 | /** Allows an application to write to the user's call log. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 286 | public static final String OPSTR_WRITE_CALL_LOG |
| 287 | = "android:write_call_log"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 288 | /** Allows an application to read the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 289 | public static final String OPSTR_READ_CALENDAR |
| 290 | = "android:read_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 291 | /** Allows an application to write to the user's calendar data. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 292 | public static final String OPSTR_WRITE_CALENDAR |
| 293 | = "android:write_calendar"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 294 | /** Allows an application to initiate a phone call. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 295 | public static final String OPSTR_CALL_PHONE |
| 296 | = "android:call_phone"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 297 | /** Allows an application to read SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 298 | public static final String OPSTR_READ_SMS |
| 299 | = "android:read_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 300 | /** Allows an application to receive SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 301 | public static final String OPSTR_RECEIVE_SMS |
| 302 | = "android:receive_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 303 | /** Allows an application to receive MMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 304 | public static final String OPSTR_RECEIVE_MMS |
| 305 | = "android:receive_mms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 306 | /** Allows an application to receive WAP push messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 307 | public static final String OPSTR_RECEIVE_WAP_PUSH |
| 308 | = "android:receive_wap_push"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 309 | /** Allows an application to send SMS messages. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 310 | public static final String OPSTR_SEND_SMS |
| 311 | = "android:send_sms"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 312 | /** Required to be able to access the camera device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 313 | public static final String OPSTR_CAMERA |
| 314 | = "android:camera"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 315 | /** Required to be able to access the microphone device. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 316 | public static final String OPSTR_RECORD_AUDIO |
| 317 | = "android:record_audio"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 318 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 319 | public static final String OPSTR_READ_PHONE_STATE |
| 320 | = "android:read_phone_state"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 321 | /** Required to access phone state related information. */ |
Svet Ganov | 6e8f67c | 2015-04-29 17:35:19 -0700 | [diff] [blame] | 322 | public static final String OPSTR_ADD_VOICEMAIL |
| 323 | = "android:add_voicemail"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 324 | /** Access APIs for SIP calling over VOIP or WiFi */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 325 | public static final String OPSTR_USE_SIP |
| 326 | = "android:use_sip"; |
Svet Ganov | e8e8942 | 2016-09-22 19:56:50 -0700 | [diff] [blame] | 327 | /** Access APIs for diverting outgoing calls */ |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 328 | public static final String OPSTR_PROCESS_OUTGOING_CALLS |
| 329 | = "android:process_outgoing_calls"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 330 | /** Use the fingerprint API. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 331 | public static final String OPSTR_USE_FINGERPRINT |
| 332 | = "android:use_fingerprint"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 333 | /** Access to body sensors such as heart rate, etc. */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 334 | public static final String OPSTR_BODY_SENSORS |
| 335 | = "android:body_sensors"; |
Svet Ganov | 715cf2a | 2015-06-13 17:31:29 -0700 | [diff] [blame] | 336 | /** Read previously received cell broadcast messages. */ |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 337 | public static final String OPSTR_READ_CELL_BROADCASTS |
| 338 | = "android:read_cell_broadcasts"; |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 339 | /** Inject mock location into the system. */ |
| 340 | public static final String OPSTR_MOCK_LOCATION |
| 341 | = "android:mock_location"; |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 342 | /** Read external storage. */ |
| 343 | public static final String OPSTR_READ_EXTERNAL_STORAGE |
| 344 | = "android:read_external_storage"; |
| 345 | /** Write external storage. */ |
| 346 | public static final String OPSTR_WRITE_EXTERNAL_STORAGE |
| 347 | = "android:write_external_storage"; |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 348 | /** Required to draw on top of other apps. */ |
| 349 | public static final String OPSTR_SYSTEM_ALERT_WINDOW |
| 350 | = "android:system_alert_window"; |
| 351 | /** Required to write/modify/update system settingss. */ |
| 352 | public static final String OPSTR_WRITE_SETTINGS |
| 353 | = "android:write_settings"; |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 354 | /** @hide Get device accounts. */ |
| 355 | public static final String OPSTR_GET_ACCOUNTS |
| 356 | = "android:get_accounts"; |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 357 | public static final String OPSTR_READ_PHONE_NUMBERS |
| 358 | = "android:read_phone_numbers"; |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 359 | /** Access to picture-in-picture. */ |
| 360 | public static final String OPSTR_PICTURE_IN_PICTURE |
| 361 | = "android:picture_in_picture"; |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 362 | /** @hide */ |
| 363 | public static final String OPSTR_INSTANT_APP_START_FOREGROUND |
| 364 | = "android:instant_app_start_foreground"; |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 365 | /** Answer incoming phone calls */ |
| 366 | public static final String OPSTR_ANSWER_PHONE_CALLS |
| 367 | = "android:answer_phone_calls"; |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 368 | |
Philip P. Moltmann | e56c08e | 2017-03-15 12:46:04 -0700 | [diff] [blame] | 369 | // Warning: If an permission is added here it also has to be added to |
| 370 | // com.android.packageinstaller.permission.utils.EventLogger |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 371 | private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = { |
| 372 | // RUNTIME PERMISSIONS |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 373 | // Contacts |
| 374 | OP_READ_CONTACTS, |
| 375 | OP_WRITE_CONTACTS, |
| 376 | OP_GET_ACCOUNTS, |
| 377 | // Calendar |
| 378 | OP_READ_CALENDAR, |
| 379 | OP_WRITE_CALENDAR, |
| 380 | // SMS |
| 381 | OP_SEND_SMS, |
| 382 | OP_RECEIVE_SMS, |
| 383 | OP_READ_SMS, |
| 384 | OP_RECEIVE_WAP_PUSH, |
| 385 | OP_RECEIVE_MMS, |
| 386 | OP_READ_CELL_BROADCASTS, |
| 387 | // Storage |
| 388 | OP_READ_EXTERNAL_STORAGE, |
| 389 | OP_WRITE_EXTERNAL_STORAGE, |
| 390 | // Location |
| 391 | OP_COARSE_LOCATION, |
| 392 | OP_FINE_LOCATION, |
| 393 | // Phone |
| 394 | OP_READ_PHONE_STATE, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 395 | OP_READ_PHONE_NUMBERS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 396 | OP_CALL_PHONE, |
| 397 | OP_READ_CALL_LOG, |
| 398 | OP_WRITE_CALL_LOG, |
| 399 | OP_ADD_VOICEMAIL, |
| 400 | OP_USE_SIP, |
| 401 | OP_PROCESS_OUTGOING_CALLS, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 402 | OP_ANSWER_PHONE_CALLS, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 403 | // Microphone |
| 404 | OP_RECORD_AUDIO, |
| 405 | // Camera |
| 406 | OP_CAMERA, |
| 407 | // Body sensors |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 408 | OP_BODY_SENSORS, |
| 409 | |
| 410 | // APPOP PERMISSIONS |
| 411 | OP_ACCESS_NOTIFICATIONS, |
| 412 | OP_SYSTEM_ALERT_WINDOW, |
| 413 | OP_WRITE_SETTINGS, |
| 414 | OP_REQUEST_INSTALL_PACKAGES, |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 415 | }; |
| 416 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 417 | /** |
| 418 | * This maps each operation to the operation that serves as the |
| 419 | * switch to determine whether it is allowed. Generally this is |
| 420 | * a 1:1 mapping, but for some things (like location) that have |
| 421 | * multiple low-level operations being tracked that should be |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 422 | * presented to the user as one switch then this can be used to |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 423 | * make them all controlled by the same single operation. |
| 424 | */ |
| 425 | private static int[] sOpToSwitch = new int[] { |
| 426 | OP_COARSE_LOCATION, |
| 427 | OP_COARSE_LOCATION, |
| 428 | OP_COARSE_LOCATION, |
| 429 | OP_VIBRATE, |
| 430 | OP_READ_CONTACTS, |
| 431 | OP_WRITE_CONTACTS, |
| 432 | OP_READ_CALL_LOG, |
| 433 | OP_WRITE_CALL_LOG, |
| 434 | OP_READ_CALENDAR, |
| 435 | OP_WRITE_CALENDAR, |
| 436 | OP_COARSE_LOCATION, |
| 437 | OP_POST_NOTIFICATION, |
| 438 | OP_COARSE_LOCATION, |
| 439 | OP_CALL_PHONE, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 440 | OP_READ_SMS, |
| 441 | OP_WRITE_SMS, |
David Braun | 18966a8 | 2013-09-10 13:14:46 -0700 | [diff] [blame] | 442 | OP_RECEIVE_SMS, |
| 443 | OP_RECEIVE_SMS, |
Svet Ganov | 99e4d51 | 2016-09-21 19:50:14 -0700 | [diff] [blame] | 444 | OP_RECEIVE_MMS, |
| 445 | OP_RECEIVE_WAP_PUSH, |
David Braun | 18966a8 | 2013-09-10 13:14:46 -0700 | [diff] [blame] | 446 | OP_SEND_SMS, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 447 | OP_READ_SMS, |
| 448 | OP_WRITE_SMS, |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 449 | OP_WRITE_SETTINGS, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 450 | OP_SYSTEM_ALERT_WINDOW, |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 451 | OP_ACCESS_NOTIFICATIONS, |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 452 | OP_CAMERA, |
| 453 | OP_RECORD_AUDIO, |
| 454 | OP_PLAY_AUDIO, |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 455 | OP_READ_CLIPBOARD, |
| 456 | OP_WRITE_CLIPBOARD, |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 457 | OP_TAKE_MEDIA_BUTTONS, |
| 458 | OP_TAKE_AUDIO_FOCUS, |
| 459 | OP_AUDIO_MASTER_VOLUME, |
| 460 | OP_AUDIO_VOICE_VOLUME, |
| 461 | OP_AUDIO_RING_VOLUME, |
| 462 | OP_AUDIO_MEDIA_VOLUME, |
| 463 | OP_AUDIO_ALARM_VOLUME, |
| 464 | OP_AUDIO_NOTIFICATION_VOLUME, |
| 465 | OP_AUDIO_BLUETOOTH_VOLUME, |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 466 | OP_WAKE_LOCK, |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 467 | OP_COARSE_LOCATION, |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 468 | OP_COARSE_LOCATION, |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 469 | OP_GET_USAGE_STATS, |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 470 | OP_MUTE_MICROPHONE, |
| 471 | OP_TOAST_WINDOW, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 472 | OP_PROJECT_MEDIA, |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 473 | OP_ACTIVATE_VPN, |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 474 | OP_WRITE_WALLPAPER, |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 475 | OP_ASSIST_STRUCTURE, |
| 476 | OP_ASSIST_SCREENSHOT, |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 477 | OP_READ_PHONE_STATE, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 478 | OP_ADD_VOICEMAIL, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 479 | OP_USE_SIP, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 480 | OP_PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 481 | OP_USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 482 | OP_BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 483 | OP_READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 484 | OP_MOCK_LOCATION, |
| 485 | OP_READ_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 486 | OP_WRITE_EXTERNAL_STORAGE, |
| 487 | OP_TURN_SCREEN_ON, |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 488 | OP_GET_ACCOUNTS, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 489 | OP_RUN_IN_BACKGROUND, |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 490 | OP_AUDIO_ACCESSIBILITY_VOLUME, |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 491 | OP_READ_PHONE_NUMBERS, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 492 | OP_REQUEST_INSTALL_PACKAGES, |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 493 | OP_PICTURE_IN_PICTURE, |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 494 | OP_INSTANT_APP_START_FOREGROUND, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 495 | OP_ANSWER_PHONE_CALLS |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 499 | * This maps each operation to the public string constant for it. |
| 500 | * If it doesn't have a public string constant, it maps to null. |
| 501 | */ |
| 502 | private static String[] sOpToString = new String[] { |
| 503 | OPSTR_COARSE_LOCATION, |
| 504 | OPSTR_FINE_LOCATION, |
| 505 | null, |
| 506 | null, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 507 | OPSTR_READ_CONTACTS, |
| 508 | OPSTR_WRITE_CONTACTS, |
| 509 | OPSTR_READ_CALL_LOG, |
| 510 | OPSTR_WRITE_CALL_LOG, |
| 511 | OPSTR_READ_CALENDAR, |
| 512 | OPSTR_WRITE_CALENDAR, |
| 513 | null, |
| 514 | null, |
| 515 | null, |
| 516 | OPSTR_CALL_PHONE, |
| 517 | OPSTR_READ_SMS, |
| 518 | null, |
| 519 | OPSTR_RECEIVE_SMS, |
| 520 | null, |
| 521 | OPSTR_RECEIVE_MMS, |
| 522 | OPSTR_RECEIVE_WAP_PUSH, |
| 523 | OPSTR_SEND_SMS, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 524 | null, |
| 525 | null, |
Billy Lau | 24b9c83 | 2015-07-20 17:34:09 +0100 | [diff] [blame] | 526 | OPSTR_WRITE_SETTINGS, |
| 527 | OPSTR_SYSTEM_ALERT_WINDOW, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 528 | null, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 529 | OPSTR_CAMERA, |
| 530 | OPSTR_RECORD_AUDIO, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 531 | null, |
| 532 | null, |
| 533 | null, |
| 534 | null, |
| 535 | null, |
| 536 | null, |
| 537 | null, |
| 538 | null, |
| 539 | null, |
| 540 | null, |
| 541 | null, |
| 542 | null, |
| 543 | null, |
| 544 | OPSTR_MONITOR_LOCATION, |
| 545 | OPSTR_MONITOR_HIGH_POWER_LOCATION, |
Dianne Hackborn | 5064e7c | 2014-09-02 10:57:16 -0700 | [diff] [blame] | 546 | OPSTR_GET_USAGE_STATS, |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 547 | null, |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 548 | null, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 549 | null, |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 550 | OPSTR_ACTIVATE_VPN, |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 551 | null, |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 552 | null, |
| 553 | null, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 554 | OPSTR_READ_PHONE_STATE, |
| 555 | OPSTR_ADD_VOICEMAIL, |
| 556 | OPSTR_USE_SIP, |
Svet Ganov | 824ad6e | 2016-09-22 19:36:53 -0700 | [diff] [blame] | 557 | OPSTR_PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 558 | OPSTR_USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 559 | OPSTR_BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 560 | OPSTR_READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 561 | OPSTR_MOCK_LOCATION, |
| 562 | OPSTR_READ_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 563 | OPSTR_WRITE_EXTERNAL_STORAGE, |
| 564 | null, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 565 | OPSTR_GET_ACCOUNTS, |
| 566 | null, |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 567 | null, // OP_AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 568 | OPSTR_READ_PHONE_NUMBERS, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 569 | null, // OP_REQUEST_INSTALL_PACKAGES |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 570 | OPSTR_PICTURE_IN_PICTURE, |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 571 | OPSTR_INSTANT_APP_START_FOREGROUND, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 572 | OPSTR_ANSWER_PHONE_CALLS, |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 573 | }; |
| 574 | |
| 575 | /** |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 576 | * This provides a simple name for each operation to be used |
| 577 | * in debug output. |
| 578 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 579 | private static String[] sOpNames = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 580 | "COARSE_LOCATION", |
| 581 | "FINE_LOCATION", |
| 582 | "GPS", |
| 583 | "VIBRATE", |
| 584 | "READ_CONTACTS", |
| 585 | "WRITE_CONTACTS", |
| 586 | "READ_CALL_LOG", |
| 587 | "WRITE_CALL_LOG", |
| 588 | "READ_CALENDAR", |
| 589 | "WRITE_CALENDAR", |
| 590 | "WIFI_SCAN", |
| 591 | "POST_NOTIFICATION", |
| 592 | "NEIGHBORING_CELLS", |
| 593 | "CALL_PHONE", |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 594 | "READ_SMS", |
| 595 | "WRITE_SMS", |
| 596 | "RECEIVE_SMS", |
| 597 | "RECEIVE_EMERGECY_SMS", |
| 598 | "RECEIVE_MMS", |
| 599 | "RECEIVE_WAP_PUSH", |
| 600 | "SEND_SMS", |
| 601 | "READ_ICC_SMS", |
| 602 | "WRITE_ICC_SMS", |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 603 | "WRITE_SETTINGS", |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 604 | "SYSTEM_ALERT_WINDOW", |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 605 | "ACCESS_NOTIFICATIONS", |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 606 | "CAMERA", |
| 607 | "RECORD_AUDIO", |
| 608 | "PLAY_AUDIO", |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 609 | "READ_CLIPBOARD", |
| 610 | "WRITE_CLIPBOARD", |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 611 | "TAKE_MEDIA_BUTTONS", |
| 612 | "TAKE_AUDIO_FOCUS", |
| 613 | "AUDIO_MASTER_VOLUME", |
| 614 | "AUDIO_VOICE_VOLUME", |
| 615 | "AUDIO_RING_VOLUME", |
| 616 | "AUDIO_MEDIA_VOLUME", |
| 617 | "AUDIO_ALARM_VOLUME", |
| 618 | "AUDIO_NOTIFICATION_VOLUME", |
| 619 | "AUDIO_BLUETOOTH_VOLUME", |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 620 | "WAKE_LOCK", |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 621 | "MONITOR_LOCATION", |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 622 | "MONITOR_HIGH_POWER_LOCATION", |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 623 | "GET_USAGE_STATS", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 624 | "MUTE_MICROPHONE", |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 625 | "TOAST_WINDOW", |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 626 | "PROJECT_MEDIA", |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 627 | "ACTIVATE_VPN", |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 628 | "WRITE_WALLPAPER", |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 629 | "ASSIST_STRUCTURE", |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 630 | "ASSIST_SCREENSHOT", |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 631 | "OP_READ_PHONE_STATE", |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 632 | "ADD_VOICEMAIL", |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 633 | "USE_SIP", |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 634 | "PROCESS_OUTGOING_CALLS", |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 635 | "USE_FINGERPRINT", |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 636 | "BODY_SENSORS", |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 637 | "READ_CELL_BROADCASTS", |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 638 | "MOCK_LOCATION", |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 639 | "READ_EXTERNAL_STORAGE", |
| 640 | "WRITE_EXTERNAL_STORAGE", |
| 641 | "TURN_ON_SCREEN", |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 642 | "GET_ACCOUNTS", |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 643 | "RUN_IN_BACKGROUND", |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 644 | "AUDIO_ACCESSIBILITY_VOLUME", |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 645 | "READ_PHONE_NUMBERS", |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 646 | "REQUEST_INSTALL_PACKAGES", |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 647 | "PICTURE_IN_PICTURE", |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 648 | "INSTANT_APP_START_FOREGROUND", |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 649 | "ANSWER_PHONE_CALLS", |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 650 | }; |
| 651 | |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 652 | /** |
| 653 | * This optionally maps a permission to an operation. If there |
| 654 | * is no permission associated with an operation, it is null. |
| 655 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 656 | private static String[] sOpPerms = new String[] { |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 657 | android.Manifest.permission.ACCESS_COARSE_LOCATION, |
| 658 | android.Manifest.permission.ACCESS_FINE_LOCATION, |
| 659 | null, |
| 660 | android.Manifest.permission.VIBRATE, |
| 661 | android.Manifest.permission.READ_CONTACTS, |
| 662 | android.Manifest.permission.WRITE_CONTACTS, |
| 663 | android.Manifest.permission.READ_CALL_LOG, |
| 664 | android.Manifest.permission.WRITE_CALL_LOG, |
| 665 | android.Manifest.permission.READ_CALENDAR, |
| 666 | android.Manifest.permission.WRITE_CALENDAR, |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 667 | android.Manifest.permission.ACCESS_WIFI_STATE, |
Robert Craig | f97616c | 2013-10-07 12:32:02 -0400 | [diff] [blame] | 668 | null, // no permission required for notifications |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 669 | null, // neighboring cells shares the coarse location perm |
| 670 | android.Manifest.permission.CALL_PHONE, |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 671 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 672 | null, // no permission required for writing sms |
Dianne Hackborn | f51f612 | 2013-02-04 18:23:34 -0800 | [diff] [blame] | 673 | android.Manifest.permission.RECEIVE_SMS, |
| 674 | android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST, |
| 675 | android.Manifest.permission.RECEIVE_MMS, |
| 676 | android.Manifest.permission.RECEIVE_WAP_PUSH, |
| 677 | android.Manifest.permission.SEND_SMS, |
| 678 | android.Manifest.permission.READ_SMS, |
Svetoslav | 6c58957 | 2015-04-16 16:19:24 -0700 | [diff] [blame] | 679 | null, // no permission required for writing icc sms |
Dianne Hackborn | 961321f | 2013-02-05 17:22:41 -0800 | [diff] [blame] | 680 | android.Manifest.permission.WRITE_SETTINGS, |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 681 | android.Manifest.permission.SYSTEM_ALERT_WINDOW, |
Daniel Sandler | fde19b1 | 2013-01-17 00:21:05 -0500 | [diff] [blame] | 682 | android.Manifest.permission.ACCESS_NOTIFICATIONS, |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 683 | android.Manifest.permission.CAMERA, |
| 684 | android.Manifest.permission.RECORD_AUDIO, |
| 685 | null, // no permission for playing audio |
Dianne Hackborn | efcc1a2 | 2013-02-25 18:02:35 -0800 | [diff] [blame] | 686 | null, // no permission for reading clipboard |
| 687 | null, // no permission for writing clipboard |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 688 | null, // no permission for taking media buttons |
| 689 | null, // no permission for taking audio focus |
| 690 | null, // no permission for changing master volume |
| 691 | null, // no permission for changing voice volume |
| 692 | null, // no permission for changing ring volume |
| 693 | null, // no permission for changing media volume |
| 694 | null, // no permission for changing alarm volume |
| 695 | null, // no permission for changing notification volume |
| 696 | null, // no permission for changing bluetooth volume |
Dianne Hackborn | 713df15 | 2013-05-17 11:27:57 -0700 | [diff] [blame] | 697 | android.Manifest.permission.WAKE_LOCK, |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 698 | null, // no permission for generic location monitoring |
David Christie | 0b83745 | 2013-07-29 16:02:13 -0700 | [diff] [blame] | 699 | null, // no permission for high power location monitoring |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 700 | android.Manifest.permission.PACKAGE_USAGE_STATS, |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 701 | null, // no permission for muting/unmuting microphone |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 702 | null, // no permission for displaying toasts |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 703 | null, // no permission for projecting media |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 704 | null, // no permission for activating vpn |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 705 | null, // no permission for supporting wallpaper |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 706 | null, // no permission for receiving assist structure |
| 707 | null, // no permission for receiving assist screenshot |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 708 | Manifest.permission.READ_PHONE_STATE, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 709 | Manifest.permission.ADD_VOICEMAIL, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 710 | Manifest.permission.USE_SIP, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 711 | Manifest.permission.PROCESS_OUTGOING_CALLS, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 712 | Manifest.permission.USE_FINGERPRINT, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 713 | Manifest.permission.BODY_SENSORS, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 714 | Manifest.permission.READ_CELL_BROADCASTS, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 715 | null, |
| 716 | Manifest.permission.READ_EXTERNAL_STORAGE, |
| 717 | Manifest.permission.WRITE_EXTERNAL_STORAGE, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 718 | null, // no permission for turning the screen on |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 719 | Manifest.permission.GET_ACCOUNTS, |
| 720 | null, // no permission for running in background |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 721 | null, // no permission for changing accessibility volume |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 722 | Manifest.permission.READ_PHONE_NUMBERS, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 723 | Manifest.permission.REQUEST_INSTALL_PACKAGES, |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 724 | null, // no permission for entering picture-in-picture on hide |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 725 | Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 726 | Manifest.permission.ANSWER_PHONE_CALLS, |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 727 | }; |
| 728 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 729 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 730 | * Specifies whether an Op should be restricted by a user restriction. |
| 731 | * Each Op should be filled with a restriction string from UserManager or |
| 732 | * null to specify it is not affected by any user restriction. |
| 733 | */ |
| 734 | private static String[] sOpRestrictions = new String[] { |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 735 | UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION |
| 736 | UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION |
| 737 | UserManager.DISALLOW_SHARE_LOCATION, //GPS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 738 | null, //VIBRATE |
| 739 | null, //READ_CONTACTS |
| 740 | null, //WRITE_CONTACTS |
Yorke Lee | 15f83c6 | 2014-08-13 14:14:29 -0700 | [diff] [blame] | 741 | UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG |
| 742 | UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 743 | null, //READ_CALENDAR |
| 744 | null, //WRITE_CALENDAR |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 745 | UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 746 | null, //POST_NOTIFICATION |
| 747 | null, //NEIGHBORING_CELLS |
| 748 | null, //CALL_PHONE |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 749 | UserManager.DISALLOW_SMS, //READ_SMS |
| 750 | UserManager.DISALLOW_SMS, //WRITE_SMS |
| 751 | UserManager.DISALLOW_SMS, //RECEIVE_SMS |
| 752 | null, //RECEIVE_EMERGENCY_SMS |
| 753 | UserManager.DISALLOW_SMS, //RECEIVE_MMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 754 | null, //RECEIVE_WAP_PUSH |
Amith Yamasani | 41c1ded | 2014-08-05 11:15:05 -0700 | [diff] [blame] | 755 | UserManager.DISALLOW_SMS, //SEND_SMS |
| 756 | UserManager.DISALLOW_SMS, //READ_ICC_SMS |
| 757 | UserManager.DISALLOW_SMS, //WRITE_ICC_SMS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 758 | null, //WRITE_SETTINGS |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 759 | UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 760 | null, //ACCESS_NOTIFICATIONS |
Makoto Onuki | 759a763 | 2015-10-28 16:43:10 -0700 | [diff] [blame] | 761 | UserManager.DISALLOW_CAMERA, //CAMERA |
Fyodor Kupolov | b501330 | 2015-04-17 17:59:14 -0700 | [diff] [blame] | 762 | UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 763 | null, //PLAY_AUDIO |
| 764 | null, //READ_CLIPBOARD |
| 765 | null, //WRITE_CLIPBOARD |
| 766 | null, //TAKE_MEDIA_BUTTONS |
| 767 | null, //TAKE_AUDIO_FOCUS |
Emily Bernier | 45775c4 | 2014-05-16 15:12:04 -0400 | [diff] [blame] | 768 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME |
| 769 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME |
| 770 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME |
| 771 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME |
| 772 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME |
| 773 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME |
| 774 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 775 | null, //WAKE_LOCK |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 776 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION |
| 777 | UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 778 | null, //GET_USAGE_STATS |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 779 | UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 780 | UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 781 | null, //PROJECT_MEDIA |
Tony Mak | 33d03a9 | 2016-06-02 15:01:16 +0100 | [diff] [blame] | 782 | null, // ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 783 | UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 784 | null, // ASSIST_STRUCTURE |
| 785 | null, // ASSIST_SCREENSHOT |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 786 | null, // READ_PHONE_STATE |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 787 | null, // ADD_VOICEMAIL |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 788 | null, // USE_SIP |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 789 | null, // PROCESS_OUTGOING_CALLS |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 790 | null, // USE_FINGERPRINT |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 791 | null, // BODY_SENSORS |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 792 | null, // READ_CELL_BROADCASTS |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 793 | null, // MOCK_LOCATION |
| 794 | null, // READ_EXTERNAL_STORAGE |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 795 | null, // WRITE_EXTERNAL_STORAGE |
| 796 | null, // TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 797 | null, // GET_ACCOUNTS |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 798 | null, // RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 799 | UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 800 | null, // READ_PHONE_NUMBERS |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 801 | null, // REQUEST_INSTALL_PACKAGES |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 802 | null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 803 | null, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 804 | null, // ANSWER_PHONE_CALLS |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 805 | }; |
| 806 | |
| 807 | /** |
| 808 | * This specifies whether each option should allow the system |
| 809 | * (and system ui) to bypass the user restriction when active. |
| 810 | */ |
| 811 | private static boolean[] sOpAllowSystemRestrictionBypass = new boolean[] { |
Fyodor Kupolov | 639e73d | 2016-02-25 11:58:21 -0800 | [diff] [blame] | 812 | true, //COARSE_LOCATION |
| 813 | true, //FINE_LOCATION |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 814 | false, //GPS |
| 815 | false, //VIBRATE |
| 816 | false, //READ_CONTACTS |
| 817 | false, //WRITE_CONTACTS |
| 818 | false, //READ_CALL_LOG |
| 819 | false, //WRITE_CALL_LOG |
| 820 | false, //READ_CALENDAR |
| 821 | false, //WRITE_CALENDAR |
Julia Reynolds | 9854d57 | 2014-07-02 14:46:02 -0400 | [diff] [blame] | 822 | true, //WIFI_SCAN |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 823 | false, //POST_NOTIFICATION |
| 824 | false, //NEIGHBORING_CELLS |
| 825 | false, //CALL_PHONE |
| 826 | false, //READ_SMS |
| 827 | false, //WRITE_SMS |
| 828 | false, //RECEIVE_SMS |
| 829 | false, //RECEIVE_EMERGECY_SMS |
| 830 | false, //RECEIVE_MMS |
| 831 | false, //RECEIVE_WAP_PUSH |
| 832 | false, //SEND_SMS |
| 833 | false, //READ_ICC_SMS |
| 834 | false, //WRITE_ICC_SMS |
| 835 | false, //WRITE_SETTINGS |
| 836 | true, //SYSTEM_ALERT_WINDOW |
| 837 | false, //ACCESS_NOTIFICATIONS |
| 838 | false, //CAMERA |
| 839 | false, //RECORD_AUDIO |
| 840 | false, //PLAY_AUDIO |
| 841 | false, //READ_CLIPBOARD |
| 842 | false, //WRITE_CLIPBOARD |
| 843 | false, //TAKE_MEDIA_BUTTONS |
| 844 | false, //TAKE_AUDIO_FOCUS |
| 845 | false, //AUDIO_MASTER_VOLUME |
| 846 | false, //AUDIO_VOICE_VOLUME |
| 847 | false, //AUDIO_RING_VOLUME |
| 848 | false, //AUDIO_MEDIA_VOLUME |
| 849 | false, //AUDIO_ALARM_VOLUME |
| 850 | false, //AUDIO_NOTIFICATION_VOLUME |
| 851 | false, //AUDIO_BLUETOOTH_VOLUME |
| 852 | false, //WAKE_LOCK |
| 853 | false, //MONITOR_LOCATION |
| 854 | false, //MONITOR_HIGH_POWER_LOCATION |
| 855 | false, //GET_USAGE_STATS |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 856 | false, //MUTE_MICROPHONE |
| 857 | true, //TOAST_WINDOW |
| 858 | false, //PROJECT_MEDIA |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 859 | false, //ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 860 | false, //WALLPAPER |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 861 | false, //ASSIST_STRUCTURE |
| 862 | false, //ASSIST_SCREENSHOT |
Svet Ganov | 16a1689 | 2015-04-16 10:32:04 -0700 | [diff] [blame] | 863 | false, //READ_PHONE_STATE |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 864 | false, //ADD_VOICEMAIL |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 865 | false, // USE_SIP |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 866 | false, // PROCESS_OUTGOING_CALLS |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 867 | false, // USE_FINGERPRINT |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 868 | false, // BODY_SENSORS |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 869 | false, // READ_CELL_BROADCASTS |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 870 | false, // MOCK_LOCATION |
| 871 | false, // READ_EXTERNAL_STORAGE |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 872 | false, // WRITE_EXTERNAL_STORAGE |
| 873 | false, // TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 874 | false, // GET_ACCOUNTS |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 875 | false, // RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 876 | false, // AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 0c1651f | 2017-03-30 16:29:10 -0700 | [diff] [blame] | 877 | false, // READ_PHONE_NUMBERS |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 878 | false, // REQUEST_INSTALL_PACKAGES |
Winson Chung | 59fda9e | 2017-01-20 16:14:51 -0800 | [diff] [blame] | 879 | false, // ENTER_PICTURE_IN_PICTURE_ON_HIDE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 880 | false, // INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 881 | false, // ANSWER_PHONE_CALLS |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 882 | }; |
| 883 | |
| 884 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 885 | * This specifies the default mode for each operation. |
| 886 | */ |
| 887 | private static int[] sOpDefaultMode = new int[] { |
| 888 | AppOpsManager.MODE_ALLOWED, |
| 889 | AppOpsManager.MODE_ALLOWED, |
| 890 | AppOpsManager.MODE_ALLOWED, |
| 891 | AppOpsManager.MODE_ALLOWED, |
| 892 | AppOpsManager.MODE_ALLOWED, |
| 893 | AppOpsManager.MODE_ALLOWED, |
| 894 | AppOpsManager.MODE_ALLOWED, |
| 895 | AppOpsManager.MODE_ALLOWED, |
| 896 | AppOpsManager.MODE_ALLOWED, |
| 897 | AppOpsManager.MODE_ALLOWED, |
| 898 | AppOpsManager.MODE_ALLOWED, |
| 899 | AppOpsManager.MODE_ALLOWED, |
| 900 | AppOpsManager.MODE_ALLOWED, |
| 901 | AppOpsManager.MODE_ALLOWED, |
| 902 | AppOpsManager.MODE_ALLOWED, |
| 903 | AppOpsManager.MODE_IGNORED, // OP_WRITE_SMS |
| 904 | AppOpsManager.MODE_ALLOWED, |
| 905 | AppOpsManager.MODE_ALLOWED, |
| 906 | AppOpsManager.MODE_ALLOWED, |
| 907 | AppOpsManager.MODE_ALLOWED, |
| 908 | AppOpsManager.MODE_ALLOWED, |
| 909 | AppOpsManager.MODE_ALLOWED, |
| 910 | AppOpsManager.MODE_ALLOWED, |
Billy Lau | 6ad2d66 | 2015-07-18 00:26:58 +0100 | [diff] [blame] | 911 | AppOpsManager.MODE_DEFAULT, // OP_WRITE_SETTINGS |
Billy Lau | 060275f | 2015-07-15 22:29:19 +0100 | [diff] [blame] | 912 | AppOpsManager.MODE_DEFAULT, // OP_SYSTEM_ALERT_WINDOW |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 913 | AppOpsManager.MODE_ALLOWED, |
| 914 | AppOpsManager.MODE_ALLOWED, |
| 915 | AppOpsManager.MODE_ALLOWED, |
| 916 | AppOpsManager.MODE_ALLOWED, |
| 917 | AppOpsManager.MODE_ALLOWED, |
| 918 | AppOpsManager.MODE_ALLOWED, |
| 919 | AppOpsManager.MODE_ALLOWED, |
| 920 | AppOpsManager.MODE_ALLOWED, |
| 921 | AppOpsManager.MODE_ALLOWED, |
| 922 | AppOpsManager.MODE_ALLOWED, |
| 923 | AppOpsManager.MODE_ALLOWED, |
| 924 | AppOpsManager.MODE_ALLOWED, |
| 925 | AppOpsManager.MODE_ALLOWED, |
| 926 | AppOpsManager.MODE_ALLOWED, |
| 927 | AppOpsManager.MODE_ALLOWED, |
| 928 | AppOpsManager.MODE_ALLOWED, |
| 929 | AppOpsManager.MODE_ALLOWED, |
| 930 | AppOpsManager.MODE_ALLOWED, |
Dianne Hackborn | 33f5ddd | 2014-07-21 15:35:45 -0700 | [diff] [blame] | 931 | AppOpsManager.MODE_DEFAULT, // OP_GET_USAGE_STATS |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 932 | AppOpsManager.MODE_ALLOWED, |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 933 | AppOpsManager.MODE_ALLOWED, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 934 | AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 935 | AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 936 | AppOpsManager.MODE_ALLOWED, |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 937 | AppOpsManager.MODE_ALLOWED, |
| 938 | AppOpsManager.MODE_ALLOWED, |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 939 | AppOpsManager.MODE_ALLOWED, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 940 | AppOpsManager.MODE_ALLOWED, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 941 | AppOpsManager.MODE_ALLOWED, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 942 | AppOpsManager.MODE_ALLOWED, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 943 | AppOpsManager.MODE_ALLOWED, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 944 | AppOpsManager.MODE_ALLOWED, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 945 | AppOpsManager.MODE_ALLOWED, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 946 | AppOpsManager.MODE_ERRORED, // OP_MOCK_LOCATION |
| 947 | AppOpsManager.MODE_ALLOWED, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 948 | AppOpsManager.MODE_ALLOWED, |
| 949 | AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN |
Svetoslav | f3f02ac | 2015-09-08 14:36:35 -0700 | [diff] [blame] | 950 | AppOpsManager.MODE_ALLOWED, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 951 | AppOpsManager.MODE_ALLOWED, // OP_RUN_IN_BACKGROUND |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 952 | AppOpsManager.MODE_ALLOWED, // OP_AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 73ec8f9 | 2016-11-10 11:24:40 -0800 | [diff] [blame] | 953 | AppOpsManager.MODE_ALLOWED, |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 954 | AppOpsManager.MODE_DEFAULT, // OP_REQUEST_INSTALL_PACKAGES |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 955 | AppOpsManager.MODE_ALLOWED, // OP_PICTURE_IN_PICTURE |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 956 | AppOpsManager.MODE_DEFAULT, // OP_INSTANT_APP_START_FOREGROUND |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 957 | AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 958 | }; |
| 959 | |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 960 | /** |
| 961 | * This specifies whether each option is allowed to be reset |
| 962 | * when resetting all app preferences. Disable reset for |
| 963 | * app ops that are under strong control of some part of the |
| 964 | * system (such as OP_WRITE_SMS, which should be allowed only |
| 965 | * for whichever app is selected as the current SMS app). |
| 966 | */ |
| 967 | private static boolean[] sOpDisableReset = new boolean[] { |
| 968 | false, |
| 969 | false, |
| 970 | false, |
| 971 | false, |
| 972 | false, |
| 973 | false, |
| 974 | false, |
| 975 | false, |
| 976 | false, |
| 977 | false, |
| 978 | false, |
| 979 | false, |
| 980 | false, |
| 981 | false, |
| 982 | false, |
| 983 | true, // OP_WRITE_SMS |
| 984 | false, |
| 985 | false, |
| 986 | false, |
| 987 | false, |
| 988 | false, |
| 989 | false, |
| 990 | false, |
| 991 | false, |
| 992 | false, |
| 993 | false, |
| 994 | false, |
| 995 | false, |
| 996 | false, |
| 997 | false, |
| 998 | false, |
| 999 | false, |
| 1000 | false, |
| 1001 | false, |
| 1002 | false, |
| 1003 | false, |
| 1004 | false, |
| 1005 | false, |
| 1006 | false, |
| 1007 | false, |
| 1008 | false, |
| 1009 | false, |
| 1010 | false, |
Dianne Hackborn | e22b3b1 | 2014-05-07 18:06:44 -0700 | [diff] [blame] | 1011 | false, |
Emily Bernier | 22c921a | 2014-05-28 11:01:32 -0400 | [diff] [blame] | 1012 | false, |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1013 | false, |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 1014 | false, |
Jeff Davidson | 0554260 | 2014-08-11 14:07:27 -0700 | [diff] [blame] | 1015 | false, |
Benjamin Franz | f3ece36 | 2015-02-11 10:51:10 +0000 | [diff] [blame] | 1016 | false, |
Dianne Hackborn | d59a5d5 | 2015-04-04 14:52:14 -0700 | [diff] [blame] | 1017 | false, |
| 1018 | false, |
Svet Ganov | c330009 | 2015-04-17 09:07:22 -0700 | [diff] [blame] | 1019 | false, |
Svetoslav | 5335b67 | 2015-04-29 12:00:51 -0700 | [diff] [blame] | 1020 | false, |
Svetoslav | c656e6f | 2015-04-29 14:08:16 -0700 | [diff] [blame] | 1021 | false, |
Svetoslav | 4af76a5 | 2015-04-29 15:29:46 -0700 | [diff] [blame] | 1022 | false, |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1023 | false, |
Svet Ganov | ede4316 | 2015-05-02 17:42:44 -0700 | [diff] [blame] | 1024 | false, |
Svet Ganov | f7e9cf4 | 2015-05-13 10:40:31 -0700 | [diff] [blame] | 1025 | false, |
Svet Ganov | 921c7df | 2015-06-29 21:51:41 -0700 | [diff] [blame] | 1026 | false, |
| 1027 | false, |
Dianne Hackborn | 280a64e | 2015-07-13 14:48:08 -0700 | [diff] [blame] | 1028 | false, |
| 1029 | false, |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1030 | false, |
| 1031 | false, |
Jean-Michel Trivi | 3f0945a | 2016-11-11 10:05:18 -0800 | [diff] [blame] | 1032 | false, // OP_AUDIO_ACCESSIBILITY_VOLUME |
Chad Brubaker | 73ec8f9 | 2016-11-10 11:24:40 -0800 | [diff] [blame] | 1033 | false, |
Suprabh Shukla | 2f34b1a | 2016-12-16 14:47:25 -0800 | [diff] [blame] | 1034 | false, // OP_REQUEST_INSTALL_PACKAGES |
Winson Chung | f4ac063 | 2017-03-17 12:34:12 -0700 | [diff] [blame] | 1035 | false, // OP_PICTURE_IN_PICTURE |
Chad Brubaker | 97b383f | 2017-02-02 15:04:35 -0800 | [diff] [blame] | 1036 | false, |
Eugene Susla | cae3d3e | 2017-01-31 11:08:11 -0800 | [diff] [blame] | 1037 | false, // ANSWER_PHONE_CALLS |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1038 | }; |
| 1039 | |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1040 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1041 | * Mapping from an app op name to the app op code. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1042 | */ |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1043 | private static HashMap<String, Integer> sOpStrToOp = new HashMap<>(); |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1044 | |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1045 | /** |
| 1046 | * Mapping from a permission to the corresponding app op. |
| 1047 | */ |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1048 | private static HashMap<String, Integer> sPermToOp = new HashMap<>(); |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1049 | |
| 1050 | static { |
| 1051 | if (sOpToSwitch.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1052 | throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1053 | + " should be " + _NUM_OP); |
| 1054 | } |
| 1055 | if (sOpToString.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1056 | throw new IllegalStateException("sOpToString length " + sOpToString.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1057 | + " should be " + _NUM_OP); |
| 1058 | } |
| 1059 | if (sOpNames.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1060 | throw new IllegalStateException("sOpNames length " + sOpNames.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1061 | + " should be " + _NUM_OP); |
| 1062 | } |
| 1063 | if (sOpPerms.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1064 | throw new IllegalStateException("sOpPerms length " + sOpPerms.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1065 | + " should be " + _NUM_OP); |
| 1066 | } |
| 1067 | if (sOpDefaultMode.length != _NUM_OP) { |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1068 | throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length |
| 1069 | + " should be " + _NUM_OP); |
| 1070 | } |
| 1071 | if (sOpDisableReset.length != _NUM_OP) { |
| 1072 | throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1073 | + " should be " + _NUM_OP); |
| 1074 | } |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1075 | if (sOpRestrictions.length != _NUM_OP) { |
| 1076 | throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length |
| 1077 | + " should be " + _NUM_OP); |
| 1078 | } |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1079 | if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) { |
| 1080 | throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length " |
| 1081 | + sOpRestrictions.length + " should be " + _NUM_OP); |
| 1082 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1083 | for (int i=0; i<_NUM_OP; i++) { |
| 1084 | if (sOpToString[i] != null) { |
| 1085 | sOpStrToOp.put(sOpToString[i], i); |
| 1086 | } |
| 1087 | } |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1088 | for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) { |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1089 | if (sOpPerms[op] != null) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1090 | sPermToOp.put(sOpPerms[op], op); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1091 | } |
| 1092 | } |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 1095 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1096 | * Retrieve the op switch that controls the given operation. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1097 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1098 | */ |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 1099 | public static int opToSwitch(int op) { |
| 1100 | return sOpToSwitch[op]; |
| 1101 | } |
| 1102 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1103 | /** |
| 1104 | * Retrieve a non-localized name for the operation, for debugging output. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1105 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1106 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1107 | public static String opToName(int op) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1108 | if (op == OP_NONE) return "NONE"; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1109 | return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")"); |
| 1110 | } |
| 1111 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1112 | /** |
Dianne Hackborn | 7b7c58b | 2014-12-02 18:32:20 -0800 | [diff] [blame] | 1113 | * @hide |
| 1114 | */ |
| 1115 | public static int strDebugOpToOp(String op) { |
| 1116 | for (int i=0; i<sOpNames.length; i++) { |
| 1117 | if (sOpNames[i].equals(op)) { |
| 1118 | return i; |
| 1119 | } |
| 1120 | } |
| 1121 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 1122 | } |
| 1123 | |
| 1124 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1125 | * Retrieve the permission associated with an operation, or null if there is not one. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1126 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1127 | */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1128 | public static String opToPermission(int op) { |
| 1129 | return sOpPerms[op]; |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1130 | } |
| 1131 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1132 | /** |
Jason Monk | 6206299 | 2014-05-06 09:55:28 -0400 | [diff] [blame] | 1133 | * Retrieve the user restriction associated with an operation, or null if there is not one. |
| 1134 | * @hide |
| 1135 | */ |
| 1136 | public static String opToRestriction(int op) { |
| 1137 | return sOpRestrictions[op]; |
| 1138 | } |
| 1139 | |
| 1140 | /** |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1141 | * Retrieve the app op code for a permission, or null if there is not one. |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1142 | * This API is intended to be used for mapping runtime or appop permissions |
| 1143 | * to the corresponding app op. |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1144 | * @hide |
| 1145 | */ |
| 1146 | public static int permissionToOpCode(String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1147 | Integer boxedOpCode = sPermToOp.get(permission); |
Svet Ganov | 019d230 | 2015-05-04 11:07:38 -0700 | [diff] [blame] | 1148 | return boxedOpCode != null ? boxedOpCode : OP_NONE; |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /** |
Jason Monk | 1c7c319 | 2014-06-26 12:52:18 -0400 | [diff] [blame] | 1152 | * Retrieve whether the op allows the system (and system ui) to |
| 1153 | * bypass the user restriction. |
| 1154 | * @hide |
| 1155 | */ |
| 1156 | public static boolean opAllowSystemBypassRestriction(int op) { |
| 1157 | return sOpAllowSystemRestrictionBypass[op]; |
| 1158 | } |
| 1159 | |
| 1160 | /** |
David Braun | f5d8319 | 2013-09-16 13:43:51 -0700 | [diff] [blame] | 1161 | * Retrieve the default mode for the operation. |
| 1162 | * @hide |
| 1163 | */ |
| 1164 | public static int opToDefaultMode(int op) { |
| 1165 | return sOpDefaultMode[op]; |
| 1166 | } |
| 1167 | |
| 1168 | /** |
Dianne Hackborn | 8828d3a | 2013-09-25 16:47:10 -0700 | [diff] [blame] | 1169 | * Retrieve whether the op allows itself to be reset. |
| 1170 | * @hide |
| 1171 | */ |
| 1172 | public static boolean opAllowsReset(int op) { |
| 1173 | return !sOpDisableReset[op]; |
| 1174 | } |
| 1175 | |
| 1176 | /** |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1177 | * Class holding all of the operation information associated with an app. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1178 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1179 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1180 | public static class PackageOps implements Parcelable { |
| 1181 | private final String mPackageName; |
| 1182 | private final int mUid; |
| 1183 | private final List<OpEntry> mEntries; |
| 1184 | |
| 1185 | public PackageOps(String packageName, int uid, List<OpEntry> entries) { |
| 1186 | mPackageName = packageName; |
| 1187 | mUid = uid; |
| 1188 | mEntries = entries; |
| 1189 | } |
| 1190 | |
| 1191 | public String getPackageName() { |
| 1192 | return mPackageName; |
| 1193 | } |
| 1194 | |
| 1195 | public int getUid() { |
| 1196 | return mUid; |
| 1197 | } |
| 1198 | |
| 1199 | public List<OpEntry> getOps() { |
| 1200 | return mEntries; |
| 1201 | } |
| 1202 | |
| 1203 | @Override |
| 1204 | public int describeContents() { |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | @Override |
| 1209 | public void writeToParcel(Parcel dest, int flags) { |
| 1210 | dest.writeString(mPackageName); |
| 1211 | dest.writeInt(mUid); |
| 1212 | dest.writeInt(mEntries.size()); |
| 1213 | for (int i=0; i<mEntries.size(); i++) { |
| 1214 | mEntries.get(i).writeToParcel(dest, flags); |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | PackageOps(Parcel source) { |
| 1219 | mPackageName = source.readString(); |
| 1220 | mUid = source.readInt(); |
| 1221 | mEntries = new ArrayList<OpEntry>(); |
| 1222 | final int N = source.readInt(); |
| 1223 | for (int i=0; i<N; i++) { |
| 1224 | mEntries.add(OpEntry.CREATOR.createFromParcel(source)); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | public static final Creator<PackageOps> CREATOR = new Creator<PackageOps>() { |
| 1229 | @Override public PackageOps createFromParcel(Parcel source) { |
| 1230 | return new PackageOps(source); |
| 1231 | } |
| 1232 | |
| 1233 | @Override public PackageOps[] newArray(int size) { |
| 1234 | return new PackageOps[size]; |
| 1235 | } |
| 1236 | }; |
| 1237 | } |
| 1238 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1239 | /** |
| 1240 | * Class holding the information about one unique operation of an application. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1241 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1242 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1243 | public static class OpEntry implements Parcelable { |
| 1244 | private final int mOp; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1245 | private final int mMode; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1246 | private final long mTime; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1247 | private final long mRejectTime; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1248 | private final int mDuration; |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1249 | private final int mProxyUid; |
| 1250 | private final String mProxyPackageName; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1251 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1252 | public OpEntry(int op, int mode, long time, long rejectTime, int duration, |
| 1253 | int proxyUid, String proxyPackage) { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1254 | mOp = op; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1255 | mMode = mode; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1256 | mTime = time; |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1257 | mRejectTime = rejectTime; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1258 | mDuration = duration; |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1259 | mProxyUid = proxyUid; |
| 1260 | mProxyPackageName = proxyPackage; |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | public int getOp() { |
| 1264 | return mOp; |
| 1265 | } |
| 1266 | |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1267 | public int getMode() { |
| 1268 | return mMode; |
| 1269 | } |
| 1270 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1271 | public long getTime() { |
| 1272 | return mTime; |
| 1273 | } |
| 1274 | |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1275 | public long getRejectTime() { |
| 1276 | return mRejectTime; |
| 1277 | } |
| 1278 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1279 | public boolean isRunning() { |
| 1280 | return mDuration == -1; |
| 1281 | } |
| 1282 | |
| 1283 | public int getDuration() { |
| 1284 | return mDuration == -1 ? (int)(System.currentTimeMillis()-mTime) : mDuration; |
| 1285 | } |
| 1286 | |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1287 | public int getProxyUid() { |
| 1288 | return mProxyUid; |
| 1289 | } |
| 1290 | |
| 1291 | public String getProxyPackageName() { |
| 1292 | return mProxyPackageName; |
| 1293 | } |
| 1294 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1295 | @Override |
| 1296 | public int describeContents() { |
| 1297 | return 0; |
| 1298 | } |
| 1299 | |
| 1300 | @Override |
| 1301 | public void writeToParcel(Parcel dest, int flags) { |
| 1302 | dest.writeInt(mOp); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1303 | dest.writeInt(mMode); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1304 | dest.writeLong(mTime); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1305 | dest.writeLong(mRejectTime); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1306 | dest.writeInt(mDuration); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1307 | dest.writeInt(mProxyUid); |
| 1308 | dest.writeString(mProxyPackageName); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | OpEntry(Parcel source) { |
| 1312 | mOp = source.readInt(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1313 | mMode = source.readInt(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1314 | mTime = source.readLong(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1315 | mRejectTime = source.readLong(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1316 | mDuration = source.readInt(); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1317 | mProxyUid = source.readInt(); |
| 1318 | mProxyPackageName = source.readString(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | public static final Creator<OpEntry> CREATOR = new Creator<OpEntry>() { |
| 1322 | @Override public OpEntry createFromParcel(Parcel source) { |
| 1323 | return new OpEntry(source); |
| 1324 | } |
| 1325 | |
| 1326 | @Override public OpEntry[] newArray(int size) { |
| 1327 | return new OpEntry[size]; |
| 1328 | } |
| 1329 | }; |
| 1330 | } |
| 1331 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1332 | /** |
| 1333 | * Callback for notification of changes to operation state. |
| 1334 | */ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1335 | public interface OnOpChangedListener { |
| 1336 | public void onOpChanged(String op, String packageName); |
| 1337 | } |
| 1338 | |
| 1339 | /** |
| 1340 | * Callback for notification of changes to operation state. |
| 1341 | * This allows you to see the raw op codes instead of strings. |
| 1342 | * @hide |
| 1343 | */ |
| 1344 | public static class OnOpChangedInternalListener implements OnOpChangedListener { |
| 1345 | public void onOpChanged(String op, String packageName) { } |
| 1346 | public void onOpChanged(int op, String packageName) { } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1347 | } |
| 1348 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1349 | AppOpsManager(Context context, IAppOpsService service) { |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1350 | mContext = context; |
| 1351 | mService = service; |
| 1352 | } |
| 1353 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1354 | /** |
| 1355 | * Retrieve current operation state for all applications. |
| 1356 | * |
| 1357 | * @param ops The set of operations you are interested in, or null if you want all of them. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1358 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1359 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1360 | public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) { |
| 1361 | try { |
| 1362 | return mService.getPackagesForOps(ops); |
| 1363 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1364 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1365 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1366 | } |
| 1367 | |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1368 | /** |
| 1369 | * Retrieve current operation state for one application. |
| 1370 | * |
| 1371 | * @param uid The uid of the application of interest. |
| 1372 | * @param packageName The name of the application of interest. |
| 1373 | * @param ops The set of operations you are interested in, or null if you want all of them. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1374 | * @hide |
Dianne Hackborn | d7d28e6 | 2013-02-12 14:59:53 -0800 | [diff] [blame] | 1375 | */ |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 1376 | public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) { |
| 1377 | try { |
| 1378 | return mService.getOpsForPackage(uid, packageName, ops); |
| 1379 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1380 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 1381 | } |
Dianne Hackborn | 72e3983 | 2013-01-18 18:36:09 -0800 | [diff] [blame] | 1382 | } |
| 1383 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 1384 | /** |
| 1385 | * Sets given app op in the specified mode for app ops in the UID. |
| 1386 | * This applies to all apps currently in the UID or installed in |
| 1387 | * this UID in the future. |
| 1388 | * |
| 1389 | * @param code The app op. |
| 1390 | * @param uid The UID for which to set the app. |
| 1391 | * @param mode The app op mode to set. |
| 1392 | * @hide |
| 1393 | */ |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 1394 | public void setUidMode(int code, int uid, int mode) { |
| 1395 | try { |
| 1396 | mService.setUidMode(code, uid, mode); |
| 1397 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1398 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 1399 | } |
| 1400 | } |
| 1401 | |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 1402 | /** |
| 1403 | * Sets given app op in the specified mode for app ops in the UID. |
| 1404 | * This applies to all apps currently in the UID or installed in |
| 1405 | * this UID in the future. |
| 1406 | * |
| 1407 | * @param appOp The app op. |
| 1408 | * @param uid The UID for which to set the app. |
| 1409 | * @param mode The app op mode to set. |
| 1410 | * @hide |
| 1411 | */ |
| 1412 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 1413 | @RequiresPermission(android.Manifest.permission.UPDATE_APP_OPS_STATS) |
Svet Ganov | ae0e03a | 2016-02-25 18:22:10 -0800 | [diff] [blame] | 1414 | public void setUidMode(String appOp, int uid, int mode) { |
| 1415 | try { |
| 1416 | mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode); |
| 1417 | } catch (RemoteException e) { |
| 1418 | throw e.rethrowFromSystemServer(); |
| 1419 | } |
| 1420 | } |
| 1421 | |
Svet Ganov | 2af5708 | 2015-07-30 08:44:20 -0700 | [diff] [blame] | 1422 | /** @hide */ |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 1423 | public void setUserRestriction(int code, boolean restricted, IBinder token) { |
Ruben Brunk | 29931bc | 2016-03-11 00:24:26 -0800 | [diff] [blame] | 1424 | setUserRestriction(code, restricted, token, /*exceptionPackages*/null); |
| 1425 | } |
| 1426 | |
| 1427 | /** @hide */ |
| 1428 | public void setUserRestriction(int code, boolean restricted, IBinder token, |
| 1429 | String[] exceptionPackages) { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 1430 | setUserRestrictionForUser(code, restricted, token, exceptionPackages, mContext.getUserId()); |
| 1431 | } |
| 1432 | |
| 1433 | /** @hide */ |
| 1434 | public void setUserRestrictionForUser(int code, boolean restricted, IBinder token, |
| 1435 | String[] exceptionPackages, int userId) { |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 1436 | try { |
Svetoslav Ganov | e33f613 | 2016-06-01 16:25:31 -0700 | [diff] [blame] | 1437 | mService.setUserRestriction(code, restricted, token, userId, exceptionPackages); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 1438 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1439 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 9cea80cd | 2016-02-16 11:47:00 -0800 | [diff] [blame] | 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | /** @hide */ |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1444 | public void setMode(int code, int uid, String packageName, int mode) { |
| 1445 | try { |
| 1446 | mService.setMode(code, uid, packageName, mode); |
| 1447 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1448 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 5e45ee6 | 2013-01-24 19:13:44 -0800 | [diff] [blame] | 1449 | } |
| 1450 | } |
| 1451 | |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1452 | /** |
| 1453 | * Set a non-persisted restriction on an audio operation at a stream-level. |
| 1454 | * Restrictions are temporary additional constraints imposed on top of the persisted rules |
| 1455 | * defined by {@link #setMode}. |
| 1456 | * |
| 1457 | * @param code The operation to restrict. |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 1458 | * @param usage The {@link android.media.AudioAttributes} usage value. |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1459 | * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict. |
| 1460 | * @param exceptionPackages Optional list of packages to exclude from the restriction. |
| 1461 | * @hide |
| 1462 | */ |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 1463 | public void setRestriction(int code, @AttributeUsage int usage, int mode, |
| 1464 | String[] exceptionPackages) { |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1465 | try { |
| 1466 | final int uid = Binder.getCallingUid(); |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 1467 | mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1468 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1469 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1470 | } |
| 1471 | } |
| 1472 | |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 1473 | /** @hide */ |
| 1474 | public void resetAllModes() { |
| 1475 | try { |
Dianne Hackborn | 7b7c58b | 2014-12-02 18:32:20 -0800 | [diff] [blame] | 1476 | mService.resetAllModes(UserHandle.myUserId(), null); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 1477 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1478 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 607b414 | 2013-08-02 18:10:10 -0700 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1482 | /** |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1483 | * Gets the app op name associated with a given permission. |
| 1484 | * The app op name is one of the public constants defined |
| 1485 | * in this class such as {@link #OPSTR_COARSE_LOCATION}. |
Svetoslav Ganov | eaca4c5 | 2016-05-05 18:08:00 -0700 | [diff] [blame] | 1486 | * This API is intended to be used for mapping runtime |
| 1487 | * permissions to the corresponding app op. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1488 | * |
| 1489 | * @param permission The permission. |
| 1490 | * @return The app op associated with the permission or null. |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1491 | */ |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1492 | public static String permissionToOp(String permission) { |
Svet Ganov | da0acdf | 2017-02-15 10:28:51 -0800 | [diff] [blame] | 1493 | final Integer opCode = sPermToOp.get(permission); |
Svet Ganov | b9d71a6 | 2015-04-30 10:38:13 -0700 | [diff] [blame] | 1494 | if (opCode == null) { |
| 1495 | return null; |
| 1496 | } |
| 1497 | return sOpToString[opCode]; |
Svet Ganov | fbf01f7 | 2015-04-28 18:39:06 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1501 | * Monitor for changes to the operating mode for the given op in the given app package. |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 1502 | * @param op The operation to monitor, one of OPSTR_*. |
| 1503 | * @param packageName The name of the application to monitor. |
| 1504 | * @param callback Where to report changes. |
| 1505 | */ |
| 1506 | public void startWatchingMode(String op, String packageName, |
| 1507 | final OnOpChangedListener callback) { |
| 1508 | startWatchingMode(strOpToOp(op), packageName, callback); |
| 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Monitor for changes to the operating mode for the given op in the given app package. |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1513 | * @param op The operation to monitor, one of OP_*. |
| 1514 | * @param packageName The name of the application to monitor. |
| 1515 | * @param callback Where to report changes. |
Dianne Hackborn | e4cb66f | 2013-10-02 10:34:02 -0700 | [diff] [blame] | 1516 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1517 | */ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1518 | public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1519 | synchronized (mModeWatchers) { |
| 1520 | IAppOpsCallback cb = mModeWatchers.get(callback); |
| 1521 | if (cb == null) { |
| 1522 | cb = new IAppOpsCallback.Stub() { |
Dianne Hackborn | bef28fe | 2015-10-29 17:57:11 -0700 | [diff] [blame] | 1523 | public void opChanged(int op, int uid, String packageName) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1524 | if (callback instanceof OnOpChangedInternalListener) { |
| 1525 | ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName); |
| 1526 | } |
| 1527 | if (sOpToString[op] != null) { |
| 1528 | callback.onOpChanged(sOpToString[op], packageName); |
| 1529 | } |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1530 | } |
| 1531 | }; |
| 1532 | mModeWatchers.put(callback, cb); |
| 1533 | } |
| 1534 | try { |
| 1535 | mService.startWatchingMode(op, packageName, cb); |
| 1536 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1537 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1538 | } |
| 1539 | } |
| 1540 | } |
| 1541 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1542 | /** |
| 1543 | * Stop monitoring that was previously started with {@link #startWatchingMode}. All |
| 1544 | * monitoring associated with this callback will be removed. |
| 1545 | */ |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1546 | public void stopWatchingMode(OnOpChangedListener callback) { |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1547 | synchronized (mModeWatchers) { |
| 1548 | IAppOpsCallback cb = mModeWatchers.get(callback); |
| 1549 | if (cb != null) { |
| 1550 | try { |
| 1551 | mService.stopWatchingMode(cb); |
| 1552 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1553 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | } |
| 1558 | |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1559 | private String buildSecurityExceptionMsg(int op, int uid, String packageName) { |
| 1560 | return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op]; |
| 1561 | } |
| 1562 | |
Adam Lesinski | b5cf61b | 2014-08-18 16:10:28 -0700 | [diff] [blame] | 1563 | /** |
| 1564 | * {@hide} |
| 1565 | */ |
| 1566 | public static int strOpToOp(String op) { |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1567 | Integer val = sOpStrToOp.get(op); |
| 1568 | if (val == null) { |
| 1569 | throw new IllegalArgumentException("Unknown operation string: " + op); |
| 1570 | } |
| 1571 | return val; |
| 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * Do a quick check for whether an application might be able to perform an operation. |
| 1576 | * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String)} |
| 1577 | * or {@link #startOp(String, int, String)} for your actual security checks, which also |
| 1578 | * ensure that the given uid and package name are consistent. This function can just be |
| 1579 | * used for a quick check to see if an operation has been disabled for the application, |
| 1580 | * as an early reject of some work. This does not modify the time stamp or other data |
| 1581 | * about the operation. |
| 1582 | * @param op The operation to check. One of the OPSTR_* constants. |
| 1583 | * @param uid The user id of the application attempting to perform the operation. |
| 1584 | * @param packageName The name of the application attempting to perform the operation. |
| 1585 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1586 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1587 | * causing the app to crash). |
| 1588 | * @throws SecurityException If the app has been configured to crash on this op. |
| 1589 | */ |
| 1590 | public int checkOp(String op, int uid, String packageName) { |
| 1591 | return checkOp(strOpToOp(op), uid, packageName); |
| 1592 | } |
| 1593 | |
| 1594 | /** |
John Spurlock | 925b85e | 2014-03-10 16:52:11 -0400 | [diff] [blame] | 1595 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1596 | * returns {@link #MODE_ERRORED}. |
| 1597 | */ |
| 1598 | public int checkOpNoThrow(String op, int uid, String packageName) { |
| 1599 | return checkOpNoThrow(strOpToOp(op), uid, packageName); |
| 1600 | } |
| 1601 | |
| 1602 | /** |
| 1603 | * Make note of an application performing an operation. Note that you must pass |
| 1604 | * in both the uid and name of the application to be checked; this function will verify |
| 1605 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 1606 | * succeeds, the last execution time of the operation for this app will be updated to |
| 1607 | * the current time. |
| 1608 | * @param op The operation to note. One of the OPSTR_* constants. |
| 1609 | * @param uid The user id of the application attempting to perform the operation. |
| 1610 | * @param packageName The name of the application attempting to perform the operation. |
| 1611 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1612 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1613 | * causing the app to crash). |
| 1614 | * @throws SecurityException If the app has been configured to crash on this op. |
| 1615 | */ |
| 1616 | public int noteOp(String op, int uid, String packageName) { |
| 1617 | return noteOp(strOpToOp(op), uid, packageName); |
| 1618 | } |
| 1619 | |
| 1620 | /** |
| 1621 | * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it |
| 1622 | * returns {@link #MODE_ERRORED}. |
| 1623 | */ |
| 1624 | public int noteOpNoThrow(String op, int uid, String packageName) { |
| 1625 | return noteOpNoThrow(strOpToOp(op), uid, packageName); |
| 1626 | } |
| 1627 | |
| 1628 | /** |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1629 | * Make note of an application performing an operation on behalf of another |
| 1630 | * application when handling an IPC. Note that you must pass the package name |
| 1631 | * of the application that is being proxied while its UID will be inferred from |
| 1632 | * the IPC state; this function will verify that the calling uid and proxied |
| 1633 | * package name match, and if not, return {@link #MODE_IGNORED}. If this call |
| 1634 | * succeeds, the last execution time of the operation for the proxied app and |
| 1635 | * your app will be updated to the current time. |
| 1636 | * @param op The operation to note. One of the OPSTR_* constants. |
| 1637 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 1638 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1639 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1640 | * causing the app to crash). |
| 1641 | * @throws SecurityException If the app has been configured to crash on this op. |
| 1642 | */ |
| 1643 | public int noteProxyOp(String op, String proxiedPackageName) { |
| 1644 | return noteProxyOp(strOpToOp(op), proxiedPackageName); |
| 1645 | } |
| 1646 | |
| 1647 | /** |
| 1648 | * Like {@link #noteProxyOp(String, String)} but instead |
| 1649 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 1650 | */ |
| 1651 | public int noteProxyOpNoThrow(String op, String proxiedPackageName) { |
| 1652 | return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName); |
| 1653 | } |
| 1654 | |
| 1655 | /** |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1656 | * Report that an application has started executing a long-running operation. Note that you |
| 1657 | * must pass in both the uid and name of the application to be checked; this function will |
| 1658 | * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 1659 | * succeeds, the last execution time of the operation for this app will be updated to |
| 1660 | * the current time and the operation will be marked as "running". In this case you must |
| 1661 | * later call {@link #finishOp(String, int, String)} to report when the application is no |
| 1662 | * longer performing the operation. |
| 1663 | * @param op The operation to start. One of the OPSTR_* constants. |
| 1664 | * @param uid The user id of the application attempting to perform the operation. |
| 1665 | * @param packageName The name of the application attempting to perform the operation. |
| 1666 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1667 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1668 | * causing the app to crash). |
| 1669 | * @throws SecurityException If the app has been configured to crash on this op. |
| 1670 | */ |
| 1671 | public int startOp(String op, int uid, String packageName) { |
| 1672 | return startOp(strOpToOp(op), uid, packageName); |
| 1673 | } |
| 1674 | |
| 1675 | /** |
| 1676 | * Like {@link #startOp} but instead of throwing a {@link SecurityException} it |
| 1677 | * returns {@link #MODE_ERRORED}. |
| 1678 | */ |
| 1679 | public int startOpNoThrow(String op, int uid, String packageName) { |
| 1680 | return startOpNoThrow(strOpToOp(op), uid, packageName); |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * Report that an application is no longer performing an operation that had previously |
| 1685 | * been started with {@link #startOp(String, int, String)}. There is no validation of input |
| 1686 | * or result; the parameters supplied here must be the exact same ones previously passed |
| 1687 | * in when starting the operation. |
| 1688 | */ |
| 1689 | public void finishOp(String op, int uid, String packageName) { |
| 1690 | finishOp(strOpToOp(op), uid, packageName); |
| 1691 | } |
| 1692 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1693 | /** |
| 1694 | * Do a quick check for whether an application might be able to perform an operation. |
| 1695 | * This is <em>not</em> a security check; you must use {@link #noteOp(int, int, String)} |
| 1696 | * or {@link #startOp(int, int, String)} for your actual security checks, which also |
| 1697 | * ensure that the given uid and package name are consistent. This function can just be |
| 1698 | * used for a quick check to see if an operation has been disabled for the application, |
| 1699 | * as an early reject of some work. This does not modify the time stamp or other data |
| 1700 | * about the operation. |
| 1701 | * @param op The operation to check. One of the OP_* constants. |
| 1702 | * @param uid The user id of the application attempting to perform the operation. |
| 1703 | * @param packageName The name of the application attempting to perform the operation. |
| 1704 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1705 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1706 | * causing the app to crash). |
| 1707 | * @throws SecurityException If the app has been configured to crash on this op. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1708 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1709 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1710 | public int checkOp(int op, int uid, String packageName) { |
| 1711 | try { |
| 1712 | int mode = mService.checkOperation(op, uid, packageName); |
| 1713 | if (mode == MODE_ERRORED) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1714 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1715 | } |
| 1716 | return mode; |
| 1717 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1718 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1719 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1720 | } |
| 1721 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1722 | /** |
| 1723 | * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it |
| 1724 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1725 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1726 | */ |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1727 | public int checkOpNoThrow(int op, int uid, String packageName) { |
| 1728 | try { |
| 1729 | return mService.checkOperation(op, uid, packageName); |
| 1730 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1731 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1732 | } |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1733 | } |
| 1734 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1735 | /** |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 1736 | * Do a quick check to validate if a package name belongs to a UID. |
| 1737 | * |
| 1738 | * @throws SecurityException if the package name doesn't belong to the given |
| 1739 | * UID, or if ownership cannot be verified. |
| 1740 | */ |
| 1741 | public void checkPackage(int uid, String packageName) { |
| 1742 | try { |
| 1743 | if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) { |
| 1744 | throw new SecurityException( |
| 1745 | "Package " + packageName + " does not belong to " + uid); |
| 1746 | } |
| 1747 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1748 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 911d7f4 | 2013-09-05 18:11:45 -0700 | [diff] [blame] | 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | /** |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1753 | * Like {@link #checkOp} but at a stream-level for audio operations. |
| 1754 | * @hide |
| 1755 | */ |
| 1756 | public int checkAudioOp(int op, int stream, int uid, String packageName) { |
| 1757 | try { |
| 1758 | final int mode = mService.checkAudioOperation(op, stream, uid, packageName); |
| 1759 | if (mode == MODE_ERRORED) { |
| 1760 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
| 1761 | } |
| 1762 | return mode; |
| 1763 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1764 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1765 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /** |
| 1769 | * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it |
| 1770 | * returns {@link #MODE_ERRORED}. |
| 1771 | * @hide |
| 1772 | */ |
| 1773 | public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) { |
| 1774 | try { |
| 1775 | return mService.checkAudioOperation(op, stream, uid, packageName); |
| 1776 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1777 | throw e.rethrowFromSystemServer(); |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1778 | } |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1782 | * Make note of an application performing an operation. Note that you must pass |
| 1783 | * in both the uid and name of the application to be checked; this function will verify |
| 1784 | * that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 1785 | * succeeds, the last execution time of the operation for this app will be updated to |
| 1786 | * the current time. |
| 1787 | * @param op The operation to note. One of the OP_* constants. |
| 1788 | * @param uid The user id of the application attempting to perform the operation. |
| 1789 | * @param packageName The name of the application attempting to perform the operation. |
| 1790 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1791 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1792 | * causing the app to crash). |
| 1793 | * @throws SecurityException If the app has been configured to crash on this op. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1794 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1795 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1796 | public int noteOp(int op, int uid, String packageName) { |
| 1797 | try { |
| 1798 | int mode = mService.noteOperation(op, uid, packageName); |
| 1799 | if (mode == MODE_ERRORED) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1800 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1801 | } |
| 1802 | return mode; |
| 1803 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1804 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1805 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1808 | /** |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1809 | * Make note of an application performing an operation on behalf of another |
| 1810 | * application when handling an IPC. Note that you must pass the package name |
| 1811 | * of the application that is being proxied while its UID will be inferred from |
| 1812 | * the IPC state; this function will verify that the calling uid and proxied |
| 1813 | * package name match, and if not, return {@link #MODE_IGNORED}. If this call |
| 1814 | * succeeds, the last execution time of the operation for the proxied app and |
| 1815 | * your app will be updated to the current time. |
| 1816 | * @param op The operation to note. One of the OPSTR_* constants. |
| 1817 | * @param proxiedPackageName The name of the application calling into the proxy application. |
| 1818 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1819 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1820 | * causing the app to crash). |
| 1821 | * @throws SecurityException If the proxy or proxied app has been configured to |
| 1822 | * crash on this op. |
| 1823 | * |
| 1824 | * @hide |
| 1825 | */ |
| 1826 | public int noteProxyOp(int op, String proxiedPackageName) { |
| 1827 | int mode = noteProxyOpNoThrow(op, proxiedPackageName); |
| 1828 | if (mode == MODE_ERRORED) { |
| 1829 | throw new SecurityException("Proxy package " + mContext.getOpPackageName() |
| 1830 | + " from uid " + Process.myUid() + " or calling package " |
| 1831 | + proxiedPackageName + " from uid " + Binder.getCallingUid() |
| 1832 | + " not allowed to perform " + sOpNames[op]); |
| 1833 | } |
| 1834 | return mode; |
| 1835 | } |
| 1836 | |
| 1837 | /** |
| 1838 | * Like {@link #noteProxyOp(int, String)} but instead |
| 1839 | * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}. |
| 1840 | * @hide |
| 1841 | */ |
| 1842 | public int noteProxyOpNoThrow(int op, String proxiedPackageName) { |
| 1843 | try { |
| 1844 | return mService.noteProxyOperation(op, mContext.getOpPackageName(), |
| 1845 | Binder.getCallingUid(), proxiedPackageName); |
| 1846 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1847 | throw e.rethrowFromSystemServer(); |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1848 | } |
Svet Ganov | 99b6043 | 2015-06-27 13:15:22 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
| 1851 | /** |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1852 | * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it |
| 1853 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1854 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1855 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1856 | public int noteOpNoThrow(int op, int uid, String packageName) { |
| 1857 | try { |
| 1858 | return mService.noteOperation(op, uid, packageName); |
| 1859 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1860 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1861 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1862 | } |
| 1863 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1864 | /** @hide */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1865 | public int noteOp(int op) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1866 | return noteOp(op, Process.myUid(), mContext.getOpPackageName()); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1867 | } |
| 1868 | |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 1869 | /** @hide */ |
| 1870 | public static IBinder getToken(IAppOpsService service) { |
| 1871 | synchronized (AppOpsManager.class) { |
| 1872 | if (sToken != null) { |
| 1873 | return sToken; |
| 1874 | } |
| 1875 | try { |
| 1876 | sToken = service.getToken(new Binder()); |
| 1877 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1878 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 1879 | } |
| 1880 | return sToken; |
| 1881 | } |
| 1882 | } |
| 1883 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1884 | /** |
| 1885 | * Report that an application has started executing a long-running operation. Note that you |
| 1886 | * must pass in both the uid and name of the application to be checked; this function will |
| 1887 | * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call |
| 1888 | * succeeds, the last execution time of the operation for this app will be updated to |
| 1889 | * the current time and the operation will be marked as "running". In this case you must |
| 1890 | * later call {@link #finishOp(int, int, String)} to report when the application is no |
| 1891 | * longer performing the operation. |
| 1892 | * @param op The operation to start. One of the OP_* constants. |
| 1893 | * @param uid The user id of the application attempting to perform the operation. |
| 1894 | * @param packageName The name of the application attempting to perform the operation. |
| 1895 | * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or |
| 1896 | * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without |
| 1897 | * causing the app to crash). |
| 1898 | * @throws SecurityException If the app has been configured to crash on this op. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1899 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1900 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1901 | public int startOp(int op, int uid, String packageName) { |
| 1902 | try { |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 1903 | int mode = mService.startOperation(getToken(mService), op, uid, packageName); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1904 | if (mode == MODE_ERRORED) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1905 | throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName)); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1906 | } |
| 1907 | return mode; |
| 1908 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1909 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1910 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1911 | } |
| 1912 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1913 | /** |
| 1914 | * Like {@link #startOp} but instead of throwing a {@link SecurityException} it |
| 1915 | * returns {@link #MODE_ERRORED}. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1916 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1917 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1918 | public int startOpNoThrow(int op, int uid, String packageName) { |
| 1919 | try { |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 1920 | return mService.startOperation(getToken(mService), op, uid, packageName); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1921 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1922 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1923 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1924 | } |
| 1925 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1926 | /** @hide */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1927 | public int startOp(int op) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1928 | return startOp(op, Process.myUid(), mContext.getOpPackageName()); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1929 | } |
| 1930 | |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1931 | /** |
| 1932 | * Report that an application is no longer performing an operation that had previously |
| 1933 | * been started with {@link #startOp(int, int, String)}. There is no validation of input |
| 1934 | * or result; the parameters supplied here must be the exact same ones previously passed |
| 1935 | * in when starting the operation. |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1936 | * @hide |
Dianne Hackborn | 1304f4a | 2013-07-09 18:17:27 -0700 | [diff] [blame] | 1937 | */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1938 | public void finishOp(int op, int uid, String packageName) { |
| 1939 | try { |
Dianne Hackborn | e98f5db | 2013-07-17 17:23:25 -0700 | [diff] [blame] | 1940 | mService.finishOperation(getToken(mService), op, uid, packageName); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1941 | } catch (RemoteException e) { |
Jeff Sharkey | f888056 | 2016-02-26 13:03:01 -0700 | [diff] [blame] | 1942 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1943 | } |
| 1944 | } |
| 1945 | |
Dianne Hackborn | 9bb0ee9 | 2013-09-22 12:31:38 -0700 | [diff] [blame] | 1946 | /** @hide */ |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1947 | public void finishOp(int op) { |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 1948 | finishOp(op, Process.myUid(), mContext.getOpPackageName()); |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1949 | } |
Jeff Sharkey | 35e46d2 | 2017-06-09 10:01:20 -0600 | [diff] [blame] | 1950 | |
| 1951 | /** @hide */ |
| 1952 | public boolean isOperationActive(int code, int uid, String packageName) { |
| 1953 | try { |
| 1954 | return mService.isOperationActive(code, uid, packageName); |
| 1955 | } catch (RemoteException e) { |
| 1956 | throw e.rethrowFromSystemServer(); |
| 1957 | } |
| 1958 | } |
Dianne Hackborn | a06de0f | 2012-12-11 16:34:47 -0800 | [diff] [blame] | 1959 | } |