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