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:
@@ -106,7 +106,7 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeEnforceRestrictions();
|
final boolean restricted = maybeEnforceRestrictions();
|
||||||
|
|
||||||
if (mLocalAdapter == null) {
|
if (mLocalAdapter == null) {
|
||||||
mSwitchWidget.setEnabled(false);
|
mSwitchWidget.setEnabled(false);
|
||||||
@@ -114,7 +114,9 @@ public final class BluetoothEnabler implements SwitchWidgetController.OnSwitchCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bluetooth state is not sticky, so set it manually
|
// Bluetooth state is not sticky, so set it manually
|
||||||
handleStateChanged(mLocalAdapter.getBluetoothState());
|
if (!restricted) {
|
||||||
|
handleStateChanged(mLocalAdapter.getBluetoothState());
|
||||||
|
}
|
||||||
|
|
||||||
mSwitchWidget.startListening();
|
mSwitchWidget.startListening();
|
||||||
mContext.registerReceiver(mReceiver, mIntentFilter);
|
mContext.registerReceiver(mReceiver, mIntentFilter);
|
||||||
|
@@ -24,6 +24,7 @@ import com.android.settings.TestConfig;
|
|||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.widget.MasterSwitchController;
|
import com.android.settings.widget.MasterSwitchController;
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
|
import com.android.settingslib.bluetooth.LocalBluetoothAdapter;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -58,17 +59,22 @@ public class BluetoothEnablerTest {
|
|||||||
private MasterSwitchController mMasterSwitchController;
|
private MasterSwitchController mMasterSwitchController;
|
||||||
@Mock
|
@Mock
|
||||||
private RestrictionUtils mRestrictionUtils;
|
private RestrictionUtils mRestrictionUtils;
|
||||||
|
@Mock
|
||||||
|
private LocalBluetoothManager mBluetoothManager;
|
||||||
|
@Mock
|
||||||
|
private LocalBluetoothAdapter mBluetoothAdapter;
|
||||||
|
|
||||||
private BluetoothEnabler mBluetoothEnabler;
|
private BluetoothEnabler mBluetoothEnabler;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
when(mBluetoothManager.getBluetoothAdapter()).thenReturn(mBluetoothAdapter);
|
||||||
mBluetoothEnabler = new BluetoothEnabler(
|
mBluetoothEnabler = new BluetoothEnabler(
|
||||||
mContext,
|
mContext,
|
||||||
mMasterSwitchController,
|
mMasterSwitchController,
|
||||||
mMetricsFeatureProvider,
|
mMetricsFeatureProvider,
|
||||||
mock(LocalBluetoothManager.class),
|
mBluetoothManager,
|
||||||
123,
|
123,
|
||||||
mRestrictionUtils);
|
mRestrictionUtils);
|
||||||
}
|
}
|
||||||
@@ -136,4 +142,17 @@ public class BluetoothEnablerTest {
|
|||||||
verify(mMasterSwitchController).setChecked(false);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user