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

Commit a9f933e5 authored by Jeremy Joslin's avatar Jeremy Joslin
Browse files

Revert permission check on setActiveScorer.

Reverted to the pre-O behavior of allowing the call if the caller
has the SCORE_NETWORKS permission.

Test: runtest frameworks-services -c com.android.server.NetworkScoreServiceTest
Bug: 37722313
Change-Id: I54a99dde364d6a5c88d35072922020542c6ae003
parent 7aa0b0d9
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -45,7 +45,7 @@ interface INetworkScoreService
     * Set the active scorer and clear existing scores.
     * Set the active scorer and clear existing scores.
     * @param packageName the package name of the new scorer to use.
     * @param packageName the package name of the new scorer to use.
     * @return true if the operation succeeded, or false if the new package is not a valid scorer.
     * @return true if the operation succeeded, or false if the new package is not a valid scorer.
     * @throws SecurityException if the caller is not the system.
     * @throws SecurityException if the caller is not the system or a network scorer.
     */
     */
    boolean setActiveScorer(in String packageName);
    boolean setActiveScorer(in String packageName);


+8 −34
Original line number Original line Diff line number Diff line
@@ -16,27 +16,20 @@


package android.net;
package android.net;


import static android.net.NetworkRecommendationProvider.EXTRA_RECOMMENDATION_RESULT;
import android.Manifest.permission;

import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SdkConstant.SdkConstantType;
import android.annotation.SystemApi;
import android.annotation.SystemApi;
import android.content.Context;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.ServiceManager.ServiceNotFoundException;
import com.android.internal.util.Preconditions;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.List;
import java.util.concurrent.CompletableFuture;


/**
/**
 * Class that manages communication between network subsystems and a network scorer.
 * Class that manages communication between network subsystems and a network scorer.
@@ -49,9 +42,9 @@ import java.util.concurrent.CompletableFuture;
 *
 *
 * <p>A network scorer is any application which:
 * <p>A network scorer is any application which:
 * <ul>
 * <ul>
 * <li>Declares the {@link android.Manifest.permission#SCORE_NETWORKS} permission.
 * <li>Declares the {@link permission#SCORE_NETWORKS} permission.
 * <li>Include a Service for the {@link #ACTION_RECOMMEND_NETWORKS} action
 * <li>Include a Service for the {@link #ACTION_RECOMMEND_NETWORKS} action
 *     protected by the {@link android.Manifest.permission#BIND_NETWORK_RECOMMENDATION_SERVICE}
 *     protected by the {@link permission#BIND_NETWORK_RECOMMENDATION_SERVICE}
 *     permission.
 *     permission.
 * </ul>
 * </ul>
 *
 *
@@ -319,7 +312,7 @@ public class NetworkScoreManager {
     *
     *
     * @return true if the operation succeeded, or false if the new package is not a valid scorer.
     * @return true if the operation succeeded, or false if the new package is not a valid scorer.
     * @throws SecurityException if the caller is not a system process or does not hold the
     * @throws SecurityException if the caller is not a system process or does not hold the
     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission
     *         {@link permission#SCORE_NETWORKS} permission
     * @hide
     * @hide
     */
     */
    @SystemApi
    @SystemApi
@@ -351,7 +344,7 @@ public class NetworkScoreManager {
     *
     *
     * @return true if the broadcast was sent, or false if there is no active scorer.
     * @return true if the broadcast was sent, or false if there is no active scorer.
     * @throws SecurityException if the caller does not hold the
     * @throws SecurityException if the caller does not hold the
     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
     * @hide
     * @hide
     */
     */
    public boolean requestScores(NetworkKey[] networks) throws SecurityException {
    public boolean requestScores(NetworkKey[] networks) throws SecurityException {
@@ -368,7 +361,7 @@ public class NetworkScoreManager {
     * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
     * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
     * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
     * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
     * @throws SecurityException if the caller does not hold the
     * @throws SecurityException if the caller does not hold the
     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
     * @throws IllegalArgumentException if a score cache is already registered for this type.
     * @throws IllegalArgumentException if a score cache is already registered for this type.
     * @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE.
     * @deprecated equivalent to registering for cache updates with CACHE_FILTER_NONE.
     * @hide
     * @hide
@@ -385,7 +378,7 @@ public class NetworkScoreManager {
     * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
     * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores
     * @param filterType the {@link CacheUpdateFilter} to apply
     * @param filterType the {@link CacheUpdateFilter} to apply
     * @throws SecurityException if the caller does not hold the
     * @throws SecurityException if the caller does not hold the
     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
     * @throws IllegalArgumentException if a score cache is already registered for this type.
     * @throws IllegalArgumentException if a score cache is already registered for this type.
     * @hide
     * @hide
     */
     */
@@ -404,7 +397,7 @@ public class NetworkScoreManager {
     * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
     * @param networkType the type of network this cache can handle. See {@link NetworkKey#type}.
     * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
     * @param scoreCache implementation of {@link INetworkScoreCache} to store the scores.
     * @throws SecurityException if the caller does not hold the
     * @throws SecurityException if the caller does not hold the
     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
     *         {@link permission#REQUEST_NETWORK_SCORES} permission.
     * @throws IllegalArgumentException if a score cache is already registered for this type.
     * @throws IllegalArgumentException if a score cache is already registered for this type.
     * @hide
     * @hide
     */
     */
@@ -416,25 +409,6 @@ public class NetworkScoreManager {
        }
        }
    }
    }


    /**
     * Request a recommendation for which network to connect to.
     *
     * <p>It is not safe to call this method from the main thread.
     *
     * @param request a {@link RecommendationRequest} instance containing additional
     *                request details
     * @return a {@link RecommendationResult} instance containing the recommended network
     *         to connect to
     * @throws SecurityException if the caller does not hold the
     *         {@link android.Manifest.permission#REQUEST_NETWORK_SCORES} permission.
     * @hide
     * @deprecated to be removed.
     */
    public RecommendationResult requestRecommendation(RecommendationRequest request)
            throws SecurityException {
        return null;
    }

    /**
    /**
     * Determine whether the application with the given UID is the enabled scorer.
     * Determine whether the application with the given UID is the enabled scorer.
     *
     *
+7 −2
Original line number Original line Diff line number Diff line
@@ -631,6 +631,11 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
                 PackageManager.PERMISSION_GRANTED;
                 PackageManager.PERMISSION_GRANTED;
    }
    }


    private boolean callerCanScoreNetworks() {
        return mContext.checkCallingOrSelfPermission(permission.SCORE_NETWORKS) ==
                PackageManager.PERMISSION_GRANTED;
    }

    @Override
    @Override
    public boolean clearScores() {
    public boolean clearScores() {
        // Only the active scorer or the system should be allowed to flush all scores.
        // Only the active scorer or the system should be allowed to flush all scores.
@@ -651,9 +656,9 @@ public class NetworkScoreService extends INetworkScoreService.Stub {
    @Override
    @Override
    public boolean setActiveScorer(String packageName) {
    public boolean setActiveScorer(String packageName) {
        // Only the system can set the active scorer
        // Only the system can set the active scorer
        if (!isCallerSystemProcess(getCallingUid()) && !callerCanRequestScores()) {
        if (!isCallerSystemProcess(getCallingUid()) && !callerCanScoreNetworks()) {
            throw new SecurityException(
            throw new SecurityException(
                    "Caller is neither the system process nor a score requester.");
                    "Caller is neither the system process or a network scorer.");
        }
        }


        return mNetworkScorerAppManager.setActiveScorer(packageName);
        return mNetworkScorerAppManager.setActiveScorer(packageName);
+2 −2
Original line number Original line Diff line number Diff line
@@ -368,8 +368,8 @@ public class NetworkScoreServiceTest {
    }
    }


    @Test
    @Test
    public void testSetActiveScorer_noRequestNetworkScoresPermission() {
    public void testSetActiveScorer_noScoreNetworksPermission() {
        when(mContext.checkCallingOrSelfPermission(permission.REQUEST_NETWORK_SCORES))
        when(mContext.checkCallingOrSelfPermission(permission.SCORE_NETWORKS))
                .thenReturn(PackageManager.PERMISSION_DENIED);
                .thenReturn(PackageManager.PERMISSION_DENIED);


        try {
        try {