Merge "Check multi-user support in isUserSwitcherEnabled"

This commit is contained in:
Fyodor Kupolov
2015-09-30 21:58:19 +00:00
committed by Android (Google) Code Review
8 changed files with 25 additions and 41 deletions

View File

@@ -2437,6 +2437,17 @@ public class DevicePolicyManager {
return false;
}
/**
* Determine whether or not creating a guest user has been disabled for the device
*
* @hide
*/
public boolean getGuestUserDisabled(@Nullable ComponentName admin) {
// Currently guest users can always be created if multi-user is enabled
// TODO introduce a policy for guest user creation
return false;
}
/**
* Called by a device/profile owner to set whether the screen capture is disabled. Disabling
* screen capture also prevents the content from being shown on display devices that do not have

View File

@@ -20,6 +20,7 @@ import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.pm.UserInfo;
import android.content.res.Resources;
@@ -1337,12 +1338,15 @@ public class UserManager {
}
/**
* Returns true if the user switcher should be shown, this will be if there
* are multiple users that aren't managed profiles.
* Returns true if the user switcher should be shown, this will be if device supports multi-user
* and there are at least 2 users available that are not managed profiles.
* @hide
* @return true if user switcher should be shown.
*/
public boolean isUserSwitcherEnabled() {
if (!supportsMultipleUsers()) {
return false;
}
List<UserInfo> users = getUsers(true);
if (users == null) {
return false;
@@ -1353,8 +1357,8 @@ public class UserManager {
++switchableUserCount;
}
}
final boolean guestEnabled = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.GUEST_USER_ENABLED, 0) == 1;
final boolean guestEnabled = !mContext.getSystemService(DevicePolicyManager.class)
.getGuestUserDisabled(null);
return switchableUserCount > 1 || guestEnabled;
}

View File

@@ -7688,14 +7688,6 @@ public final class Settings {
*/
public static final String DEVICE_NAME = "device_name";
/**
* Whether it should be possible to create a guest user on the device.
* <p>
* Type: int (0 for disabled, 1 for enabled)
* @hide
*/
public static final String GUEST_USER_ENABLED = "guest_user_enabled";
/**
* Whether the NetworkScoringService has been first initialized.
* <p>

View File

@@ -204,9 +204,6 @@
<!-- Default for Settings.Secure.WAKE_GESTURE_ENABLED -->
<bool name="def_wake_gesture_enabled">true</bool>
<!-- Default for Settings.Global.GUEST_USER_ENABLED -->
<bool name="def_guest_user_enabled">true</bool>
<!-- Default state of tap to wake -->
<bool name="def_double_tap_to_wake">true</bool>

View File

@@ -1693,20 +1693,7 @@ class DatabaseHelper extends SQLiteOpenHelper {
}
if (upgradeVersion < 105) {
if (mUserHandle == UserHandle.USER_SYSTEM) {
db.beginTransaction();
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
+ " VALUES(?,?);");
loadBooleanSetting(stmt, Settings.Global.GUEST_USER_ENABLED,
R.bool.def_guest_user_enabled);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (stmt != null) stmt.close();
}
}
// No-op: GUEST_USER_ENABLED setting was removed
upgradeVersion = 105;
}
@@ -2705,8 +2692,6 @@ class DatabaseHelper extends SQLiteOpenHelper {
loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
loadBooleanSetting(stmt, Settings.Global.GUEST_USER_ENABLED,
R.bool.def_guest_user_enabled);
loadSetting(stmt, Settings.Global.ENHANCED_4G_MODE_ENABLED,
ImsConfig.FeatureValueConstants.ON);

View File

@@ -81,7 +81,7 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
}
private void registerListener() {
if (UserSwitcherController.isUserSwitcherAvailable(mUserManager) && mUserListener == null) {
if (mUserManager.isUserSwitcherEnabled() && mUserListener == null) {
final UserSwitcherController controller = mUserSwitcherController;
if (controller != null) {
@@ -103,7 +103,7 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
@Override
public void onClick(View v) {
if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
if (mUserManager.isUserSwitcherEnabled()) {
if (mKeyguardMode) {
if (mKeyguardUserSwitcher != null) {
mKeyguardUserSwitcher.show(true /* animate */);
@@ -135,14 +135,14 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
private void refreshContentDescription() {
String currentUser = null;
if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)
if (mUserManager.isUserSwitcherEnabled()
&& mUserSwitcherController != null) {
currentUser = mUserSwitcherController.getCurrentUserName(mContext);
}
String text = null;
if (isClickable()) {
if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
if (mUserManager.isUserSwitcherEnabled()) {
if (TextUtils.isEmpty(currentUser)) {
text = mContext.getString(R.string.accessibility_multi_user_switch_switcher);
} else {

View File

@@ -882,7 +882,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mKeyguardBottomArea.setAccessibilityController(mAccessibilityController);
mNextAlarmController = new NextAlarmController(mContext);
mKeyguardMonitor = new KeyguardMonitor(mContext);
if (UserSwitcherController.isUserSwitcherAvailable(UserManager.get(mContext))) {
if (UserManager.get(mContext).isUserSwitcherEnabled()) {
mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor,
mHandler);
if (mUserSwitcherController.useFullscreenUserSwitcher()) {

View File

@@ -752,9 +752,4 @@ public class UserSwitcherController {
}
}
}
public static boolean isUserSwitcherAvailable(UserManager um) {
return UserManager.supportsMultipleUsers() && um.isUserSwitcherEnabled();
}
}