diff --git a/src/com/android/settings/bluetooth/BluetoothEnabler.java b/src/com/android/settings/bluetooth/BluetoothEnabler.java index 6c41f830a12..3d7c5b6c5ba 100644 --- a/src/com/android/settings/bluetooth/BluetoothEnabler.java +++ b/src/com/android/settings/bluetooth/BluetoothEnabler.java @@ -106,7 +106,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh mContext = context; } - maybeEnforceRestrictions(); + final boolean restricted = maybeEnforceRestrictions(); if (mLocalAdapter == null) { mSwitchWidget.setEnabled(false); @@ -114,7 +114,9 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh } // Bluetooth state is not sticky, so set it manually - handleStateChanged(mLocalAdapter.getBluetoothState()); + if (!restricted) { + handleStateChanged(mLocalAdapter.getBluetoothState()); + } mSwitchWidget.startListening(); mContext.registerReceiver(mReceiver, mIntentFilter); diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java index 2d64396bb8c..74c47e237dc 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothEnablerTest.java @@ -24,6 +24,7 @@ import com.android.settings.TestConfig; import com.android.settings.core.instrumentation.MetricsFeatureProvider; import com.android.settings.widget.MasterSwitchController; import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; +import com.android.settingslib.bluetooth.LocalBluetoothAdapter; import com.android.settingslib.bluetooth.LocalBluetoothManager; import org.junit.Before; @@ -58,17 +59,22 @@ public class BluetoothEnablerTest { private MasterSwitchController mMasterSwitchController; @Mock private RestrictionUtils mRestrictionUtils; + @Mock + private LocalBluetoothManager mBluetoothManager; + @Mock + private LocalBluetoothAdapter mBluetoothAdapter; private BluetoothEnabler mBluetoothEnabler; @Before public void setUp() { MockitoAnnotations.initMocks(this); + when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter); mBluetoothEnabler = new BluetoothEnabler( mContext, mMasterSwitchController, mMetricsFeatureProvider, - mock(LocalBluetoothManager.class), + mBluetoothManager, 123, mRestrictionUtils); } @@ -136,4 +142,17 @@ public class BluetoothEnablerTest { verify(mMasterSwitchController).setChecked(false); } + @Test + public void maybeEnforceRestrictions_disallowBluetoothNotOverriden() { + // GIVEN Bluetooth has been disallowed... + when(mRestrictionUtils.checkIfRestrictionEnforced( + mContext, UserManager.DISALLOW_BLUETOOTH)).thenReturn(FAKE_ENFORCED_ADMIN); + when(mRestrictionUtils.checkIfRestrictionEnforced( + mContext, UserManager.DISALLOW_CONFIG_BLUETOOTH)).thenReturn(null); + + mBluetoothEnabler.resume(mContext); + + verify(mMasterSwitchController, never()).setEnabled(true); + } + }