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

Commit da1798c8 authored by Bookatz's avatar Bookatz
Browse files

Statsd atom: Wifi on (enabled) and running

BatteryStats logs when Wifi is 'running' and 'on'.
It appears that 'on' is the Wifi on/off toggle, while 'running'
is Wifi actually working. Right now, only Client Mode is considered
running, which is probably wrong - Hotspot mode should probably be
included too.

'Running' is currently used by BatteryStats in its power blaming, so
statsd needs it too. Therefore it is added here, exactly as BatteryStats
uses it. In the future, this should be upgraded to be more accurate, but
that is beyond the scope of this cl.

Test: Manual only. Toggling 'Wifi On' via app is no longer allowed in Q.
Bug: 115639456
Change-Id: Icad7d1476bb6ff0788ffc690f0a27507d32cd4b8
parent 8168f6fa
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -169,6 +169,8 @@ message Atom {
        DocsUIRootVisitedReported docs_ui_root_visited = 110;
        DocsUIStartupMsReported docs_ui_startup_ms = 111;
        DocsUIUserActionReported docs_ui_user_action_reported = 112;
        WifiEnabledStateChanged wifi_enabled_state_changed = 113;
        WifiRunningStateChanged wifi_running_state_changed = 114;
    }

    // Pulled events will start at field 10000.
@@ -870,6 +872,37 @@ message KernelWakeupReported {
    optional int64 duration_micros = 2;
}

/**
 * Logs when Wifi is toggled on/off.
 *
 * Logged from:
 *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
 */
message WifiEnabledStateChanged {
    enum State {
        OFF = 0;
        ON = 1;
    }
    optional State state = 1;
}

/**
 * Logs when an app causes Wifi to run. In this context, 'to run' means to use Wifi Client Mode.
 * TODO: Include support for Hotspot.
 *
 * Logged from:
 *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
 */
message WifiRunningStateChanged {
    repeated AttributionNode attribution_node = 1;

    enum State {
        OFF = 0;
        ON = 1;
    }
    optional State state = 2;
}

/**
 * Logs wifi locks held by an app.
 *
+13 −0
Original line number Diff line number Diff line
@@ -724,6 +724,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
            mStats.noteWifiOnLocked();
        }
        StatsLog.write(StatsLog.WIFI_ENABLED_STATE_CHANGED,
                StatsLog.WIFI_ENABLED_STATE_CHANGED__STATE__ON);
    }

    public void noteWifiOff() {
@@ -731,6 +733,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
            mStats.noteWifiOffLocked();
        }
        StatsLog.write(StatsLog.WIFI_ENABLED_STATE_CHANGED,
                StatsLog.WIFI_ENABLED_STATE_CHANGED__STATE__OFF);
    }

    public void noteStartAudio(int uid) {
@@ -865,6 +869,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
            mStats.noteWifiRunningLocked(ws);
        }
        // TODO: Log WIFI_RUNNING_STATE_CHANGED in a better spot to include Hotspot too.
        StatsLog.write(StatsLog.WIFI_RUNNING_STATE_CHANGED,
                ws, StatsLog.WIFI_RUNNING_STATE_CHANGED__STATE__ON);
    }

    public void noteWifiRunningChanged(WorkSource oldWs, WorkSource newWs) {
@@ -872,6 +879,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
            mStats.noteWifiRunningChangedLocked(oldWs, newWs);
        }
        StatsLog.write(StatsLog.WIFI_RUNNING_STATE_CHANGED,
                newWs, StatsLog.WIFI_RUNNING_STATE_CHANGED__STATE__ON);
        StatsLog.write(StatsLog.WIFI_RUNNING_STATE_CHANGED,
                oldWs, StatsLog.WIFI_RUNNING_STATE_CHANGED__STATE__OFF);
    }

    public void noteWifiStopped(WorkSource ws) {
@@ -879,6 +890,8 @@ public final class BatteryStatsService extends IBatteryStats.Stub
        synchronized (mStats) {
            mStats.noteWifiStoppedLocked(ws);
        }
        StatsLog.write(StatsLog.WIFI_RUNNING_STATE_CHANGED,
                ws, StatsLog.WIFI_RUNNING_STATE_CHANGED__STATE__OFF);
    }

    public void noteWifiState(int wifiState, String accessPoint) {