summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2021-03-18 15:54:31 +0900
committerLorenzo Colitti <lorenzo@google.com>2021-03-20 22:23:23 +0900
commitf969377a96b827d7704957d6164151ef248b29e7 (patch)
tree4b7e6fdb381e75ffa53e8d1b3cb80e0bdc1fe0a6 /core/java
parent00b8d2cf370b73e4b1e17c1818806725e4ad79d9 (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
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/net/NetworkPolicyManager.java6
1 files changed, 2 insertions, 4 deletions
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);