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

Commit def7f619 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by Android (Google) Code Review
Browse files

Merge "Support ignoring penalty for bad wifi networks" into nyc-dr1-dev

parents 33a900a9 c8e9e122
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -7441,6 +7441,12 @@ public final class Settings {
       public static final String NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS =
              "network_switch_notification_rate_limit_millis";

       /**
        * Whether to automatically switch away from wifi networks that lose Internet access.
        * @hide
        */
       public static final String NETWORK_AVOID_BAD_WIFI = "network_avoid_bad_wifi";

       /**
        * Whether Wifi display is enabled/disabled
        * 0=disabled. 1=enabled.
+5 −0
Original line number Diff line number Diff line
@@ -275,6 +275,11 @@
    <string-array translatable="false" name="config_networkNotifySwitches">
    </string-array>

    <!-- Whether the device should automatically switch away from Wi-Fi networks that lose
         Internet access. Actual device behaviour is controlled by
         Settings.Global.NETWORK_AVOID_BAD_WIFI. This is the default value of that setting. -->
    <integer translatable="false" name="config_networkAvoidBadWifi">1</integer>

    <!-- List of regexpressions describing the interface (if any) that represent tetherable
         USB interfaces.  If the device doesn't want to support tethering over USB this should
         be empty.  An example would be "usb.*" -->
+1 −0
Original line number Diff line number Diff line
@@ -1746,6 +1746,7 @@
  <java-symbol type="integer" name="config_networkTransitionTimeout" />
  <java-symbol type="integer" name="config_networkNotifySwitchType" />
  <java-symbol type="array" name="config_networkNotifySwitches" />
  <java-symbol type="integer" name="config_networkAvoidBadWifi" />
  <java-symbol type="integer" name="config_notificationsBatteryFullARGB" />
  <java-symbol type="integer" name="config_notificationsBatteryLedOff" />
  <java-symbol type="integer" name="config_notificationsBatteryLedOn" />
+9 −0
Original line number Diff line number Diff line
@@ -2704,6 +2704,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
                PROMPT_UNVALIDATED_DELAY_MS);
    }

    @VisibleForTesting
    public boolean avoidBadWifi() {
        int defaultAvoidBadWifi =
            mContext.getResources().getInteger(R.integer.config_networkAvoidBadWifi);
        int avoid = Settings.Global.getInt(mContext.getContentResolver(),
            Settings.Global.NETWORK_AVOID_BAD_WIFI, defaultAvoidBadWifi);
        return avoid == 1;
    }

    private void handlePromptUnvalidated(Network network) {
        if (VDBG) log("handlePromptUnvalidated " + network);
        NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
+9 −1
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ import java.util.TreeSet;
// a NetworkRequest, ConnectivityService will cancel the future disconnection of the NetworkAgent's
// AsyncChannel, and the network is no longer considered "lingering".
public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {

    public NetworkInfo networkInfo;
    // This Network object should always be used if possible, so as to encourage reuse of the
    // enclosed socket factory and connection pool.  Avoid creating other Network objects.
@@ -354,13 +355,20 @@ public class NetworkAgentInfo implements Comparable<NetworkAgentInfo> {
        }

        int score = currentScore;
        if (!lastValidated && !pretendValidated) {
        if (!lastValidated && !pretendValidated && !ignoreWifiUnvalidationPenalty()) {
            score -= UNVALIDATED_SCORE_PENALTY;
        }
        if (score < 0) score = 0;
        return score;
    }

    // Return true on devices configured to ignore score penalty for wifi networks
    // that become unvalidated (b/31075769).
    private boolean ignoreWifiUnvalidationPenalty() {
        boolean isWifi = networkCapabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI);
        return isWifi && !mConnService.avoidBadWifi() && everValidated;
    }

    // Get the current score for this Network.  This may be modified from what the
    // NetworkAgent sent, as it has modifiers applied to it.
    public int getCurrentScore() {