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

Commit 4c2b1952 authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge "Add a new RestrictionsManager API to get app restrictions per admin"

parents a2b56254 17981fdc
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -11356,7 +11356,8 @@ package android.content {
  public class RestrictionsManager {
    method public static android.os.Bundle convertRestrictionsToBundle(java.util.List<android.content.RestrictionEntry>);
    method public android.content.Intent createLocalApprovalIntent();
    method public android.os.Bundle getApplicationRestrictions();
    method @Deprecated public android.os.Bundle getApplicationRestrictions();
    method @NonNull @WorkerThread public java.util.List<android.os.Bundle> getApplicationRestrictionsPerAdmin();
    method public java.util.List<android.content.RestrictionEntry> getManifestRestrictions(String);
    method public boolean hasRestrictionsProvider();
    method public void notifyPermissionResponse(String, android.os.PersistableBundle);
@@ -33752,7 +33753,7 @@ package android.os {
  public class UserManager {
    method public static android.content.Intent createUserCreationIntent(@Nullable String, @Nullable String, @Nullable String, @Nullable android.os.PersistableBundle);
    method @WorkerThread public android.os.Bundle getApplicationRestrictions(String);
    method @Deprecated @WorkerThread public android.os.Bundle getApplicationRestrictions(String);
    method public long getSerialNumberForUser(android.os.UserHandle);
    method @RequiresPermission(anyOf={"android.permission.MANAGE_USERS", "android.permission.CREATE_USERS"}) public int getUserCount();
    method public long getUserCreationTime(android.os.UserHandle);
+5 −0
Original line number Diff line number Diff line
@@ -10067,6 +10067,11 @@ public class DevicePolicyManager {
     * owner, and the application restrictions managing package via
     * {@link #getApplicationRestrictions}.
     *
     * <p>Starting from Android Version {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * multiple admins can set app restrictions for the same application, the target application can
     * get the list of app restrictions set by each admin via
     * {@link android.content.RestrictionsManager#getApplicationRestrictionsPerAdmin}.
     *
     * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with, or
+4 −4
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.os.Bundle;
import android.os.UserHandle;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
@@ -322,8 +321,9 @@ public abstract class DevicePolicyManagerInternal {
    public abstract boolean isApplicationExemptionsFlagEnabled();

    /**
    * Returns the application restrictions set by each admin for the given {@code packageName}.
     * Returns a map of admin to {@link Bundle} map of restrictions set by the admins for the
     * provided {@code packageName} in the provided {@code userId}
     */
    public abstract Map<String, Bundle> getApplicationRestrictionsPerAdmin(
            String packageName, int userId);
    public abstract List<Bundle> getApplicationRestrictionsPerAdminForUser(
            String packageName, @UserIdInt int userId);
}
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.PersistableBundle;
 */
interface IRestrictionsManager {
    Bundle getApplicationRestrictions(in String packageName);
    List<Bundle> getApplicationRestrictionsPerAdminForUser(int userId, in String packageName);
    boolean hasRestrictionsProvider();
    void requestPermission(in String packageName, in String requestType, in String requestId,
            in PersistableBundle requestData);
+52 −0
Original line number Diff line number Diff line
@@ -18,7 +18,10 @@ package android.content;

import static android.content.Intent.LOCAL_FLAG_FROM_SYSTEM;

import android.annotation.NonNull;
import android.annotation.SystemService;
import android.annotation.UserHandleAware;
import android.annotation.WorkerThread;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.compat.annotation.UnsupportedAppUsage;
@@ -31,6 +34,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.UserManager;
import android.service.restrictions.RestrictionsReceiver;
import android.util.AttributeSet;
import android.util.Log;
@@ -422,6 +426,14 @@ public class RestrictionsManager {
     * to this application.
     * @return the application restrictions as a Bundle. Returns null if there
     * are no restrictions.
     *
     * @deprecated Use {@link #getApplicationRestrictionsPerAdmin} instead.
     * Starting from Android version {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, it is
     * possible for there to be multiple managing agents on the device with the ability to set
     * restrictions. This API will only to return the restrictions set by device policy controllers
     * (DPCs)
     *
     * @see DevicePolicyManager
     */
    public Bundle getApplicationRestrictions() {
        try {
@@ -434,6 +446,46 @@ public class RestrictionsManager {
        return null;
    }

    /**
     * Returns a {@link List} containing a {@link Bundle} for each managing agent that has set
     * restrictions for the current application, the bundle contains any application restrictions
     * set for the current package. The order of the items in the list is not guaranteed to remain
     * stable between multiple calls.
     *
     * <p>Starting from Android version {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * it is possible for there to be multiple managing agents on the device with the ability to set
     * restrictions, e.g. an Enterprise DPC and a Supervision admin.
     *
     * <p>Each {@link Bundle} consists of key-value pairs, as defined by the application,
     * where the types of values may be:
     * <ul>
     * <li>{@code boolean}
     * <li>{@code int}
     * <li>{@code String} or {@code String[]}
     * <li>From {@link android.os.Build.VERSION_CODES#M}, {@code Bundle} or {@code Bundle[]}
     * </ul>
     *
     * <p>NOTE: The method performs disk I/O and shouldn't be called on the main thread
     *
     * @return a {@link List} of {@link Bundle} containing the restrictions set by admins for that
     * package. Returns an empty {@link List} if there are no saved restrictions.
     *
     * @see UserManager#KEY_RESTRICTIONS_PENDING
     */
    @WorkerThread
    @UserHandleAware
    public @NonNull List<Bundle> getApplicationRestrictionsPerAdmin() {
        try {
            if (mService != null) {
                return mService.getApplicationRestrictionsPerAdminForUser(
                        mContext.getUserId(), mContext.getPackageName());
            }
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
        return null;
    }

    /**
     * Called by an application to check if there is an active Restrictions Provider. If
     * there isn't, {@link #requestPermission(String, String, PersistableBundle)} is not available.
Loading