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

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

Merge "Add DPM API to explicitly set/get global restrictions"

parents d53a4c8d d1f0c3ae
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7782,6 +7782,7 @@ package android.app.admin {
    method public int addOverrideApn(@NonNull android.content.ComponentName, @NonNull android.telephony.data.ApnSetting);
    method public void addPersistentPreferredActivity(@NonNull android.content.ComponentName, android.content.IntentFilter, @NonNull android.content.ComponentName);
    method public void addUserRestriction(@NonNull android.content.ComponentName, String);
    method public void addUserRestrictionGlobally(@NonNull String);
    method public boolean bindDeviceAdminServiceAsUser(@NonNull android.content.ComponentName, android.content.Intent, @NonNull android.content.ServiceConnection, int, @NonNull android.os.UserHandle);
    method public boolean canAdminGrantSensorsPermissions();
    method public boolean canUsbDataSignalingBeDisabled();
@@ -7884,6 +7885,7 @@ package android.app.admin {
    method @Nullable public java.util.List<android.os.PersistableBundle> getTrustAgentConfiguration(@Nullable android.content.ComponentName, @NonNull android.content.ComponentName);
    method @NonNull public java.util.List<java.lang.String> getUserControlDisabledPackages(@NonNull android.content.ComponentName);
    method @NonNull public android.os.Bundle getUserRestrictions(@NonNull android.content.ComponentName);
    method @NonNull public android.os.Bundle getUserRestrictionsGlobally();
    method @Nullable public String getWifiMacAddress(@NonNull android.content.ComponentName);
    method @Nullable public android.app.admin.WifiSsidPolicy getWifiSsidPolicy();
    method public boolean grantKeyPairToApp(@Nullable android.content.ComponentName, @NonNull String, @NonNull String);
+7 −0
Original line number Diff line number Diff line
@@ -1559,6 +1559,13 @@ package android.app.admin {
    field @NonNull public static final android.os.Parcelable.Creator<android.app.admin.UnknownAuthority> CREATOR;
  }
  public final class UserRestrictionPolicyKey extends android.app.admin.PolicyKey {
    method public int describeContents();
    method @NonNull public String getRestriction();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.admin.UserRestrictionPolicyKey> CREATOR;
  }
}
package android.app.ambientcontext {
+84 −3
Original line number Diff line number Diff line
@@ -11269,6 +11269,13 @@ public class DevicePolicyManager {
     * See the constants in {@link android.os.UserManager} for the list of restrictions that can
     * be enforced device-wide.
     *
     * <p>For callers targeting Android {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or
     * above, calling this API will result in applying the restriction locally on the calling user,
     * or locally on the parent profile if called from the
     * {@link DevicePolicyManager} instance obtained from
     * {@link #getParentProfileInstance(ComponentName)}. To set a restriction globally, call
     * {@link #addUserRestrictionGlobally} instead.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param key   The key of the restriction.
     * @throws SecurityException if {@code admin} is not a device or profile owner.
@@ -11277,7 +11284,38 @@ public class DevicePolicyManager {
            @UserManager.UserRestrictionKey String key) {
        if (mService != null) {
            try {
                mService.setUserRestriction(admin, key, true, mParentInstance);
                mService.setUserRestriction(
                        admin, mContext.getPackageName(), key, true, mParentInstance);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
    }
    /**
     * Called by a profile or device owner to set a user restriction specified by the provided
     * {@code key} globally on all users. To clear the restriction use
     * {@link #clearUserRestriction}.
     *
     * <p>For a given user, a restriction will be set if it was applied globally or locally by any
     * admin.
     *
     * <p> The calling device admin must be a profile or device owner; if it is not, a security
     * exception will be thrown.
     *
     * <p> See the constants in {@link android.os.UserManager} for the list of restrictions that can
     * be enforced device-wide.
     *
     * @param key The key of the restriction.
     * @throws SecurityException if {@code admin} is not a device or profile owner.
     * @throws IllegalStateException if caller is not targeting Android
     * {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or above.
     */
    public void addUserRestrictionGlobally(@NonNull @UserManager.UserRestrictionKey String key) {
        throwIfParentInstance("addUserRestrictionGlobally");
        if (mService != null) {
            try {
                mService.setUserRestrictionGlobally(mContext.getPackageName(), key);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -11296,6 +11334,10 @@ public class DevicePolicyManager {
     * <p>
     * See the constants in {@link android.os.UserManager} for the list of restrictions.
     *
     * <p>For callers targeting Android {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or
     * above, calling this API will result in clearing any local and global restriction with the
     * specified key that was previously set by the caller.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @param key   The key of the restriction.
     * @throws SecurityException if {@code admin} is not a device or profile owner.
@@ -11304,7 +11346,8 @@ public class DevicePolicyManager {
            @UserManager.UserRestrictionKey String key) {
        if (mService != null) {
            try {
                mService.setUserRestriction(admin, key, false, mParentInstance);
                mService.setUserRestriction(
                        admin, mContext.getPackageName(), key, false, mParentInstance);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
@@ -11324,6 +11367,18 @@ public class DevicePolicyManager {
     * {@link #getParentProfileInstance(ComponentName)}, for retrieving device-wide restrictions
     * it previously set with {@link #addUserRestriction(ComponentName, String)}.
     *
     * <p>For callers targeting Android {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or
     * above, this API will return the local restrictions set on the calling user, or on the parent
     * profile if called from the {@link DevicePolicyManager} instance obtained from
     * {@link #getParentProfileInstance(ComponentName)}. To get global restrictions set by admin,
     * call {@link #getUserRestrictionsGlobally()} instead.
     *
     * <p>Note that this is different that the returned restrictions for callers targeting pre
     * Android {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, were this API returns
     * all local/global restrictions set by the admin on the calling user using
     * {@link #addUserRestriction(ComponentName, String)} or the parent user if called on the
     * {@link DevicePolicyManager} instance it obtained from {@link #getParentProfileInstance}.
     *
     * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
     * @return a {@link Bundle} whose keys are the user restrictions, and the values a
     * {@code boolean} indicating whether the restriction is set.
@@ -11333,7 +11388,33 @@ public class DevicePolicyManager {
        Bundle ret = null;
        if (mService != null) {
            try {
                ret = mService.getUserRestrictions(admin, mParentInstance);
                ret = mService.getUserRestrictions(
                        admin, mContext.getPackageName(), mParentInstance);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
        }
        return ret == null ? new Bundle() : ret;
    }
    /**
     * Called by a profile or device owner to get global user restrictions set with
     * {@link #addUserRestrictionGlobally(String)}.
     * <p>
     * To get all the user restrictions currently set for a certain user, use
     * {@link UserManager#getUserRestrictions()}.
     * @return a {@link Bundle} whose keys are the user restrictions, and the values a
     * {@code boolean} indicating whether the restriction is set.
     * @throws SecurityException if {@code admin} is not a device or profile owner.
     * @throws IllegalStateException if caller is not targeting Android
     * {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE} or above.
     */
    public @NonNull Bundle getUserRestrictionsGlobally() {
        throwIfParentInstance("createAdminSupportIntent");
        Bundle ret = null;
        if (mService != null) {
            try {
                ret = mService.getUserRestrictionsGlobally(mContext.getPackageName());
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
            }
+5 −2
Original line number Diff line number Diff line
@@ -247,8 +247,11 @@ interface IDevicePolicyManager {
    void setRestrictionsProvider(in ComponentName who, in ComponentName provider);
    ComponentName getRestrictionsProvider(int userHandle);

    void setUserRestriction(in ComponentName who, in String key, boolean enable, boolean parent);
    Bundle getUserRestrictions(in ComponentName who, boolean parent);
    void setUserRestriction(in ComponentName who, in String callerPackage, in String key, boolean enable, boolean parent);
    void setUserRestrictionGlobally(in String callerPackage, in String key);
    Bundle getUserRestrictions(in ComponentName who, in String callerPackage, boolean parent);
    Bundle getUserRestrictionsGlobally(in String callerPackage);

    void addCrossProfileIntentFilter(in ComponentName admin, in IntentFilter filter, int flags);
    void clearCrossProfileIntentFilters(in ComponentName admin);

+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.app.admin;

import static android.app.admin.PolicyUpdatesReceiver.EXTRA_INTENT_FILTER;
import static android.app.admin.PolicyUpdatesReceiver.EXTRA_POLICY_BUNDLE_KEY;
import static android.app.admin.PolicyUpdatesReceiver.EXTRA_POLICY_KEY;

import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -100,7 +101,7 @@ public final class IntentFilterPolicyKey extends PolicyKey {
     */
    @Override
    public void writeToBundle(Bundle bundle) {
        super.writeToBundle(bundle);
        bundle.putString(EXTRA_POLICY_KEY, getIdentifier());
        Bundle extraPolicyParams = new Bundle();
        extraPolicyParams.putParcelable(EXTRA_INTENT_FILTER, mFilter);
        bundle.putBundle(EXTRA_POLICY_BUNDLE_KEY, extraPolicyParams);
Loading