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

Commit 830e1e95 authored by Paul Hu's avatar Paul Hu Committed by Gerrit Code Review
Browse files

Merge "Replace NPMI#isUidNetworkingBlocked()"

parents 1c600eed b4fc12ed
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -82,4 +82,5 @@ interface INetworkPolicyManager {

    boolean isUidNetworkingBlocked(int uid, boolean meteredNetwork);
    boolean isUidRestrictedOnMeteredNetworks(int uid);
    boolean checkUidNetworkingBlocked(int uid, int uidRules, boolean isNetworkMetered, boolean isBackgroundRestricted);
}
+25 −0
Original line number Diff line number Diff line
@@ -463,6 +463,31 @@ public class NetworkPolicyManager {
        }
    }

    /**
     * Figure out if networking is blocked for a given set of conditions.
     *
     * This is used by ConnectivityService via passing stale copies of conditions, so it must not
     * take any locks.
     *
     * @param uid The target uid.
     * @param uidRules The uid rules which are obtained from NetworkPolicyManagerService.
     * @param isNetworkMetered True if the network is metered.
     * @param isBackgroundRestricted True if data saver is enabled.
     *
     * @return true if networking is blocked for the UID under the specified conditions.
     *
     * @hide
     */
    public boolean checkUidNetworkingBlocked(int uid, int uidRules,
            boolean isNetworkMetered, boolean isBackgroundRestricted) {
        try {
            return mService.checkUidNetworkingBlocked(uid, uidRules, isNetworkMetered,
                    isBackgroundRestricted);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Check that the given uid is restricted from doing networking on metered networks.
     *
+2 −2
Original line number Diff line number Diff line
@@ -2142,8 +2142,8 @@ public class ConnectivityService extends IConnectivityManager.Stub

    private boolean isUidBlockedByRules(int uid, int uidRules, boolean isNetworkMetered,
            boolean isBackgroundRestricted) {
        return NetworkPolicyManagerInternal.isUidNetworkingBlocked(uid, uidRules,
                isNetworkMetered, isBackgroundRestricted);
        return mPolicyManager.checkUidNetworkingBlocked(uid, uidRules, isNetworkMetered,
                isBackgroundRestricted);
    }

    /**
+0 −24
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.net;

import static com.android.server.net.NetworkPolicyManagerService.isUidNetworkingBlockedInternal;

import android.annotation.NonNull;
import android.net.Network;
import android.net.NetworkTemplate;
@@ -38,28 +36,6 @@ public abstract class NetworkPolicyManagerInternal {
     */
    public abstract void resetUserState(int userId);

    /**
     * Figure out if networking is blocked for a given set of conditions.
     *
     * This is used by ConnectivityService via passing stale copies of conditions, so it must not
     * take any locks.
     *
     * @param uid The target uid.
     * @param uidRules The uid rules which are obtained from NetworkPolicyManagerService.
     * @param isNetworkMetered True if the network is metered.
     * @param isBackgroundRestricted True if data saver is enabled.
     *
     * @return true if networking is blocked for the UID under the specified conditions.
     */
    public static boolean isUidNetworkingBlocked(int uid, int uidRules, boolean isNetworkMetered,
            boolean isBackgroundRestricted) {
        // Log of invoking internal function is disabled because it will be called very
        // frequently. And metrics are unlikely needed on this method because the callers are
        // external and this method doesn't take any locks or perform expensive operations.
        return isUidNetworkingBlockedInternal(uid, uidRules, isNetworkMetered,
                isBackgroundRestricted, null);
    }

    /**
     * Informs that an appId has been added or removed from the temp-powersave-allowlist so that
     * that network rules for that appId can be updated.
+14 −3
Original line number Diff line number Diff line
@@ -5403,6 +5403,17 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
        return ret;
    }

    @Override
    public boolean checkUidNetworkingBlocked(int uid, int uidRules,
            boolean isNetworkMetered, boolean isBackgroundRestricted) {
        mContext.enforceCallingOrSelfPermission(OBSERVE_NETWORK_POLICY, TAG);
        // Log of invoking this function is disabled because it will be called very frequently. And
        // metrics are unlikely needed on this method because the callers are external and this
        // method doesn't take any locks or perform expensive operations.
        return isUidNetworkingBlockedInternal(uid, uidRules, isNetworkMetered,
                isBackgroundRestricted, null);
    }

    @Override
    public boolean isUidRestrictedOnMeteredNetworks(int uid) {
        mContext.enforceCallingOrSelfPermission(OBSERVE_NETWORK_POLICY, TAG);
Loading