Loading core/java/android/net/INetworkPolicyManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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); } core/java/android/net/NetworkPolicyManager.java +25 −0 Original line number Diff line number Diff line Loading @@ -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. * Loading services/core/java/com/android/server/ConnectivityService.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); } /** Loading services/core/java/com/android/server/net/NetworkPolicyManagerInternal.java +0 −24 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. Loading services/core/java/com/android/server/net/NetworkPolicyManagerService.java +14 −3 Original line number Diff line number Diff line Loading @@ -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 Loading
core/java/android/net/INetworkPolicyManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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); }
core/java/android/net/NetworkPolicyManager.java +25 −0 Original line number Diff line number Diff line Loading @@ -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. * Loading
services/core/java/com/android/server/ConnectivityService.java +2 −2 Original line number Diff line number Diff line Loading @@ -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); } /** Loading
services/core/java/com/android/server/net/NetworkPolicyManagerInternal.java +0 −24 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. Loading
services/core/java/com/android/server/net/NetworkPolicyManagerService.java +14 −3 Original line number Diff line number Diff line Loading @@ -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