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

Commit 71a1b532 authored by Hugo Benichi's avatar Hugo Benichi
Browse files

DefaultNetworkEvent: fix two bugs with validation times

This patch fixes two bugs around the validation time calculation for
default network metrics:
  - for events representing the absence of a default network, the
    validation time was not correctly set to 0.
  - for events representing a default network, the validation time was
    always set to the duration time. This was overlooked by commit
    380a0638.

Also fix a minor printing padding issue in DefaultNetworkEvent#toString

Test: manually inspected the output of $ adb shell dumpsys connmetrics
      while enabling and disabling wifi.

Change-Id: I0eb4ccdf7a61d3097d0661104cb40d738e59772a
parent cdb84d2f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class DefaultNetworkEvent {
            j.add("final_score=" + finalScore);
        }
        j.add(String.format("duration=%.0fs", durationMs / 1000.0));
        j.add(String.format("validation=%4.1f%%", (validatedMs * 100.0) / durationMs));
        j.add(String.format("validation=%04.1f%%", (validatedMs * 100.0) / durationMs));
        return j.toString();
    }

+11 −3
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ public class DefaultNetworkMetrics {
    // Information about the current status of the default network.
    @GuardedBy("this")
    private DefaultNetworkEvent mCurrentDefaultNetwork;
    // True if the current default network has been validated.
    @GuardedBy("this")
    private boolean mIsCurrentlyValid;
    @GuardedBy("this")
@@ -71,6 +72,8 @@ public class DefaultNetworkMetrics {
            printEvent(localTimeMs, pw, ev);
        }
        mCurrentDefaultNetwork.updateDuration(timeMs);
        // When printing default network events for bug reports, update validation time
        // and refresh the last validation timestmap for future validation time updates.
        if (mIsCurrentlyValid) {
            updateValidationTime(timeMs);
            mLastValidationTimeMs = timeMs;
@@ -92,11 +95,13 @@ public class DefaultNetworkMetrics {
    }

    public synchronized void logDefaultNetworkValidity(long timeMs, boolean isValid) {
        // Transition from valid to invalid: update validity duration since last update
        if (!isValid && mIsCurrentlyValid) {
            mIsCurrentlyValid = false;
            updateValidationTime(timeMs);
        }

        // Transition from invalid to valid: simply mark the validation timestamp.
        if (isValid && !mIsCurrentlyValid) {
            mIsCurrentlyValid = true;
            mLastValidationTimeMs = timeMs;
@@ -114,6 +119,9 @@ public class DefaultNetworkMetrics {
    }

    private void logCurrentDefaultNetwork(long timeMs, NetworkAgentInfo oldNai) {
        if (mIsCurrentlyValid) {
            updateValidationTime(timeMs);
        }
        DefaultNetworkEvent ev = mCurrentDefaultNetwork;
        ev.updateDuration(timeMs);
        ev.previousTransports = mLastTransports;
@@ -122,7 +130,6 @@ public class DefaultNetworkMetrics {
            // The system acquired a new default network.
            fillLinkInfo(ev, oldNai);
            ev.finalScore = oldNai.getCurrentScore();
            ev.validatedMs = ev.durationMs;
        }
        // Only change transport of the previous default network if the event currently logged
        // corresponds to an existing default network, and not to the absence of a default network.
@@ -143,9 +150,10 @@ public class DefaultNetworkMetrics {
            fillLinkInfo(ev, newNai);
            ev.initialScore = newNai.getCurrentScore();
            if (newNai.lastValidated) {
                mIsCurrentlyValid = true;
                mLastValidationTimeMs = timeMs;
                logDefaultNetworkValidity(timeMs, true);
            }
        } else {
            mIsCurrentlyValid = false;
        }
        mCurrentDefaultNetwork = ev;
    }