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

Commit c92342bb authored by Maggie Benthall's avatar Maggie Benthall Committed by Android (Google) Code Review
Browse files

Merge "Add user restrictions for bluetooth, sideloading, usb file transfer" into jb-mr2-dev

parents 1263deb9 a12fccf5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -16814,6 +16814,9 @@ package android.os {
    field public static final java.lang.String DISALLOW_MODIFY_ACCOUNTS = "no_modify_accounts";
    field public static final java.lang.String DISALLOW_SHARE_LOCATION = "no_share_location";
    field public static final java.lang.String DISALLOW_UNINSTALL_APPS = "no_uninstall_apps";
    field public static final java.lang.String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";
    field public static final java.lang.String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";
    field public static final java.lang.String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";
  }
  public abstract class Vibrator {
+46 −9
Original line number Diff line number Diff line
@@ -86,8 +86,42 @@ public class UserManager {
     * @see #setUserRestrictions(Bundle)
     * @see #getUserRestrictions()
     */

    public static final String DISALLOW_SHARE_LOCATION = "no_share_location";

    /**
     * Key for user restrictions. Specifies if a user is disallowed from enabling the
     * "Unknown Sources" setting, that allows installation of apps from unknown sources.
     * The default value is <code>false</code>.
     * <p/>
     * Type: Boolean
     * @see #setUserRestrictions(Bundle)
     * @see #getUserRestrictions()
     */
    public static final String DISALLOW_INSTALL_UNKNOWN_SOURCES = "no_install_unknown_sources";

    /**
     * Key for user restrictions. Specifies if a user is disallowed from configuring bluetooth.
     * The default value is <code>false</code>.
     * <p/>
     * Type: Boolean
     * @see #setUserRestrictions(Bundle)
     * @see #getUserRestrictions()
     */
    public static final String DISALLOW_CONFIG_BLUETOOTH = "no_config_bluetooth";


    /**
     * Key for user restrictions. Specifies if a user is disallowed from transferring files over
     * USB. The default value is <code>false</code>.
     * <p/>
     * Type: Boolean
     * @see #setUserRestrictions(Bundle)
     * @see #getUserRestrictions()
     */
    public static final String DISALLOW_USB_FILE_TRANSFER = "no_usb_file_transfer";


    /** @hide */
    public UserManager(Context context, IUserManager service) {
        mService = service;
@@ -271,6 +305,16 @@ public class UserManager {
        setUserRestrictions(bundle, userHandle);
    }

    /**
     * @hide
     * Returns whether the current user has been disallowed from performing certain actions
     * or setting certain settings.
     * @param restrictionKey the string key representing the restriction
     */
    public boolean hasUserRestriction(String restrictionKey) {
        return getUserRestrictions().getBoolean(restrictionKey, false);
    }

    /**
     * Return the serial number for a user.  This is a device-unique
     * number assigned to that user; if the user is deleted and then a new
@@ -508,13 +552,6 @@ public class UserManager {
        return -1;
    }

    /**
     * Returns whether the current user is allowed to toggle location sharing settings.
     * @hide
     */
    public boolean isLocationSharingToggleAllowed() {
        return !getUserRestrictions().getBoolean(DISALLOW_SHARE_LOCATION, false);
    }

    /**
     * @hide
+2 −2
Original line number Diff line number Diff line
@@ -98,7 +98,7 @@ public class SettingsHelper {

    private void setGpsLocation(String value) {
        UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        if (! um.isLocationSharingToggleAllowed()) {
        if (um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION)) {
            return;
        }
        final String GPS = LocationManager.GPS_PROVIDER;
+4 −6
Original line number Diff line number Diff line
@@ -906,6 +906,7 @@ public class AccountManagerService
        }
    }

    @Override
    public void invalidateAuthToken(String accountType, String authToken) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "invalidateAuthToken: accountType " + accountType
@@ -1426,8 +1427,7 @@ public class AccountManagerService
        checkManageAccountsPermission();

        // Is user disallowed from modifying accounts?
        if (getUserManager().getUserRestrictions(Binder.getCallingUserHandle())
                .getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
        if (getUserManager().hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
            try {
                response.onError(AccountManager.ERROR_CODE_USER_RESTRICTED,
                        "User is not allowed to add an account!");
@@ -2570,9 +2570,7 @@ public class AccountManagerService

    private boolean canUserModifyAccounts(int callingUid) {
        if (callingUid != android.os.Process.myUid()) {
            Bundle restrictions = getUserManager().getUserRestrictions(
                    new UserHandle(UserHandle.getUserId(callingUid)));
            if (restrictions.getBoolean(UserManager.DISALLOW_MODIFY_ACCOUNTS, false)) {
            if (getUserManager().hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) {
                return false;
            }
        }
+8 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.RestrictionEntry;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
@@ -619,6 +618,10 @@ public class UserManagerService extends IUserManager.Stub {
                writeBoolean(serializer, restrictions, UserManager.DISALLOW_INSTALL_APPS);
                writeBoolean(serializer, restrictions, UserManager.DISALLOW_UNINSTALL_APPS);
                writeBoolean(serializer, restrictions, UserManager.DISALLOW_SHARE_LOCATION);
                writeBoolean(serializer, restrictions,
                        UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
                writeBoolean(serializer, restrictions, UserManager.DISALLOW_CONFIG_BLUETOOTH);
                writeBoolean(serializer, restrictions, UserManager.DISALLOW_USB_FILE_TRANSFER);
                serializer.endTag(null, TAG_RESTRICTIONS);
            }
            serializer.endTag(null, TAG_USER);
@@ -735,6 +738,10 @@ public class UserManagerService extends IUserManager.Stub {
                        readBoolean(parser, restrictions, UserManager.DISALLOW_INSTALL_APPS);
                        readBoolean(parser, restrictions, UserManager.DISALLOW_UNINSTALL_APPS);
                        readBoolean(parser, restrictions, UserManager.DISALLOW_SHARE_LOCATION);
                        readBoolean(parser, restrictions,
                                UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
                        readBoolean(parser, restrictions, UserManager.DISALLOW_CONFIG_BLUETOOTH);
                        readBoolean(parser, restrictions, UserManager.DISALLOW_USB_FILE_TRANSFER);
                    }
                }
            }