From f969377a96b827d7704957d6164151ef248b29e7 Mon Sep 17 00:00:00 2001 From: Lorenzo Colitti Date: Thu, 18 Mar 2021 15:54:31 +0900 Subject: Expose isUidNetworkingBlocked and isUidRestrictedOnMeteredNetworks These methods are used by ConnectivityService for synchronous calls such as getActiveNetworkInfo, isActiveNetworkMetered, etc. These calls must call into NPMS and acquire the NPMS lock because they are synchronous. They cannot use the stale copy of the policy rules maintained by ConnectivityService, because if they did, races like the following could occur: 1. App gets broadcast/callback/.... 2. App calls isActiveNetworkMetered or other synchronous method. 3. ConnectivityService's copy of the rules is out of date, so the call returns stale information that the UID is still blocked. 4. The app thinks it has no networking, and does not call the synchronous method again until some other event occurs, potentially much later. Bug: 176289731 Test: passes existing tests in ConnectivityServiceTest Change-Id: I4ad0ca60431fe3702be85332530b6e93728d55e7 Merged-In: I4ad0ca60431fe3702be85332530b6e93728d55e7 --- core/java/android/net/NetworkPolicyManager.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'core/java') diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java index cceddaa3203b..6152589516c9 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -630,9 +630,8 @@ public class NetworkPolicyManager { * @param meteredNetwork True if the network is metered. * @return true if networking is blocked for the given uid according to current networking * policies. - * - * @hide */ + @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public boolean isUidNetworkingBlocked(int uid, boolean meteredNetwork) { try { return mService.isUidNetworkingBlocked(uid, meteredNetwork); @@ -671,9 +670,8 @@ public class NetworkPolicyManager { * * @param uid The target uid. * @return true if the given uid is restricted from doing networking on metered networks. - * - * @hide */ + @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public boolean isUidRestrictedOnMeteredNetworks(int uid) { try { return mService.isUidRestrictedOnMeteredNetworks(uid); -- cgit v1.2.3