blob: e923fb217beaec2b860d4aa9b2177ab9eba9a52d [file] [log] [blame]
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001/*
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
Svet Ganov16a16892015-04-16 10:32:04 -070019import android.Manifest;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060020import android.annotation.RequiresPermission;
Jeff Davidson05542602014-08-11 14:07:27 -070021import android.annotation.SystemApi;
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060022import android.annotation.SystemService;
Peter Visontay5a2a1ef2017-12-18 20:34:03 +000023import android.annotation.TestApi;
Jeff Davidson05542602014-08-11 14:07:27 -070024import android.app.usage.UsageStatsManager;
25import android.content.Context;
John Spurlock7b414672014-07-18 13:02:39 -040026import android.media.AudioAttributes.AttributeUsage;
Dianne Hackborne98f5db2013-07-17 17:23:25 -070027import android.os.Binder;
28import android.os.IBinder;
Dianne Hackborn35654b62013-01-14 17:38:02 -080029import android.os.Parcel;
30import android.os.Parcelable;
Dianne Hackborna06de0f2012-12-11 16:34:47 -080031import android.os.Process;
32import android.os.RemoteException;
Dianne Hackborn7b7c58b2014-12-02 18:32:20 -080033import android.os.UserHandle;
Jeff Davidson05542602014-08-11 14:07:27 -070034import android.os.UserManager;
35import android.util.ArrayMap;
36
37import com.android.internal.app.IAppOpsCallback;
38import com.android.internal.app.IAppOpsService;
39
40import java.util.ArrayList;
Peter Visontay5a2a1ef2017-12-18 20:34:03 +000041import java.util.Arrays;
Jeff Davidson05542602014-08-11 14:07:27 -070042import java.util.HashMap;
43import java.util.List;
Dianne Hackborna06de0f2012-12-11 16:34:47 -080044
Dianne Hackbornd7d28e62013-02-12 14:59:53 -080045/**
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070046 * API for interacting with "application operation" tracking.
Dianne Hackbornd7d28e62013-02-12 14:59:53 -080047 *
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070048 * <p>This API is not generally intended for third party application developers; most
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060049 * features are only available to system applications.
Dianne Hackbornd7d28e62013-02-12 14:59:53 -080050 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060051@SystemService(Context.APP_OPS_SERVICE)
Dianne Hackborna06de0f2012-12-11 16:34:47 -080052public class AppOpsManager {
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070053 /**
54 * <p>App ops allows callers to:</p>
55 *
56 * <ul>
57 * <li> Note when operations are happening, and find out if they are allowed for the current
58 * caller.</li>
59 * <li> Disallow specific apps from doing specific operations.</li>
60 * <li> Collect all of the current information about operations that have been executed or
61 * are not being allowed.</li>
62 * <li> Monitor for changes in whether an operation is allowed.</li>
63 * </ul>
64 *
65 * <p>Each operation is identified by a single integer; these integers are a fixed set of
66 * operations, enumerated by the OP_* constants.
67 *
68 * <p></p>When checking operations, the result is a "mode" integer indicating the current
69 * setting for the operation under that caller: MODE_ALLOWED, MODE_IGNORED (don't execute
70 * the operation but fake its behavior enough so that the caller doesn't crash),
71 * MODE_ERRORED (throw a SecurityException back to the caller; the normal operation calls
72 * will do this for you).
73 */
74
Dianne Hackborna06de0f2012-12-11 16:34:47 -080075 final Context mContext;
76 final IAppOpsService mService;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070077 final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers
78 = new ArrayMap<OnOpChangedListener, IAppOpsCallback>();
Dianne Hackborna06de0f2012-12-11 16:34:47 -080079
Dianne Hackborne98f5db2013-07-17 17:23:25 -070080 static IBinder sToken;
81
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070082 /**
83 * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
84 * allowed to perform the given operation.
85 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -080086 public static final int MODE_ALLOWED = 0;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070087
88 /**
89 * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
90 * not allowed to perform the given operation, and this attempt should
91 * <em>silently fail</em> (it should not cause the app to crash).
92 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -080093 public static final int MODE_IGNORED = 1;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070094
95 /**
96 * Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the
97 * given caller is not allowed to perform the given operation, and this attempt should
98 * cause it to have a fatal error, typically a {@link SecurityException}.
99 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800100 public static final int MODE_ERRORED = 2;
101
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700102 /**
103 * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should
104 * use its default security check. This mode is not normally used; it should only be used
105 * with appop permissions, and callers must explicitly check for it and deal with it.
106 */
107 public static final int MODE_DEFAULT = 3;
108
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500109 // when adding one of these:
110 // - increment _NUM_OP
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000111 // - define an OPSTR_* constant (marked as @SystemApi)
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700112 // - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500113 // - add descriptive strings to Settings/res/values/arrays.xml
David Christie0b837452013-07-29 16:02:13 -0700114 // - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app)
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700115
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700116 /** @hide No operation specified. */
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800117 public static final int OP_NONE = -1;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700118 /** @hide Access to coarse location information. */
Dianne Hackborn35654b62013-01-14 17:38:02 -0800119 public static final int OP_COARSE_LOCATION = 0;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700120 /** @hide Access to fine location information. */
Dianne Hackborn35654b62013-01-14 17:38:02 -0800121 public static final int OP_FINE_LOCATION = 1;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700122 /** @hide Causing GPS to run. */
Dianne Hackborn35654b62013-01-14 17:38:02 -0800123 public static final int OP_GPS = 2;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800124 /** @hide */
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700125 public static final int OP_VIBRATE = 3;
126 /** @hide */
127 public static final int OP_READ_CONTACTS = 4;
128 /** @hide */
129 public static final int OP_WRITE_CONTACTS = 5;
130 /** @hide */
131 public static final int OP_READ_CALL_LOG = 6;
132 /** @hide */
133 public static final int OP_WRITE_CALL_LOG = 7;
134 /** @hide */
135 public static final int OP_READ_CALENDAR = 8;
136 /** @hide */
137 public static final int OP_WRITE_CALENDAR = 9;
138 /** @hide */
139 public static final int OP_WIFI_SCAN = 10;
140 /** @hide */
141 public static final int OP_POST_NOTIFICATION = 11;
142 /** @hide */
143 public static final int OP_NEIGHBORING_CELLS = 12;
144 /** @hide */
145 public static final int OP_CALL_PHONE = 13;
146 /** @hide */
147 public static final int OP_READ_SMS = 14;
148 /** @hide */
149 public static final int OP_WRITE_SMS = 15;
150 /** @hide */
151 public static final int OP_RECEIVE_SMS = 16;
152 /** @hide */
153 public static final int OP_RECEIVE_EMERGECY_SMS = 17;
154 /** @hide */
155 public static final int OP_RECEIVE_MMS = 18;
156 /** @hide */
157 public static final int OP_RECEIVE_WAP_PUSH = 19;
158 /** @hide */
159 public static final int OP_SEND_SMS = 20;
160 /** @hide */
161 public static final int OP_READ_ICC_SMS = 21;
162 /** @hide */
163 public static final int OP_WRITE_ICC_SMS = 22;
164 /** @hide */
165 public static final int OP_WRITE_SETTINGS = 23;
Peter Visontay96449f62017-12-11 18:50:03 +0000166 /** @hide Required to draw on top of other apps. */
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700167 public static final int OP_SYSTEM_ALERT_WINDOW = 24;
168 /** @hide */
169 public static final int OP_ACCESS_NOTIFICATIONS = 25;
170 /** @hide */
171 public static final int OP_CAMERA = 26;
172 /** @hide */
173 public static final int OP_RECORD_AUDIO = 27;
174 /** @hide */
175 public static final int OP_PLAY_AUDIO = 28;
176 /** @hide */
177 public static final int OP_READ_CLIPBOARD = 29;
178 /** @hide */
179 public static final int OP_WRITE_CLIPBOARD = 30;
180 /** @hide */
181 public static final int OP_TAKE_MEDIA_BUTTONS = 31;
182 /** @hide */
183 public static final int OP_TAKE_AUDIO_FOCUS = 32;
184 /** @hide */
185 public static final int OP_AUDIO_MASTER_VOLUME = 33;
186 /** @hide */
187 public static final int OP_AUDIO_VOICE_VOLUME = 34;
188 /** @hide */
189 public static final int OP_AUDIO_RING_VOLUME = 35;
190 /** @hide */
191 public static final int OP_AUDIO_MEDIA_VOLUME = 36;
192 /** @hide */
193 public static final int OP_AUDIO_ALARM_VOLUME = 37;
194 /** @hide */
195 public static final int OP_AUDIO_NOTIFICATION_VOLUME = 38;
196 /** @hide */
197 public static final int OP_AUDIO_BLUETOOTH_VOLUME = 39;
198 /** @hide */
199 public static final int OP_WAKE_LOCK = 40;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700200 /** @hide Continually monitoring location data. */
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700201 public static final int OP_MONITOR_LOCATION = 41;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700202 /** @hide Continually monitoring location data with a relatively high power request. */
David Christie0b837452013-07-29 16:02:13 -0700203 public static final int OP_MONITOR_HIGH_POWER_LOCATION = 42;
Dianne Hackborne22b3b12014-05-07 18:06:44 -0700204 /** @hide Retrieve current usage stats via {@link UsageStatsManager}. */
205 public static final int OP_GET_USAGE_STATS = 43;
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700206 /** @hide */
Emily Bernier22c921a2014-05-28 11:01:32 -0400207 public static final int OP_MUTE_MICROPHONE = 44;
208 /** @hide */
Jason Monk1c7c3192014-06-26 12:52:18 -0400209 public static final int OP_TOAST_WINDOW = 45;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700210 /** @hide Capture the device's display contents and/or audio */
211 public static final int OP_PROJECT_MEDIA = 46;
Jeff Davidson05542602014-08-11 14:07:27 -0700212 /** @hide Activate a VPN connection without user intervention. */
213 public static final int OP_ACTIVATE_VPN = 47;
Benjamin Franzf3ece362015-02-11 10:51:10 +0000214 /** @hide Access the WallpaperManagerAPI to write wallpapers. */
215 public static final int OP_WRITE_WALLPAPER = 48;
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700216 /** @hide Received the assist structure from an app. */
217 public static final int OP_ASSIST_STRUCTURE = 49;
218 /** @hide Received a screenshot from assist. */
219 public static final int OP_ASSIST_SCREENSHOT = 50;
Svet Ganov16a16892015-04-16 10:32:04 -0700220 /** @hide Read the phone state. */
221 public static final int OP_READ_PHONE_STATE = 51;
Svet Ganovc3300092015-04-17 09:07:22 -0700222 /** @hide Add voicemail messages to the voicemail content provider. */
223 public static final int OP_ADD_VOICEMAIL = 52;
Svetoslav5335b672015-04-29 12:00:51 -0700224 /** @hide Access APIs for SIP calling over VOIP or WiFi. */
225 public static final int OP_USE_SIP = 53;
Svetoslavc656e6f2015-04-29 14:08:16 -0700226 /** @hide Intercept outgoing calls. */
227 public static final int OP_PROCESS_OUTGOING_CALLS = 54;
Svetoslav4af76a52015-04-29 15:29:46 -0700228 /** @hide User the fingerprint API. */
229 public static final int OP_USE_FINGERPRINT = 55;
Svet Ganovb9d71a62015-04-30 10:38:13 -0700230 /** @hide Access to body sensors such as heart rate, etc. */
231 public static final int OP_BODY_SENSORS = 56;
Svet Ganovede43162015-05-02 17:42:44 -0700232 /** @hide Read previously received cell broadcast messages. */
233 public static final int OP_READ_CELL_BROADCASTS = 57;
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700234 /** @hide Inject mock location into the system. */
235 public static final int OP_MOCK_LOCATION = 58;
Svet Ganov921c7df2015-06-29 21:51:41 -0700236 /** @hide Read external storage. */
237 public static final int OP_READ_EXTERNAL_STORAGE = 59;
238 /** @hide Write external storage. */
239 public static final int OP_WRITE_EXTERNAL_STORAGE = 60;
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700240 /** @hide Turned on the screen. */
241 public static final int OP_TURN_SCREEN_ON = 61;
Svetoslavf3f02ac2015-09-08 14:36:35 -0700242 /** @hide Get device accounts. */
243 public static final int OP_GET_ACCOUNTS = 62;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700244 /** @hide Control whether an application is allowed to run in the background. */
245 public static final int OP_RUN_IN_BACKGROUND = 63;
Jason Monk1c7c3192014-06-26 12:52:18 -0400246 /** @hide */
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800247 public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = 64;
Chad Brubaker73ec8f92016-11-10 11:24:40 -0800248 /** @hide Read the phone number. */
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700249 public static final int OP_READ_PHONE_NUMBERS = 65;
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800250 /** @hide Request package installs through package installer */
251 public static final int OP_REQUEST_INSTALL_PACKAGES = 66;
Winson Chungf4ac0632017-03-17 12:34:12 -0700252 /** @hide Enter picture-in-picture. */
253 public static final int OP_PICTURE_IN_PICTURE = 67;
Chad Brubaker97b383f2017-02-02 15:04:35 -0800254 /** @hide Instant app start foreground service. */
255 public static final int OP_INSTANT_APP_START_FOREGROUND = 68;
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800256 /** @hide Answer incoming phone calls */
257 public static final int OP_ANSWER_PHONE_CALLS = 69;
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700258 /** @hide Run jobs when in background */
259 public static final int OP_RUN_ANY_IN_BACKGROUND = 70;
Peter Visontay1246d9e2017-10-17 17:02:45 +0100260 /** @hide Change Wi-Fi connectivity state */
261 public static final int OP_CHANGE_WIFI_STATE = 71;
Peter Visontayf2e38362017-11-27 15:27:16 +0000262 /** @hide Request package deletion through package installer */
263 public static final int OP_REQUEST_DELETE_PACKAGES = 72;
Peter Visontay11950832017-11-14 19:34:59 +0000264 /** @hide Bind an accessibility service. */
265 public static final int OP_BIND_ACCESSIBILITY_SERVICE = 73;
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800266 /** @hide Continue handover of a call from another app */
267 public static final int OP_ACCEPT_HANDOVER = 74;
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800268 /** @hide */
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800269 public static final int _NUM_OP = 75;
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800270
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700271 /** Access to coarse location information. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700272 public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700273 /** Access to fine location information. */
274 public static final String OPSTR_FINE_LOCATION =
275 "android:fine_location";
276 /** Continually monitoring location data. */
277 public static final String OPSTR_MONITOR_LOCATION
278 = "android:monitor_location";
279 /** Continually monitoring location data with a relatively high power request. */
280 public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION
281 = "android:monitor_location_high_power";
Dianne Hackborn5064e7c2014-09-02 10:57:16 -0700282 /** Access to {@link android.app.usage.UsageStatsManager}. */
283 public static final String OPSTR_GET_USAGE_STATS
284 = "android:get_usage_stats";
Jeff Davidson05542602014-08-11 14:07:27 -0700285 /** Activate a VPN connection without user intervention. @hide */
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000286 @SystemApi @TestApi
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700287 public static final String OPSTR_ACTIVATE_VPN
288 = "android:activate_vpn";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700289 /** Allows an application to read the user's contacts data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700290 public static final String OPSTR_READ_CONTACTS
291 = "android:read_contacts";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700292 /** Allows an application to write to the user's contacts data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700293 public static final String OPSTR_WRITE_CONTACTS
294 = "android:write_contacts";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700295 /** Allows an application to read the user's call log. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700296 public static final String OPSTR_READ_CALL_LOG
297 = "android:read_call_log";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700298 /** Allows an application to write to the user's call log. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700299 public static final String OPSTR_WRITE_CALL_LOG
300 = "android:write_call_log";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700301 /** Allows an application to read the user's calendar data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700302 public static final String OPSTR_READ_CALENDAR
303 = "android:read_calendar";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700304 /** Allows an application to write to the user's calendar data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700305 public static final String OPSTR_WRITE_CALENDAR
306 = "android:write_calendar";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700307 /** Allows an application to initiate a phone call. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700308 public static final String OPSTR_CALL_PHONE
309 = "android:call_phone";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700310 /** Allows an application to read SMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700311 public static final String OPSTR_READ_SMS
312 = "android:read_sms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700313 /** Allows an application to receive SMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700314 public static final String OPSTR_RECEIVE_SMS
315 = "android:receive_sms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700316 /** Allows an application to receive MMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700317 public static final String OPSTR_RECEIVE_MMS
318 = "android:receive_mms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700319 /** Allows an application to receive WAP push messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700320 public static final String OPSTR_RECEIVE_WAP_PUSH
321 = "android:receive_wap_push";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700322 /** Allows an application to send SMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700323 public static final String OPSTR_SEND_SMS
324 = "android:send_sms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700325 /** Required to be able to access the camera device. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700326 public static final String OPSTR_CAMERA
327 = "android:camera";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700328 /** Required to be able to access the microphone device. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700329 public static final String OPSTR_RECORD_AUDIO
330 = "android:record_audio";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700331 /** Required to access phone state related information. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700332 public static final String OPSTR_READ_PHONE_STATE
333 = "android:read_phone_state";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700334 /** Required to access phone state related information. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700335 public static final String OPSTR_ADD_VOICEMAIL
336 = "android:add_voicemail";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700337 /** Access APIs for SIP calling over VOIP or WiFi */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700338 public static final String OPSTR_USE_SIP
339 = "android:use_sip";
Svet Ganove8e89422016-09-22 19:56:50 -0700340 /** Access APIs for diverting outgoing calls */
Svet Ganov824ad6e2016-09-22 19:36:53 -0700341 public static final String OPSTR_PROCESS_OUTGOING_CALLS
342 = "android:process_outgoing_calls";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700343 /** Use the fingerprint API. */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700344 public static final String OPSTR_USE_FINGERPRINT
345 = "android:use_fingerprint";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700346 /** Access to body sensors such as heart rate, etc. */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700347 public static final String OPSTR_BODY_SENSORS
348 = "android:body_sensors";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700349 /** Read previously received cell broadcast messages. */
Svet Ganovede43162015-05-02 17:42:44 -0700350 public static final String OPSTR_READ_CELL_BROADCASTS
351 = "android:read_cell_broadcasts";
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700352 /** Inject mock location into the system. */
353 public static final String OPSTR_MOCK_LOCATION
354 = "android:mock_location";
Svet Ganov921c7df2015-06-29 21:51:41 -0700355 /** Read external storage. */
356 public static final String OPSTR_READ_EXTERNAL_STORAGE
357 = "android:read_external_storage";
358 /** Write external storage. */
359 public static final String OPSTR_WRITE_EXTERNAL_STORAGE
360 = "android:write_external_storage";
Billy Lau24b9c832015-07-20 17:34:09 +0100361 /** Required to draw on top of other apps. */
362 public static final String OPSTR_SYSTEM_ALERT_WINDOW
363 = "android:system_alert_window";
364 /** Required to write/modify/update system settingss. */
365 public static final String OPSTR_WRITE_SETTINGS
366 = "android:write_settings";
Svetoslavf3f02ac2015-09-08 14:36:35 -0700367 /** @hide Get device accounts. */
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000368 @SystemApi @TestApi
Svetoslavf3f02ac2015-09-08 14:36:35 -0700369 public static final String OPSTR_GET_ACCOUNTS
370 = "android:get_accounts";
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700371 public static final String OPSTR_READ_PHONE_NUMBERS
372 = "android:read_phone_numbers";
Winson Chungf4ac0632017-03-17 12:34:12 -0700373 /** Access to picture-in-picture. */
374 public static final String OPSTR_PICTURE_IN_PICTURE
375 = "android:picture_in_picture";
Chad Brubaker97b383f2017-02-02 15:04:35 -0800376 /** @hide */
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000377 @SystemApi @TestApi
Chad Brubaker97b383f2017-02-02 15:04:35 -0800378 public static final String OPSTR_INSTANT_APP_START_FOREGROUND
379 = "android:instant_app_start_foreground";
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800380 /** Answer incoming phone calls */
381 public static final String OPSTR_ANSWER_PHONE_CALLS
382 = "android:answer_phone_calls";
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800383 /**
384 * Accept call handover
385 * @hide
386 */
387 @SystemApi @TestApi
388 public static final String OPSTR_ACCEPT_HANDOVER
389 = "android:accept_handover";
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000390 /** @hide */
391 @SystemApi @TestApi
392 public static final String OPSTR_GPS = "android:gps";
393 /** @hide */
394 @SystemApi @TestApi
395 public static final String OPSTR_VIBRATE = "android:vibrate";
396 /** @hide */
397 @SystemApi @TestApi
398 public static final String OPSTR_WIFI_SCAN = "android:wifi_scan";
399 /** @hide */
400 @SystemApi @TestApi
401 public static final String OPSTR_POST_NOTIFICATION = "android:post_notification";
402 /** @hide */
403 @SystemApi @TestApi
404 public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells";
405 /** @hide */
406 @SystemApi @TestApi
407 public static final String OPSTR_WRITE_SMS = "android:write_sms";
408 /** @hide */
409 @SystemApi @TestApi
410 public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST =
411 "android:receive_emergency_broadcast";
412 /** @hide */
413 @SystemApi @TestApi
414 public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms";
415 /** @hide */
416 @SystemApi @TestApi
417 public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms";
418 /** @hide */
419 @SystemApi @TestApi
420 public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications";
421 /** @hide */
422 @SystemApi @TestApi
423 public static final String OPSTR_PLAY_AUDIO = "android:play_audio";
424 /** @hide */
425 @SystemApi @TestApi
426 public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard";
427 /** @hide */
428 @SystemApi @TestApi
429 public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard";
430 /** @hide */
431 @SystemApi @TestApi
432 public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons";
433 /** @hide */
434 @SystemApi @TestApi
435 public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus";
436 /** @hide */
437 @SystemApi @TestApi
438 public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume";
439 /** @hide */
440 @SystemApi @TestApi
441 public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume";
442 /** @hide */
443 @SystemApi @TestApi
444 public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume";
445 /** @hide */
446 @SystemApi @TestApi
447 public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume";
448 /** @hide */
449 @SystemApi @TestApi
450 public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume";
451 /** @hide */
452 @SystemApi @TestApi
453 public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME =
454 "android:audio_notification_volume";
455 /** @hide */
456 @SystemApi @TestApi
457 public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume";
458 /** @hide */
459 @SystemApi @TestApi
460 public static final String OPSTR_WAKE_LOCK = "android:wake_lock";
461 /** @hide */
462 @SystemApi @TestApi
463 public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone";
464 /** @hide */
465 @SystemApi @TestApi
466 public static final String OPSTR_TOAST_WINDOW = "android:toast_window";
467 /** @hide */
468 @SystemApi @TestApi
469 public static final String OPSTR_PROJECT_MEDIA = "android:project_media";
470 /** @hide */
471 @SystemApi @TestApi
472 public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper";
473 /** @hide */
474 @SystemApi @TestApi
475 public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure";
476 /** @hide */
477 @SystemApi @TestApi
478 public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot";
479 /** @hide */
480 @SystemApi @TestApi
481 public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on";
482 /** @hide */
483 @SystemApi @TestApi
484 public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background";
485 /** @hide */
486 @SystemApi @TestApi
487 public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME =
488 "android:audio_accessibility_volume";
489 /** @hide */
490 @SystemApi @TestApi
491 public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages";
492 /** @hide */
493 @SystemApi @TestApi
494 public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background";
495 /** @hide */
496 @SystemApi @TestApi
497 public static final String OPSTR_CHANGE_WIFI_STATE = "change_wifi_state";
498 /** @hide */
499 @SystemApi @TestApi
500 public static final String OPSTR_REQUEST_DELETE_PACKAGES = "request_delete_packages";
501 /** @hide */
502 @SystemApi @TestApi
503 public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE = "bind_accessibility_service";
504
Philip P. Moltmanne56c08e2017-03-15 12:46:04 -0700505 // Warning: If an permission is added here it also has to be added to
506 // com.android.packageinstaller.permission.utils.EventLogger
Svet Ganovda0acdf2017-02-15 10:28:51 -0800507 private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
508 // RUNTIME PERMISSIONS
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700509 // Contacts
510 OP_READ_CONTACTS,
511 OP_WRITE_CONTACTS,
512 OP_GET_ACCOUNTS,
513 // Calendar
514 OP_READ_CALENDAR,
515 OP_WRITE_CALENDAR,
516 // SMS
517 OP_SEND_SMS,
518 OP_RECEIVE_SMS,
519 OP_READ_SMS,
520 OP_RECEIVE_WAP_PUSH,
521 OP_RECEIVE_MMS,
522 OP_READ_CELL_BROADCASTS,
523 // Storage
524 OP_READ_EXTERNAL_STORAGE,
525 OP_WRITE_EXTERNAL_STORAGE,
526 // Location
527 OP_COARSE_LOCATION,
528 OP_FINE_LOCATION,
529 // Phone
530 OP_READ_PHONE_STATE,
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700531 OP_READ_PHONE_NUMBERS,
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700532 OP_CALL_PHONE,
533 OP_READ_CALL_LOG,
534 OP_WRITE_CALL_LOG,
535 OP_ADD_VOICEMAIL,
536 OP_USE_SIP,
537 OP_PROCESS_OUTGOING_CALLS,
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800538 OP_ANSWER_PHONE_CALLS,
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800539 OP_ACCEPT_HANDOVER,
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700540 // Microphone
541 OP_RECORD_AUDIO,
542 // Camera
543 OP_CAMERA,
544 // Body sensors
Svet Ganovda0acdf2017-02-15 10:28:51 -0800545 OP_BODY_SENSORS,
Peter Visontayf2e38362017-11-27 15:27:16 +0000546 OP_REQUEST_DELETE_PACKAGES,
Svet Ganovda0acdf2017-02-15 10:28:51 -0800547
548 // APPOP PERMISSIONS
549 OP_ACCESS_NOTIFICATIONS,
550 OP_SYSTEM_ALERT_WINDOW,
551 OP_WRITE_SETTINGS,
552 OP_REQUEST_INSTALL_PACKAGES,
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700553 };
554
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800555 /**
556 * This maps each operation to the operation that serves as the
557 * switch to determine whether it is allowed. Generally this is
558 * a 1:1 mapping, but for some things (like location) that have
559 * multiple low-level operations being tracked that should be
David Christie0b837452013-07-29 16:02:13 -0700560 * presented to the user as one switch then this can be used to
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800561 * make them all controlled by the same single operation.
562 */
563 private static int[] sOpToSwitch = new int[] {
564 OP_COARSE_LOCATION,
565 OP_COARSE_LOCATION,
566 OP_COARSE_LOCATION,
567 OP_VIBRATE,
568 OP_READ_CONTACTS,
569 OP_WRITE_CONTACTS,
570 OP_READ_CALL_LOG,
571 OP_WRITE_CALL_LOG,
572 OP_READ_CALENDAR,
573 OP_WRITE_CALENDAR,
574 OP_COARSE_LOCATION,
575 OP_POST_NOTIFICATION,
576 OP_COARSE_LOCATION,
577 OP_CALL_PHONE,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800578 OP_READ_SMS,
579 OP_WRITE_SMS,
David Braun18966a82013-09-10 13:14:46 -0700580 OP_RECEIVE_SMS,
581 OP_RECEIVE_SMS,
Svet Ganov99e4d512016-09-21 19:50:14 -0700582 OP_RECEIVE_MMS,
583 OP_RECEIVE_WAP_PUSH,
David Braun18966a82013-09-10 13:14:46 -0700584 OP_SEND_SMS,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800585 OP_READ_SMS,
586 OP_WRITE_SMS,
Dianne Hackborn961321f2013-02-05 17:22:41 -0800587 OP_WRITE_SETTINGS,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800588 OP_SYSTEM_ALERT_WINDOW,
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500589 OP_ACCESS_NOTIFICATIONS,
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800590 OP_CAMERA,
591 OP_RECORD_AUDIO,
592 OP_PLAY_AUDIO,
Dianne Hackbornefcc1a22013-02-25 18:02:35 -0800593 OP_READ_CLIPBOARD,
594 OP_WRITE_CLIPBOARD,
Dianne Hackbornba50b97c2013-04-30 15:04:46 -0700595 OP_TAKE_MEDIA_BUTTONS,
596 OP_TAKE_AUDIO_FOCUS,
597 OP_AUDIO_MASTER_VOLUME,
598 OP_AUDIO_VOICE_VOLUME,
599 OP_AUDIO_RING_VOLUME,
600 OP_AUDIO_MEDIA_VOLUME,
601 OP_AUDIO_ALARM_VOLUME,
602 OP_AUDIO_NOTIFICATION_VOLUME,
603 OP_AUDIO_BLUETOOTH_VOLUME,
Dianne Hackborn713df152013-05-17 11:27:57 -0700604 OP_WAKE_LOCK,
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700605 OP_COARSE_LOCATION,
David Christie0b837452013-07-29 16:02:13 -0700606 OP_COARSE_LOCATION,
Dianne Hackborne22b3b12014-05-07 18:06:44 -0700607 OP_GET_USAGE_STATS,
Jason Monk1c7c3192014-06-26 12:52:18 -0400608 OP_MUTE_MICROPHONE,
609 OP_TOAST_WINDOW,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700610 OP_PROJECT_MEDIA,
Jeff Davidson05542602014-08-11 14:07:27 -0700611 OP_ACTIVATE_VPN,
Benjamin Franzf3ece362015-02-11 10:51:10 +0000612 OP_WRITE_WALLPAPER,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700613 OP_ASSIST_STRUCTURE,
614 OP_ASSIST_SCREENSHOT,
Svet Ganovc3300092015-04-17 09:07:22 -0700615 OP_READ_PHONE_STATE,
Svetoslav5335b672015-04-29 12:00:51 -0700616 OP_ADD_VOICEMAIL,
Svetoslavc656e6f2015-04-29 14:08:16 -0700617 OP_USE_SIP,
Svetoslav4af76a52015-04-29 15:29:46 -0700618 OP_PROCESS_OUTGOING_CALLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700619 OP_USE_FINGERPRINT,
Svet Ganovede43162015-05-02 17:42:44 -0700620 OP_BODY_SENSORS,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700621 OP_READ_CELL_BROADCASTS,
Svet Ganov921c7df2015-06-29 21:51:41 -0700622 OP_MOCK_LOCATION,
623 OP_READ_EXTERNAL_STORAGE,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700624 OP_WRITE_EXTERNAL_STORAGE,
625 OP_TURN_SCREEN_ON,
Svetoslavf3f02ac2015-09-08 14:36:35 -0700626 OP_GET_ACCOUNTS,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700627 OP_RUN_IN_BACKGROUND,
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800628 OP_AUDIO_ACCESSIBILITY_VOLUME,
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700629 OP_READ_PHONE_NUMBERS,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800630 OP_REQUEST_INSTALL_PACKAGES,
Winson Chungf4ac0632017-03-17 12:34:12 -0700631 OP_PICTURE_IN_PICTURE,
Chad Brubaker97b383f2017-02-02 15:04:35 -0800632 OP_INSTANT_APP_START_FOREGROUND,
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700633 OP_ANSWER_PHONE_CALLS,
634 OP_RUN_ANY_IN_BACKGROUND,
Peter Visontay1246d9e2017-10-17 17:02:45 +0100635 OP_CHANGE_WIFI_STATE,
Peter Visontayf2e38362017-11-27 15:27:16 +0000636 OP_REQUEST_DELETE_PACKAGES,
Peter Visontay11950832017-11-14 19:34:59 +0000637 OP_BIND_ACCESSIBILITY_SERVICE,
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800638 OP_ACCEPT_HANDOVER,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800639 };
640
641 /**
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700642 * This maps each operation to the public string constant for it.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700643 */
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000644 private static String[] sOpToString = new String[]{
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700645 OPSTR_COARSE_LOCATION,
646 OPSTR_FINE_LOCATION,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000647 OPSTR_GPS,
648 OPSTR_VIBRATE,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700649 OPSTR_READ_CONTACTS,
650 OPSTR_WRITE_CONTACTS,
651 OPSTR_READ_CALL_LOG,
652 OPSTR_WRITE_CALL_LOG,
653 OPSTR_READ_CALENDAR,
654 OPSTR_WRITE_CALENDAR,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000655 OPSTR_WIFI_SCAN,
656 OPSTR_POST_NOTIFICATION,
657 OPSTR_NEIGHBORING_CELLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700658 OPSTR_CALL_PHONE,
659 OPSTR_READ_SMS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000660 OPSTR_WRITE_SMS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700661 OPSTR_RECEIVE_SMS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000662 OPSTR_RECEIVE_EMERGENCY_BROADCAST,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700663 OPSTR_RECEIVE_MMS,
664 OPSTR_RECEIVE_WAP_PUSH,
665 OPSTR_SEND_SMS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000666 OPSTR_READ_ICC_SMS,
667 OPSTR_WRITE_ICC_SMS,
Billy Lau24b9c832015-07-20 17:34:09 +0100668 OPSTR_WRITE_SETTINGS,
669 OPSTR_SYSTEM_ALERT_WINDOW,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000670 OPSTR_ACCESS_NOTIFICATIONS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700671 OPSTR_CAMERA,
672 OPSTR_RECORD_AUDIO,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000673 OPSTR_PLAY_AUDIO,
674 OPSTR_READ_CLIPBOARD,
675 OPSTR_WRITE_CLIPBOARD,
676 OPSTR_TAKE_MEDIA_BUTTONS,
677 OPSTR_TAKE_AUDIO_FOCUS,
678 OPSTR_AUDIO_MASTER_VOLUME,
679 OPSTR_AUDIO_VOICE_VOLUME,
680 OPSTR_AUDIO_RING_VOLUME,
681 OPSTR_AUDIO_MEDIA_VOLUME,
682 OPSTR_AUDIO_ALARM_VOLUME,
683 OPSTR_AUDIO_NOTIFICATION_VOLUME,
684 OPSTR_AUDIO_BLUETOOTH_VOLUME,
685 OPSTR_WAKE_LOCK,
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700686 OPSTR_MONITOR_LOCATION,
687 OPSTR_MONITOR_HIGH_POWER_LOCATION,
Dianne Hackborn5064e7c2014-09-02 10:57:16 -0700688 OPSTR_GET_USAGE_STATS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000689 OPSTR_MUTE_MICROPHONE,
690 OPSTR_TOAST_WINDOW,
691 OPSTR_PROJECT_MEDIA,
Jeff Davidson05542602014-08-11 14:07:27 -0700692 OPSTR_ACTIVATE_VPN,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000693 OPSTR_WRITE_WALLPAPER,
694 OPSTR_ASSIST_STRUCTURE,
695 OPSTR_ASSIST_SCREENSHOT,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700696 OPSTR_READ_PHONE_STATE,
697 OPSTR_ADD_VOICEMAIL,
698 OPSTR_USE_SIP,
Svet Ganov824ad6e2016-09-22 19:36:53 -0700699 OPSTR_PROCESS_OUTGOING_CALLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700700 OPSTR_USE_FINGERPRINT,
Svet Ganovede43162015-05-02 17:42:44 -0700701 OPSTR_BODY_SENSORS,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700702 OPSTR_READ_CELL_BROADCASTS,
Svet Ganov921c7df2015-06-29 21:51:41 -0700703 OPSTR_MOCK_LOCATION,
704 OPSTR_READ_EXTERNAL_STORAGE,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700705 OPSTR_WRITE_EXTERNAL_STORAGE,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000706 OPSTR_TURN_SCREEN_ON,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700707 OPSTR_GET_ACCOUNTS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000708 OPSTR_RUN_IN_BACKGROUND,
709 OPSTR_AUDIO_ACCESSIBILITY_VOLUME,
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700710 OPSTR_READ_PHONE_NUMBERS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000711 OPSTR_REQUEST_INSTALL_PACKAGES,
Winson Chungf4ac0632017-03-17 12:34:12 -0700712 OPSTR_PICTURE_IN_PICTURE,
Chad Brubaker97b383f2017-02-02 15:04:35 -0800713 OPSTR_INSTANT_APP_START_FOREGROUND,
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800714 OPSTR_ANSWER_PHONE_CALLS,
Peter Visontay5a2a1ef2017-12-18 20:34:03 +0000715 OPSTR_RUN_ANY_IN_BACKGROUND,
716 OPSTR_CHANGE_WIFI_STATE,
717 OPSTR_REQUEST_DELETE_PACKAGES,
718 OPSTR_BIND_ACCESSIBILITY_SERVICE,
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800719 OPSTR_ACCEPT_HANDOVER,
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700720 };
721
722 /**
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800723 * This provides a simple name for each operation to be used
724 * in debug output.
725 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800726 private static String[] sOpNames = new String[] {
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800727 "COARSE_LOCATION",
728 "FINE_LOCATION",
729 "GPS",
730 "VIBRATE",
731 "READ_CONTACTS",
732 "WRITE_CONTACTS",
733 "READ_CALL_LOG",
734 "WRITE_CALL_LOG",
735 "READ_CALENDAR",
736 "WRITE_CALENDAR",
737 "WIFI_SCAN",
738 "POST_NOTIFICATION",
739 "NEIGHBORING_CELLS",
740 "CALL_PHONE",
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800741 "READ_SMS",
742 "WRITE_SMS",
743 "RECEIVE_SMS",
744 "RECEIVE_EMERGECY_SMS",
745 "RECEIVE_MMS",
746 "RECEIVE_WAP_PUSH",
747 "SEND_SMS",
748 "READ_ICC_SMS",
749 "WRITE_ICC_SMS",
Dianne Hackborn961321f2013-02-05 17:22:41 -0800750 "WRITE_SETTINGS",
Dianne Hackbornc2293022013-02-06 23:14:49 -0800751 "SYSTEM_ALERT_WINDOW",
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500752 "ACCESS_NOTIFICATIONS",
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800753 "CAMERA",
754 "RECORD_AUDIO",
755 "PLAY_AUDIO",
Dianne Hackbornefcc1a22013-02-25 18:02:35 -0800756 "READ_CLIPBOARD",
757 "WRITE_CLIPBOARD",
Dianne Hackbornba50b97c2013-04-30 15:04:46 -0700758 "TAKE_MEDIA_BUTTONS",
759 "TAKE_AUDIO_FOCUS",
760 "AUDIO_MASTER_VOLUME",
761 "AUDIO_VOICE_VOLUME",
762 "AUDIO_RING_VOLUME",
763 "AUDIO_MEDIA_VOLUME",
764 "AUDIO_ALARM_VOLUME",
765 "AUDIO_NOTIFICATION_VOLUME",
766 "AUDIO_BLUETOOTH_VOLUME",
Dianne Hackborn713df152013-05-17 11:27:57 -0700767 "WAKE_LOCK",
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700768 "MONITOR_LOCATION",
David Christie0b837452013-07-29 16:02:13 -0700769 "MONITOR_HIGH_POWER_LOCATION",
Emily Bernier22c921a2014-05-28 11:01:32 -0400770 "GET_USAGE_STATS",
Michael Wrightc39d47a2014-07-08 18:07:36 -0700771 "MUTE_MICROPHONE",
Jason Monk1c7c3192014-06-26 12:52:18 -0400772 "TOAST_WINDOW",
Michael Wrightc39d47a2014-07-08 18:07:36 -0700773 "PROJECT_MEDIA",
Jeff Davidson05542602014-08-11 14:07:27 -0700774 "ACTIVATE_VPN",
Benjamin Franzf3ece362015-02-11 10:51:10 +0000775 "WRITE_WALLPAPER",
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700776 "ASSIST_STRUCTURE",
Svet Ganov16a16892015-04-16 10:32:04 -0700777 "ASSIST_SCREENSHOT",
Svet Ganovc3300092015-04-17 09:07:22 -0700778 "OP_READ_PHONE_STATE",
Svetoslav5335b672015-04-29 12:00:51 -0700779 "ADD_VOICEMAIL",
Svetoslavc656e6f2015-04-29 14:08:16 -0700780 "USE_SIP",
Svetoslav4af76a52015-04-29 15:29:46 -0700781 "PROCESS_OUTGOING_CALLS",
Svet Ganovb9d71a62015-04-30 10:38:13 -0700782 "USE_FINGERPRINT",
Svet Ganovede43162015-05-02 17:42:44 -0700783 "BODY_SENSORS",
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700784 "READ_CELL_BROADCASTS",
Svet Ganov921c7df2015-06-29 21:51:41 -0700785 "MOCK_LOCATION",
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700786 "READ_EXTERNAL_STORAGE",
787 "WRITE_EXTERNAL_STORAGE",
788 "TURN_ON_SCREEN",
Svetoslavf3f02ac2015-09-08 14:36:35 -0700789 "GET_ACCOUNTS",
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700790 "RUN_IN_BACKGROUND",
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800791 "AUDIO_ACCESSIBILITY_VOLUME",
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700792 "READ_PHONE_NUMBERS",
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800793 "REQUEST_INSTALL_PACKAGES",
Winson Chungf4ac0632017-03-17 12:34:12 -0700794 "PICTURE_IN_PICTURE",
Chad Brubaker97b383f2017-02-02 15:04:35 -0800795 "INSTANT_APP_START_FOREGROUND",
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800796 "ANSWER_PHONE_CALLS",
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700797 "RUN_ANY_IN_BACKGROUND",
Peter Visontay1246d9e2017-10-17 17:02:45 +0100798 "CHANGE_WIFI_STATE",
Peter Visontayf2e38362017-11-27 15:27:16 +0000799 "REQUEST_DELETE_PACKAGES",
Peter Visontay11950832017-11-14 19:34:59 +0000800 "BIND_ACCESSIBILITY_SERVICE",
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800801 "ACCEPT_HANDOVER",
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800802 };
803
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800804 /**
805 * This optionally maps a permission to an operation. If there
806 * is no permission associated with an operation, it is null.
807 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800808 private static String[] sOpPerms = new String[] {
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800809 android.Manifest.permission.ACCESS_COARSE_LOCATION,
810 android.Manifest.permission.ACCESS_FINE_LOCATION,
811 null,
812 android.Manifest.permission.VIBRATE,
813 android.Manifest.permission.READ_CONTACTS,
814 android.Manifest.permission.WRITE_CONTACTS,
815 android.Manifest.permission.READ_CALL_LOG,
816 android.Manifest.permission.WRITE_CALL_LOG,
817 android.Manifest.permission.READ_CALENDAR,
818 android.Manifest.permission.WRITE_CALENDAR,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800819 android.Manifest.permission.ACCESS_WIFI_STATE,
Robert Craigf97616c2013-10-07 12:32:02 -0400820 null, // no permission required for notifications
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800821 null, // neighboring cells shares the coarse location perm
822 android.Manifest.permission.CALL_PHONE,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800823 android.Manifest.permission.READ_SMS,
Svetoslav6c589572015-04-16 16:19:24 -0700824 null, // no permission required for writing sms
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800825 android.Manifest.permission.RECEIVE_SMS,
826 android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
827 android.Manifest.permission.RECEIVE_MMS,
828 android.Manifest.permission.RECEIVE_WAP_PUSH,
829 android.Manifest.permission.SEND_SMS,
830 android.Manifest.permission.READ_SMS,
Svetoslav6c589572015-04-16 16:19:24 -0700831 null, // no permission required for writing icc sms
Dianne Hackborn961321f2013-02-05 17:22:41 -0800832 android.Manifest.permission.WRITE_SETTINGS,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800833 android.Manifest.permission.SYSTEM_ALERT_WINDOW,
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500834 android.Manifest.permission.ACCESS_NOTIFICATIONS,
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800835 android.Manifest.permission.CAMERA,
836 android.Manifest.permission.RECORD_AUDIO,
837 null, // no permission for playing audio
Dianne Hackbornefcc1a22013-02-25 18:02:35 -0800838 null, // no permission for reading clipboard
839 null, // no permission for writing clipboard
Dianne Hackbornba50b97c2013-04-30 15:04:46 -0700840 null, // no permission for taking media buttons
841 null, // no permission for taking audio focus
842 null, // no permission for changing master volume
843 null, // no permission for changing voice volume
844 null, // no permission for changing ring volume
845 null, // no permission for changing media volume
846 null, // no permission for changing alarm volume
847 null, // no permission for changing notification volume
848 null, // no permission for changing bluetooth volume
Dianne Hackborn713df152013-05-17 11:27:57 -0700849 android.Manifest.permission.WAKE_LOCK,
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700850 null, // no permission for generic location monitoring
David Christie0b837452013-07-29 16:02:13 -0700851 null, // no permission for high power location monitoring
Dianne Hackborne22b3b12014-05-07 18:06:44 -0700852 android.Manifest.permission.PACKAGE_USAGE_STATS,
Emily Bernier22c921a2014-05-28 11:01:32 -0400853 null, // no permission for muting/unmuting microphone
Jason Monk1c7c3192014-06-26 12:52:18 -0400854 null, // no permission for displaying toasts
Michael Wrightc39d47a2014-07-08 18:07:36 -0700855 null, // no permission for projecting media
Jeff Davidson05542602014-08-11 14:07:27 -0700856 null, // no permission for activating vpn
Benjamin Franzf3ece362015-02-11 10:51:10 +0000857 null, // no permission for supporting wallpaper
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700858 null, // no permission for receiving assist structure
859 null, // no permission for receiving assist screenshot
Svet Ganovc3300092015-04-17 09:07:22 -0700860 Manifest.permission.READ_PHONE_STATE,
Svetoslav5335b672015-04-29 12:00:51 -0700861 Manifest.permission.ADD_VOICEMAIL,
Svetoslavc656e6f2015-04-29 14:08:16 -0700862 Manifest.permission.USE_SIP,
Svetoslav4af76a52015-04-29 15:29:46 -0700863 Manifest.permission.PROCESS_OUTGOING_CALLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700864 Manifest.permission.USE_FINGERPRINT,
Svet Ganovede43162015-05-02 17:42:44 -0700865 Manifest.permission.BODY_SENSORS,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700866 Manifest.permission.READ_CELL_BROADCASTS,
Svet Ganov921c7df2015-06-29 21:51:41 -0700867 null,
868 Manifest.permission.READ_EXTERNAL_STORAGE,
869 Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700870 null, // no permission for turning the screen on
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700871 Manifest.permission.GET_ACCOUNTS,
872 null, // no permission for running in background
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800873 null, // no permission for changing accessibility volume
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700874 Manifest.permission.READ_PHONE_NUMBERS,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800875 Manifest.permission.REQUEST_INSTALL_PACKAGES,
Winson Chung59fda9e2017-01-20 16:14:51 -0800876 null, // no permission for entering picture-in-picture on hide
Chad Brubaker97b383f2017-02-02 15:04:35 -0800877 Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE,
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800878 Manifest.permission.ANSWER_PHONE_CALLS,
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700879 null, // no permission for OP_RUN_ANY_IN_BACKGROUND
Peter Visontay1246d9e2017-10-17 17:02:45 +0100880 Manifest.permission.CHANGE_WIFI_STATE,
Peter Visontayf2e38362017-11-27 15:27:16 +0000881 Manifest.permission.REQUEST_DELETE_PACKAGES,
Peter Visontay11950832017-11-14 19:34:59 +0000882 Manifest.permission.BIND_ACCESSIBILITY_SERVICE,
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800883 Manifest.permission.ACCEPT_HANDOVER,
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800884 };
885
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800886 /**
Jason Monk62062992014-05-06 09:55:28 -0400887 * Specifies whether an Op should be restricted by a user restriction.
888 * Each Op should be filled with a restriction string from UserManager or
889 * null to specify it is not affected by any user restriction.
890 */
891 private static String[] sOpRestrictions = new String[] {
Julia Reynolds9854d572014-07-02 14:46:02 -0400892 UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION
893 UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION
894 UserManager.DISALLOW_SHARE_LOCATION, //GPS
Jason Monk62062992014-05-06 09:55:28 -0400895 null, //VIBRATE
896 null, //READ_CONTACTS
897 null, //WRITE_CONTACTS
Yorke Lee15f83c62014-08-13 14:14:29 -0700898 UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG
899 UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG
Jason Monk62062992014-05-06 09:55:28 -0400900 null, //READ_CALENDAR
901 null, //WRITE_CALENDAR
Julia Reynolds9854d572014-07-02 14:46:02 -0400902 UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN
Jason Monk62062992014-05-06 09:55:28 -0400903 null, //POST_NOTIFICATION
904 null, //NEIGHBORING_CELLS
905 null, //CALL_PHONE
Amith Yamasani41c1ded2014-08-05 11:15:05 -0700906 UserManager.DISALLOW_SMS, //READ_SMS
907 UserManager.DISALLOW_SMS, //WRITE_SMS
908 UserManager.DISALLOW_SMS, //RECEIVE_SMS
909 null, //RECEIVE_EMERGENCY_SMS
910 UserManager.DISALLOW_SMS, //RECEIVE_MMS
Jason Monk62062992014-05-06 09:55:28 -0400911 null, //RECEIVE_WAP_PUSH
Amith Yamasani41c1ded2014-08-05 11:15:05 -0700912 UserManager.DISALLOW_SMS, //SEND_SMS
913 UserManager.DISALLOW_SMS, //READ_ICC_SMS
914 UserManager.DISALLOW_SMS, //WRITE_ICC_SMS
Jason Monk62062992014-05-06 09:55:28 -0400915 null, //WRITE_SETTINGS
Jason Monk1c7c3192014-06-26 12:52:18 -0400916 UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW
Jason Monk62062992014-05-06 09:55:28 -0400917 null, //ACCESS_NOTIFICATIONS
Makoto Onuki759a7632015-10-28 16:43:10 -0700918 UserManager.DISALLOW_CAMERA, //CAMERA
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700919 UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO
Jason Monk62062992014-05-06 09:55:28 -0400920 null, //PLAY_AUDIO
921 null, //READ_CLIPBOARD
922 null, //WRITE_CLIPBOARD
923 null, //TAKE_MEDIA_BUTTONS
924 null, //TAKE_AUDIO_FOCUS
Emily Bernier45775c42014-05-16 15:12:04 -0400925 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME
926 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME
927 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME
928 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME
929 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME
930 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME
931 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME
Jason Monk62062992014-05-06 09:55:28 -0400932 null, //WAKE_LOCK
Julia Reynolds9854d572014-07-02 14:46:02 -0400933 UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION
934 UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION
Jason Monk62062992014-05-06 09:55:28 -0400935 null, //GET_USAGE_STATS
Emily Bernier22c921a2014-05-28 11:01:32 -0400936 UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE
Jason Monk1c7c3192014-06-26 12:52:18 -0400937 UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW
Michael Wrightc39d47a2014-07-08 18:07:36 -0700938 null, //PROJECT_MEDIA
Tony Mak33d03a92016-06-02 15:01:16 +0100939 null, // ACTIVATE_VPN
Benjamin Franzf3ece362015-02-11 10:51:10 +0000940 UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700941 null, // ASSIST_STRUCTURE
942 null, // ASSIST_SCREENSHOT
Svet Ganovc3300092015-04-17 09:07:22 -0700943 null, // READ_PHONE_STATE
Svetoslav5335b672015-04-29 12:00:51 -0700944 null, // ADD_VOICEMAIL
Svetoslavc656e6f2015-04-29 14:08:16 -0700945 null, // USE_SIP
Svetoslav4af76a52015-04-29 15:29:46 -0700946 null, // PROCESS_OUTGOING_CALLS
Svet Ganovb9d71a62015-04-30 10:38:13 -0700947 null, // USE_FINGERPRINT
Svet Ganovede43162015-05-02 17:42:44 -0700948 null, // BODY_SENSORS
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700949 null, // READ_CELL_BROADCASTS
Svet Ganov921c7df2015-06-29 21:51:41 -0700950 null, // MOCK_LOCATION
951 null, // READ_EXTERNAL_STORAGE
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700952 null, // WRITE_EXTERNAL_STORAGE
953 null, // TURN_ON_SCREEN
Svetoslavf3f02ac2015-09-08 14:36:35 -0700954 null, // GET_ACCOUNTS
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700955 null, // RUN_IN_BACKGROUND
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800956 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700957 null, // READ_PHONE_NUMBERS
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800958 null, // REQUEST_INSTALL_PACKAGES
Winson Chung59fda9e2017-01-20 16:14:51 -0800959 null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
Chad Brubaker97b383f2017-02-02 15:04:35 -0800960 null, // INSTANT_APP_START_FOREGROUND
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800961 null, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700962 null, // OP_RUN_ANY_IN_BACKGROUND
Peter Visontay1246d9e2017-10-17 17:02:45 +0100963 null, // OP_CHANGE_WIFI_STATE
Peter Visontayf2e38362017-11-27 15:27:16 +0000964 null, // REQUEST_DELETE_PACKAGES
Peter Visontay11950832017-11-14 19:34:59 +0000965 null, // OP_BIND_ACCESSIBILITY_SERVICE
Tyler Gunn79bc1ec2018-01-22 15:17:54 -0800966 null, // ACCEPT_HANDOVER
Jason Monk1c7c3192014-06-26 12:52:18 -0400967 };
968
969 /**
970 * This specifies whether each option should allow the system
971 * (and system ui) to bypass the user restriction when active.
972 */
973 private static boolean[] sOpAllowSystemRestrictionBypass = new boolean[] {
Fyodor Kupolov639e73d2016-02-25 11:58:21 -0800974 true, //COARSE_LOCATION
975 true, //FINE_LOCATION
Jason Monk1c7c3192014-06-26 12:52:18 -0400976 false, //GPS
977 false, //VIBRATE
978 false, //READ_CONTACTS
979 false, //WRITE_CONTACTS
980 false, //READ_CALL_LOG
981 false, //WRITE_CALL_LOG
982 false, //READ_CALENDAR
983 false, //WRITE_CALENDAR
Julia Reynolds9854d572014-07-02 14:46:02 -0400984 true, //WIFI_SCAN
Jason Monk1c7c3192014-06-26 12:52:18 -0400985 false, //POST_NOTIFICATION
986 false, //NEIGHBORING_CELLS
987 false, //CALL_PHONE
988 false, //READ_SMS
989 false, //WRITE_SMS
990 false, //RECEIVE_SMS
991 false, //RECEIVE_EMERGECY_SMS
992 false, //RECEIVE_MMS
993 false, //RECEIVE_WAP_PUSH
994 false, //SEND_SMS
995 false, //READ_ICC_SMS
996 false, //WRITE_ICC_SMS
997 false, //WRITE_SETTINGS
998 true, //SYSTEM_ALERT_WINDOW
999 false, //ACCESS_NOTIFICATIONS
1000 false, //CAMERA
1001 false, //RECORD_AUDIO
1002 false, //PLAY_AUDIO
1003 false, //READ_CLIPBOARD
1004 false, //WRITE_CLIPBOARD
1005 false, //TAKE_MEDIA_BUTTONS
1006 false, //TAKE_AUDIO_FOCUS
1007 false, //AUDIO_MASTER_VOLUME
1008 false, //AUDIO_VOICE_VOLUME
1009 false, //AUDIO_RING_VOLUME
1010 false, //AUDIO_MEDIA_VOLUME
1011 false, //AUDIO_ALARM_VOLUME
1012 false, //AUDIO_NOTIFICATION_VOLUME
1013 false, //AUDIO_BLUETOOTH_VOLUME
1014 false, //WAKE_LOCK
1015 false, //MONITOR_LOCATION
1016 false, //MONITOR_HIGH_POWER_LOCATION
1017 false, //GET_USAGE_STATS
Michael Wrightc39d47a2014-07-08 18:07:36 -07001018 false, //MUTE_MICROPHONE
1019 true, //TOAST_WINDOW
1020 false, //PROJECT_MEDIA
Jeff Davidson05542602014-08-11 14:07:27 -07001021 false, //ACTIVATE_VPN
Benjamin Franzf3ece362015-02-11 10:51:10 +00001022 false, //WALLPAPER
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07001023 false, //ASSIST_STRUCTURE
1024 false, //ASSIST_SCREENSHOT
Svet Ganov16a16892015-04-16 10:32:04 -07001025 false, //READ_PHONE_STATE
Svetoslav5335b672015-04-29 12:00:51 -07001026 false, //ADD_VOICEMAIL
Svetoslavc656e6f2015-04-29 14:08:16 -07001027 false, // USE_SIP
Svetoslav4af76a52015-04-29 15:29:46 -07001028 false, // PROCESS_OUTGOING_CALLS
Svet Ganovb9d71a62015-04-30 10:38:13 -07001029 false, // USE_FINGERPRINT
Svet Ganovede43162015-05-02 17:42:44 -07001030 false, // BODY_SENSORS
Svet Ganovf7e9cf42015-05-13 10:40:31 -07001031 false, // READ_CELL_BROADCASTS
Svet Ganov921c7df2015-06-29 21:51:41 -07001032 false, // MOCK_LOCATION
1033 false, // READ_EXTERNAL_STORAGE
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001034 false, // WRITE_EXTERNAL_STORAGE
1035 false, // TURN_ON_SCREEN
Svetoslavf3f02ac2015-09-08 14:36:35 -07001036 false, // GET_ACCOUNTS
Dianne Hackbornbef28fe2015-10-29 17:57:11 -07001037 false, // RUN_IN_BACKGROUND
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -08001038 false, // AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker0c1651f2017-03-30 16:29:10 -07001039 false, // READ_PHONE_NUMBERS
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -08001040 false, // REQUEST_INSTALL_PACKAGES
Winson Chung59fda9e2017-01-20 16:14:51 -08001041 false, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
Chad Brubaker97b383f2017-02-02 15:04:35 -08001042 false, // INSTANT_APP_START_FOREGROUND
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001043 false, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -07001044 false, // OP_RUN_ANY_IN_BACKGROUND
Peter Visontay1246d9e2017-10-17 17:02:45 +01001045 false, // OP_CHANGE_WIFI_STATE
Peter Visontayf2e38362017-11-27 15:27:16 +00001046 false, // OP_REQUEST_DELETE_PACKAGES
Peter Visontay11950832017-11-14 19:34:59 +00001047 false, // OP_BIND_ACCESSIBILITY_SERVICE
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001048 false, // ACCEPT_HANDOVER
Jason Monk62062992014-05-06 09:55:28 -04001049 };
1050
1051 /**
David Braunf5d83192013-09-16 13:43:51 -07001052 * This specifies the default mode for each operation.
1053 */
1054 private static int[] sOpDefaultMode = new int[] {
1055 AppOpsManager.MODE_ALLOWED,
1056 AppOpsManager.MODE_ALLOWED,
1057 AppOpsManager.MODE_ALLOWED,
1058 AppOpsManager.MODE_ALLOWED,
1059 AppOpsManager.MODE_ALLOWED,
1060 AppOpsManager.MODE_ALLOWED,
1061 AppOpsManager.MODE_ALLOWED,
1062 AppOpsManager.MODE_ALLOWED,
1063 AppOpsManager.MODE_ALLOWED,
1064 AppOpsManager.MODE_ALLOWED,
1065 AppOpsManager.MODE_ALLOWED,
1066 AppOpsManager.MODE_ALLOWED,
1067 AppOpsManager.MODE_ALLOWED,
1068 AppOpsManager.MODE_ALLOWED,
1069 AppOpsManager.MODE_ALLOWED,
1070 AppOpsManager.MODE_IGNORED, // OP_WRITE_SMS
1071 AppOpsManager.MODE_ALLOWED,
1072 AppOpsManager.MODE_ALLOWED,
1073 AppOpsManager.MODE_ALLOWED,
1074 AppOpsManager.MODE_ALLOWED,
1075 AppOpsManager.MODE_ALLOWED,
1076 AppOpsManager.MODE_ALLOWED,
1077 AppOpsManager.MODE_ALLOWED,
Billy Lau6ad2d662015-07-18 00:26:58 +01001078 AppOpsManager.MODE_DEFAULT, // OP_WRITE_SETTINGS
Billy Lau060275f2015-07-15 22:29:19 +01001079 AppOpsManager.MODE_DEFAULT, // OP_SYSTEM_ALERT_WINDOW
David Braunf5d83192013-09-16 13:43:51 -07001080 AppOpsManager.MODE_ALLOWED,
1081 AppOpsManager.MODE_ALLOWED,
1082 AppOpsManager.MODE_ALLOWED,
1083 AppOpsManager.MODE_ALLOWED,
1084 AppOpsManager.MODE_ALLOWED,
1085 AppOpsManager.MODE_ALLOWED,
1086 AppOpsManager.MODE_ALLOWED,
1087 AppOpsManager.MODE_ALLOWED,
1088 AppOpsManager.MODE_ALLOWED,
1089 AppOpsManager.MODE_ALLOWED,
1090 AppOpsManager.MODE_ALLOWED,
1091 AppOpsManager.MODE_ALLOWED,
1092 AppOpsManager.MODE_ALLOWED,
1093 AppOpsManager.MODE_ALLOWED,
1094 AppOpsManager.MODE_ALLOWED,
1095 AppOpsManager.MODE_ALLOWED,
1096 AppOpsManager.MODE_ALLOWED,
1097 AppOpsManager.MODE_ALLOWED,
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -07001098 AppOpsManager.MODE_DEFAULT, // OP_GET_USAGE_STATS
Emily Bernier22c921a2014-05-28 11:01:32 -04001099 AppOpsManager.MODE_ALLOWED,
Jason Monk1c7c3192014-06-26 12:52:18 -04001100 AppOpsManager.MODE_ALLOWED,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001101 AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
Jeff Davidson05542602014-08-11 14:07:27 -07001102 AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
Benjamin Franzf3ece362015-02-11 10:51:10 +00001103 AppOpsManager.MODE_ALLOWED,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07001104 AppOpsManager.MODE_ALLOWED,
1105 AppOpsManager.MODE_ALLOWED,
Svet Ganovc3300092015-04-17 09:07:22 -07001106 AppOpsManager.MODE_ALLOWED,
Svetoslav5335b672015-04-29 12:00:51 -07001107 AppOpsManager.MODE_ALLOWED,
Svetoslavc656e6f2015-04-29 14:08:16 -07001108 AppOpsManager.MODE_ALLOWED,
Svetoslav4af76a52015-04-29 15:29:46 -07001109 AppOpsManager.MODE_ALLOWED,
Svet Ganovb9d71a62015-04-30 10:38:13 -07001110 AppOpsManager.MODE_ALLOWED,
Svet Ganovede43162015-05-02 17:42:44 -07001111 AppOpsManager.MODE_ALLOWED,
Svet Ganovf7e9cf42015-05-13 10:40:31 -07001112 AppOpsManager.MODE_ALLOWED,
Svet Ganov921c7df2015-06-29 21:51:41 -07001113 AppOpsManager.MODE_ERRORED, // OP_MOCK_LOCATION
1114 AppOpsManager.MODE_ALLOWED,
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001115 AppOpsManager.MODE_ALLOWED,
1116 AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN
Svetoslavf3f02ac2015-09-08 14:36:35 -07001117 AppOpsManager.MODE_ALLOWED,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -07001118 AppOpsManager.MODE_ALLOWED, // OP_RUN_IN_BACKGROUND
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -08001119 AppOpsManager.MODE_ALLOWED, // OP_AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker73ec8f92016-11-10 11:24:40 -08001120 AppOpsManager.MODE_ALLOWED,
Svet Ganovda0acdf2017-02-15 10:28:51 -08001121 AppOpsManager.MODE_DEFAULT, // OP_REQUEST_INSTALL_PACKAGES
Winson Chungf4ac0632017-03-17 12:34:12 -07001122 AppOpsManager.MODE_ALLOWED, // OP_PICTURE_IN_PICTURE
Svet Ganovda0acdf2017-02-15 10:28:51 -08001123 AppOpsManager.MODE_DEFAULT, // OP_INSTANT_APP_START_FOREGROUND
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001124 AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -07001125 AppOpsManager.MODE_ALLOWED, // OP_RUN_ANY_IN_BACKGROUND
Peter Visontay1246d9e2017-10-17 17:02:45 +01001126 AppOpsManager.MODE_ALLOWED, // OP_CHANGE_WIFI_STATE
Peter Visontayf2e38362017-11-27 15:27:16 +00001127 AppOpsManager.MODE_ALLOWED, // REQUEST_DELETE_PACKAGES
Peter Visontay11950832017-11-14 19:34:59 +00001128 AppOpsManager.MODE_ALLOWED, // OP_BIND_ACCESSIBILITY_SERVICE
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001129 AppOpsManager.MODE_ALLOWED, // ACCEPT_HANDOVER
David Braunf5d83192013-09-16 13:43:51 -07001130 };
1131
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001132 /**
1133 * This specifies whether each option is allowed to be reset
1134 * when resetting all app preferences. Disable reset for
1135 * app ops that are under strong control of some part of the
1136 * system (such as OP_WRITE_SMS, which should be allowed only
1137 * for whichever app is selected as the current SMS app).
1138 */
1139 private static boolean[] sOpDisableReset = new boolean[] {
1140 false,
1141 false,
1142 false,
1143 false,
1144 false,
1145 false,
1146 false,
1147 false,
1148 false,
1149 false,
1150 false,
1151 false,
1152 false,
1153 false,
1154 false,
1155 true, // OP_WRITE_SMS
1156 false,
1157 false,
1158 false,
1159 false,
1160 false,
1161 false,
1162 false,
1163 false,
1164 false,
1165 false,
1166 false,
1167 false,
1168 false,
1169 false,
1170 false,
1171 false,
1172 false,
1173 false,
1174 false,
1175 false,
1176 false,
1177 false,
1178 false,
1179 false,
1180 false,
1181 false,
1182 false,
Dianne Hackborne22b3b12014-05-07 18:06:44 -07001183 false,
Emily Bernier22c921a2014-05-28 11:01:32 -04001184 false,
Jason Monk1c7c3192014-06-26 12:52:18 -04001185 false,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001186 false,
Jeff Davidson05542602014-08-11 14:07:27 -07001187 false,
Benjamin Franzf3ece362015-02-11 10:51:10 +00001188 false,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07001189 false,
1190 false,
Svet Ganovc3300092015-04-17 09:07:22 -07001191 false,
Svetoslav5335b672015-04-29 12:00:51 -07001192 false,
Svetoslavc656e6f2015-04-29 14:08:16 -07001193 false,
Svetoslav4af76a52015-04-29 15:29:46 -07001194 false,
Svet Ganovb9d71a62015-04-30 10:38:13 -07001195 false,
Svet Ganovede43162015-05-02 17:42:44 -07001196 false,
Svet Ganovf7e9cf42015-05-13 10:40:31 -07001197 false,
Svet Ganov921c7df2015-06-29 21:51:41 -07001198 false,
1199 false,
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001200 false,
1201 false,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -07001202 false,
1203 false,
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -08001204 false, // OP_AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker73ec8f92016-11-10 11:24:40 -08001205 false,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -08001206 false, // OP_REQUEST_INSTALL_PACKAGES
Winson Chungf4ac0632017-03-17 12:34:12 -07001207 false, // OP_PICTURE_IN_PICTURE
Chad Brubaker97b383f2017-02-02 15:04:35 -08001208 false,
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001209 false, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -07001210 false, // OP_RUN_ANY_IN_BACKGROUND
Peter Visontay1246d9e2017-10-17 17:02:45 +01001211 false, // OP_CHANGE_WIFI_STATE
Peter Visontayf2e38362017-11-27 15:27:16 +00001212 false, // OP_REQUEST_DELETE_PACKAGES
Peter Visontay11950832017-11-14 19:34:59 +00001213 false, // OP_BIND_ACCESSIBILITY_SERVICE
Tyler Gunn79bc1ec2018-01-22 15:17:54 -08001214 false, // ACCEPT_HANDOVER
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001215 };
1216
Svet Ganovfbf01f72015-04-28 18:39:06 -07001217 /**
Svet Ganovb9d71a62015-04-30 10:38:13 -07001218 * Mapping from an app op name to the app op code.
Svet Ganovfbf01f72015-04-28 18:39:06 -07001219 */
Svet Ganovb9d71a62015-04-30 10:38:13 -07001220 private static HashMap<String, Integer> sOpStrToOp = new HashMap<>();
Svet Ganovfbf01f72015-04-28 18:39:06 -07001221
Svet Ganovb9d71a62015-04-30 10:38:13 -07001222 /**
1223 * Mapping from a permission to the corresponding app op.
1224 */
Svet Ganovda0acdf2017-02-15 10:28:51 -08001225 private static HashMap<String, Integer> sPermToOp = new HashMap<>();
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001226
1227 static {
1228 if (sOpToSwitch.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001229 throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001230 + " should be " + _NUM_OP);
1231 }
1232 if (sOpToString.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001233 throw new IllegalStateException("sOpToString length " + sOpToString.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001234 + " should be " + _NUM_OP);
1235 }
1236 if (sOpNames.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001237 throw new IllegalStateException("sOpNames length " + sOpNames.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001238 + " should be " + _NUM_OP);
1239 }
1240 if (sOpPerms.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001241 throw new IllegalStateException("sOpPerms length " + sOpPerms.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001242 + " should be " + _NUM_OP);
1243 }
1244 if (sOpDefaultMode.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001245 throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length
1246 + " should be " + _NUM_OP);
1247 }
1248 if (sOpDisableReset.length != _NUM_OP) {
1249 throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001250 + " should be " + _NUM_OP);
1251 }
Jason Monk62062992014-05-06 09:55:28 -04001252 if (sOpRestrictions.length != _NUM_OP) {
1253 throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length
1254 + " should be " + _NUM_OP);
1255 }
Jason Monk1c7c3192014-06-26 12:52:18 -04001256 if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) {
1257 throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length "
1258 + sOpRestrictions.length + " should be " + _NUM_OP);
1259 }
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001260 for (int i=0; i<_NUM_OP; i++) {
1261 if (sOpToString[i] != null) {
1262 sOpStrToOp.put(sOpToString[i], i);
1263 }
1264 }
Svet Ganovda0acdf2017-02-15 10:28:51 -08001265 for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) {
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -07001266 if (sOpPerms[op] != null) {
Svet Ganovda0acdf2017-02-15 10:28:51 -08001267 sPermToOp.put(sOpPerms[op], op);
Svet Ganovb9d71a62015-04-30 10:38:13 -07001268 }
1269 }
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001270 }
1271
David Braunf5d83192013-09-16 13:43:51 -07001272 /**
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001273 * Retrieve the op switch that controls the given operation.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001274 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001275 */
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001276 public static int opToSwitch(int op) {
1277 return sOpToSwitch[op];
1278 }
1279
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001280 /**
1281 * Retrieve a non-localized name for the operation, for debugging output.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001282 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001283 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001284 public static String opToName(int op) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001285 if (op == OP_NONE) return "NONE";
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001286 return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")");
1287 }
1288
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001289 /**
Dianne Hackborn7b7c58b2014-12-02 18:32:20 -08001290 * @hide
1291 */
1292 public static int strDebugOpToOp(String op) {
1293 for (int i=0; i<sOpNames.length; i++) {
1294 if (sOpNames[i].equals(op)) {
1295 return i;
1296 }
1297 }
1298 throw new IllegalArgumentException("Unknown operation string: " + op);
1299 }
1300
1301 /**
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001302 * Retrieve the permission associated with an operation, or null if there is not one.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001303 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001304 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001305 public static String opToPermission(int op) {
1306 return sOpPerms[op];
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001307 }
1308
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001309 /**
Jason Monk62062992014-05-06 09:55:28 -04001310 * Retrieve the user restriction associated with an operation, or null if there is not one.
1311 * @hide
1312 */
1313 public static String opToRestriction(int op) {
1314 return sOpRestrictions[op];
1315 }
1316
1317 /**
Svet Ganovb9d71a62015-04-30 10:38:13 -07001318 * Retrieve the app op code for a permission, or null if there is not one.
Svet Ganovda0acdf2017-02-15 10:28:51 -08001319 * This API is intended to be used for mapping runtime or appop permissions
1320 * to the corresponding app op.
Svet Ganovb9d71a62015-04-30 10:38:13 -07001321 * @hide
1322 */
1323 public static int permissionToOpCode(String permission) {
Svet Ganovda0acdf2017-02-15 10:28:51 -08001324 Integer boxedOpCode = sPermToOp.get(permission);
Svet Ganov019d2302015-05-04 11:07:38 -07001325 return boxedOpCode != null ? boxedOpCode : OP_NONE;
Svet Ganovb9d71a62015-04-30 10:38:13 -07001326 }
1327
1328 /**
Jason Monk1c7c3192014-06-26 12:52:18 -04001329 * Retrieve whether the op allows the system (and system ui) to
1330 * bypass the user restriction.
1331 * @hide
1332 */
1333 public static boolean opAllowSystemBypassRestriction(int op) {
1334 return sOpAllowSystemRestrictionBypass[op];
1335 }
1336
1337 /**
David Braunf5d83192013-09-16 13:43:51 -07001338 * Retrieve the default mode for the operation.
1339 * @hide
1340 */
1341 public static int opToDefaultMode(int op) {
1342 return sOpDefaultMode[op];
1343 }
1344
1345 /**
Svet Ganov82f09bc2018-01-12 22:08:40 -08001346 * Retrieve the human readable mode.
1347 * @hide
1348 */
1349 public static String modeToString(int mode) {
1350 switch (mode) {
1351 case MODE_ALLOWED:
1352 return "allow";
1353 case MODE_IGNORED:
1354 return "ignore";
1355 case MODE_ERRORED:
1356 return "deny";
1357 case MODE_DEFAULT:
1358 return "default";
1359 default:
1360 return "mode=" + mode;
1361 }
1362 }
1363
1364 /**
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001365 * Retrieve whether the op allows itself to be reset.
1366 * @hide
1367 */
1368 public static boolean opAllowsReset(int op) {
1369 return !sOpDisableReset[op];
1370 }
1371
1372 /**
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001373 * Class holding all of the operation information associated with an app.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001374 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001375 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001376 public static class PackageOps implements Parcelable {
1377 private final String mPackageName;
1378 private final int mUid;
1379 private final List<OpEntry> mEntries;
1380
1381 public PackageOps(String packageName, int uid, List<OpEntry> entries) {
1382 mPackageName = packageName;
1383 mUid = uid;
1384 mEntries = entries;
1385 }
1386
1387 public String getPackageName() {
1388 return mPackageName;
1389 }
1390
1391 public int getUid() {
1392 return mUid;
1393 }
1394
1395 public List<OpEntry> getOps() {
1396 return mEntries;
1397 }
1398
1399 @Override
1400 public int describeContents() {
1401 return 0;
1402 }
1403
1404 @Override
1405 public void writeToParcel(Parcel dest, int flags) {
1406 dest.writeString(mPackageName);
1407 dest.writeInt(mUid);
1408 dest.writeInt(mEntries.size());
1409 for (int i=0; i<mEntries.size(); i++) {
1410 mEntries.get(i).writeToParcel(dest, flags);
1411 }
1412 }
1413
1414 PackageOps(Parcel source) {
1415 mPackageName = source.readString();
1416 mUid = source.readInt();
1417 mEntries = new ArrayList<OpEntry>();
1418 final int N = source.readInt();
1419 for (int i=0; i<N; i++) {
1420 mEntries.add(OpEntry.CREATOR.createFromParcel(source));
1421 }
1422 }
1423
1424 public static final Creator<PackageOps> CREATOR = new Creator<PackageOps>() {
1425 @Override public PackageOps createFromParcel(Parcel source) {
1426 return new PackageOps(source);
1427 }
1428
1429 @Override public PackageOps[] newArray(int size) {
1430 return new PackageOps[size];
1431 }
1432 };
1433 }
1434
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001435 /**
1436 * Class holding the information about one unique operation of an application.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001437 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001438 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001439 public static class OpEntry implements Parcelable {
1440 private final int mOp;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001441 private final int mMode;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001442 private final long mTime;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001443 private final long mRejectTime;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001444 private final int mDuration;
Svet Ganov99b60432015-06-27 13:15:22 -07001445 private final int mProxyUid;
1446 private final String mProxyPackageName;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001447
Svet Ganov99b60432015-06-27 13:15:22 -07001448 public OpEntry(int op, int mode, long time, long rejectTime, int duration,
1449 int proxyUid, String proxyPackage) {
Dianne Hackborn35654b62013-01-14 17:38:02 -08001450 mOp = op;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001451 mMode = mode;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001452 mTime = time;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001453 mRejectTime = rejectTime;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001454 mDuration = duration;
Svet Ganov99b60432015-06-27 13:15:22 -07001455 mProxyUid = proxyUid;
1456 mProxyPackageName = proxyPackage;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001457 }
1458
1459 public int getOp() {
1460 return mOp;
1461 }
1462
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001463 public int getMode() {
1464 return mMode;
1465 }
1466
Dianne Hackborn35654b62013-01-14 17:38:02 -08001467 public long getTime() {
1468 return mTime;
1469 }
1470
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001471 public long getRejectTime() {
1472 return mRejectTime;
1473 }
1474
Dianne Hackborn35654b62013-01-14 17:38:02 -08001475 public boolean isRunning() {
1476 return mDuration == -1;
1477 }
1478
1479 public int getDuration() {
1480 return mDuration == -1 ? (int)(System.currentTimeMillis()-mTime) : mDuration;
1481 }
1482
Svet Ganov99b60432015-06-27 13:15:22 -07001483 public int getProxyUid() {
1484 return mProxyUid;
1485 }
1486
1487 public String getProxyPackageName() {
1488 return mProxyPackageName;
1489 }
1490
Dianne Hackborn35654b62013-01-14 17:38:02 -08001491 @Override
1492 public int describeContents() {
1493 return 0;
1494 }
1495
1496 @Override
1497 public void writeToParcel(Parcel dest, int flags) {
1498 dest.writeInt(mOp);
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001499 dest.writeInt(mMode);
Dianne Hackborn35654b62013-01-14 17:38:02 -08001500 dest.writeLong(mTime);
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001501 dest.writeLong(mRejectTime);
Dianne Hackborn35654b62013-01-14 17:38:02 -08001502 dest.writeInt(mDuration);
Svet Ganov99b60432015-06-27 13:15:22 -07001503 dest.writeInt(mProxyUid);
1504 dest.writeString(mProxyPackageName);
Dianne Hackborn35654b62013-01-14 17:38:02 -08001505 }
1506
1507 OpEntry(Parcel source) {
1508 mOp = source.readInt();
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001509 mMode = source.readInt();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001510 mTime = source.readLong();
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001511 mRejectTime = source.readLong();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001512 mDuration = source.readInt();
Svet Ganov99b60432015-06-27 13:15:22 -07001513 mProxyUid = source.readInt();
1514 mProxyPackageName = source.readString();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001515 }
1516
1517 public static final Creator<OpEntry> CREATOR = new Creator<OpEntry>() {
1518 @Override public OpEntry createFromParcel(Parcel source) {
1519 return new OpEntry(source);
1520 }
1521
1522 @Override public OpEntry[] newArray(int size) {
1523 return new OpEntry[size];
1524 }
1525 };
1526 }
1527
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001528 /**
1529 * Callback for notification of changes to operation state.
1530 */
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001531 public interface OnOpChangedListener {
1532 public void onOpChanged(String op, String packageName);
1533 }
1534
1535 /**
1536 * Callback for notification of changes to operation state.
1537 * This allows you to see the raw op codes instead of strings.
1538 * @hide
1539 */
1540 public static class OnOpChangedInternalListener implements OnOpChangedListener {
1541 public void onOpChanged(String op, String packageName) { }
1542 public void onOpChanged(int op, String packageName) { }
Dianne Hackbornc2293022013-02-06 23:14:49 -08001543 }
1544
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001545 AppOpsManager(Context context, IAppOpsService service) {
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001546 mContext = context;
1547 mService = service;
1548 }
1549
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001550 /**
1551 * Retrieve current operation state for all applications.
1552 *
1553 * @param ops The set of operations you are interested in, or null if you want all of them.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001554 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001555 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001556 public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
1557 try {
1558 return mService.getPackagesForOps(ops);
1559 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001560 throw e.rethrowFromSystemServer();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001561 }
Dianne Hackborn35654b62013-01-14 17:38:02 -08001562 }
1563
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001564 /**
1565 * Retrieve current operation state for one application.
1566 *
1567 * @param uid The uid of the application of interest.
1568 * @param packageName The name of the application of interest.
1569 * @param ops The set of operations you are interested in, or null if you want all of them.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001570 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001571 */
Dianne Hackborn72e39832013-01-18 18:36:09 -08001572 public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) {
1573 try {
1574 return mService.getOpsForPackage(uid, packageName, ops);
1575 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001576 throw e.rethrowFromSystemServer();
Dianne Hackborn72e39832013-01-18 18:36:09 -08001577 }
Dianne Hackborn72e39832013-01-18 18:36:09 -08001578 }
1579
Svet Ganovae0e03a2016-02-25 18:22:10 -08001580 /**
1581 * Sets given app op in the specified mode for app ops in the UID.
1582 * This applies to all apps currently in the UID or installed in
1583 * this UID in the future.
1584 *
1585 * @param code The app op.
1586 * @param uid The UID for which to set the app.
1587 * @param mode The app op mode to set.
1588 * @hide
1589 */
Svet Ganov2af57082015-07-30 08:44:20 -07001590 public void setUidMode(int code, int uid, int mode) {
1591 try {
1592 mService.setUidMode(code, uid, mode);
1593 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001594 throw e.rethrowFromSystemServer();
Svet Ganov2af57082015-07-30 08:44:20 -07001595 }
1596 }
1597
Svet Ganovae0e03a2016-02-25 18:22:10 -08001598 /**
1599 * Sets given app op in the specified mode for app ops in the UID.
1600 * This applies to all apps currently in the UID or installed in
1601 * this UID in the future.
1602 *
1603 * @param appOp The app op.
1604 * @param uid The UID for which to set the app.
1605 * @param mode The app op mode to set.
1606 * @hide
1607 */
1608 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001609 @RequiresPermission(android.Manifest.permission.UPDATE_APP_OPS_STATS)
Svet Ganovae0e03a2016-02-25 18:22:10 -08001610 public void setUidMode(String appOp, int uid, int mode) {
1611 try {
1612 mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode);
1613 } catch (RemoteException e) {
1614 throw e.rethrowFromSystemServer();
1615 }
1616 }
1617
Svet Ganov2af57082015-07-30 08:44:20 -07001618 /** @hide */
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001619 public void setUserRestriction(int code, boolean restricted, IBinder token) {
Ruben Brunk29931bc2016-03-11 00:24:26 -08001620 setUserRestriction(code, restricted, token, /*exceptionPackages*/null);
1621 }
1622
1623 /** @hide */
1624 public void setUserRestriction(int code, boolean restricted, IBinder token,
1625 String[] exceptionPackages) {
Svetoslav Ganove33f6132016-06-01 16:25:31 -07001626 setUserRestrictionForUser(code, restricted, token, exceptionPackages, mContext.getUserId());
1627 }
1628
1629 /** @hide */
1630 public void setUserRestrictionForUser(int code, boolean restricted, IBinder token,
1631 String[] exceptionPackages, int userId) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001632 try {
Svetoslav Ganove33f6132016-06-01 16:25:31 -07001633 mService.setUserRestriction(code, restricted, token, userId, exceptionPackages);
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001634 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001635 throw e.rethrowFromSystemServer();
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001636 }
1637 }
1638
1639 /** @hide */
Peter Visontayb97fbc82017-12-21 16:23:55 +00001640 @TestApi
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001641 public void setMode(int code, int uid, String packageName, int mode) {
1642 try {
1643 mService.setMode(code, uid, packageName, mode);
1644 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001645 throw e.rethrowFromSystemServer();
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001646 }
1647 }
1648
John Spurlock1af30c72014-03-10 08:33:35 -04001649 /**
1650 * Set a non-persisted restriction on an audio operation at a stream-level.
1651 * Restrictions are temporary additional constraints imposed on top of the persisted rules
1652 * defined by {@link #setMode}.
1653 *
1654 * @param code The operation to restrict.
John Spurlock7b414672014-07-18 13:02:39 -04001655 * @param usage The {@link android.media.AudioAttributes} usage value.
John Spurlock1af30c72014-03-10 08:33:35 -04001656 * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict.
1657 * @param exceptionPackages Optional list of packages to exclude from the restriction.
1658 * @hide
1659 */
John Spurlock7b414672014-07-18 13:02:39 -04001660 public void setRestriction(int code, @AttributeUsage int usage, int mode,
1661 String[] exceptionPackages) {
John Spurlock1af30c72014-03-10 08:33:35 -04001662 try {
1663 final int uid = Binder.getCallingUid();
John Spurlock7b414672014-07-18 13:02:39 -04001664 mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages);
John Spurlock1af30c72014-03-10 08:33:35 -04001665 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001666 throw e.rethrowFromSystemServer();
John Spurlock1af30c72014-03-10 08:33:35 -04001667 }
1668 }
1669
Dianne Hackborn607b4142013-08-02 18:10:10 -07001670 /** @hide */
1671 public void resetAllModes() {
1672 try {
Dianne Hackborn7b7c58b2014-12-02 18:32:20 -08001673 mService.resetAllModes(UserHandle.myUserId(), null);
Dianne Hackborn607b4142013-08-02 18:10:10 -07001674 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001675 throw e.rethrowFromSystemServer();
Dianne Hackborn607b4142013-08-02 18:10:10 -07001676 }
1677 }
1678
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001679 /**
Svet Ganovfbf01f72015-04-28 18:39:06 -07001680 * Gets the app op name associated with a given permission.
1681 * The app op name is one of the public constants defined
1682 * in this class such as {@link #OPSTR_COARSE_LOCATION}.
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -07001683 * This API is intended to be used for mapping runtime
1684 * permissions to the corresponding app op.
Svet Ganovfbf01f72015-04-28 18:39:06 -07001685 *
1686 * @param permission The permission.
1687 * @return The app op associated with the permission or null.
Svet Ganovfbf01f72015-04-28 18:39:06 -07001688 */
Svet Ganovfbf01f72015-04-28 18:39:06 -07001689 public static String permissionToOp(String permission) {
Svet Ganovda0acdf2017-02-15 10:28:51 -08001690 final Integer opCode = sPermToOp.get(permission);
Svet Ganovb9d71a62015-04-30 10:38:13 -07001691 if (opCode == null) {
1692 return null;
1693 }
1694 return sOpToString[opCode];
Svet Ganovfbf01f72015-04-28 18:39:06 -07001695 }
1696
1697 /**
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001698 * Monitor for changes to the operating mode for the given op in the given app package.
Dianne Hackborne4cb66f2013-10-02 10:34:02 -07001699 * @param op The operation to monitor, one of OPSTR_*.
1700 * @param packageName The name of the application to monitor.
1701 * @param callback Where to report changes.
1702 */
1703 public void startWatchingMode(String op, String packageName,
1704 final OnOpChangedListener callback) {
1705 startWatchingMode(strOpToOp(op), packageName, callback);
1706 }
1707
1708 /**
1709 * Monitor for changes to the operating mode for the given op in the given app package.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001710 * @param op The operation to monitor, one of OP_*.
1711 * @param packageName The name of the application to monitor.
1712 * @param callback Where to report changes.
Dianne Hackborne4cb66f2013-10-02 10:34:02 -07001713 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001714 */
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001715 public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001716 synchronized (mModeWatchers) {
1717 IAppOpsCallback cb = mModeWatchers.get(callback);
1718 if (cb == null) {
1719 cb = new IAppOpsCallback.Stub() {
Dianne Hackbornbef28fe2015-10-29 17:57:11 -07001720 public void opChanged(int op, int uid, String packageName) {
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001721 if (callback instanceof OnOpChangedInternalListener) {
1722 ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName);
1723 }
1724 if (sOpToString[op] != null) {
1725 callback.onOpChanged(sOpToString[op], packageName);
1726 }
Dianne Hackbornc2293022013-02-06 23:14:49 -08001727 }
1728 };
1729 mModeWatchers.put(callback, cb);
1730 }
1731 try {
1732 mService.startWatchingMode(op, packageName, cb);
1733 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001734 throw e.rethrowFromSystemServer();
Dianne Hackbornc2293022013-02-06 23:14:49 -08001735 }
1736 }
1737 }
1738
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001739 /**
1740 * Stop monitoring that was previously started with {@link #startWatchingMode}. All
1741 * monitoring associated with this callback will be removed.
1742 */
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001743 public void stopWatchingMode(OnOpChangedListener callback) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001744 synchronized (mModeWatchers) {
1745 IAppOpsCallback cb = mModeWatchers.get(callback);
1746 if (cb != null) {
1747 try {
1748 mService.stopWatchingMode(cb);
1749 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001750 throw e.rethrowFromSystemServer();
Dianne Hackbornc2293022013-02-06 23:14:49 -08001751 }
1752 }
1753 }
1754 }
1755
Dianne Hackborn95d78532013-09-11 09:51:14 -07001756 private String buildSecurityExceptionMsg(int op, int uid, String packageName) {
1757 return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op];
1758 }
1759
Adam Lesinskib5cf61b2014-08-18 16:10:28 -07001760 /**
1761 * {@hide}
1762 */
1763 public static int strOpToOp(String op) {
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001764 Integer val = sOpStrToOp.get(op);
1765 if (val == null) {
1766 throw new IllegalArgumentException("Unknown operation string: " + op);
1767 }
1768 return val;
1769 }
1770
1771 /**
1772 * Do a quick check for whether an application might be able to perform an operation.
1773 * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String)}
1774 * or {@link #startOp(String, int, String)} for your actual security checks, which also
1775 * ensure that the given uid and package name are consistent. This function can just be
1776 * used for a quick check to see if an operation has been disabled for the application,
1777 * as an early reject of some work. This does not modify the time stamp or other data
1778 * about the operation.
1779 * @param op The operation to check. One of the OPSTR_* constants.
1780 * @param uid The user id of the application attempting to perform the operation.
1781 * @param packageName The name of the application attempting to perform the operation.
1782 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1783 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1784 * causing the app to crash).
1785 * @throws SecurityException If the app has been configured to crash on this op.
1786 */
1787 public int checkOp(String op, int uid, String packageName) {
1788 return checkOp(strOpToOp(op), uid, packageName);
1789 }
1790
1791 /**
John Spurlock925b85e2014-03-10 16:52:11 -04001792 * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001793 * returns {@link #MODE_ERRORED}.
1794 */
1795 public int checkOpNoThrow(String op, int uid, String packageName) {
1796 return checkOpNoThrow(strOpToOp(op), uid, packageName);
1797 }
1798
1799 /**
1800 * Make note of an application performing an operation. Note that you must pass
1801 * in both the uid and name of the application to be checked; this function will verify
1802 * that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1803 * succeeds, the last execution time of the operation for this app will be updated to
1804 * the current time.
1805 * @param op The operation to note. One of the OPSTR_* constants.
1806 * @param uid The user id of the application attempting to perform the operation.
1807 * @param packageName The name of the application attempting to perform the operation.
1808 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1809 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1810 * causing the app to crash).
1811 * @throws SecurityException If the app has been configured to crash on this op.
1812 */
1813 public int noteOp(String op, int uid, String packageName) {
1814 return noteOp(strOpToOp(op), uid, packageName);
1815 }
1816
1817 /**
1818 * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it
1819 * returns {@link #MODE_ERRORED}.
1820 */
1821 public int noteOpNoThrow(String op, int uid, String packageName) {
1822 return noteOpNoThrow(strOpToOp(op), uid, packageName);
1823 }
1824
1825 /**
Svet Ganov99b60432015-06-27 13:15:22 -07001826 * Make note of an application performing an operation on behalf of another
1827 * application when handling an IPC. Note that you must pass the package name
1828 * of the application that is being proxied while its UID will be inferred from
1829 * the IPC state; this function will verify that the calling uid and proxied
1830 * package name match, and if not, return {@link #MODE_IGNORED}. If this call
1831 * succeeds, the last execution time of the operation for the proxied app and
1832 * your app will be updated to the current time.
1833 * @param op The operation to note. One of the OPSTR_* constants.
1834 * @param proxiedPackageName The name of the application calling into the proxy application.
1835 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1836 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1837 * causing the app to crash).
1838 * @throws SecurityException If the app has been configured to crash on this op.
1839 */
1840 public int noteProxyOp(String op, String proxiedPackageName) {
1841 return noteProxyOp(strOpToOp(op), proxiedPackageName);
1842 }
1843
1844 /**
1845 * Like {@link #noteProxyOp(String, String)} but instead
1846 * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}.
1847 */
1848 public int noteProxyOpNoThrow(String op, String proxiedPackageName) {
1849 return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName);
1850 }
1851
1852 /**
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001853 * Report that an application has started executing a long-running operation. Note that you
1854 * must pass in both the uid and name of the application to be checked; this function will
1855 * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1856 * succeeds, the last execution time of the operation for this app will be updated to
1857 * the current time and the operation will be marked as "running". In this case you must
1858 * later call {@link #finishOp(String, int, String)} to report when the application is no
1859 * longer performing the operation.
1860 * @param op The operation to start. One of the OPSTR_* constants.
1861 * @param uid The user id of the application attempting to perform the operation.
1862 * @param packageName The name of the application attempting to perform the operation.
1863 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1864 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1865 * causing the app to crash).
1866 * @throws SecurityException If the app has been configured to crash on this op.
1867 */
1868 public int startOp(String op, int uid, String packageName) {
1869 return startOp(strOpToOp(op), uid, packageName);
1870 }
1871
1872 /**
1873 * Like {@link #startOp} but instead of throwing a {@link SecurityException} it
1874 * returns {@link #MODE_ERRORED}.
1875 */
1876 public int startOpNoThrow(String op, int uid, String packageName) {
1877 return startOpNoThrow(strOpToOp(op), uid, packageName);
1878 }
1879
1880 /**
1881 * Report that an application is no longer performing an operation that had previously
1882 * been started with {@link #startOp(String, int, String)}. There is no validation of input
1883 * or result; the parameters supplied here must be the exact same ones previously passed
1884 * in when starting the operation.
1885 */
1886 public void finishOp(String op, int uid, String packageName) {
1887 finishOp(strOpToOp(op), uid, packageName);
1888 }
1889
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001890 /**
1891 * Do a quick check for whether an application might be able to perform an operation.
1892 * This is <em>not</em> a security check; you must use {@link #noteOp(int, int, String)}
1893 * or {@link #startOp(int, int, String)} for your actual security checks, which also
1894 * ensure that the given uid and package name are consistent. This function can just be
1895 * used for a quick check to see if an operation has been disabled for the application,
1896 * as an early reject of some work. This does not modify the time stamp or other data
1897 * about the operation.
1898 * @param op The operation to check. One of the OP_* constants.
1899 * @param uid The user id of the application attempting to perform the operation.
1900 * @param packageName The name of the application attempting to perform the operation.
1901 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1902 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1903 * causing the app to crash).
1904 * @throws SecurityException If the app has been configured to crash on this op.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001905 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001906 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001907 public int checkOp(int op, int uid, String packageName) {
1908 try {
1909 int mode = mService.checkOperation(op, uid, packageName);
1910 if (mode == MODE_ERRORED) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001911 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
Dianne Hackborn35654b62013-01-14 17:38:02 -08001912 }
1913 return mode;
1914 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001915 throw e.rethrowFromSystemServer();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001916 }
Dianne Hackborn35654b62013-01-14 17:38:02 -08001917 }
1918
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001919 /**
1920 * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
1921 * returns {@link #MODE_ERRORED}.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001922 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001923 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001924 public int checkOpNoThrow(int op, int uid, String packageName) {
1925 try {
1926 return mService.checkOperation(op, uid, packageName);
1927 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001928 throw e.rethrowFromSystemServer();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001929 }
Dianne Hackborn35654b62013-01-14 17:38:02 -08001930 }
1931
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001932 /**
Jeff Sharkey911d7f42013-09-05 18:11:45 -07001933 * Do a quick check to validate if a package name belongs to a UID.
1934 *
1935 * @throws SecurityException if the package name doesn't belong to the given
1936 * UID, or if ownership cannot be verified.
1937 */
1938 public void checkPackage(int uid, String packageName) {
1939 try {
1940 if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) {
1941 throw new SecurityException(
1942 "Package " + packageName + " does not belong to " + uid);
1943 }
1944 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001945 throw e.rethrowFromSystemServer();
Jeff Sharkey911d7f42013-09-05 18:11:45 -07001946 }
1947 }
1948
1949 /**
John Spurlock1af30c72014-03-10 08:33:35 -04001950 * Like {@link #checkOp} but at a stream-level for audio operations.
1951 * @hide
1952 */
1953 public int checkAudioOp(int op, int stream, int uid, String packageName) {
1954 try {
1955 final int mode = mService.checkAudioOperation(op, stream, uid, packageName);
1956 if (mode == MODE_ERRORED) {
1957 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
1958 }
1959 return mode;
1960 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001961 throw e.rethrowFromSystemServer();
John Spurlock1af30c72014-03-10 08:33:35 -04001962 }
John Spurlock1af30c72014-03-10 08:33:35 -04001963 }
1964
1965 /**
1966 * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it
1967 * returns {@link #MODE_ERRORED}.
1968 * @hide
1969 */
1970 public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) {
1971 try {
1972 return mService.checkAudioOperation(op, stream, uid, packageName);
1973 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001974 throw e.rethrowFromSystemServer();
John Spurlock1af30c72014-03-10 08:33:35 -04001975 }
John Spurlock1af30c72014-03-10 08:33:35 -04001976 }
1977
1978 /**
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001979 * Make note of an application performing an operation. Note that you must pass
1980 * in both the uid and name of the application to be checked; this function will verify
1981 * that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1982 * succeeds, the last execution time of the operation for this app will be updated to
1983 * the current time.
1984 * @param op The operation to note. One of the OP_* constants.
1985 * @param uid The user id of the application attempting to perform the operation.
1986 * @param packageName The name of the application attempting to perform the operation.
1987 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1988 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1989 * causing the app to crash).
1990 * @throws SecurityException If the app has been configured to crash on this op.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001991 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001992 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001993 public int noteOp(int op, int uid, String packageName) {
1994 try {
1995 int mode = mService.noteOperation(op, uid, packageName);
1996 if (mode == MODE_ERRORED) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001997 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001998 }
1999 return mode;
2000 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002001 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002002 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002003 }
2004
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002005 /**
Svet Ganov99b60432015-06-27 13:15:22 -07002006 * Make note of an application performing an operation on behalf of another
2007 * application when handling an IPC. Note that you must pass the package name
2008 * of the application that is being proxied while its UID will be inferred from
2009 * the IPC state; this function will verify that the calling uid and proxied
2010 * package name match, and if not, return {@link #MODE_IGNORED}. If this call
2011 * succeeds, the last execution time of the operation for the proxied app and
2012 * your app will be updated to the current time.
2013 * @param op The operation to note. One of the OPSTR_* constants.
2014 * @param proxiedPackageName The name of the application calling into the proxy application.
2015 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
2016 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
2017 * causing the app to crash).
2018 * @throws SecurityException If the proxy or proxied app has been configured to
2019 * crash on this op.
2020 *
2021 * @hide
2022 */
2023 public int noteProxyOp(int op, String proxiedPackageName) {
2024 int mode = noteProxyOpNoThrow(op, proxiedPackageName);
2025 if (mode == MODE_ERRORED) {
2026 throw new SecurityException("Proxy package " + mContext.getOpPackageName()
2027 + " from uid " + Process.myUid() + " or calling package "
2028 + proxiedPackageName + " from uid " + Binder.getCallingUid()
2029 + " not allowed to perform " + sOpNames[op]);
2030 }
2031 return mode;
2032 }
2033
2034 /**
2035 * Like {@link #noteProxyOp(int, String)} but instead
2036 * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}.
2037 * @hide
2038 */
2039 public int noteProxyOpNoThrow(int op, String proxiedPackageName) {
2040 try {
2041 return mService.noteProxyOperation(op, mContext.getOpPackageName(),
2042 Binder.getCallingUid(), proxiedPackageName);
2043 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002044 throw e.rethrowFromSystemServer();
Svet Ganov99b60432015-06-27 13:15:22 -07002045 }
Svet Ganov99b60432015-06-27 13:15:22 -07002046 }
2047
2048 /**
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002049 * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it
2050 * returns {@link #MODE_ERRORED}.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07002051 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002052 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002053 public int noteOpNoThrow(int op, int uid, String packageName) {
2054 try {
2055 return mService.noteOperation(op, uid, packageName);
2056 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002057 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002058 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002059 }
2060
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002061 /** @hide */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002062 public int noteOp(int op) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07002063 return noteOp(op, Process.myUid(), mContext.getOpPackageName());
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002064 }
2065
Dianne Hackborne98f5db2013-07-17 17:23:25 -07002066 /** @hide */
2067 public static IBinder getToken(IAppOpsService service) {
2068 synchronized (AppOpsManager.class) {
2069 if (sToken != null) {
2070 return sToken;
2071 }
2072 try {
2073 sToken = service.getToken(new Binder());
2074 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002075 throw e.rethrowFromSystemServer();
Dianne Hackborne98f5db2013-07-17 17:23:25 -07002076 }
2077 return sToken;
2078 }
2079 }
2080
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002081 /**
2082 * Report that an application has started executing a long-running operation. Note that you
2083 * must pass in both the uid and name of the application to be checked; this function will
2084 * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call
2085 * succeeds, the last execution time of the operation for this app will be updated to
2086 * the current time and the operation will be marked as "running". In this case you must
2087 * later call {@link #finishOp(int, int, String)} to report when the application is no
2088 * longer performing the operation.
2089 * @param op The operation to start. One of the OP_* constants.
2090 * @param uid The user id of the application attempting to perform the operation.
2091 * @param packageName The name of the application attempting to perform the operation.
2092 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
2093 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
2094 * causing the app to crash).
2095 * @throws SecurityException If the app has been configured to crash on this op.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07002096 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002097 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002098 public int startOp(int op, int uid, String packageName) {
2099 try {
Dianne Hackborne98f5db2013-07-17 17:23:25 -07002100 int mode = mService.startOperation(getToken(mService), op, uid, packageName);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002101 if (mode == MODE_ERRORED) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07002102 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002103 }
2104 return mode;
2105 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002106 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002107 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002108 }
2109
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002110 /**
2111 * Like {@link #startOp} but instead of throwing a {@link SecurityException} it
2112 * returns {@link #MODE_ERRORED}.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07002113 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002114 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002115 public int startOpNoThrow(int op, int uid, String packageName) {
2116 try {
Dianne Hackborne98f5db2013-07-17 17:23:25 -07002117 return mService.startOperation(getToken(mService), op, uid, packageName);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002118 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002119 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002120 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002121 }
2122
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002123 /** @hide */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002124 public int startOp(int op) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07002125 return startOp(op, Process.myUid(), mContext.getOpPackageName());
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002126 }
2127
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002128 /**
2129 * Report that an application is no longer performing an operation that had previously
2130 * been started with {@link #startOp(int, int, String)}. There is no validation of input
2131 * or result; the parameters supplied here must be the exact same ones previously passed
2132 * in when starting the operation.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07002133 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07002134 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002135 public void finishOp(int op, int uid, String packageName) {
2136 try {
Dianne Hackborne98f5db2013-07-17 17:23:25 -07002137 mService.finishOperation(getToken(mService), op, uid, packageName);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002138 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07002139 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002140 }
2141 }
2142
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07002143 /** @hide */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002144 public void finishOp(int op) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07002145 finishOp(op, Process.myUid(), mContext.getOpPackageName());
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002146 }
Jeff Sharkey35e46d22017-06-09 10:01:20 -06002147
2148 /** @hide */
2149 public boolean isOperationActive(int code, int uid, String packageName) {
2150 try {
2151 return mService.isOperationActive(code, uid, packageName);
2152 } catch (RemoteException e) {
2153 throw e.rethrowFromSystemServer();
2154 }
2155 }
Peter Visontay5a2a1ef2017-12-18 20:34:03 +00002156
2157 /**
2158 * Returns all supported operation names.
2159 * @hide
2160 */
2161 @SystemApi
2162 @TestApi
2163 public static String[] getOpStrs() {
2164 return Arrays.copyOf(sOpToString, sOpToString.length);
2165 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08002166}