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

Commit 7b42f399 authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Add a lastValidated bit and use it when reporting capabilities.

When we switched the way the status bar determines if a
connection is validated from using INET_CONDITION_ACTION
broadcasts to calling getDefaultNetworkCapabilitiesForUser(),
the statusbar stopped displaying ! when a network stopped having
working Internet connectivity. This is because the validated bit
is never set to false once a network is validated.

Fix this, hopefully temporarily, by introducing a new validated
bit that does go back to being false when a network no longer
has working connectivity, and use that bit in
getDefaultNetworkCapabilitiesForUser().

Bug: 18777225
Change-Id: I991c068be50252391d0e64c647fcf2e053dc82f9
parent d3b8a3e7
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1048,7 +1048,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            synchronized (nai) {
                if (nai.created) {
                    NetworkCapabilities nc = new NetworkCapabilities(nai.networkCapabilities);
                    if (nai.everValidated) {
                    if (nai.lastValidated) {
                        nc.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
                    } else {
                        nc.removeCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
@@ -1954,6 +1954,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                    NetworkAgentInfo nai = (NetworkAgentInfo)msg.obj;
                    if (isLiveNetworkAgent(nai, "EVENT_NETWORK_VALIDATED")) {
                        boolean valid = (msg.arg1 == NetworkMonitor.NETWORK_TEST_RESULT_VALID);
                        nai.lastValidated = valid;
                        if (valid) {
                            if (DBG) log("Validated " + nai.name());
                            if (!nai.everValidated) {
@@ -1964,7 +1965,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                                sendUpdatedScoreToFactories(nai);
                            }
                        }
                        updateInetCondition(nai, valid);
                        updateInetCondition(nai);
                        // Let the NetworkAgent know the state of its network
                        nai.asyncChannel.sendMessage(
                                android.net.NetworkAgent.CMD_REPORT_NETWORK_STATUS,
@@ -4200,14 +4201,14 @@ public class ConnectivityService extends IConnectivityManager.Stub
        }
    }

    private void updateInetCondition(NetworkAgentInfo nai, boolean valid) {
    private void updateInetCondition(NetworkAgentInfo nai) {
        // Don't bother updating until we've graduated to validated at least once.
        if (!nai.everValidated) return;
        // For now only update icons for default connection.
        // TODO: Update WiFi and cellular icons separately. b/17237507
        if (!isDefaultNetwork(nai)) return;

        int newInetCondition = valid ? 100 : 0;
        int newInetCondition = nai.lastValidated ? 100 : 0;
        // Don't repeat publish.
        if (newInetCondition == mDefaultInetConditionPublished) return;

+11 −2
Original line number Diff line number Diff line
@@ -55,6 +55,13 @@ public class NetworkAgentInfo {
    // fail.
    public boolean everValidated;

    // The result of the last validation attempt on this network (true if validated, false if not).
    // This bit exists only because we never unvalidate a network once it's been validated, and that
    // is because the network scoring and revalidation code does not (may not?) deal properly with
    // networks becoming unvalidated.
    // TODO: Fix the network scoring code, remove this, and rename everValidated to validated.
    public boolean lastValidated;

    // This represents the last score received from the NetworkAgent.
    private int currentScore;
    // Penalty applied to scores of Networks that have not been validated.
@@ -90,6 +97,7 @@ public class NetworkAgentInfo {
        networkMisc = misc;
        created = false;
        everValidated = false;
        lastValidated = false;
    }

    public void addRequest(NetworkRequest networkRequest) {
@@ -143,7 +151,8 @@ public class NetworkAgentInfo {
                network + "}  lp{" +
                linkProperties + "}  nc{" +
                networkCapabilities + "}  Score{" + getCurrentScore() + "}  " +
                "everValidated{" + everValidated + "} created{" + created + "} " +
                "everValidated{" + everValidated + "}  lastValidated{" + lastValidated + "}  " +
                "created{" + created + "}  " +
                "explicitlySelected{" + networkMisc.explicitlySelected + "} }";
    }