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