Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7df83567 authored by Jeremy Joslin's avatar Jeremy Joslin Committed by Android (Google) Code Review
Browse files

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

parents ace5cf4a da11f5cd
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -105,7 +105,8 @@ public class NetworkScoreManager {
    /**
    /**
     * Broadcast action: the active scorer has been changed. Scorer apps may listen to this to
     * 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
     * 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.
     * this is handled by the system.
     *
     *
     * <p>The new scorer will be specified in {@link #EXTRA_NEW_SCORER}.
     * <p>The new scorer will be specified in {@link #EXTRA_NEW_SCORER}.
+15 −3
Original line number Original line Diff line number Diff line
@@ -234,12 +234,24 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
            // safety as scores should never be compared across apps; in practice, Settings should
            // 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.
            // only be allowing valid apps to be set as scorers, so failure here should be rare.
            clearInternal();
            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);
            boolean result = NetworkScorerAppManager.setActiveScorer(mContext, packageName);
            if (result) {
            if (result) { // new scorer successfully set
                registerPackageReceiverIfNeeded();
                registerPackageReceiverIfNeeded();
                Intent intent = new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED);
                Intent intent = new Intent(NetworkScoreManager.ACTION_SCORER_CHANGED);
                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.putExtra(NetworkScoreManager.EXTRA_NEW_SCORER, packageName);
                mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
                    intent.setPackage(packageName);
                    // TODO: Need to update when we support per-user scorers. http://b/23422763
                    mContext.sendBroadcastAsUser(intent, UserHandle.SYSTEM);
                }
            }
            }
            return result;
            return result;
        } finally {
        } finally {