am 41bb3455: Merge "Set the default user restrictions to disallow calling and sms" into lmp-dev
* commit '41bb3455e44dc8fde4569bbfd56fa20c6da8a27d': Set the default user restrictions to disallow calling and sms
This commit is contained in:
@@ -720,6 +720,39 @@ public class UserManager {
|
|||||||
return guest;
|
return guest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a secondary user with the specified name and options and configures it with default
|
||||||
|
* restrictions.
|
||||||
|
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
|
||||||
|
*
|
||||||
|
* @param name the user's name
|
||||||
|
* @param flags flags that identify the type of user and other properties.
|
||||||
|
* @see UserInfo
|
||||||
|
*
|
||||||
|
* @return the UserInfo object for the created user, or null if the user could not be created.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public UserInfo createSecondaryUser(String name, int flags) {
|
||||||
|
try {
|
||||||
|
UserInfo user = mService.createUser(name, flags);
|
||||||
|
if (user == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Bundle userRestrictions = mService.getUserRestrictions(user.id);
|
||||||
|
addDefaultUserRestrictions(userRestrictions);
|
||||||
|
mService.setUserRestrictions(userRestrictions, user.id);
|
||||||
|
return user;
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
Log.w(TAG, "Could not create a user", re);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addDefaultUserRestrictions(Bundle restrictions) {
|
||||||
|
restrictions.putBoolean(DISALLOW_OUTGOING_CALLS, true);
|
||||||
|
restrictions.putBoolean(DISALLOW_SMS, true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a user with the specified name and options as a profile of another user.
|
* Creates a user with the specified name and options as a profile of another user.
|
||||||
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
|
* Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ public class UserSwitcherController {
|
|||||||
cancel();
|
cancel();
|
||||||
} else {
|
} else {
|
||||||
dismiss();
|
dismiss();
|
||||||
UserInfo user = mUserManager.createUser(
|
UserInfo user = mUserManager.createSecondaryUser(
|
||||||
mContext.getString(R.string.user_new_user_name), 0 /* flags */);
|
mContext.getString(R.string.user_new_user_name), 0 /* flags */);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
// Couldn't create user, most likely because there are too many, but we haven't
|
// Couldn't create user, most likely because there are too many, but we haven't
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
|
|
||||||
private static final int MIN_USER_ID = 10;
|
private static final int MIN_USER_ID = 10;
|
||||||
|
|
||||||
private static final int USER_VERSION = 4;
|
private static final int USER_VERSION = 5;
|
||||||
|
|
||||||
private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms
|
private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms
|
||||||
|
|
||||||
@@ -462,6 +462,17 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If default guest restrictions haven't been initialized yet, add the basic
|
||||||
|
* restrictions.
|
||||||
|
*/
|
||||||
|
private void initDefaultGuestRestrictions() {
|
||||||
|
if (mGuestRestrictions.isEmpty()) {
|
||||||
|
mGuestRestrictions.putBoolean(UserManager.DISALLOW_OUTGOING_CALLS, true);
|
||||||
|
writeUserListLocked();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bundle getDefaultGuestRestrictions() {
|
public Bundle getDefaultGuestRestrictions() {
|
||||||
checkManageUsersPermission("getDefaultGuestRestrictions");
|
checkManageUsersPermission("getDefaultGuestRestrictions");
|
||||||
@@ -693,6 +704,11 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
userVersion = 4;
|
userVersion = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userVersion < 5) {
|
||||||
|
initDefaultGuestRestrictions();
|
||||||
|
userVersion = 5;
|
||||||
|
}
|
||||||
|
|
||||||
if (userVersion < USER_VERSION) {
|
if (userVersion < USER_VERSION) {
|
||||||
Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to "
|
Slog.w(LOG_TAG, "User version " + mUserVersion + " didn't upgrade as expected to "
|
||||||
+ USER_VERSION);
|
+ USER_VERSION);
|
||||||
@@ -715,6 +731,7 @@ public class UserManagerService extends IUserManager.Stub {
|
|||||||
mUserRestrictions.append(UserHandle.USER_OWNER, restrictions);
|
mUserRestrictions.append(UserHandle.USER_OWNER, restrictions);
|
||||||
|
|
||||||
updateUserIdsLocked();
|
updateUserIdsLocked();
|
||||||
|
initDefaultGuestRestrictions();
|
||||||
|
|
||||||
writeUserListLocked();
|
writeUserListLocked();
|
||||||
writeUserLocked(primary);
|
writeUserLocked(primary);
|
||||||
|
|||||||
Reference in New Issue
Block a user