summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Joslin <jjoslin@google.com>2015-12-17 17:38:04 -0800
committerAddison Nuding <addison@google.com>2016-02-27 00:32:18 +0000
commitefb0c507481d4e7bb3b003d35c383631ec8cf7df (patch)
tree4f727960f3fbfc9caee8a5c9fb7d1dfef4995518
parent2e0fb0f559374102ebb3963819f6f3a816e77709 (diff)
downloadbase-efb0c507481d4e7bb3b003d35c383631ec8cf7df.tar.gz
Exit getAllValidScorers early if not the primary.
This fixes the crash that occurs when getAllValidScorers() is invoked by a non-primary user when a scorer is active. BUG: 23040221 Change-Id: I42c9e18d74389be3191258ca5626f2c433ca7cc7 (cherry picked from commit 5b294b45d0d7afbed71fd2e59342c5ad7b8b7d76) (cherry picked from commit 44d550c2d1343887371d9013e202c3436d621dad)
-rw-r--r--core/java/android/net/NetworkScorerAppManager.java17
1 files changed, 12 insertions, 5 deletions
diff --git a/core/java/android/net/NetworkScorerAppManager.java b/core/java/android/net/NetworkScorerAppManager.java
index 29daf352e1d3..5880e5dcccef 100644
--- a/core/java/android/net/NetworkScorerAppManager.java
+++ b/core/java/android/net/NetworkScorerAppManager.java
@@ -33,6 +33,7 @@ import android.util.Log;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
/**
@@ -90,8 +91,13 @@ public final class NetworkScorerAppManager {
* @return the list of scorers, or the empty list if there are no valid scorers.
*/
public static Collection<NetworkScorerAppData> getAllValidScorers(Context context) {
- List<NetworkScorerAppData> scorers = new ArrayList<>();
+ // Network scorer apps can only run as the primary user so exit early if we're not the
+ // primary user.
+ if (UserHandle.getCallingUserId() != 0 /*USER_SYSTEM*/) {
+ return Collections.emptyList();
+ }
+ List<NetworkScorerAppData> scorers = new ArrayList<>();
PackageManager pm = context.getPackageManager();
// Only apps installed under the primary user of the device can be scorers.
List<ResolveInfo> receivers =
@@ -104,8 +110,9 @@ public final class NetworkScorerAppManager {
continue;
}
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.
+ // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which
+ // means anyone could trigger network scoring and flood the framework with score
+ // requests.
continue;
}
if (pm.checkPermission(permission.SCORE_NETWORKS, receiverInfo.packageName) !=
@@ -127,8 +134,8 @@ public final class NetworkScorerAppManager {
}
}
- // NOTE: loadLabel will attempt to load the receiver's label and fall back to the app
- // label if none is present.
+ // NOTE: loadLabel will attempt to load the receiver's label and fall back to the
+ // app label if none is present.
scorers.add(new NetworkScorerAppData(receiverInfo.packageName,
receiverInfo.applicationInfo.uid, receiverInfo.loadLabel(pm),
configurationActivityClassName));