Prevent crash on uninstall.

- Crash due to race between package removal and permission revocation.
- Catch exception thrown by packagemanager.
- Improve documentation of packagemanager methods.

Bug: 32247014
Change-Id: Ie548c385e9e86418e7c4b87c571beebfcaeff353
This commit is contained in:
Ruben Brunk
2016-11-10 15:27:30 -08:00
parent bbc8d1d6ec
commit 12ab5e1d70
2 changed files with 20 additions and 6 deletions

View File

@@ -3291,7 +3291,8 @@ public abstract class PackageManager {
* Grant a runtime permission to an application which the application does not
* already have. The permission must have been requested by the application.
* If the application is not allowed to hold the permission, a {@link
* java.lang.SecurityException} is thrown.
* java.lang.SecurityException} is thrown. If the package or permission is
* invalid, a {@link java.lang.IllegalArgumentException} is thrown.
* <p>
* <strong>Note: </strong>Using this API requires holding
* android.permission.GRANT_REVOKE_PERMISSIONS and if the user id is
@@ -3316,7 +3317,8 @@ public abstract class PackageManager {
* #grantRuntimePermission(String, String, android.os.UserHandle)}. The
* permission must have been requested by and granted to the application.
* If the application is not allowed to hold the permission, a {@link
* java.lang.SecurityException} is thrown.
* java.lang.SecurityException} is thrown. If the package or permission is
* invalid, a {@link java.lang.IllegalArgumentException} is thrown.
* <p>
* <strong>Note: </strong>Using this API requires holding
* android.permission.GRANT_REVOKE_PERMISSIONS and if the user id is

View File

@@ -663,16 +663,28 @@ public class VrManagerService extends SystemService implements EnabledComponentC
private void grantCoarseLocationPermissionIfNeeded(String pkg, int userId) {
// Don't clobber the user if permission set in current state explicitly
if (!isPermissionUserUpdated(Manifest.permission.ACCESS_COARSE_LOCATION, pkg, userId)) {
mContext.getPackageManager().grantRuntimePermission(pkg,
Manifest.permission.ACCESS_COARSE_LOCATION, new UserHandle(userId));
try {
mContext.getPackageManager().grantRuntimePermission(pkg,
Manifest.permission.ACCESS_COARSE_LOCATION, new UserHandle(userId));
} catch (IllegalArgumentException e) {
// Package was removed during update.
Slog.w(TAG, "Could not grant coarse location permission, package " + pkg
+ " was removed.");
}
}
}
private void revokeCoarseLocationPermissionIfNeeded(String pkg, int userId) {
// Don't clobber the user if permission set in current state explicitly
if (!isPermissionUserUpdated(Manifest.permission.ACCESS_COARSE_LOCATION, pkg, userId)) {
mContext.getPackageManager().revokeRuntimePermission(pkg,
Manifest.permission.ACCESS_COARSE_LOCATION, new UserHandle(userId));
try {
mContext.getPackageManager().revokeRuntimePermission(pkg,
Manifest.permission.ACCESS_COARSE_LOCATION, new UserHandle(userId));
} catch (IllegalArgumentException e) {
// Package was removed during update.
Slog.w(TAG, "Could not revoke coarse location permission, package " + pkg
+ " was removed.");
}
}
}