summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuang Luong <qal@google.com>2020-06-05 17:51:57 -0700
committerQuang Luong <qal@google.com>2020-06-10 10:39:03 -0700
commit20f739ce0be068971dc13426b03309277efe91fc (patch)
treedfec194bea36e098020153a31086ca4faedb3703
parent6151647754280820ff82760e4111cf6b484f360b (diff)
[WifiTrackerLib] Cache NetworkInfo from NETWORK_STATE_CHANGED
NetworkInfo from the last NETWORK_STATE_CHANGED broadcast should be used instead of relying on NetworkInfo from ConnectivityManager, which is not valid for a currently connecting network. The NetworkInfo from NETWORK_STATE_CHANGED will still be valid for a connecting network. Bug: 158337413 Test: build and verify connecting network in wifi picker has correct connecting status. Change-Id: I32bf312a4b01a48fc6a6b48a5d288e276b2231a5
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java14
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java13
-rw-r--r--libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java13
3 files changed, 21 insertions, 19 deletions
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
index 9bd2a5905..e2d7acc8e 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java
@@ -26,6 +26,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
+import android.net.Network;
import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
import android.net.wifi.ScanResult;
@@ -57,6 +58,7 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
private final PasspointWifiEntry mChosenEntry;
private OsuWifiEntry mOsuWifiEntry;
+ private NetworkInfo mCurrentNetworkInfo;
PasspointNetworkDetailsTracker(@NonNull Lifecycle lifecycle,
@NonNull Context context,
@@ -104,8 +106,9 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
conditionallyUpdateScanResults(true /* lastScanSucceeded */);
conditionallyUpdateConfig();
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
- final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();
- mChosenEntry.updateConnectionInfo(wifiInfo, networkInfo);
+ final Network currentNetwork = mWifiManager.getCurrentNetwork();
+ mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
+ mChosenEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(
mWifiManager.getCurrentNetwork()));
}
@@ -141,16 +144,15 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker {
@WorkerThread
@Override
protected void handleRssiChangedAction() {
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(),
- mConnectivityManager.getActiveNetworkInfo());
+ mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
}
@WorkerThread
@Override
protected void handleNetworkStateChangedAction(@NonNull Intent intent) {
checkNotNull(intent, "Intent cannot be null!");
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(),
- (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO));
+ mCurrentNetworkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
+ mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
}
@WorkerThread
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
index b89c8ab9b..3ef1b4727 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java
@@ -31,6 +31,7 @@ import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;
import android.net.NetworkScoreManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
@@ -55,6 +56,7 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
private final StandardWifiEntry mChosenEntry;
private final boolean mIsNetworkRequest;
+ private NetworkInfo mCurrentNetworkInfo;
StandardNetworkDetailsTracker(@NonNull Lifecycle lifecycle,
@NonNull Context context,
@@ -84,8 +86,8 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
conditionallyUpdateConfig();
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
final Network currentNetwork = mWifiManager.getCurrentNetwork();
- mChosenEntry.updateConnectionInfo(wifiInfo, mConnectivityManager
- .getNetworkInfo(currentNetwork));
+ mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
+ mChosenEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
}
@@ -134,15 +136,14 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker {
@Override
protected void handleNetworkStateChangedAction(@NonNull Intent intent) {
checkNotNull(intent, "Intent cannot be null!");
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(),
- mConnectivityManager.getNetworkInfo(mWifiManager.getCurrentNetwork()));
+ mCurrentNetworkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
+ mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
}
@WorkerThread
@Override
protected void handleRssiChangedAction() {
- mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(),
- mConnectivityManager.getNetworkInfo(mWifiManager.getCurrentNetwork()));
+ mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), mCurrentNetworkInfo);
}
@WorkerThread
diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
index 2b433bb76..bb3a2246a 100644
--- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
+++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java
@@ -96,6 +96,7 @@ public class WifiPickerTracker extends BaseWifiTracker {
// NetworkRequestEntry representing a network that was connected through the NetworkRequest API
private NetworkRequestEntry mNetworkRequestEntry;
+ private NetworkInfo mCurrentNetworkInfo;
// Cache containing saved WifiConfigurations mapped by StandardWifiEntry key
private final Map<String, WifiConfiguration> mWifiConfigCache = new HashMap<>();
// Cache containing suggested WifiConfigurations mapped by StandardWifiEntry key
@@ -192,7 +193,8 @@ public class WifiPickerTracker extends BaseWifiTracker {
conditionallyUpdateScanResults(true /* lastScanSucceeded */);
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
final Network currentNetwork = mWifiManager.getCurrentNetwork();
- updateConnectionInfo(wifiInfo, mConnectivityManager.getNetworkInfo(currentNetwork));
+ mCurrentNetworkInfo = mConnectivityManager.getNetworkInfo(currentNetwork);
+ updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties(currentNetwork));
notifyOnNumSavedNetworksChanged();
notifyOnNumSavedSubscriptionsChanged();
@@ -245,9 +247,8 @@ public class WifiPickerTracker extends BaseWifiTracker {
protected void handleNetworkStateChangedAction(@NonNull Intent intent) {
checkNotNull(intent, "Intent cannot be null!");
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
- final NetworkInfo networkInfo =
- (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
- updateConnectionInfo(wifiInfo, networkInfo);
+ mCurrentNetworkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO);
+ updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
updateWifiEntries();
}
@@ -256,9 +257,7 @@ public class WifiPickerTracker extends BaseWifiTracker {
protected void handleRssiChangedAction() {
if (mConnectedWifiEntry != null) {
final WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
- final NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(
- mWifiManager.getCurrentNetwork());
- mConnectedWifiEntry.updateConnectionInfo(wifiInfo, networkInfo);
+ mConnectedWifiEntry.updateConnectionInfo(wifiInfo, mCurrentNetworkInfo);
}
}