Search in sources :

Example 1 with BatteryStats

use of android.os.BatteryStats in project platform_frameworks_base by android.

the class BatteryStatsHelper method statsFromFile.

public static BatteryStats statsFromFile(Context context, String fname) {
    synchronized (sFileXfer) {
        File path = makeFilePath(context, fname);
        BatteryStats stats = sFileXfer.get(path);
        if (stats != null) {
            return stats;
        }
        FileInputStream fin = null;
        try {
            fin = new FileInputStream(path);
            byte[] data = readFully(fin);
            Parcel parcel = Parcel.obtain();
            parcel.unmarshall(data, 0, data.length);
            parcel.setDataPosition(0);
            return com.android.internal.os.BatteryStatsImpl.CREATOR.createFromParcel(parcel);
        } catch (IOException e) {
            Log.w(TAG, "Unable to read history to file", e);
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (IOException e) {
                }
            }
        }
    }
    return getStats(IBatteryStats.Stub.asInterface(ServiceManager.getService(BatteryStats.SERVICE_NAME)));
}
Also used : Parcel(android.os.Parcel) IOException(java.io.IOException) MemoryFile(android.os.MemoryFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IBatteryStats(com.android.internal.app.IBatteryStats) BatteryStats(android.os.BatteryStats)

Example 2 with BatteryStats

use of android.os.BatteryStats in project platform_frameworks_base by android.

the class HealthStatsBatteryStatsWriter method writeUid.

/**
     * Writes the contents of a BatteryStats.Uid into a HealthStatsWriter.
     */
public void writeUid(HealthStatsWriter uidWriter, BatteryStats bs, BatteryStats.Uid uid) {
    int N;
    BatteryStats.Timer timer;
    SparseArray<? extends BatteryStats.Uid.Sensor> sensors;
    SparseArray<? extends BatteryStats.Uid.Pid> pids;
    BatteryStats.ControllerActivityCounter controller;
    long sum;
    //
    // It's a little odd for these first four to be here but it's not the end of the
    // world. It would be easy enough to duplicate them somewhere else if this API
    // grows.
    //
    // MEASUREMENT_REALTIME_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, bs.computeBatteryRealtime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_UPTIME_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_BATTERY_MS, bs.computeBatteryUptime(mNowUptimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS, bs.computeBatteryScreenOffRealtime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS, bs.computeBatteryScreenOffUptime(mNowUptimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> entry : uid.getWakelockStats().entrySet()) {
        final String key = entry.getKey();
        final BatteryStats.Uid.Wakelock wakelock = entry.getValue();
        // TIMERS_WAKELOCKS_FULL
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_FULL);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_FULL, key, timer);
        // TIMERS_WAKELOCKS_PARTIAL
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_PARTIAL, key, timer);
        // TIMERS_WAKELOCKS_WINDOW
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_WINDOW);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_WINDOW, key, timer);
        // TIMERS_WAKELOCKS_DRAW
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_DRAW);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_DRAW, key, timer);
    }
    // TIMERS_SYNCS
    for (final Map.Entry<String, ? extends BatteryStats.Timer> entry : uid.getSyncStats().entrySet()) {
        addTimers(uidWriter, UidHealthStats.TIMERS_SYNCS, entry.getKey(), entry.getValue());
    }
    // TIMERS_JOBS
    for (final Map.Entry<String, ? extends BatteryStats.Timer> entry : uid.getJobStats().entrySet()) {
        addTimers(uidWriter, UidHealthStats.TIMERS_JOBS, entry.getKey(), entry.getValue());
    }
    // TIMERS_SENSORS
    sensors = uid.getSensorStats();
    N = sensors.size();
    for (int i = 0; i < N; i++) {
        int sensorId = sensors.keyAt(i);
        // as a separate metric here so as to not expose that in the API.
        if (sensorId == BatteryStats.Uid.Sensor.GPS) {
            addTimer(uidWriter, UidHealthStats.TIMER_GPS_SENSOR, sensors.valueAt(i).getSensorTime());
        } else {
            addTimers(uidWriter, UidHealthStats.TIMERS_SENSORS, Integer.toString(sensorId), sensors.valueAt(i).getSensorTime());
        }
    }
    // STATS_PIDS
    pids = uid.getPidStats();
    N = pids.size();
    for (int i = 0; i < N; i++) {
        final HealthStatsWriter writer = new HealthStatsWriter(PidHealthStats.CONSTANTS);
        writePid(writer, pids.valueAt(i));
        uidWriter.addStats(UidHealthStats.STATS_PIDS, Integer.toString(pids.keyAt(i)), writer);
    }
    // STATS_PROCESSES
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Proc> entry : uid.getProcessStats().entrySet()) {
        final HealthStatsWriter writer = new HealthStatsWriter(ProcessHealthStats.CONSTANTS);
        writeProc(writer, entry.getValue());
        uidWriter.addStats(UidHealthStats.STATS_PROCESSES, entry.getKey(), writer);
    }
    // STATS_PACKAGES
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Pkg> entry : uid.getPackageStats().entrySet()) {
        final HealthStatsWriter writer = new HealthStatsWriter(PackageHealthStats.CONSTANTS);
        writePkg(writer, entry.getValue());
        uidWriter.addStats(UidHealthStats.STATS_PACKAGES, entry.getKey(), writer);
    }
    controller = uid.getWifiControllerActivity();
    if (controller != null) {
        // MEASUREMENT_WIFI_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_WIFI_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_WIFI_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_MS, sum);
        // MEASUREMENT_WIFI_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    controller = uid.getBluetoothControllerActivity();
    if (controller != null) {
        // MEASUREMENT_BLUETOOTH_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_BLUETOOTH_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_BLUETOOTH_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_MS, sum);
        // MEASUREMENT_BLUETOOTH_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    controller = uid.getModemControllerActivity();
    if (controller != null) {
        // MEASUREMENT_MOBILE_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_MOBILE_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_MOBILE_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_MS, sum);
        // MEASUREMENT_MOBILE_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    // MEASUREMENT_WIFI_RUNNING_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RUNNING_MS, uid.getWifiRunningTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_WIFI_FULL_LOCK_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_FULL_LOCK_MS, uid.getFullWifiLockTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // TIMER_WIFI_SCAN
    uidWriter.addTimer(UidHealthStats.TIMER_WIFI_SCAN, uid.getWifiScanCount(STATS_SINCE_UNPLUGGED), uid.getWifiScanTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_WIFI_MULTICAST_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_MULTICAST_MS, uid.getWifiMulticastTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // TIMER_AUDIO
    addTimer(uidWriter, UidHealthStats.TIMER_AUDIO, uid.getAudioTurnedOnTimer());
    // TIMER_VIDEO
    addTimer(uidWriter, UidHealthStats.TIMER_VIDEO, uid.getVideoTurnedOnTimer());
    // TIMER_FLASHLIGHT
    addTimer(uidWriter, UidHealthStats.TIMER_FLASHLIGHT, uid.getFlashlightTurnedOnTimer());
    // TIMER_CAMERA
    addTimer(uidWriter, UidHealthStats.TIMER_CAMERA, uid.getCameraTurnedOnTimer());
    // TIMER_FOREGROUND_ACTIVITY
    addTimer(uidWriter, UidHealthStats.TIMER_FOREGROUND_ACTIVITY, uid.getForegroundActivityTimer());
    // TIMER_BLUETOOTH_SCAN
    addTimer(uidWriter, UidHealthStats.TIMER_BLUETOOTH_SCAN, uid.getBluetoothScanTimer());
    // TIMER_PROCESS_STATE_TOP_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP));
    // TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE));
    // TIMER_PROCESS_STATE_TOP_SLEEPING_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_SLEEPING_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING));
    // TIMER_PROCESS_STATE_FOREGROUND_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND));
    // TIMER_PROCESS_STATE_BACKGROUND_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_BACKGROUND_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_BACKGROUND));
    // TIMER_PROCESS_STATE_CACHED_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_CACHED_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_CACHED));
    // TIMER_VIBRATOR
    addTimer(uidWriter, UidHealthStats.TIMER_VIBRATOR, uid.getVibratorOnTimer());
    // MEASUREMENT_OTHER_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_OTHER_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_OTHER, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_BUTTON, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_TOUCH, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_TX_DATA, STATS_SINCE_UNPLUGGED));
    // TIMER_MOBILE_RADIO_ACTIVE
    uidWriter.addTimer(UidHealthStats.TIMER_MOBILE_RADIO_ACTIVE, uid.getMobileRadioActiveCount(STATS_SINCE_UNPLUGGED), uid.getMobileRadioActiveTime(STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_USER_CPU_TIME_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_USER_CPU_TIME_MS, uid.getUserCpuTimeUs(STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_SYSTEM_CPU_TIME_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_SYSTEM_CPU_TIME_MS, uid.getSystemCpuTimeUs(STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_CPU_POWER_MAMS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_CPU_POWER_MAMS, uid.getCpuPowerMaUs(STATS_SINCE_UNPLUGGED) / 1000);
}
Also used : BatteryStats(android.os.BatteryStats) HealthStatsWriter(android.os.health.HealthStatsWriter) Map(java.util.Map)

Example 3 with BatteryStats

use of android.os.BatteryStats in project android_frameworks_base by DirtyUnicorns.

the class HealthStatsBatteryStatsWriter method writeUid.

/**
     * Writes the contents of a BatteryStats.Uid into a HealthStatsWriter.
     */
public void writeUid(HealthStatsWriter uidWriter, BatteryStats bs, BatteryStats.Uid uid) {
    int N;
    BatteryStats.Timer timer;
    SparseArray<? extends BatteryStats.Uid.Sensor> sensors;
    SparseArray<? extends BatteryStats.Uid.Pid> pids;
    BatteryStats.ControllerActivityCounter controller;
    long sum;
    //
    // It's a little odd for these first four to be here but it's not the end of the
    // world. It would be easy enough to duplicate them somewhere else if this API
    // grows.
    //
    // MEASUREMENT_REALTIME_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, bs.computeBatteryRealtime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_UPTIME_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_BATTERY_MS, bs.computeBatteryUptime(mNowUptimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS, bs.computeBatteryScreenOffRealtime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS, bs.computeBatteryScreenOffUptime(mNowUptimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> entry : uid.getWakelockStats().entrySet()) {
        final String key = entry.getKey();
        final BatteryStats.Uid.Wakelock wakelock = entry.getValue();
        // TIMERS_WAKELOCKS_FULL
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_FULL);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_FULL, key, timer);
        // TIMERS_WAKELOCKS_PARTIAL
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_PARTIAL, key, timer);
        // TIMERS_WAKELOCKS_WINDOW
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_WINDOW);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_WINDOW, key, timer);
        // TIMERS_WAKELOCKS_DRAW
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_DRAW);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_DRAW, key, timer);
    }
    // TIMERS_SYNCS
    for (final Map.Entry<String, ? extends BatteryStats.Timer> entry : uid.getSyncStats().entrySet()) {
        addTimers(uidWriter, UidHealthStats.TIMERS_SYNCS, entry.getKey(), entry.getValue());
    }
    // TIMERS_JOBS
    for (final Map.Entry<String, ? extends BatteryStats.Timer> entry : uid.getJobStats().entrySet()) {
        addTimers(uidWriter, UidHealthStats.TIMERS_JOBS, entry.getKey(), entry.getValue());
    }
    // TIMERS_SENSORS
    sensors = uid.getSensorStats();
    N = sensors.size();
    for (int i = 0; i < N; i++) {
        int sensorId = sensors.keyAt(i);
        // as a separate metric here so as to not expose that in the API.
        if (sensorId == BatteryStats.Uid.Sensor.GPS) {
            addTimer(uidWriter, UidHealthStats.TIMER_GPS_SENSOR, sensors.valueAt(i).getSensorTime());
        } else {
            addTimers(uidWriter, UidHealthStats.TIMERS_SENSORS, Integer.toString(sensorId), sensors.valueAt(i).getSensorTime());
        }
    }
    // STATS_PIDS
    pids = uid.getPidStats();
    N = pids.size();
    for (int i = 0; i < N; i++) {
        final HealthStatsWriter writer = new HealthStatsWriter(PidHealthStats.CONSTANTS);
        writePid(writer, pids.valueAt(i));
        uidWriter.addStats(UidHealthStats.STATS_PIDS, Integer.toString(pids.keyAt(i)), writer);
    }
    // STATS_PROCESSES
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Proc> entry : uid.getProcessStats().entrySet()) {
        final HealthStatsWriter writer = new HealthStatsWriter(ProcessHealthStats.CONSTANTS);
        writeProc(writer, entry.getValue());
        uidWriter.addStats(UidHealthStats.STATS_PROCESSES, entry.getKey(), writer);
    }
    // STATS_PACKAGES
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Pkg> entry : uid.getPackageStats().entrySet()) {
        final HealthStatsWriter writer = new HealthStatsWriter(PackageHealthStats.CONSTANTS);
        writePkg(writer, entry.getValue());
        uidWriter.addStats(UidHealthStats.STATS_PACKAGES, entry.getKey(), writer);
    }
    controller = uid.getWifiControllerActivity();
    if (controller != null) {
        // MEASUREMENT_WIFI_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_WIFI_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_WIFI_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_MS, sum);
        // MEASUREMENT_WIFI_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    controller = uid.getBluetoothControllerActivity();
    if (controller != null) {
        // MEASUREMENT_BLUETOOTH_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_BLUETOOTH_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_BLUETOOTH_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_MS, sum);
        // MEASUREMENT_BLUETOOTH_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    controller = uid.getModemControllerActivity();
    if (controller != null) {
        // MEASUREMENT_MOBILE_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_MOBILE_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_MOBILE_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_MS, sum);
        // MEASUREMENT_MOBILE_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    // MEASUREMENT_WIFI_RUNNING_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RUNNING_MS, uid.getWifiRunningTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_WIFI_FULL_LOCK_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_FULL_LOCK_MS, uid.getFullWifiLockTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // TIMER_WIFI_SCAN
    uidWriter.addTimer(UidHealthStats.TIMER_WIFI_SCAN, uid.getWifiScanCount(STATS_SINCE_UNPLUGGED), uid.getWifiScanTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_WIFI_MULTICAST_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_MULTICAST_MS, uid.getWifiMulticastTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // TIMER_AUDIO
    addTimer(uidWriter, UidHealthStats.TIMER_AUDIO, uid.getAudioTurnedOnTimer());
    // TIMER_VIDEO
    addTimer(uidWriter, UidHealthStats.TIMER_VIDEO, uid.getVideoTurnedOnTimer());
    // TIMER_FLASHLIGHT
    addTimer(uidWriter, UidHealthStats.TIMER_FLASHLIGHT, uid.getFlashlightTurnedOnTimer());
    // TIMER_CAMERA
    addTimer(uidWriter, UidHealthStats.TIMER_CAMERA, uid.getCameraTurnedOnTimer());
    // TIMER_FOREGROUND_ACTIVITY
    addTimer(uidWriter, UidHealthStats.TIMER_FOREGROUND_ACTIVITY, uid.getForegroundActivityTimer());
    // TIMER_BLUETOOTH_SCAN
    addTimer(uidWriter, UidHealthStats.TIMER_BLUETOOTH_SCAN, uid.getBluetoothScanTimer());
    // TIMER_PROCESS_STATE_TOP_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP));
    // TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE));
    // TIMER_PROCESS_STATE_TOP_SLEEPING_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_SLEEPING_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING));
    // TIMER_PROCESS_STATE_FOREGROUND_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND));
    // TIMER_PROCESS_STATE_BACKGROUND_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_BACKGROUND_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_BACKGROUND));
    // TIMER_PROCESS_STATE_CACHED_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_CACHED_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_CACHED));
    // TIMER_VIBRATOR
    addTimer(uidWriter, UidHealthStats.TIMER_VIBRATOR, uid.getVibratorOnTimer());
    // MEASUREMENT_OTHER_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_OTHER_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_OTHER, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_BUTTON, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_TOUCH, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_TX_DATA, STATS_SINCE_UNPLUGGED));
    // TIMER_MOBILE_RADIO_ACTIVE
    uidWriter.addTimer(UidHealthStats.TIMER_MOBILE_RADIO_ACTIVE, uid.getMobileRadioActiveCount(STATS_SINCE_UNPLUGGED), uid.getMobileRadioActiveTime(STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_USER_CPU_TIME_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_USER_CPU_TIME_MS, uid.getUserCpuTimeUs(STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_SYSTEM_CPU_TIME_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_SYSTEM_CPU_TIME_MS, uid.getSystemCpuTimeUs(STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_CPU_POWER_MAMS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_CPU_POWER_MAMS, uid.getCpuPowerMaUs(STATS_SINCE_UNPLUGGED) / 1000);
}
Also used : BatteryStats(android.os.BatteryStats) HealthStatsWriter(android.os.health.HealthStatsWriter) Map(java.util.Map)

Example 4 with BatteryStats

use of android.os.BatteryStats in project android_frameworks_base by AOSPA.

the class HealthStatsBatteryStatsWriter method writeUid.

/**
     * Writes the contents of a BatteryStats.Uid into a HealthStatsWriter.
     */
public void writeUid(HealthStatsWriter uidWriter, BatteryStats bs, BatteryStats.Uid uid) {
    int N;
    BatteryStats.Timer timer;
    SparseArray<? extends BatteryStats.Uid.Sensor> sensors;
    SparseArray<? extends BatteryStats.Uid.Pid> pids;
    BatteryStats.ControllerActivityCounter controller;
    long sum;
    //
    // It's a little odd for these first four to be here but it's not the end of the
    // world. It would be easy enough to duplicate them somewhere else if this API
    // grows.
    //
    // MEASUREMENT_REALTIME_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_BATTERY_MS, bs.computeBatteryRealtime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_UPTIME_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_BATTERY_MS, bs.computeBatteryUptime(mNowUptimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_REALTIME_SCREEN_OFF_BATTERY_MS, bs.computeBatteryScreenOffRealtime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_UPTIME_SCREEN_OFF_BATTERY_MS, bs.computeBatteryScreenOffUptime(mNowUptimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Wakelock> entry : uid.getWakelockStats().entrySet()) {
        final String key = entry.getKey();
        final BatteryStats.Uid.Wakelock wakelock = entry.getValue();
        // TIMERS_WAKELOCKS_FULL
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_FULL);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_FULL, key, timer);
        // TIMERS_WAKELOCKS_PARTIAL
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_PARTIAL);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_PARTIAL, key, timer);
        // TIMERS_WAKELOCKS_WINDOW
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_WINDOW);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_WINDOW, key, timer);
        // TIMERS_WAKELOCKS_DRAW
        timer = wakelock.getWakeTime(BatteryStats.WAKE_TYPE_DRAW);
        addTimers(uidWriter, UidHealthStats.TIMERS_WAKELOCKS_DRAW, key, timer);
    }
    // TIMERS_SYNCS
    for (final Map.Entry<String, ? extends BatteryStats.Timer> entry : uid.getSyncStats().entrySet()) {
        addTimers(uidWriter, UidHealthStats.TIMERS_SYNCS, entry.getKey(), entry.getValue());
    }
    // TIMERS_JOBS
    for (final Map.Entry<String, ? extends BatteryStats.Timer> entry : uid.getJobStats().entrySet()) {
        addTimers(uidWriter, UidHealthStats.TIMERS_JOBS, entry.getKey(), entry.getValue());
    }
    // TIMERS_SENSORS
    sensors = uid.getSensorStats();
    N = sensors.size();
    for (int i = 0; i < N; i++) {
        int sensorId = sensors.keyAt(i);
        // as a separate metric here so as to not expose that in the API.
        if (sensorId == BatteryStats.Uid.Sensor.GPS) {
            addTimer(uidWriter, UidHealthStats.TIMER_GPS_SENSOR, sensors.valueAt(i).getSensorTime());
        } else {
            addTimers(uidWriter, UidHealthStats.TIMERS_SENSORS, Integer.toString(sensorId), sensors.valueAt(i).getSensorTime());
        }
    }
    // STATS_PIDS
    pids = uid.getPidStats();
    N = pids.size();
    for (int i = 0; i < N; i++) {
        final HealthStatsWriter writer = new HealthStatsWriter(PidHealthStats.CONSTANTS);
        writePid(writer, pids.valueAt(i));
        uidWriter.addStats(UidHealthStats.STATS_PIDS, Integer.toString(pids.keyAt(i)), writer);
    }
    // STATS_PROCESSES
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Proc> entry : uid.getProcessStats().entrySet()) {
        final HealthStatsWriter writer = new HealthStatsWriter(ProcessHealthStats.CONSTANTS);
        writeProc(writer, entry.getValue());
        uidWriter.addStats(UidHealthStats.STATS_PROCESSES, entry.getKey(), writer);
    }
    // STATS_PACKAGES
    for (final Map.Entry<String, ? extends BatteryStats.Uid.Pkg> entry : uid.getPackageStats().entrySet()) {
        final HealthStatsWriter writer = new HealthStatsWriter(PackageHealthStats.CONSTANTS);
        writePkg(writer, entry.getValue());
        uidWriter.addStats(UidHealthStats.STATS_PACKAGES, entry.getKey(), writer);
    }
    controller = uid.getWifiControllerActivity();
    if (controller != null) {
        // MEASUREMENT_WIFI_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_WIFI_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_WIFI_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_MS, sum);
        // MEASUREMENT_WIFI_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    controller = uid.getBluetoothControllerActivity();
    if (controller != null) {
        // MEASUREMENT_BLUETOOTH_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_BLUETOOTH_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_BLUETOOTH_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_MS, sum);
        // MEASUREMENT_BLUETOOTH_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    controller = uid.getModemControllerActivity();
    if (controller != null) {
        // MEASUREMENT_MOBILE_IDLE_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_IDLE_MS, controller.getIdleTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_MOBILE_RX_MS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_MS, controller.getRxTimeCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
        // MEASUREMENT_MOBILE_TX_MS
        sum = 0;
        for (final BatteryStats.LongCounter counter : controller.getTxTimeCounters()) {
            sum += counter.getCountLocked(STATS_SINCE_UNPLUGGED);
        }
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_MS, sum);
        // MEASUREMENT_MOBILE_POWER_MAMS
        uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_POWER_MAMS, controller.getPowerCounter().getCountLocked(STATS_SINCE_UNPLUGGED));
    }
    // MEASUREMENT_WIFI_RUNNING_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RUNNING_MS, uid.getWifiRunningTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_WIFI_FULL_LOCK_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_FULL_LOCK_MS, uid.getFullWifiLockTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // TIMER_WIFI_SCAN
    uidWriter.addTimer(UidHealthStats.TIMER_WIFI_SCAN, uid.getWifiScanCount(STATS_SINCE_UNPLUGGED), uid.getWifiScanTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_WIFI_MULTICAST_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_MULTICAST_MS, uid.getWifiMulticastTime(mNowRealtimeMs * 1000, STATS_SINCE_UNPLUGGED) / 1000);
    // TIMER_AUDIO
    addTimer(uidWriter, UidHealthStats.TIMER_AUDIO, uid.getAudioTurnedOnTimer());
    // TIMER_VIDEO
    addTimer(uidWriter, UidHealthStats.TIMER_VIDEO, uid.getVideoTurnedOnTimer());
    // TIMER_FLASHLIGHT
    addTimer(uidWriter, UidHealthStats.TIMER_FLASHLIGHT, uid.getFlashlightTurnedOnTimer());
    // TIMER_CAMERA
    addTimer(uidWriter, UidHealthStats.TIMER_CAMERA, uid.getCameraTurnedOnTimer());
    // TIMER_FOREGROUND_ACTIVITY
    addTimer(uidWriter, UidHealthStats.TIMER_FOREGROUND_ACTIVITY, uid.getForegroundActivityTimer());
    // TIMER_BLUETOOTH_SCAN
    addTimer(uidWriter, UidHealthStats.TIMER_BLUETOOTH_SCAN, uid.getBluetoothScanTimer());
    // TIMER_PROCESS_STATE_TOP_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP));
    // TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_SERVICE_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE));
    // TIMER_PROCESS_STATE_TOP_SLEEPING_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_TOP_SLEEPING_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING));
    // TIMER_PROCESS_STATE_FOREGROUND_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_FOREGROUND_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_FOREGROUND));
    // TIMER_PROCESS_STATE_BACKGROUND_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_BACKGROUND_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_BACKGROUND));
    // TIMER_PROCESS_STATE_CACHED_MS
    addTimer(uidWriter, UidHealthStats.TIMER_PROCESS_STATE_CACHED_MS, uid.getProcessStateTimer(BatteryStats.Uid.PROCESS_STATE_CACHED));
    // TIMER_VIBRATOR
    addTimer(uidWriter, UidHealthStats.TIMER_VIBRATOR, uid.getVibratorOnTimer());
    // MEASUREMENT_OTHER_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_OTHER_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_OTHER, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BUTTON_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_BUTTON, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_TOUCH_USER_ACTIVITY_COUNT, uid.getUserActivityCount(PowerManager.USER_ACTIVITY_EVENT_TOUCH, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_MOBILE_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_WIFI_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_RX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_TX_BYTES
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_BYTES, uid.getNetworkActivityBytes(BatteryStats.NETWORK_BT_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_MOBILE_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_MOBILE_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_MOBILE_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_WIFI_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_WIFI_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_WIFI_TX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_RX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_RX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_RX_DATA, STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_BLUETOOTH_TX_PACKETS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_BLUETOOTH_TX_PACKETS, uid.getNetworkActivityPackets(BatteryStats.NETWORK_BT_TX_DATA, STATS_SINCE_UNPLUGGED));
    // TIMER_MOBILE_RADIO_ACTIVE
    uidWriter.addTimer(UidHealthStats.TIMER_MOBILE_RADIO_ACTIVE, uid.getMobileRadioActiveCount(STATS_SINCE_UNPLUGGED), uid.getMobileRadioActiveTime(STATS_SINCE_UNPLUGGED));
    // MEASUREMENT_USER_CPU_TIME_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_USER_CPU_TIME_MS, uid.getUserCpuTimeUs(STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_SYSTEM_CPU_TIME_MS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_SYSTEM_CPU_TIME_MS, uid.getSystemCpuTimeUs(STATS_SINCE_UNPLUGGED) / 1000);
    // MEASUREMENT_CPU_POWER_MAMS
    uidWriter.addMeasurement(UidHealthStats.MEASUREMENT_CPU_POWER_MAMS, uid.getCpuPowerMaUs(STATS_SINCE_UNPLUGGED) / 1000);
}
Also used : BatteryStats(android.os.BatteryStats) HealthStatsWriter(android.os.health.HealthStatsWriter) Map(java.util.Map)

Example 5 with BatteryStats

use of android.os.BatteryStats in project android_frameworks_base by AOSPA.

the class BatteryStatsHelper method statsFromFile.

public static BatteryStats statsFromFile(Context context, String fname) {
    synchronized (sFileXfer) {
        File path = makeFilePath(context, fname);
        BatteryStats stats = sFileXfer.get(path);
        if (stats != null) {
            return stats;
        }
        FileInputStream fin = null;
        try {
            fin = new FileInputStream(path);
            byte[] data = readFully(fin);
            Parcel parcel = Parcel.obtain();
            parcel.unmarshall(data, 0, data.length);
            parcel.setDataPosition(0);
            return com.android.internal.os.BatteryStatsImpl.CREATOR.createFromParcel(parcel);
        } catch (IOException e) {
            Log.w(TAG, "Unable to read history to file", e);
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (IOException e) {
                }
            }
        }
    }
    return getStats(IBatteryStats.Stub.asInterface(ServiceManager.getService(BatteryStats.SERVICE_NAME)));
}
Also used : Parcel(android.os.Parcel) IOException(java.io.IOException) MemoryFile(android.os.MemoryFile) File(java.io.File) FileInputStream(java.io.FileInputStream) IBatteryStats(com.android.internal.app.IBatteryStats) BatteryStats(android.os.BatteryStats)

Aggregations

BatteryStats (android.os.BatteryStats)11 MemoryFile (android.os.MemoryFile)5 Parcel (android.os.Parcel)5 HealthStatsWriter (android.os.health.HealthStatsWriter)5 IBatteryStats (com.android.internal.app.IBatteryStats)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Drawable (android.graphics.drawable.Drawable)1 UserHandle (android.os.UserHandle)1 TypedValue (android.util.TypedValue)1 BatterySipper (com.android.internal.os.BatterySipper)1 PowerProfile (com.android.internal.os.PowerProfile)1