Refactor permissions code for bluetooth controller enabler
Bluetooth may be disabled for a user. This CL refactors the code that determines this a bit so we can query that without having to have the UI open. Test: robotests still pass Bug: 62022517 Change-Id: Ic0837d21bdc4007a20d6ad138753d4f5d37ceceb Merged-In: I3b54529865e16b7e1640b0adda7f7edb9d1a41f7
This commit is contained in:
@@ -208,12 +208,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
boolean maybeEnforceRestrictions() {
|
boolean maybeEnforceRestrictions() {
|
||||||
EnforcedAdmin admin = mRestrictionUtils.checkIfRestrictionEnforced(
|
EnforcedAdmin admin = getEnforcedAdmin(mRestrictionUtils, mContext);
|
||||||
mContext, UserManager.DISALLOW_BLUETOOTH);
|
|
||||||
if (admin == null) {
|
|
||||||
admin = mRestrictionUtils.checkIfRestrictionEnforced(
|
|
||||||
mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH);
|
|
||||||
}
|
|
||||||
mSwitchWidget.setDisabledByAdmin(admin);
|
mSwitchWidget.setDisabledByAdmin(admin);
|
||||||
if (admin != null) {
|
if (admin != null) {
|
||||||
mSwitchWidget.setChecked(false);
|
mSwitchWidget.setChecked(false);
|
||||||
@@ -225,4 +220,15 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
return admin != null;
|
return admin != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static EnforcedAdmin getEnforcedAdmin(RestrictionUtils mRestrictionUtils,
|
||||||
|
Context mContext) {
|
||||||
|
EnforcedAdmin admin = mRestrictionUtils.checkIfRestrictionEnforced(
|
||||||
|
mContext, UserManager.DISALLOW_BLUETOOTH);
|
||||||
|
if (admin == null) {
|
||||||
|
admin = mRestrictionUtils.checkIfRestrictionEnforced(
|
||||||
|
mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH);
|
||||||
|
}
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
package com.android.settings.testutils.shadow;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import com.android.settings.bluetooth.RestrictionUtils;
|
||||||
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
|
@Implements(RestrictionUtils.class)
|
||||||
|
public class ShadowRestrictionUtils {
|
||||||
|
private static boolean isRestricted = false;
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public EnforcedAdmin checkIfRestrictionEnforced(Context context, String restriction) {
|
||||||
|
if (isRestricted) {
|
||||||
|
return new EnforcedAdmin();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setRestricted(boolean restricted) {
|
||||||
|
isRestricted = restricted;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user