Merge "Part1 - Don't add padlock if the restriction is not set by admin." into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f498c8ddc1
@@ -113,6 +113,12 @@ public class RestrictedLockUtils {
|
||||
return admin;
|
||||
}
|
||||
|
||||
public static boolean hasBaseUserRestriction(Context context,
|
||||
String userRestriction, int userId) {
|
||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
return um.hasBaseUserRestriction(userRestriction, UserHandle.of(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if keyguard features are disabled by policy.
|
||||
*
|
||||
|
||||
@@ -70,6 +70,12 @@ public class RestrictedPreferenceHelper {
|
||||
}
|
||||
}
|
||||
mAttrUserRestriction = data == null ? null : data.toString();
|
||||
// If the system has set the user restriction, then we shouldn't add the padlock.
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(mContext, mAttrUserRestriction,
|
||||
UserHandle.myUserId())) {
|
||||
mAttrUserRestriction = null;
|
||||
return;
|
||||
}
|
||||
|
||||
final TypedValue useAdminDisabledSummary =
|
||||
attributes.peekValue(R.styleable.RestrictedPreference_useAdminDisabledSummary);
|
||||
|
||||
@@ -279,10 +279,11 @@ public abstract class QSTile<TState extends State> implements Listenable {
|
||||
mCallbacks.clear();
|
||||
}
|
||||
|
||||
protected void checkIfRestrictionEnforced(State state, String userRestriction) {
|
||||
protected void checkIfRestrictionEnforcedByAdminOnly(State state, String userRestriction) {
|
||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
|
||||
userRestriction, ActivityManager.getCurrentUser());
|
||||
if (admin != null) {
|
||||
if (admin != null && !RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
userRestriction, ActivityManager.getCurrentUser())) {
|
||||
state.disabledByPolicy = true;
|
||||
state.enforcedAdmin = admin;
|
||||
} else {
|
||||
|
||||
@@ -29,11 +29,13 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnAttachStateChangeListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.MetricsProto.MetricsEvent;
|
||||
import com.android.systemui.Prefs;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysUIToast;
|
||||
import com.android.systemui.qs.QSTile;
|
||||
import com.android.systemui.statusbar.policy.ZenModeController;
|
||||
import com.android.systemui.volume.ZenModePanel;
|
||||
@@ -100,6 +102,14 @@ public class DndTile extends QSTile<QSTile.BooleanState> {
|
||||
|
||||
@Override
|
||||
public void handleClick() {
|
||||
if (mController.isVolumeRestricted()) {
|
||||
// Collapse the panels, so the user can see the toast.
|
||||
mHost.collapsePanels();
|
||||
SysUIToast.makeText(mContext, mContext.getString(
|
||||
com.android.internal.R.string.error_message_change_not_allowed),
|
||||
Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
MetricsLogger.action(mContext, getMetricsCategory(), !mState.value);
|
||||
if (mState.value) {
|
||||
mController.setZen(Global.ZEN_MODE_OFF, null, TAG);
|
||||
@@ -116,8 +126,7 @@ public class DndTile extends QSTile<QSTile.BooleanState> {
|
||||
final boolean newValue = zen != Global.ZEN_MODE_OFF;
|
||||
final boolean valueChanged = state.value != newValue;
|
||||
state.value = newValue;
|
||||
state.disabledByPolicy = mController.isVolumeRestricted();
|
||||
checkIfRestrictionEnforced(state, UserManager.DISALLOW_ADJUST_VOLUME);
|
||||
checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_ADJUST_VOLUME);
|
||||
switch (zen) {
|
||||
case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
|
||||
state.icon = ResourceIcon.get(R.drawable.ic_qs_dnd_on);
|
||||
|
||||
@@ -68,8 +68,7 @@ public class HotspotTile extends QSTile<QSTile.BooleanState> {
|
||||
protected void handleUpdateState(BooleanState state, Object arg) {
|
||||
state.label = mContext.getString(R.string.quick_settings_hotspot_label);
|
||||
|
||||
state.disabledByPolicy = mController.isTetheringAllowed();
|
||||
checkIfRestrictionEnforced(state, UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_CONFIG_TETHERING);
|
||||
if (arg instanceof Boolean) {
|
||||
state.value = (boolean) arg;
|
||||
} else {
|
||||
|
||||
@@ -87,8 +87,7 @@ public class LocationTile extends QSTile<QSTile.BooleanState> {
|
||||
// bug is fixed, this should be reverted to only hiding it on secure lock screens:
|
||||
// state.visible = !(mKeyguard.isSecure() && mKeyguard.isShowing());
|
||||
state.value = locationEnabled;
|
||||
state.disabledByPolicy = mController.isUserLocationRestricted();
|
||||
checkIfRestrictionEnforced(state, UserManager.DISALLOW_SHARE_LOCATION);
|
||||
checkIfRestrictionEnforcedByAdminOnly(state, UserManager.DISALLOW_SHARE_LOCATION);
|
||||
if (locationEnabled) {
|
||||
state.icon = mEnable;
|
||||
state.label = mContext.getString(R.string.quick_settings_location_label);
|
||||
|
||||
@@ -21,7 +21,6 @@ public interface HotspotController {
|
||||
void removeCallback(Callback callback);
|
||||
boolean isHotspotEnabled();
|
||||
void setHotspotEnabled(boolean enabled);
|
||||
boolean isTetheringAllowed();
|
||||
|
||||
public interface Callback {
|
||||
void onHotspotChanged(boolean enabled);
|
||||
|
||||
@@ -16,15 +16,12 @@
|
||||
|
||||
package com.android.systemui.statusbar.policy;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
@@ -40,8 +37,6 @@ public class HotspotControllerImpl implements HotspotController {
|
||||
private final Receiver mReceiver = new Receiver();
|
||||
private final ConnectivityManager mConnectivityManager;
|
||||
private final Context mContext;
|
||||
private final UserManager mUserManager;
|
||||
private final int mCurrentUser;
|
||||
|
||||
private int mHotspotState;
|
||||
|
||||
@@ -49,8 +44,6 @@ public class HotspotControllerImpl implements HotspotController {
|
||||
mContext = context;
|
||||
mConnectivityManager = (ConnectivityManager) context.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
mCurrentUser = ActivityManager.getCurrentUser();
|
||||
}
|
||||
|
||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||
@@ -95,12 +88,6 @@ public class HotspotControllerImpl implements HotspotController {
|
||||
return mHotspotState == WifiManager.WIFI_AP_STATE_ENABLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTetheringAllowed() {
|
||||
return !mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING,
|
||||
UserHandle.of(mCurrentUser));
|
||||
}
|
||||
|
||||
static final class OnStartTetheringCallback extends
|
||||
ConnectivityManager.OnStartTetheringCallback {
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,6 @@ public interface LocationController {
|
||||
boolean setLocationEnabled(boolean enabled);
|
||||
void addSettingsChangedCallback(LocationSettingsChangeCallback cb);
|
||||
void removeSettingsChangedCallback(LocationSettingsChangeCallback cb);
|
||||
boolean isUserLocationRestricted();
|
||||
|
||||
/**
|
||||
* A callback for change in location settings (the user has enabled/disabled location).
|
||||
|
||||
@@ -52,7 +52,6 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
|
||||
private AppOpsManager mAppOpsManager;
|
||||
private StatusBarManager mStatusBarManager;
|
||||
private final int mCurrentUser;
|
||||
|
||||
private boolean mAreActiveLocationRequests;
|
||||
|
||||
@@ -74,7 +73,6 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
|
||||
mStatusBarManager
|
||||
= (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
|
||||
mCurrentUser = ActivityManager.getCurrentUser();
|
||||
|
||||
// Examine the current location state and initialize the status view.
|
||||
updateActiveLocationRequests();
|
||||
@@ -105,6 +103,10 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
* @return true if attempt to change setting was successful.
|
||||
*/
|
||||
public boolean setLocationEnabled(boolean enabled) {
|
||||
int currentUserId = ActivityManager.getCurrentUser();
|
||||
if (isUserLocationRestricted(currentUserId)) {
|
||||
return false;
|
||||
}
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
// When enabling location, a user consent dialog will pop up, and the
|
||||
// setting won't be fully enabled until the user accepts the agreement.
|
||||
@@ -113,7 +115,7 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
// QuickSettings always runs as the owner, so specifically set the settings
|
||||
// for the current foreground user.
|
||||
return Settings.Secure
|
||||
.putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, mCurrentUser);
|
||||
.putIntForUser(cr, Settings.Secure.LOCATION_MODE, mode, currentUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,10 +133,10 @@ public class LocationControllerImpl extends BroadcastReceiver implements Locatio
|
||||
/**
|
||||
* Returns true if the current user is restricted from using location.
|
||||
*/
|
||||
public boolean isUserLocationRestricted() {
|
||||
private boolean isUserLocationRestricted(int userId) {
|
||||
final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
return um.hasUserRestriction(UserManager.DISALLOW_SHARE_LOCATION,
|
||||
UserHandle.of(mCurrentUser));
|
||||
UserHandle.of(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -210,12 +210,16 @@ public class UserSwitcherController {
|
||||
}
|
||||
}
|
||||
|
||||
boolean systemCanCreateUsers = !mUserManager.hasBaseUserRestriction(
|
||||
UserManager.DISALLOW_ADD_USER, UserHandle.SYSTEM);
|
||||
boolean currentUserCanCreateUsers = currentUserInfo != null
|
||||
&& (currentUserInfo.isAdmin()
|
||||
|| currentUserInfo.id == UserHandle.USER_SYSTEM);
|
||||
boolean canCreateGuest = (currentUserCanCreateUsers || addUsersWhenLocked)
|
||||
|| currentUserInfo.id == UserHandle.USER_SYSTEM)
|
||||
&& systemCanCreateUsers;
|
||||
boolean anyoneCanCreateUsers = systemCanCreateUsers && addUsersWhenLocked;
|
||||
boolean canCreateGuest = (currentUserCanCreateUsers || anyoneCanCreateUsers)
|
||||
&& guestRecord == null;
|
||||
boolean canCreateUser = (currentUserCanCreateUsers || addUsersWhenLocked)
|
||||
boolean canCreateUser = (currentUserCanCreateUsers || anyoneCanCreateUsers)
|
||||
&& mUserManager.canAddMoreUsers();
|
||||
boolean createIsRestricted = !addUsersWhenLocked;
|
||||
|
||||
@@ -225,7 +229,7 @@ public class UserSwitcherController {
|
||||
guestRecord = new UserRecord(null /* info */, null /* picture */,
|
||||
true /* isGuest */, false /* isCurrent */,
|
||||
false /* isAddUser */, createIsRestricted);
|
||||
checkIfAddUserDisallowed(guestRecord);
|
||||
checkIfAddUserDisallowedByAdminOnly(guestRecord);
|
||||
records.add(guestRecord);
|
||||
}
|
||||
} else {
|
||||
@@ -238,7 +242,7 @@ public class UserSwitcherController {
|
||||
UserRecord addUserRecord = new UserRecord(null /* info */, null /* picture */,
|
||||
false /* isGuest */, false /* isCurrent */, true /* isAddUser */,
|
||||
createIsRestricted);
|
||||
checkIfAddUserDisallowed(addUserRecord);
|
||||
checkIfAddUserDisallowedByAdminOnly(addUserRecord);
|
||||
records.add(addUserRecord);
|
||||
}
|
||||
|
||||
@@ -615,10 +619,11 @@ public class UserSwitcherController {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfAddUserDisallowed(UserRecord record) {
|
||||
private void checkIfAddUserDisallowedByAdminOnly(UserRecord record) {
|
||||
EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(mContext,
|
||||
UserManager.DISALLOW_ADD_USER, ActivityManager.getCurrentUser());
|
||||
if (admin != null) {
|
||||
if (admin != null && !RestrictedLockUtils.hasBaseUserRestriction(mContext,
|
||||
UserManager.DISALLOW_ADD_USER, ActivityManager.getCurrentUser())) {
|
||||
record.isDisabledByAdmin = true;
|
||||
record.enforcedAdmin = admin;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user