Fix mac randomization value mismatch
WifiConfigController2 passes in WifiConfiguration.MacRandomizationSetting to methods that expect WifiEntry.Privacy enums, resulting in the wrong values being saved and displayed for the edit dialog. Fix this by making sure the correct WifiEntry values are used. Note that the Network Details Page uses WifiPrivacyPreferenceController2, which uses the correct values. Flag: EXEMPT bugfix Bug: 284230986 Test: atest WifiPrivacyPreferenceController2Test, atest WifiConfigController2Test, manually verify adding a new network saves the config with RANDOMIZATION_AUTO by default and changing the value works correctly. Change-Id: I84dc7cc50d04360aca611ca80ee400a97b693722
This commit is contained in:
committed by
Quang Luong
parent
5751c90a3a
commit
47a83c7ed7
@@ -459,46 +459,45 @@ public class WifiConfigController2Test {
|
||||
public void loadMacRandomizedValue_shouldPersistentAsDefault() {
|
||||
final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
|
||||
final int prefPersist =
|
||||
WifiPrivacyPreferenceController2.translateMacRandomizedValueToPrefValue(
|
||||
WifiConfiguration.RANDOMIZATION_PERSISTENT);
|
||||
WifiPrivacyPreferenceController2.translateWifiEntryPrivacyToPrefValue(
|
||||
WifiEntry.PRIVACY_RANDOMIZED_MAC);
|
||||
|
||||
assertThat(privacySetting.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(privacySetting.getSelectedItemPosition()).isEqualTo(prefPersist);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadSavedMacRandomizedPersistentValue_shouldCorrectMacValue() {
|
||||
checkSavedMacRandomizedValue(WifiConfiguration.RANDOMIZATION_PERSISTENT);
|
||||
public void loadSavedPrivacyRandomizedMacValue_shouldCorrectMacValue() {
|
||||
checkSavedMacRandomizedValue(WifiEntry.PRIVACY_RANDOMIZED_MAC);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadSavedMacRandomizedNoneValue_shouldCorrectMacValue() {
|
||||
checkSavedMacRandomizedValue(WifiConfiguration.RANDOMIZATION_NONE);
|
||||
public void loadSavedPrivacyDeviceMacValue_shouldCorrectMacValue() {
|
||||
checkSavedMacRandomizedValue(WifiEntry.PRIVACY_DEVICE_MAC);
|
||||
}
|
||||
|
||||
private void checkSavedMacRandomizedValue(int macRandomizedValue) {
|
||||
private void checkSavedMacRandomizedValue(@WifiEntry.Privacy int privacy) {
|
||||
when(mWifiEntry.isSaved()).thenReturn(true);
|
||||
final WifiConfiguration mockWifiConfig = spy(new WifiConfiguration());
|
||||
when(mockWifiConfig.getIpConfiguration()).thenReturn(mock(IpConfiguration.class));
|
||||
when(mWifiEntry.getWifiConfiguration()).thenReturn(mockWifiConfig);
|
||||
mockWifiConfig.macRandomizationSetting = macRandomizedValue;
|
||||
when(mWifiEntry.getPrivacy()).thenReturn(privacy);
|
||||
createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
|
||||
|
||||
final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
|
||||
final int expectedPrefValue =
|
||||
WifiPrivacyPreferenceController2.translateMacRandomizedValueToPrefValue(
|
||||
macRandomizedValue);
|
||||
WifiPrivacyPreferenceController2.translateWifiEntryPrivacyToPrefValue(privacy);
|
||||
|
||||
assertThat(privacySetting.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
assertThat(privacySetting.getSelectedItemPosition()).isEqualTo(expectedPrefValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveMacRandomizedValue_noChanged_shouldPersistentAsDefault() {
|
||||
public void saveMacRandomizedValue_noChanged_shouldAutoAsDefault() {
|
||||
createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
|
||||
WifiConfiguration config = mController.getConfig();
|
||||
assertThat(config.macRandomizationSetting).isEqualTo(
|
||||
WifiConfiguration.RANDOMIZATION_PERSISTENT);
|
||||
WifiConfiguration.RANDOMIZATION_AUTO);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -506,7 +505,7 @@ public class WifiConfigController2Test {
|
||||
createController(mWifiEntry, WifiConfigUiBase2.MODE_CONNECT, false);
|
||||
final Spinner privacySetting = mView.findViewById(R.id.privacy_settings);
|
||||
final int prefMacNone =
|
||||
WifiPrivacyPreferenceController2.translateMacRandomizedValueToPrefValue(
|
||||
WifiPrivacyPreferenceController2.translateWifiEntryPrivacyToPrefValue(
|
||||
WifiConfiguration.RANDOMIZATION_NONE);
|
||||
privacySetting.setSelection(prefMacNone);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user