Bluetooth Settings Policy Transparency

If handleStateChanged() is called after
maybeEnforceRestriction, the disabled switch will be
enabled again, only to be disabled when the user touches it.

Bug: 37737621
Test: make RunSettingsRoboTests -j40 ROBOTEST_FILTER=*BluetoothEnablerTest

Change-Id: I3086806dfd6d911d6d7fca1f1d30fa7d8b8757d1
This commit is contained in:
phweiss
2017-06-02 19:04:56 +02:00
parent 84040fdb8b
commit df4bb2a84f
2 changed files with 24 additions and 3 deletions

View File

@@ -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);
}
}