Fix install permission revocation upon source package uninstallation.

The revocation should only be done when the source package is completely
removed, instead of only being marked as uninstalled for certain users.
However, the original code would erroneously take a null pkg parameter
as the package is gone instead of its original meaning that all packages
need to be updated. So simply drop that parameter and get the pkg from
package manager to see if the package is really being completely
removed.

Bug: 206047992
Test: atest RemovePermissionTest
Change-Id: Iabbf045a87cb00b4c27d562ff126570f385f64c1
This commit is contained in:
Hai Zhang
2021-11-16 11:09:24 +00:00
parent 9e816cb183
commit 0b43aa9cd9

View File

@@ -4205,7 +4205,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
// Make sure all dynamic permissions have been assigned to a package,
// and make sure there are no dangling permissions.
boolean permissionSourcePackageChanged = updatePermissionSourcePackage(changingPkgName,
changingPkg, callback);
callback);
if (permissionTreesSourcePackageChanged | permissionSourcePackageChanged) {
// Permission ownership has changed. This e.g. changes which packages can get signature
@@ -4244,22 +4244,12 @@ public class PermissionManagerService extends IPermissionManager.Stub {
/**
* Update which app declares a permission.
*
* <p>Possible parameter combinations
* <table>
* <tr><th></th><th>packageName != null</th><th>packageName == null</th></tr>
* <tr><th>pkg != null</th><td>package is updated</td><td>invalid</td></tr>
* <tr><th>pkg == null</th><td>package is deleted</td><td>all packages are updated</td></tr>
* </table>
*
* @param packageName The package that is updated, or {@code null} if all packages should be
* updated
* @param pkg The package that is updated, or {@code null} if all packages should be updated or
* package is deleted
*
* @return {@code true} if a permission source package might have changed
*/
private boolean updatePermissionSourcePackage(@Nullable String packageName,
@Nullable AndroidPackage pkg,
final @Nullable PermissionCallback callback) {
// Always need update if packageName is null
if (packageName == null) {
@@ -4289,6 +4279,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
}
}
if (needsUpdate != null) {
final AndroidPackage pkg = mPackageManagerInt.getPackage(packageName);
for (final Permission bp : needsUpdate) {
// If the target package is being uninstalled, we need to revoke this permission
// From all other packages