Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.pm.permission; |
| 18 | |
| 19 | import static android.Manifest.permission.READ_EXTERNAL_STORAGE; |
| 20 | import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 21 | import static android.content.pm.PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED; |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 22 | import static com.android.server.pm.PackageManagerService.DEBUG_INSTALL; |
| 23 | import static com.android.server.pm.PackageManagerService.DEBUG_PACKAGE_SCANNING; |
| 24 | import static com.android.server.pm.PackageManagerService.DEBUG_PERMISSIONS; |
| 25 | import static com.android.server.pm.PackageManagerService.DEBUG_REMOVE; |
| 26 | import static com.android.server.pm.PackageManagerService.PLATFORM_PACKAGE_NAME; |
| 27 | import static android.os.Trace.TRACE_TAG_PACKAGE_MANAGER; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 28 | |
| 29 | import android.Manifest; |
| 30 | import android.annotation.NonNull; |
| 31 | import android.annotation.Nullable; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.pm.PackageManager; |
| 34 | import android.content.pm.PackageManagerInternal; |
| 35 | import android.content.pm.PackageParser; |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 36 | import android.content.pm.PermissionGroupInfo; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 37 | import android.content.pm.PermissionInfo; |
| 38 | import android.content.pm.PackageParser.Package; |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 39 | import android.metrics.LogMaker; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 40 | import android.os.Binder; |
| 41 | import android.os.Build; |
| 42 | import android.os.Handler; |
| 43 | import android.os.HandlerThread; |
| 44 | import android.os.Process; |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 45 | import android.os.Trace; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 46 | import android.os.UserHandle; |
| 47 | import android.os.UserManager; |
| 48 | import android.os.UserManagerInternal; |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 49 | import android.os.storage.StorageManager; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 50 | import android.os.storage.StorageManagerInternal; |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 51 | import android.text.TextUtils; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 52 | import android.util.ArrayMap; |
| 53 | import android.util.ArraySet; |
| 54 | import android.util.Log; |
| 55 | import android.util.Slog; |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 56 | import android.util.SparseArray; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 57 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 58 | import com.android.internal.annotations.GuardedBy; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 59 | import com.android.internal.logging.MetricsLogger; |
| 60 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 61 | import com.android.internal.os.RoSystemProperties; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 62 | import com.android.internal.util.ArrayUtils; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 63 | import com.android.server.LocalServices; |
| 64 | import com.android.server.ServiceThread; |
| 65 | import com.android.server.SystemConfig; |
| 66 | import com.android.server.Watchdog; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 67 | import com.android.server.pm.PackageManagerServiceUtils; |
| 68 | import com.android.server.pm.PackageSetting; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 69 | import com.android.server.pm.SharedUserSetting; |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 70 | import com.android.server.pm.UserManagerService; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 71 | import com.android.server.pm.permission.DefaultPermissionGrantPolicy.DefaultPermissionGrantedCallback; |
| 72 | import com.android.server.pm.permission.PermissionManagerInternal.PermissionCallback; |
| 73 | import com.android.server.pm.permission.PermissionsState.PermissionState; |
| 74 | |
| 75 | import libcore.util.EmptyArray; |
| 76 | |
| 77 | import java.util.ArrayList; |
| 78 | import java.util.Arrays; |
| 79 | import java.util.Collection; |
| 80 | import java.util.Iterator; |
| 81 | import java.util.List; |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 82 | import java.util.Objects; |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 83 | import java.util.Set; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Manages all permissions and handles permissions related tasks. |
| 87 | */ |
| 88 | public class PermissionManagerService { |
| 89 | private static final String TAG = "PackageManager"; |
| 90 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 91 | /** Permission grant: not grant the permission. */ |
| 92 | private static final int GRANT_DENIED = 1; |
| 93 | /** Permission grant: grant the permission as an install permission. */ |
| 94 | private static final int GRANT_INSTALL = 2; |
| 95 | /** Permission grant: grant the permission as a runtime one. */ |
| 96 | private static final int GRANT_RUNTIME = 3; |
| 97 | /** Permission grant: grant as runtime a permission that was granted as an install time one. */ |
| 98 | private static final int GRANT_UPGRADE = 4; |
| 99 | |
| 100 | /** Cap the size of permission trees that 3rd party apps can define; in characters of text */ |
| 101 | private static final int MAX_PERMISSION_TREE_FOOTPRINT = 32768; |
| 102 | /** Empty array to avoid allocations */ |
| 103 | private static final int[] EMPTY_INT_ARRAY = new int[0]; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 104 | |
| 105 | /** Lock to protect internal data access */ |
| 106 | private final Object mLock; |
| 107 | |
| 108 | /** Internal connection to the package manager */ |
| 109 | private final PackageManagerInternal mPackageManagerInt; |
| 110 | |
| 111 | /** Internal connection to the user manager */ |
| 112 | private final UserManagerInternal mUserManagerInt; |
| 113 | |
| 114 | /** Default permission policy to provide proper behaviour out-of-the-box */ |
| 115 | private final DefaultPermissionGrantPolicy mDefaultPermissionGrantPolicy; |
| 116 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 117 | /** |
| 118 | * Built-in permissions. Read from system configuration files. Mapping is from |
| 119 | * UID to permission name. |
| 120 | */ |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 121 | private final SparseArray<ArraySet<String>> mSystemPermissions; |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 122 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 123 | /** Built-in group IDs given to all packages. Read from system configuration files. */ |
| 124 | private final int[] mGlobalGids; |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 125 | |
| 126 | private final HandlerThread mHandlerThread; |
| 127 | private final Handler mHandler; |
| 128 | private final Context mContext; |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 129 | private final MetricsLogger mMetricsLogger = new MetricsLogger(); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 130 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 131 | /** Internal storage for permissions and related settings */ |
| 132 | @GuardedBy("mLock") |
| 133 | private final PermissionSettings mSettings; |
| 134 | |
| 135 | @GuardedBy("mLock") |
| 136 | private ArraySet<String> mPrivappPermissionsViolations; |
| 137 | |
| 138 | @GuardedBy("mLock") |
| 139 | private boolean mSystemReady; |
| 140 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 141 | PermissionManagerService(Context context, |
| 142 | @Nullable DefaultPermissionGrantedCallback defaultGrantCallback, |
| 143 | @NonNull Object externalLock) { |
| 144 | mContext = context; |
| 145 | mLock = externalLock; |
| 146 | mPackageManagerInt = LocalServices.getService(PackageManagerInternal.class); |
| 147 | mUserManagerInt = LocalServices.getService(UserManagerInternal.class); |
| 148 | mSettings = new PermissionSettings(context, mLock); |
| 149 | |
| 150 | mHandlerThread = new ServiceThread(TAG, |
| 151 | Process.THREAD_PRIORITY_BACKGROUND, true /*allowIo*/); |
| 152 | mHandlerThread.start(); |
| 153 | mHandler = new Handler(mHandlerThread.getLooper()); |
| 154 | Watchdog.getInstance().addThread(mHandler); |
| 155 | |
| 156 | mDefaultPermissionGrantPolicy = new DefaultPermissionGrantPolicy( |
| 157 | context, mHandlerThread.getLooper(), defaultGrantCallback, this); |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 158 | SystemConfig systemConfig = SystemConfig.getInstance(); |
| 159 | mSystemPermissions = systemConfig.getSystemPermissions(); |
| 160 | mGlobalGids = systemConfig.getGlobalGids(); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 161 | |
| 162 | // propagate permission configuration |
| 163 | final ArrayMap<String, SystemConfig.PermissionEntry> permConfig = |
| 164 | SystemConfig.getInstance().getPermissions(); |
| 165 | synchronized (mLock) { |
| 166 | for (int i=0; i<permConfig.size(); i++) { |
| 167 | final SystemConfig.PermissionEntry perm = permConfig.valueAt(i); |
| 168 | BasePermission bp = mSettings.getPermissionLocked(perm.name); |
| 169 | if (bp == null) { |
| 170 | bp = new BasePermission(perm.name, "android", BasePermission.TYPE_BUILTIN); |
| 171 | mSettings.putPermissionLocked(perm.name, bp); |
| 172 | } |
| 173 | if (perm.gids != null) { |
| 174 | bp.setGids(perm.gids, perm.perUser); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | LocalServices.addService( |
| 180 | PermissionManagerInternal.class, new PermissionManagerInternalImpl()); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Creates and returns an initialized, internal service for use by other components. |
| 185 | * <p> |
| 186 | * The object returned is identical to the one returned by the LocalServices class using: |
| 187 | * {@code LocalServices.getService(PermissionManagerInternal.class);} |
| 188 | * <p> |
| 189 | * NOTE: The external lock is temporary and should be removed. This needs to be a |
| 190 | * lock created by the permission manager itself. |
| 191 | */ |
| 192 | public static PermissionManagerInternal create(Context context, |
| 193 | @Nullable DefaultPermissionGrantedCallback defaultGrantCallback, |
| 194 | @NonNull Object externalLock) { |
| 195 | final PermissionManagerInternal permMgrInt = |
| 196 | LocalServices.getService(PermissionManagerInternal.class); |
| 197 | if (permMgrInt != null) { |
| 198 | return permMgrInt; |
| 199 | } |
| 200 | new PermissionManagerService(context, defaultGrantCallback, externalLock); |
| 201 | return LocalServices.getService(PermissionManagerInternal.class); |
| 202 | } |
| 203 | |
| 204 | @Nullable BasePermission getPermission(String permName) { |
| 205 | synchronized (mLock) { |
| 206 | return mSettings.getPermissionLocked(permName); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | private int checkPermission(String permName, String pkgName, int callingUid, int userId) { |
| 211 | if (!mUserManagerInt.exists(userId)) { |
| 212 | return PackageManager.PERMISSION_DENIED; |
| 213 | } |
| 214 | |
| 215 | final PackageParser.Package pkg = mPackageManagerInt.getPackage(pkgName); |
| 216 | if (pkg != null && pkg.mExtras != null) { |
| 217 | if (mPackageManagerInt.filterAppAccess(pkg, callingUid, userId)) { |
| 218 | return PackageManager.PERMISSION_DENIED; |
| 219 | } |
| 220 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 221 | final boolean instantApp = ps.getInstantApp(userId); |
| 222 | final PermissionsState permissionsState = ps.getPermissionsState(); |
| 223 | if (permissionsState.hasPermission(permName, userId)) { |
| 224 | if (instantApp) { |
| 225 | synchronized (mLock) { |
| 226 | BasePermission bp = mSettings.getPermissionLocked(permName); |
| 227 | if (bp != null && bp.isInstant()) { |
| 228 | return PackageManager.PERMISSION_GRANTED; |
| 229 | } |
| 230 | } |
| 231 | } else { |
| 232 | return PackageManager.PERMISSION_GRANTED; |
| 233 | } |
| 234 | } |
| 235 | // Special case: ACCESS_FINE_LOCATION permission includes ACCESS_COARSE_LOCATION |
| 236 | if (Manifest.permission.ACCESS_COARSE_LOCATION.equals(permName) && permissionsState |
| 237 | .hasPermission(Manifest.permission.ACCESS_FINE_LOCATION, userId)) { |
| 238 | return PackageManager.PERMISSION_GRANTED; |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | return PackageManager.PERMISSION_DENIED; |
| 243 | } |
| 244 | |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 245 | private int checkUidPermission(String permName, int uid, int callingUid) { |
| 246 | final int callingUserId = UserHandle.getUserId(callingUid); |
| 247 | final boolean isCallerInstantApp = |
| 248 | mPackageManagerInt.getInstantAppPackageName(callingUid) != null; |
| 249 | final boolean isUidInstantApp = |
| 250 | mPackageManagerInt.getInstantAppPackageName(uid) != null; |
| 251 | final int userId = UserHandle.getUserId(uid); |
| 252 | if (!mUserManagerInt.exists(userId)) { |
| 253 | return PackageManager.PERMISSION_DENIED; |
| 254 | } |
| 255 | |
| 256 | final String[] packages = mContext.getPackageManager().getPackagesForUid(uid); |
| 257 | if (packages != null && packages.length > 0) { |
Todd Kennedy | 1ab4384 | 2017-10-26 08:45:21 -0700 | [diff] [blame] | 258 | PackageParser.Package pkg = null; |
| 259 | for (String packageName : packages) { |
| 260 | pkg = mPackageManagerInt.getPackage(packageName); |
| 261 | if (pkg != null) { |
Todd Kennedy | 1ab4384 | 2017-10-26 08:45:21 -0700 | [diff] [blame] | 262 | break; |
Todd Kennedy | 1ab4384 | 2017-10-26 08:45:21 -0700 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | if (pkg == null) { |
| 266 | Slog.e(TAG, "TODD: No package not found; UID: " + uid); |
Todd Kennedy | b8ce9f0 | 2017-10-26 14:31:15 -0700 | [diff] [blame] | 267 | Slog.e(TAG, "TODD: Packages: " + Arrays.toString(packages)); |
Todd Kennedy | 1ab4384 | 2017-10-26 08:45:21 -0700 | [diff] [blame] | 268 | return PackageManager.PERMISSION_DENIED; |
| 269 | } |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 270 | if (pkg.mSharedUserId != null) { |
| 271 | if (isCallerInstantApp) { |
| 272 | return PackageManager.PERMISSION_DENIED; |
| 273 | } |
| 274 | } else { |
| 275 | if (mPackageManagerInt.filterAppAccess(pkg, callingUid, callingUserId)) { |
| 276 | return PackageManager.PERMISSION_DENIED; |
| 277 | } |
| 278 | } |
| 279 | final PermissionsState permissionsState = |
| 280 | ((PackageSetting) pkg.mExtras).getPermissionsState(); |
| 281 | if (permissionsState.hasPermission(permName, userId)) { |
| 282 | if (isUidInstantApp) { |
| 283 | if (mSettings.isPermissionInstant(permName)) { |
| 284 | return PackageManager.PERMISSION_GRANTED; |
| 285 | } |
| 286 | } else { |
| 287 | return PackageManager.PERMISSION_GRANTED; |
| 288 | } |
| 289 | } |
| 290 | // Special case: ACCESS_FINE_LOCATION permission includes ACCESS_COARSE_LOCATION |
| 291 | if (Manifest.permission.ACCESS_COARSE_LOCATION.equals(permName) && permissionsState |
| 292 | .hasPermission(Manifest.permission.ACCESS_FINE_LOCATION, userId)) { |
| 293 | return PackageManager.PERMISSION_GRANTED; |
| 294 | } |
| 295 | } else { |
| 296 | ArraySet<String> perms = mSystemPermissions.get(uid); |
| 297 | if (perms != null) { |
| 298 | if (perms.contains(permName)) { |
| 299 | return PackageManager.PERMISSION_GRANTED; |
| 300 | } |
| 301 | if (Manifest.permission.ACCESS_COARSE_LOCATION.equals(permName) && perms |
| 302 | .contains(Manifest.permission.ACCESS_FINE_LOCATION)) { |
| 303 | return PackageManager.PERMISSION_GRANTED; |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | return PackageManager.PERMISSION_DENIED; |
| 308 | } |
| 309 | |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 310 | private PermissionGroupInfo getPermissionGroupInfo(String groupName, int flags, |
| 311 | int callingUid) { |
| 312 | if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { |
| 313 | return null; |
| 314 | } |
| 315 | synchronized (mLock) { |
| 316 | return PackageParser.generatePermissionGroupInfo( |
| 317 | mSettings.mPermissionGroups.get(groupName), flags); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | private List<PermissionGroupInfo> getAllPermissionGroups(int flags, int callingUid) { |
| 322 | if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { |
| 323 | return null; |
| 324 | } |
| 325 | synchronized (mLock) { |
| 326 | final int N = mSettings.mPermissionGroups.size(); |
| 327 | final ArrayList<PermissionGroupInfo> out |
| 328 | = new ArrayList<PermissionGroupInfo>(N); |
| 329 | for (PackageParser.PermissionGroup pg : mSettings.mPermissionGroups.values()) { |
| 330 | out.add(PackageParser.generatePermissionGroupInfo(pg, flags)); |
| 331 | } |
| 332 | return out; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | private PermissionInfo getPermissionInfo(String permName, String packageName, int flags, |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 337 | int callingUid) { |
| 338 | if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { |
| 339 | return null; |
| 340 | } |
| 341 | // reader |
| 342 | synchronized (mLock) { |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 343 | final BasePermission bp = mSettings.getPermissionLocked(permName); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 344 | if (bp == null) { |
| 345 | return null; |
| 346 | } |
| 347 | final int adjustedProtectionLevel = adjustPermissionProtectionFlagsLocked( |
| 348 | bp.getProtectionLevel(), packageName, callingUid); |
| 349 | return bp.generatePermissionInfo(adjustedProtectionLevel, flags); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | private List<PermissionInfo> getPermissionInfoByGroup( |
| 354 | String groupName, int flags, int callingUid) { |
| 355 | if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { |
| 356 | return null; |
| 357 | } |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 358 | synchronized (mLock) { |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 359 | if (groupName != null && !mSettings.mPermissionGroups.containsKey(groupName)) { |
| 360 | return null; |
| 361 | } |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 362 | final ArrayList<PermissionInfo> out = new ArrayList<PermissionInfo>(10); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 363 | for (BasePermission bp : mSettings.mPermissions.values()) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 364 | final PermissionInfo pi = bp.generatePermissionInfo(groupName, flags); |
| 365 | if (pi != null) { |
| 366 | out.add(pi); |
| 367 | } |
| 368 | } |
| 369 | return out; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | private int adjustPermissionProtectionFlagsLocked( |
| 374 | int protectionLevel, String packageName, int uid) { |
| 375 | // Signature permission flags area always reported |
| 376 | final int protectionLevelMasked = protectionLevel |
| 377 | & (PermissionInfo.PROTECTION_NORMAL |
| 378 | | PermissionInfo.PROTECTION_DANGEROUS |
| 379 | | PermissionInfo.PROTECTION_SIGNATURE); |
| 380 | if (protectionLevelMasked == PermissionInfo.PROTECTION_SIGNATURE) { |
| 381 | return protectionLevel; |
| 382 | } |
| 383 | // System sees all flags. |
| 384 | final int appId = UserHandle.getAppId(uid); |
| 385 | if (appId == Process.SYSTEM_UID || appId == Process.ROOT_UID |
| 386 | || appId == Process.SHELL_UID) { |
| 387 | return protectionLevel; |
| 388 | } |
| 389 | // Normalize package name to handle renamed packages and static libs |
| 390 | final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName); |
| 391 | if (pkg == null) { |
| 392 | return protectionLevel; |
| 393 | } |
| 394 | if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.O) { |
| 395 | return protectionLevelMasked; |
| 396 | } |
| 397 | // Apps that target O see flags for all protection levels. |
| 398 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 399 | if (ps == null) { |
| 400 | return protectionLevel; |
| 401 | } |
| 402 | if (ps.getAppId() != appId) { |
| 403 | return protectionLevel; |
| 404 | } |
| 405 | return protectionLevel; |
| 406 | } |
| 407 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 408 | private void addAllPermissions(PackageParser.Package pkg, boolean chatty) { |
| 409 | final int N = pkg.permissions.size(); |
| 410 | for (int i=0; i<N; i++) { |
| 411 | PackageParser.Permission p = pkg.permissions.get(i); |
| 412 | |
| 413 | // Assume by default that we did not install this permission into the system. |
| 414 | p.info.flags &= ~PermissionInfo.FLAG_INSTALLED; |
| 415 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 416 | synchronized (PermissionManagerService.this.mLock) { |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 417 | // Now that permission groups have a special meaning, we ignore permission |
| 418 | // groups for legacy apps to prevent unexpected behavior. In particular, |
| 419 | // permissions for one app being granted to someone just because they happen |
| 420 | // to be in a group defined by another app (before this had no implications). |
| 421 | if (pkg.applicationInfo.targetSdkVersion > Build.VERSION_CODES.LOLLIPOP_MR1) { |
| 422 | p.group = mSettings.mPermissionGroups.get(p.info.group); |
| 423 | // Warn for a permission in an unknown group. |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 424 | if (DEBUG_PERMISSIONS |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 425 | && p.info.group != null && p.group == null) { |
| 426 | Slog.i(TAG, "Permission " + p.info.name + " from package " |
| 427 | + p.info.packageName + " in an unknown group " + p.info.group); |
| 428 | } |
| 429 | } |
| 430 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 431 | if (p.tree) { |
| 432 | final BasePermission bp = BasePermission.createOrUpdate( |
| 433 | mSettings.getPermissionTreeLocked(p.info.name), p, pkg, |
| 434 | mSettings.getAllPermissionTreesLocked(), chatty); |
| 435 | mSettings.putPermissionTreeLocked(p.info.name, bp); |
| 436 | } else { |
| 437 | final BasePermission bp = BasePermission.createOrUpdate( |
| 438 | mSettings.getPermissionLocked(p.info.name), |
| 439 | p, pkg, mSettings.getAllPermissionTreesLocked(), chatty); |
| 440 | mSettings.putPermissionLocked(p.info.name, bp); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 446 | private void addAllPermissionGroups(PackageParser.Package pkg, boolean chatty) { |
| 447 | final int N = pkg.permissionGroups.size(); |
| 448 | StringBuilder r = null; |
| 449 | for (int i=0; i<N; i++) { |
| 450 | final PackageParser.PermissionGroup pg = pkg.permissionGroups.get(i); |
| 451 | final PackageParser.PermissionGroup cur = mSettings.mPermissionGroups.get(pg.info.name); |
| 452 | final String curPackageName = (cur == null) ? null : cur.info.packageName; |
| 453 | final boolean isPackageUpdate = pg.info.packageName.equals(curPackageName); |
| 454 | if (cur == null || isPackageUpdate) { |
| 455 | mSettings.mPermissionGroups.put(pg.info.name, pg); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 456 | if (chatty && DEBUG_PACKAGE_SCANNING) { |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 457 | if (r == null) { |
| 458 | r = new StringBuilder(256); |
| 459 | } else { |
| 460 | r.append(' '); |
| 461 | } |
| 462 | if (isPackageUpdate) { |
| 463 | r.append("UPD:"); |
| 464 | } |
| 465 | r.append(pg.info.name); |
| 466 | } |
| 467 | } else { |
| 468 | Slog.w(TAG, "Permission group " + pg.info.name + " from package " |
| 469 | + pg.info.packageName + " ignored: original from " |
| 470 | + cur.info.packageName); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 471 | if (chatty && DEBUG_PACKAGE_SCANNING) { |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 472 | if (r == null) { |
| 473 | r = new StringBuilder(256); |
| 474 | } else { |
| 475 | r.append(' '); |
| 476 | } |
| 477 | r.append("DUP:"); |
| 478 | r.append(pg.info.name); |
| 479 | } |
| 480 | } |
| 481 | } |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 482 | if (r != null && DEBUG_PACKAGE_SCANNING) { |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 483 | Log.d(TAG, " Permission Groups: " + r); |
| 484 | } |
| 485 | |
| 486 | } |
| 487 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 488 | private void removeAllPermissions(PackageParser.Package pkg, boolean chatty) { |
| 489 | synchronized (mLock) { |
| 490 | int N = pkg.permissions.size(); |
| 491 | StringBuilder r = null; |
| 492 | for (int i=0; i<N; i++) { |
| 493 | PackageParser.Permission p = pkg.permissions.get(i); |
| 494 | BasePermission bp = (BasePermission) mSettings.mPermissions.get(p.info.name); |
| 495 | if (bp == null) { |
| 496 | bp = mSettings.mPermissionTrees.get(p.info.name); |
| 497 | } |
| 498 | if (bp != null && bp.isPermission(p)) { |
| 499 | bp.setPermission(null); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 500 | if (DEBUG_REMOVE && chatty) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 501 | if (r == null) { |
| 502 | r = new StringBuilder(256); |
| 503 | } else { |
| 504 | r.append(' '); |
| 505 | } |
| 506 | r.append(p.info.name); |
| 507 | } |
| 508 | } |
| 509 | if (p.isAppOp()) { |
| 510 | ArraySet<String> appOpPkgs = |
| 511 | mSettings.mAppOpPermissionPackages.get(p.info.name); |
| 512 | if (appOpPkgs != null) { |
| 513 | appOpPkgs.remove(pkg.packageName); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | if (r != null) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 518 | if (DEBUG_REMOVE) Log.d(TAG, " Permissions: " + r); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | N = pkg.requestedPermissions.size(); |
| 522 | r = null; |
| 523 | for (int i=0; i<N; i++) { |
| 524 | String perm = pkg.requestedPermissions.get(i); |
| 525 | if (mSettings.isPermissionAppOp(perm)) { |
| 526 | ArraySet<String> appOpPkgs = mSettings.mAppOpPermissionPackages.get(perm); |
| 527 | if (appOpPkgs != null) { |
| 528 | appOpPkgs.remove(pkg.packageName); |
| 529 | if (appOpPkgs.isEmpty()) { |
| 530 | mSettings.mAppOpPermissionPackages.remove(perm); |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | if (r != null) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 536 | if (DEBUG_REMOVE) Log.d(TAG, " Permissions: " + r); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | private boolean addDynamicPermission( |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 542 | PermissionInfo info, int callingUid, PermissionCallback callback) { |
| 543 | if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { |
| 544 | throw new SecurityException("Instant apps can't add permissions"); |
| 545 | } |
| 546 | if (info.labelRes == 0 && info.nonLocalizedLabel == null) { |
| 547 | throw new SecurityException("Label must be specified in permission"); |
| 548 | } |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 549 | final BasePermission tree = mSettings.enforcePermissionTree(info.name, callingUid); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 550 | final boolean added; |
| 551 | final boolean changed; |
| 552 | synchronized (mLock) { |
| 553 | BasePermission bp = mSettings.getPermissionLocked(info.name); |
| 554 | added = bp == null; |
| 555 | int fixedLevel = PermissionInfo.fixProtectionLevel(info.protectionLevel); |
| 556 | if (added) { |
| 557 | enforcePermissionCapLocked(info, tree); |
| 558 | bp = new BasePermission(info.name, tree.getSourcePackageName(), |
| 559 | BasePermission.TYPE_DYNAMIC); |
| 560 | } else if (bp.isDynamic()) { |
Jeff Sharkey | 4dc5052 | 2017-10-17 15:29:41 -0600 | [diff] [blame] | 561 | // TODO: switch this back to SecurityException |
| 562 | Slog.wtf(TAG, "Not allowed to modify non-dynamic permission " |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 563 | + info.name); |
| 564 | } |
| 565 | changed = bp.addToTree(fixedLevel, info, tree); |
| 566 | if (added) { |
| 567 | mSettings.putPermissionLocked(info.name, bp); |
| 568 | } |
| 569 | } |
| 570 | if (changed && callback != null) { |
| 571 | callback.onPermissionChanged(); |
| 572 | } |
| 573 | return added; |
| 574 | } |
| 575 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 576 | private void removeDynamicPermission( |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 577 | String permName, int callingUid, PermissionCallback callback) { |
| 578 | if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { |
| 579 | throw new SecurityException("Instant applications don't have access to this method"); |
| 580 | } |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 581 | final BasePermission tree = mSettings.enforcePermissionTree(permName, callingUid); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 582 | synchronized (mLock) { |
| 583 | final BasePermission bp = mSettings.getPermissionLocked(permName); |
| 584 | if (bp == null) { |
| 585 | return; |
| 586 | } |
| 587 | if (bp.isDynamic()) { |
Jeff Sharkey | 4dc5052 | 2017-10-17 15:29:41 -0600 | [diff] [blame] | 588 | // TODO: switch this back to SecurityException |
| 589 | Slog.wtf(TAG, "Not allowed to modify non-dynamic permission " |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 590 | + permName); |
| 591 | } |
| 592 | mSettings.removePermissionLocked(permName); |
| 593 | if (callback != null) { |
| 594 | callback.onPermissionRemoved(); |
| 595 | } |
| 596 | } |
| 597 | } |
| 598 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 599 | private void grantPermissions(PackageParser.Package pkg, boolean replace, |
| 600 | String packageOfInterest, PermissionCallback callback) { |
| 601 | // IMPORTANT: There are two types of permissions: install and runtime. |
| 602 | // Install time permissions are granted when the app is installed to |
| 603 | // all device users and users added in the future. Runtime permissions |
| 604 | // are granted at runtime explicitly to specific users. Normal and signature |
| 605 | // protected permissions are install time permissions. Dangerous permissions |
| 606 | // are install permissions if the app's target SDK is Lollipop MR1 or older, |
| 607 | // otherwise they are runtime permissions. This function does not manage |
| 608 | // runtime permissions except for the case an app targeting Lollipop MR1 |
| 609 | // being upgraded to target a newer SDK, in which case dangerous permissions |
| 610 | // are transformed from install time to runtime ones. |
| 611 | |
| 612 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 613 | if (ps == null) { |
| 614 | return; |
| 615 | } |
| 616 | final boolean isLegacySystemApp = mPackageManagerInt.isLegacySystemApp(pkg); |
| 617 | |
| 618 | final PermissionsState permissionsState = ps.getPermissionsState(); |
| 619 | PermissionsState origPermissions = permissionsState; |
| 620 | |
| 621 | final int[] currentUserIds = UserManagerService.getInstance().getUserIds(); |
| 622 | |
| 623 | boolean runtimePermissionsRevoked = false; |
| 624 | int[] updatedUserIds = EMPTY_INT_ARRAY; |
| 625 | |
| 626 | boolean changedInstallPermission = false; |
| 627 | |
| 628 | if (replace) { |
| 629 | ps.setInstallPermissionsFixed(false); |
| 630 | if (!ps.isSharedUser()) { |
| 631 | origPermissions = new PermissionsState(permissionsState); |
| 632 | permissionsState.reset(); |
| 633 | } else { |
| 634 | // We need to know only about runtime permission changes since the |
| 635 | // calling code always writes the install permissions state but |
| 636 | // the runtime ones are written only if changed. The only cases of |
| 637 | // changed runtime permissions here are promotion of an install to |
| 638 | // runtime and revocation of a runtime from a shared user. |
| 639 | synchronized (mLock) { |
| 640 | updatedUserIds = revokeUnusedSharedUserPermissionsLocked( |
| 641 | ps.getSharedUser(), UserManagerService.getInstance().getUserIds()); |
| 642 | if (!ArrayUtils.isEmpty(updatedUserIds)) { |
| 643 | runtimePermissionsRevoked = true; |
| 644 | } |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | permissionsState.setGlobalGids(mGlobalGids); |
| 650 | |
| 651 | synchronized (mLock) { |
| 652 | final int N = pkg.requestedPermissions.size(); |
| 653 | for (int i = 0; i < N; i++) { |
| 654 | final String permName = pkg.requestedPermissions.get(i); |
| 655 | final BasePermission bp = mSettings.getPermissionLocked(permName); |
| 656 | final boolean appSupportsRuntimePermissions = |
| 657 | pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M; |
| 658 | |
| 659 | if (DEBUG_INSTALL) { |
| 660 | Log.i(TAG, "Package " + pkg.packageName + " checking " + permName + ": " + bp); |
| 661 | } |
| 662 | |
| 663 | if (bp == null || bp.getSourcePackageSetting() == null) { |
| 664 | if (packageOfInterest == null || packageOfInterest.equals(pkg.packageName)) { |
| 665 | if (DEBUG_PERMISSIONS) { |
| 666 | Slog.i(TAG, "Unknown permission " + permName |
| 667 | + " in package " + pkg.packageName); |
| 668 | } |
| 669 | } |
| 670 | continue; |
| 671 | } |
| 672 | |
| 673 | // Limit ephemeral apps to ephemeral allowed permissions. |
| 674 | if (pkg.applicationInfo.isInstantApp() && !bp.isInstant()) { |
| 675 | if (DEBUG_PERMISSIONS) { |
| 676 | Log.i(TAG, "Denying non-ephemeral permission " + bp.getName() |
| 677 | + " for package " + pkg.packageName); |
| 678 | } |
| 679 | continue; |
| 680 | } |
| 681 | |
| 682 | if (bp.isRuntimeOnly() && !appSupportsRuntimePermissions) { |
| 683 | if (DEBUG_PERMISSIONS) { |
| 684 | Log.i(TAG, "Denying runtime-only permission " + bp.getName() |
| 685 | + " for package " + pkg.packageName); |
| 686 | } |
| 687 | continue; |
| 688 | } |
| 689 | |
| 690 | final String perm = bp.getName(); |
| 691 | boolean allowedSig = false; |
| 692 | int grant = GRANT_DENIED; |
| 693 | |
| 694 | // Keep track of app op permissions. |
| 695 | if (bp.isAppOp()) { |
| 696 | mSettings.addAppOpPackage(perm, pkg.packageName); |
| 697 | } |
| 698 | |
| 699 | if (bp.isNormal()) { |
| 700 | // For all apps normal permissions are install time ones. |
| 701 | grant = GRANT_INSTALL; |
| 702 | } else if (bp.isRuntime()) { |
| 703 | // If a permission review is required for legacy apps we represent |
| 704 | // their permissions as always granted runtime ones since we need |
| 705 | // to keep the review required permission flag per user while an |
| 706 | // install permission's state is shared across all users. |
| 707 | if (!appSupportsRuntimePermissions && !mSettings.mPermissionReviewRequired) { |
| 708 | // For legacy apps dangerous permissions are install time ones. |
| 709 | grant = GRANT_INSTALL; |
| 710 | } else if (origPermissions.hasInstallPermission(bp.getName())) { |
| 711 | // For legacy apps that became modern, install becomes runtime. |
| 712 | grant = GRANT_UPGRADE; |
| 713 | } else if (isLegacySystemApp) { |
| 714 | // For legacy system apps, install becomes runtime. |
| 715 | // We cannot check hasInstallPermission() for system apps since those |
| 716 | // permissions were granted implicitly and not persisted pre-M. |
| 717 | grant = GRANT_UPGRADE; |
| 718 | } else { |
| 719 | // For modern apps keep runtime permissions unchanged. |
| 720 | grant = GRANT_RUNTIME; |
| 721 | } |
| 722 | } else if (bp.isSignature()) { |
| 723 | // For all apps signature permissions are install time ones. |
| 724 | allowedSig = grantSignaturePermission(perm, pkg, bp, origPermissions); |
| 725 | if (allowedSig) { |
| 726 | grant = GRANT_INSTALL; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | if (DEBUG_PERMISSIONS) { |
| 731 | Slog.i(TAG, "Granting permission " + perm + " to package " + pkg.packageName); |
| 732 | } |
| 733 | |
| 734 | if (grant != GRANT_DENIED) { |
| 735 | if (!ps.isSystem() && ps.areInstallPermissionsFixed()) { |
| 736 | // If this is an existing, non-system package, then |
| 737 | // we can't add any new permissions to it. |
| 738 | if (!allowedSig && !origPermissions.hasInstallPermission(perm)) { |
| 739 | // Except... if this is a permission that was added |
| 740 | // to the platform (note: need to only do this when |
| 741 | // updating the platform). |
| 742 | if (!isNewPlatformPermissionForPackage(perm, pkg)) { |
| 743 | grant = GRANT_DENIED; |
| 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | switch (grant) { |
| 749 | case GRANT_INSTALL: { |
| 750 | // Revoke this as runtime permission to handle the case of |
| 751 | // a runtime permission being downgraded to an install one. |
| 752 | // Also in permission review mode we keep dangerous permissions |
| 753 | // for legacy apps |
| 754 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 755 | if (origPermissions.getRuntimePermissionState( |
| 756 | perm, userId) != null) { |
| 757 | // Revoke the runtime permission and clear the flags. |
| 758 | origPermissions.revokeRuntimePermission(bp, userId); |
| 759 | origPermissions.updatePermissionFlags(bp, userId, |
| 760 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 761 | // If we revoked a permission permission, we have to write. |
| 762 | updatedUserIds = ArrayUtils.appendInt( |
| 763 | updatedUserIds, userId); |
| 764 | } |
| 765 | } |
| 766 | // Grant an install permission. |
| 767 | if (permissionsState.grantInstallPermission(bp) != |
| 768 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 769 | changedInstallPermission = true; |
| 770 | } |
| 771 | } break; |
| 772 | |
| 773 | case GRANT_RUNTIME: { |
| 774 | // Grant previously granted runtime permissions. |
| 775 | for (int userId : UserManagerService.getInstance().getUserIds()) { |
| 776 | final PermissionState permissionState = origPermissions |
| 777 | .getRuntimePermissionState(perm, userId); |
| 778 | int flags = permissionState != null |
| 779 | ? permissionState.getFlags() : 0; |
| 780 | if (origPermissions.hasRuntimePermission(perm, userId)) { |
| 781 | // Don't propagate the permission in a permission review |
| 782 | // mode if the former was revoked, i.e. marked to not |
| 783 | // propagate on upgrade. Note that in a permission review |
| 784 | // mode install permissions are represented as constantly |
| 785 | // granted runtime ones since we need to keep a per user |
| 786 | // state associated with the permission. Also the revoke |
| 787 | // on upgrade flag is no longer applicable and is reset. |
| 788 | final boolean revokeOnUpgrade = (flags & PackageManager |
| 789 | .FLAG_PERMISSION_REVOKE_ON_UPGRADE) != 0; |
| 790 | if (revokeOnUpgrade) { |
| 791 | flags &= ~PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE; |
| 792 | // Since we changed the flags, we have to write. |
| 793 | updatedUserIds = ArrayUtils.appendInt( |
| 794 | updatedUserIds, userId); |
| 795 | } |
| 796 | if (!mSettings.mPermissionReviewRequired || !revokeOnUpgrade) { |
| 797 | if (permissionsState.grantRuntimePermission(bp, userId) == |
| 798 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 799 | // If we cannot put the permission as it was, |
| 800 | // we have to write. |
| 801 | updatedUserIds = ArrayUtils.appendInt( |
| 802 | updatedUserIds, userId); |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | // If the app supports runtime permissions no need for a review. |
| 807 | if (mSettings.mPermissionReviewRequired |
| 808 | && appSupportsRuntimePermissions |
| 809 | && (flags & PackageManager |
| 810 | .FLAG_PERMISSION_REVIEW_REQUIRED) != 0) { |
| 811 | flags &= ~PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED; |
| 812 | // Since we changed the flags, we have to write. |
| 813 | updatedUserIds = ArrayUtils.appendInt( |
| 814 | updatedUserIds, userId); |
| 815 | } |
| 816 | } else if (mSettings.mPermissionReviewRequired |
| 817 | && !appSupportsRuntimePermissions) { |
| 818 | // For legacy apps that need a permission review, every new |
| 819 | // runtime permission is granted but it is pending a review. |
| 820 | // We also need to review only platform defined runtime |
| 821 | // permissions as these are the only ones the platform knows |
| 822 | // how to disable the API to simulate revocation as legacy |
| 823 | // apps don't expect to run with revoked permissions. |
| 824 | if (PLATFORM_PACKAGE_NAME.equals(bp.getSourcePackageName())) { |
| 825 | if ((flags & FLAG_PERMISSION_REVIEW_REQUIRED) == 0) { |
| 826 | flags |= FLAG_PERMISSION_REVIEW_REQUIRED; |
| 827 | // We changed the flags, hence have to write. |
| 828 | updatedUserIds = ArrayUtils.appendInt( |
| 829 | updatedUserIds, userId); |
| 830 | } |
| 831 | } |
| 832 | if (permissionsState.grantRuntimePermission(bp, userId) |
| 833 | != PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 834 | // We changed the permission, hence have to write. |
| 835 | updatedUserIds = ArrayUtils.appendInt( |
| 836 | updatedUserIds, userId); |
| 837 | } |
| 838 | } |
| 839 | // Propagate the permission flags. |
| 840 | permissionsState.updatePermissionFlags(bp, userId, flags, flags); |
| 841 | } |
| 842 | } break; |
| 843 | |
| 844 | case GRANT_UPGRADE: { |
| 845 | // Grant runtime permissions for a previously held install permission. |
| 846 | final PermissionState permissionState = origPermissions |
| 847 | .getInstallPermissionState(perm); |
| 848 | final int flags = |
| 849 | (permissionState != null) ? permissionState.getFlags() : 0; |
| 850 | |
| 851 | if (origPermissions.revokeInstallPermission(bp) |
| 852 | != PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 853 | // We will be transferring the permission flags, so clear them. |
| 854 | origPermissions.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 855 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 856 | changedInstallPermission = true; |
| 857 | } |
| 858 | |
| 859 | // If the permission is not to be promoted to runtime we ignore it and |
| 860 | // also its other flags as they are not applicable to install permissions. |
| 861 | if ((flags & PackageManager.FLAG_PERMISSION_REVOKE_ON_UPGRADE) == 0) { |
| 862 | for (int userId : currentUserIds) { |
| 863 | if (permissionsState.grantRuntimePermission(bp, userId) != |
| 864 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 865 | // Transfer the permission flags. |
| 866 | permissionsState.updatePermissionFlags(bp, userId, |
| 867 | flags, flags); |
| 868 | // If we granted the permission, we have to write. |
| 869 | updatedUserIds = ArrayUtils.appendInt( |
| 870 | updatedUserIds, userId); |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | } break; |
| 875 | |
| 876 | default: { |
| 877 | if (packageOfInterest == null |
| 878 | || packageOfInterest.equals(pkg.packageName)) { |
| 879 | if (DEBUG_PERMISSIONS) { |
| 880 | Slog.i(TAG, "Not granting permission " + perm |
| 881 | + " to package " + pkg.packageName |
| 882 | + " because it was previously installed without"); |
| 883 | } |
| 884 | } |
| 885 | } break; |
| 886 | } |
| 887 | } else { |
| 888 | if (permissionsState.revokeInstallPermission(bp) != |
| 889 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 890 | // Also drop the permission flags. |
| 891 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 892 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 893 | changedInstallPermission = true; |
| 894 | Slog.i(TAG, "Un-granting permission " + perm |
| 895 | + " from package " + pkg.packageName |
| 896 | + " (protectionLevel=" + bp.getProtectionLevel() |
| 897 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 898 | + ")"); |
| 899 | } else if (bp.isAppOp()) { |
| 900 | // Don't print warning for app op permissions, since it is fine for them |
| 901 | // not to be granted, there is a UI for the user to decide. |
| 902 | if (DEBUG_PERMISSIONS |
| 903 | && (packageOfInterest == null |
| 904 | || packageOfInterest.equals(pkg.packageName))) { |
| 905 | Slog.i(TAG, "Not granting permission " + perm |
| 906 | + " to package " + pkg.packageName |
| 907 | + " (protectionLevel=" + bp.getProtectionLevel() |
| 908 | + " flags=0x" + Integer.toHexString(pkg.applicationInfo.flags) |
| 909 | + ")"); |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | if ((changedInstallPermission || replace) && !ps.areInstallPermissionsFixed() && |
| 916 | !ps.isSystem() || ps.isUpdatedSystem()) { |
| 917 | // This is the first that we have heard about this package, so the |
| 918 | // permissions we have now selected are fixed until explicitly |
| 919 | // changed. |
| 920 | ps.setInstallPermissionsFixed(true); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | // Persist the runtime permissions state for users with changes. If permissions |
| 925 | // were revoked because no app in the shared user declares them we have to |
| 926 | // write synchronously to avoid losing runtime permissions state. |
| 927 | if (callback != null) { |
| 928 | callback.onPermissionUpdated(updatedUserIds, runtimePermissionsRevoked); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | private boolean isNewPlatformPermissionForPackage(String perm, PackageParser.Package pkg) { |
| 933 | boolean allowed = false; |
| 934 | final int NP = PackageParser.NEW_PERMISSIONS.length; |
| 935 | for (int ip=0; ip<NP; ip++) { |
| 936 | final PackageParser.NewPermissionInfo npi |
| 937 | = PackageParser.NEW_PERMISSIONS[ip]; |
| 938 | if (npi.name.equals(perm) |
| 939 | && pkg.applicationInfo.targetSdkVersion < npi.sdkVersion) { |
| 940 | allowed = true; |
| 941 | Log.i(TAG, "Auto-granting " + perm + " to old pkg " |
| 942 | + pkg.packageName); |
| 943 | break; |
| 944 | } |
| 945 | } |
| 946 | return allowed; |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * Determines whether a package is whitelisted for a particular privapp permission. |
| 951 | * |
| 952 | * <p>Does NOT check whether the package is a privapp, just whether it's whitelisted. |
| 953 | * |
| 954 | * <p>This handles parent/child apps. |
| 955 | */ |
| 956 | private boolean hasPrivappWhitelistEntry(String perm, PackageParser.Package pkg) { |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 957 | ArraySet<String> wlPermissions = null; |
| 958 | if (pkg.isVendor()) { |
| 959 | wlPermissions = |
| 960 | SystemConfig.getInstance().getVendorPrivAppPermissions(pkg.packageName); |
| 961 | } else if (pkg.isProduct()) { |
| 962 | wlPermissions = |
| 963 | SystemConfig.getInstance().getProductPrivAppPermissions(pkg.packageName); |
| 964 | } else { |
| 965 | wlPermissions = SystemConfig.getInstance().getPrivAppPermissions(pkg.packageName); |
| 966 | } |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 967 | // Let's check if this package is whitelisted... |
| 968 | boolean whitelisted = wlPermissions != null && wlPermissions.contains(perm); |
| 969 | // If it's not, we'll also tail-recurse to the parent. |
| 970 | return whitelisted || |
| 971 | pkg.parentPackage != null && hasPrivappWhitelistEntry(perm, pkg.parentPackage); |
| 972 | } |
| 973 | |
| 974 | private boolean grantSignaturePermission(String perm, PackageParser.Package pkg, |
| 975 | BasePermission bp, PermissionsState origPermissions) { |
| 976 | boolean oemPermission = bp.isOEM(); |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 977 | boolean vendorPrivilegedPermission = bp.isVendorPrivileged(); |
| 978 | boolean privilegedPermission = bp.isPrivileged() || bp.isVendorPrivileged(); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 979 | boolean privappPermissionsDisable = |
| 980 | RoSystemProperties.CONTROL_PRIVAPP_PERMISSIONS_DISABLE; |
| 981 | boolean platformPermission = PLATFORM_PACKAGE_NAME.equals(bp.getSourcePackageName()); |
| 982 | boolean platformPackage = PLATFORM_PACKAGE_NAME.equals(pkg.packageName); |
| 983 | if (!privappPermissionsDisable && privilegedPermission && pkg.isPrivileged() |
| 984 | && !platformPackage && platformPermission) { |
| 985 | if (!hasPrivappWhitelistEntry(perm, pkg)) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 986 | // Only report violations for apps on system image |
| 987 | if (!mSystemReady && !pkg.isUpdatedSystemApp()) { |
| 988 | // it's only a reportable violation if the permission isn't explicitly denied |
Jaekyun Seok | 1713d9e | 2018-01-12 21:47:26 +0900 | [diff] [blame] | 989 | ArraySet<String> deniedPermissions = null; |
| 990 | if (pkg.isVendor()) { |
| 991 | deniedPermissions = SystemConfig.getInstance() |
| 992 | .getVendorPrivAppDenyPermissions(pkg.packageName); |
| 993 | } else if (pkg.isProduct()) { |
| 994 | deniedPermissions = SystemConfig.getInstance() |
| 995 | .getProductPrivAppDenyPermissions(pkg.packageName); |
| 996 | } else { |
| 997 | deniedPermissions = SystemConfig.getInstance() |
| 998 | .getPrivAppDenyPermissions(pkg.packageName); |
| 999 | } |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1000 | final boolean permissionViolation = |
| 1001 | deniedPermissions == null || !deniedPermissions.contains(perm); |
Fyodor Kupolov | f5e600d | 2017-10-25 17:03:50 -0700 | [diff] [blame] | 1002 | if (permissionViolation) { |
| 1003 | Slog.w(TAG, "Privileged permission " + perm + " for package " |
| 1004 | + pkg.packageName + " - not in privapp-permissions whitelist"); |
| 1005 | |
| 1006 | if (RoSystemProperties.CONTROL_PRIVAPP_PERMISSIONS_ENFORCE) { |
| 1007 | if (mPrivappPermissionsViolations == null) { |
| 1008 | mPrivappPermissionsViolations = new ArraySet<>(); |
| 1009 | } |
| 1010 | mPrivappPermissionsViolations.add(pkg.packageName + ": " + perm); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1011 | } |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1012 | } else { |
| 1013 | return false; |
| 1014 | } |
| 1015 | } |
| 1016 | if (RoSystemProperties.CONTROL_PRIVAPP_PERMISSIONS_ENFORCE) { |
| 1017 | return false; |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | final String systemPackageName = mPackageManagerInt.getKnownPackageName( |
| 1022 | PackageManagerInternal.PACKAGE_SYSTEM, UserHandle.USER_SYSTEM); |
| 1023 | final PackageParser.Package systemPackage = |
| 1024 | mPackageManagerInt.getPackage(systemPackageName); |
Dan Cashman | 1dbe6d0 | 2018-01-23 11:18:28 -0800 | [diff] [blame^] | 1025 | |
| 1026 | // check if the package is allow to use this signature permission. A package is allowed to |
| 1027 | // use a signature permission if: |
| 1028 | // - it has the same set of signing certificates as the source package |
| 1029 | // - or its signing certificate was rotated from the source package's certificate |
| 1030 | // - or its signing certificate is a previous signing certificate of the defining |
| 1031 | // package, and the defining package still trusts the old certificate for permissions |
| 1032 | // - or it shares the above relationships with the system package |
| 1033 | boolean allowed = |
| 1034 | pkg.mSigningDetails.hasAncestorOrSelf( |
| 1035 | bp.getSourcePackageSetting().getSigningDetails()) |
| 1036 | || bp.getSourcePackageSetting().getSigningDetails().checkCapability( |
| 1037 | pkg.mSigningDetails, |
| 1038 | PackageParser.SigningDetails.CertCapabilities.PERMISSION) |
| 1039 | || pkg.mSigningDetails.hasAncestorOrSelf(systemPackage.mSigningDetails) |
| 1040 | || systemPackage.mSigningDetails.checkCapability( |
| 1041 | pkg.mSigningDetails, |
| 1042 | PackageParser.SigningDetails.CertCapabilities.PERMISSION); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1043 | if (!allowed && (privilegedPermission || oemPermission)) { |
| 1044 | if (pkg.isSystem()) { |
| 1045 | // For updated system applications, a privileged/oem permission |
| 1046 | // is granted only if it had been defined by the original application. |
| 1047 | if (pkg.isUpdatedSystemApp()) { |
| 1048 | final PackageParser.Package disabledPkg = |
| 1049 | mPackageManagerInt.getDisabledPackage(pkg.packageName); |
| 1050 | final PackageSetting disabledPs = |
| 1051 | (disabledPkg != null) ? (PackageSetting) disabledPkg.mExtras : null; |
| 1052 | if (disabledPs != null |
| 1053 | && disabledPs.getPermissionsState().hasInstallPermission(perm)) { |
| 1054 | // If the original was granted this permission, we take |
| 1055 | // that grant decision as read and propagate it to the |
| 1056 | // update. |
| 1057 | if ((privilegedPermission && disabledPs.isPrivileged()) |
| 1058 | || (oemPermission && disabledPs.isOem() |
| 1059 | && canGrantOemPermission(disabledPs, perm))) { |
| 1060 | allowed = true; |
| 1061 | } |
| 1062 | } else { |
| 1063 | // The system apk may have been updated with an older |
| 1064 | // version of the one on the data partition, but which |
| 1065 | // granted a new system permission that it didn't have |
| 1066 | // before. In this case we do want to allow the app to |
| 1067 | // now get the new permission if the ancestral apk is |
| 1068 | // privileged to get it. |
Todd Kennedy | 1efb833 | 2017-10-25 15:51:36 -0700 | [diff] [blame] | 1069 | if (disabledPs != null && disabledPkg != null |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1070 | && isPackageRequestingPermission(disabledPkg, perm) |
| 1071 | && ((privilegedPermission && disabledPs.isPrivileged()) |
| 1072 | || (oemPermission && disabledPs.isOem() |
| 1073 | && canGrantOemPermission(disabledPs, perm)))) { |
| 1074 | allowed = true; |
| 1075 | } |
| 1076 | // Also if a privileged parent package on the system image or any of |
| 1077 | // its children requested a privileged/oem permission, the updated child |
| 1078 | // packages can also get the permission. |
| 1079 | if (pkg.parentPackage != null) { |
| 1080 | final PackageParser.Package disabledParentPkg = mPackageManagerInt |
| 1081 | .getDisabledPackage(pkg.parentPackage.packageName); |
| 1082 | final PackageSetting disabledParentPs = (disabledParentPkg != null) |
| 1083 | ? (PackageSetting) disabledParentPkg.mExtras : null; |
| 1084 | if (disabledParentPkg != null |
| 1085 | && ((privilegedPermission && disabledParentPs.isPrivileged()) |
| 1086 | || (oemPermission && disabledParentPs.isOem()))) { |
| 1087 | if (isPackageRequestingPermission(disabledParentPkg, perm) |
| 1088 | && canGrantOemPermission(disabledParentPs, perm)) { |
| 1089 | allowed = true; |
| 1090 | } else if (disabledParentPkg.childPackages != null) { |
| 1091 | for (PackageParser.Package disabledChildPkg |
| 1092 | : disabledParentPkg.childPackages) { |
| 1093 | final PackageSetting disabledChildPs = |
| 1094 | (disabledChildPkg != null) |
| 1095 | ? (PackageSetting) disabledChildPkg.mExtras |
| 1096 | : null; |
| 1097 | if (isPackageRequestingPermission(disabledChildPkg, perm) |
| 1098 | && canGrantOemPermission( |
| 1099 | disabledChildPs, perm)) { |
| 1100 | allowed = true; |
| 1101 | break; |
| 1102 | } |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | } else { |
| 1109 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1110 | allowed = (privilegedPermission && pkg.isPrivileged()) |
| 1111 | || (oemPermission && pkg.isOem() |
| 1112 | && canGrantOemPermission(ps, perm)); |
| 1113 | } |
Jiyong Park | 002fdbd | 2017-02-13 20:50:31 +0900 | [diff] [blame] | 1114 | // In any case, don't grant a privileged permission to privileged vendor apps, if |
| 1115 | // the permission's protectionLevel does not have the extra 'vendorPrivileged' |
| 1116 | // flag. |
| 1117 | if (allowed && privilegedPermission && |
| 1118 | !vendorPrivilegedPermission && pkg.isVendor()) { |
| 1119 | Slog.w(TAG, "Permission " + perm + " cannot be granted to privileged vendor apk " |
| 1120 | + pkg.packageName + " because it isn't a 'vendorPrivileged' permission."); |
| 1121 | allowed = false; |
| 1122 | } |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1123 | } |
| 1124 | } |
| 1125 | if (!allowed) { |
| 1126 | if (!allowed |
| 1127 | && bp.isPre23() |
| 1128 | && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) { |
| 1129 | // If this was a previously normal/dangerous permission that got moved |
| 1130 | // to a system permission as part of the runtime permission redesign, then |
| 1131 | // we still want to blindly grant it to old apps. |
| 1132 | allowed = true; |
| 1133 | } |
| 1134 | if (!allowed && bp.isInstaller() |
| 1135 | && pkg.packageName.equals(mPackageManagerInt.getKnownPackageName( |
| 1136 | PackageManagerInternal.PACKAGE_INSTALLER, UserHandle.USER_SYSTEM))) { |
| 1137 | // If this permission is to be granted to the system installer and |
| 1138 | // this app is an installer, then it gets the permission. |
| 1139 | allowed = true; |
| 1140 | } |
| 1141 | if (!allowed && bp.isVerifier() |
| 1142 | && pkg.packageName.equals(mPackageManagerInt.getKnownPackageName( |
| 1143 | PackageManagerInternal.PACKAGE_VERIFIER, UserHandle.USER_SYSTEM))) { |
| 1144 | // If this permission is to be granted to the system verifier and |
| 1145 | // this app is a verifier, then it gets the permission. |
| 1146 | allowed = true; |
| 1147 | } |
| 1148 | if (!allowed && bp.isPreInstalled() |
| 1149 | && pkg.isSystem()) { |
| 1150 | // Any pre-installed system app is allowed to get this permission. |
| 1151 | allowed = true; |
| 1152 | } |
| 1153 | if (!allowed && bp.isDevelopment()) { |
| 1154 | // For development permissions, a development permission |
| 1155 | // is granted only if it was already granted. |
| 1156 | allowed = origPermissions.hasInstallPermission(perm); |
| 1157 | } |
| 1158 | if (!allowed && bp.isSetup() |
| 1159 | && pkg.packageName.equals(mPackageManagerInt.getKnownPackageName( |
| 1160 | PackageManagerInternal.PACKAGE_SETUP_WIZARD, UserHandle.USER_SYSTEM))) { |
| 1161 | // If this permission is to be granted to the system setup wizard and |
| 1162 | // this app is a setup wizard, then it gets the permission. |
| 1163 | allowed = true; |
| 1164 | } |
| 1165 | } |
| 1166 | return allowed; |
| 1167 | } |
| 1168 | |
| 1169 | private static boolean canGrantOemPermission(PackageSetting ps, String permission) { |
| 1170 | if (!ps.isOem()) { |
| 1171 | return false; |
| 1172 | } |
| 1173 | // all oem permissions must explicitly be granted or denied |
| 1174 | final Boolean granted = |
| 1175 | SystemConfig.getInstance().getOemPermissions(ps.name).get(permission); |
| 1176 | if (granted == null) { |
| 1177 | throw new IllegalStateException("OEM permission" + permission + " requested by package " |
| 1178 | + ps.name + " must be explicitly declared granted or not"); |
| 1179 | } |
| 1180 | return Boolean.TRUE == granted; |
| 1181 | } |
| 1182 | |
| 1183 | private boolean isPermissionsReviewRequired(PackageParser.Package pkg, int userId) { |
| 1184 | if (!mSettings.mPermissionReviewRequired) { |
| 1185 | return false; |
| 1186 | } |
| 1187 | |
| 1188 | // Permission review applies only to apps not supporting the new permission model. |
| 1189 | if (pkg.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.M) { |
| 1190 | return false; |
| 1191 | } |
| 1192 | |
| 1193 | // Legacy apps have the permission and get user consent on launch. |
| 1194 | if (pkg == null || pkg.mExtras == null) { |
| 1195 | return false; |
| 1196 | } |
| 1197 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1198 | final PermissionsState permissionsState = ps.getPermissionsState(); |
| 1199 | return permissionsState.isPermissionReviewRequired(userId); |
| 1200 | } |
| 1201 | |
| 1202 | private boolean isPackageRequestingPermission(PackageParser.Package pkg, String permission) { |
| 1203 | final int permCount = pkg.requestedPermissions.size(); |
| 1204 | for (int j = 0; j < permCount; j++) { |
| 1205 | String requestedPermission = pkg.requestedPermissions.get(j); |
| 1206 | if (permission.equals(requestedPermission)) { |
| 1207 | return true; |
| 1208 | } |
| 1209 | } |
| 1210 | return false; |
| 1211 | } |
| 1212 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1213 | private void grantRuntimePermissionsGrantedToDisabledPackageLocked( |
| 1214 | PackageParser.Package pkg, int callingUid, PermissionCallback callback) { |
| 1215 | if (pkg.parentPackage == null) { |
| 1216 | return; |
| 1217 | } |
| 1218 | if (pkg.requestedPermissions == null) { |
| 1219 | return; |
| 1220 | } |
| 1221 | final PackageParser.Package disabledPkg = |
| 1222 | mPackageManagerInt.getDisabledPackage(pkg.parentPackage.packageName); |
| 1223 | if (disabledPkg == null || disabledPkg.mExtras == null) { |
| 1224 | return; |
| 1225 | } |
| 1226 | final PackageSetting disabledPs = (PackageSetting) disabledPkg.mExtras; |
| 1227 | if (!disabledPs.isPrivileged() || disabledPs.hasChildPackages()) { |
| 1228 | return; |
| 1229 | } |
| 1230 | final int permCount = pkg.requestedPermissions.size(); |
| 1231 | for (int i = 0; i < permCount; i++) { |
| 1232 | String permission = pkg.requestedPermissions.get(i); |
| 1233 | BasePermission bp = mSettings.getPermissionLocked(permission); |
| 1234 | if (bp == null || !(bp.isRuntime() || bp.isDevelopment())) { |
| 1235 | continue; |
| 1236 | } |
| 1237 | for (int userId : mUserManagerInt.getUserIds()) { |
| 1238 | if (disabledPs.getPermissionsState().hasRuntimePermission(permission, userId)) { |
| 1239 | grantRuntimePermission( |
| 1240 | permission, pkg.packageName, false, callingUid, userId, callback); |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | private void grantRequestedRuntimePermissions(PackageParser.Package pkg, int[] userIds, |
| 1247 | String[] grantedPermissions, int callingUid, PermissionCallback callback) { |
| 1248 | for (int userId : userIds) { |
| 1249 | grantRequestedRuntimePermissionsForUser(pkg, userId, grantedPermissions, callingUid, |
| 1250 | callback); |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | private void grantRequestedRuntimePermissionsForUser(PackageParser.Package pkg, int userId, |
| 1255 | String[] grantedPermissions, int callingUid, PermissionCallback callback) { |
| 1256 | PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1257 | if (ps == null) { |
| 1258 | return; |
| 1259 | } |
| 1260 | |
| 1261 | PermissionsState permissionsState = ps.getPermissionsState(); |
| 1262 | |
| 1263 | final int immutableFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED |
| 1264 | | PackageManager.FLAG_PERMISSION_POLICY_FIXED; |
| 1265 | |
| 1266 | final boolean supportsRuntimePermissions = pkg.applicationInfo.targetSdkVersion |
| 1267 | >= Build.VERSION_CODES.M; |
| 1268 | |
| 1269 | final boolean instantApp = mPackageManagerInt.isInstantApp(pkg.packageName, userId); |
| 1270 | |
| 1271 | for (String permission : pkg.requestedPermissions) { |
| 1272 | final BasePermission bp; |
| 1273 | synchronized (mLock) { |
| 1274 | bp = mSettings.getPermissionLocked(permission); |
| 1275 | } |
| 1276 | if (bp != null && (bp.isRuntime() || bp.isDevelopment()) |
| 1277 | && (!instantApp || bp.isInstant()) |
| 1278 | && (supportsRuntimePermissions || !bp.isRuntimeOnly()) |
| 1279 | && (grantedPermissions == null |
| 1280 | || ArrayUtils.contains(grantedPermissions, permission))) { |
| 1281 | final int flags = permissionsState.getPermissionFlags(permission, userId); |
| 1282 | if (supportsRuntimePermissions) { |
| 1283 | // Installer cannot change immutable permissions. |
| 1284 | if ((flags & immutableFlags) == 0) { |
| 1285 | grantRuntimePermission(permission, pkg.packageName, false, callingUid, |
| 1286 | userId, callback); |
| 1287 | } |
| 1288 | } else if (mSettings.mPermissionReviewRequired) { |
| 1289 | // In permission review mode we clear the review flag when we |
| 1290 | // are asked to install the app with all permissions granted. |
| 1291 | if ((flags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) != 0) { |
| 1292 | updatePermissionFlags(permission, pkg.packageName, |
| 1293 | PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED, 0, callingUid, |
| 1294 | userId, callback); |
| 1295 | } |
| 1296 | } |
| 1297 | } |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | private void grantRuntimePermission(String permName, String packageName, boolean overridePolicy, |
| 1302 | int callingUid, final int userId, PermissionCallback callback) { |
| 1303 | if (!mUserManagerInt.exists(userId)) { |
| 1304 | Log.e(TAG, "No such user:" + userId); |
| 1305 | return; |
| 1306 | } |
| 1307 | |
| 1308 | mContext.enforceCallingOrSelfPermission( |
| 1309 | android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS, |
| 1310 | "grantRuntimePermission"); |
| 1311 | |
| 1312 | enforceCrossUserPermission(callingUid, userId, |
| 1313 | true /* requireFullPermission */, true /* checkShell */, |
| 1314 | "grantRuntimePermission"); |
| 1315 | |
| 1316 | final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName); |
| 1317 | if (pkg == null || pkg.mExtras == null) { |
| 1318 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 1319 | } |
| 1320 | final BasePermission bp; |
| 1321 | synchronized(mLock) { |
| 1322 | bp = mSettings.getPermissionLocked(permName); |
| 1323 | } |
| 1324 | if (bp == null) { |
| 1325 | throw new IllegalArgumentException("Unknown permission: " + permName); |
| 1326 | } |
| 1327 | if (mPackageManagerInt.filterAppAccess(pkg, callingUid, userId)) { |
| 1328 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 1329 | } |
| 1330 | |
| 1331 | bp.enforceDeclaredUsedAndRuntimeOrDevelopment(pkg); |
| 1332 | |
| 1333 | // If a permission review is required for legacy apps we represent |
| 1334 | // their permissions as always granted runtime ones since we need |
| 1335 | // to keep the review required permission flag per user while an |
| 1336 | // install permission's state is shared across all users. |
| 1337 | if (mSettings.mPermissionReviewRequired |
| 1338 | && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M |
| 1339 | && bp.isRuntime()) { |
| 1340 | return; |
| 1341 | } |
| 1342 | |
| 1343 | final int uid = UserHandle.getUid(userId, pkg.applicationInfo.uid); |
| 1344 | |
| 1345 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1346 | final PermissionsState permissionsState = ps.getPermissionsState(); |
| 1347 | |
| 1348 | final int flags = permissionsState.getPermissionFlags(permName, userId); |
| 1349 | if ((flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0) { |
| 1350 | throw new SecurityException("Cannot grant system fixed permission " |
| 1351 | + permName + " for package " + packageName); |
| 1352 | } |
| 1353 | if (!overridePolicy && (flags & PackageManager.FLAG_PERMISSION_POLICY_FIXED) != 0) { |
| 1354 | throw new SecurityException("Cannot grant policy fixed permission " |
| 1355 | + permName + " for package " + packageName); |
| 1356 | } |
| 1357 | |
| 1358 | if (bp.isDevelopment()) { |
| 1359 | // Development permissions must be handled specially, since they are not |
| 1360 | // normal runtime permissions. For now they apply to all users. |
| 1361 | if (permissionsState.grantInstallPermission(bp) != |
| 1362 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 1363 | if (callback != null) { |
| 1364 | callback.onInstallPermissionGranted(); |
| 1365 | } |
| 1366 | } |
| 1367 | return; |
| 1368 | } |
| 1369 | |
| 1370 | if (ps.getInstantApp(userId) && !bp.isInstant()) { |
| 1371 | throw new SecurityException("Cannot grant non-ephemeral permission" |
| 1372 | + permName + " for package " + packageName); |
| 1373 | } |
| 1374 | |
| 1375 | if (pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) { |
| 1376 | Slog.w(TAG, "Cannot grant runtime permission to a legacy app"); |
| 1377 | return; |
| 1378 | } |
| 1379 | |
| 1380 | final int result = permissionsState.grantRuntimePermission(bp, userId); |
| 1381 | switch (result) { |
| 1382 | case PermissionsState.PERMISSION_OPERATION_FAILURE: { |
| 1383 | return; |
| 1384 | } |
| 1385 | |
| 1386 | case PermissionsState.PERMISSION_OPERATION_SUCCESS_GIDS_CHANGED: { |
| 1387 | if (callback != null) { |
| 1388 | callback.onGidsChanged(UserHandle.getAppId(pkg.applicationInfo.uid), userId); |
| 1389 | } |
| 1390 | } |
| 1391 | break; |
| 1392 | } |
| 1393 | |
| 1394 | if (bp.isRuntime()) { |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1395 | logPermission(MetricsEvent.ACTION_PERMISSION_GRANTED, permName, packageName); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | if (callback != null) { |
| 1399 | callback.onPermissionGranted(uid, userId); |
| 1400 | } |
| 1401 | |
| 1402 | // Only need to do this if user is initialized. Otherwise it's a new user |
| 1403 | // and there are no processes running as the user yet and there's no need |
| 1404 | // to make an expensive call to remount processes for the changed permissions. |
| 1405 | if (READ_EXTERNAL_STORAGE.equals(permName) |
| 1406 | || WRITE_EXTERNAL_STORAGE.equals(permName)) { |
| 1407 | final long token = Binder.clearCallingIdentity(); |
| 1408 | try { |
| 1409 | if (mUserManagerInt.isUserInitialized(userId)) { |
| 1410 | StorageManagerInternal storageManagerInternal = LocalServices.getService( |
| 1411 | StorageManagerInternal.class); |
| 1412 | storageManagerInternal.onExternalStoragePolicyChanged(uid, packageName); |
| 1413 | } |
| 1414 | } finally { |
| 1415 | Binder.restoreCallingIdentity(token); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | } |
| 1420 | |
| 1421 | private void revokeRuntimePermission(String permName, String packageName, |
| 1422 | boolean overridePolicy, int callingUid, int userId, PermissionCallback callback) { |
| 1423 | if (!mUserManagerInt.exists(userId)) { |
| 1424 | Log.e(TAG, "No such user:" + userId); |
| 1425 | return; |
| 1426 | } |
| 1427 | |
| 1428 | mContext.enforceCallingOrSelfPermission( |
| 1429 | android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS, |
| 1430 | "revokeRuntimePermission"); |
| 1431 | |
| 1432 | enforceCrossUserPermission(Binder.getCallingUid(), userId, |
| 1433 | true /* requireFullPermission */, true /* checkShell */, |
| 1434 | "revokeRuntimePermission"); |
| 1435 | |
| 1436 | final int appId; |
| 1437 | |
| 1438 | final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName); |
| 1439 | if (pkg == null || pkg.mExtras == null) { |
| 1440 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 1441 | } |
| 1442 | if (mPackageManagerInt.filterAppAccess(pkg, Binder.getCallingUid(), userId)) { |
| 1443 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 1444 | } |
| 1445 | final BasePermission bp = mSettings.getPermissionLocked(permName); |
| 1446 | if (bp == null) { |
| 1447 | throw new IllegalArgumentException("Unknown permission: " + permName); |
| 1448 | } |
| 1449 | |
| 1450 | bp.enforceDeclaredUsedAndRuntimeOrDevelopment(pkg); |
| 1451 | |
| 1452 | // If a permission review is required for legacy apps we represent |
| 1453 | // their permissions as always granted runtime ones since we need |
| 1454 | // to keep the review required permission flag per user while an |
| 1455 | // install permission's state is shared across all users. |
| 1456 | if (mSettings.mPermissionReviewRequired |
| 1457 | && pkg.applicationInfo.targetSdkVersion < Build.VERSION_CODES.M |
| 1458 | && bp.isRuntime()) { |
| 1459 | return; |
| 1460 | } |
| 1461 | |
| 1462 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1463 | final PermissionsState permissionsState = ps.getPermissionsState(); |
| 1464 | |
| 1465 | final int flags = permissionsState.getPermissionFlags(permName, userId); |
| 1466 | if ((flags & PackageManager.FLAG_PERMISSION_SYSTEM_FIXED) != 0) { |
| 1467 | throw new SecurityException("Cannot revoke system fixed permission " |
| 1468 | + permName + " for package " + packageName); |
| 1469 | } |
| 1470 | if (!overridePolicy && (flags & PackageManager.FLAG_PERMISSION_POLICY_FIXED) != 0) { |
| 1471 | throw new SecurityException("Cannot revoke policy fixed permission " |
| 1472 | + permName + " for package " + packageName); |
| 1473 | } |
| 1474 | |
| 1475 | if (bp.isDevelopment()) { |
| 1476 | // Development permissions must be handled specially, since they are not |
| 1477 | // normal runtime permissions. For now they apply to all users. |
| 1478 | if (permissionsState.revokeInstallPermission(bp) != |
| 1479 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 1480 | if (callback != null) { |
| 1481 | callback.onInstallPermissionRevoked(); |
| 1482 | } |
| 1483 | } |
| 1484 | return; |
| 1485 | } |
| 1486 | |
| 1487 | if (permissionsState.revokeRuntimePermission(bp, userId) == |
| 1488 | PermissionsState.PERMISSION_OPERATION_FAILURE) { |
| 1489 | return; |
| 1490 | } |
| 1491 | |
| 1492 | if (bp.isRuntime()) { |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1493 | logPermission(MetricsEvent.ACTION_PERMISSION_REVOKED, permName, packageName); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | if (callback != null) { |
| 1497 | final int uid = UserHandle.getUid(userId, pkg.applicationInfo.uid); |
| 1498 | callback.onPermissionRevoked(pkg.applicationInfo.uid, userId); |
| 1499 | } |
| 1500 | } |
| 1501 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1502 | private int[] revokeUnusedSharedUserPermissionsLocked( |
| 1503 | SharedUserSetting suSetting, int[] allUserIds) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1504 | // Collect all used permissions in the UID |
| 1505 | final ArraySet<String> usedPermissions = new ArraySet<>(); |
| 1506 | final List<PackageParser.Package> pkgList = suSetting.getPackages(); |
| 1507 | if (pkgList == null || pkgList.size() == 0) { |
| 1508 | return EmptyArray.INT; |
| 1509 | } |
| 1510 | for (PackageParser.Package pkg : pkgList) { |
| 1511 | final int requestedPermCount = pkg.requestedPermissions.size(); |
| 1512 | for (int j = 0; j < requestedPermCount; j++) { |
| 1513 | String permission = pkg.requestedPermissions.get(j); |
| 1514 | BasePermission bp = mSettings.getPermissionLocked(permission); |
| 1515 | if (bp != null) { |
| 1516 | usedPermissions.add(permission); |
| 1517 | } |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | PermissionsState permissionsState = suSetting.getPermissionsState(); |
| 1522 | // Prune install permissions |
| 1523 | List<PermissionState> installPermStates = permissionsState.getInstallPermissionStates(); |
| 1524 | final int installPermCount = installPermStates.size(); |
| 1525 | for (int i = installPermCount - 1; i >= 0; i--) { |
| 1526 | PermissionState permissionState = installPermStates.get(i); |
| 1527 | if (!usedPermissions.contains(permissionState.getName())) { |
| 1528 | BasePermission bp = mSettings.getPermissionLocked(permissionState.getName()); |
| 1529 | if (bp != null) { |
| 1530 | permissionsState.revokeInstallPermission(bp); |
| 1531 | permissionsState.updatePermissionFlags(bp, UserHandle.USER_ALL, |
| 1532 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 1533 | } |
| 1534 | } |
| 1535 | } |
| 1536 | |
| 1537 | int[] runtimePermissionChangedUserIds = EmptyArray.INT; |
| 1538 | |
| 1539 | // Prune runtime permissions |
| 1540 | for (int userId : allUserIds) { |
| 1541 | List<PermissionState> runtimePermStates = permissionsState |
| 1542 | .getRuntimePermissionStates(userId); |
| 1543 | final int runtimePermCount = runtimePermStates.size(); |
| 1544 | for (int i = runtimePermCount - 1; i >= 0; i--) { |
| 1545 | PermissionState permissionState = runtimePermStates.get(i); |
| 1546 | if (!usedPermissions.contains(permissionState.getName())) { |
| 1547 | BasePermission bp = mSettings.getPermissionLocked(permissionState.getName()); |
| 1548 | if (bp != null) { |
| 1549 | permissionsState.revokeRuntimePermission(bp, userId); |
| 1550 | permissionsState.updatePermissionFlags(bp, userId, |
| 1551 | PackageManager.MASK_PERMISSION_FLAGS, 0); |
| 1552 | runtimePermissionChangedUserIds = ArrayUtils.appendInt( |
| 1553 | runtimePermissionChangedUserIds, userId); |
| 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | } |
| 1558 | |
| 1559 | return runtimePermissionChangedUserIds; |
| 1560 | } |
| 1561 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1562 | private String[] getAppOpPermissionPackages(String permName) { |
| 1563 | if (mPackageManagerInt.getInstantAppPackageName(Binder.getCallingUid()) != null) { |
| 1564 | return null; |
| 1565 | } |
| 1566 | synchronized (mLock) { |
| 1567 | final ArraySet<String> pkgs = mSettings.mAppOpPermissionPackages.get(permName); |
| 1568 | if (pkgs == null) { |
| 1569 | return null; |
| 1570 | } |
| 1571 | return pkgs.toArray(new String[pkgs.size()]); |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | private int getPermissionFlags( |
| 1576 | String permName, String packageName, int callingUid, int userId) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1577 | if (!mUserManagerInt.exists(userId)) { |
| 1578 | return 0; |
| 1579 | } |
| 1580 | |
| 1581 | enforceGrantRevokeRuntimePermissionPermissions("getPermissionFlags"); |
| 1582 | |
| 1583 | enforceCrossUserPermission(callingUid, userId, |
| 1584 | true /* requireFullPermission */, false /* checkShell */, |
| 1585 | "getPermissionFlags"); |
| 1586 | |
| 1587 | final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName); |
| 1588 | if (pkg == null || pkg.mExtras == null) { |
| 1589 | return 0; |
| 1590 | } |
| 1591 | synchronized (mLock) { |
| 1592 | if (mSettings.getPermissionLocked(permName) == null) { |
| 1593 | return 0; |
| 1594 | } |
| 1595 | } |
| 1596 | if (mPackageManagerInt.filterAppAccess(pkg, callingUid, userId)) { |
| 1597 | return 0; |
| 1598 | } |
| 1599 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1600 | PermissionsState permissionsState = ps.getPermissionsState(); |
| 1601 | return permissionsState.getPermissionFlags(permName, userId); |
| 1602 | } |
| 1603 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1604 | private static final int UPDATE_PERMISSIONS_ALL = 1<<0; |
| 1605 | private static final int UPDATE_PERMISSIONS_REPLACE_PKG = 1<<1; |
| 1606 | private static final int UPDATE_PERMISSIONS_REPLACE_ALL = 1<<2; |
| 1607 | |
| 1608 | private void updatePermissions(String packageName, PackageParser.Package pkg, |
| 1609 | boolean replaceGrant, Collection<PackageParser.Package> allPackages, |
| 1610 | PermissionCallback callback) { |
| 1611 | final int flags = (pkg != null ? UPDATE_PERMISSIONS_ALL : 0) | |
| 1612 | (replaceGrant ? UPDATE_PERMISSIONS_REPLACE_PKG : 0); |
| 1613 | updatePermissions( |
| 1614 | packageName, pkg, getVolumeUuidForPackage(pkg), flags, allPackages, callback); |
| 1615 | if (pkg != null && pkg.childPackages != null) { |
| 1616 | for (PackageParser.Package childPkg : pkg.childPackages) { |
| 1617 | updatePermissions(childPkg.packageName, childPkg, |
| 1618 | getVolumeUuidForPackage(childPkg), flags, allPackages, callback); |
| 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | private void updateAllPermissions(String volumeUuid, boolean sdkUpdated, |
| 1624 | Collection<PackageParser.Package> allPackages, PermissionCallback callback) { |
| 1625 | final int flags = UPDATE_PERMISSIONS_ALL | |
| 1626 | (sdkUpdated |
| 1627 | ? UPDATE_PERMISSIONS_REPLACE_PKG | UPDATE_PERMISSIONS_REPLACE_ALL |
| 1628 | : 0); |
| 1629 | updatePermissions(null, null, volumeUuid, flags, allPackages, callback); |
| 1630 | } |
| 1631 | |
| 1632 | private void updatePermissions(String changingPkgName, PackageParser.Package changingPkg, |
| 1633 | String replaceVolumeUuid, int flags, Collection<PackageParser.Package> allPackages, |
| 1634 | PermissionCallback callback) { |
| 1635 | // TODO: Most of the methods exposing BasePermission internals [source package name, |
| 1636 | // etc..] shouldn't be needed. Instead, when we've parsed a permission that doesn't |
| 1637 | // have package settings, we should make note of it elsewhere [map between |
| 1638 | // source package name and BasePermission] and cycle through that here. Then we |
| 1639 | // define a single method on BasePermission that takes a PackageSetting, changing |
| 1640 | // package name and a package. |
| 1641 | // NOTE: With this approach, we also don't need to tree trees differently than |
| 1642 | // normal permissions. Today, we need two separate loops because these BasePermission |
| 1643 | // objects are stored separately. |
| 1644 | // Make sure there are no dangling permission trees. |
| 1645 | flags = updatePermissionTrees(changingPkgName, changingPkg, flags); |
| 1646 | |
| 1647 | // Make sure all dynamic permissions have been assigned to a package, |
| 1648 | // and make sure there are no dangling permissions. |
| 1649 | flags = updatePermissions(changingPkgName, changingPkg, flags); |
| 1650 | |
| 1651 | Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "grantPermissions"); |
| 1652 | // Now update the permissions for all packages, in particular |
| 1653 | // replace the granted permissions of the system packages. |
| 1654 | if ((flags & UPDATE_PERMISSIONS_ALL) != 0) { |
| 1655 | for (PackageParser.Package pkg : allPackages) { |
| 1656 | if (pkg != changingPkg) { |
| 1657 | // Only replace for packages on requested volume |
| 1658 | final String volumeUuid = getVolumeUuidForPackage(pkg); |
| 1659 | final boolean replace = ((flags & UPDATE_PERMISSIONS_REPLACE_ALL) != 0) |
| 1660 | && Objects.equals(replaceVolumeUuid, volumeUuid); |
| 1661 | grantPermissions(pkg, replace, changingPkgName, callback); |
| 1662 | } |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | if (changingPkg != null) { |
| 1667 | // Only replace for packages on requested volume |
| 1668 | final String volumeUuid = getVolumeUuidForPackage(changingPkg); |
| 1669 | final boolean replace = ((flags & UPDATE_PERMISSIONS_REPLACE_PKG) != 0) |
| 1670 | && Objects.equals(replaceVolumeUuid, volumeUuid); |
| 1671 | grantPermissions(changingPkg, replace, changingPkgName, callback); |
| 1672 | } |
| 1673 | Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); |
| 1674 | } |
| 1675 | |
| 1676 | private int updatePermissions(String packageName, PackageParser.Package pkg, int flags) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1677 | Set<BasePermission> needsUpdate = null; |
| 1678 | synchronized (mLock) { |
| 1679 | final Iterator<BasePermission> it = mSettings.mPermissions.values().iterator(); |
| 1680 | while (it.hasNext()) { |
| 1681 | final BasePermission bp = it.next(); |
| 1682 | if (bp.isDynamic()) { |
| 1683 | bp.updateDynamicPermission(mSettings.mPermissionTrees.values()); |
| 1684 | } |
| 1685 | if (bp.getSourcePackageSetting() != null) { |
| 1686 | if (packageName != null && packageName.equals(bp.getSourcePackageName()) |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1687 | && (pkg == null || !hasPermission(pkg, bp.getName()))) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1688 | Slog.i(TAG, "Removing old permission tree: " + bp.getName() |
| 1689 | + " from package " + bp.getSourcePackageName()); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1690 | flags |= UPDATE_PERMISSIONS_ALL; |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1691 | it.remove(); |
| 1692 | } |
| 1693 | continue; |
| 1694 | } |
| 1695 | if (needsUpdate == null) { |
| 1696 | needsUpdate = new ArraySet<>(mSettings.mPermissions.size()); |
| 1697 | } |
| 1698 | needsUpdate.add(bp); |
| 1699 | } |
| 1700 | } |
| 1701 | if (needsUpdate != null) { |
| 1702 | for (final BasePermission bp : needsUpdate) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1703 | final PackageParser.Package sourcePkg = |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1704 | mPackageManagerInt.getPackage(bp.getSourcePackageName()); |
| 1705 | synchronized (mLock) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1706 | if (sourcePkg != null && sourcePkg.mExtras != null) { |
| 1707 | final PackageSetting sourcePs = (PackageSetting) sourcePkg.mExtras; |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1708 | if (bp.getSourcePackageSetting() == null) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1709 | bp.setSourcePackageSetting(sourcePs); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1710 | } |
| 1711 | continue; |
| 1712 | } |
| 1713 | Slog.w(TAG, "Removing dangling permission: " + bp.getName() |
| 1714 | + " from package " + bp.getSourcePackageName()); |
| 1715 | mSettings.removePermissionLocked(bp.getName()); |
| 1716 | } |
| 1717 | } |
| 1718 | } |
| 1719 | return flags; |
| 1720 | } |
| 1721 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1722 | private int updatePermissionTrees(String packageName, PackageParser.Package pkg, |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1723 | int flags) { |
| 1724 | Set<BasePermission> needsUpdate = null; |
| 1725 | synchronized (mLock) { |
| 1726 | final Iterator<BasePermission> it = mSettings.mPermissionTrees.values().iterator(); |
| 1727 | while (it.hasNext()) { |
| 1728 | final BasePermission bp = it.next(); |
| 1729 | if (bp.getSourcePackageSetting() != null) { |
| 1730 | if (packageName != null && packageName.equals(bp.getSourcePackageName()) |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1731 | && (pkg == null || !hasPermission(pkg, bp.getName()))) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1732 | Slog.i(TAG, "Removing old permission tree: " + bp.getName() |
| 1733 | + " from package " + bp.getSourcePackageName()); |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1734 | flags |= UPDATE_PERMISSIONS_ALL; |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1735 | it.remove(); |
| 1736 | } |
| 1737 | continue; |
| 1738 | } |
| 1739 | if (needsUpdate == null) { |
| 1740 | needsUpdate = new ArraySet<>(mSettings.mPermissionTrees.size()); |
| 1741 | } |
| 1742 | needsUpdate.add(bp); |
| 1743 | } |
| 1744 | } |
| 1745 | if (needsUpdate != null) { |
| 1746 | for (final BasePermission bp : needsUpdate) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1747 | final PackageParser.Package sourcePkg = |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1748 | mPackageManagerInt.getPackage(bp.getSourcePackageName()); |
| 1749 | synchronized (mLock) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1750 | if (sourcePkg != null && sourcePkg.mExtras != null) { |
| 1751 | final PackageSetting sourcePs = (PackageSetting) sourcePkg.mExtras; |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1752 | if (bp.getSourcePackageSetting() == null) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1753 | bp.setSourcePackageSetting(sourcePs); |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1754 | } |
| 1755 | continue; |
| 1756 | } |
| 1757 | Slog.w(TAG, "Removing dangling permission tree: " + bp.getName() |
| 1758 | + " from package " + bp.getSourcePackageName()); |
| 1759 | mSettings.removePermissionLocked(bp.getName()); |
| 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | return flags; |
| 1764 | } |
| 1765 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1766 | private void updatePermissionFlags(String permName, String packageName, int flagMask, |
| 1767 | int flagValues, int callingUid, int userId, PermissionCallback callback) { |
| 1768 | if (!mUserManagerInt.exists(userId)) { |
| 1769 | return; |
| 1770 | } |
| 1771 | |
| 1772 | enforceGrantRevokeRuntimePermissionPermissions("updatePermissionFlags"); |
| 1773 | |
| 1774 | enforceCrossUserPermission(callingUid, userId, |
| 1775 | true /* requireFullPermission */, true /* checkShell */, |
| 1776 | "updatePermissionFlags"); |
| 1777 | |
| 1778 | // Only the system can change these flags and nothing else. |
| 1779 | if (callingUid != Process.SYSTEM_UID) { |
| 1780 | flagMask &= ~PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
| 1781 | flagValues &= ~PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
| 1782 | flagMask &= ~PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT; |
| 1783 | flagValues &= ~PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT; |
| 1784 | flagValues &= ~PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED; |
| 1785 | } |
| 1786 | |
| 1787 | final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName); |
| 1788 | if (pkg == null || pkg.mExtras == null) { |
| 1789 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 1790 | } |
| 1791 | if (mPackageManagerInt.filterAppAccess(pkg, callingUid, userId)) { |
| 1792 | throw new IllegalArgumentException("Unknown package: " + packageName); |
| 1793 | } |
| 1794 | |
| 1795 | final BasePermission bp; |
| 1796 | synchronized (mLock) { |
| 1797 | bp = mSettings.getPermissionLocked(permName); |
| 1798 | } |
| 1799 | if (bp == null) { |
| 1800 | throw new IllegalArgumentException("Unknown permission: " + permName); |
| 1801 | } |
| 1802 | |
| 1803 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1804 | final PermissionsState permissionsState = ps.getPermissionsState(); |
| 1805 | final boolean hadState = |
| 1806 | permissionsState.getRuntimePermissionState(permName, userId) != null; |
| 1807 | final boolean permissionUpdated = |
| 1808 | permissionsState.updatePermissionFlags(bp, userId, flagMask, flagValues); |
| 1809 | if (permissionUpdated && callback != null) { |
| 1810 | // Install and runtime permissions are stored in different places, |
| 1811 | // so figure out what permission changed and persist the change. |
| 1812 | if (permissionsState.getInstallPermissionState(permName) != null) { |
| 1813 | callback.onInstallPermissionUpdated(); |
| 1814 | } else if (permissionsState.getRuntimePermissionState(permName, userId) != null |
| 1815 | || hadState) { |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1816 | callback.onPermissionUpdated(new int[] { userId }, false); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | private boolean updatePermissionFlagsForAllApps(int flagMask, int flagValues, int callingUid, |
| 1822 | int userId, Collection<Package> packages, PermissionCallback callback) { |
| 1823 | if (!mUserManagerInt.exists(userId)) { |
| 1824 | return false; |
| 1825 | } |
| 1826 | |
| 1827 | enforceGrantRevokeRuntimePermissionPermissions( |
| 1828 | "updatePermissionFlagsForAllApps"); |
| 1829 | enforceCrossUserPermission(callingUid, userId, |
| 1830 | true /* requireFullPermission */, true /* checkShell */, |
| 1831 | "updatePermissionFlagsForAllApps"); |
| 1832 | |
| 1833 | // Only the system can change system fixed flags. |
| 1834 | if (callingUid != Process.SYSTEM_UID) { |
| 1835 | flagMask &= ~PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
| 1836 | flagValues &= ~PackageManager.FLAG_PERMISSION_SYSTEM_FIXED; |
| 1837 | } |
| 1838 | |
| 1839 | boolean changed = false; |
| 1840 | for (PackageParser.Package pkg : packages) { |
| 1841 | final PackageSetting ps = (PackageSetting) pkg.mExtras; |
| 1842 | if (ps == null) { |
| 1843 | continue; |
| 1844 | } |
| 1845 | PermissionsState permissionsState = ps.getPermissionsState(); |
| 1846 | changed |= permissionsState.updatePermissionFlagsForAllPermissions( |
| 1847 | userId, flagMask, flagValues); |
| 1848 | } |
| 1849 | return changed; |
| 1850 | } |
| 1851 | |
| 1852 | private void enforceGrantRevokeRuntimePermissionPermissions(String message) { |
| 1853 | if (mContext.checkCallingOrSelfPermission(Manifest.permission.GRANT_RUNTIME_PERMISSIONS) |
| 1854 | != PackageManager.PERMISSION_GRANTED |
| 1855 | && mContext.checkCallingOrSelfPermission(Manifest.permission.REVOKE_RUNTIME_PERMISSIONS) |
| 1856 | != PackageManager.PERMISSION_GRANTED) { |
| 1857 | throw new SecurityException(message + " requires " |
| 1858 | + Manifest.permission.GRANT_RUNTIME_PERMISSIONS + " or " |
| 1859 | + Manifest.permission.REVOKE_RUNTIME_PERMISSIONS); |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | /** |
| 1864 | * Checks if the request is from the system or an app that has INTERACT_ACROSS_USERS |
| 1865 | * or INTERACT_ACROSS_USERS_FULL permissions, if the userid is not for the caller. |
| 1866 | * @param checkShell whether to prevent shell from access if there's a debugging restriction |
| 1867 | * @param message the message to log on security exception |
| 1868 | */ |
| 1869 | private void enforceCrossUserPermission(int callingUid, int userId, |
| 1870 | boolean requireFullPermission, boolean checkShell, String message) { |
| 1871 | if (userId < 0) { |
| 1872 | throw new IllegalArgumentException("Invalid userId " + userId); |
| 1873 | } |
| 1874 | if (checkShell) { |
| 1875 | PackageManagerServiceUtils.enforceShellRestriction( |
| 1876 | UserManager.DISALLOW_DEBUGGING_FEATURES, callingUid, userId); |
| 1877 | } |
| 1878 | if (userId == UserHandle.getUserId(callingUid)) return; |
| 1879 | if (callingUid != Process.SYSTEM_UID && callingUid != 0) { |
| 1880 | if (requireFullPermission) { |
| 1881 | mContext.enforceCallingOrSelfPermission( |
| 1882 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, message); |
| 1883 | } else { |
| 1884 | try { |
| 1885 | mContext.enforceCallingOrSelfPermission( |
| 1886 | android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, message); |
| 1887 | } catch (SecurityException se) { |
| 1888 | mContext.enforceCallingOrSelfPermission( |
| 1889 | android.Manifest.permission.INTERACT_ACROSS_USERS, message); |
| 1890 | } |
| 1891 | } |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | private int calculateCurrentPermissionFootprintLocked(BasePermission tree) { |
| 1896 | int size = 0; |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1897 | for (BasePermission perm : mSettings.mPermissions.values()) { |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1898 | size += tree.calculateFootprint(perm); |
| 1899 | } |
| 1900 | return size; |
| 1901 | } |
| 1902 | |
| 1903 | private void enforcePermissionCapLocked(PermissionInfo info, BasePermission tree) { |
| 1904 | // We calculate the max size of permissions defined by this uid and throw |
| 1905 | // if that plus the size of 'info' would exceed our stated maximum. |
| 1906 | if (tree.getUid() != Process.SYSTEM_UID) { |
| 1907 | final int curTreeSize = calculateCurrentPermissionFootprintLocked(tree); |
| 1908 | if (curTreeSize + info.calculateFootprint() > MAX_PERMISSION_TREE_FOOTPRINT) { |
| 1909 | throw new SecurityException("Permission tree size cap exceeded"); |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1914 | private void systemReady() { |
| 1915 | mSystemReady = true; |
| 1916 | if (mPrivappPermissionsViolations != null) { |
| 1917 | throw new IllegalStateException("Signature|privileged permissions not in " |
| 1918 | + "privapp-permissions whitelist: " + mPrivappPermissionsViolations); |
| 1919 | } |
| 1920 | } |
| 1921 | |
| 1922 | private static String getVolumeUuidForPackage(PackageParser.Package pkg) { |
| 1923 | if (pkg == null) { |
| 1924 | return StorageManager.UUID_PRIVATE_INTERNAL; |
| 1925 | } |
| 1926 | if (pkg.isExternal()) { |
| 1927 | if (TextUtils.isEmpty(pkg.volumeUuid)) { |
| 1928 | return StorageManager.UUID_PRIMARY_PHYSICAL; |
| 1929 | } else { |
| 1930 | return pkg.volumeUuid; |
| 1931 | } |
| 1932 | } else { |
| 1933 | return StorageManager.UUID_PRIVATE_INTERNAL; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1937 | private static boolean hasPermission(PackageParser.Package pkgInfo, String permName) { |
| 1938 | for (int i=pkgInfo.permissions.size()-1; i>=0; i--) { |
| 1939 | if (pkgInfo.permissions.get(i).info.name.equals(permName)) { |
| 1940 | return true; |
| 1941 | } |
| 1942 | } |
| 1943 | return false; |
| 1944 | } |
| 1945 | |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1946 | /** |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1947 | * Log that a permission request was granted/revoked. |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1948 | * |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1949 | * @param action the action performed |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1950 | * @param name name of the permission |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1951 | * @param packageName package permission is for |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1952 | */ |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1953 | private void logPermission(int action, @NonNull String name, @NonNull String packageName) { |
| 1954 | final LogMaker log = new LogMaker(action); |
| 1955 | log.setPackageName(packageName); |
| 1956 | log.addTaggedData(MetricsEvent.FIELD_PERMISSION, name); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1957 | |
Philip P. Moltmann | 8cff8b9 | 2017-10-25 14:32:41 -0700 | [diff] [blame] | 1958 | mMetricsLogger.write(log); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | private class PermissionManagerInternalImpl extends PermissionManagerInternal { |
| 1962 | @Override |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 1963 | public void systemReady() { |
| 1964 | PermissionManagerService.this.systemReady(); |
| 1965 | } |
| 1966 | @Override |
| 1967 | public boolean isPermissionsReviewRequired(Package pkg, int userId) { |
| 1968 | return PermissionManagerService.this.isPermissionsReviewRequired(pkg, userId); |
| 1969 | } |
| 1970 | @Override |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1971 | public void addAllPermissions(Package pkg, boolean chatty) { |
| 1972 | PermissionManagerService.this.addAllPermissions(pkg, chatty); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1973 | } |
| 1974 | @Override |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 1975 | public void addAllPermissionGroups(Package pkg, boolean chatty) { |
| 1976 | PermissionManagerService.this.addAllPermissionGroups(pkg, chatty); |
| 1977 | } |
| 1978 | @Override |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1979 | public void removeAllPermissions(Package pkg, boolean chatty) { |
| 1980 | PermissionManagerService.this.removeAllPermissions(pkg, chatty); |
| 1981 | } |
| 1982 | @Override |
| 1983 | public boolean addDynamicPermission(PermissionInfo info, boolean async, int callingUid, |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1984 | PermissionCallback callback) { |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 1985 | return PermissionManagerService.this.addDynamicPermission(info, callingUid, callback); |
| 1986 | } |
| 1987 | @Override |
| 1988 | public void removeDynamicPermission(String permName, int callingUid, |
| 1989 | PermissionCallback callback) { |
| 1990 | PermissionManagerService.this.removeDynamicPermission(permName, callingUid, callback); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 1991 | } |
| 1992 | @Override |
| 1993 | public void grantRuntimePermission(String permName, String packageName, |
| 1994 | boolean overridePolicy, int callingUid, int userId, |
| 1995 | PermissionCallback callback) { |
| 1996 | PermissionManagerService.this.grantRuntimePermission( |
| 1997 | permName, packageName, overridePolicy, callingUid, userId, callback); |
| 1998 | } |
| 1999 | @Override |
| 2000 | public void grantRequestedRuntimePermissions(PackageParser.Package pkg, int[] userIds, |
| 2001 | String[] grantedPermissions, int callingUid, PermissionCallback callback) { |
| 2002 | PermissionManagerService.this.grantRequestedRuntimePermissions( |
| 2003 | pkg, userIds, grantedPermissions, callingUid, callback); |
| 2004 | } |
| 2005 | @Override |
| 2006 | public void grantRuntimePermissionsGrantedToDisabledPackage(PackageParser.Package pkg, |
| 2007 | int callingUid, PermissionCallback callback) { |
| 2008 | PermissionManagerService.this.grantRuntimePermissionsGrantedToDisabledPackageLocked( |
| 2009 | pkg, callingUid, callback); |
| 2010 | } |
| 2011 | @Override |
| 2012 | public void revokeRuntimePermission(String permName, String packageName, |
| 2013 | boolean overridePolicy, int callingUid, int userId, |
| 2014 | PermissionCallback callback) { |
| 2015 | PermissionManagerService.this.revokeRuntimePermission(permName, packageName, |
| 2016 | overridePolicy, callingUid, userId, callback); |
| 2017 | } |
| 2018 | @Override |
Todd Kennedy | c29b11a | 2017-10-23 15:55:59 -0700 | [diff] [blame] | 2019 | public void updatePermissions(String packageName, Package pkg, boolean replaceGrant, |
| 2020 | Collection<PackageParser.Package> allPackages, PermissionCallback callback) { |
| 2021 | PermissionManagerService.this.updatePermissions( |
| 2022 | packageName, pkg, replaceGrant, allPackages, callback); |
| 2023 | } |
| 2024 | @Override |
| 2025 | public void updateAllPermissions(String volumeUuid, boolean sdkUpdated, |
| 2026 | Collection<PackageParser.Package> allPackages, PermissionCallback callback) { |
| 2027 | PermissionManagerService.this.updateAllPermissions( |
| 2028 | volumeUuid, sdkUpdated, allPackages, callback); |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2029 | } |
| 2030 | @Override |
Todd Kennedy | c842393 | 2017-10-05 08:58:36 -0700 | [diff] [blame] | 2031 | public String[] getAppOpPermissionPackages(String permName) { |
| 2032 | return PermissionManagerService.this.getAppOpPermissionPackages(permName); |
| 2033 | } |
| 2034 | @Override |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2035 | public int getPermissionFlags(String permName, String packageName, int callingUid, |
| 2036 | int userId) { |
| 2037 | return PermissionManagerService.this.getPermissionFlags(permName, packageName, |
| 2038 | callingUid, userId); |
| 2039 | } |
| 2040 | @Override |
| 2041 | public void updatePermissionFlags(String permName, String packageName, int flagMask, |
| 2042 | int flagValues, int callingUid, int userId, PermissionCallback callback) { |
| 2043 | PermissionManagerService.this.updatePermissionFlags( |
| 2044 | permName, packageName, flagMask, flagValues, callingUid, userId, callback); |
| 2045 | } |
| 2046 | @Override |
| 2047 | public boolean updatePermissionFlagsForAllApps(int flagMask, int flagValues, int callingUid, |
| 2048 | int userId, Collection<Package> packages, PermissionCallback callback) { |
| 2049 | return PermissionManagerService.this.updatePermissionFlagsForAllApps( |
| 2050 | flagMask, flagValues, callingUid, userId, packages, callback); |
| 2051 | } |
| 2052 | @Override |
| 2053 | public void enforceCrossUserPermission(int callingUid, int userId, |
| 2054 | boolean requireFullPermission, boolean checkShell, String message) { |
| 2055 | PermissionManagerService.this.enforceCrossUserPermission(callingUid, userId, |
| 2056 | requireFullPermission, checkShell, message); |
| 2057 | } |
| 2058 | @Override |
| 2059 | public void enforceGrantRevokeRuntimePermissionPermissions(String message) { |
| 2060 | PermissionManagerService.this.enforceGrantRevokeRuntimePermissionPermissions(message); |
| 2061 | } |
| 2062 | @Override |
| 2063 | public int checkPermission(String permName, String packageName, int callingUid, |
| 2064 | int userId) { |
| 2065 | return PermissionManagerService.this.checkPermission( |
| 2066 | permName, packageName, callingUid, userId); |
| 2067 | } |
| 2068 | @Override |
Todd Kennedy | 3bc9472 | 2017-10-10 09:55:53 -0700 | [diff] [blame] | 2069 | public int checkUidPermission(String permName, int uid, int callingUid) { |
| 2070 | return PermissionManagerService.this.checkUidPermission(permName, uid, callingUid); |
| 2071 | } |
| 2072 | @Override |
Todd Kennedy | 460f28c | 2017-10-06 13:46:22 -0700 | [diff] [blame] | 2073 | public PermissionGroupInfo getPermissionGroupInfo(String groupName, int flags, |
| 2074 | int callingUid) { |
| 2075 | return PermissionManagerService.this.getPermissionGroupInfo( |
| 2076 | groupName, flags, callingUid); |
| 2077 | } |
| 2078 | @Override |
| 2079 | public List<PermissionGroupInfo> getAllPermissionGroups(int flags, int callingUid) { |
| 2080 | return PermissionManagerService.this.getAllPermissionGroups(flags, callingUid); |
| 2081 | } |
| 2082 | @Override |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2083 | public PermissionInfo getPermissionInfo(String permName, String packageName, int flags, |
| 2084 | int callingUid) { |
| 2085 | return PermissionManagerService.this.getPermissionInfo( |
| 2086 | permName, packageName, flags, callingUid); |
| 2087 | } |
| 2088 | @Override |
| 2089 | public List<PermissionInfo> getPermissionInfoByGroup(String group, int flags, |
| 2090 | int callingUid) { |
| 2091 | return PermissionManagerService.this.getPermissionInfoByGroup(group, flags, callingUid); |
| 2092 | } |
| 2093 | @Override |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2094 | public PermissionSettings getPermissionSettings() { |
| 2095 | return mSettings; |
| 2096 | } |
| 2097 | @Override |
| 2098 | public DefaultPermissionGrantPolicy getDefaultPermissionGrantPolicy() { |
| 2099 | return mDefaultPermissionGrantPolicy; |
| 2100 | } |
| 2101 | @Override |
| 2102 | public BasePermission getPermissionTEMP(String permName) { |
| 2103 | synchronized (PermissionManagerService.this.mLock) { |
| 2104 | return mSettings.getPermissionLocked(permName); |
| 2105 | } |
| 2106 | } |
Todd Kennedy | 0eb9738 | 2017-10-03 16:57:22 -0700 | [diff] [blame] | 2107 | } |
| 2108 | } |