Loading core/java/android/app/ActivityManagerNative.java +10 −5 Original line number Diff line number Diff line Loading @@ -101,9 +101,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM } } static public void noteWakeupAlarm(PendingIntent ps) { static public void noteWakeupAlarm(PendingIntent ps, int sourceUid, String sourcePkg) { try { getDefault().noteWakeupAlarm(ps.getTarget()); getDefault().noteWakeupAlarm(ps.getTarget(), sourceUid, sourcePkg); } catch (RemoteException ex) { } } Loading Loading @@ -1258,7 +1258,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM data.enforceInterface(IActivityManager.descriptor); IIntentSender is = IIntentSender.Stub.asInterface( data.readStrongBinder()); noteWakeupAlarm(is); int sourceUid = data.readInt(); String sourcePkg = data.readString(); noteWakeupAlarm(is, sourceUid, sourcePkg); reply.writeNoException(); return true; } Loading Loading @@ -3651,10 +3653,13 @@ class ActivityManagerProxy implements IActivityManager mRemote.transact(ENTER_SAFE_MODE_TRANSACTION, data, null, 0); data.recycle(); } public void noteWakeupAlarm(IIntentSender sender) throws RemoteException { public void noteWakeupAlarm(IIntentSender sender, int sourceUid, String sourcePkg) throws RemoteException { Parcel data = Parcel.obtain(); data.writeStrongBinder(sender.asBinder()); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(sender.asBinder()); data.writeInt(sourceUid); data.writeString(sourcePkg); mRemote.transact(NOTE_WAKEUP_ALARM_TRANSACTION, data, null, 0); data.recycle(); } Loading core/java/android/app/IActivityManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -243,7 +243,8 @@ public interface IActivityManager extends IInterface { public void enterSafeMode() throws RemoteException; public void noteWakeupAlarm(IIntentSender sender) throws RemoteException; public void noteWakeupAlarm(IIntentSender sender, int sourceUid, String sourcePkg) throws RemoteException; public boolean killPids(int[] pids, String reason, boolean secure) throws RemoteException; public boolean killProcessesBelowForeground(String reason) throws RemoteException; Loading core/java/android/os/BatteryStats.java +78 −13 Original line number Diff line number Diff line Loading @@ -162,6 +162,7 @@ public abstract class BatteryStats implements Parcelable { private static final String WIFI_DATA = "wfl"; private static final String MISC_DATA = "m"; private static final String GLOBAL_NETWORK_DATA = "gn"; private static final String HISTORY_STRING_POOL = "hsp"; private static final String HISTORY_DATA = "h"; private static final String SCREEN_BRIGHTNESS_DATA = "br"; private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; Loading Loading @@ -354,6 +355,11 @@ public abstract class BatteryStats implements Parcelable { public long usedTime; } /** * Returns true if this process is still active in the battery stats. */ public abstract boolean isActive(); /** * Returns the total time (in 1/100 sec) spent executing in user code. * Loading Loading @@ -446,9 +452,6 @@ public abstract class BatteryStats implements Parcelable { } public final static class HistoryItem implements Parcelable { static final String TAG = "HistoryItem"; static final boolean DEBUG = false; public HistoryItem next; public long time; Loading Loading @@ -526,12 +529,14 @@ public abstract class BatteryStats implements Parcelable { public int states; public static final int EVENT_NONE = 0; public static final int EVENT_APP_FOREGROUND = 1; public static final int EVENT_PROC_STARTED = 1; public static final int EVENT_PROC_FINISHED = 2; // For CMD_EVENT. public int eventCode; public int eventUid; public String eventName; public int eventNameIdx; // only filled in when iterating. public int eventUid; public HistoryItem() { } Loading Loading @@ -579,6 +584,7 @@ public abstract class BatteryStats implements Parcelable { eventCode = src.readInt(); eventUid = src.readInt(); eventName = src.readString(); eventNameIdx = 0; } else { eventCode = EVENT_NONE; } Loading Loading @@ -612,6 +618,7 @@ public abstract class BatteryStats implements Parcelable { eventCode = o.eventCode; eventUid = o.eventUid; eventName = o.eventName; eventNameIdx = o.eventNameIdx; } public void setTo(long time, byte cmd, int eventCode, int eventUid, String eventName, Loading @@ -621,6 +628,7 @@ public abstract class BatteryStats implements Parcelable { this.eventCode = eventCode; this.eventUid = eventUid; this.eventName = eventName; this.eventNameIdx = 0; batteryLevel = o.batteryLevel; batteryStatus = o.batteryStatus; batteryHealth = o.batteryHealth; Loading Loading @@ -681,6 +689,10 @@ public abstract class BatteryStats implements Parcelable { public abstract boolean startIteratingHistoryLocked(); public abstract int getHistoryStringPoolSize(); public abstract String getHistoryStringPoolItem(int index); public abstract boolean getNextHistoryLocked(HistoryItem out); public abstract void finishIteratingHistoryLocked(); Loading Loading @@ -1316,7 +1328,7 @@ public abstract class BatteryStats implements Parcelable { if (sippers != null && sippers.size() > 0) { dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), BatteryStatsHelper.makemAh(helper.getTotalPower()), BatteryStatsHelper.makemAh(helper.getComputedPower()), BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); for (int i=0; i<sippers.size(); i++) { Loading Loading @@ -1835,7 +1847,7 @@ public abstract class BatteryStats implements Parcelable { pw.print(prefix); pw.println(" Estimated power use (mAh):"); pw.print(prefix); pw.print(" Capacity: "); printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); pw.print(", Computed drain: "); printmAh(pw, helper.getTotalPower()); pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); pw.print(", Min drain: "); printmAh(pw, helper.getMinDrainedPower()); pw.print(", Max drain: "); printmAh(pw, helper.getMaxDrainedPower()); pw.println(); Loading Loading @@ -2244,10 +2256,14 @@ public abstract class BatteryStats implements Parcelable { if (diff == 0) return; for (int i=0; i<descriptions.length; i++) { BitDescription bd = descriptions[i]; if ((diff&bd.mask) != 0) { int mask = bd.mask; if (bd.shift > 0) { mask <<= bd.shift; } if ((diff&mask) != 0) { pw.print(longNames ? " " : ","); if (bd.shift < 0) { pw.print((newval&bd.mask) != 0 ? "+" : "-"); pw.print((newval&mask) != 0 ? "+" : "-"); pw.print(longNames ? bd.name : bd.shortName); } else { pw.print(longNames ? bd.name : bd.shortName); Loading Loading @@ -2404,6 +2420,38 @@ public abstract class BatteryStats implements Parcelable { } printBitDescriptions(pw, oldState, rec.states, HISTORY_STATE_DESCRIPTIONS, !checkin); if (rec.eventCode != HistoryItem.EVENT_NONE) { switch (rec.eventCode) { case HistoryItem.EVENT_PROC_STARTED: pw.print(checkin ? ",PrSt=" : " procstart="); break; case HistoryItem.EVENT_PROC_FINISHED: pw.print(checkin ? ",PrFn=" : " procfin="); break; default: if (checkin) { pw.print(",?cmd_"); pw.print(rec.eventCode); pw.print("="); } else { pw.print(" cmd_"); pw.print(rec.eventCode); pw.print("="); } break; } if (checkin) { pw.print(rec.eventUid); } else { UserHandle.formatUid(pw, rec.eventUid); } pw.print(":"); if (checkin) { pw.print(rec.eventNameIdx); } else { pw.print(rec.eventName); } } pw.println(); } oldState = rec.states; Loading @@ -2416,7 +2464,8 @@ public abstract class BatteryStats implements Parcelable { * @param pw a Printer to receive the dump output. */ @SuppressWarnings("unused") public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid) { public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, boolean historyOnly) { prepareForDumpLocked(); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); Loading @@ -2442,6 +2491,10 @@ public abstract class BatteryStats implements Parcelable { pw.println(""); } if (historyOnly) { return; } SparseArray<? extends Uid> uidStats = getUidStats(); final int NU = uidStats.size(); boolean didPid = false; Loading Loading @@ -2483,14 +2536,22 @@ public abstract class BatteryStats implements Parcelable { @SuppressWarnings("unused") public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly, boolean includeHistory) { boolean includeHistory, boolean historyOnly) { prepareForDumpLocked(); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); if (includeHistory) { if (includeHistory || historyOnly) { final HistoryItem rec = new HistoryItem(); if (startIteratingHistoryLocked()) { for (int i=0; i<getHistoryStringPoolSize(); i++) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); pw.print(HISTORY_STRING_POOL); pw.print(','); pw.print(i); pw.print(','); pw.print(getHistoryStringPoolItem(i)); pw.println(); } HistoryPrinter hprinter = new HistoryPrinter(); while (getNextHistoryLocked(rec)) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); Loading @@ -2501,6 +2562,10 @@ public abstract class BatteryStats implements Parcelable { } } if (historyOnly) { return; } if (apps != null) { SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>(); for (int i=0; i<apps.size(); i++) { Loading core/java/com/android/internal/app/IBatteryStats.aidl +6 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,12 @@ interface IBatteryStats { // Remaining methods are only used in Java. byte[] getStatistics(); void addIsolatedUid(int isolatedUid, int appUid); void removeIsolatedUid(int isolatedUid, int appUid); void noteEvent(int code, String name, int uid); void noteStartWakelock(int uid, int pid, String name, int type); void noteStopWakelock(int uid, int pid, String name, int type); Loading core/java/com/android/internal/os/BatteryStatsHelper.java +41 −30 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import android.util.SparseArray; import com.android.internal.app.IBatteryStats; import com.android.internal.os.BatterySipper.DrainType; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; Loading Loading @@ -84,6 +83,7 @@ public class BatteryStatsHelper { private long mStatsPeriod = 0; private double mMaxPower = 1; private double mComputedPower; private double mTotalPower; private double mWifiPower; private double mBluetoothPower; Loading Loading @@ -156,6 +156,7 @@ public class BatteryStatsHelper { getStats(); mMaxPower = 0; mComputedPower = 0; mTotalPower = 0; mWifiPower = 0; mBluetoothPower = 0; Loading Loading @@ -195,21 +196,17 @@ public class BatteryStatsHelper { processMiscUsage(); if (DEBUG) { Log.d(TAG, "Accuracy: total computed=" + makemAh(mTotalPower) + ", min discharge=" Log.d(TAG, "Accuracy: total computed=" + makemAh(mComputedPower) + ", min discharge=" + makemAh(mMinDrainedPower) + ", max discharge=" + makemAh(mMaxDrainedPower)); } if (true || mStats.getLowDischargeAmountSinceCharge() > 10) { if (mMinDrainedPower > mTotalPower) { double amount = mMinDrainedPower - mTotalPower; if (mMaxPower < amount) { mMaxPower = amount; } mTotalPower = mComputedPower; if (mStats.getLowDischargeAmountSinceCharge() > 1) { if (mMinDrainedPower > mComputedPower) { double amount = mMinDrainedPower - mComputedPower; mTotalPower = mMinDrainedPower; addEntryNoTotal(BatterySipper.DrainType.UNACCOUNTED, 0, amount); } else if (mMaxDrainedPower < mTotalPower) { double amount = mTotalPower - mMaxDrainedPower; if (mMaxPower < amount) { mMaxPower = amount; } } else if (mMaxDrainedPower < mComputedPower) { double amount = mComputedPower - mMaxDrainedPower; addEntryNoTotal(BatterySipper.DrainType.OVERCOUNTED, 0, amount); } } Loading Loading @@ -442,7 +439,7 @@ public class BatteryStatsHelper { } else { mUsageList.add(app); if (power > mMaxPower) mMaxPower = power; mTotalPower += power; mComputedPower += power; } if (u.getUid() == 0) { osApp = app; Loading @@ -467,7 +464,7 @@ public class BatteryStatsHelper { osApp.value += power; osApp.values[0] += power; if (osApp.value > mMaxPower) mMaxPower = osApp.value; mTotalPower += power; mComputedPower += power; } } } Loading @@ -476,8 +473,10 @@ public class BatteryStatsHelper { long phoneOnTimeMs = mStats.getPhoneOnTime(mBatteryRealtime, mStatsType) / 1000; double phoneOnPower = mPowerProfile.getAveragePower(PowerProfile.POWER_RADIO_ACTIVE) * phoneOnTimeMs / (60*60*1000); if (phoneOnPower != 0) { addEntry(BatterySipper.DrainType.PHONE, phoneOnTimeMs, phoneOnPower); } } private void addScreenUsage() { double power = 0; Loading @@ -498,8 +497,10 @@ public class BatteryStatsHelper { power += p; } power /= (60*60*1000); // To hours if (power != 0) { addEntry(BatterySipper.DrainType.SCREEN, screenOnTimeMs, power); } } private void addRadioUsage() { double power = 0; Loading Loading @@ -530,12 +531,14 @@ public class BatteryStatsHelper { Log.d(TAG, "Cell radio scanning: time=" + scanningTimeMs + " power=" + makemAh(p)); } power += p; if (power != 0) { BatterySipper bs = addEntry(BatterySipper.DrainType.CELL, signalTimeMs, power); if (signalTimeMs != 0) { bs.noCoveragePercent = noCoverageTimeMs * 100.0 / signalTimeMs; } } } private void aggregateSippers(BatterySipper bs, List<BatterySipper> from, String tag) { for (int i=0; i<from.size(); i++) { Loading Loading @@ -571,10 +574,12 @@ public class BatteryStatsHelper { if (DEBUG && wifiPower != 0) { Log.d(TAG, "Wifi: time=" + runningTimeMs + " power=" + makemAh(wifiPower)); } if ((wifiPower+mWifiPower) != 0) { BatterySipper bs = addEntry(BatterySipper.DrainType.WIFI, runningTimeMs, wifiPower + mWifiPower); aggregateSippers(bs, mWifiSippers, "WIFI"); } } private void addIdleUsage() { long idleTimeMs = (mTypeBatteryRealtime Loading @@ -584,8 +589,10 @@ public class BatteryStatsHelper { if (DEBUG && idlePower != 0) { Log.d(TAG, "Idle: time=" + idleTimeMs + " power=" + makemAh(idlePower)); } if (idlePower != 0) { addEntry(BatterySipper.DrainType.IDLE, idleTimeMs, idlePower); } } private void addBluetoothUsage() { long btOnTimeMs = mStats.getBluetoothOnTime(mBatteryRealtime, mStatsType) / 1000; Loading @@ -602,10 +609,12 @@ public class BatteryStatsHelper { Log.d(TAG, "Bluetooth ping: count=" + btPingCount + " power=" + makemAh(pingPower)); } btPower += pingPower; if ((btPower+mBluetoothPower) != 0) { BatterySipper bs = addEntry(BatterySipper.DrainType.BLUETOOTH, btOnTimeMs, btPower + mBluetoothPower); aggregateSippers(bs, mBluetoothSippers, "Bluetooth"); } } private void addUserUsage() { for (int i=0; i<mUserSippers.size(); i++) { Loading Loading @@ -665,7 +674,7 @@ public class BatteryStatsHelper { } private BatterySipper addEntry(DrainType drainType, long time, double power) { mTotalPower += power; mComputedPower += power; return addEntryNoTotal(drainType, time, power); } Loading @@ -689,6 +698,8 @@ public class BatteryStatsHelper { public double getTotalPower() { return mTotalPower; } public double getComputedPower() { return mComputedPower; } public double getMinDrainedPower() { return mMinDrainedPower; } Loading Loading
core/java/android/app/ActivityManagerNative.java +10 −5 Original line number Diff line number Diff line Loading @@ -101,9 +101,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM } } static public void noteWakeupAlarm(PendingIntent ps) { static public void noteWakeupAlarm(PendingIntent ps, int sourceUid, String sourcePkg) { try { getDefault().noteWakeupAlarm(ps.getTarget()); getDefault().noteWakeupAlarm(ps.getTarget(), sourceUid, sourcePkg); } catch (RemoteException ex) { } } Loading Loading @@ -1258,7 +1258,9 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM data.enforceInterface(IActivityManager.descriptor); IIntentSender is = IIntentSender.Stub.asInterface( data.readStrongBinder()); noteWakeupAlarm(is); int sourceUid = data.readInt(); String sourcePkg = data.readString(); noteWakeupAlarm(is, sourceUid, sourcePkg); reply.writeNoException(); return true; } Loading Loading @@ -3651,10 +3653,13 @@ class ActivityManagerProxy implements IActivityManager mRemote.transact(ENTER_SAFE_MODE_TRANSACTION, data, null, 0); data.recycle(); } public void noteWakeupAlarm(IIntentSender sender) throws RemoteException { public void noteWakeupAlarm(IIntentSender sender, int sourceUid, String sourcePkg) throws RemoteException { Parcel data = Parcel.obtain(); data.writeStrongBinder(sender.asBinder()); data.writeInterfaceToken(IActivityManager.descriptor); data.writeStrongBinder(sender.asBinder()); data.writeInt(sourceUid); data.writeString(sourcePkg); mRemote.transact(NOTE_WAKEUP_ALARM_TRANSACTION, data, null, 0); data.recycle(); } Loading
core/java/android/app/IActivityManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -243,7 +243,8 @@ public interface IActivityManager extends IInterface { public void enterSafeMode() throws RemoteException; public void noteWakeupAlarm(IIntentSender sender) throws RemoteException; public void noteWakeupAlarm(IIntentSender sender, int sourceUid, String sourcePkg) throws RemoteException; public boolean killPids(int[] pids, String reason, boolean secure) throws RemoteException; public boolean killProcessesBelowForeground(String reason) throws RemoteException; Loading
core/java/android/os/BatteryStats.java +78 −13 Original line number Diff line number Diff line Loading @@ -162,6 +162,7 @@ public abstract class BatteryStats implements Parcelable { private static final String WIFI_DATA = "wfl"; private static final String MISC_DATA = "m"; private static final String GLOBAL_NETWORK_DATA = "gn"; private static final String HISTORY_STRING_POOL = "hsp"; private static final String HISTORY_DATA = "h"; private static final String SCREEN_BRIGHTNESS_DATA = "br"; private static final String SIGNAL_STRENGTH_TIME_DATA = "sgt"; Loading Loading @@ -354,6 +355,11 @@ public abstract class BatteryStats implements Parcelable { public long usedTime; } /** * Returns true if this process is still active in the battery stats. */ public abstract boolean isActive(); /** * Returns the total time (in 1/100 sec) spent executing in user code. * Loading Loading @@ -446,9 +452,6 @@ public abstract class BatteryStats implements Parcelable { } public final static class HistoryItem implements Parcelable { static final String TAG = "HistoryItem"; static final boolean DEBUG = false; public HistoryItem next; public long time; Loading Loading @@ -526,12 +529,14 @@ public abstract class BatteryStats implements Parcelable { public int states; public static final int EVENT_NONE = 0; public static final int EVENT_APP_FOREGROUND = 1; public static final int EVENT_PROC_STARTED = 1; public static final int EVENT_PROC_FINISHED = 2; // For CMD_EVENT. public int eventCode; public int eventUid; public String eventName; public int eventNameIdx; // only filled in when iterating. public int eventUid; public HistoryItem() { } Loading Loading @@ -579,6 +584,7 @@ public abstract class BatteryStats implements Parcelable { eventCode = src.readInt(); eventUid = src.readInt(); eventName = src.readString(); eventNameIdx = 0; } else { eventCode = EVENT_NONE; } Loading Loading @@ -612,6 +618,7 @@ public abstract class BatteryStats implements Parcelable { eventCode = o.eventCode; eventUid = o.eventUid; eventName = o.eventName; eventNameIdx = o.eventNameIdx; } public void setTo(long time, byte cmd, int eventCode, int eventUid, String eventName, Loading @@ -621,6 +628,7 @@ public abstract class BatteryStats implements Parcelable { this.eventCode = eventCode; this.eventUid = eventUid; this.eventName = eventName; this.eventNameIdx = 0; batteryLevel = o.batteryLevel; batteryStatus = o.batteryStatus; batteryHealth = o.batteryHealth; Loading Loading @@ -681,6 +689,10 @@ public abstract class BatteryStats implements Parcelable { public abstract boolean startIteratingHistoryLocked(); public abstract int getHistoryStringPoolSize(); public abstract String getHistoryStringPoolItem(int index); public abstract boolean getNextHistoryLocked(HistoryItem out); public abstract void finishIteratingHistoryLocked(); Loading Loading @@ -1316,7 +1328,7 @@ public abstract class BatteryStats implements Parcelable { if (sippers != null && sippers.size() > 0) { dumpLine(pw, 0 /* uid */, category, POWER_USE_SUMMARY_DATA, BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), BatteryStatsHelper.makemAh(helper.getTotalPower()), BatteryStatsHelper.makemAh(helper.getComputedPower()), BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), BatteryStatsHelper.makemAh(helper.getMaxDrainedPower())); for (int i=0; i<sippers.size(); i++) { Loading Loading @@ -1835,7 +1847,7 @@ public abstract class BatteryStats implements Parcelable { pw.print(prefix); pw.println(" Estimated power use (mAh):"); pw.print(prefix); pw.print(" Capacity: "); printmAh(pw, helper.getPowerProfile().getBatteryCapacity()); pw.print(", Computed drain: "); printmAh(pw, helper.getTotalPower()); pw.print(", Computed drain: "); printmAh(pw, helper.getComputedPower()); pw.print(", Min drain: "); printmAh(pw, helper.getMinDrainedPower()); pw.print(", Max drain: "); printmAh(pw, helper.getMaxDrainedPower()); pw.println(); Loading Loading @@ -2244,10 +2256,14 @@ public abstract class BatteryStats implements Parcelable { if (diff == 0) return; for (int i=0; i<descriptions.length; i++) { BitDescription bd = descriptions[i]; if ((diff&bd.mask) != 0) { int mask = bd.mask; if (bd.shift > 0) { mask <<= bd.shift; } if ((diff&mask) != 0) { pw.print(longNames ? " " : ","); if (bd.shift < 0) { pw.print((newval&bd.mask) != 0 ? "+" : "-"); pw.print((newval&mask) != 0 ? "+" : "-"); pw.print(longNames ? bd.name : bd.shortName); } else { pw.print(longNames ? bd.name : bd.shortName); Loading Loading @@ -2404,6 +2420,38 @@ public abstract class BatteryStats implements Parcelable { } printBitDescriptions(pw, oldState, rec.states, HISTORY_STATE_DESCRIPTIONS, !checkin); if (rec.eventCode != HistoryItem.EVENT_NONE) { switch (rec.eventCode) { case HistoryItem.EVENT_PROC_STARTED: pw.print(checkin ? ",PrSt=" : " procstart="); break; case HistoryItem.EVENT_PROC_FINISHED: pw.print(checkin ? ",PrFn=" : " procfin="); break; default: if (checkin) { pw.print(",?cmd_"); pw.print(rec.eventCode); pw.print("="); } else { pw.print(" cmd_"); pw.print(rec.eventCode); pw.print("="); } break; } if (checkin) { pw.print(rec.eventUid); } else { UserHandle.formatUid(pw, rec.eventUid); } pw.print(":"); if (checkin) { pw.print(rec.eventNameIdx); } else { pw.print(rec.eventName); } } pw.println(); } oldState = rec.states; Loading @@ -2416,7 +2464,8 @@ public abstract class BatteryStats implements Parcelable { * @param pw a Printer to receive the dump output. */ @SuppressWarnings("unused") public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid) { public void dumpLocked(Context context, PrintWriter pw, boolean isUnpluggedOnly, int reqUid, boolean historyOnly) { prepareForDumpLocked(); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); Loading @@ -2442,6 +2491,10 @@ public abstract class BatteryStats implements Parcelable { pw.println(""); } if (historyOnly) { return; } SparseArray<? extends Uid> uidStats = getUidStats(); final int NU = uidStats.size(); boolean didPid = false; Loading Loading @@ -2483,14 +2536,22 @@ public abstract class BatteryStats implements Parcelable { @SuppressWarnings("unused") public void dumpCheckinLocked(Context context, PrintWriter pw, List<ApplicationInfo> apps, boolean isUnpluggedOnly, boolean includeHistory) { boolean includeHistory, boolean historyOnly) { prepareForDumpLocked(); long now = getHistoryBaseTime() + SystemClock.elapsedRealtime(); if (includeHistory) { if (includeHistory || historyOnly) { final HistoryItem rec = new HistoryItem(); if (startIteratingHistoryLocked()) { for (int i=0; i<getHistoryStringPoolSize(); i++) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); pw.print(HISTORY_STRING_POOL); pw.print(','); pw.print(i); pw.print(','); pw.print(getHistoryStringPoolItem(i)); pw.println(); } HistoryPrinter hprinter = new HistoryPrinter(); while (getNextHistoryLocked(rec)) { pw.print(BATTERY_STATS_CHECKIN_VERSION); pw.print(','); Loading @@ -2501,6 +2562,10 @@ public abstract class BatteryStats implements Parcelable { } } if (historyOnly) { return; } if (apps != null) { SparseArray<ArrayList<String>> uids = new SparseArray<ArrayList<String>>(); for (int i=0; i<apps.size(); i++) { Loading
core/java/com/android/internal/app/IBatteryStats.aidl +6 −0 Original line number Diff line number Diff line Loading @@ -29,6 +29,12 @@ interface IBatteryStats { // Remaining methods are only used in Java. byte[] getStatistics(); void addIsolatedUid(int isolatedUid, int appUid); void removeIsolatedUid(int isolatedUid, int appUid); void noteEvent(int code, String name, int uid); void noteStartWakelock(int uid, int pid, String name, int type); void noteStopWakelock(int uid, int pid, String name, int type); Loading
core/java/com/android/internal/os/BatteryStatsHelper.java +41 −30 Original line number Diff line number Diff line Loading @@ -41,7 +41,6 @@ import android.util.SparseArray; import com.android.internal.app.IBatteryStats; import com.android.internal.os.BatterySipper.DrainType; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; Loading Loading @@ -84,6 +83,7 @@ public class BatteryStatsHelper { private long mStatsPeriod = 0; private double mMaxPower = 1; private double mComputedPower; private double mTotalPower; private double mWifiPower; private double mBluetoothPower; Loading Loading @@ -156,6 +156,7 @@ public class BatteryStatsHelper { getStats(); mMaxPower = 0; mComputedPower = 0; mTotalPower = 0; mWifiPower = 0; mBluetoothPower = 0; Loading Loading @@ -195,21 +196,17 @@ public class BatteryStatsHelper { processMiscUsage(); if (DEBUG) { Log.d(TAG, "Accuracy: total computed=" + makemAh(mTotalPower) + ", min discharge=" Log.d(TAG, "Accuracy: total computed=" + makemAh(mComputedPower) + ", min discharge=" + makemAh(mMinDrainedPower) + ", max discharge=" + makemAh(mMaxDrainedPower)); } if (true || mStats.getLowDischargeAmountSinceCharge() > 10) { if (mMinDrainedPower > mTotalPower) { double amount = mMinDrainedPower - mTotalPower; if (mMaxPower < amount) { mMaxPower = amount; } mTotalPower = mComputedPower; if (mStats.getLowDischargeAmountSinceCharge() > 1) { if (mMinDrainedPower > mComputedPower) { double amount = mMinDrainedPower - mComputedPower; mTotalPower = mMinDrainedPower; addEntryNoTotal(BatterySipper.DrainType.UNACCOUNTED, 0, amount); } else if (mMaxDrainedPower < mTotalPower) { double amount = mTotalPower - mMaxDrainedPower; if (mMaxPower < amount) { mMaxPower = amount; } } else if (mMaxDrainedPower < mComputedPower) { double amount = mComputedPower - mMaxDrainedPower; addEntryNoTotal(BatterySipper.DrainType.OVERCOUNTED, 0, amount); } } Loading Loading @@ -442,7 +439,7 @@ public class BatteryStatsHelper { } else { mUsageList.add(app); if (power > mMaxPower) mMaxPower = power; mTotalPower += power; mComputedPower += power; } if (u.getUid() == 0) { osApp = app; Loading @@ -467,7 +464,7 @@ public class BatteryStatsHelper { osApp.value += power; osApp.values[0] += power; if (osApp.value > mMaxPower) mMaxPower = osApp.value; mTotalPower += power; mComputedPower += power; } } } Loading @@ -476,8 +473,10 @@ public class BatteryStatsHelper { long phoneOnTimeMs = mStats.getPhoneOnTime(mBatteryRealtime, mStatsType) / 1000; double phoneOnPower = mPowerProfile.getAveragePower(PowerProfile.POWER_RADIO_ACTIVE) * phoneOnTimeMs / (60*60*1000); if (phoneOnPower != 0) { addEntry(BatterySipper.DrainType.PHONE, phoneOnTimeMs, phoneOnPower); } } private void addScreenUsage() { double power = 0; Loading @@ -498,8 +497,10 @@ public class BatteryStatsHelper { power += p; } power /= (60*60*1000); // To hours if (power != 0) { addEntry(BatterySipper.DrainType.SCREEN, screenOnTimeMs, power); } } private void addRadioUsage() { double power = 0; Loading Loading @@ -530,12 +531,14 @@ public class BatteryStatsHelper { Log.d(TAG, "Cell radio scanning: time=" + scanningTimeMs + " power=" + makemAh(p)); } power += p; if (power != 0) { BatterySipper bs = addEntry(BatterySipper.DrainType.CELL, signalTimeMs, power); if (signalTimeMs != 0) { bs.noCoveragePercent = noCoverageTimeMs * 100.0 / signalTimeMs; } } } private void aggregateSippers(BatterySipper bs, List<BatterySipper> from, String tag) { for (int i=0; i<from.size(); i++) { Loading Loading @@ -571,10 +574,12 @@ public class BatteryStatsHelper { if (DEBUG && wifiPower != 0) { Log.d(TAG, "Wifi: time=" + runningTimeMs + " power=" + makemAh(wifiPower)); } if ((wifiPower+mWifiPower) != 0) { BatterySipper bs = addEntry(BatterySipper.DrainType.WIFI, runningTimeMs, wifiPower + mWifiPower); aggregateSippers(bs, mWifiSippers, "WIFI"); } } private void addIdleUsage() { long idleTimeMs = (mTypeBatteryRealtime Loading @@ -584,8 +589,10 @@ public class BatteryStatsHelper { if (DEBUG && idlePower != 0) { Log.d(TAG, "Idle: time=" + idleTimeMs + " power=" + makemAh(idlePower)); } if (idlePower != 0) { addEntry(BatterySipper.DrainType.IDLE, idleTimeMs, idlePower); } } private void addBluetoothUsage() { long btOnTimeMs = mStats.getBluetoothOnTime(mBatteryRealtime, mStatsType) / 1000; Loading @@ -602,10 +609,12 @@ public class BatteryStatsHelper { Log.d(TAG, "Bluetooth ping: count=" + btPingCount + " power=" + makemAh(pingPower)); } btPower += pingPower; if ((btPower+mBluetoothPower) != 0) { BatterySipper bs = addEntry(BatterySipper.DrainType.BLUETOOTH, btOnTimeMs, btPower + mBluetoothPower); aggregateSippers(bs, mBluetoothSippers, "Bluetooth"); } } private void addUserUsage() { for (int i=0; i<mUserSippers.size(); i++) { Loading Loading @@ -665,7 +674,7 @@ public class BatteryStatsHelper { } private BatterySipper addEntry(DrainType drainType, long time, double power) { mTotalPower += power; mComputedPower += power; return addEntryNoTotal(drainType, time, power); } Loading @@ -689,6 +698,8 @@ public class BatteryStatsHelper { public double getTotalPower() { return mTotalPower; } public double getComputedPower() { return mComputedPower; } public double getMinDrainedPower() { return mMinDrainedPower; } Loading