summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java14
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java14
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java25
-rw-r--r--libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java26
4 files changed, 71 insertions, 8 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
index d873c25e5..71420b9ad 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java
@@ -16,6 +16,7 @@
package com.android.wifitrackerlib;
+import static android.net.wifi.WifiInfo.DEFAULT_MAC_ADDRESS;
import static android.net.wifi.WifiInfo.sanitizeSsid;
import static androidx.core.util.Preconditions.checkNotNull;
@@ -277,16 +278,21 @@ public class PasspointWifiEntry extends WifiEntry implements WifiEntry.WifiEntry
@Override
public String getMacAddress() {
+ if (mWifiInfo != null) {
+ final String wifiInfoMac = mWifiInfo.getMacAddress();
+ if (!TextUtils.isEmpty(wifiInfoMac)
+ && !TextUtils.equals(wifiInfoMac, DEFAULT_MAC_ADDRESS)) {
+ return wifiInfoMac;
+ }
+ }
if (mWifiConfig == null || getPrivacy() != PRIVACY_RANDOMIZED_MAC) {
final String[] factoryMacs = mWifiManager.getFactoryMacAddresses();
if (factoryMacs.length > 0) {
return factoryMacs[0];
- } else {
- return null;
}
- } else {
- return mWifiConfig.getRandomizedMacAddress().toString();
+ return null;
}
+ return mWifiConfig.getRandomizedMacAddress().toString();
}
@Override
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
index 6fef5e961..56cd16503 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java
@@ -20,6 +20,7 @@ import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_NO_CREDENTIALS;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD;
import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLED;
+import static android.net.wifi.WifiInfo.DEFAULT_MAC_ADDRESS;
import static android.net.wifi.WifiInfo.sanitizeSsid;
import static androidx.core.util.Preconditions.checkNotNull;
@@ -312,16 +313,21 @@ public class StandardWifiEntry extends WifiEntry {
@Override
public String getMacAddress() {
+ if (mWifiInfo != null) {
+ final String wifiInfoMac = mWifiInfo.getMacAddress();
+ if (!TextUtils.isEmpty(wifiInfoMac)
+ && !TextUtils.equals(wifiInfoMac, DEFAULT_MAC_ADDRESS)) {
+ return wifiInfoMac;
+ }
+ }
if (mWifiConfig == null || getPrivacy() != PRIVACY_RANDOMIZED_MAC) {
final String[] factoryMacs = mWifiManager.getFactoryMacAddresses();
if (factoryMacs.length > 0) {
return factoryMacs[0];
- } else {
- return null;
}
- } else {
- return mWifiConfig.getRandomizedMacAddress().toString();
+ return null;
}
+ return mWifiConfig.getRandomizedMacAddress().toString();
}
@Override
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
index 80a31e53f..fa7812fe6 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/PasspointWifiEntryTest.java
@@ -221,4 +221,29 @@ public class PasspointWifiEntryTest {
assertThat(entry.getSpeed()).isEqualTo(SPEED_SLOW);
}
+
+ @Test
+ public void testGetMacAddress_wifiInfoAvailable_usesWifiInfoMacAddress() {
+ final String factoryMac = "01:23:45:67:89:ab";
+ final String wifiInfoMac = "11:23:45:67:89:ab";
+ final WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"ssid\"";
+ config.macRandomizationSetting = WifiConfiguration.RANDOMIZATION_NONE;
+ config.FQDN = FQDN;
+ when(mMockWifiManager.getFactoryMacAddresses()).thenReturn(new String[]{factoryMac});
+ WifiInfo wifiInfo = mock(WifiInfo.class);
+ when(wifiInfo.isPasspointAp()).thenReturn(true);
+ when(wifiInfo.getPasspointFqdn()).thenReturn(FQDN);
+ when(wifiInfo.getMacAddress()).thenReturn(wifiInfoMac);
+ NetworkInfo networkInfo =
+ new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
+ networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
+ PasspointWifiEntry entry = new PasspointWifiEntry(mMockContext, mTestHandler,
+ getPasspointConfiguration(), mMockWifiManager, mMockScoreCache,
+ false /* forSavedNetworksPage */);
+
+ entry.updateConnectionInfo(wifiInfo, networkInfo);
+
+ assertThat(entry.getMacAddress()).isEqualTo(wifiInfoMac);
+ }
}
diff --git a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
index ba78b3fa5..81b20348d 100644
--- a/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
+++ b/libs/WifiTrackerLib/tests/src/com/android/wifitrackerlib/StandardWifiEntryTest.java
@@ -479,6 +479,32 @@ public class StandardWifiEntryTest {
}
@Test
+ public void testGetMacAddress_wifiInfoAvailable_usesWifiInfoMacAddress() {
+ final int networkId = 1;
+ final String factoryMac = "01:23:45:67:89:ab";
+ final String wifiInfoMac = "11:23:45:67:89:ab";
+
+ final NetworkInfo networkInfo =
+ new NetworkInfo(ConnectivityManager.TYPE_WIFI, 0 /* subtype */, "WIFI", "");
+ networkInfo.setDetailedState(NetworkInfo.DetailedState.CONNECTED, "", "");
+
+ when(mMockWifiInfo.getNetworkId()).thenReturn(networkId);
+ when(mMockWifiInfo.getMacAddress()).thenReturn(wifiInfoMac);
+ final WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"ssid\"";
+ config.networkId = networkId;
+ config.macRandomizationSetting = WifiConfiguration.RANDOMIZATION_NONE;
+ when(mMockWifiManager.getFactoryMacAddresses()).thenReturn(new String[]{factoryMac});
+ final StandardWifiEntry entry = new StandardWifiEntry(mMockContext, mTestHandler,
+ ssidAndSecurityToStandardWifiEntryKey("ssid", SECURITY_NONE), config,
+ mMockWifiManager, mMockScoreCache, false /* forSavedNetworksPage */);
+
+ entry.updateConnectionInfo(mMockWifiInfo, networkInfo);
+
+ assertThat(entry.getMacAddress()).isEqualTo(wifiInfoMac);
+ }
+
+ @Test
public void testCanShare_securityCanShare_shouldReturnTrue() {
final StandardWifiEntry pskWifiEntry =
getSavedStandardWifiEntry(WifiConfiguration.SECURITY_TYPE_PSK);