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

Commit b4fc12ed authored by paulhu's avatar paulhu
Browse files

Replace NPMI#isUidNetworkingBlocked()

ConnectivityService is going to become a mainline module which
will not able to access hidden APIs. NetworkPolicyManagerInternal
is a internal serivce that CS can't be access after be a mainline
module. Thus, create NPM#checkUidNetworkingBlocked to replace it.

Bug: 170598012
Test: atest FrameworksNetTests
Test: atest CtsNetTestCases
Test: atest CtsHostsideNetworkTests
Test: atest FrameworksCoreTests:NetworkPolicyManagerTest
Test: atest FrameworksServicesTests:NetworkPolicyManagerServiceTest
Change-Id: I7bee37522dc5c55c255b159fda9481eff663655a
parent be75db95
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
@@ -459,6 +459,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
@@ -2119,8 +2119,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
@@ -5379,6 +5379,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