Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df4bb2a8 authored by phweiss's avatar phweiss
Browse files

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
parent 84040fdb
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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
        if (!restricted) {
            handleStateChanged(mLocalAdapter.getBluetoothState());
        }

        mSwitchWidget.startListening();
        mContext.registerReceiver(mReceiver, mIntentFilter);
+20 −1
Original line number Diff line number Diff line
@@ -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);
    }

}