blob: 2e83b23f57d88a00b78586ea843674a3405d4a47 [file] [log] [blame]
Todd Kennedy0eb97382017-10-03 16:57:22 -07001/*
Philip P. Moltmann48456672019-01-20 13:14:03 -08002 * Copyright (C) 2019 The Android Open Source Project
Todd Kennedy0eb97382017-10-03 16:57:22 -07003 *
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 com.android.server.pm.permission;
18
Nate Myrend3a63852019-06-07 13:11:58 -070019import android.annotation.AppIdInt;
Todd Kennedy0eb97382017-10-03 16:57:22 -070020import android.annotation.NonNull;
21import android.annotation.Nullable;
Philip P. Moltmannc91ff6f2019-06-14 14:35:42 -070022import android.annotation.UserIdInt;
Svet Ganovd8eb8b22019-04-05 18:52:08 -070023import android.content.pm.PackageManager;
Todd Kennedy0eb97382017-10-03 16:57:22 -070024import android.content.pm.PermissionInfo;
Philip P. Moltmann48456672019-01-20 13:14:03 -080025import android.permission.PermissionManagerInternal;
Todd Kennedy0eb97382017-10-03 16:57:22 -070026
Winson5e0a1d52020-01-24 12:00:33 -080027import com.android.server.pm.parsing.pkg.AndroidPackage;
28
Philip P. Moltmannfae8a5282018-04-10 12:15:32 -070029import java.util.ArrayList;
Todd Kennedy0eb97382017-10-03 16:57:22 -070030import java.util.List;
Todd Kennedy583378d2019-07-12 06:50:30 -070031import java.util.function.Consumer;
Todd Kennedy0eb97382017-10-03 16:57:22 -070032
33/**
Philip P. Moltmann48456672019-01-20 13:14:03 -080034 * Internal interfaces services.
35 *
36 * TODO: Should be merged into PermissionManagerInternal, but currently uses internal classes.
Todd Kennedy0eb97382017-10-03 16:57:22 -070037 */
Philip P. Moltmann48456672019-01-20 13:14:03 -080038public abstract class PermissionManagerServiceInternal extends PermissionManagerInternal {
Winson10d51882020-05-26 10:52:23 -070039
Todd Kennedy0eb97382017-10-03 16:57:22 -070040 /**
Todd Kennedy583378d2019-07-12 06:50:30 -070041 * Provider for package names.
42 */
43 public interface PackagesProvider {
44
45 /**
46 * Gets the packages for a given user.
47 * @param userId The user id.
48 * @return The package names.
49 */
50 String[] getPackages(int userId);
51 }
52
53 /**
54 * Provider for package names.
55 */
56 public interface SyncAdapterPackagesProvider {
57
58 /**
59 * Gets the sync adapter packages for given authority and user.
60 * @param authority The authority.
61 * @param userId The user id.
62 * @return The package names.
63 */
64 String[] getPackages(String authority, int userId);
65 }
66
67 /**
68 * Provider for default browser
69 */
70 public interface DefaultBrowserProvider {
71
72 /**
73 * Get the package name of the default browser.
74 *
75 * @param userId the user id
76 *
77 * @return the package name of the default browser, or {@code null} if none
78 */
79 @Nullable
80 String getDefaultBrowser(@UserIdInt int userId);
81
82 /**
83 * Set the package name of the default browser.
84 *
85 * @param packageName package name of the default browser, or {@code null} to remove
86 * @param userId the user id
87 *
88 * @return whether the default browser was successfully set.
89 */
90 boolean setDefaultBrowser(@Nullable String packageName, @UserIdInt int userId);
91
92 /**
93 * Set the package name of the default browser asynchronously.
94 *
95 * @param packageName package name of the default browser, or {@code null} to remove
96 * @param userId the user id
97 */
98 void setDefaultBrowserAsync(@Nullable String packageName, @UserIdInt int userId);
99 }
100
101 /**
102 * Provider for default dialer
103 */
104 public interface DefaultDialerProvider {
105
106 /**
107 * Get the package name of the default dialer.
108 *
109 * @param userId the user id
110 *
111 * @return the package name of the default dialer, or {@code null} if none
112 */
113 @Nullable
114 String getDefaultDialer(@UserIdInt int userId);
115 }
116
117 /**
118 * Provider for default home
119 */
120 public interface DefaultHomeProvider {
121
122 /**
123 * Get the package name of the default home.
124 *
125 * @param userId the user id
126 *
127 * @return the package name of the default home, or {@code null} if none
128 */
129 @Nullable
130 String getDefaultHome(@UserIdInt int userId);
131
132 /**
133 * Set the package name of the default home.
134 *
135 * @param packageName package name of the default home, or {@code null} to remove
136 * @param userId the user id
137 * @param callback the callback made after the default home as been updated
138 */
139 void setDefaultHomeAsync(@Nullable String packageName, @UserIdInt int userId,
140 @NonNull Consumer<Boolean> callback);
141 }
142
143 /**
Todd Kennedy0eb97382017-10-03 16:57:22 -0700144 * Callbacks invoked when interesting actions have been taken on a permission.
145 * <p>
146 * NOTE: The current arguments are merely to support the existing use cases. This
147 * needs to be properly thought out with appropriate arguments for each of the
148 * callback methods.
149 */
150 public static class PermissionCallback {
Nate Myrend3a63852019-06-07 13:11:58 -0700151 public void onGidsChanged(@AppIdInt int appId, @UserIdInt int userId) {
Todd Kennedy0eb97382017-10-03 16:57:22 -0700152 }
153 public void onPermissionChanged() {
154 }
Nate Myrend3a63852019-06-07 13:11:58 -0700155 public void onPermissionGranted(int uid, @UserIdInt int userId) {
Todd Kennedy0eb97382017-10-03 16:57:22 -0700156 }
157 public void onInstallPermissionGranted() {
158 }
Evan Seversonaacd48b2020-06-22 16:45:03 -0700159 public void onPermissionRevoked(int uid, @UserIdInt int userId, String reason) {
Todd Kennedy0eb97382017-10-03 16:57:22 -0700160 }
161 public void onInstallPermissionRevoked() {
162 }
Nate Myrend3a63852019-06-07 13:11:58 -0700163 public void onPermissionUpdated(@UserIdInt int[] updatedUserIds, boolean sync) {
164 }
165 public void onPermissionUpdatedNotifyListener(@UserIdInt int[] updatedUserIds, boolean sync,
166 int uid) {
Nate Myrencc9e2c72019-11-08 14:57:15 -0800167 onPermissionUpdated(updatedUserIds, sync);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700168 }
169 public void onPermissionRemoved() {
170 }
171 public void onInstallPermissionUpdated() {
172 }
Nate Myrend3a63852019-06-07 13:11:58 -0700173 public void onInstallPermissionUpdatedNotifyListener(int uid) {
Nate Myrencc9e2c72019-11-08 14:57:15 -0800174 onInstallPermissionUpdated();
Nate Myrend3a63852019-06-07 13:11:58 -0700175 }
Todd Kennedy0eb97382017-10-03 16:57:22 -0700176 }
177
Todd Kennedyc29b11a2017-10-23 15:55:59 -0700178 public abstract void systemReady();
179
Winson14ff7172019-10-23 10:42:27 -0700180 public abstract boolean isPermissionsReviewRequired(@NonNull AndroidPackage pkg,
Philip P. Moltmannc91ff6f2019-06-14 14:35:42 -0700181 @UserIdInt int userId);
Todd Kennedyc29b11a2017-10-23 15:55:59 -0700182
Todd Kennedy0eb97382017-10-03 16:57:22 -0700183 public abstract void grantRequestedRuntimePermissions(
Winson14ff7172019-10-23 10:42:27 -0700184 @NonNull AndroidPackage pkg, @NonNull int[] userIds,
Todd Kennedyc971a452019-07-08 16:04:52 -0700185 @NonNull String[] grantedPermissions, int callingUid);
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700186 public abstract void setWhitelistedRestrictedPermissions(
Winson14ff7172019-10-23 10:42:27 -0700187 @NonNull AndroidPackage pkg, @NonNull int[] userIds,
Svet Ganovd8eb8b22019-04-05 18:52:08 -0700188 @NonNull List<String> permissions, int callingUid,
Todd Kennedyc971a452019-07-08 16:04:52 -0700189 @PackageManager.PermissionWhitelistFlags int whitelistFlags);
Todd Kennedy7e3dd3a2019-07-08 10:34:29 -0700190 /** Sets the whitelisted, restricted permissions for the given package. */
191 public abstract void setWhitelistedRestrictedPermissions(
192 @NonNull String packageName, @NonNull List<String> permissions,
Eugene Susla922cd082020-03-11 12:38:17 -0700193 @PackageManager.PermissionWhitelistFlags int flags, int userId);
194 public abstract void setAutoRevokeWhitelisted(
195 @NonNull String packageName, boolean whitelisted, int userId);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700196
Philip P. Moltmanndc65aa32019-03-28 12:02:45 -0700197 /**
198 * Update permissions when a package changed.
199 *
200 * <p><ol>
201 * <li>Reconsider the ownership of permission</li>
202 * <li>Update the state (grant, flags) of the permissions</li>
203 * </ol>
204 *
205 * @param packageName The package that is updated
206 * @param pkg The package that is updated, or {@code null} if package is deleted
207 * @param allPackages All currently known packages
208 * @param callback Callback to call after permission changes
209 */
210 public abstract void updatePermissions(@NonNull String packageName,
Winson14ff7172019-10-23 10:42:27 -0700211 @Nullable AndroidPackage pkg);
Philip P. Moltmanndc65aa32019-03-28 12:02:45 -0700212
213 /**
214 * Update all permissions for all apps.
215 *
216 * <p><ol>
217 * <li>Reconsider the ownership of permission</li>
218 * <li>Update the state (grant, flags) of the permissions</li>
219 * </ol>
220 *
221 * @param volumeUuid The volume of the packages to be updated, {@code null} for all volumes
222 * @param allPackages All currently known packages
223 * @param callback Callback to call after permission changes
224 */
Todd Kennedyc971a452019-07-08 16:04:52 -0700225 public abstract void updateAllPermissions(@Nullable String volumeUuid, boolean sdkUpdate);
226
227 /**
228 * Resets any user permission state changes (eg. permissions and flags) of all
229 * packages installed for the given user.
230 *
Winson14ff7172019-10-23 10:42:27 -0700231 * @see #resetRuntimePermissions(AndroidPackage, int)
Todd Kennedyc971a452019-07-08 16:04:52 -0700232 */
233 public abstract void resetAllRuntimePermissions(@UserIdInt int userId);
234
235 /**
236 * Resets any user permission state changes (eg. permissions and flags) of the
237 * specified package for the given user.
238 */
Winson14ff7172019-10-23 10:42:27 -0700239 public abstract void resetRuntimePermissions(@NonNull AndroidPackage pkg,
Todd Kennedyc971a452019-07-08 16:04:52 -0700240 @UserIdInt int userId);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700241
Todd Kennedyc8423932017-10-05 08:58:36 -0700242 /**
Philip P. Moltmannfae8a5282018-04-10 12:15:32 -0700243 * We might auto-grant permissions if any permission of the group is already granted. Hence if
244 * the group of a granted permission changes we need to revoke it to avoid having permissions of
245 * the new group auto-granted.
246 *
247 * @param newPackage The new package that was installed
248 * @param oldPackage The old package that was updated
249 * @param allPackageNames All packages
Philip P. Moltmannfae8a5282018-04-10 12:15:32 -0700250 */
251 public abstract void revokeRuntimePermissionsIfGroupChanged(
Winson14ff7172019-10-23 10:42:27 -0700252 @NonNull AndroidPackage newPackage,
253 @NonNull AndroidPackage oldPackage,
Todd Kennedyc971a452019-07-08 16:04:52 -0700254 @NonNull ArrayList<String> allPackageNames);
Philip P. Moltmannfae8a5282018-04-10 12:15:32 -0700255
256 /**
Todd Kennedyc8423932017-10-05 08:58:36 -0700257 * Add all permissions in the given package.
258 * <p>
259 * NOTE: argument {@code groupTEMP} is temporary until mPermissionGroups is moved to
260 * the permission settings.
261 */
Winson14ff7172019-10-23 10:42:27 -0700262 public abstract void addAllPermissions(@NonNull AndroidPackage pkg, boolean chatty);
263 public abstract void addAllPermissionGroups(@NonNull AndroidPackage pkg, boolean chatty);
264 public abstract void removeAllPermissions(@NonNull AndroidPackage pkg, boolean chatty);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700265
Todd Kennedy8f135982019-07-02 07:35:15 -0700266 /** Retrieve the packages that have requested the given app op permission */
267 public abstract @Nullable String[] getAppOpPermissionPackages(
268 @NonNull String permName, int callingUid);
Todd Kennedyc8423932017-10-05 08:58:36 -0700269
Todd Kennedy0eb97382017-10-03 16:57:22 -0700270 /**
271 * Enforces the request is from the system or an app that has INTERACT_ACROSS_USERS
272 * or INTERACT_ACROSS_USERS_FULL permissions, if the {@code userid} is not for the caller.
273 * @param checkShell whether to prevent shell from access if there's a debugging restriction
274 * @param message the message to log on security exception
275 */
276 public abstract void enforceCrossUserPermission(int callingUid, int userId,
277 boolean requireFullPermission, boolean checkShell, @NonNull String message);
kholoud mohamed67ac7c62019-12-06 16:33:48 +0000278
279 /**
280 * Similar to {@link #enforceCrossUserPermission(int, int, boolean, boolean, String)}
281 * but also allows INTERACT_ACROSS_PROFILES permission if calling user and {@code userId} are
282 * in the same profile group.
283 */
284 public abstract void enforceCrossUserOrProfilePermission(int callingUid, int userId,
285 boolean requireFullPermission, boolean checkShell, @NonNull String message);
286
Todd Kennedyef9acb62018-05-29 15:18:06 -0700287 /**
288 * @see #enforceCrossUserPermission(int, int, boolean, boolean, String)
289 * @param requirePermissionWhenSameUser When {@code true}, still require the cross user
290 * permission to be held even if the callingUid and userId reference the same user.
291 */
292 public abstract void enforceCrossUserPermission(int callingUid, int userId,
293 boolean requireFullPermission, boolean checkShell,
294 boolean requirePermissionWhenSameUser, @NonNull String message);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700295 public abstract void enforceGrantRevokeRuntimePermissionPermissions(@NonNull String message);
296
297 public abstract @NonNull PermissionSettings getPermissionSettings();
Todd Kennedy583378d2019-07-12 06:50:30 -0700298
299 /** Grants default browser permissions to the given package */
300 public abstract void grantDefaultPermissionsToDefaultBrowser(
301 @NonNull String packageName, @UserIdInt int userId);
Todd Kennedy0eb97382017-10-03 16:57:22 -0700302
303 /** HACK HACK methods to allow for partial migration of data to the PermissionManager class */
Todd Kennedy0eb97382017-10-03 16:57:22 -0700304 public abstract @Nullable BasePermission getPermissionTEMP(@NonNull String permName);
Philip P. Moltmannfad1a8f2019-06-14 09:02:24 -0700305
Hai Zhanga7c60c02020-03-05 16:03:35 -0800306 /** Get all permissions that have a certain protection */
307 public abstract @NonNull ArrayList<PermissionInfo> getAllPermissionsWithProtection(
Hai Zhang57bc3122019-10-21 16:04:15 -0700308 @PermissionInfo.Protection int protection);
Todd Kennedyca1ea172019-07-03 15:02:28 -0700309
Hai Zhanga7c60c02020-03-05 16:03:35 -0800310 /** Get all permissions that have certain protection flags */
311 public abstract @NonNull ArrayList<PermissionInfo> getAllPermissionsWithProtectionFlags(
312 @PermissionInfo.ProtectionFlags int protectionFlags);
313
Todd Kennedyca1ea172019-07-03 15:02:28 -0700314 /**
315 * Returns the delegate used to influence permission checking.
316 *
317 * @return The delegate instance.
318 */
319 public abstract @Nullable CheckPermissionDelegate getCheckPermissionDelegate();
320
321 /**
322 * Sets the delegate used to influence permission checking.
323 *
324 * @param delegate A delegate instance or {@code null} to clear.
325 */
326 public abstract void setCheckPermissionDelegate(@Nullable CheckPermissionDelegate delegate);
Todd Kennedy583378d2019-07-12 06:50:30 -0700327
328 /**
329 * Sets the dialer application packages provider.
330 * @param provider The provider.
331 */
332 public abstract void setDialerAppPackagesProvider(PackagesProvider provider);
333
334 /**
335 * Set the location extra packages provider.
336 * @param provider The packages provider.
337 */
338 public abstract void setLocationExtraPackagesProvider(PackagesProvider provider);
339
340 /**
341 * Sets the location provider packages provider.
342 * @param provider The packages provider.
343 */
344 public abstract void setLocationPackagesProvider(PackagesProvider provider);
345
346 /**
347 * Sets the SIM call manager packages provider.
348 * @param provider The provider.
349 */
350 public abstract void setSimCallManagerPackagesProvider(PackagesProvider provider);
351
352 /**
353 * Sets the SMS application packages provider.
354 * @param provider The provider.
355 */
356 public abstract void setSmsAppPackagesProvider(PackagesProvider provider);
357
358 /**
359 * Sets the sync adapter packages provider.
360 * @param provider The provider.
361 */
362 public abstract void setSyncAdapterPackagesProvider(SyncAdapterPackagesProvider provider);
363
364 /**
365 * Sets the Use Open Wifi packages provider.
366 * @param provider The packages provider.
367 */
368 public abstract void setUseOpenWifiAppPackagesProvider(PackagesProvider provider);
369
370 /**
371 * Sets the voice interaction packages provider.
372 * @param provider The packages provider.
373 */
374 public abstract void setVoiceInteractionPackagesProvider(PackagesProvider provider);
375
376 /**
377 * Sets the default browser provider.
378 *
379 * @param provider the provider
380 */
381 public abstract void setDefaultBrowserProvider(@NonNull DefaultBrowserProvider provider);
382
383 /**
384 * Sets the package name of the default browser provider for the given user.
385 *
386 * @param packageName The package name of the default browser or {@code null}
387 * to clear the default browser
388 * @param async If {@code true}, set the default browser asynchronously,
389 * otherwise set it synchronously
390 * @param doGrant If {@code true} and if {@code packageName} is not {@code null},
391 * perform default permission grants on the browser, otherwise skip the
392 * default permission grants.
393 * @param userId The user to set the default browser for.
394 */
395 public abstract void setDefaultBrowser(@Nullable String packageName, boolean async,
396 boolean doGrant, @UserIdInt int userId);
397
398 /**
399 * Sets the default dialer provider.
400 *
401 * @param provider the provider
402 */
403 public abstract void setDefaultDialerProvider(@NonNull DefaultDialerProvider provider);
404
405 /**
406 * Sets the default home provider.
407 *
408 * @param provider the provider
409 */
410 public abstract void setDefaultHomeProvider(@NonNull DefaultHomeProvider provider);
411
412 /**
413 * Asynchronously sets the package name of the default home provider for the given user.
414 *
415 * @param packageName The package name of the default home or {@code null}
416 * to clear the default browser
417 * @param userId The user to set the default browser for
418 * @param callback Invoked after the default home has been set
419 */
420 public abstract void setDefaultHome(@Nullable String packageName, @UserIdInt int userId,
421 @NonNull Consumer<Boolean> callback);
422
423 /**
424 * Returns the default browser package name for the given user.
425 */
426 @Nullable
427 public abstract String getDefaultBrowser(@UserIdInt int userId);
428
429 /**
430 * Returns the default dialer package name for the given user.
431 */
432 @Nullable
433 public abstract String getDefaultDialer(@UserIdInt int userId);
434
435 /**
436 * Returns the default home package name for the given user.
437 */
438 @Nullable
439 public abstract String getDefaultHome(@UserIdInt int userId);
440
441 /**
442 * Requests granting of the default permissions to the current default Use Open Wifi app.
443 * @param packageName The default use open wifi package name.
444 * @param userId The user for which to grant the permissions.
445 */
446 public abstract void grantDefaultPermissionsToDefaultSimCallManager(
447 @NonNull String packageName, @UserIdInt int userId);
448
449 /**
450 * Requests granting of the default permissions to the current default Use Open Wifi app.
451 * @param packageName The default use open wifi package name.
452 * @param userId The user for which to grant the permissions.
453 */
454 public abstract void grantDefaultPermissionsToDefaultUseOpenWifiApp(
455 @NonNull String packageName, @UserIdInt int userId);
456
Todd Kennedy583378d2019-07-12 06:50:30 -0700457 /** Called when a new user has been created. */
458 public abstract void onNewUserCreated(@UserIdInt int userId);
Winson10d51882020-05-26 10:52:23 -0700459
460 /**
461 * Removes invalid permissions which are not {@link PermissionInfo#FLAG_HARD_RESTRICTED} or
462 * {@link PermissionInfo#FLAG_SOFT_RESTRICTED} from the input.
463 */
464 public abstract void retainHardAndSoftRestrictedPermissions(@NonNull List<String> permissions);
Chad Brubaker4b5ca632018-11-20 12:53:22 -0800465}