diff --git a/core/java/android/net/NetworkScoreManager.java b/core/java/android/net/NetworkScoreManager.java index 3f36d65e577c1..b6fe68af51acf 100644 --- a/core/java/android/net/NetworkScoreManager.java +++ b/core/java/android/net/NetworkScoreManager.java @@ -105,7 +105,8 @@ public class NetworkScoreManager { /** * Broadcast action: the active scorer has been changed. Scorer apps may listen to this to * perform initialization once selected as the active scorer, or clean up unneeded resources - * if another scorer has been selected. Note that it is unnecessary to clear existing scores as + * if another scorer has been selected. This is an explicit broadcast only sent to the + * previous scorer and new scorer. Note that it is unnecessary to clear existing scores as * this is handled by the system. * *
The new scorer will be specified in {@link #EXTRA_NEW_SCORER}. diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java index b984e19387585..879bb6f72895b 100644 --- a/services/core/java/com/android/server/NetworkScoreService.java +++ b/services/core/java/com/android/server/NetworkScoreService.java @@ -234,12 +234,24 @@ public class NetworkScoreService extends INetworkScoreService.Stub { // safety as scores should never be compared across apps; in practice, Settings should // only be allowing valid apps to be set as scorers, so failure here should be rare. clearInternal(); + // Get the scorer that is about to be replaced, if any, so we can notify it directly. + NetworkScorerAppData prevScorer = NetworkScorerAppManager.getActiveScorer(mContext); boolean result = NetworkScorerAppManager.setActiveScorer(mContext, packageName); - if (result) { + if (result) { // new scorer successfully set registerPackageReceiverIfNeeded(); Intent intent = new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED); - intent.putExtra(NetworkScoreManager.EXTRA_NEW_SCORER, packageName); - mContext.sendBroadcastAsUser(intent, UserHandle.ALL); + if (prevScorer != null) { // Directly notify the old scorer. + intent.setPackage(prevScorer.mPackageName); + // TODO: Need to update when we support per-user scorers. http://b/23422763 + mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM); + } + + if (packageName != null) { // Then notify the new scorer + intent.putExtra(NetworkScoreManager.EXTRA_NEW_SCORER, packageName); + intent.setPackage(packageName); + // TODO: Need to update when we support per-user scorers. http://b/23422763 + mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM); + } } return result; } finally {