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

Commit 4b3348f1 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Automerger Merge Worker
Browse files

Merge "Remove NetworkPolicyManager.isUidBlocked() API." am: 9cff99d0 am: 433c8661

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1652550

Change-Id: I354cd41d18cfab87b1302d2dbd0ba5dcd10edca6
parents fc5e6ede 433c8661
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);