blob: 4bd85ae9ee5ca39567dc380311db65246fcb063c [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;
Jeff Davidson05542602014-08-11 14:07:27 -070023import android.app.usage.UsageStatsManager;
24import android.content.Context;
John Spurlock7b414672014-07-18 13:02:39 -040025import android.media.AudioAttributes.AttributeUsage;
Dianne Hackborne98f5db2013-07-17 17:23:25 -070026import android.os.Binder;
27import android.os.IBinder;
Dianne Hackborn35654b62013-01-14 17:38:02 -080028import android.os.Parcel;
29import android.os.Parcelable;
Dianne Hackborna06de0f2012-12-11 16:34:47 -080030import android.os.Process;
31import android.os.RemoteException;
Dianne Hackborn7b7c58b2014-12-02 18:32:20 -080032import android.os.UserHandle;
Jeff Davidson05542602014-08-11 14:07:27 -070033import android.os.UserManager;
34import android.util.ArrayMap;
35
36import com.android.internal.app.IAppOpsCallback;
37import com.android.internal.app.IAppOpsService;
38
39import java.util.ArrayList;
40import java.util.HashMap;
41import java.util.List;
Dianne Hackborna06de0f2012-12-11 16:34:47 -080042
Dianne Hackbornd7d28e62013-02-12 14:59:53 -080043/**
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070044 * API for interacting with "application operation" tracking.
Dianne Hackbornd7d28e62013-02-12 14:59:53 -080045 *
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070046 * <p>This API is not generally intended for third party application developers; most
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060047 * features are only available to system applications.
Dianne Hackbornd7d28e62013-02-12 14:59:53 -080048 */
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -060049@SystemService(Context.APP_OPS_SERVICE)
Dianne Hackborna06de0f2012-12-11 16:34:47 -080050public class AppOpsManager {
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070051 /**
52 * <p>App ops allows callers to:</p>
53 *
54 * <ul>
55 * <li> Note when operations are happening, and find out if they are allowed for the current
56 * caller.</li>
57 * <li> Disallow specific apps from doing specific operations.</li>
58 * <li> Collect all of the current information about operations that have been executed or
59 * are not being allowed.</li>
60 * <li> Monitor for changes in whether an operation is allowed.</li>
61 * </ul>
62 *
63 * <p>Each operation is identified by a single integer; these integers are a fixed set of
64 * operations, enumerated by the OP_* constants.
65 *
66 * <p></p>When checking operations, the result is a "mode" integer indicating the current
67 * setting for the operation under that caller: MODE_ALLOWED, MODE_IGNORED (don't execute
68 * the operation but fake its behavior enough so that the caller doesn't crash),
69 * MODE_ERRORED (throw a SecurityException back to the caller; the normal operation calls
70 * will do this for you).
71 */
72
Dianne Hackborna06de0f2012-12-11 16:34:47 -080073 final Context mContext;
74 final IAppOpsService mService;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070075 final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers
76 = new ArrayMap<OnOpChangedListener, IAppOpsCallback>();
Dianne Hackborna06de0f2012-12-11 16:34:47 -080077
Dianne Hackborne98f5db2013-07-17 17:23:25 -070078 static IBinder sToken;
79
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070080 /**
81 * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
82 * allowed to perform the given operation.
83 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -080084 public static final int MODE_ALLOWED = 0;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070085
86 /**
87 * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
88 * not allowed to perform the given operation, and this attempt should
89 * <em>silently fail</em> (it should not cause the app to crash).
90 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -080091 public static final int MODE_IGNORED = 1;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -070092
93 /**
94 * Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the
95 * given caller is not allowed to perform the given operation, and this attempt should
96 * cause it to have a fatal error, typically a {@link SecurityException}.
97 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -080098 public static final int MODE_ERRORED = 2;
99
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700100 /**
101 * Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should
102 * use its default security check. This mode is not normally used; it should only be used
103 * with appop permissions, and callers must explicitly check for it and deal with it.
104 */
105 public static final int MODE_DEFAULT = 3;
106
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500107 // when adding one of these:
108 // - increment _NUM_OP
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700109 // - add rows to sOpToSwitch, sOpToString, sOpNames, sOpToPerms, sOpDefault
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500110 // - add descriptive strings to Settings/res/values/arrays.xml
David Christie0b837452013-07-29 16:02:13 -0700111 // - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app)
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700112
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700113 /** @hide No operation specified. */
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800114 public static final int OP_NONE = -1;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700115 /** @hide Access to coarse location information. */
Dianne Hackborn35654b62013-01-14 17:38:02 -0800116 public static final int OP_COARSE_LOCATION = 0;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700117 /** @hide Access to fine location information. */
Dianne Hackborn35654b62013-01-14 17:38:02 -0800118 public static final int OP_FINE_LOCATION = 1;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700119 /** @hide Causing GPS to run. */
Dianne Hackborn35654b62013-01-14 17:38:02 -0800120 public static final int OP_GPS = 2;
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800121 /** @hide */
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700122 public static final int OP_VIBRATE = 3;
123 /** @hide */
124 public static final int OP_READ_CONTACTS = 4;
125 /** @hide */
126 public static final int OP_WRITE_CONTACTS = 5;
127 /** @hide */
128 public static final int OP_READ_CALL_LOG = 6;
129 /** @hide */
130 public static final int OP_WRITE_CALL_LOG = 7;
131 /** @hide */
132 public static final int OP_READ_CALENDAR = 8;
133 /** @hide */
134 public static final int OP_WRITE_CALENDAR = 9;
135 /** @hide */
136 public static final int OP_WIFI_SCAN = 10;
137 /** @hide */
138 public static final int OP_POST_NOTIFICATION = 11;
139 /** @hide */
140 public static final int OP_NEIGHBORING_CELLS = 12;
141 /** @hide */
142 public static final int OP_CALL_PHONE = 13;
143 /** @hide */
144 public static final int OP_READ_SMS = 14;
145 /** @hide */
146 public static final int OP_WRITE_SMS = 15;
147 /** @hide */
148 public static final int OP_RECEIVE_SMS = 16;
149 /** @hide */
150 public static final int OP_RECEIVE_EMERGECY_SMS = 17;
151 /** @hide */
152 public static final int OP_RECEIVE_MMS = 18;
153 /** @hide */
154 public static final int OP_RECEIVE_WAP_PUSH = 19;
155 /** @hide */
156 public static final int OP_SEND_SMS = 20;
157 /** @hide */
158 public static final int OP_READ_ICC_SMS = 21;
159 /** @hide */
160 public static final int OP_WRITE_ICC_SMS = 22;
161 /** @hide */
162 public static final int OP_WRITE_SETTINGS = 23;
163 /** @hide */
164 public static final int OP_SYSTEM_ALERT_WINDOW = 24;
165 /** @hide */
166 public static final int OP_ACCESS_NOTIFICATIONS = 25;
167 /** @hide */
168 public static final int OP_CAMERA = 26;
169 /** @hide */
170 public static final int OP_RECORD_AUDIO = 27;
171 /** @hide */
172 public static final int OP_PLAY_AUDIO = 28;
173 /** @hide */
174 public static final int OP_READ_CLIPBOARD = 29;
175 /** @hide */
176 public static final int OP_WRITE_CLIPBOARD = 30;
177 /** @hide */
178 public static final int OP_TAKE_MEDIA_BUTTONS = 31;
179 /** @hide */
180 public static final int OP_TAKE_AUDIO_FOCUS = 32;
181 /** @hide */
182 public static final int OP_AUDIO_MASTER_VOLUME = 33;
183 /** @hide */
184 public static final int OP_AUDIO_VOICE_VOLUME = 34;
185 /** @hide */
186 public static final int OP_AUDIO_RING_VOLUME = 35;
187 /** @hide */
188 public static final int OP_AUDIO_MEDIA_VOLUME = 36;
189 /** @hide */
190 public static final int OP_AUDIO_ALARM_VOLUME = 37;
191 /** @hide */
192 public static final int OP_AUDIO_NOTIFICATION_VOLUME = 38;
193 /** @hide */
194 public static final int OP_AUDIO_BLUETOOTH_VOLUME = 39;
195 /** @hide */
196 public static final int OP_WAKE_LOCK = 40;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700197 /** @hide Continually monitoring location data. */
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700198 public static final int OP_MONITOR_LOCATION = 41;
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700199 /** @hide Continually monitoring location data with a relatively high power request. */
David Christie0b837452013-07-29 16:02:13 -0700200 public static final int OP_MONITOR_HIGH_POWER_LOCATION = 42;
Dianne Hackborne22b3b12014-05-07 18:06:44 -0700201 /** @hide Retrieve current usage stats via {@link UsageStatsManager}. */
202 public static final int OP_GET_USAGE_STATS = 43;
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700203 /** @hide */
Emily Bernier22c921a2014-05-28 11:01:32 -0400204 public static final int OP_MUTE_MICROPHONE = 44;
205 /** @hide */
Jason Monk1c7c3192014-06-26 12:52:18 -0400206 public static final int OP_TOAST_WINDOW = 45;
Michael Wrightc39d47a2014-07-08 18:07:36 -0700207 /** @hide Capture the device's display contents and/or audio */
208 public static final int OP_PROJECT_MEDIA = 46;
Jeff Davidson05542602014-08-11 14:07:27 -0700209 /** @hide Activate a VPN connection without user intervention. */
210 public static final int OP_ACTIVATE_VPN = 47;
Benjamin Franzf3ece362015-02-11 10:51:10 +0000211 /** @hide Access the WallpaperManagerAPI to write wallpapers. */
212 public static final int OP_WRITE_WALLPAPER = 48;
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700213 /** @hide Received the assist structure from an app. */
214 public static final int OP_ASSIST_STRUCTURE = 49;
215 /** @hide Received a screenshot from assist. */
216 public static final int OP_ASSIST_SCREENSHOT = 50;
Svet Ganov16a16892015-04-16 10:32:04 -0700217 /** @hide Read the phone state. */
218 public static final int OP_READ_PHONE_STATE = 51;
Svet Ganovc3300092015-04-17 09:07:22 -0700219 /** @hide Add voicemail messages to the voicemail content provider. */
220 public static final int OP_ADD_VOICEMAIL = 52;
Svetoslav5335b672015-04-29 12:00:51 -0700221 /** @hide Access APIs for SIP calling over VOIP or WiFi. */
222 public static final int OP_USE_SIP = 53;
Svetoslavc656e6f2015-04-29 14:08:16 -0700223 /** @hide Intercept outgoing calls. */
224 public static final int OP_PROCESS_OUTGOING_CALLS = 54;
Svetoslav4af76a52015-04-29 15:29:46 -0700225 /** @hide User the fingerprint API. */
226 public static final int OP_USE_FINGERPRINT = 55;
Svet Ganovb9d71a62015-04-30 10:38:13 -0700227 /** @hide Access to body sensors such as heart rate, etc. */
228 public static final int OP_BODY_SENSORS = 56;
Svet Ganovede43162015-05-02 17:42:44 -0700229 /** @hide Read previously received cell broadcast messages. */
230 public static final int OP_READ_CELL_BROADCASTS = 57;
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700231 /** @hide Inject mock location into the system. */
232 public static final int OP_MOCK_LOCATION = 58;
Svet Ganov921c7df2015-06-29 21:51:41 -0700233 /** @hide Read external storage. */
234 public static final int OP_READ_EXTERNAL_STORAGE = 59;
235 /** @hide Write external storage. */
236 public static final int OP_WRITE_EXTERNAL_STORAGE = 60;
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700237 /** @hide Turned on the screen. */
238 public static final int OP_TURN_SCREEN_ON = 61;
Svetoslavf3f02ac2015-09-08 14:36:35 -0700239 /** @hide Get device accounts. */
240 public static final int OP_GET_ACCOUNTS = 62;
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700241 /** @hide Control whether an application is allowed to run in the background. */
242 public static final int OP_RUN_IN_BACKGROUND = 63;
Jason Monk1c7c3192014-06-26 12:52:18 -0400243 /** @hide */
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800244 public static final int OP_AUDIO_ACCESSIBILITY_VOLUME = 64;
Chad Brubaker73ec8f92016-11-10 11:24:40 -0800245 /** @hide Read the phone number. */
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700246 public static final int OP_READ_PHONE_NUMBERS = 65;
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800247 /** @hide Request package installs through package installer */
248 public static final int OP_REQUEST_INSTALL_PACKAGES = 66;
Winson Chungf4ac0632017-03-17 12:34:12 -0700249 /** @hide Enter picture-in-picture. */
250 public static final int OP_PICTURE_IN_PICTURE = 67;
Chad Brubaker97b383f2017-02-02 15:04:35 -0800251 /** @hide Instant app start foreground service. */
252 public static final int OP_INSTANT_APP_START_FOREGROUND = 68;
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800253 /** @hide Answer incoming phone calls */
254 public static final int OP_ANSWER_PHONE_CALLS = 69;
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700255 /** @hide Run jobs when in background */
256 public static final int OP_RUN_ANY_IN_BACKGROUND = 70;
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800257 /** @hide */
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700258 public static final int _NUM_OP = 71;
Dianne Hackborna06de0f2012-12-11 16:34:47 -0800259
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700260 /** Access to coarse location information. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700261 public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700262 /** Access to fine location information. */
263 public static final String OPSTR_FINE_LOCATION =
264 "android:fine_location";
265 /** Continually monitoring location data. */
266 public static final String OPSTR_MONITOR_LOCATION
267 = "android:monitor_location";
268 /** Continually monitoring location data with a relatively high power request. */
269 public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION
270 = "android:monitor_location_high_power";
Dianne Hackborn5064e7c2014-09-02 10:57:16 -0700271 /** Access to {@link android.app.usage.UsageStatsManager}. */
272 public static final String OPSTR_GET_USAGE_STATS
273 = "android:get_usage_stats";
Jeff Davidson05542602014-08-11 14:07:27 -0700274 /** Activate a VPN connection without user intervention. @hide */
275 @SystemApi
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700276 public static final String OPSTR_ACTIVATE_VPN
277 = "android:activate_vpn";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700278 /** Allows an application to read the user's contacts data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700279 public static final String OPSTR_READ_CONTACTS
280 = "android:read_contacts";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700281 /** Allows an application to write to the user's contacts data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700282 public static final String OPSTR_WRITE_CONTACTS
283 = "android:write_contacts";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700284 /** Allows an application to read the user's call log. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700285 public static final String OPSTR_READ_CALL_LOG
286 = "android:read_call_log";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700287 /** Allows an application to write to the user's call log. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700288 public static final String OPSTR_WRITE_CALL_LOG
289 = "android:write_call_log";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700290 /** Allows an application to read the user's calendar data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700291 public static final String OPSTR_READ_CALENDAR
292 = "android:read_calendar";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700293 /** Allows an application to write to the user's calendar data. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700294 public static final String OPSTR_WRITE_CALENDAR
295 = "android:write_calendar";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700296 /** Allows an application to initiate a phone call. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700297 public static final String OPSTR_CALL_PHONE
298 = "android:call_phone";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700299 /** Allows an application to read SMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700300 public static final String OPSTR_READ_SMS
301 = "android:read_sms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700302 /** Allows an application to receive SMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700303 public static final String OPSTR_RECEIVE_SMS
304 = "android:receive_sms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700305 /** Allows an application to receive MMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700306 public static final String OPSTR_RECEIVE_MMS
307 = "android:receive_mms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700308 /** Allows an application to receive WAP push messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700309 public static final String OPSTR_RECEIVE_WAP_PUSH
310 = "android:receive_wap_push";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700311 /** Allows an application to send SMS messages. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700312 public static final String OPSTR_SEND_SMS
313 = "android:send_sms";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700314 /** Required to be able to access the camera device. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700315 public static final String OPSTR_CAMERA
316 = "android:camera";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700317 /** Required to be able to access the microphone device. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700318 public static final String OPSTR_RECORD_AUDIO
319 = "android:record_audio";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700320 /** Required to access phone state related information. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700321 public static final String OPSTR_READ_PHONE_STATE
322 = "android:read_phone_state";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700323 /** Required to access phone state related information. */
Svet Ganov6e8f67c2015-04-29 17:35:19 -0700324 public static final String OPSTR_ADD_VOICEMAIL
325 = "android:add_voicemail";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700326 /** Access APIs for SIP calling over VOIP or WiFi */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700327 public static final String OPSTR_USE_SIP
328 = "android:use_sip";
Svet Ganove8e89422016-09-22 19:56:50 -0700329 /** Access APIs for diverting outgoing calls */
Svet Ganov824ad6e2016-09-22 19:36:53 -0700330 public static final String OPSTR_PROCESS_OUTGOING_CALLS
331 = "android:process_outgoing_calls";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700332 /** Use the fingerprint API. */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700333 public static final String OPSTR_USE_FINGERPRINT
334 = "android:use_fingerprint";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700335 /** Access to body sensors such as heart rate, etc. */
Svet Ganovb9d71a62015-04-30 10:38:13 -0700336 public static final String OPSTR_BODY_SENSORS
337 = "android:body_sensors";
Svet Ganov715cf2a2015-06-13 17:31:29 -0700338 /** Read previously received cell broadcast messages. */
Svet Ganovede43162015-05-02 17:42:44 -0700339 public static final String OPSTR_READ_CELL_BROADCASTS
340 = "android:read_cell_broadcasts";
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700341 /** Inject mock location into the system. */
342 public static final String OPSTR_MOCK_LOCATION
343 = "android:mock_location";
Svet Ganov921c7df2015-06-29 21:51:41 -0700344 /** Read external storage. */
345 public static final String OPSTR_READ_EXTERNAL_STORAGE
346 = "android:read_external_storage";
347 /** Write external storage. */
348 public static final String OPSTR_WRITE_EXTERNAL_STORAGE
349 = "android:write_external_storage";
Billy Lau24b9c832015-07-20 17:34:09 +0100350 /** Required to draw on top of other apps. */
351 public static final String OPSTR_SYSTEM_ALERT_WINDOW
352 = "android:system_alert_window";
353 /** Required to write/modify/update system settingss. */
354 public static final String OPSTR_WRITE_SETTINGS
355 = "android:write_settings";
Svetoslavf3f02ac2015-09-08 14:36:35 -0700356 /** @hide Get device accounts. */
357 public static final String OPSTR_GET_ACCOUNTS
358 = "android:get_accounts";
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700359 public static final String OPSTR_READ_PHONE_NUMBERS
360 = "android:read_phone_numbers";
Winson Chungf4ac0632017-03-17 12:34:12 -0700361 /** Access to picture-in-picture. */
362 public static final String OPSTR_PICTURE_IN_PICTURE
363 = "android:picture_in_picture";
Chad Brubaker97b383f2017-02-02 15:04:35 -0800364 /** @hide */
365 public static final String OPSTR_INSTANT_APP_START_FOREGROUND
366 = "android:instant_app_start_foreground";
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800367 /** Answer incoming phone calls */
368 public static final String OPSTR_ANSWER_PHONE_CALLS
369 = "android:answer_phone_calls";
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700370
Philip P. Moltmanne56c08e2017-03-15 12:46:04 -0700371 // Warning: If an permission is added here it also has to be added to
372 // com.android.packageinstaller.permission.utils.EventLogger
Svet Ganovda0acdf2017-02-15 10:28:51 -0800373 private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
374 // RUNTIME PERMISSIONS
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700375 // Contacts
376 OP_READ_CONTACTS,
377 OP_WRITE_CONTACTS,
378 OP_GET_ACCOUNTS,
379 // Calendar
380 OP_READ_CALENDAR,
381 OP_WRITE_CALENDAR,
382 // SMS
383 OP_SEND_SMS,
384 OP_RECEIVE_SMS,
385 OP_READ_SMS,
386 OP_RECEIVE_WAP_PUSH,
387 OP_RECEIVE_MMS,
388 OP_READ_CELL_BROADCASTS,
389 // Storage
390 OP_READ_EXTERNAL_STORAGE,
391 OP_WRITE_EXTERNAL_STORAGE,
392 // Location
393 OP_COARSE_LOCATION,
394 OP_FINE_LOCATION,
395 // Phone
396 OP_READ_PHONE_STATE,
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700397 OP_READ_PHONE_NUMBERS,
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700398 OP_CALL_PHONE,
399 OP_READ_CALL_LOG,
400 OP_WRITE_CALL_LOG,
401 OP_ADD_VOICEMAIL,
402 OP_USE_SIP,
403 OP_PROCESS_OUTGOING_CALLS,
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800404 OP_ANSWER_PHONE_CALLS,
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700405 // Microphone
406 OP_RECORD_AUDIO,
407 // Camera
408 OP_CAMERA,
409 // Body sensors
Svet Ganovda0acdf2017-02-15 10:28:51 -0800410 OP_BODY_SENSORS,
411
412 // APPOP PERMISSIONS
413 OP_ACCESS_NOTIFICATIONS,
414 OP_SYSTEM_ALERT_WINDOW,
415 OP_WRITE_SETTINGS,
416 OP_REQUEST_INSTALL_PACKAGES,
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -0700417 };
418
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800419 /**
420 * This maps each operation to the operation that serves as the
421 * switch to determine whether it is allowed. Generally this is
422 * a 1:1 mapping, but for some things (like location) that have
423 * multiple low-level operations being tracked that should be
David Christie0b837452013-07-29 16:02:13 -0700424 * presented to the user as one switch then this can be used to
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800425 * make them all controlled by the same single operation.
426 */
427 private static int[] sOpToSwitch = new int[] {
428 OP_COARSE_LOCATION,
429 OP_COARSE_LOCATION,
430 OP_COARSE_LOCATION,
431 OP_VIBRATE,
432 OP_READ_CONTACTS,
433 OP_WRITE_CONTACTS,
434 OP_READ_CALL_LOG,
435 OP_WRITE_CALL_LOG,
436 OP_READ_CALENDAR,
437 OP_WRITE_CALENDAR,
438 OP_COARSE_LOCATION,
439 OP_POST_NOTIFICATION,
440 OP_COARSE_LOCATION,
441 OP_CALL_PHONE,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800442 OP_READ_SMS,
443 OP_WRITE_SMS,
David Braun18966a82013-09-10 13:14:46 -0700444 OP_RECEIVE_SMS,
445 OP_RECEIVE_SMS,
Svet Ganov99e4d512016-09-21 19:50:14 -0700446 OP_RECEIVE_MMS,
447 OP_RECEIVE_WAP_PUSH,
David Braun18966a82013-09-10 13:14:46 -0700448 OP_SEND_SMS,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800449 OP_READ_SMS,
450 OP_WRITE_SMS,
Dianne Hackborn961321f2013-02-05 17:22:41 -0800451 OP_WRITE_SETTINGS,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800452 OP_SYSTEM_ALERT_WINDOW,
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500453 OP_ACCESS_NOTIFICATIONS,
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800454 OP_CAMERA,
455 OP_RECORD_AUDIO,
456 OP_PLAY_AUDIO,
Dianne Hackbornefcc1a22013-02-25 18:02:35 -0800457 OP_READ_CLIPBOARD,
458 OP_WRITE_CLIPBOARD,
Dianne Hackbornba50b97c2013-04-30 15:04:46 -0700459 OP_TAKE_MEDIA_BUTTONS,
460 OP_TAKE_AUDIO_FOCUS,
461 OP_AUDIO_MASTER_VOLUME,
462 OP_AUDIO_VOICE_VOLUME,
463 OP_AUDIO_RING_VOLUME,
464 OP_AUDIO_MEDIA_VOLUME,
465 OP_AUDIO_ALARM_VOLUME,
466 OP_AUDIO_NOTIFICATION_VOLUME,
467 OP_AUDIO_BLUETOOTH_VOLUME,
Dianne Hackborn713df152013-05-17 11:27:57 -0700468 OP_WAKE_LOCK,
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700469 OP_COARSE_LOCATION,
David Christie0b837452013-07-29 16:02:13 -0700470 OP_COARSE_LOCATION,
Dianne Hackborne22b3b12014-05-07 18:06:44 -0700471 OP_GET_USAGE_STATS,
Jason Monk1c7c3192014-06-26 12:52:18 -0400472 OP_MUTE_MICROPHONE,
473 OP_TOAST_WINDOW,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700474 OP_PROJECT_MEDIA,
Jeff Davidson05542602014-08-11 14:07:27 -0700475 OP_ACTIVATE_VPN,
Benjamin Franzf3ece362015-02-11 10:51:10 +0000476 OP_WRITE_WALLPAPER,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700477 OP_ASSIST_STRUCTURE,
478 OP_ASSIST_SCREENSHOT,
Svet Ganovc3300092015-04-17 09:07:22 -0700479 OP_READ_PHONE_STATE,
Svetoslav5335b672015-04-29 12:00:51 -0700480 OP_ADD_VOICEMAIL,
Svetoslavc656e6f2015-04-29 14:08:16 -0700481 OP_USE_SIP,
Svetoslav4af76a52015-04-29 15:29:46 -0700482 OP_PROCESS_OUTGOING_CALLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700483 OP_USE_FINGERPRINT,
Svet Ganovede43162015-05-02 17:42:44 -0700484 OP_BODY_SENSORS,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700485 OP_READ_CELL_BROADCASTS,
Svet Ganov921c7df2015-06-29 21:51:41 -0700486 OP_MOCK_LOCATION,
487 OP_READ_EXTERNAL_STORAGE,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700488 OP_WRITE_EXTERNAL_STORAGE,
489 OP_TURN_SCREEN_ON,
Svetoslavf3f02ac2015-09-08 14:36:35 -0700490 OP_GET_ACCOUNTS,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700491 OP_RUN_IN_BACKGROUND,
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800492 OP_AUDIO_ACCESSIBILITY_VOLUME,
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700493 OP_READ_PHONE_NUMBERS,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800494 OP_REQUEST_INSTALL_PACKAGES,
Winson Chungf4ac0632017-03-17 12:34:12 -0700495 OP_PICTURE_IN_PICTURE,
Chad Brubaker97b383f2017-02-02 15:04:35 -0800496 OP_INSTANT_APP_START_FOREGROUND,
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700497 OP_ANSWER_PHONE_CALLS,
498 OP_RUN_ANY_IN_BACKGROUND,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800499 };
500
501 /**
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700502 * This maps each operation to the public string constant for it.
503 * If it doesn't have a public string constant, it maps to null.
504 */
505 private static String[] sOpToString = new String[] {
506 OPSTR_COARSE_LOCATION,
507 OPSTR_FINE_LOCATION,
508 null,
509 null,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700510 OPSTR_READ_CONTACTS,
511 OPSTR_WRITE_CONTACTS,
512 OPSTR_READ_CALL_LOG,
513 OPSTR_WRITE_CALL_LOG,
514 OPSTR_READ_CALENDAR,
515 OPSTR_WRITE_CALENDAR,
516 null,
517 null,
518 null,
519 OPSTR_CALL_PHONE,
520 OPSTR_READ_SMS,
521 null,
522 OPSTR_RECEIVE_SMS,
523 null,
524 OPSTR_RECEIVE_MMS,
525 OPSTR_RECEIVE_WAP_PUSH,
526 OPSTR_SEND_SMS,
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700527 null,
528 null,
Billy Lau24b9c832015-07-20 17:34:09 +0100529 OPSTR_WRITE_SETTINGS,
530 OPSTR_SYSTEM_ALERT_WINDOW,
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700531 null,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700532 OPSTR_CAMERA,
533 OPSTR_RECORD_AUDIO,
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700534 null,
535 null,
536 null,
537 null,
538 null,
539 null,
540 null,
541 null,
542 null,
543 null,
544 null,
545 null,
546 null,
547 OPSTR_MONITOR_LOCATION,
548 OPSTR_MONITOR_HIGH_POWER_LOCATION,
Dianne Hackborn5064e7c2014-09-02 10:57:16 -0700549 OPSTR_GET_USAGE_STATS,
Emily Bernier22c921a2014-05-28 11:01:32 -0400550 null,
Jason Monk1c7c3192014-06-26 12:52:18 -0400551 null,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700552 null,
Jeff Davidson05542602014-08-11 14:07:27 -0700553 OPSTR_ACTIVATE_VPN,
Benjamin Franzf3ece362015-02-11 10:51:10 +0000554 null,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700555 null,
556 null,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700557 OPSTR_READ_PHONE_STATE,
558 OPSTR_ADD_VOICEMAIL,
559 OPSTR_USE_SIP,
Svet Ganov824ad6e2016-09-22 19:36:53 -0700560 OPSTR_PROCESS_OUTGOING_CALLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700561 OPSTR_USE_FINGERPRINT,
Svet Ganovede43162015-05-02 17:42:44 -0700562 OPSTR_BODY_SENSORS,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700563 OPSTR_READ_CELL_BROADCASTS,
Svet Ganov921c7df2015-06-29 21:51:41 -0700564 OPSTR_MOCK_LOCATION,
565 OPSTR_READ_EXTERNAL_STORAGE,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700566 OPSTR_WRITE_EXTERNAL_STORAGE,
567 null,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700568 OPSTR_GET_ACCOUNTS,
569 null,
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800570 null, // OP_AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700571 OPSTR_READ_PHONE_NUMBERS,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800572 null, // OP_REQUEST_INSTALL_PACKAGES
Winson Chungf4ac0632017-03-17 12:34:12 -0700573 OPSTR_PICTURE_IN_PICTURE,
Chad Brubaker97b383f2017-02-02 15:04:35 -0800574 OPSTR_INSTANT_APP_START_FOREGROUND,
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800575 OPSTR_ANSWER_PHONE_CALLS,
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700576 null, // OP_RUN_ANY_IN_BACKGROUND
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -0700577 };
578
579 /**
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800580 * This provides a simple name for each operation to be used
581 * in debug output.
582 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800583 private static String[] sOpNames = new String[] {
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800584 "COARSE_LOCATION",
585 "FINE_LOCATION",
586 "GPS",
587 "VIBRATE",
588 "READ_CONTACTS",
589 "WRITE_CONTACTS",
590 "READ_CALL_LOG",
591 "WRITE_CALL_LOG",
592 "READ_CALENDAR",
593 "WRITE_CALENDAR",
594 "WIFI_SCAN",
595 "POST_NOTIFICATION",
596 "NEIGHBORING_CELLS",
597 "CALL_PHONE",
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800598 "READ_SMS",
599 "WRITE_SMS",
600 "RECEIVE_SMS",
601 "RECEIVE_EMERGECY_SMS",
602 "RECEIVE_MMS",
603 "RECEIVE_WAP_PUSH",
604 "SEND_SMS",
605 "READ_ICC_SMS",
606 "WRITE_ICC_SMS",
Dianne Hackborn961321f2013-02-05 17:22:41 -0800607 "WRITE_SETTINGS",
Dianne Hackbornc2293022013-02-06 23:14:49 -0800608 "SYSTEM_ALERT_WINDOW",
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500609 "ACCESS_NOTIFICATIONS",
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800610 "CAMERA",
611 "RECORD_AUDIO",
612 "PLAY_AUDIO",
Dianne Hackbornefcc1a22013-02-25 18:02:35 -0800613 "READ_CLIPBOARD",
614 "WRITE_CLIPBOARD",
Dianne Hackbornba50b97c2013-04-30 15:04:46 -0700615 "TAKE_MEDIA_BUTTONS",
616 "TAKE_AUDIO_FOCUS",
617 "AUDIO_MASTER_VOLUME",
618 "AUDIO_VOICE_VOLUME",
619 "AUDIO_RING_VOLUME",
620 "AUDIO_MEDIA_VOLUME",
621 "AUDIO_ALARM_VOLUME",
622 "AUDIO_NOTIFICATION_VOLUME",
623 "AUDIO_BLUETOOTH_VOLUME",
Dianne Hackborn713df152013-05-17 11:27:57 -0700624 "WAKE_LOCK",
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700625 "MONITOR_LOCATION",
David Christie0b837452013-07-29 16:02:13 -0700626 "MONITOR_HIGH_POWER_LOCATION",
Emily Bernier22c921a2014-05-28 11:01:32 -0400627 "GET_USAGE_STATS",
Michael Wrightc39d47a2014-07-08 18:07:36 -0700628 "MUTE_MICROPHONE",
Jason Monk1c7c3192014-06-26 12:52:18 -0400629 "TOAST_WINDOW",
Michael Wrightc39d47a2014-07-08 18:07:36 -0700630 "PROJECT_MEDIA",
Jeff Davidson05542602014-08-11 14:07:27 -0700631 "ACTIVATE_VPN",
Benjamin Franzf3ece362015-02-11 10:51:10 +0000632 "WRITE_WALLPAPER",
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700633 "ASSIST_STRUCTURE",
Svet Ganov16a16892015-04-16 10:32:04 -0700634 "ASSIST_SCREENSHOT",
Svet Ganovc3300092015-04-17 09:07:22 -0700635 "OP_READ_PHONE_STATE",
Svetoslav5335b672015-04-29 12:00:51 -0700636 "ADD_VOICEMAIL",
Svetoslavc656e6f2015-04-29 14:08:16 -0700637 "USE_SIP",
Svetoslav4af76a52015-04-29 15:29:46 -0700638 "PROCESS_OUTGOING_CALLS",
Svet Ganovb9d71a62015-04-30 10:38:13 -0700639 "USE_FINGERPRINT",
Svet Ganovede43162015-05-02 17:42:44 -0700640 "BODY_SENSORS",
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700641 "READ_CELL_BROADCASTS",
Svet Ganov921c7df2015-06-29 21:51:41 -0700642 "MOCK_LOCATION",
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700643 "READ_EXTERNAL_STORAGE",
644 "WRITE_EXTERNAL_STORAGE",
645 "TURN_ON_SCREEN",
Svetoslavf3f02ac2015-09-08 14:36:35 -0700646 "GET_ACCOUNTS",
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700647 "RUN_IN_BACKGROUND",
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800648 "AUDIO_ACCESSIBILITY_VOLUME",
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700649 "READ_PHONE_NUMBERS",
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800650 "REQUEST_INSTALL_PACKAGES",
Winson Chungf4ac0632017-03-17 12:34:12 -0700651 "PICTURE_IN_PICTURE",
Chad Brubaker97b383f2017-02-02 15:04:35 -0800652 "INSTANT_APP_START_FOREGROUND",
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800653 "ANSWER_PHONE_CALLS",
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700654 "RUN_ANY_IN_BACKGROUND",
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800655 };
656
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800657 /**
658 * This optionally maps a permission to an operation. If there
659 * is no permission associated with an operation, it is null.
660 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800661 private static String[] sOpPerms = new String[] {
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800662 android.Manifest.permission.ACCESS_COARSE_LOCATION,
663 android.Manifest.permission.ACCESS_FINE_LOCATION,
664 null,
665 android.Manifest.permission.VIBRATE,
666 android.Manifest.permission.READ_CONTACTS,
667 android.Manifest.permission.WRITE_CONTACTS,
668 android.Manifest.permission.READ_CALL_LOG,
669 android.Manifest.permission.WRITE_CALL_LOG,
670 android.Manifest.permission.READ_CALENDAR,
671 android.Manifest.permission.WRITE_CALENDAR,
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800672 android.Manifest.permission.ACCESS_WIFI_STATE,
Robert Craigf97616c2013-10-07 12:32:02 -0400673 null, // no permission required for notifications
Dianne Hackbornf265ea92013-01-31 15:00:51 -0800674 null, // neighboring cells shares the coarse location perm
675 android.Manifest.permission.CALL_PHONE,
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800676 android.Manifest.permission.READ_SMS,
Svetoslav6c589572015-04-16 16:19:24 -0700677 null, // no permission required for writing sms
Dianne Hackbornf51f6122013-02-04 18:23:34 -0800678 android.Manifest.permission.RECEIVE_SMS,
679 android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
680 android.Manifest.permission.RECEIVE_MMS,
681 android.Manifest.permission.RECEIVE_WAP_PUSH,
682 android.Manifest.permission.SEND_SMS,
683 android.Manifest.permission.READ_SMS,
Svetoslav6c589572015-04-16 16:19:24 -0700684 null, // no permission required for writing icc sms
Dianne Hackborn961321f2013-02-05 17:22:41 -0800685 android.Manifest.permission.WRITE_SETTINGS,
Dianne Hackbornc2293022013-02-06 23:14:49 -0800686 android.Manifest.permission.SYSTEM_ALERT_WINDOW,
Daniel Sandlerfde19b12013-01-17 00:21:05 -0500687 android.Manifest.permission.ACCESS_NOTIFICATIONS,
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800688 android.Manifest.permission.CAMERA,
689 android.Manifest.permission.RECORD_AUDIO,
690 null, // no permission for playing audio
Dianne Hackbornefcc1a22013-02-25 18:02:35 -0800691 null, // no permission for reading clipboard
692 null, // no permission for writing clipboard
Dianne Hackbornba50b97c2013-04-30 15:04:46 -0700693 null, // no permission for taking media buttons
694 null, // no permission for taking audio focus
695 null, // no permission for changing master volume
696 null, // no permission for changing voice volume
697 null, // no permission for changing ring volume
698 null, // no permission for changing media volume
699 null, // no permission for changing alarm volume
700 null, // no permission for changing notification volume
701 null, // no permission for changing bluetooth volume
Dianne Hackborn713df152013-05-17 11:27:57 -0700702 android.Manifest.permission.WAKE_LOCK,
Dianne Hackborn1304f4a2013-07-09 18:17:27 -0700703 null, // no permission for generic location monitoring
David Christie0b837452013-07-29 16:02:13 -0700704 null, // no permission for high power location monitoring
Dianne Hackborne22b3b12014-05-07 18:06:44 -0700705 android.Manifest.permission.PACKAGE_USAGE_STATS,
Emily Bernier22c921a2014-05-28 11:01:32 -0400706 null, // no permission for muting/unmuting microphone
Jason Monk1c7c3192014-06-26 12:52:18 -0400707 null, // no permission for displaying toasts
Michael Wrightc39d47a2014-07-08 18:07:36 -0700708 null, // no permission for projecting media
Jeff Davidson05542602014-08-11 14:07:27 -0700709 null, // no permission for activating vpn
Benjamin Franzf3ece362015-02-11 10:51:10 +0000710 null, // no permission for supporting wallpaper
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700711 null, // no permission for receiving assist structure
712 null, // no permission for receiving assist screenshot
Svet Ganovc3300092015-04-17 09:07:22 -0700713 Manifest.permission.READ_PHONE_STATE,
Svetoslav5335b672015-04-29 12:00:51 -0700714 Manifest.permission.ADD_VOICEMAIL,
Svetoslavc656e6f2015-04-29 14:08:16 -0700715 Manifest.permission.USE_SIP,
Svetoslav4af76a52015-04-29 15:29:46 -0700716 Manifest.permission.PROCESS_OUTGOING_CALLS,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700717 Manifest.permission.USE_FINGERPRINT,
Svet Ganovede43162015-05-02 17:42:44 -0700718 Manifest.permission.BODY_SENSORS,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700719 Manifest.permission.READ_CELL_BROADCASTS,
Svet Ganov921c7df2015-06-29 21:51:41 -0700720 null,
721 Manifest.permission.READ_EXTERNAL_STORAGE,
722 Manifest.permission.WRITE_EXTERNAL_STORAGE,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700723 null, // no permission for turning the screen on
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700724 Manifest.permission.GET_ACCOUNTS,
725 null, // no permission for running in background
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800726 null, // no permission for changing accessibility volume
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700727 Manifest.permission.READ_PHONE_NUMBERS,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800728 Manifest.permission.REQUEST_INSTALL_PACKAGES,
Winson Chung59fda9e2017-01-20 16:14:51 -0800729 null, // no permission for entering picture-in-picture on hide
Chad Brubaker97b383f2017-02-02 15:04:35 -0800730 Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE,
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800731 Manifest.permission.ANSWER_PHONE_CALLS,
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700732 null, // no permission for OP_RUN_ANY_IN_BACKGROUND
Dianne Hackborn5e45ee62013-01-24 19:13:44 -0800733 };
734
Dianne Hackbornd7d28e62013-02-12 14:59:53 -0800735 /**
Jason Monk62062992014-05-06 09:55:28 -0400736 * Specifies whether an Op should be restricted by a user restriction.
737 * Each Op should be filled with a restriction string from UserManager or
738 * null to specify it is not affected by any user restriction.
739 */
740 private static String[] sOpRestrictions = new String[] {
Julia Reynolds9854d572014-07-02 14:46:02 -0400741 UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION
742 UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION
743 UserManager.DISALLOW_SHARE_LOCATION, //GPS
Jason Monk62062992014-05-06 09:55:28 -0400744 null, //VIBRATE
745 null, //READ_CONTACTS
746 null, //WRITE_CONTACTS
Yorke Lee15f83c62014-08-13 14:14:29 -0700747 UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG
748 UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG
Jason Monk62062992014-05-06 09:55:28 -0400749 null, //READ_CALENDAR
750 null, //WRITE_CALENDAR
Julia Reynolds9854d572014-07-02 14:46:02 -0400751 UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN
Jason Monk62062992014-05-06 09:55:28 -0400752 null, //POST_NOTIFICATION
753 null, //NEIGHBORING_CELLS
754 null, //CALL_PHONE
Amith Yamasani41c1ded2014-08-05 11:15:05 -0700755 UserManager.DISALLOW_SMS, //READ_SMS
756 UserManager.DISALLOW_SMS, //WRITE_SMS
757 UserManager.DISALLOW_SMS, //RECEIVE_SMS
758 null, //RECEIVE_EMERGENCY_SMS
759 UserManager.DISALLOW_SMS, //RECEIVE_MMS
Jason Monk62062992014-05-06 09:55:28 -0400760 null, //RECEIVE_WAP_PUSH
Amith Yamasani41c1ded2014-08-05 11:15:05 -0700761 UserManager.DISALLOW_SMS, //SEND_SMS
762 UserManager.DISALLOW_SMS, //READ_ICC_SMS
763 UserManager.DISALLOW_SMS, //WRITE_ICC_SMS
Jason Monk62062992014-05-06 09:55:28 -0400764 null, //WRITE_SETTINGS
Jason Monk1c7c3192014-06-26 12:52:18 -0400765 UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW
Jason Monk62062992014-05-06 09:55:28 -0400766 null, //ACCESS_NOTIFICATIONS
Makoto Onuki759a7632015-10-28 16:43:10 -0700767 UserManager.DISALLOW_CAMERA, //CAMERA
Fyodor Kupolovb5013302015-04-17 17:59:14 -0700768 UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO
Jason Monk62062992014-05-06 09:55:28 -0400769 null, //PLAY_AUDIO
770 null, //READ_CLIPBOARD
771 null, //WRITE_CLIPBOARD
772 null, //TAKE_MEDIA_BUTTONS
773 null, //TAKE_AUDIO_FOCUS
Emily Bernier45775c42014-05-16 15:12:04 -0400774 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME
775 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME
776 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME
777 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME
778 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME
779 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME
780 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME
Jason Monk62062992014-05-06 09:55:28 -0400781 null, //WAKE_LOCK
Julia Reynolds9854d572014-07-02 14:46:02 -0400782 UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION
783 UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION
Jason Monk62062992014-05-06 09:55:28 -0400784 null, //GET_USAGE_STATS
Emily Bernier22c921a2014-05-28 11:01:32 -0400785 UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE
Jason Monk1c7c3192014-06-26 12:52:18 -0400786 UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW
Michael Wrightc39d47a2014-07-08 18:07:36 -0700787 null, //PROJECT_MEDIA
Tony Mak33d03a92016-06-02 15:01:16 +0100788 null, // ACTIVATE_VPN
Benjamin Franzf3ece362015-02-11 10:51:10 +0000789 UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700790 null, // ASSIST_STRUCTURE
791 null, // ASSIST_SCREENSHOT
Svet Ganovc3300092015-04-17 09:07:22 -0700792 null, // READ_PHONE_STATE
Svetoslav5335b672015-04-29 12:00:51 -0700793 null, // ADD_VOICEMAIL
Svetoslavc656e6f2015-04-29 14:08:16 -0700794 null, // USE_SIP
Svetoslav4af76a52015-04-29 15:29:46 -0700795 null, // PROCESS_OUTGOING_CALLS
Svet Ganovb9d71a62015-04-30 10:38:13 -0700796 null, // USE_FINGERPRINT
Svet Ganovede43162015-05-02 17:42:44 -0700797 null, // BODY_SENSORS
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700798 null, // READ_CELL_BROADCASTS
Svet Ganov921c7df2015-06-29 21:51:41 -0700799 null, // MOCK_LOCATION
800 null, // READ_EXTERNAL_STORAGE
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700801 null, // WRITE_EXTERNAL_STORAGE
802 null, // TURN_ON_SCREEN
Svetoslavf3f02ac2015-09-08 14:36:35 -0700803 null, // GET_ACCOUNTS
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700804 null, // RUN_IN_BACKGROUND
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800805 UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700806 null, // READ_PHONE_NUMBERS
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800807 null, // REQUEST_INSTALL_PACKAGES
Winson Chung59fda9e2017-01-20 16:14:51 -0800808 null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
Chad Brubaker97b383f2017-02-02 15:04:35 -0800809 null, // INSTANT_APP_START_FOREGROUND
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800810 null, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700811 null, // OP_RUN_ANY_IN_BACKGROUND
Jason Monk1c7c3192014-06-26 12:52:18 -0400812 };
813
814 /**
815 * This specifies whether each option should allow the system
816 * (and system ui) to bypass the user restriction when active.
817 */
818 private static boolean[] sOpAllowSystemRestrictionBypass = new boolean[] {
Fyodor Kupolov639e73d2016-02-25 11:58:21 -0800819 true, //COARSE_LOCATION
820 true, //FINE_LOCATION
Jason Monk1c7c3192014-06-26 12:52:18 -0400821 false, //GPS
822 false, //VIBRATE
823 false, //READ_CONTACTS
824 false, //WRITE_CONTACTS
825 false, //READ_CALL_LOG
826 false, //WRITE_CALL_LOG
827 false, //READ_CALENDAR
828 false, //WRITE_CALENDAR
Julia Reynolds9854d572014-07-02 14:46:02 -0400829 true, //WIFI_SCAN
Jason Monk1c7c3192014-06-26 12:52:18 -0400830 false, //POST_NOTIFICATION
831 false, //NEIGHBORING_CELLS
832 false, //CALL_PHONE
833 false, //READ_SMS
834 false, //WRITE_SMS
835 false, //RECEIVE_SMS
836 false, //RECEIVE_EMERGECY_SMS
837 false, //RECEIVE_MMS
838 false, //RECEIVE_WAP_PUSH
839 false, //SEND_SMS
840 false, //READ_ICC_SMS
841 false, //WRITE_ICC_SMS
842 false, //WRITE_SETTINGS
843 true, //SYSTEM_ALERT_WINDOW
844 false, //ACCESS_NOTIFICATIONS
845 false, //CAMERA
846 false, //RECORD_AUDIO
847 false, //PLAY_AUDIO
848 false, //READ_CLIPBOARD
849 false, //WRITE_CLIPBOARD
850 false, //TAKE_MEDIA_BUTTONS
851 false, //TAKE_AUDIO_FOCUS
852 false, //AUDIO_MASTER_VOLUME
853 false, //AUDIO_VOICE_VOLUME
854 false, //AUDIO_RING_VOLUME
855 false, //AUDIO_MEDIA_VOLUME
856 false, //AUDIO_ALARM_VOLUME
857 false, //AUDIO_NOTIFICATION_VOLUME
858 false, //AUDIO_BLUETOOTH_VOLUME
859 false, //WAKE_LOCK
860 false, //MONITOR_LOCATION
861 false, //MONITOR_HIGH_POWER_LOCATION
862 false, //GET_USAGE_STATS
Michael Wrightc39d47a2014-07-08 18:07:36 -0700863 false, //MUTE_MICROPHONE
864 true, //TOAST_WINDOW
865 false, //PROJECT_MEDIA
Jeff Davidson05542602014-08-11 14:07:27 -0700866 false, //ACTIVATE_VPN
Benjamin Franzf3ece362015-02-11 10:51:10 +0000867 false, //WALLPAPER
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700868 false, //ASSIST_STRUCTURE
869 false, //ASSIST_SCREENSHOT
Svet Ganov16a16892015-04-16 10:32:04 -0700870 false, //READ_PHONE_STATE
Svetoslav5335b672015-04-29 12:00:51 -0700871 false, //ADD_VOICEMAIL
Svetoslavc656e6f2015-04-29 14:08:16 -0700872 false, // USE_SIP
Svetoslav4af76a52015-04-29 15:29:46 -0700873 false, // PROCESS_OUTGOING_CALLS
Svet Ganovb9d71a62015-04-30 10:38:13 -0700874 false, // USE_FINGERPRINT
Svet Ganovede43162015-05-02 17:42:44 -0700875 false, // BODY_SENSORS
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700876 false, // READ_CELL_BROADCASTS
Svet Ganov921c7df2015-06-29 21:51:41 -0700877 false, // MOCK_LOCATION
878 false, // READ_EXTERNAL_STORAGE
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700879 false, // WRITE_EXTERNAL_STORAGE
880 false, // TURN_ON_SCREEN
Svetoslavf3f02ac2015-09-08 14:36:35 -0700881 false, // GET_ACCOUNTS
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700882 false, // RUN_IN_BACKGROUND
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800883 false, // AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker0c1651f2017-03-30 16:29:10 -0700884 false, // READ_PHONE_NUMBERS
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -0800885 false, // REQUEST_INSTALL_PACKAGES
Winson Chung59fda9e2017-01-20 16:14:51 -0800886 false, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
Chad Brubaker97b383f2017-02-02 15:04:35 -0800887 false, // INSTANT_APP_START_FOREGROUND
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800888 false, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700889 false, // OP_RUN_ANY_IN_BACKGROUND
Jason Monk62062992014-05-06 09:55:28 -0400890 };
891
892 /**
David Braunf5d83192013-09-16 13:43:51 -0700893 * This specifies the default mode for each operation.
894 */
895 private static int[] sOpDefaultMode = new int[] {
896 AppOpsManager.MODE_ALLOWED,
897 AppOpsManager.MODE_ALLOWED,
898 AppOpsManager.MODE_ALLOWED,
899 AppOpsManager.MODE_ALLOWED,
900 AppOpsManager.MODE_ALLOWED,
901 AppOpsManager.MODE_ALLOWED,
902 AppOpsManager.MODE_ALLOWED,
903 AppOpsManager.MODE_ALLOWED,
904 AppOpsManager.MODE_ALLOWED,
905 AppOpsManager.MODE_ALLOWED,
906 AppOpsManager.MODE_ALLOWED,
907 AppOpsManager.MODE_ALLOWED,
908 AppOpsManager.MODE_ALLOWED,
909 AppOpsManager.MODE_ALLOWED,
910 AppOpsManager.MODE_ALLOWED,
911 AppOpsManager.MODE_IGNORED, // OP_WRITE_SMS
912 AppOpsManager.MODE_ALLOWED,
913 AppOpsManager.MODE_ALLOWED,
914 AppOpsManager.MODE_ALLOWED,
915 AppOpsManager.MODE_ALLOWED,
916 AppOpsManager.MODE_ALLOWED,
917 AppOpsManager.MODE_ALLOWED,
918 AppOpsManager.MODE_ALLOWED,
Billy Lau6ad2d662015-07-18 00:26:58 +0100919 AppOpsManager.MODE_DEFAULT, // OP_WRITE_SETTINGS
Billy Lau060275f2015-07-15 22:29:19 +0100920 AppOpsManager.MODE_DEFAULT, // OP_SYSTEM_ALERT_WINDOW
David Braunf5d83192013-09-16 13:43:51 -0700921 AppOpsManager.MODE_ALLOWED,
922 AppOpsManager.MODE_ALLOWED,
923 AppOpsManager.MODE_ALLOWED,
924 AppOpsManager.MODE_ALLOWED,
925 AppOpsManager.MODE_ALLOWED,
926 AppOpsManager.MODE_ALLOWED,
927 AppOpsManager.MODE_ALLOWED,
928 AppOpsManager.MODE_ALLOWED,
929 AppOpsManager.MODE_ALLOWED,
930 AppOpsManager.MODE_ALLOWED,
931 AppOpsManager.MODE_ALLOWED,
932 AppOpsManager.MODE_ALLOWED,
933 AppOpsManager.MODE_ALLOWED,
934 AppOpsManager.MODE_ALLOWED,
935 AppOpsManager.MODE_ALLOWED,
936 AppOpsManager.MODE_ALLOWED,
937 AppOpsManager.MODE_ALLOWED,
938 AppOpsManager.MODE_ALLOWED,
Dianne Hackborn33f5ddd2014-07-21 15:35:45 -0700939 AppOpsManager.MODE_DEFAULT, // OP_GET_USAGE_STATS
Emily Bernier22c921a2014-05-28 11:01:32 -0400940 AppOpsManager.MODE_ALLOWED,
Jason Monk1c7c3192014-06-26 12:52:18 -0400941 AppOpsManager.MODE_ALLOWED,
Michael Wrightc39d47a2014-07-08 18:07:36 -0700942 AppOpsManager.MODE_IGNORED, // OP_PROJECT_MEDIA
Jeff Davidson05542602014-08-11 14:07:27 -0700943 AppOpsManager.MODE_IGNORED, // OP_ACTIVATE_VPN
Benjamin Franzf3ece362015-02-11 10:51:10 +0000944 AppOpsManager.MODE_ALLOWED,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -0700945 AppOpsManager.MODE_ALLOWED,
946 AppOpsManager.MODE_ALLOWED,
Svet Ganovc3300092015-04-17 09:07:22 -0700947 AppOpsManager.MODE_ALLOWED,
Svetoslav5335b672015-04-29 12:00:51 -0700948 AppOpsManager.MODE_ALLOWED,
Svetoslavc656e6f2015-04-29 14:08:16 -0700949 AppOpsManager.MODE_ALLOWED,
Svetoslav4af76a52015-04-29 15:29:46 -0700950 AppOpsManager.MODE_ALLOWED,
Svet Ganovb9d71a62015-04-30 10:38:13 -0700951 AppOpsManager.MODE_ALLOWED,
Svet Ganovede43162015-05-02 17:42:44 -0700952 AppOpsManager.MODE_ALLOWED,
Svet Ganovf7e9cf42015-05-13 10:40:31 -0700953 AppOpsManager.MODE_ALLOWED,
Svet Ganov921c7df2015-06-29 21:51:41 -0700954 AppOpsManager.MODE_ERRORED, // OP_MOCK_LOCATION
955 AppOpsManager.MODE_ALLOWED,
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700956 AppOpsManager.MODE_ALLOWED,
957 AppOpsManager.MODE_ALLOWED, // OP_TURN_ON_SCREEN
Svetoslavf3f02ac2015-09-08 14:36:35 -0700958 AppOpsManager.MODE_ALLOWED,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -0700959 AppOpsManager.MODE_ALLOWED, // OP_RUN_IN_BACKGROUND
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -0800960 AppOpsManager.MODE_ALLOWED, // OP_AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker73ec8f92016-11-10 11:24:40 -0800961 AppOpsManager.MODE_ALLOWED,
Svet Ganovda0acdf2017-02-15 10:28:51 -0800962 AppOpsManager.MODE_DEFAULT, // OP_REQUEST_INSTALL_PACKAGES
Winson Chungf4ac0632017-03-17 12:34:12 -0700963 AppOpsManager.MODE_ALLOWED, // OP_PICTURE_IN_PICTURE
Svet Ganovda0acdf2017-02-15 10:28:51 -0800964 AppOpsManager.MODE_DEFAULT, // OP_INSTANT_APP_START_FOREGROUND
Eugene Suslacae3d3e2017-01-31 11:08:11 -0800965 AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -0700966 AppOpsManager.MODE_ALLOWED, // OP_RUN_ANY_IN_BACKGROUND
David Braunf5d83192013-09-16 13:43:51 -0700967 };
968
Dianne Hackborn8828d3a2013-09-25 16:47:10 -0700969 /**
970 * This specifies whether each option is allowed to be reset
971 * when resetting all app preferences. Disable reset for
972 * app ops that are under strong control of some part of the
973 * system (such as OP_WRITE_SMS, which should be allowed only
974 * for whichever app is selected as the current SMS app).
975 */
976 private static boolean[] sOpDisableReset = new boolean[] {
977 false,
978 false,
979 false,
980 false,
981 false,
982 false,
983 false,
984 false,
985 false,
986 false,
987 false,
988 false,
989 false,
990 false,
991 false,
992 true, // OP_WRITE_SMS
993 false,
994 false,
995 false,
996 false,
997 false,
998 false,
999 false,
1000 false,
1001 false,
1002 false,
1003 false,
1004 false,
1005 false,
1006 false,
1007 false,
1008 false,
1009 false,
1010 false,
1011 false,
1012 false,
1013 false,
1014 false,
1015 false,
1016 false,
1017 false,
1018 false,
1019 false,
Dianne Hackborne22b3b12014-05-07 18:06:44 -07001020 false,
Emily Bernier22c921a2014-05-28 11:01:32 -04001021 false,
Jason Monk1c7c3192014-06-26 12:52:18 -04001022 false,
Michael Wrightc39d47a2014-07-08 18:07:36 -07001023 false,
Jeff Davidson05542602014-08-11 14:07:27 -07001024 false,
Benjamin Franzf3ece362015-02-11 10:51:10 +00001025 false,
Dianne Hackbornd59a5d52015-04-04 14:52:14 -07001026 false,
1027 false,
Svet Ganovc3300092015-04-17 09:07:22 -07001028 false,
Svetoslav5335b672015-04-29 12:00:51 -07001029 false,
Svetoslavc656e6f2015-04-29 14:08:16 -07001030 false,
Svetoslav4af76a52015-04-29 15:29:46 -07001031 false,
Svet Ganovb9d71a62015-04-30 10:38:13 -07001032 false,
Svet Ganovede43162015-05-02 17:42:44 -07001033 false,
Svet Ganovf7e9cf42015-05-13 10:40:31 -07001034 false,
Svet Ganov921c7df2015-06-29 21:51:41 -07001035 false,
1036 false,
Dianne Hackborn280a64e2015-07-13 14:48:08 -07001037 false,
1038 false,
Dianne Hackbornbef28fe2015-10-29 17:57:11 -07001039 false,
1040 false,
Jean-Michel Trivi3f0945a2016-11-11 10:05:18 -08001041 false, // OP_AUDIO_ACCESSIBILITY_VOLUME
Chad Brubaker73ec8f92016-11-10 11:24:40 -08001042 false,
Suprabh Shukla2f34b1a2016-12-16 14:47:25 -08001043 false, // OP_REQUEST_INSTALL_PACKAGES
Winson Chungf4ac0632017-03-17 12:34:12 -07001044 false, // OP_PICTURE_IN_PICTURE
Chad Brubaker97b383f2017-02-02 15:04:35 -08001045 false,
Eugene Suslacae3d3e2017-01-31 11:08:11 -08001046 false, // ANSWER_PHONE_CALLS
Suprabh Shukla3ac1daa2017-07-14 12:15:27 -07001047 false, // OP_RUN_ANY_IN_BACKGROUND
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001048 };
1049
Svet Ganovfbf01f72015-04-28 18:39:06 -07001050 /**
Svet Ganovb9d71a62015-04-30 10:38:13 -07001051 * Mapping from an app op name to the app op code.
Svet Ganovfbf01f72015-04-28 18:39:06 -07001052 */
Svet Ganovb9d71a62015-04-30 10:38:13 -07001053 private static HashMap<String, Integer> sOpStrToOp = new HashMap<>();
Svet Ganovfbf01f72015-04-28 18:39:06 -07001054
Svet Ganovb9d71a62015-04-30 10:38:13 -07001055 /**
1056 * Mapping from a permission to the corresponding app op.
1057 */
Svet Ganovda0acdf2017-02-15 10:28:51 -08001058 private static HashMap<String, Integer> sPermToOp = new HashMap<>();
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001059
1060 static {
1061 if (sOpToSwitch.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001062 throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001063 + " should be " + _NUM_OP);
1064 }
1065 if (sOpToString.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001066 throw new IllegalStateException("sOpToString length " + sOpToString.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001067 + " should be " + _NUM_OP);
1068 }
1069 if (sOpNames.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001070 throw new IllegalStateException("sOpNames length " + sOpNames.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001071 + " should be " + _NUM_OP);
1072 }
1073 if (sOpPerms.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001074 throw new IllegalStateException("sOpPerms length " + sOpPerms.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001075 + " should be " + _NUM_OP);
1076 }
1077 if (sOpDefaultMode.length != _NUM_OP) {
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001078 throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length
1079 + " should be " + _NUM_OP);
1080 }
1081 if (sOpDisableReset.length != _NUM_OP) {
1082 throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001083 + " should be " + _NUM_OP);
1084 }
Jason Monk62062992014-05-06 09:55:28 -04001085 if (sOpRestrictions.length != _NUM_OP) {
1086 throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length
1087 + " should be " + _NUM_OP);
1088 }
Jason Monk1c7c3192014-06-26 12:52:18 -04001089 if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) {
1090 throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length "
1091 + sOpRestrictions.length + " should be " + _NUM_OP);
1092 }
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001093 for (int i=0; i<_NUM_OP; i++) {
1094 if (sOpToString[i] != null) {
1095 sOpStrToOp.put(sOpToString[i], i);
1096 }
1097 }
Svet Ganovda0acdf2017-02-15 10:28:51 -08001098 for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) {
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -07001099 if (sOpPerms[op] != null) {
Svet Ganovda0acdf2017-02-15 10:28:51 -08001100 sPermToOp.put(sOpPerms[op], op);
Svet Ganovb9d71a62015-04-30 10:38:13 -07001101 }
1102 }
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001103 }
1104
David Braunf5d83192013-09-16 13:43:51 -07001105 /**
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001106 * Retrieve the op switch that controls the given operation.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001107 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001108 */
Dianne Hackbornf265ea92013-01-31 15:00:51 -08001109 public static int opToSwitch(int op) {
1110 return sOpToSwitch[op];
1111 }
1112
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001113 /**
1114 * Retrieve a non-localized name for the operation, for debugging output.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001115 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001116 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001117 public static String opToName(int op) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001118 if (op == OP_NONE) return "NONE";
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001119 return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")");
1120 }
1121
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001122 /**
Dianne Hackborn7b7c58b2014-12-02 18:32:20 -08001123 * @hide
1124 */
1125 public static int strDebugOpToOp(String op) {
1126 for (int i=0; i<sOpNames.length; i++) {
1127 if (sOpNames[i].equals(op)) {
1128 return i;
1129 }
1130 }
1131 throw new IllegalArgumentException("Unknown operation string: " + op);
1132 }
1133
1134 /**
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001135 * Retrieve the permission associated with an operation, or null if there is not one.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001136 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001137 */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001138 public static String opToPermission(int op) {
1139 return sOpPerms[op];
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001140 }
1141
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001142 /**
Jason Monk62062992014-05-06 09:55:28 -04001143 * Retrieve the user restriction associated with an operation, or null if there is not one.
1144 * @hide
1145 */
1146 public static String opToRestriction(int op) {
1147 return sOpRestrictions[op];
1148 }
1149
1150 /**
Svet Ganovb9d71a62015-04-30 10:38:13 -07001151 * Retrieve the app op code for a permission, or null if there is not one.
Svet Ganovda0acdf2017-02-15 10:28:51 -08001152 * This API is intended to be used for mapping runtime or appop permissions
1153 * to the corresponding app op.
Svet Ganovb9d71a62015-04-30 10:38:13 -07001154 * @hide
1155 */
1156 public static int permissionToOpCode(String permission) {
Svet Ganovda0acdf2017-02-15 10:28:51 -08001157 Integer boxedOpCode = sPermToOp.get(permission);
Svet Ganov019d2302015-05-04 11:07:38 -07001158 return boxedOpCode != null ? boxedOpCode : OP_NONE;
Svet Ganovb9d71a62015-04-30 10:38:13 -07001159 }
1160
1161 /**
Jason Monk1c7c3192014-06-26 12:52:18 -04001162 * Retrieve whether the op allows the system (and system ui) to
1163 * bypass the user restriction.
1164 * @hide
1165 */
1166 public static boolean opAllowSystemBypassRestriction(int op) {
1167 return sOpAllowSystemRestrictionBypass[op];
1168 }
1169
1170 /**
David Braunf5d83192013-09-16 13:43:51 -07001171 * Retrieve the default mode for the operation.
1172 * @hide
1173 */
1174 public static int opToDefaultMode(int op) {
1175 return sOpDefaultMode[op];
1176 }
1177
1178 /**
Dianne Hackborn8828d3a2013-09-25 16:47:10 -07001179 * Retrieve whether the op allows itself to be reset.
1180 * @hide
1181 */
1182 public static boolean opAllowsReset(int op) {
1183 return !sOpDisableReset[op];
1184 }
1185
1186 /**
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001187 * Class holding all of the operation information associated with an app.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001188 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001189 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001190 public static class PackageOps implements Parcelable {
1191 private final String mPackageName;
1192 private final int mUid;
1193 private final List<OpEntry> mEntries;
1194
1195 public PackageOps(String packageName, int uid, List<OpEntry> entries) {
1196 mPackageName = packageName;
1197 mUid = uid;
1198 mEntries = entries;
1199 }
1200
1201 public String getPackageName() {
1202 return mPackageName;
1203 }
1204
1205 public int getUid() {
1206 return mUid;
1207 }
1208
1209 public List<OpEntry> getOps() {
1210 return mEntries;
1211 }
1212
1213 @Override
1214 public int describeContents() {
1215 return 0;
1216 }
1217
1218 @Override
1219 public void writeToParcel(Parcel dest, int flags) {
1220 dest.writeString(mPackageName);
1221 dest.writeInt(mUid);
1222 dest.writeInt(mEntries.size());
1223 for (int i=0; i<mEntries.size(); i++) {
1224 mEntries.get(i).writeToParcel(dest, flags);
1225 }
1226 }
1227
1228 PackageOps(Parcel source) {
1229 mPackageName = source.readString();
1230 mUid = source.readInt();
1231 mEntries = new ArrayList<OpEntry>();
1232 final int N = source.readInt();
1233 for (int i=0; i<N; i++) {
1234 mEntries.add(OpEntry.CREATOR.createFromParcel(source));
1235 }
1236 }
1237
1238 public static final Creator<PackageOps> CREATOR = new Creator<PackageOps>() {
1239 @Override public PackageOps createFromParcel(Parcel source) {
1240 return new PackageOps(source);
1241 }
1242
1243 @Override public PackageOps[] newArray(int size) {
1244 return new PackageOps[size];
1245 }
1246 };
1247 }
1248
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001249 /**
1250 * Class holding the information about one unique operation of an application.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001251 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001252 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001253 public static class OpEntry implements Parcelable {
1254 private final int mOp;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001255 private final int mMode;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001256 private final long mTime;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001257 private final long mRejectTime;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001258 private final int mDuration;
Svet Ganov99b60432015-06-27 13:15:22 -07001259 private final int mProxyUid;
1260 private final String mProxyPackageName;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001261
Svet Ganov99b60432015-06-27 13:15:22 -07001262 public OpEntry(int op, int mode, long time, long rejectTime, int duration,
1263 int proxyUid, String proxyPackage) {
Dianne Hackborn35654b62013-01-14 17:38:02 -08001264 mOp = op;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001265 mMode = mode;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001266 mTime = time;
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001267 mRejectTime = rejectTime;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001268 mDuration = duration;
Svet Ganov99b60432015-06-27 13:15:22 -07001269 mProxyUid = proxyUid;
1270 mProxyPackageName = proxyPackage;
Dianne Hackborn35654b62013-01-14 17:38:02 -08001271 }
1272
1273 public int getOp() {
1274 return mOp;
1275 }
1276
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001277 public int getMode() {
1278 return mMode;
1279 }
1280
Dianne Hackborn35654b62013-01-14 17:38:02 -08001281 public long getTime() {
1282 return mTime;
1283 }
1284
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001285 public long getRejectTime() {
1286 return mRejectTime;
1287 }
1288
Dianne Hackborn35654b62013-01-14 17:38:02 -08001289 public boolean isRunning() {
1290 return mDuration == -1;
1291 }
1292
1293 public int getDuration() {
1294 return mDuration == -1 ? (int)(System.currentTimeMillis()-mTime) : mDuration;
1295 }
1296
Svet Ganov99b60432015-06-27 13:15:22 -07001297 public int getProxyUid() {
1298 return mProxyUid;
1299 }
1300
1301 public String getProxyPackageName() {
1302 return mProxyPackageName;
1303 }
1304
Dianne Hackborn35654b62013-01-14 17:38:02 -08001305 @Override
1306 public int describeContents() {
1307 return 0;
1308 }
1309
1310 @Override
1311 public void writeToParcel(Parcel dest, int flags) {
1312 dest.writeInt(mOp);
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001313 dest.writeInt(mMode);
Dianne Hackborn35654b62013-01-14 17:38:02 -08001314 dest.writeLong(mTime);
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001315 dest.writeLong(mRejectTime);
Dianne Hackborn35654b62013-01-14 17:38:02 -08001316 dest.writeInt(mDuration);
Svet Ganov99b60432015-06-27 13:15:22 -07001317 dest.writeInt(mProxyUid);
1318 dest.writeString(mProxyPackageName);
Dianne Hackborn35654b62013-01-14 17:38:02 -08001319 }
1320
1321 OpEntry(Parcel source) {
1322 mOp = source.readInt();
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001323 mMode = source.readInt();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001324 mTime = source.readLong();
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001325 mRejectTime = source.readLong();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001326 mDuration = source.readInt();
Svet Ganov99b60432015-06-27 13:15:22 -07001327 mProxyUid = source.readInt();
1328 mProxyPackageName = source.readString();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001329 }
1330
1331 public static final Creator<OpEntry> CREATOR = new Creator<OpEntry>() {
1332 @Override public OpEntry createFromParcel(Parcel source) {
1333 return new OpEntry(source);
1334 }
1335
1336 @Override public OpEntry[] newArray(int size) {
1337 return new OpEntry[size];
1338 }
1339 };
1340 }
1341
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001342 /**
1343 * Callback for notification of changes to operation state.
1344 */
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001345 public interface OnOpChangedListener {
1346 public void onOpChanged(String op, String packageName);
1347 }
1348
1349 /**
1350 * Callback for notification of changes to operation state.
1351 * This allows you to see the raw op codes instead of strings.
1352 * @hide
1353 */
1354 public static class OnOpChangedInternalListener implements OnOpChangedListener {
1355 public void onOpChanged(String op, String packageName) { }
1356 public void onOpChanged(int op, String packageName) { }
Dianne Hackbornc2293022013-02-06 23:14:49 -08001357 }
1358
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001359 AppOpsManager(Context context, IAppOpsService service) {
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001360 mContext = context;
1361 mService = service;
1362 }
1363
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001364 /**
1365 * Retrieve current operation state for all applications.
1366 *
1367 * @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 -07001368 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001369 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001370 public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
1371 try {
1372 return mService.getPackagesForOps(ops);
1373 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001374 throw e.rethrowFromSystemServer();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001375 }
Dianne Hackborn35654b62013-01-14 17:38:02 -08001376 }
1377
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001378 /**
1379 * Retrieve current operation state for one application.
1380 *
1381 * @param uid The uid of the application of interest.
1382 * @param packageName The name of the application of interest.
1383 * @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 -07001384 * @hide
Dianne Hackbornd7d28e62013-02-12 14:59:53 -08001385 */
Dianne Hackborn72e39832013-01-18 18:36:09 -08001386 public List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) {
1387 try {
1388 return mService.getOpsForPackage(uid, packageName, ops);
1389 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001390 throw e.rethrowFromSystemServer();
Dianne Hackborn72e39832013-01-18 18:36:09 -08001391 }
Dianne Hackborn72e39832013-01-18 18:36:09 -08001392 }
1393
Svet Ganovae0e03a2016-02-25 18:22:10 -08001394 /**
1395 * Sets given app op in the specified mode for app ops in the UID.
1396 * This applies to all apps currently in the UID or installed in
1397 * this UID in the future.
1398 *
1399 * @param code The app op.
1400 * @param uid The UID for which to set the app.
1401 * @param mode The app op mode to set.
1402 * @hide
1403 */
Svet Ganov2af57082015-07-30 08:44:20 -07001404 public void setUidMode(int code, int uid, int mode) {
1405 try {
1406 mService.setUidMode(code, uid, mode);
1407 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001408 throw e.rethrowFromSystemServer();
Svet Ganov2af57082015-07-30 08:44:20 -07001409 }
1410 }
1411
Svet Ganovae0e03a2016-02-25 18:22:10 -08001412 /**
1413 * Sets given app op in the specified mode for app ops in the UID.
1414 * This applies to all apps currently in the UID or installed in
1415 * this UID in the future.
1416 *
1417 * @param appOp The app op.
1418 * @param uid The UID for which to set the app.
1419 * @param mode The app op mode to set.
1420 * @hide
1421 */
1422 @SystemApi
Jeff Sharkeyd86b8fe2017-06-02 17:36:26 -06001423 @RequiresPermission(android.Manifest.permission.UPDATE_APP_OPS_STATS)
Svet Ganovae0e03a2016-02-25 18:22:10 -08001424 public void setUidMode(String appOp, int uid, int mode) {
1425 try {
1426 mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode);
1427 } catch (RemoteException e) {
1428 throw e.rethrowFromSystemServer();
1429 }
1430 }
1431
Svet Ganov2af57082015-07-30 08:44:20 -07001432 /** @hide */
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001433 public void setUserRestriction(int code, boolean restricted, IBinder token) {
Ruben Brunk29931bc2016-03-11 00:24:26 -08001434 setUserRestriction(code, restricted, token, /*exceptionPackages*/null);
1435 }
1436
1437 /** @hide */
1438 public void setUserRestriction(int code, boolean restricted, IBinder token,
1439 String[] exceptionPackages) {
Svetoslav Ganove33f6132016-06-01 16:25:31 -07001440 setUserRestrictionForUser(code, restricted, token, exceptionPackages, mContext.getUserId());
1441 }
1442
1443 /** @hide */
1444 public void setUserRestrictionForUser(int code, boolean restricted, IBinder token,
1445 String[] exceptionPackages, int userId) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001446 try {
Svetoslav Ganove33f6132016-06-01 16:25:31 -07001447 mService.setUserRestriction(code, restricted, token, userId, exceptionPackages);
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001448 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001449 throw e.rethrowFromSystemServer();
Svet Ganov9cea80cd2016-02-16 11:47:00 -08001450 }
1451 }
1452
1453 /** @hide */
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001454 public void setMode(int code, int uid, String packageName, int mode) {
1455 try {
1456 mService.setMode(code, uid, packageName, mode);
1457 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001458 throw e.rethrowFromSystemServer();
Dianne Hackborn5e45ee62013-01-24 19:13:44 -08001459 }
1460 }
1461
John Spurlock1af30c72014-03-10 08:33:35 -04001462 /**
1463 * Set a non-persisted restriction on an audio operation at a stream-level.
1464 * Restrictions are temporary additional constraints imposed on top of the persisted rules
1465 * defined by {@link #setMode}.
1466 *
1467 * @param code The operation to restrict.
John Spurlock7b414672014-07-18 13:02:39 -04001468 * @param usage The {@link android.media.AudioAttributes} usage value.
John Spurlock1af30c72014-03-10 08:33:35 -04001469 * @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict.
1470 * @param exceptionPackages Optional list of packages to exclude from the restriction.
1471 * @hide
1472 */
John Spurlock7b414672014-07-18 13:02:39 -04001473 public void setRestriction(int code, @AttributeUsage int usage, int mode,
1474 String[] exceptionPackages) {
John Spurlock1af30c72014-03-10 08:33:35 -04001475 try {
1476 final int uid = Binder.getCallingUid();
John Spurlock7b414672014-07-18 13:02:39 -04001477 mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages);
John Spurlock1af30c72014-03-10 08:33:35 -04001478 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001479 throw e.rethrowFromSystemServer();
John Spurlock1af30c72014-03-10 08:33:35 -04001480 }
1481 }
1482
Dianne Hackborn607b4142013-08-02 18:10:10 -07001483 /** @hide */
1484 public void resetAllModes() {
1485 try {
Dianne Hackborn7b7c58b2014-12-02 18:32:20 -08001486 mService.resetAllModes(UserHandle.myUserId(), null);
Dianne Hackborn607b4142013-08-02 18:10:10 -07001487 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001488 throw e.rethrowFromSystemServer();
Dianne Hackborn607b4142013-08-02 18:10:10 -07001489 }
1490 }
1491
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001492 /**
Svet Ganovfbf01f72015-04-28 18:39:06 -07001493 * Gets the app op name associated with a given permission.
1494 * The app op name is one of the public constants defined
1495 * in this class such as {@link #OPSTR_COARSE_LOCATION}.
Svetoslav Ganoveaca4c52016-05-05 18:08:00 -07001496 * This API is intended to be used for mapping runtime
1497 * permissions to the corresponding app op.
Svet Ganovfbf01f72015-04-28 18:39:06 -07001498 *
1499 * @param permission The permission.
1500 * @return The app op associated with the permission or null.
Svet Ganovfbf01f72015-04-28 18:39:06 -07001501 */
Svet Ganovfbf01f72015-04-28 18:39:06 -07001502 public static String permissionToOp(String permission) {
Svet Ganovda0acdf2017-02-15 10:28:51 -08001503 final Integer opCode = sPermToOp.get(permission);
Svet Ganovb9d71a62015-04-30 10:38:13 -07001504 if (opCode == null) {
1505 return null;
1506 }
1507 return sOpToString[opCode];
Svet Ganovfbf01f72015-04-28 18:39:06 -07001508 }
1509
1510 /**
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001511 * Monitor for changes to the operating mode for the given op in the given app package.
Dianne Hackborne4cb66f2013-10-02 10:34:02 -07001512 * @param op The operation to monitor, one of OPSTR_*.
1513 * @param packageName The name of the application to monitor.
1514 * @param callback Where to report changes.
1515 */
1516 public void startWatchingMode(String op, String packageName,
1517 final OnOpChangedListener callback) {
1518 startWatchingMode(strOpToOp(op), packageName, callback);
1519 }
1520
1521 /**
1522 * Monitor for changes to the operating mode for the given op in the given app package.
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001523 * @param op The operation to monitor, one of OP_*.
1524 * @param packageName The name of the application to monitor.
1525 * @param callback Where to report changes.
Dianne Hackborne4cb66f2013-10-02 10:34:02 -07001526 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001527 */
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001528 public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001529 synchronized (mModeWatchers) {
1530 IAppOpsCallback cb = mModeWatchers.get(callback);
1531 if (cb == null) {
1532 cb = new IAppOpsCallback.Stub() {
Dianne Hackbornbef28fe2015-10-29 17:57:11 -07001533 public void opChanged(int op, int uid, String packageName) {
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001534 if (callback instanceof OnOpChangedInternalListener) {
1535 ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName);
1536 }
1537 if (sOpToString[op] != null) {
1538 callback.onOpChanged(sOpToString[op], packageName);
1539 }
Dianne Hackbornc2293022013-02-06 23:14:49 -08001540 }
1541 };
1542 mModeWatchers.put(callback, cb);
1543 }
1544 try {
1545 mService.startWatchingMode(op, packageName, cb);
1546 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001547 throw e.rethrowFromSystemServer();
Dianne Hackbornc2293022013-02-06 23:14:49 -08001548 }
1549 }
1550 }
1551
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001552 /**
1553 * Stop monitoring that was previously started with {@link #startWatchingMode}. All
1554 * monitoring associated with this callback will be removed.
1555 */
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001556 public void stopWatchingMode(OnOpChangedListener callback) {
Dianne Hackbornc2293022013-02-06 23:14:49 -08001557 synchronized (mModeWatchers) {
1558 IAppOpsCallback cb = mModeWatchers.get(callback);
1559 if (cb != null) {
1560 try {
1561 mService.stopWatchingMode(cb);
1562 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001563 throw e.rethrowFromSystemServer();
Dianne Hackbornc2293022013-02-06 23:14:49 -08001564 }
1565 }
1566 }
1567 }
1568
Dianne Hackborn95d78532013-09-11 09:51:14 -07001569 private String buildSecurityExceptionMsg(int op, int uid, String packageName) {
1570 return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op];
1571 }
1572
Adam Lesinskib5cf61b2014-08-18 16:10:28 -07001573 /**
1574 * {@hide}
1575 */
1576 public static int strOpToOp(String op) {
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001577 Integer val = sOpStrToOp.get(op);
1578 if (val == null) {
1579 throw new IllegalArgumentException("Unknown operation string: " + op);
1580 }
1581 return val;
1582 }
1583
1584 /**
1585 * Do a quick check for whether an application might be able to perform an operation.
1586 * This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String)}
1587 * or {@link #startOp(String, int, String)} for your actual security checks, which also
1588 * ensure that the given uid and package name are consistent. This function can just be
1589 * used for a quick check to see if an operation has been disabled for the application,
1590 * as an early reject of some work. This does not modify the time stamp or other data
1591 * about the operation.
1592 * @param op The operation to check. One of the OPSTR_* constants.
1593 * @param uid The user id of the application attempting to perform the operation.
1594 * @param packageName The name of the application attempting to perform the operation.
1595 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1596 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1597 * causing the app to crash).
1598 * @throws SecurityException If the app has been configured to crash on this op.
1599 */
1600 public int checkOp(String op, int uid, String packageName) {
1601 return checkOp(strOpToOp(op), uid, packageName);
1602 }
1603
1604 /**
John Spurlock925b85e2014-03-10 16:52:11 -04001605 * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001606 * returns {@link #MODE_ERRORED}.
1607 */
1608 public int checkOpNoThrow(String op, int uid, String packageName) {
1609 return checkOpNoThrow(strOpToOp(op), uid, packageName);
1610 }
1611
1612 /**
1613 * Make note of an application performing an operation. Note that you must pass
1614 * in both the uid and name of the application to be checked; this function will verify
1615 * that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1616 * succeeds, the last execution time of the operation for this app will be updated to
1617 * the current time.
1618 * @param op The operation to note. One of the OPSTR_* constants.
1619 * @param uid The user id of the application attempting to perform the operation.
1620 * @param packageName The name of the application attempting to perform the operation.
1621 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1622 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1623 * causing the app to crash).
1624 * @throws SecurityException If the app has been configured to crash on this op.
1625 */
1626 public int noteOp(String op, int uid, String packageName) {
1627 return noteOp(strOpToOp(op), uid, packageName);
1628 }
1629
1630 /**
1631 * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it
1632 * returns {@link #MODE_ERRORED}.
1633 */
1634 public int noteOpNoThrow(String op, int uid, String packageName) {
1635 return noteOpNoThrow(strOpToOp(op), uid, packageName);
1636 }
1637
1638 /**
Svet Ganov99b60432015-06-27 13:15:22 -07001639 * Make note of an application performing an operation on behalf of another
1640 * application when handling an IPC. Note that you must pass the package name
1641 * of the application that is being proxied while its UID will be inferred from
1642 * the IPC state; this function will verify that the calling uid and proxied
1643 * package name match, and if not, return {@link #MODE_IGNORED}. If this call
1644 * succeeds, the last execution time of the operation for the proxied app and
1645 * your app will be updated to the current time.
1646 * @param op The operation to note. One of the OPSTR_* constants.
1647 * @param proxiedPackageName The name of the application calling into the proxy application.
1648 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1649 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1650 * causing the app to crash).
1651 * @throws SecurityException If the app has been configured to crash on this op.
1652 */
1653 public int noteProxyOp(String op, String proxiedPackageName) {
1654 return noteProxyOp(strOpToOp(op), proxiedPackageName);
1655 }
1656
1657 /**
1658 * Like {@link #noteProxyOp(String, String)} but instead
1659 * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}.
1660 */
1661 public int noteProxyOpNoThrow(String op, String proxiedPackageName) {
1662 return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName);
1663 }
1664
1665 /**
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001666 * Report that an application has started executing a long-running operation. Note that you
1667 * must pass in both the uid and name of the application to be checked; this function will
1668 * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1669 * succeeds, the last execution time of the operation for this app will be updated to
1670 * the current time and the operation will be marked as "running". In this case you must
1671 * later call {@link #finishOp(String, int, String)} to report when the application is no
1672 * longer performing the operation.
1673 * @param op The operation to start. One of the OPSTR_* constants.
1674 * @param uid The user id of the application attempting to perform the operation.
1675 * @param packageName The name of the application attempting to perform the operation.
1676 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1677 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1678 * causing the app to crash).
1679 * @throws SecurityException If the app has been configured to crash on this op.
1680 */
1681 public int startOp(String op, int uid, String packageName) {
1682 return startOp(strOpToOp(op), uid, packageName);
1683 }
1684
1685 /**
1686 * Like {@link #startOp} but instead of throwing a {@link SecurityException} it
1687 * returns {@link #MODE_ERRORED}.
1688 */
1689 public int startOpNoThrow(String op, int uid, String packageName) {
1690 return startOpNoThrow(strOpToOp(op), uid, packageName);
1691 }
1692
1693 /**
1694 * Report that an application is no longer performing an operation that had previously
1695 * been started with {@link #startOp(String, int, String)}. There is no validation of input
1696 * or result; the parameters supplied here must be the exact same ones previously passed
1697 * in when starting the operation.
1698 */
1699 public void finishOp(String op, int uid, String packageName) {
1700 finishOp(strOpToOp(op), uid, packageName);
1701 }
1702
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001703 /**
1704 * Do a quick check for whether an application might be able to perform an operation.
1705 * This is <em>not</em> a security check; you must use {@link #noteOp(int, int, String)}
1706 * or {@link #startOp(int, int, String)} for your actual security checks, which also
1707 * ensure that the given uid and package name are consistent. This function can just be
1708 * used for a quick check to see if an operation has been disabled for the application,
1709 * as an early reject of some work. This does not modify the time stamp or other data
1710 * about the operation.
1711 * @param op The operation to check. One of the OP_* constants.
1712 * @param uid The user id of the application attempting to perform the operation.
1713 * @param packageName The name of the application attempting to perform the operation.
1714 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1715 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1716 * causing the app to crash).
1717 * @throws SecurityException If the app has been configured to crash on this op.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001718 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001719 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001720 public int checkOp(int op, int uid, String packageName) {
1721 try {
1722 int mode = mService.checkOperation(op, uid, packageName);
1723 if (mode == MODE_ERRORED) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001724 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
Dianne Hackborn35654b62013-01-14 17:38:02 -08001725 }
1726 return mode;
1727 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001728 throw e.rethrowFromSystemServer();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001729 }
Dianne Hackborn35654b62013-01-14 17:38:02 -08001730 }
1731
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001732 /**
1733 * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
1734 * returns {@link #MODE_ERRORED}.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001735 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001736 */
Dianne Hackborn35654b62013-01-14 17:38:02 -08001737 public int checkOpNoThrow(int op, int uid, String packageName) {
1738 try {
1739 return mService.checkOperation(op, uid, packageName);
1740 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001741 throw e.rethrowFromSystemServer();
Dianne Hackborn35654b62013-01-14 17:38:02 -08001742 }
Dianne Hackborn35654b62013-01-14 17:38:02 -08001743 }
1744
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001745 /**
Jeff Sharkey911d7f42013-09-05 18:11:45 -07001746 * Do a quick check to validate if a package name belongs to a UID.
1747 *
1748 * @throws SecurityException if the package name doesn't belong to the given
1749 * UID, or if ownership cannot be verified.
1750 */
1751 public void checkPackage(int uid, String packageName) {
1752 try {
1753 if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) {
1754 throw new SecurityException(
1755 "Package " + packageName + " does not belong to " + uid);
1756 }
1757 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001758 throw e.rethrowFromSystemServer();
Jeff Sharkey911d7f42013-09-05 18:11:45 -07001759 }
1760 }
1761
1762 /**
John Spurlock1af30c72014-03-10 08:33:35 -04001763 * Like {@link #checkOp} but at a stream-level for audio operations.
1764 * @hide
1765 */
1766 public int checkAudioOp(int op, int stream, int uid, String packageName) {
1767 try {
1768 final int mode = mService.checkAudioOperation(op, stream, uid, packageName);
1769 if (mode == MODE_ERRORED) {
1770 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
1771 }
1772 return mode;
1773 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001774 throw e.rethrowFromSystemServer();
John Spurlock1af30c72014-03-10 08:33:35 -04001775 }
John Spurlock1af30c72014-03-10 08:33:35 -04001776 }
1777
1778 /**
1779 * Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it
1780 * returns {@link #MODE_ERRORED}.
1781 * @hide
1782 */
1783 public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) {
1784 try {
1785 return mService.checkAudioOperation(op, stream, uid, packageName);
1786 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001787 throw e.rethrowFromSystemServer();
John Spurlock1af30c72014-03-10 08:33:35 -04001788 }
John Spurlock1af30c72014-03-10 08:33:35 -04001789 }
1790
1791 /**
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001792 * Make note of an application performing an operation. Note that you must pass
1793 * in both the uid and name of the application to be checked; this function will verify
1794 * that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1795 * succeeds, the last execution time of the operation for this app will be updated to
1796 * the current time.
1797 * @param op The operation to note. One of the OP_* constants.
1798 * @param uid The user id of the application attempting to perform the operation.
1799 * @param packageName The name of the application attempting to perform the operation.
1800 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1801 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1802 * causing the app to crash).
1803 * @throws SecurityException If the app has been configured to crash on this op.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001804 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001805 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001806 public int noteOp(int op, int uid, String packageName) {
1807 try {
1808 int mode = mService.noteOperation(op, uid, packageName);
1809 if (mode == MODE_ERRORED) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001810 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001811 }
1812 return mode;
1813 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001814 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001815 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001816 }
1817
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001818 /**
Svet Ganov99b60432015-06-27 13:15:22 -07001819 * Make note of an application performing an operation on behalf of another
1820 * application when handling an IPC. Note that you must pass the package name
1821 * of the application that is being proxied while its UID will be inferred from
1822 * the IPC state; this function will verify that the calling uid and proxied
1823 * package name match, and if not, return {@link #MODE_IGNORED}. If this call
1824 * succeeds, the last execution time of the operation for the proxied app and
1825 * your app will be updated to the current time.
1826 * @param op The operation to note. One of the OPSTR_* constants.
1827 * @param proxiedPackageName The name of the application calling into the proxy application.
1828 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1829 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1830 * causing the app to crash).
1831 * @throws SecurityException If the proxy or proxied app has been configured to
1832 * crash on this op.
1833 *
1834 * @hide
1835 */
1836 public int noteProxyOp(int op, String proxiedPackageName) {
1837 int mode = noteProxyOpNoThrow(op, proxiedPackageName);
1838 if (mode == MODE_ERRORED) {
1839 throw new SecurityException("Proxy package " + mContext.getOpPackageName()
1840 + " from uid " + Process.myUid() + " or calling package "
1841 + proxiedPackageName + " from uid " + Binder.getCallingUid()
1842 + " not allowed to perform " + sOpNames[op]);
1843 }
1844 return mode;
1845 }
1846
1847 /**
1848 * Like {@link #noteProxyOp(int, String)} but instead
1849 * of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}.
1850 * @hide
1851 */
1852 public int noteProxyOpNoThrow(int op, String proxiedPackageName) {
1853 try {
1854 return mService.noteProxyOperation(op, mContext.getOpPackageName(),
1855 Binder.getCallingUid(), proxiedPackageName);
1856 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001857 throw e.rethrowFromSystemServer();
Svet Ganov99b60432015-06-27 13:15:22 -07001858 }
Svet Ganov99b60432015-06-27 13:15:22 -07001859 }
1860
1861 /**
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001862 * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it
1863 * returns {@link #MODE_ERRORED}.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001864 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001865 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001866 public int noteOpNoThrow(int op, int uid, String packageName) {
1867 try {
1868 return mService.noteOperation(op, uid, packageName);
1869 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001870 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001871 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001872 }
1873
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001874 /** @hide */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001875 public int noteOp(int op) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001876 return noteOp(op, Process.myUid(), mContext.getOpPackageName());
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001877 }
1878
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001879 /** @hide */
1880 public static IBinder getToken(IAppOpsService service) {
1881 synchronized (AppOpsManager.class) {
1882 if (sToken != null) {
1883 return sToken;
1884 }
1885 try {
1886 sToken = service.getToken(new Binder());
1887 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001888 throw e.rethrowFromSystemServer();
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001889 }
1890 return sToken;
1891 }
1892 }
1893
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001894 /**
1895 * Report that an application has started executing a long-running operation. Note that you
1896 * must pass in both the uid and name of the application to be checked; this function will
1897 * verify that these two match, and if not, return {@link #MODE_IGNORED}. If this call
1898 * succeeds, the last execution time of the operation for this app will be updated to
1899 * the current time and the operation will be marked as "running". In this case you must
1900 * later call {@link #finishOp(int, int, String)} to report when the application is no
1901 * longer performing the operation.
1902 * @param op The operation to start. One of the OP_* constants.
1903 * @param uid The user id of the application attempting to perform the operation.
1904 * @param packageName The name of the application attempting to perform the operation.
1905 * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
1906 * {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
1907 * causing the app to crash).
1908 * @throws SecurityException If the app has been configured to crash on this op.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001909 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001910 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001911 public int startOp(int op, int uid, String packageName) {
1912 try {
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001913 int mode = mService.startOperation(getToken(mService), op, uid, packageName);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001914 if (mode == MODE_ERRORED) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001915 throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001916 }
1917 return mode;
1918 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001919 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001920 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001921 }
1922
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001923 /**
1924 * Like {@link #startOp} but instead of throwing a {@link SecurityException} it
1925 * returns {@link #MODE_ERRORED}.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001926 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001927 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001928 public int startOpNoThrow(int op, int uid, String packageName) {
1929 try {
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001930 return mService.startOperation(getToken(mService), op, uid, packageName);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001931 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001932 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001933 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001934 }
1935
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001936 /** @hide */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001937 public int startOp(int op) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001938 return startOp(op, Process.myUid(), mContext.getOpPackageName());
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001939 }
1940
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001941 /**
1942 * Report that an application is no longer performing an operation that had previously
1943 * been started with {@link #startOp(int, int, String)}. There is no validation of input
1944 * or result; the parameters supplied here must be the exact same ones previously passed
1945 * in when starting the operation.
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001946 * @hide
Dianne Hackborn1304f4a2013-07-09 18:17:27 -07001947 */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001948 public void finishOp(int op, int uid, String packageName) {
1949 try {
Dianne Hackborne98f5db2013-07-17 17:23:25 -07001950 mService.finishOperation(getToken(mService), op, uid, packageName);
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001951 } catch (RemoteException e) {
Jeff Sharkeyf8880562016-02-26 13:03:01 -07001952 throw e.rethrowFromSystemServer();
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001953 }
1954 }
1955
Dianne Hackborn9bb0ee92013-09-22 12:31:38 -07001956 /** @hide */
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001957 public void finishOp(int op) {
Dianne Hackborn95d78532013-09-11 09:51:14 -07001958 finishOp(op, Process.myUid(), mContext.getOpPackageName());
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001959 }
Jeff Sharkey35e46d22017-06-09 10:01:20 -06001960
1961 /** @hide */
1962 public boolean isOperationActive(int code, int uid, String packageName) {
1963 try {
1964 return mService.isOperationActive(code, uid, packageName);
1965 } catch (RemoteException e) {
1966 throw e.rethrowFromSystemServer();
1967 }
1968 }
Dianne Hackborna06de0f2012-12-11 16:34:47 -08001969}