Merge "Address [set|get]RestrictedAllowedApps API review feedback" am: 16c34f0d8b am: 38544887c7
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1708327 Change-Id: Iedd6429e956f77ba595f5dd6029c48a487ddbf0c
This commit is contained in:
@@ -48,6 +48,7 @@ package android.net {
|
||||
|
||||
public class ConnectivitySettingsManager {
|
||||
method public static void clearGlobalProxy(@NonNull android.content.Context);
|
||||
method @NonNull public static java.util.Set<java.lang.String> getAppsAllowedOnRestrictedNetworks(@NonNull android.content.Context);
|
||||
method @Nullable public static String getCaptivePortalHttpUrl(@NonNull android.content.Context);
|
||||
method public static int getCaptivePortalMode(@NonNull android.content.Context, int);
|
||||
method @NonNull public static java.time.Duration getConnectivityKeepPendingIntentDuration(@NonNull android.content.Context, @NonNull java.time.Duration);
|
||||
@@ -65,9 +66,9 @@ package android.net {
|
||||
method @NonNull public static String getPrivateDnsDefaultMode(@NonNull android.content.Context);
|
||||
method @Nullable public static String getPrivateDnsHostname(@NonNull android.content.Context);
|
||||
method public static int getPrivateDnsMode(@NonNull android.content.Context);
|
||||
method @NonNull public static java.util.Set<java.lang.String> getRestrictedAllowedApps(@NonNull android.content.Context);
|
||||
method public static boolean getWifiAlwaysRequested(@NonNull android.content.Context, boolean);
|
||||
method @NonNull public static java.time.Duration getWifiDataActivityTimeout(@NonNull android.content.Context, @NonNull java.time.Duration);
|
||||
method public static void setAppsAllowedOnRestrictedNetworks(@NonNull android.content.Context, @NonNull java.util.Set<java.lang.String>);
|
||||
method public static void setCaptivePortalHttpUrl(@NonNull android.content.Context, @Nullable String);
|
||||
method public static void setCaptivePortalMode(@NonNull android.content.Context, int);
|
||||
method public static void setConnectivityKeepPendingIntentDuration(@NonNull android.content.Context, @NonNull java.time.Duration);
|
||||
@@ -85,7 +86,6 @@ package android.net {
|
||||
method public static void setPrivateDnsDefaultMode(@NonNull android.content.Context, @NonNull int);
|
||||
method public static void setPrivateDnsHostname(@NonNull android.content.Context, @Nullable String);
|
||||
method public static void setPrivateDnsMode(@NonNull android.content.Context, int);
|
||||
method public static void setRestrictedAllowedApps(@NonNull android.content.Context, @NonNull java.util.Set<java.lang.String>);
|
||||
method public static void setWifiAlwaysRequested(@NonNull android.content.Context, boolean);
|
||||
method public static void setWifiDataActivityTimeout(@NonNull android.content.Context, @NonNull java.time.Duration);
|
||||
field public static final int CAPTIVE_PORTAL_MODE_AVOID = 2; // 0x2
|
||||
|
||||
@@ -43,7 +43,6 @@ import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A manager class for connectivity module settings.
|
||||
@@ -375,11 +374,12 @@ public class ConnectivitySettingsManager {
|
||||
private static final String PRIVATE_DNS_MODE_PROVIDER_HOSTNAME_STRING = "hostname";
|
||||
|
||||
/**
|
||||
* A list of apps that should be granted netd system permission for using restricted networks.
|
||||
* A list of apps that is allowed on restricted networks.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final String RESTRICTED_ALLOWED_APPS = "restricted_allowed_apps";
|
||||
public static final String APPS_ALLOWED_ON_RESTRICTED_NETWORKS =
|
||||
"apps_allowed_on_restricted_networks";
|
||||
|
||||
/**
|
||||
* Get mobile data activity timeout from {@link Settings}.
|
||||
@@ -1047,17 +1047,16 @@ public class ConnectivitySettingsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of apps(from {@link Settings}) that should be granted netd system permission for
|
||||
* using restricted networks.
|
||||
* Get the list of apps(from {@link Settings}) that is allowed on restricted networks.
|
||||
*
|
||||
* @param context The {@link Context} to query the setting.
|
||||
* @return A list of apps that should be granted netd system permission for using restricted
|
||||
* networks or null if no setting value.
|
||||
* @return A list of apps that is allowed on restricted networks or null if no setting
|
||||
* value.
|
||||
*/
|
||||
@NonNull
|
||||
public static Set<String> getRestrictedAllowedApps(@NonNull Context context) {
|
||||
public static Set<String> getAppsAllowedOnRestrictedNetworks(@NonNull Context context) {
|
||||
final String appList = Settings.Secure.getString(
|
||||
context.getContentResolver(), RESTRICTED_ALLOWED_APPS);
|
||||
context.getContentResolver(), APPS_ALLOWED_ON_RESTRICTED_NETWORKS);
|
||||
if (TextUtils.isEmpty(appList)) {
|
||||
return new ArraySet<>();
|
||||
}
|
||||
@@ -1065,27 +1064,24 @@ public class ConnectivitySettingsManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of apps(from {@link Settings}) that should be granted netd system permission for
|
||||
* using restricted networks.
|
||||
* Set the list of apps(from {@link Settings}) that is allowed on restricted networks.
|
||||
*
|
||||
* Note: Please refer to android developer guidelines for valid app(package name).
|
||||
* https://developer.android.com/guide/topics/manifest/manifest-element.html#package
|
||||
*
|
||||
* @param context The {@link Context} to set the setting.
|
||||
* @param list A list of apps that should be granted netd system permission for using
|
||||
* restricted networks.
|
||||
* @param list A list of apps that is allowed on restricted networks.
|
||||
*/
|
||||
public static void setRestrictedAllowedApps(@NonNull Context context,
|
||||
public static void setAppsAllowedOnRestrictedNetworks(@NonNull Context context,
|
||||
@NonNull Set<String> list) {
|
||||
final Pattern appPattern = Pattern.compile("[a-zA-Z_0-9]+([.][a-zA-Z_0-9]+)*");
|
||||
final StringJoiner joiner = new StringJoiner(";");
|
||||
for (String app : list) {
|
||||
if (!appPattern.matcher(app).matches()) {
|
||||
if (app == null || app.contains(";")) {
|
||||
throw new IllegalArgumentException("Invalid app(package name)");
|
||||
}
|
||||
joiner.add(app);
|
||||
}
|
||||
Settings.Secure.putString(
|
||||
context.getContentResolver(), RESTRICTED_ALLOWED_APPS, joiner.toString());
|
||||
Settings.Secure.putString(context.getContentResolver(), APPS_ALLOWED_ON_RESTRICTED_NETWORKS,
|
||||
joiner.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user