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

Commit 17e5e2e5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add some atoms to statsd"

parents 38b93486 8c6571bd
Loading
Loading
Loading
Loading
+110 −0
Original line number Diff line number Diff line
@@ -57,6 +57,14 @@ message StatsEvent {
        UidProcessStateChanged uid_process_state_changed = 27;
        ProcessLifeCycleStateChanged process_life_cycle_state_changed = 28;
        ScreenStateChanged screen_state_changed = 29;
        BatteryLevelChanged battery_level_changed = 30;
        ChargingStateChanged charging_state_changed = 31;
        PluggedStateChanged plugged_state_changed = 32;
        DeviceTemperatureReported device_temperature_reported = 33;
        DeviceOnStatusChanged device_on_status_changed = 34;
        WakeupAlarmOccurred wakeup_alarm_occurred = 35;
        KernelWakeupReported kernel_wakeup_reported = 36;

        // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
    }
}
@@ -461,3 +469,105 @@ message ScreenBrightnessChanged {
    // Screen brightness level. Should be in [-1, 255] according to PowerManager.java.
    optional int32 level = 1;
}

/**
 * Logs battery level (percent full, from 0 to 100).
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message BatteryLevelChanged {
    // Battery level. Should be in [0, 100].
    optional int32 battery_level = 1;
}

/**
 * Logs change in charging status of the device.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message ChargingStateChanged {
    // TODO: Link directly to BatteryManager.java's constants (via a proto).
    enum State {
        BATTERY_STATUS_UNKNOWN = 1;
        BATTERY_STATUS_CHARGING = 2;
        BATTERY_STATUS_DISCHARGING = 3;
        BATTERY_STATUS_NOT_CHARGING = 4;
        BATTERY_STATUS_FULL = 5;
    }
    optional State charging_state = 1;
}

/**
 * Logs whether the device is plugged in, and what power source it is using.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message PluggedStateChanged {
    // TODO: Link directly to BatteryManager.java's constants (via a proto).
    enum State {
        // Note that NONE is not in BatteryManager.java's constants.
        BATTERY_PLUGGED_NONE = 0;
        // Power source is an AC charger.
        BATTERY_PLUGGED_AC = 1;
        // Power source is a USB port.
        BATTERY_PLUGGED_USB = 2;
        // Power source is wireless.
        BATTERY_PLUGGED_WIRELESS = 4;
    }
    optional State plugged_state = 1;
}

/**
 * Logs the temperature of the device, in tenths of a degree Celsius.
 *
 * Logged from:
  *   frameworks/base/core/java/com/android/internal/os/BatteryStatsImpl.java
 */
message DeviceTemperatureReported {
    // Temperature in tenths of a degree C.
    optional int32 temperature = 1;
}

// TODO: Define this more precisely.
// TODO: Log the ON state somewhere. It isn't currently logged anywhere.
/**
 * Logs when the device turns off or on.
 *
 * Logged from:
  *   frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
 */
message DeviceOnStatusChanged {
    enum State {
        OFF = 0;
        ON = 1;
    }
    optional State state = 1;
}

/**
 * Logs when an app's wakeup alarm fires.
 *
 * Logged from:
  *   frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java
 */
message WakeupAlarmOccurred {
    // TODO: Add attribution instead of uid?
    optional int32 uid = 1;
}

/**
 * Logs kernel wakeup reasons and aborts.
 *
 * Logged from:
 *   frameworks/base/services/core/java/com/android/server/am/BatteryStatsService.java
 */
message KernelWakeupReported {
    // Name of the kernel wakeup reason (or abort).
    optional string wakeup_reason_name = 1;

    // Duration (in microseconds) for the wake-up interrupt to be serviced.
    optional int64 duration_usec = 2;
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -1986,7 +1986,7 @@ public abstract class BatteryStats implements Parcelable {
    public abstract long getDeviceIdlingTime(int mode, long elapsedRealtimeUs, int which);

    /**
     * Returns the number of times that the devie has started idling.
     * Returns the number of times that the device has started idling.
     *
     * {@hide}
     */
+25 −2
Original line number Diff line number Diff line
@@ -4055,6 +4055,7 @@ public class BatteryStatsImpl extends BatteryStats {
            long deltaUptime = uptimeMs - mLastWakeupUptimeMs;
            SamplingTimer timer = getWakeupReasonTimerLocked(mLastWakeupReason);
            timer.add(deltaUptime * 1000, 1); // time in in microseconds
            StatsLog.write(StatsLog.KERNEL_WAKEUP_REPORTED, mLastWakeupReason, deltaUptime * 1000);
            mLastWakeupReason = null;
        }
    }
@@ -11156,11 +11157,15 @@ public class BatteryStatsImpl extends BatteryStats {
    // This should probably be exposed in the API, though it's not critical
    public static final int BATTERY_PLUGGED_NONE = 0;
    public void setBatteryStateLocked(int status, int health, int plugType, int level,
            int temp, int volt, int chargeUAh, int chargeFullUAh) {
    public void setBatteryStateLocked(final int status, final int health, final int plugType,
            final int level, /* not final */ int temp, final int volt, final int chargeUAh,
            final int chargeFullUAh) {
        // Temperature is encoded without the signed bit, so clamp any negative temperatures to 0.
        temp = Math.max(0, temp);
        reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null,
                status, plugType, level, temp);
        final boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
        final long uptime = mClocks.uptimeMillis();
        final long elapsedRealtime = mClocks.elapsedRealtime();
@@ -11337,6 +11342,24 @@ public class BatteryStatsImpl extends BatteryStats {
        mMaxLearnedBatteryCapacity = Math.max(mMaxLearnedBatteryCapacity, chargeFullUAh);
    }
    // Inform StatsLog of setBatteryState changes.
    // If this is the first reporting, pass in recentPast == null.
    private void reportChangesToStatsLog(HistoryItem recentPast,
            final int status, final int plugType, final int level, final int temp) {
        if (recentPast == null || recentPast.batteryStatus != status) {
            StatsLog.write(StatsLog.CHARGING_STATE_CHANGED, status);
        }
        if (recentPast == null || recentPast.batteryPlugType != plugType) {
            StatsLog.write(StatsLog.PLUGGED_STATE_CHANGED, plugType);
        }
        if (recentPast == null || recentPast.batteryLevel != level) {
            StatsLog.write(StatsLog.BATTERY_LEVEL_CHANGED, level);
        }
        // Let's just always print the temperature, regardless of whether it changed.
        StatsLog.write(StatsLog.DEVICE_TEMPERATURE_REPORTED, temp);
    }
    public long getAwakeTimeBattery() {
        return computeBatteryUptime(getBatteryUptimeLocked(), STATS_CURRENT);
    }
+5 −0
Original line number Diff line number Diff line
@@ -334,6 +334,7 @@ import android.text.style.SuggestionSpan;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.AtomicFile;
import android.util.StatsLog;
import android.util.TimingsTraceLog;
import android.util.DebugUtils;
import android.util.DisplayMetrics;
@@ -12332,6 +12333,9 @@ public class ActivityManagerService extends IActivityManager.Stub
                    + android.Manifest.permission.SHUTDOWN);
        }
        // TODO: Where should the corresponding '1' (start) write go?
        StatsLog.write(StatsLog.DEVICE_ON_STATUS_CHANGED, 0);
        boolean timedout = false;
        synchronized(this) {
@@ -13514,6 +13518,7 @@ public class ActivityManagerService extends IActivityManager.Stub
                    stats.getPackageStatsLocked(sourceUid >= 0 ? sourceUid : uid,
                            sourcePkg != null ? sourcePkg : rec.key.packageName);
                pkg.noteWakeupAlarmLocked(tag);
                StatsLog.write(StatsLog.WAKEUP_ALARM_OCCURRED, sourceUid >= 0 ? sourceUid : uid);
            }
        }
    }