Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f6b16a7 authored by Paul Hu's avatar Paul Hu Committed by Automerger Merge Worker
Browse files

Merge "Add more connectivity module settings" am: f3d84f44

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1641784

Change-Id: If6fab011720145f2ba18df478e6660be442bcad5
parents c7eef81c f3d84f44
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@
package android.net;

import static android.annotation.SystemApi.Client.MODULE_LIBRARIES;
import static android.net.ConnectivitySettingsManager.PRIVATE_DNS_DEFAULT_MODE;
import static android.net.ConnectivitySettingsManager.PRIVATE_DNS_MODE;
import static android.net.NetworkRequest.Type.BACKGROUND_REQUEST;
import static android.net.NetworkRequest.Type.LISTEN;
import static android.net.NetworkRequest.Type.LISTEN_FOR_BEST;
@@ -23,8 +25,6 @@ import static android.net.NetworkRequest.Type.REQUEST;
import static android.net.NetworkRequest.Type.TRACK_DEFAULT;
import static android.net.NetworkRequest.Type.TRACK_SYSTEM_DEFAULT;
import static android.net.QosCallback.QosCallbackRegistrationException;
import static android.provider.Settings.Global.PRIVATE_DNS_DEFAULT_MODE;
import static android.provider.Settings.Global.PRIVATE_DNS_MODE;

import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
+195 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@

package android.net;

import android.annotation.IntDef;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * A manager class for connectivity module settings.
 *
@@ -25,6 +30,196 @@ public class ConnectivitySettingsManager {

    private ConnectivitySettingsManager() {}

    /** Data activity timeout settings */

    /**
     * Inactivity timeout to track mobile data activity.
     *
     * If set to a positive integer, it indicates the inactivity timeout value in seconds to
     * infer the data activity of mobile network. After a period of no activity on mobile
     * networks with length specified by the timeout, an {@code ACTION_DATA_ACTIVITY_CHANGE}
     * intent is fired to indicate a transition of network status from "active" to "idle". Any
     * subsequent activity on mobile networks triggers the firing of {@code
     * ACTION_DATA_ACTIVITY_CHANGE} intent indicating transition from "idle" to "active".
     *
     * Network activity refers to transmitting or receiving data on the network interfaces.
     *
     * Tracking is disabled if set to zero or negative value.
     */
    public static final String DATA_ACTIVITY_TIMEOUT_MOBILE = "data_activity_timeout_mobile";

    /**
     * Timeout to tracking Wifi data activity. Same as {@code DATA_ACTIVITY_TIMEOUT_MOBILE}
     * but for Wifi network.
     */
    public static final String DATA_ACTIVITY_TIMEOUT_WIFI = "data_activity_timeout_wifi";

    /** Dns resolver settings */

    /**
     * Sample validity in seconds to configure for the system DNS resolver.
     */
    public static final String DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS =
            "dns_resolver_sample_validity_seconds";

    /**
     * Success threshold in percent for use with the system DNS resolver.
     */
    public static final String DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT =
            "dns_resolver_success_threshold_percent";

    /**
     * Minimum number of samples needed for statistics to be considered meaningful in the
     * system DNS resolver.
     */
    public static final String DNS_RESOLVER_MIN_SAMPLES = "dns_resolver_min_samples";

    /**
     * Maximum number taken into account for statistics purposes in the system DNS resolver.
     */
    public static final String DNS_RESOLVER_MAX_SAMPLES = "dns_resolver_max_samples";

    /** Network switch notification settings */

    /**
     * The maximum number of notifications shown in 24 hours when switching networks.
     */
    public static final String NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT =
            "network_switch_notification_daily_limit";

    /**
     * The minimum time in milliseconds between notifications when switching networks.
     */
    public static final String NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS =
            "network_switch_notification_rate_limit_millis";

    /** Captive portal settings */

    /**
     * The URL used for HTTP captive portal detection upon a new connection.
     * A 204 response code from the server is used for validation.
     */
    public static final String CAPTIVE_PORTAL_HTTP_URL = "captive_portal_http_url";

    /**
     * What to do when connecting a network that presents a captive portal.
     * Must be one of the CAPTIVE_PORTAL_MODE_* constants above.
     *
     * The default for this setting is CAPTIVE_PORTAL_MODE_PROMPT.
     */
    public static final String CAPTIVE_PORTAL_MODE = "captive_portal_mode";

    /**
     * Don't attempt to detect captive portals.
     */
    public static final int CAPTIVE_PORTAL_MODE_IGNORE = 0;

    /**
     * When detecting a captive portal, display a notification that
     * prompts the user to sign in.
     */
    public static final int CAPTIVE_PORTAL_MODE_PROMPT = 1;

    /**
     * When detecting a captive portal, immediately disconnect from the
     * network and do not reconnect to that network in the future.
     */
    public static final int CAPTIVE_PORTAL_MODE_AVOID = 2;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {
            CAPTIVE_PORTAL_MODE_IGNORE,
            CAPTIVE_PORTAL_MODE_PROMPT,
            CAPTIVE_PORTAL_MODE_AVOID,
    })
    public @interface CaptivePortalMode {}

    /** Global http proxy settings */

    /**
     * Host name for global http proxy. Set via ConnectivityManager.
     */
    public static final String GLOBAL_HTTP_PROXY_HOST = "global_http_proxy_host";

    /**
     * Integer host port for global http proxy. Set via ConnectivityManager.
     */
    public static final String GLOBAL_HTTP_PROXY_PORT = "global_http_proxy_port";

    /**
     * Exclusion list for global proxy. This string contains a list of
     * comma-separated domains where the global proxy does not apply.
     * Domains should be listed in a comma- separated list. Example of
     * acceptable formats: ".domain1.com,my.domain2.com" Use
     * ConnectivityManager to set/get.
     */
    public static final String GLOBAL_HTTP_PROXY_EXCLUSION_LIST =
            "global_http_proxy_exclusion_list";

    /**
     * The location PAC File for the proxy.
     */
    public static final String GLOBAL_HTTP_PROXY_PAC = "global_proxy_pac_url";

    /** Private dns settings */

    /**
     * The requested Private DNS mode (string), and an accompanying specifier (string).
     *
     * Currently, the specifier holds the chosen provider name when the mode requests
     * a specific provider. It may be used to store the provider name even when the
     * mode changes so that temporarily disabling and re-enabling the specific
     * provider mode does not necessitate retyping the provider hostname.
     */
    public static final String PRIVATE_DNS_MODE = "private_dns_mode";

    /**
     * The specific Private DNS provider name.
     */
    public static final String PRIVATE_DNS_SPECIFIER = "private_dns_specifier";

    /**
     * Forced override of the default mode (hardcoded as "automatic", nee "opportunistic").
     * This allows changing the default mode without effectively disabling other modes,
     * all of which require explicit user action to enable/configure. See also b/79719289.
     *
     * Value is a string, suitable for assignment to PRIVATE_DNS_MODE above.
     */
    public static final String PRIVATE_DNS_DEFAULT_MODE = "private_dns_default_mode";

    /** Other settings */

    /**
     * The number of milliseconds to hold on to a PendingIntent based request. This delay gives
     * the receivers of the PendingIntent an opportunity to make a new network request before
     * the Network satisfying the request is potentially removed.
     */
    public static final String CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS =
            "connectivity_release_pending_intent_delay_ms";

    /**
     * Whether the mobile data connection should remain active even when higher
     * priority networks like WiFi are active, to help make network switching faster.
     *
     * See ConnectivityService for more info.
     *
     * (0 = disabled, 1 = enabled)
     */
    public static final String MOBILE_DATA_ALWAYS_ON = "mobile_data_always_on";

    /**
     * Whether the wifi data connection should remain active even when higher
     * priority networks like Ethernet are active, to keep both networks.
     * In the case where higher priority networks are connected, wifi will be
     * unused unless an application explicitly requests to use it.
     *
     * See ConnectivityService for more info.
     *
     * (0 = disabled, 1 = enabled)
     */
    public static final String WIFI_ALWAYS_REQUESTED = "wifi_always_requested";

    /**
     * Whether to automatically switch away from wifi networks that lose Internet access.
     * Only meaningful if config_networkAvoidBadWifi is set to 0, otherwise the system always
+19 −18
Original line number Diff line number Diff line
@@ -285,7 +285,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    /**
     * Default URL to use for {@link #getCaptivePortalServerUrl()}. This should not be changed
     * by OEMs for configuration purposes, as this value is overridden by
     * Settings.Global.CAPTIVE_PORTAL_HTTP_URL.
     * ConnectivitySettingsManager.CAPTIVE_PORTAL_HTTP_URL.
     * R.string.config_networkCaptivePortalServerUrl should be overridden instead for this purpose
     * (preferably via runtime resource overlays).
     */
@@ -318,7 +318,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    protected int mNascentDelayMs;

    // How long to delay to removal of a pending intent based request.
    // See Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS
    // See ConnectivitySettingsManager.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS
    private final int mReleasePendingIntentDelayMs;

    private MockableSystemProperties mSystemProperties;
@@ -1234,7 +1234,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                new ConnectivityDiagnosticsHandler(mHandlerThread.getLooper());

        mReleasePendingIntentDelayMs = Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS, 5_000);
                ConnectivitySettingsManager.CONNECTIVITY_RELEASE_PENDING_INTENT_DELAY_MS, 5_000);

        mLingerDelayMs = mSystemProperties.getInt(LINGER_DELAY_PROPERTY, DEFAULT_LINGER_DELAY_MS);
        // TODO: Consider making the timer customizable.
@@ -1306,10 +1306,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
        mQosCallbackTracker = new QosCallbackTracker(mHandler, mNetworkRequestCounter);

        final int dailyLimit = Settings.Global.getInt(mContext.getContentResolver(),
                Settings.Global.NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT,
                ConnectivitySettingsManager.NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT,
                LingerMonitor.DEFAULT_NOTIFICATION_DAILY_LIMIT);
        final long rateLimit = Settings.Global.getLong(mContext.getContentResolver(),
                Settings.Global.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS,
                ConnectivitySettingsManager.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS,
                LingerMonitor.DEFAULT_NOTIFICATION_RATE_LIMIT_MILLIS);
        mLingerMonitor = new LingerMonitor(mContext, mNotifier, dailyLimit, rateLimit);

@@ -1427,10 +1427,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
    }

    private void handleConfigureAlwaysOnNetworks() {
        handleAlwaysOnNetworkRequest(
                mDefaultMobileDataRequest, Settings.Global.MOBILE_DATA_ALWAYS_ON, true);
        handleAlwaysOnNetworkRequest(mDefaultWifiRequest, Settings.Global.WIFI_ALWAYS_REQUESTED,
                false);
        handleAlwaysOnNetworkRequest(mDefaultMobileDataRequest,
                ConnectivitySettingsManager.MOBILE_DATA_ALWAYS_ON, true /* defaultValue */);
        handleAlwaysOnNetworkRequest(mDefaultWifiRequest,
                ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED, false /* defaultValue */);
        handleAlwaysOnNetworkRequest(mDefaultVehicleRequest,
                com.android.internal.R.bool.config_vehicleInternalNetworkAlwaysRequested);
    }
@@ -1443,12 +1443,12 @@ public class ConnectivityService extends IConnectivityManager.Stub

        // Watch for whether or not to keep mobile data always on.
        mSettingsObserver.observe(
                Settings.Global.getUriFor(Settings.Global.MOBILE_DATA_ALWAYS_ON),
                Settings.Global.getUriFor(ConnectivitySettingsManager.MOBILE_DATA_ALWAYS_ON),
                EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);

        // Watch for whether or not to keep wifi always on.
        mSettingsObserver.observe(
                Settings.Global.getUriFor(Settings.Global.WIFI_ALWAYS_REQUESTED),
                Settings.Global.getUriFor(ConnectivitySettingsManager.WIFI_ALWAYS_REQUESTED),
                EVENT_CONFIGURE_ALWAYS_ON_NETWORKS);
    }

@@ -3110,7 +3110,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
                        nai.lastCaptivePortalDetected = visible;
                        nai.everCaptivePortalDetected |= visible;
                        if (nai.lastCaptivePortalDetected &&
                            Settings.Global.CAPTIVE_PORTAL_MODE_AVOID == getCaptivePortalMode()) {
                                ConnectivitySettingsManager.CAPTIVE_PORTAL_MODE_AVOID
                                        == getCaptivePortalMode()) {
                            if (DBG) log("Avoiding captive portal network: " + nai.toShortString());
                            nai.onPreventAutomaticReconnect();
                            teardownUnneededNetwork(nai);
@@ -3221,8 +3222,8 @@ public class ConnectivityService extends IConnectivityManager.Stub

        private int getCaptivePortalMode() {
            return Settings.Global.getInt(mContext.getContentResolver(),
                    Settings.Global.CAPTIVE_PORTAL_MODE,
                    Settings.Global.CAPTIVE_PORTAL_MODE_PROMPT);
                    ConnectivitySettingsManager.CAPTIVE_PORTAL_MODE,
                    ConnectivitySettingsManager.CAPTIVE_PORTAL_MODE_PROMPT);
        }

        private boolean maybeHandleNetworkAgentInfoMessage(Message msg) {
@@ -8159,7 +8160,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }

        settingUrl = Settings.Global.getString(mContext.getContentResolver(),
                Settings.Global.CAPTIVE_PORTAL_HTTP_URL);
                ConnectivitySettingsManager.CAPTIVE_PORTAL_HTTP_URL);
        if (!TextUtils.isEmpty(settingUrl)) {
            return settingUrl;
        }
@@ -8241,7 +8242,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        // restore private DNS settings to default mode (opportunistic)
        if (!mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_PRIVATE_DNS)) {
            Settings.Global.putString(mContext.getContentResolver(),
                    Settings.Global.PRIVATE_DNS_MODE, PRIVATE_DNS_MODE_OPPORTUNISTIC);
                    ConnectivitySettingsManager.PRIVATE_DNS_MODE, PRIVATE_DNS_MODE_OPPORTUNISTIC);
        }

        Settings.Global.putString(mContext.getContentResolver(),
@@ -8997,13 +8998,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
            if (networkAgent.networkCapabilities.hasTransport(
                    NetworkCapabilities.TRANSPORT_CELLULAR)) {
                timeout = Settings.Global.getInt(mContext.getContentResolver(),
                        Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE,
                        ConnectivitySettingsManager.DATA_ACTIVITY_TIMEOUT_MOBILE,
                        10);
                type = NetworkCapabilities.TRANSPORT_CELLULAR;
            } else if (networkAgent.networkCapabilities.hasTransport(
                    NetworkCapabilities.TRANSPORT_WIFI)) {
                timeout = Settings.Global.getInt(mContext.getContentResolver(),
                        Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI,
                        ConnectivitySettingsManager.DATA_ACTIVITY_TIMEOUT_WIFI,
                        15);
                type = NetworkCapabilities.TRANSPORT_WIFI;
            } else {
+7 −7
Original line number Diff line number Diff line
@@ -18,15 +18,15 @@ package com.android.server.connectivity;

import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_OFF;
import static android.net.ConnectivityManager.PRIVATE_DNS_MODE_PROVIDER_HOSTNAME;
import static android.net.ConnectivitySettingsManager.DNS_RESOLVER_MAX_SAMPLES;
import static android.net.ConnectivitySettingsManager.DNS_RESOLVER_MIN_SAMPLES;
import static android.net.ConnectivitySettingsManager.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS;
import static android.net.ConnectivitySettingsManager.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT;
import static android.net.ConnectivitySettingsManager.PRIVATE_DNS_DEFAULT_MODE;
import static android.net.ConnectivitySettingsManager.PRIVATE_DNS_MODE;
import static android.net.ConnectivitySettingsManager.PRIVATE_DNS_SPECIFIER;
import static android.net.resolv.aidl.IDnsResolverUnsolicitedEventListener.VALIDATION_RESULT_FAILURE;
import static android.net.resolv.aidl.IDnsResolverUnsolicitedEventListener.VALIDATION_RESULT_SUCCESS;
import static android.provider.Settings.Global.DNS_RESOLVER_MAX_SAMPLES;
import static android.provider.Settings.Global.DNS_RESOLVER_MIN_SAMPLES;
import static android.provider.Settings.Global.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS;
import static android.provider.Settings.Global.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT;
import static android.provider.Settings.Global.PRIVATE_DNS_DEFAULT_MODE;
import static android.provider.Settings.Global.PRIVATE_DNS_MODE;
import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER;

import android.annotation.NonNull;
import android.content.ContentResolver;
+4 −4
Original line number Diff line number Diff line
@@ -16,10 +16,10 @@

package com.android.server.connectivity;

import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST;
import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_HOST;
import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_PAC;
import static android.provider.Settings.Global.GLOBAL_HTTP_PROXY_PORT;
import static android.net.ConnectivitySettingsManager.GLOBAL_HTTP_PROXY_EXCLUSION_LIST;
import static android.net.ConnectivitySettingsManager.GLOBAL_HTTP_PROXY_HOST;
import static android.net.ConnectivitySettingsManager.GLOBAL_HTTP_PROXY_PAC;
import static android.net.ConnectivitySettingsManager.GLOBAL_HTTP_PROXY_PORT;
import static android.provider.Settings.Global.HTTP_PROXY;

import android.annotation.NonNull;
Loading