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

Commit d3ba15be authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Remove NetworkPolicyManager.isUidBlocked() API.

It isn't used by ConnectivityService any more and even if
it needs such utility method in the future, we could create
one which is part of connectivity module and doesn't need
to be exposed as part of NetworkPolicyManager API surface.

Bug: 183696103
Test: atest ./tests/net/java/com/android/server/ConnectivityServiceTest.java
Change-Id: Ie3c681f88e4b2b9bb92d2224c5ea96b074f155d5
parent 31e7ebdd
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -50,7 +50,6 @@ package android.net {
    method @NonNull public static String blockedReasonsToString(int);
    method @RequiresPermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public int getMultipathPreference(@NonNull android.net.Network);
    method @RequiresPermission(android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK) public int getRestrictBackgroundStatus(int);
    method public static boolean isUidBlocked(int, boolean);
    method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public boolean isUidNetworkingBlocked(int, boolean);
    method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public boolean isUidRestrictedOnMeteredNetworks(int);
    method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public void registerNetworkPolicyCallback(@Nullable java.util.concurrent.Executor, @NonNull android.net.NetworkPolicyManager.NetworkPolicyCallback);
+0 −32
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package android.net;

import static android.app.ActivityManager.procStateToString;
import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.net.ConnectivityManager.BLOCKED_METERED_REASON_MASK;
import static android.net.ConnectivityManager.BLOCKED_REASON_NONE;

import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -786,36 +784,6 @@ public class NetworkPolicyManager {
        return WifiInfo.sanitizeSsid(ssid);
    }

    /**
     * Returns whether network access of an UID is blocked or not based on {@code blockedReasons}
     * corresponding to it.
     *
     * {@code blockedReasons} would be a bitwise {@code OR} combination of the
     * {@code BLOCKED_REASON_*} and/or {@code BLOCKED_METERED_REASON_*} constants.
     *
     * @param blockedReasons Value indicating the reasons for why the network access of an UID is
     *                       blocked. If the value is equal to
     *                       {@link ConnectivityManager#BLOCKED_REASON_NONE}, then
     *                       it indicates that an app's network access is not blocked.
     * @param meteredNetwork Value indicating whether the network is metered or not.
     * @return Whether network access is blocked or not.
     * @hide
     */
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    public static boolean isUidBlocked(int blockedReasons, boolean meteredNetwork) {
        if (blockedReasons == BLOCKED_REASON_NONE) {
            return false;
        }
        final int blockedOnAllNetworksReason = (blockedReasons & ~BLOCKED_METERED_REASON_MASK);
        if (blockedOnAllNetworksReason != BLOCKED_REASON_NONE) {
            return true;
        }
        if (meteredNetwork) {
            return blockedReasons != BLOCKED_REASON_NONE;
        }
        return false;
    }

    /**
     * Returns the {@code string} representation of {@code blockedReasons} argument.
     *
+13 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import static android.content.pm.PackageManager.PERMISSION_DENIED;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.net.ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN;
import static android.net.ConnectivityManager.BLOCKED_METERED_REASON_DATA_SAVER;
import static android.net.ConnectivityManager.BLOCKED_METERED_REASON_MASK;
import static android.net.ConnectivityManager.BLOCKED_METERED_REASON_USER_RESTRICTED;
import static android.net.ConnectivityManager.BLOCKED_REASON_BATTERY_SAVER;
import static android.net.ConnectivityManager.BLOCKED_REASON_NONE;
@@ -1373,10 +1374,21 @@ public class ConnectivityServiceTest {
    }
    private void mockUidNetworkingBlocked() {
        doAnswer(i -> NetworkPolicyManager.isUidBlocked(mBlockedReasons, i.getArgument(1))
        doAnswer(i -> isUidBlocked(mBlockedReasons, i.getArgument(1))
        ).when(mNetworkPolicyManager).isUidNetworkingBlocked(anyInt(), anyBoolean());
    }
    private boolean isUidBlocked(int blockedReasons, boolean meteredNetwork) {
        final int blockedOnAllNetworksReason = (blockedReasons & ~BLOCKED_METERED_REASON_MASK);
        if (blockedOnAllNetworksReason != BLOCKED_REASON_NONE) {
            return true;
        }
        if (meteredNetwork) {
            return blockedReasons != BLOCKED_REASON_NONE;
        }
        return false;
    }
    private void setBlockedReasonChanged(int blockedReasons) {
        mBlockedReasons = blockedReasons;
        mPolicyCallback.onUidBlockedReasonChanged(Process.myUid(), blockedReasons);