OSDN Git Service

Do not clear scores during stopTracking.
authorSundeep Ghuman <sghuman@google.com>
Mon, 26 Jun 2017 23:05:40 +0000 (16:05 -0700)
committerSundeep Ghuman <sghuman@google.com>
Thu, 13 Jul 2017 05:52:59 +0000 (05:52 +0000)
Bug: b/63034725
Test: runtest --path
frameworks/base/packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java

Change-Id: Ic15c7f42ec9a3883e8ba34194d9a9410457e4399
(cherry picked from commit 4bb84116636b51bf6925580df569fdeedf6061ae)

packages/SettingsLib/src/com/android/settingslib/wifi/WifiTracker.java
packages/SettingsLib/tests/integ/src/com/android/settingslib/wifi/WifiTrackerTest.java

index 9ccd332..5a35da9 100644 (file)
@@ -365,7 +365,7 @@ public class WifiTracker {
                 mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
                 mRegistered = false;
             }
-            unregisterAndClearScoreCache();
+            unregisterScoreCache();
             pauseScanning();
             mContext.getContentResolver().unregisterContentObserver(mObserver);
 
@@ -375,11 +375,14 @@ public class WifiTracker {
         mStaleScanResults = true;
     }
 
-    private void unregisterAndClearScoreCache() {
+    private void unregisterScoreCache() {
         mNetworkScoreManager.unregisterNetworkScoreCache(NetworkKey.TYPE_WIFI, mScoreCache);
-        mScoreCache.clearScores();
 
-        // Synchronize on mLock to avoid concurrent modification during updateAccessPoints
+        // We do not want to clear the existing scores in the cache, as this method is called during
+        // stop tracking on activity pause. Hence, on resumption we want the ability to show the
+        // last known, potentially stale, scores. However, by clearing requested scores, the scores
+        // will be requested again upon resumption of tracking, and if any changes have occurred
+        // the listeners (UI) will be updated accordingly.
         synchronized (mLock) {
             mRequestedScores.clear();
         }
index b6d0c45..c87d01a 100644 (file)
@@ -473,6 +473,17 @@ public class WifiTrackerTest {
     }
 
     @Test
+    public void stopTracking_shouldNotClearExistingScores()
+            throws InterruptedException {
+        // Start the tracker and inject the initial scan results and then stop tracking
+        WifiTracker tracker =  createTrackerWithImmediateBroadcastsAndInjectInitialScanResults();
+        updateScoresAndWaitForAccessPointsChangedCallback(tracker);
+        tracker.stopTracking();
+
+        assertThat(mScoreCacheCaptor.getValue().getScoredNetwork(NETWORK_KEY_1)).isNotNull();
+    }
+
+    @Test
     public void scoreCacheUpdateScoresShouldTriggerOnAccessPointsChanged()
             throws InterruptedException {
         WifiTracker tracker = createMockedWifiTracker();