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

Commit c5b0e860 authored by Todd Kennedy's avatar Todd Kennedy
Browse files

Move few remaining permission methods

This should be the last method movement. More work needs to
happen with the intenral APIs between the permission manager
and the package manager. There is still a lot of package
manager internal logic inside the permission manager.

Bug: 135279435
Test: atest PermissionUpdateListenerTest
Test: atest android.content.pm.cts.PackageManagerTest
Test: atest android.permission2.cts.RestrictedPermissionsTest
Change-Id: Iec118d198cb4ce3c4789991ddbdd2928dbc4bf6f
parent 583378df
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -635,7 +635,7 @@ public class ApplicationPackageManager extends PackageManager {
    @Override
    @Override
    public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
    public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
        try {
        try {
            return mPM.isPermissionRevokedByPolicy(permName, pkgName, getUserId());
            return mPermissionManager.isPermissionRevokedByPolicy(permName, pkgName, getUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -795,10 +795,11 @@ public class ApplicationPackageManager extends PackageManager {


    @Override
    @Override
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public boolean shouldShowRequestPermissionRationale(String permission) {
    public boolean shouldShowRequestPermissionRationale(String permName) {
        try {
        try {
            return mPM.shouldShowRequestPermissionRationale(permission,
            final String packageName = mContext.getPackageName();
                    mContext.getPackageName(), getUserId());
            return mPermissionManager
                    .shouldShowRequestPermissionRationale(permName, packageName, getUserId());
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+0 −7
Original line number Original line Diff line number Diff line
@@ -94,8 +94,6 @@ interface IPackageManager {


    @UnsupportedAppUsage
    @UnsupportedAppUsage
    ProviderInfo getProviderInfo(in ComponentName className, int flags, int userId);
    ProviderInfo getProviderInfo(in ComponentName className, int flags, int userId);
    boolean shouldShowRequestPermissionRationale(String permName,
            String packageName, int userId);


    boolean isProtectedBroadcast(String actionName);
    boolean isProtectedBroadcast(String actionName);


@@ -600,9 +598,6 @@ interface IPackageManager {
    boolean isOnlyCoreApps();
    boolean isOnlyCoreApps();
    boolean isDeviceUpgrading();
    boolean isDeviceUpgrading();


    void setPermissionEnforced(String permission, boolean enforced);
    boolean isPermissionEnforced(String permission);

    /** Reflects current DeviceStorageMonitorService state */
    /** Reflects current DeviceStorageMonitorService state */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    boolean isStorageLow();
    boolean isStorageLow();
@@ -626,8 +621,6 @@ interface IPackageManager {
    boolean isPackageSignedByKeySet(String packageName, in KeySet ks);
    boolean isPackageSignedByKeySet(String packageName, in KeySet ks);
    boolean isPackageSignedByKeySetExactly(String packageName, in KeySet ks);
    boolean isPackageSignedByKeySetExactly(String packageName, in KeySet ks);


    boolean isPermissionRevokedByPolicy(String permission, String packageName, int userId);

    @UnsupportedAppUsage
    @UnsupportedAppUsage
    String getPermissionControllerPackageName();
    String getPermissionControllerPackageName();


+24 −24
Original line number Original line Diff line number Diff line
@@ -3571,7 +3571,7 @@ public abstract class PackageManager {
    /**
    /**
     * Retrieve all of the information we know about a particular permission.
     * Retrieve all of the information we know about a particular permission.
     *
     *
     * @param permissionName The fully qualified name (i.e. com.google.permission.LOGIN)
     * @param permName The fully qualified name (i.e. com.google.permission.LOGIN)
     *            of the permission you are interested in.
     *            of the permission you are interested in.
     * @param flags Additional option flags to modify the data returned.
     * @param flags Additional option flags to modify the data returned.
     * @return Returns a {@link PermissionInfo} containing information about the
     * @return Returns a {@link PermissionInfo} containing information about the
@@ -3579,7 +3579,7 @@ public abstract class PackageManager {
     * @throws NameNotFoundException if a package with the given name cannot be
     * @throws NameNotFoundException if a package with the given name cannot be
     *             found on the system.
     *             found on the system.
     */
     */
    public abstract PermissionInfo getPermissionInfo(@NonNull String permissionName,
    public abstract PermissionInfo getPermissionInfo(@NonNull String permName,
            @PermissionInfoFlags int flags) throws NameNotFoundException;
            @PermissionInfoFlags int flags) throws NameNotFoundException;


    /**
    /**
@@ -3620,7 +3620,7 @@ public abstract class PackageManager {
     * Retrieve all of the information we know about a particular group of
     * Retrieve all of the information we know about a particular group of
     * permissions.
     * permissions.
     *
     *
     * @param permissionName The fully qualified name (i.e.
     * @param permName The fully qualified name (i.e.
     *            com.google.permission_group.APPS) of the permission you are
     *            com.google.permission_group.APPS) of the permission you are
     *            interested in.
     *            interested in.
     * @param flags Additional option flags to modify the data returned.
     * @param flags Additional option flags to modify the data returned.
@@ -3630,7 +3630,7 @@ public abstract class PackageManager {
     *             found on the system.
     *             found on the system.
     */
     */
    @NonNull
    @NonNull
    public abstract PermissionGroupInfo getPermissionGroupInfo(@NonNull String permissionName,
    public abstract PermissionGroupInfo getPermissionGroupInfo(@NonNull String permName,
            @PermissionGroupInfoFlags int flags) throws NameNotFoundException;
            @PermissionGroupInfoFlags int flags) throws NameNotFoundException;


    /**
    /**
@@ -3858,7 +3858,7 @@ public abstract class PackageManager {
     * Check whether a particular package has been granted a particular
     * Check whether a particular package has been granted a particular
     * permission.
     * permission.
     *
     *
     * @param permissionName The name of the permission you are checking for.
     * @param permName The name of the permission you are checking for.
     * @param packageName The name of the package you are checking against.
     * @param packageName The name of the package you are checking against.
     *
     *
     * @return If the package has the permission, PERMISSION_GRANTED is
     * @return If the package has the permission, PERMISSION_GRANTED is
@@ -3870,7 +3870,7 @@ public abstract class PackageManager {
     */
     */
    @CheckResult
    @CheckResult
    @PermissionResult
    @PermissionResult
    public abstract int checkPermission(@NonNull String permissionName,
    public abstract int checkPermission(@NonNull String permName,
            @NonNull String packageName);
            @NonNull String packageName);


    /**
    /**
@@ -3880,13 +3880,13 @@ public abstract class PackageManager {
     * permissions, hence the only way for an app to get such a permission
     * permissions, hence the only way for an app to get such a permission
     * is by a policy change.
     * is by a policy change.
     *
     *
     * @param permissionName The name of the permission you are checking for.
     * @param permName The name of the permission you are checking for.
     * @param packageName The name of the package you are checking against.
     * @param packageName The name of the package you are checking against.
     *
     *
     * @return Whether the permission is restricted by policy.
     * @return Whether the permission is restricted by policy.
     */
     */
    @CheckResult
    @CheckResult
    public abstract boolean isPermissionRevokedByPolicy(@NonNull String permissionName,
    public abstract boolean isPermissionRevokedByPolicy(@NonNull String permName,
            @NonNull String packageName);
            @NonNull String packageName);


    /**
    /**
@@ -3949,14 +3949,14 @@ public abstract class PackageManager {
     * -- you are only allowed to remove permissions that you are allowed
     * -- you are only allowed to remove permissions that you are allowed
     * to add.
     * to add.
     *
     *
     * @param permissionName The name of the permission to remove.
     * @param permName The name of the permission to remove.
     *
     *
     * @throws SecurityException if you are not allowed to remove the
     * @throws SecurityException if you are not allowed to remove the
     * given permission name.
     * given permission name.
     *
     *
     * @see #addPermission(PermissionInfo)
     * @see #addPermission(PermissionInfo)
     */
     */
    public abstract void removePermission(@NonNull String permissionName);
    public abstract void removePermission(@NonNull String permName);


    /**
    /**
     * Permission flags set when granting or revoking a permission.
     * Permission flags set when granting or revoking a permission.
@@ -3998,7 +3998,7 @@ public abstract class PackageManager {
     * </p>
     * </p>
     *
     *
     * @param packageName The package to which to grant the permission.
     * @param packageName The package to which to grant the permission.
     * @param permissionName The permission name to grant.
     * @param permName The permission name to grant.
     * @param user The user for which to grant the permission.
     * @param user The user for which to grant the permission.
     *
     *
     * @see #revokeRuntimePermission(String, String, android.os.UserHandle)
     * @see #revokeRuntimePermission(String, String, android.os.UserHandle)
@@ -4009,7 +4009,7 @@ public abstract class PackageManager {
    @SystemApi
    @SystemApi
    @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS)
    @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS)
    public abstract void grantRuntimePermission(@NonNull String packageName,
    public abstract void grantRuntimePermission(@NonNull String packageName,
            @NonNull String permissionName, @NonNull UserHandle user);
            @NonNull String permName, @NonNull UserHandle user);


    /**
    /**
     * Revoke a runtime permission that was previously granted by {@link
     * Revoke a runtime permission that was previously granted by {@link
@@ -4025,7 +4025,7 @@ public abstract class PackageManager {
     * </p>
     * </p>
     *
     *
     * @param packageName The package from which to revoke the permission.
     * @param packageName The package from which to revoke the permission.
     * @param permissionName The permission name to revoke.
     * @param permName The permission name to revoke.
     * @param user The user for which to revoke the permission.
     * @param user The user for which to revoke the permission.
     *
     *
     * @see #grantRuntimePermission(String, String, android.os.UserHandle)
     * @see #grantRuntimePermission(String, String, android.os.UserHandle)
@@ -4036,12 +4036,12 @@ public abstract class PackageManager {
    @SystemApi
    @SystemApi
    @RequiresPermission(android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS)
    @RequiresPermission(android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS)
    public abstract void revokeRuntimePermission(@NonNull String packageName,
    public abstract void revokeRuntimePermission(@NonNull String packageName,
            @NonNull String permissionName, @NonNull UserHandle user);
            @NonNull String permName, @NonNull UserHandle user);


    /**
    /**
     * Gets the state flags associated with a permission.
     * Gets the state flags associated with a permission.
     *
     *
     * @param permissionName The permission for which to get the flags.
     * @param permName The permission for which to get the flags.
     * @param packageName The package name for which to get the flags.
     * @param packageName The package name for which to get the flags.
     * @param user The user for which to get permission flags.
     * @param user The user for which to get permission flags.
     * @return The permission flags.
     * @return The permission flags.
@@ -4056,14 +4056,14 @@ public abstract class PackageManager {
            android.Manifest.permission.GET_RUNTIME_PERMISSIONS
            android.Manifest.permission.GET_RUNTIME_PERMISSIONS
    })
    })
    @PermissionFlags
    @PermissionFlags
    public abstract int getPermissionFlags(@NonNull String permissionName,
    public abstract int getPermissionFlags(@NonNull String permName,
            @NonNull String packageName, @NonNull UserHandle user);
            @NonNull String packageName, @NonNull UserHandle user);


    /**
    /**
     * Updates the flags associated with a permission by replacing the flags in
     * Updates the flags associated with a permission by replacing the flags in
     * the specified mask with the provided flag values.
     * the specified mask with the provided flag values.
     *
     *
     * @param permissionName The permission for which to update the flags.
     * @param permName The permission for which to update the flags.
     * @param packageName The package name for which to update the flags.
     * @param packageName The package name for which to update the flags.
     * @param flagMask The flags which to replace.
     * @param flagMask The flags which to replace.
     * @param flagValues The flags with which to replace.
     * @param flagValues The flags with which to replace.
@@ -4077,7 +4077,7 @@ public abstract class PackageManager {
            android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
            android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS,
            android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
            android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS
    })
    })
    public abstract void updatePermissionFlags(@NonNull String permissionName,
    public abstract void updatePermissionFlags(@NonNull String permName,
            @NonNull String packageName, @PermissionFlags int flagMask,
            @NonNull String packageName, @PermissionFlags int flagMask,
            @PermissionFlags int flagValues, @NonNull UserHandle user);
            @PermissionFlags int flagValues, @NonNull UserHandle user);


@@ -4164,7 +4164,7 @@ public abstract class PackageManager {
     * provided ones.
     * provided ones.
     *
     *
     * @param packageName The app for which to get whitelisted permissions.
     * @param packageName The app for which to get whitelisted permissions.
     * @param permission The whitelisted permission to add.
     * @param permName The whitelisted permission to add.
     * @param whitelistFlags The whitelists to which to add. Passing multiple flags
     * @param whitelistFlags The whitelists to which to add. Passing multiple flags
     * updates all specified whitelists.
     * updates all specified whitelists.
     * @return Whether the permission was added to the whitelist.
     * @return Whether the permission was added to the whitelist.
@@ -4180,7 +4180,7 @@ public abstract class PackageManager {
    @RequiresPermission(value = Manifest.permission.WHITELIST_RESTRICTED_PERMISSIONS,
    @RequiresPermission(value = Manifest.permission.WHITELIST_RESTRICTED_PERMISSIONS,
            conditional = true)
            conditional = true)
    public boolean addWhitelistedRestrictedPermission(@NonNull String packageName,
    public boolean addWhitelistedRestrictedPermission(@NonNull String packageName,
            @NonNull String permission, @PermissionWhitelistFlags int whitelistFlags) {
            @NonNull String permName, @PermissionWhitelistFlags int whitelistFlags) {
        return false;
        return false;
    }
    }


@@ -4218,7 +4218,7 @@ public abstract class PackageManager {
     * provided ones.
     * provided ones.
     *
     *
     * @param packageName The app for which to get whitelisted permissions.
     * @param packageName The app for which to get whitelisted permissions.
     * @param permission The whitelisted permission to remove.
     * @param permName The whitelisted permission to remove.
     * @param whitelistFlags The whitelists from which to remove. Passing multiple flags
     * @param whitelistFlags The whitelists from which to remove. Passing multiple flags
     * updates all specified whitelists.
     * updates all specified whitelists.
     * @return Whether the permission was removed from the whitelist.
     * @return Whether the permission was removed from the whitelist.
@@ -4234,7 +4234,7 @@ public abstract class PackageManager {
    @RequiresPermission(value = Manifest.permission.WHITELIST_RESTRICTED_PERMISSIONS,
    @RequiresPermission(value = Manifest.permission.WHITELIST_RESTRICTED_PERMISSIONS,
        conditional = true)
        conditional = true)
    public boolean removeWhitelistedRestrictedPermission(@NonNull String packageName,
    public boolean removeWhitelistedRestrictedPermission(@NonNull String packageName,
        @NonNull String permission, @PermissionWhitelistFlags int whitelistFlags) {
            @NonNull String permName, @PermissionWhitelistFlags int whitelistFlags) {
        return false;
        return false;
    }
    }


@@ -4244,13 +4244,13 @@ public abstract class PackageManager {
     * which the permission is requested does not clearly communicate to the user
     * which the permission is requested does not clearly communicate to the user
     * what would be the benefit from grating this permission.
     * what would be the benefit from grating this permission.
     *
     *
     * @param permissionName A permission your app wants to request.
     * @param permName A permission your app wants to request.
     * @return Whether you can show permission rationale UI.
     * @return Whether you can show permission rationale UI.
     *
     *
     * @hide
     * @hide
     */
     */
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public abstract boolean shouldShowRequestPermissionRationale(@NonNull String permissionName);
    public abstract boolean shouldShowRequestPermissionRationale(@NonNull String permName);


    /**
    /**
     * Returns an {@link android.content.Intent} suitable for passing to
     * Returns an {@link android.content.Intent} suitable for passing to
+12 −1
Original line number Original line Diff line number Diff line
@@ -556,7 +556,15 @@ public abstract class PackageManagerInternal {
     * @see #canAccessInstantApps
     * @see #canAccessInstantApps
     */
     */
    public abstract boolean filterAppAccess(
    public abstract boolean filterAppAccess(
            @Nullable PackageParser.Package pkg, int callingUid, int userId);
            @NonNull PackageParser.Package pkg, int callingUid, int userId);

    /**
     * Returns whether or not access to the application should be filtered.
     *
     * @see #filterAppAccess(android.content.pm.PackageParser.Package, int, int)
     */
    public abstract boolean filterAppAccess(
            @NonNull String packageName, int callingUid, int userId);


    /** Returns whether the given package was signed by the platform */
    /** Returns whether the given package was signed by the platform */
    public abstract boolean isPlatformSigned(String pkg);
    public abstract boolean isPlatformSigned(String pkg);
@@ -792,4 +800,7 @@ public abstract class PackageManagerInternal {


    /** Returns whether or not default runtime permissions are granted for the given user */
    /** Returns whether or not default runtime permissions are granted for the given user */
    public abstract boolean areDefaultRuntimePermissionsGranted(@UserIdInt int userId);
    public abstract boolean areDefaultRuntimePermissionsGranted(@UserIdInt int userId);

    /** Sets the enforcement of reading external storage */
    public abstract void setReadExternalStorageEnforced(boolean enforced);
}
}
+9 −0
Original line number Original line Diff line number Diff line
@@ -88,4 +88,13 @@ interface IPermissionManager {
    void grantDefaultPermissionsToActiveLuiApp(in String packageName, int userId);
    void grantDefaultPermissionsToActiveLuiApp(in String packageName, int userId);


    void revokeDefaultPermissionsFromLuiApps(in String[] packageNames, int userId);
    void revokeDefaultPermissionsFromLuiApps(in String[] packageNames, int userId);

    void setPermissionEnforced(String permName, boolean enforced);

    boolean isPermissionEnforced(String permName);

    boolean shouldShowRequestPermissionRationale(String permName,
            String packageName, int userId);

    boolean isPermissionRevokedByPolicy(String permName, String packageName, int userId);
}
}
Loading