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:
Quang Anh Luong
2024-07-18 14:25:15 +09:00
committed by Quang Luong
parent 5751c90a3a
commit 47a83c7ed7
4 changed files with 26 additions and 26 deletions

View File

@@ -17,6 +17,7 @@
package com.android.settings.wifi.details2;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import androidx.annotation.NonNull;
@@ -98,30 +99,30 @@ public class WifiPrivacyPreferenceController2 extends BasePreferenceController i
private static final int PREF_RANDOMIZATION_NONE = 1;
/**
* Returns preference index value.
* Translates a WifiEntry.Privacy value to the matching preference index value.
*
* @param macRandomized is mac randomized value
* @param privacy WifiEntry.Privacy value
* @return index value of preference
*/
public static int translateMacRandomizedValueToPrefValue(int macRandomized) {
return (macRandomized == WifiEntry.PRIVACY_RANDOMIZED_MAC)
public static int translateWifiEntryPrivacyToPrefValue(@WifiEntry.Privacy int privacy) {
return (privacy == WifiEntry.PRIVACY_RANDOMIZED_MAC)
? PREF_RANDOMIZATION_PERSISTENT : PREF_RANDOMIZATION_NONE;
}
/**
* Returns mac randomized value.
* Translates the pref value to WifiConfiguration.MacRandomizationSetting value
*
* @param prefMacRandomized is preference index value
* @return mac randomized value
* @return WifiConfiguration.MacRandomizationSetting value
*/
public static int translatePrefValueToMacRandomizedValue(int prefMacRandomized) {
public static int translatePrefValueToWifiConfigSetting(int prefMacRandomized) {
return (prefMacRandomized == PREF_RANDOMIZATION_PERSISTENT)
? WifiEntry.PRIVACY_RANDOMIZED_MAC : WifiEntry.PRIVACY_DEVICE_MAC;
? WifiConfiguration.RANDOMIZATION_AUTO : WifiConfiguration.RANDOMIZATION_NONE;
}
private void updateSummary(ListPreference preference, int macRandomized) {
// Translates value here to set RANDOMIZATION_PERSISTENT as first item in UI for better UX.
final int prefMacRandomized = translateMacRandomizedValueToPrefValue(macRandomized);
final int prefMacRandomized = translateWifiEntryPrivacyToPrefValue(macRandomized);
preference.setSummary(preference.getEntries()[prefMacRandomized]);
}
}