From 161977998feebf0a855ea56558464470877040cf Mon Sep 17 00:00:00 2001 From: Jeff Davidson Date: Mon, 3 Nov 2014 17:39:54 -0800 Subject: [PATCH] Rename BROADCAST_SCORE_NETWORKS to BROADCAST_NETWORK_PRIVILEGED. This is necessary/desired for two reasons: 1. UX around network scoring shipped with L despite lacking underlying platform support. We do not want network scoring applications to trigger this UX on L devices, and therefore we must break the contract of what defines a network scorer so that apps build against the new contract don't trigger the old UX. 2. As a start towards generalizing the term "score" for a potentially broader role in the future, though that role is very much undefined. Bug: 18160480 Change-Id: If228977513e32e45bc44dbeda24aa18436fdfca6 --- core/java/android/net/NetworkScoreManager.java | 16 ++++++++-------- .../android/net/NetworkScorerAppManager.java | 6 +++--- core/res/AndroidManifest.xml | 9 +++++---- core/res/res/values/strings.xml | 6 +++--- .../android/net/NetworkScorerAppManagerTest.java | 4 ++-- .../com/android/server/NetworkScoreService.java | 16 ++++++++-------- 6 files changed, 29 insertions(+), 28 deletions(-) diff --git a/core/java/android/net/NetworkScoreManager.java b/core/java/android/net/NetworkScoreManager.java index 3f68a4431d256..03a20857fa6b8 100644 --- a/core/java/android/net/NetworkScoreManager.java +++ b/core/java/android/net/NetworkScoreManager.java @@ -41,10 +41,10 @@ import android.os.UserHandle; * * *

The system keeps track of an active scorer application; at any time, only this application @@ -194,8 +194,8 @@ public class NetworkScoreManager { * * @return true if the operation succeeded, or false if the new package is not a valid scorer. * @throws SecurityException if the caller does not hold the - * {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission indicating - * that it can manage scorer applications. + * {@link android.Manifest.permission#BROADCAST_NETWORK_PRIVILEGED} permission + * indicating that it can manage scorer applications. * @hide */ public boolean setActiveScorer(String packageName) throws SecurityException { @@ -228,7 +228,7 @@ public class NetworkScoreManager { * * @return true if the broadcast was sent, or false if there is no active scorer. * @throws SecurityException if the caller does not hold the - * {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission. + * {@link android.Manifest.permission#BROADCAST_NETWORK_PRIVILEGED} permission. * @hide */ public boolean requestScores(NetworkKey[] networks) throws SecurityException { @@ -252,7 +252,7 @@ public class NetworkScoreManager { * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}. * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores. * @throws SecurityException if the caller does not hold the - * {@link android.Manifest.permission#BROADCAST_SCORE_NETWORKS} permission. + * {@link android.Manifest.permission#BROADCAST_NETWORK_PRIVILEGED} permission. * @throws IllegalArgumentException if a score cache is already registered for this type. * @hide */ diff --git a/core/java/android/net/NetworkScorerAppManager.java b/core/java/android/net/NetworkScorerAppManager.java index c33f5ecf59c48..46f7194a0d8e3 100644 --- a/core/java/android/net/NetworkScorerAppManager.java +++ b/core/java/android/net/NetworkScorerAppManager.java @@ -79,7 +79,7 @@ public final class NetworkScorerAppManager { *

* * @return the list of scorers, or the empty list if there are no valid scorers. @@ -98,8 +98,8 @@ public final class NetworkScorerAppManager { // Should never happen with queryBroadcastReceivers, but invalid nonetheless. continue; } - if (!permission.BROADCAST_SCORE_NETWORKS.equals(receiverInfo.permission)) { - // Receiver doesn't require the BROADCAST_SCORE_NETWORKS permission, which means + if (!permission.BROADCAST_NETWORK_PRIVILEGED.equals(receiverInfo.permission)) { + // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which means // anyone could trigger network scoring and flood the framework with score requests. continue; } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 8e0cd52660907..db7174e15f1f4 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -2500,11 +2500,12 @@ android:description="@string/permdesc_broadcastWapPush" android:protectionLevel="signature" /> - - diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 27616c7b143eb..22ea3df52e7ae 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -977,10 +977,10 @@ - send score networks broadcast + send privileged network broadcasts - Allows the app - to broadcast a notification that networks need to be scored. + Allows the app + to send privileged network broadcasts. Never needed for normal apps. diff --git a/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java b/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java index f91671129eb0c..9bb44d00ddc25 100644 --- a/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java +++ b/core/tests/coretests/src/android/net/NetworkScorerAppManagerTest.java @@ -59,7 +59,7 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase { // Package 1 - Valid scorer. Pair package1 = buildResolveInfo("package1", true, true, false); - // Package 2 - Receiver does not have BROADCAST_SCORE_NETWORKS permission. + // Package 2 - Receiver does not have BROADCAST_NETWORK_PRIVILEGED permission. Pair package2 = buildResolveInfo("package2", false, true, false); // Package 3 - App does not have SCORE_NETWORKS permission. @@ -134,7 +134,7 @@ public class NetworkScorerAppManagerTest extends InstrumentationTestCase { resolveInfo.activityInfo.packageName = packageName; resolveInfo.activityInfo.applicationInfo = new ApplicationInfo(); if (hasReceiverPermission) { - resolveInfo.activityInfo.permission = permission.BROADCAST_SCORE_NETWORKS; + resolveInfo.activityInfo.permission = permission.BROADCAST_NETWORK_PRIVILEGED; } ResolveInfo configActivityInfo = null; diff --git a/services/core/java/com/android/server/NetworkScoreService.java b/services/core/java/com/android/server/NetworkScoreService.java index 395e365c421d9..bb91a14309ad4 100644 --- a/services/core/java/com/android/server/NetworkScoreService.java +++ b/services/core/java/com/android/server/NetworkScoreService.java @@ -115,10 +115,10 @@ public class NetworkScoreService extends INetworkScoreService.Stub { @Override public boolean clearScores() { - // Only the active scorer or the system (who can broadcast BROADCAST_SCORE_NETWORKS) should - // be allowed to flush all scores. + // Only the active scorer or the system (who can broadcast BROADCAST_NETWORK_PRIVILEGED) + // should be allowed to flush all scores. if (NetworkScorerAppManager.isCallerActiveScorer(mContext, getCallingUid()) || - mContext.checkCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS) == + mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED) == PackageManager.PERMISSION_GRANTED) { clearInternal(); return true; @@ -130,16 +130,16 @@ public class NetworkScoreService extends INetworkScoreService.Stub { @Override public boolean setActiveScorer(String packageName) { - mContext.enforceCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS, TAG); + mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG); return setScorerInternal(packageName); } @Override public void disableScoring() { - // Only the active scorer or the system (who can broadcast BROADCAST_SCORE_NETOWRKS) should - // be allowed to disable scoring. + // Only the active scorer or the system (who can broadcast BROADCAST_NETWORK_PRIVILEGED) + // should be allowed to disable scoring. if (NetworkScorerAppManager.isCallerActiveScorer(mContext, getCallingUid()) || - mContext.checkCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS) == + mContext.checkCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED) == PackageManager.PERMISSION_GRANTED) { // The return value is discarded here because at this point, the call should always // succeed. The only reason for failure is if the new package is not a valid scorer, but @@ -188,7 +188,7 @@ public class NetworkScoreService extends INetworkScoreService.Stub { @Override public void registerNetworkScoreCache(int networkType, INetworkScoreCache scoreCache) { - mContext.enforceCallingOrSelfPermission(permission.BROADCAST_SCORE_NETWORKS, TAG); + mContext.enforceCallingOrSelfPermission(permission.BROADCAST_NETWORK_PRIVILEGED, TAG); synchronized (mScoreCaches) { if (mScoreCaches.containsKey(networkType)) { throw new IllegalArgumentException(