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

Commit 5fa9f2b1 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Single-user restrictions"

parents 57b867f3 655d0e20
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6155,6 +6155,7 @@ package android.content {
    field public static final java.lang.String ACTION_PROVIDER_CHANGED = "android.intent.action.PROVIDER_CHANGED";
    field public static final java.lang.String ACTION_QUICK_CLOCK = "android.intent.action.QUICK_CLOCK";
    field public static final java.lang.String ACTION_REBOOT = "android.intent.action.REBOOT";
    field public static final java.lang.String ACTION_RESTRICTIONS_PIN_CHALLENGE = "android.intent.action.RESTRICTIONS_PIN_CHALLENGE";
    field public static final java.lang.String ACTION_RUN = "android.intent.action.RUN";
    field public static final java.lang.String ACTION_SCREEN_OFF = "android.intent.action.SCREEN_OFF";
    field public static final java.lang.String ACTION_SCREEN_ON = "android.intent.action.SCREEN_ON";
@@ -17964,6 +17965,7 @@ package android.os {
    method public java.lang.String getUserName();
    method public android.os.Bundle getUserRestrictions();
    method public android.os.Bundle getUserRestrictions(android.os.UserHandle);
    method public boolean hasRestrictionsPin();
    method public boolean isUserAGoat();
    method public boolean isUserRunning(android.os.UserHandle);
    method public boolean isUserRunningOrStopping(android.os.UserHandle);
+42 −0
Original line number Diff line number Diff line
@@ -147,6 +147,16 @@ public final class Pm {
            return;
        }

        if ("block".equals(op)) {
            runSetBlockedSetting(true);
            return;
        }

        if ("unblock".equals(op)) {
            runSetBlockedSetting(false);
            return;
        }

        if ("grant".equals(op)) {
            runGrantRevokePermission(true);
            return;
@@ -1256,6 +1266,36 @@ public final class Pm {
        }
    }

    private void runSetBlockedSetting(boolean state) {
        int userId = 0;
        String option = nextOption();
        if (option != null && option.equals("--user")) {
            String optionData = nextOptionData();
            if (optionData == null || !isNumber(optionData)) {
                System.err.println("Error: no USER_ID specified");
                showUsage();
                return;
            } else {
                userId = Integer.parseInt(optionData);
            }
        }

        String pkg = nextArg();
        if (pkg == null) {
            System.err.println("Error: no package or component specified");
            showUsage();
            return;
        }
        try {
            mPm.setApplicationBlockedSettingAsUser(pkg, state, userId);
            System.err.println("Package " + pkg + " new blocked state: "
                    + mPm.getApplicationBlockedSettingAsUser(pkg, userId));
        } catch (RemoteException e) {
            System.err.println(e.toString());
            System.err.println(PM_NOT_RUNNING_ERR);
        }
    }

    private void runGrantRevokePermission(boolean grant) {
        String pkg = nextArg();
        if (pkg == null) {
@@ -1482,6 +1522,8 @@ public final class Pm {
        System.err.println("       pm disable [--user USER_ID] PACKAGE_OR_COMPONENT");
        System.err.println("       pm disable-user [--user USER_ID] PACKAGE_OR_COMPONENT");
        System.err.println("       pm disable-until-used [--user USER_ID] PACKAGE_OR_COMPONENT");
        System.err.println("       pm block [--user USER_ID] PACKAGE_OR_COMPONENT");
        System.err.println("       pm unblock [--user USER_ID] PACKAGE_OR_COMPONENT");
        System.err.println("       pm grant PACKAGE PERMISSION");
        System.err.println("       pm revoke PACKAGE PERMISSION");
        System.err.println("       pm set-install-location [0/auto] [1/internal] [2/external]");
+22 −0
Original line number Diff line number Diff line
@@ -1296,6 +1296,28 @@ final class ApplicationPackageManager extends PackageManager {
        return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
    }

    @Override
    public boolean setApplicationBlockedSettingAsUser(String packageName, boolean blocked,
            UserHandle user) {
        try {
            return mPM.setApplicationBlockedSettingAsUser(packageName, blocked,
                    user.getIdentifier());
        } catch (RemoteException re) {
            // Should never happen!
        }
        return false;
    }

    @Override
    public boolean getApplicationBlockedSettingAsUser(String packageName, UserHandle user) {
        try {
            return mPM.getApplicationBlockedSettingAsUser(packageName, user.getIdentifier());
        } catch (RemoteException re) {
            // Should never happen!
        }
        return false;
    }

    /**
     * @hide
     */
+12 −0
Original line number Diff line number Diff line
@@ -2439,6 +2439,18 @@ public class Intent implements Parcelable, Cloneable {
    public static final String ACTION_GET_RESTRICTION_ENTRIES =
            "android.intent.action.GET_RESTRICTION_ENTRIES";

    /**
     * Activity to challenge the user for a PIN that was configured when setting up
     * restrictions. Launch the activity using
     * {@link android.app.Activity#startActivityForResult(Intent, int)} and check if the
     * result is {@link android.app.Activity#RESULT_OK} for a successful response to the
     * challenge.<p/>
     * Before launching this activity, make sure that there is a PIN in effect, by calling
     * {@link android.os.UserManager#hasRestrictionsPin()}.
     */
    public static final String ACTION_RESTRICTIONS_PIN_CHALLENGE =
            "android.intent.action.RESTRICTIONS_PIN_CHALLENGE";

    /**
     * Sent the first time a user is starting, to allow system apps to
     * perform one time initialization.  (This will not be seen by third
+8 −1
Original line number Diff line number Diff line
@@ -345,6 +345,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public static final int FLAG_CANT_SAVE_STATE = 1<<28;

    /**
     * Value for {@link #flags}: true if the application is blocked via restrictions and for
     * most purposes is considered as not installed.
     * {@hide}
     */
    public static final int FLAG_BLOCKED = 1<<27;

    /**
     * Flags associated with the application.  Any combination of
     * {@link #FLAG_SYSTEM}, {@link #FLAG_DEBUGGABLE}, {@link #FLAG_HAS_CODE},
Loading