Search in sources :

Example 6 with HistoryItem

use of android.os.BatteryStats.HistoryItem in project android_frameworks_base by crdroidandroid.

the class BatteryInfo method bindHistory.

public void bindHistory(final UsageView view, BatteryDataParser... parsers) {
    BatteryDataParser parser = new BatteryDataParser() {

        SparseIntArray points = new SparseIntArray();

        @Override
        public void onParsingStarted(long startTime, long endTime) {
            timePeriod = endTime - startTime - remainingTimeUs / 1000;
            view.clearPaths();
            view.configureGraph((int) (endTime - startTime), 100, remainingTimeUs != 0, mCharging);
        }

        @Override
        public void onDataPoint(long time, HistoryItem record) {
            points.put((int) time, record.batteryLevel);
        }

        @Override
        public void onDataGap() {
            if (points.size() > 1) {
                view.addPath(points);
            }
            points.clear();
        }

        @Override
        public void onParsingDone() {
            if (points.size() > 1) {
                view.addPath(points);
            }
        }
    };
    BatteryDataParser[] parserList = new BatteryDataParser[parsers.length + 1];
    for (int i = 0; i < parsers.length; i++) {
        parserList[i] = parsers[i];
    }
    parserList[parsers.length] = parser;
    parse(mStats, remainingTimeUs, parserList);
    final Context context = view.getContext();
    String timeString = context.getString(R.string.charge_length_format, Formatter.formatShortElapsedTime(context, Math.abs(timePeriod)));
    String remaining = "";
    if (remainingTimeUs != 0) {
        remaining = context.getString(R.string.remaining_length_format, Formatter.formatShortElapsedTime(context, remainingTimeUs / 1000));
    }
    view.setBottomLabels(new CharSequence[] { timeString, remaining });
}
Also used : Context(android.content.Context) SparseIntArray(android.util.SparseIntArray) HistoryItem(android.os.BatteryStats.HistoryItem)

Example 7 with HistoryItem

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

the class BatteryInfo method bindHistory.

public void bindHistory(final UsageView view, BatteryDataParser... parsers) {
    BatteryDataParser parser = new BatteryDataParser() {

        SparseIntArray points = new SparseIntArray();

        @Override
        public void onParsingStarted(long startTime, long endTime) {
            timePeriod = endTime - startTime - remainingTimeUs / 1000;
            view.clearPaths();
            view.configureGraph((int) (endTime - startTime), 100, remainingTimeUs != 0, mCharging);
        }

        @Override
        public void onDataPoint(long time, HistoryItem record) {
            points.put((int) time, record.batteryLevel);
        }

        @Override
        public void onDataGap() {
            if (points.size() > 1) {
                view.addPath(points);
            }
            points.clear();
        }

        @Override
        public void onParsingDone() {
            if (points.size() > 1) {
                view.addPath(points);
            }
        }
    };
    BatteryDataParser[] parserList = new BatteryDataParser[parsers.length + 1];
    for (int i = 0; i < parsers.length; i++) {
        parserList[i] = parsers[i];
    }
    parserList[parsers.length] = parser;
    parse(mStats, remainingTimeUs, parserList);
    final Context context = view.getContext();
    String timeString = context.getString(R.string.charge_length_format, Formatter.formatShortElapsedTime(context, Math.abs(timePeriod)));
    String remaining = "";
    if (remainingTimeUs != 0) {
        remaining = context.getString(R.string.remaining_length_format, Formatter.formatShortElapsedTime(context, remainingTimeUs / 1000));
    }
    view.setBottomLabels(new CharSequence[] { timeString, remaining });
}
Also used : Context(android.content.Context) SparseIntArray(android.util.SparseIntArray) HistoryItem(android.os.BatteryStats.HistoryItem)

Example 8 with HistoryItem

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

the class BatteryInfo method parse.

private static void parse(BatteryStats stats, long remainingTimeUs, BatteryDataParser... parsers) {
    long startWalltime = 0;
    long endDateWalltime = 0;
    long endWalltime = 0;
    long historyStart = 0;
    long historyEnd = 0;
    byte lastLevel = -1;
    long curWalltime = startWalltime;
    long lastWallTime = 0;
    long lastRealtime = 0;
    int lastInteresting = 0;
    int pos = 0;
    boolean first = true;
    if (stats.startIteratingHistoryLocked()) {
        final HistoryItem rec = new HistoryItem();
        while (stats.getNextHistoryLocked(rec)) {
            pos++;
            if (first) {
                first = false;
                historyStart = rec.time;
            }
            if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
                // pretty much just noise.
                if (rec.currentTime > (lastWallTime + (180 * 24 * 60 * 60 * 1000L)) || rec.time < (historyStart + (5 * 60 * 1000L))) {
                    startWalltime = 0;
                }
                lastWallTime = rec.currentTime;
                lastRealtime = rec.time;
                if (startWalltime == 0) {
                    startWalltime = lastWallTime - (lastRealtime - historyStart);
                }
            }
            if (rec.isDeltaData()) {
                if (rec.batteryLevel != lastLevel || pos == 1) {
                    lastLevel = rec.batteryLevel;
                }
                lastInteresting = pos;
                historyEnd = rec.time;
            }
        }
    }
    stats.finishIteratingHistoryLocked();
    endDateWalltime = lastWallTime + historyEnd - lastRealtime;
    endWalltime = endDateWalltime + (remainingTimeUs / 1000);
    int i = 0;
    final int N = lastInteresting;
    for (int j = 0; j < parsers.length; j++) {
        parsers[j].onParsingStarted(startWalltime, endWalltime);
    }
    if (endDateWalltime > startWalltime && stats.startIteratingHistoryLocked()) {
        final HistoryItem rec = new HistoryItem();
        while (stats.getNextHistoryLocked(rec) && i < N) {
            if (rec.isDeltaData()) {
                curWalltime += rec.time - lastRealtime;
                lastRealtime = rec.time;
                long x = (curWalltime - startWalltime);
                if (x < 0) {
                    x = 0;
                }
                for (int j = 0; j < parsers.length; j++) {
                    parsers[j].onDataPoint(x, rec);
                }
            } else {
                long lastWalltime = curWalltime;
                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
                    if (rec.currentTime >= startWalltime) {
                        curWalltime = rec.currentTime;
                    } else {
                        curWalltime = startWalltime + (rec.time - historyStart);
                    }
                    lastRealtime = rec.time;
                }
                if (rec.cmd != HistoryItem.CMD_OVERFLOW && (rec.cmd != HistoryItem.CMD_CURRENT_TIME || Math.abs(lastWalltime - curWalltime) > (60 * 60 * 1000))) {
                    for (int j = 0; j < parsers.length; j++) {
                        parsers[j].onDataGap();
                    }
                }
            }
            i++;
        }
    }
    stats.finishIteratingHistoryLocked();
    for (int j = 0; j < parsers.length; j++) {
        parsers[j].onParsingDone();
    }
}
Also used : HistoryItem(android.os.BatteryStats.HistoryItem)

Example 9 with HistoryItem

use of android.os.BatteryStats.HistoryItem in project android_frameworks_base by ResurrectionRemix.

the class BatteryInfo method parse.

private static void parse(BatteryStats stats, long remainingTimeUs, BatteryDataParser... parsers) {
    long startWalltime = 0;
    long endDateWalltime = 0;
    long endWalltime = 0;
    long historyStart = 0;
    long historyEnd = 0;
    byte lastLevel = -1;
    long curWalltime = startWalltime;
    long lastWallTime = 0;
    long lastRealtime = 0;
    int lastInteresting = 0;
    int pos = 0;
    boolean first = true;
    if (stats.startIteratingHistoryLocked()) {
        final HistoryItem rec = new HistoryItem();
        while (stats.getNextHistoryLocked(rec)) {
            pos++;
            if (first) {
                first = false;
                historyStart = rec.time;
            }
            if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
                // pretty much just noise.
                if (rec.currentTime > (lastWallTime + (180 * 24 * 60 * 60 * 1000L)) || rec.time < (historyStart + (5 * 60 * 1000L))) {
                    startWalltime = 0;
                }
                lastWallTime = rec.currentTime;
                lastRealtime = rec.time;
                if (startWalltime == 0) {
                    startWalltime = lastWallTime - (lastRealtime - historyStart);
                }
            }
            if (rec.isDeltaData()) {
                if (rec.batteryLevel != lastLevel || pos == 1) {
                    lastLevel = rec.batteryLevel;
                }
                lastInteresting = pos;
                historyEnd = rec.time;
            }
        }
    }
    stats.finishIteratingHistoryLocked();
    endDateWalltime = lastWallTime + historyEnd - lastRealtime;
    endWalltime = endDateWalltime + (remainingTimeUs / 1000);
    int i = 0;
    final int N = lastInteresting;
    for (int j = 0; j < parsers.length; j++) {
        parsers[j].onParsingStarted(startWalltime, endWalltime);
    }
    if (endDateWalltime > startWalltime && stats.startIteratingHistoryLocked()) {
        final HistoryItem rec = new HistoryItem();
        while (stats.getNextHistoryLocked(rec) && i < N) {
            if (rec.isDeltaData()) {
                curWalltime += rec.time - lastRealtime;
                lastRealtime = rec.time;
                long x = (curWalltime - startWalltime);
                if (x < 0) {
                    x = 0;
                }
                for (int j = 0; j < parsers.length; j++) {
                    parsers[j].onDataPoint(x, rec);
                }
            } else {
                long lastWalltime = curWalltime;
                if (rec.cmd == HistoryItem.CMD_CURRENT_TIME || rec.cmd == HistoryItem.CMD_RESET) {
                    if (rec.currentTime >= startWalltime) {
                        curWalltime = rec.currentTime;
                    } else {
                        curWalltime = startWalltime + (rec.time - historyStart);
                    }
                    lastRealtime = rec.time;
                }
                if (rec.cmd != HistoryItem.CMD_OVERFLOW && (rec.cmd != HistoryItem.CMD_CURRENT_TIME || Math.abs(lastWalltime - curWalltime) > (60 * 60 * 1000))) {
                    for (int j = 0; j < parsers.length; j++) {
                        parsers[j].onDataGap();
                    }
                }
            }
            i++;
        }
    }
    stats.finishIteratingHistoryLocked();
    for (int j = 0; j < parsers.length; j++) {
        parsers[j].onParsingDone();
    }
}
Also used : HistoryItem(android.os.BatteryStats.HistoryItem)

Example 10 with HistoryItem

use of android.os.BatteryStats.HistoryItem in project android_frameworks_base by ResurrectionRemix.

the class BatteryInfo method bindHistory.

public void bindHistory(final UsageView view, BatteryDataParser... parsers) {
    BatteryDataParser parser = new BatteryDataParser() {

        SparseIntArray points = new SparseIntArray();

        @Override
        public void onParsingStarted(long startTime, long endTime) {
            timePeriod = endTime - startTime - remainingTimeUs / 1000;
            view.clearPaths();
            view.configureGraph((int) (endTime - startTime), 100, remainingTimeUs != 0, mCharging);
        }

        @Override
        public void onDataPoint(long time, HistoryItem record) {
            points.put((int) time, record.batteryLevel);
        }

        @Override
        public void onDataGap() {
            if (points.size() > 1) {
                view.addPath(points);
            }
            points.clear();
        }

        @Override
        public void onParsingDone() {
            if (points.size() > 1) {
                view.addPath(points);
            }
        }
    };
    BatteryDataParser[] parserList = new BatteryDataParser[parsers.length + 1];
    for (int i = 0; i < parsers.length; i++) {
        parserList[i] = parsers[i];
    }
    parserList[parsers.length] = parser;
    parse(mStats, remainingTimeUs, parserList);
    final Context context = view.getContext();
    String timeString = context.getString(R.string.charge_length_format, Formatter.formatShortElapsedTime(context, Math.abs(timePeriod)));
    String remaining = "";
    if (remainingTimeUs != 0) {
        remaining = context.getString(R.string.remaining_length_format, Formatter.formatShortElapsedTime(context, remainingTimeUs / 1000));
    }
    view.setBottomLabels(new CharSequence[] { timeString, remaining });
}
Also used : Context(android.content.Context) SparseIntArray(android.util.SparseIntArray) HistoryItem(android.os.BatteryStats.HistoryItem)

Aggregations

HistoryItem (android.os.BatteryStats.HistoryItem)12 Context (android.content.Context)5 SparseIntArray (android.util.SparseIntArray)5 Paint (android.graphics.Paint)2 TextPaint (android.text.TextPaint)2 Path (android.graphics.Path)1 Calendar (java.util.Calendar)1