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