summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorAaron Huang <huangaaron@google.com>2019-12-30 20:11:36 +0800
committerChalard Jean <jchalard@google.com>2020-01-22 23:01:47 +0900
commit2d471ca1e141d58a3bea996b4940a5894fd1edce (patch)
tree6fec614402786fd9d7a9baaa52ad27ecf1472a8b /core/java/android
parentb3191a3396252fe5dcfbcf0f763b00976f3857e6 (diff)
Add setSubscriptionOverride() to system API
Add new API setSubscriptionOverride() in NetworkPolicyManager and rename constants OVERRIDE_* to SUBSCRIPTION_OVERRIDE_*. Make them @SystemApi for mainline support. Bug: 138306002 Test: atest FrameworksNetTests atest FrameworksTelephonyTests Change-Id: I56c777aa66d6f455695f133f9889979c13cd1bc8
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/net/NetworkPolicyManager.java135
1 files changed, 121 insertions, 14 deletions
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index de962f8f25e3..03ec24506375 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -18,6 +18,9 @@ package android.net;
import static android.content.pm.PackageManager.GET_SIGNATURES;
+import android.annotation.IntDef;
+import android.annotation.NonNull;
+import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.app.ActivityManager;
import android.compat.annotation.UnsupportedAppUsage;
@@ -38,6 +41,8 @@ import android.util.Range;
import com.google.android.collect.Sets;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.Iterator;
@@ -48,14 +53,24 @@ import java.util.Iterator;
* {@hide}
*/
@SystemService(Context.NETWORK_POLICY_SERVICE)
+@SystemApi
public class NetworkPolicyManager {
/* POLICY_* are masks and can be ORed, although currently they are not.*/
- /** No specific network policy, use system default. */
+ /**
+ * No specific network policy, use system default.
+ * @hide
+ */
public static final int POLICY_NONE = 0x0;
- /** Reject network usage on metered networks when application in background. */
+ /**
+ * Reject network usage on metered networks when application in background.
+ * @hide
+ */
public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
- /** Allow metered network use in the background even when in data usage save mode. */
+ /**
+ * Allow metered network use in the background even when in data usage save mode.
+ * @hide
+ */
public static final int POLICY_ALLOW_METERED_BACKGROUND = 0x4;
/*
@@ -74,49 +89,98 @@ public class NetworkPolicyManager {
*
* See network-policy-restrictions.md for more info.
*/
- /** No specific rule was set */
+ /**
+ * No specific rule was set
+ * @hide
+ */
public static final int RULE_NONE = 0;
- /** Allow traffic on metered networks. */
+ /**
+ * Allow traffic on metered networks.
+ * @hide
+ */
public static final int RULE_ALLOW_METERED = 1 << 0;
- /** Temporarily allow traffic on metered networks because app is on foreground. */
+ /**
+ * Temporarily allow traffic on metered networks because app is on foreground.
+ * @hide
+ */
public static final int RULE_TEMPORARY_ALLOW_METERED = 1 << 1;
- /** Reject traffic on metered networks. */
+ /**
+ * Reject traffic on metered networks.
+ * @hide
+ */
public static final int RULE_REJECT_METERED = 1 << 2;
- /** Network traffic should be allowed on all networks (metered or non-metered), although
- * metered-network restrictions could still apply. */
+ /**
+ * Network traffic should be allowed on all networks (metered or non-metered), although
+ * metered-network restrictions could still apply.
+ * @hide
+ */
public static final int RULE_ALLOW_ALL = 1 << 5;
- /** Reject traffic on all networks. */
+ /**
+ * Reject traffic on all networks.
+ * @hide
+ */
public static final int RULE_REJECT_ALL = 1 << 6;
- /** Mask used to get the {@code RULE_xxx_METERED} rules */
+ /**
+ * Mask used to get the {@code RULE_xxx_METERED} rules
+ * @hide
+ */
public static final int MASK_METERED_NETWORKS = 0b00001111;
- /** Mask used to get the {@code RULE_xxx_ALL} rules */
+ /**
+ * Mask used to get the {@code RULE_xxx_ALL} rules
+ * @hide
+ */
public static final int MASK_ALL_NETWORKS = 0b11110000;
+ /** @hide */
public static final int FIREWALL_RULE_DEFAULT = 0;
+ /** @hide */
public static final String FIREWALL_CHAIN_NAME_NONE = "none";
+ /** @hide */
public static final String FIREWALL_CHAIN_NAME_DOZABLE = "dozable";
+ /** @hide */
public static final String FIREWALL_CHAIN_NAME_STANDBY = "standby";
+ /** @hide */
public static final String FIREWALL_CHAIN_NAME_POWERSAVE = "powersave";
private static final boolean ALLOW_PLATFORM_APP_POLICY = true;
+ /** @hide */
public static final int FOREGROUND_THRESHOLD_STATE =
ActivityManager.PROCESS_STATE_BOUND_FOREGROUND_SERVICE;
/**
* {@link Intent} extra that indicates which {@link NetworkTemplate} rule it
* applies to.
+ * @hide
*/
public static final String EXTRA_NETWORK_TEMPLATE = "android.net.NETWORK_TEMPLATE";
- public static final int OVERRIDE_UNMETERED = 1 << 0;
- public static final int OVERRIDE_CONGESTED = 1 << 1;
+ /**
+ * Mask used to check if an override value is marked as unmetered.
+ */
+ public static final int SUBSCRIPTION_OVERRIDE_UNMETERED = 1 << 0;
+
+ /**
+ * Mask used to check if an override value is marked as congested.
+ */
+ public static final int SUBSCRIPTION_OVERRIDE_CONGESTED = 1 << 1;
+
+ /**
+ * @hide
+ */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(flag = true, prefix = { "SUBSCRIPTION_OVERRIDE_" }, value = {
+ SUBSCRIPTION_OVERRIDE_UNMETERED,
+ SUBSCRIPTION_OVERRIDE_CONGESTED
+ })
+ public @interface SubscriptionOverrideMask {}
private final Context mContext;
@UnsupportedAppUsage
private INetworkPolicyManager mService;
+ /** @hide */
public NetworkPolicyManager(Context context, INetworkPolicyManager service) {
if (service == null) {
throw new IllegalArgumentException("missing INetworkPolicyManager");
@@ -125,6 +189,7 @@ public class NetworkPolicyManager {
mService = service;
}
+ /** @hide */
@UnsupportedAppUsage
public static NetworkPolicyManager from(Context context) {
return (NetworkPolicyManager) context.getSystemService(Context.NETWORK_POLICY_SERVICE);
@@ -135,6 +200,7 @@ public class NetworkPolicyManager {
*
* @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
* although it is not validated.
+ * @hide
*/
@UnsupportedAppUsage
public void setUidPolicy(int uid, int policy) {
@@ -152,6 +218,7 @@ public class NetworkPolicyManager {
*
* @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
* although it is not validated.
+ * @hide
*/
public void addUidPolicy(int uid, int policy) {
try {
@@ -168,6 +235,7 @@ public class NetworkPolicyManager {
*
* @param policy should be {@link #POLICY_NONE} or any combination of {@code POLICY_} flags,
* although it is not validated.
+ * @hide
*/
public void removeUidPolicy(int uid, int policy) {
try {
@@ -177,6 +245,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage
public int getUidPolicy(int uid) {
try {
@@ -186,6 +255,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage
public int[] getUidsWithPolicy(int policy) {
try {
@@ -195,6 +265,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public void registerListener(INetworkPolicyListener listener) {
try {
@@ -204,6 +275,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public void unregisterListener(INetworkPolicyListener listener) {
try {
@@ -213,6 +285,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
public void setNetworkPolicies(NetworkPolicy[] policies) {
try {
mService.setNetworkPolicies(policies);
@@ -221,6 +294,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage
public NetworkPolicy[] getNetworkPolicies() {
try {
@@ -230,6 +304,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage
public void setRestrictBackground(boolean restrictBackground) {
try {
@@ -239,6 +314,7 @@ public class NetworkPolicyManager {
}
}
+ /** @hide */
@UnsupportedAppUsage
public boolean getRestrictBackground() {
try {
@@ -249,6 +325,32 @@ public class NetworkPolicyManager {
}
/**
+ * Override connections to be temporarily marked as either unmetered or congested,
+ * along with automatic timeouts if desired.
+ *
+ * @param subId the subscriber ID this override applies to.
+ * @param overrideMask the bitmask that specifies which of the overrides is being
+ * set or cleared.
+ * @param overrideValue the override values to set or clear.
+ * @param timeoutMillis the timeout after which the requested override will
+ * be automatically cleared, or {@code 0} to leave in the
+ * requested state until explicitly cleared, or the next reboot,
+ * whichever happens first
+ * @param callingPackage the name of the package making the call.
+ *
+ */
+ public void setSubscriptionOverride(int subId, @SubscriptionOverrideMask int overrideMask,
+ @SubscriptionOverrideMask int overrideValue, long timeoutMillis,
+ @NonNull String callingPackage) {
+ try {
+ mService.setSubscriptionOverride(subId, overrideMask, overrideValue, timeoutMillis,
+ callingPackage);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Resets network policy settings back to factory defaults.
*
* @hide
@@ -286,6 +388,7 @@ public class NetworkPolicyManager {
/**
* Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
* usually to protect critical system services.
+ * @hide
*/
@Deprecated
public static boolean isUidValidForPolicy(Context context, int uid) {
@@ -353,6 +456,7 @@ public class NetworkPolicyManager {
/**
* Returns true if {@param procState} is considered foreground and as such will be allowed
* to access network when the device is idle or in battery saver mode. Otherwise, false.
+ * @hide
*/
public static boolean isProcStateAllowedWhileIdleOrPowerSaveMode(int procState) {
return procState <= FOREGROUND_THRESHOLD_STATE;
@@ -361,16 +465,19 @@ public class NetworkPolicyManager {
/**
* Returns true if {@param procState} is considered foreground and as such will be allowed
* to access network when the device is in data saver mode. Otherwise, false.
+ * @hide
*/
public static boolean isProcStateAllowedWhileOnRestrictBackground(int procState) {
return procState <= FOREGROUND_THRESHOLD_STATE;
}
+ /** @hide */
public static String resolveNetworkId(WifiConfiguration config) {
return WifiInfo.removeDoubleQuotes(config.isPasspoint()
? config.providerFriendlyName : config.SSID);
}
+ /** @hide */
public static String resolveNetworkId(String ssid) {
return WifiInfo.removeDoubleQuotes(ssid);
}