From 33f77f08365873040980424649a9fe257cde7b1c Mon Sep 17 00:00:00 2001 From: Quang Luong Date: Fri, 10 Apr 2020 17:54:18 -0700 Subject: [WifiTrackerLib] Use WifiInfo RSSI for connected entry Use the rssi from WifiInfo instead of relying on the scan result rssi if we're connected. This fixes connected entries disappearing due to missed scans, since the rssi from WifiInfo will prevent the entry from being marked as unreachable. Bug: 152623244 Bug: 151344151 Test: manually verify RSSI is being updated in wifi picker Change-Id: Iefe282b1a9d9ec5fc5706e9095a65b9c7dd5fe12 --- .../android/wifitrackerlib/BaseWifiTracker.java | 11 ++++++++++ .../PasspointNetworkDetailsTracker.java | 7 +++++++ .../StandardNetworkDetailsTracker.java | 7 +++++++ .../android/wifitrackerlib/StandardWifiEntry.java | 10 +++++---- .../android/wifitrackerlib/WifiPickerTracker.java | 24 ++++++++++++++-------- 5 files changed, 46 insertions(+), 13 deletions(-) (limited to 'libs') diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java index 2c749ad2e..bc551c20d 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/BaseWifiTracker.java @@ -109,6 +109,8 @@ public class BaseWifiTracker implements LifecycleObserver { handleConfiguredNetworksChangedAction(intent); } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { handleNetworkStateChangedAction(intent); + } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) { + handleRssiChangedAction(); } } }; @@ -199,6 +201,7 @@ public class BaseWifiTracker implements LifecycleObserver { filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION); filter.addAction(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION); filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); + filter.addAction(WifiManager.RSSI_CHANGED_ACTION); mContext.registerReceiver(mBroadcastReceiver, filter, /* broadcastPermission */ null, mWorkerHandler); mConnectivityManager.registerNetworkCallback(mNetworkRequest, mNetworkCallback, @@ -278,6 +281,14 @@ public class BaseWifiTracker implements LifecycleObserver { // Do nothing. } + /** + * Handle receiving the WifiManager.RSSI_CHANGED_ACTION broadcast + */ + @WorkerThread + protected void handleRssiChangedAction() { + // Do nothing. + } + /** * Handle link property changes for the current connected Wifi network. */ diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java index a5b489a72..22d200fc2 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/PasspointNetworkDetailsTracker.java @@ -117,6 +117,13 @@ class PasspointNetworkDetailsTracker extends NetworkDetailsTracker { conditionallyUpdateConfig(); } + @WorkerThread + @Override + protected void handleRssiChangedAction() { + mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), + mConnectivityManager.getActiveNetworkInfo()); + } + @WorkerThread @Override protected void handleNetworkStateChangedAction(@NonNull Intent intent) { diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java index 68f58ddc3..65560d60f 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardNetworkDetailsTracker.java @@ -130,6 +130,13 @@ class StandardNetworkDetailsTracker extends NetworkDetailsTracker { (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO)); } + @WorkerThread + @Override + protected void handleRssiChangedAction() { + mChosenEntry.updateConnectionInfo(mWifiManager.getConnectionInfo(), + mConnectivityManager.getActiveNetworkInfo()); + } + @WorkerThread @Override protected void handleLinkPropertiesChanged(@Nullable LinkProperties linkProperties) { diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java index 5f8d44ddd..e6680a917 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/StandardWifiEntry.java @@ -627,14 +627,16 @@ public class StandardWifiEntry extends WifiEntry { } final ScanResult bestScanResult = getBestScanResultByLevel(scanResults); - if (bestScanResult == null) { - mLevel = WIFI_LEVEL_UNREACHABLE; - } else { - mLevel = mWifiManager.calculateSignalLevel(bestScanResult.level); + if (bestScanResult != null) { updateEapType(bestScanResult); updatePskType(bestScanResult); } + if (getConnectedState() == CONNECTED_STATE_DISCONNECTED) { + mLevel = bestScanResult != null + ? mWifiManager.calculateSignalLevel(bestScanResult.level) + : WIFI_LEVEL_UNREACHABLE; + } notifyOnUpdated(); } diff --git a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java index c08b47cd1..86845c7b4 100644 --- a/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java +++ b/libs/WifiTrackerLib/src/com/android/wifitrackerlib/WifiPickerTracker.java @@ -187,10 +187,6 @@ public class WifiPickerTracker extends BaseWifiTracker { final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); updateConnectionInfo(wifiInfo, networkInfo); - // Create a StandardWifiEntry for the current connection if there are no scan results yet. - conditionallyCreateConnectedStandardWifiEntry(wifiInfo, networkInfo); - conditionallyCreateConnectedSuggestedWifiEntry(wifiInfo, networkInfo); - conditionallyCreateConnectedPasspointWifiEntry(wifiInfo, networkInfo); handleLinkPropertiesChanged(mConnectivityManager.getLinkProperties( mWifiManager.getCurrentNetwork())); notifyOnNumSavedNetworksChanged(); @@ -222,7 +218,7 @@ public class WifiPickerTracker extends BaseWifiTracker { final WifiConfiguration config = (WifiConfiguration) intent.getExtra(WifiManager.EXTRA_WIFI_CONFIGURATION); - if (config != null && !config.isPasspoint() && !config.fromWifiNetworkSuggestion) { + if (config != null && !config.isEphemeral() && !config.isPasspoint()) { updateStandardWifiEntryConfig( config, (Integer) intent.getExtra(WifiManager.EXTRA_CHANGE_REASON)); } else { @@ -250,13 +246,19 @@ public class WifiPickerTracker extends BaseWifiTracker { final NetworkInfo networkInfo = (NetworkInfo) intent.getExtra(WifiManager.EXTRA_NETWORK_INFO); updateConnectionInfo(wifiInfo, networkInfo); - // Create a StandardWifiEntry for the current connection if there are no scan results yet. - conditionallyCreateConnectedStandardWifiEntry(wifiInfo, networkInfo); - conditionallyCreateConnectedSuggestedWifiEntry(wifiInfo, networkInfo); - conditionallyCreateConnectedPasspointWifiEntry(wifiInfo, networkInfo); updateWifiEntries(); } + @WorkerThread + @Override + protected void handleRssiChangedAction() { + if (mConnectedWifiEntry != null) { + final WifiInfo wifiInfo = mWifiManager.getConnectionInfo(); + final NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo(); + mConnectedWifiEntry.updateConnectionInfo(wifiInfo, networkInfo); + } + } + @WorkerThread @Override protected void handleLinkPropertiesChanged(@Nullable LinkProperties linkProperties) { @@ -641,6 +643,10 @@ public class WifiPickerTracker extends BaseWifiTracker { for (WifiEntry entry : mOsuWifiEntryCache.values()) { entry.updateConnectionInfo(wifiInfo, networkInfo); } + // Create a StandardWifiEntry for the current connection if there are no scan results yet. + conditionallyCreateConnectedStandardWifiEntry(wifiInfo, networkInfo); + conditionallyCreateConnectedSuggestedWifiEntry(wifiInfo, networkInfo); + conditionallyCreateConnectedPasspointWifiEntry(wifiInfo, networkInfo); } /** -- cgit v1.2.3