diff options
author | Quang Luong <qal@google.com> | 2020-07-30 14:43:58 -0700 |
---|---|---|
committer | Quang Luong <qal@google.com> | 2020-08-07 23:22:17 +0000 |
commit | 65779e054a210b106029807204f12ff3ceda9d04 (patch) | |
tree | 12de1b9ccef19287c5d92e5052b512d5b8e54d4c /libs/WifiTrackerLib/src | |
parent | 058fc1de39ed8c11473bf9d60aac92dbf21106c0 (diff) | |
download | frameworks_opt_net_wifi-65779e054a210b106029807204f12ff3ceda9d04.tar.gz frameworks_opt_net_wifi-65779e054a210b106029807204f12ff3ceda9d04.tar.bz2 frameworks_opt_net_wifi-65779e054a210b106029807204f12ff3ceda9d04.zip |
[WifiTrackerLib] Use WifiInfo MAC address if available
Always use the mac address from WifiInfo if available so that we are
always displaying the actual mac address of the connection instead of
the address stored in the wificonfig, in case enhanced mac randomization
is enabled.
Bug: 160028657
Test: atest WifiTrackerLibTests
Change-Id: I403957b2ba5a845ed5ddc51fe8b39a087f29456a
(cherry picked from commit 6fd689db23cb2974fa1078d476fe94aa127cec24)
Diffstat (limited to 'libs/WifiTrackerLib/src')
-rw-r--r-- | libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointWifiEntry.java | 14 | ||||
-rw-r--r-- | libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java | 14 |
2 files changed, 20 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 |