Merge "Send explicit broadcasts when the scorer changes." into nyc-dev

am: 7df8356724

* commit '7df8356724efde8af5e280a0a57f7fbe39169aaa':
  Send explicit broadcasts when the scorer changes.
This commit is contained in:
Jeremy Joslin
2016-02-11 19:09:27 +00:00
committed by android-build-merger
2 changed files with 17 additions and 4 deletions

View File

@@ -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.
*
* <p>The new scorer will be specified in {@link #EXTRA_NEW_SCORER}.

View File

@@ -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 {