OSDN Git Service

Stay bound to the most current active scorer.
authorJeremy Joslin <jjoslin@google.com>
Wed, 21 Dec 2016 00:59:26 +0000 (16:59 -0800)
committerJeremy Joslin <jjoslin@google.com>
Wed, 21 Dec 2016 21:44:53 +0000 (13:44 -0800)
This fixes the following issue:

1) Scorer A is active and bound.
2) A change occurs to Scorer A such that it is no longer the selected
   scorer.
3) Scorer B is selected as the scorer and returned whenever
   getActiveScorer() is queried.
4) Scorer A is never unbound because it isn't seen as the active
   scorer.
5) Scorer B is never bound until its package changes in some way (or
   the feature is disabled/enabled).

Test: runtest frameworks-services -c com.android.server.NetworkScoreServiceTest + manual testing.
Change-Id: I40f055df472e2b9e7b07e6979a841dd4c0b794ce
Merged-In: I468a8c02a72f089f1fb778d150d945efe5485b88

services/core/java/com/android/server/NetworkScoreService.java

index c64aa8e..496d5d0 100644 (file)
@@ -159,15 +159,23 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
                     if (DBG) Log.d(TAG, "No active scorers available.");
                     unbindFromScoringServiceIfNeeded();
                 } else if (activeScorer.packageName.equals(scorerPackageName)) {
+                    // The active scoring service changed in some way.
                     if (DBG) {
                         Log.d(TAG, "Possible change to the active scorer: "
                             + activeScorer.packageName);
                     }
-                    // The scoring service changed in some way.
                     if (forceUnbind) {
                         unbindFromScoringServiceIfNeeded();
                     }
                     bindToScoringServiceIfNeeded(activeScorer);
+                } else {
+                    // One of the scoring apps on the device has changed and we may no longer be
+                    // bound to the correct scoring app. The logic in bindToScoringServiceIfNeeded()
+                    // will sort that out to leave us bound to the most recent active scorer.
+                    if (DBG) {
+                        Log.d(TAG, "Binding to " + activeScorer.packageName + " if needed.");
+                    }
+                    bindToScoringServiceIfNeeded(activeScorer);
                 }
             }
         }