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
This commit is contained in:
Alex Johnston
2021-03-17 15:18:00 +00:00
parent caf50d1203
commit 46c72f3cac
4 changed files with 60 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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