Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d71c0ce3 authored by Rubin Xu's avatar Rubin Xu
Browse files

device policy: ignore unknown permission in setPermissionGrantState

When setting a permission grant on a non-existent permission,
implementation currently throws RemoteException but that's not
propagated across binder causing the client cide to stuck until
the timeout. Replace this with an immediate fail.

Bug: 197200931
Test: manual with TestDPC
Change-Id: I9a0ea42e52d68259eb0464194a5a1d9fbfc2a216
parent 10337fae
Loading
Loading
Loading
Loading
+12 −14
Original line number Diff line number Diff line
@@ -13986,16 +13986,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                        return;
                    }
                }
                try {
                if (!isRuntimePermission(permission)) {
                    callback.sendResult(null);
                    return;
                }
                } catch (NameNotFoundException e) {
                    throw new RemoteException("Cannot check if " + permission
                            + "is a runtime permission", e, false, true);
                }
                if (grantState == DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED
                        || grantState == DevicePolicyManager.PERMISSION_GRANT_STATE_DENIED
                        || grantState == DevicePolicyManager.PERMISSION_GRANT_STATE_DEFAULT) {
@@ -14108,11 +14102,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        });
    }
    public boolean isRuntimePermission(String permissionName) throws NameNotFoundException {
    private boolean isRuntimePermission(String permissionName) {
        try {
            final PackageManager packageManager = mInjector.getPackageManager();
            PermissionInfo permissionInfo = packageManager.getPermissionInfo(permissionName, 0);
            return (permissionInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
                    == PermissionInfo.PROTECTION_DANGEROUS;
        } catch (NameNotFoundException e) {
            return false;
        }
    }
    @Override