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

Commit e588524f authored by Bookatz's avatar Bookatz
Browse files

Add more atoms to statsd

The following events are added to statsd:
WifiLockStateChanged
WifiSignalStrengthChanged
WifiSignalStrengthChanged
PhoneSignalStrengthChanged

Test: manually confirmed these show up in the statslog.
Change-Id: Ifee27c86a28616d8cb9d43bdf11f9cabe2b367c6
parent d674624a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ namespace android {
namespace os {
namespace statsd {

// TODO: Can probably be used for Count, Value, and Gauge. If so, rename to ValueAnomalyTracker.
// (caveat: currently, the value cannot be negative. Probably fine for P.)
class CountAnomalyTracker {
public:
    CountAnomalyTracker(const Alert& alert);
+74 −0
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ message StatsEvent {
        DeviceOnStatusChanged device_on_status_changed = 34;
        WakeupAlarmOccurred wakeup_alarm_occurred = 35;
        KernelWakeupReported kernel_wakeup_reported = 36;
        WifiLockStateChanged wifi_lock_state_changed = 37;
        WifiSignalStrengthChanged wifi_signal_strength_changed = 38;
        WifiScanStateChanged wifi_scan_state_changed = 39;
        PhoneSignalStrengthChanged phone_signal_strength_changed = 40;

        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }
@@ -572,3 +576,73 @@ message KernelWakeupReported {
    // Duration (in microseconds) for the wake-up interrupt to be serviced.
    optional int64 duration_usec = 2;
}

/**
 * Logs wifi locks held by an app.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message WifiLockStateChanged {
    // TODO: Add attribution instead of uid.
    optional int32 uid = 1;

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

/**
 * Logs wifi signal strength changes.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message WifiSignalStrengthChanged {
    // TODO: Reference the actual telephony/java/android/telephony/SignalStrength.java states.
    enum SignalStrength {
        SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
        SIGNAL_STRENGTH_POOR = 1;
        SIGNAL_STRENGTH_MODERATE = 2;
        SIGNAL_STRENGTH_GOOD = 3;
        SIGNAL_STRENGTH_GREAT = 4;
    }
    optional SignalStrength signal_strength = 1;
}

/**
 * Logs wifi scans performed by an app.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message WifiScanStateChanged {
    // TODO: Add attribution instead of uid.
    optional int32 uid = 1;

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

/**
 * Logs phone signal strength changes.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message PhoneSignalStrengthChanged {
    // TODO: Reference the actual telephony/java/android/telephony/SignalStrength.java states.
    enum SignalStrength {
        SIGNAL_STRENGTH_NONE_OR_UNKNOWN = 0;
        SIGNAL_STRENGTH_POOR = 1;
        SIGNAL_STRENGTH_MODERATE = 2;
        SIGNAL_STRENGTH_GOOD = 3;
        SIGNAL_STRENGTH_GREAT = 4;
    }
    optional SignalStrength signal_strength = 1;
}
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
@@ -4634,6 +4634,7 @@ public class BatteryStatsImpl extends BatteryStats {
                if (DEBUG_HISTORY) Slog.v(TAG, "Signal strength " + strengthBin + " to: "
                        + Integer.toHexString(mHistoryCur.states));
                newHistory = true;
                StatsLog.write(StatsLog.PHONE_SIGNAL_STRENGTH_CHANGED, strengthBin);
            } else {
                stopAllPhoneSignalStrengthTimersLocked(-1);
            }
@@ -5189,6 +5190,7 @@ public class BatteryStatsImpl extends BatteryStats {
            if (strengthBin >= 0) {
                if (!mWifiSignalStrengthsTimer[strengthBin].isRunningLocked()) {
                    mWifiSignalStrengthsTimer[strengthBin].startRunningLocked(elapsedRealtime);
                    StatsLog.write(StatsLog.WIFI_SIGNAL_STRENGTH_CHANGED, strengthBin);
                }
                mHistoryCur.states2 =
                        (mHistoryCur.states2&~HistoryItem.STATE2_WIFI_SIGNAL_STRENGTH_MASK)
@@ -6054,6 +6056,8 @@ public class BatteryStatsImpl extends BatteryStats {
                            mBsi.mFullWifiLockTimers, mBsi.mOnBatteryTimeBase);
                }
                mFullWifiLockTimer.startRunningLocked(elapsedRealtimeMs);
                // TODO(statsd): Possibly use a worksource instead of a uid.
                StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, getUid(), 1);
            }
        }
@@ -6062,6 +6066,10 @@ public class BatteryStatsImpl extends BatteryStats {
            if (mFullWifiLockOut) {
                mFullWifiLockOut = false;
                mFullWifiLockTimer.stopRunningLocked(elapsedRealtimeMs);
                if (!mFullWifiLockTimer.isRunningLocked()) { // only tell statsd if truly stopped
                    // TODO(statsd): Possibly use a worksource instead of a uid.
                    StatsLog.write(StatsLog.WIFI_LOCK_STATE_CHANGED, getUid(), 0);
                }
            }
        }
@@ -6075,6 +6083,8 @@ public class BatteryStatsImpl extends BatteryStats {
                            mOnBatteryBackgroundTimeBase);
                }
                mWifiScanTimer.startRunningLocked(elapsedRealtimeMs);
                // TODO(statsd): Possibly use a worksource instead of a uid.
                StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, getUid(), 1);
            }
        }
@@ -6083,6 +6093,10 @@ public class BatteryStatsImpl extends BatteryStats {
            if (mWifiScanStarted) {
                mWifiScanStarted = false;
                mWifiScanTimer.stopRunningLocked(elapsedRealtimeMs);
                if (!mWifiScanTimer.isRunningLocked()) { // only tell statsd if truly stopped
                    // TODO(statsd): Possibly use a worksource instead of a uid.
                    StatsLog.write(StatsLog.WIFI_SCAN_STATE_CHANGED, getUid(), 0);
                }
            }
        }