diff options
author | Lorenzo Colitti <lorenzo@google.com> | 2021-03-18 15:54:31 +0900 |
---|---|---|
committer | Lorenzo Colitti <lorenzo@google.com> | 2021-03-20 22:23:23 +0900 |
commit | f969377a96b827d7704957d6164151ef248b29e7 (patch) | |
tree | 4b7e6fdb381e75ffa53e8d1b3cb80e0bdc1fe0a6 | |
parent | 00b8d2cf370b73e4b1e17c1818806725e4ad79d9 (diff) |
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
-rw-r--r-- | core/api/module-lib-current.txt | 2 | ||||
-rw-r--r-- | core/api/test-current.txt | 2 | ||||
-rw-r--r-- | core/java/android/net/NetworkPolicyManager.java | 6 |
3 files changed, 6 insertions, 4 deletions
diff --git a/core/api/module-lib-current.txt b/core/api/module-lib-current.txt index e1e82b2fce94..f155a5f07fd7 100644 --- a/core/api/module-lib-current.txt +++ b/core/api/module-lib-current.txt @@ -51,6 +51,8 @@ package android.net { 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); method @RequiresPermission(android.Manifest.permission.OBSERVE_NETWORK_POLICY) public void unregisterNetworkPolicyCallback(@NonNull android.net.NetworkPolicyManager.NetworkPolicyCallback); field public static final int BLOCKED_METERED_REASON_ADMIN_DISABLED = 262144; // 0x40000 diff --git a/core/api/test-current.txt b/core/api/test-current.txt index a0ff97e1f338..11df05812e21 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -996,6 +996,8 @@ package android.net { public class NetworkPolicyManager { method public boolean getRestrictBackground(); + 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 @NonNull public static String resolveNetworkId(@NonNull android.net.wifi.WifiConfiguration); method public void setRestrictBackground(boolean); } 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); |