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

Commit 46c72f3c authored by Alex Johnston's avatar Alex Johnston
Browse files

Settings: Disable USB preferences if USB signaling is off

* When developer options is turned
  off and on again, 'Default USB
  configuration' and 'Disable USB
  audio routing' should not be enabled
  if USB data signaling is disabled.

Manual testing:
* Disable USB data signaling
* Verify preferences are disabled
* Turn developer options off and on
* Verify preferences remain disabled

Bug: 180711035
Test: manual testing
      make RunSettingsRoboTests -j ROBOTEST_FILTER=UsbAudioRoutingPreferenceControllerTest
      make RunSettingsRoboTests -j ROBOTEST_FILTER=DefaultUsbConfigurationPreferenceControllerTest
Change-Id: Id08228da812b7534e2217b0c3f30a7ac989f7553
parent caf50d12
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -54,4 +54,11 @@ public class DefaultUsbConfigurationPreferenceController extends
        mPreference.setDisabledByAdmin(
                checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        super.onDeveloperOptionsSwitchEnabled();
        mPreference.setDisabledByAdmin(
                checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -83,4 +83,11 @@ public class UsbAudioRoutingPreferenceController extends DeveloperOptionsPrefere
                Settings.Secure.USB_AUDIO_AUTOMATIC_ROUTING_DISABLED, SETTING_VALUE_OFF);
        ((SwitchPreference) mPreference).setChecked(false);
    }

    @Override
    protected void onDeveloperOptionsSwitchEnabled() {
        super.onDeveloperOptionsSwitchEnabled();
        mPreference.setDisabledByAdmin(
                checkIfUsbDataSignalingIsDisabled(mContext, UserHandle.myUserId()));
    }
}
+23 −0
Original line number Diff line number Diff line
@@ -91,4 +91,27 @@ public class DefaultUsbConfigurationPreferenceControllerTest {
        verify(mPreference).setDisabledByAdmin(eq(new RestrictedLockUtils.EnforcedAdmin(
                TEST_COMPONENT_NAME, null, UserHandle.SYSTEM)));
    }

    @Test
    public void onDeveloperOptionsSwitchEnabled_usbEnabled_shouldNotDisablePreference() {
        when(mDevicePolicyManager.isUsbDataSignalingEnabledForUser(
                UserHandle.myUserId())).thenReturn(true);
        when(mDevicePolicyManager.getProfileOwner()).thenReturn(TEST_COMPONENT_NAME);

        mController.onDeveloperOptionsSwitchEnabled();

        verify(mPreference).setDisabledByAdmin(null);
    }

    @Test
    public void onDeveloperOptionsSwitchEnabled_usbDisabled_shouldDisablePreference() {
        when(mDevicePolicyManager.isUsbDataSignalingEnabledForUser(
                UserHandle.myUserId())).thenReturn(false);
        when(mDevicePolicyManager.getProfileOwner()).thenReturn(TEST_COMPONENT_NAME);

        mController.onDeveloperOptionsSwitchEnabled();

        verify(mPreference).setDisabledByAdmin(eq(new RestrictedLockUtils.EnforcedAdmin(
                TEST_COMPONENT_NAME, null, UserHandle.SYSTEM)));
    }
}
+23 −0
Original line number Diff line number Diff line
@@ -147,4 +147,27 @@ public class UsbAudioRoutingPreferenceControllerTest {
        verify(mPreference).setEnabled(false);
        verify(mPreference).setChecked(false);
    }

    @Test
    public void onDeveloperOptionsSwitchEnabled_usbEnabled_shouldNotDisablePreference() {
        when(mDevicePolicyManager.isUsbDataSignalingEnabledForUser(
                UserHandle.myUserId())).thenReturn(true);
        when(mDevicePolicyManager.getProfileOwner()).thenReturn(TEST_COMPONENT_NAME);

        mController.onDeveloperOptionsSwitchEnabled();

        verify(mPreference).setDisabledByAdmin(null);
    }

    @Test
    public void onDeveloperOptionsSwitchEnabled_usbDisabled_shouldDisablePreference() {
        when(mDevicePolicyManager.isUsbDataSignalingEnabledForUser(
                UserHandle.myUserId())).thenReturn(false);
        when(mDevicePolicyManager.getProfileOwner()).thenReturn(TEST_COMPONENT_NAME);

        mController.onDeveloperOptionsSwitchEnabled();

        verify(mPreference).setDisabledByAdmin(eq(new RestrictedLockUtils.EnforcedAdmin(
                TEST_COMPONENT_NAME, null, UserHandle.SYSTEM)));
    }
}