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

Commit eae2b897 authored by Akshay Thakker's avatar Akshay Thakker Committed by android-build-merger
Browse files

Merge "Exit getAllValidScorers early if not the primary." into mnc-dr-dev

am: ae31e13a

* commit 'ae31e13a':
  Exit getAllValidScorers early if not the primary.
parents 4baa9012 ae31e13a
Loading
Loading
Loading
Loading
+12 −5
Original line number Original line Diff line number Diff line
@@ -33,6 +33,7 @@ import android.util.Log;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
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.
     * @return the list of scorers, or the empty list if there are no valid scorers.
     */
     */
    public static Collection<NetworkScorerAppData> getAllValidScorers(Context context) {
    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();
        PackageManager pm = context.getPackageManager();
        // Only apps installed under the primary user of the device can be scorers.
        // Only apps installed under the primary user of the device can be scorers.
        List<ResolveInfo> receivers =
        List<ResolveInfo> receivers =
@@ -104,8 +110,9 @@ public final class NetworkScorerAppManager {
                continue;
                continue;
            }
            }
            if (!permission.BROADCAST_NETWORK_PRIVILEGED.equals(receiverInfo.permission)) {
            if (!permission.BROADCAST_NETWORK_PRIVILEGED.equals(receiverInfo.permission)) {
                // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which means
                // Receiver doesn't require the BROADCAST_NETWORK_PRIVILEGED permission, which
                // anyone could trigger network scoring and flood the framework with score requests.
                // means anyone could trigger network scoring and flood the framework with score
                // requests.
                continue;
                continue;
            }
            }
            if (pm.checkPermission(permission.SCORE_NETWORKS, receiverInfo.packageName) !=
            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
            // NOTE: loadLabel will attempt to load the receiver's label and fall back to the
            // label if none is present.
            // app label if none is present.
            scorers.add(new NetworkScorerAppData(receiverInfo.packageName,
            scorers.add(new NetworkScorerAppData(receiverInfo.packageName,
                    receiverInfo.applicationInfo.uid, receiverInfo.loadLabel(pm),
                    receiverInfo.applicationInfo.uid, receiverInfo.loadLabel(pm),
                    configurationActivityClassName));
                    configurationActivityClassName));