Loading core/java/android/os/BatteryStats.java +30 −9 Original line number Diff line number Diff line Loading @@ -1844,12 +1844,20 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } /** * Temporary for settings. */ public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); } /** * Checkin server version of dump to produce more compact, computer-readable log. * * NOTE: all times are expressed in 'ms'. */ public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, boolean wifiOnly) { final long rawUptime = SystemClock.uptimeMillis() * 1000; final long rawRealtime = SystemClock.elapsedRealtime() * 1000; final long batteryUptime = getBatteryUptime(rawUptime); Loading Loading @@ -2046,7 +2054,7 @@ public abstract class BatteryStats implements Parcelable { } } BatteryStatsHelper helper = new BatteryStatsHelper(context, false); BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading Loading @@ -2315,9 +2323,17 @@ public abstract class BatteryStats implements Parcelable { printer.print(BatteryStatsHelper.makemAh(power)); } /** * Temporary for settings. */ public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, int reqUid) { dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); } @SuppressWarnings("unused") public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which, int reqUid) { int reqUid, boolean wifiOnly) { final long rawUptime = SystemClock.uptimeMillis() * 1000; final long rawRealtime = SystemClock.elapsedRealtime() * 1000; final long batteryUptime = getBatteryUptime(rawUptime); Loading Loading @@ -2746,7 +2762,7 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } BatteryStatsHelper helper = new BatteryStatsHelper(context, false); BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading Loading @@ -3723,6 +3739,7 @@ public abstract class BatteryStats implements Parcelable { public static final int DUMP_HISTORY_ONLY = 1<<2; public static final int DUMP_INCLUDE_HISTORY = 1<<3; public static final int DUMP_VERBOSE = 1<<4; public static final int DUMP_DEVICE_WIFI_ONLY = 1<<5; private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { final HistoryPrinter hprinter = new HistoryPrinter(); Loading Loading @@ -3918,12 +3935,14 @@ public abstract class BatteryStats implements Parcelable { pw.println("Statistics since last charge:"); pw.println(" System starts: " + getStartCount() + ", currently on battery: " + getIsOnBattery()); dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid); dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); pw.println(); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { pw.println("Statistics since last unplugged:"); dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid); dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); } } Loading Loading @@ -4013,10 +4032,12 @@ public abstract class BatteryStats implements Parcelable { dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, (Object[])lineArgs); } dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1); dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); } } } core/java/com/android/internal/os/BatteryStatsHelper.java +15 −3 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ public final class BatteryStatsHelper { final private Context mContext; final private boolean mCollectBatteryBroadcast; final private boolean mWifiOnly; private IBatteryStats mBatteryInfo; private BatteryStats mStats; Loading Loading @@ -123,6 +124,19 @@ public final class BatteryStatsHelper { public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast) { mContext = context; mCollectBatteryBroadcast = collectBatteryBroadcast; mWifiOnly = checkWifiOnly(context); } public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast, boolean wifiOnly) { mContext = context; mCollectBatteryBroadcast = collectBatteryBroadcast; mWifiOnly = wifiOnly; } public static boolean checkWifiOnly(Context context) { ConnectivityManager cm = (ConnectivityManager)context.getSystemService( Context.CONNECTIVITY_SERVICE); return !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } public void storeStatsHistoryInFile(String fname) { Loading Loading @@ -870,9 +884,7 @@ public final class BatteryStatsHelper { addBluetoothUsage(); addIdleUsage(); // Not including cellular idle power // Don't compute radio usage if it's a wifi-only device ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( Context.CONNECTIVITY_SERVICE); if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { if (!mWifiOnly) { addRadioUsage(); } } Loading core/java/com/android/internal/os/BatteryStatsImpl.java +256 −130 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/am/BatteryStatsService.java +4 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.telephony.TelephonyManager; import android.util.Slog; import com.android.internal.app.IBatteryStats; import com.android.internal.os.BatteryStatsHelper; import com.android.internal.os.BatteryStatsImpl; import com.android.internal.os.PowerProfile; import com.android.server.LocalServices; Loading Loading @@ -868,6 +869,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub if (noOutput) { return; } if (BatteryStatsHelper.checkWifiOnly(mContext)) { flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY; } if (useCheckinFormat) { List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0); if (isRealCheckin) { Loading services/core/java/com/android/server/power/PowerManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -862,7 +862,8 @@ public final class PowerManagerService extends com.android.server.SystemService } } private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws, String historyTag) { private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws, String historyTag, int callingUid) { synchronized (mLock) { int index = findWakeLockIndexLocked(lock); if (index < 0) { Loading @@ -870,7 +871,8 @@ public final class PowerManagerService extends com.android.server.SystemService Slog.d(TAG, "updateWakeLockWorkSourceInternal: lock=" + Objects.hashCode(lock) + " [not found], ws=" + ws); } throw new IllegalArgumentException("Wake lock not active"); throw new IllegalArgumentException("Wake lock not active: " + lock + " from uid " + callingUid); } WakeLock wakeLock = mWakeLocks.get(index); Loading Loading @@ -2834,9 +2836,10 @@ public final class PowerManagerService extends com.android.server.SystemService ws = null; } final int callingUid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { updateWakeLockWorkSourceInternal(lock, ws, historyTag); updateWakeLockWorkSourceInternal(lock, ws, historyTag, callingUid); } finally { Binder.restoreCallingIdentity(ident); } Loading Loading
core/java/android/os/BatteryStats.java +30 −9 Original line number Diff line number Diff line Loading @@ -1844,12 +1844,20 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } /** * Temporary for settings. */ public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { dumpCheckinLocked(context, pw, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); } /** * Checkin server version of dump to produce more compact, computer-readable log. * * NOTE: all times are expressed in 'ms'. */ public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid) { public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, boolean wifiOnly) { final long rawUptime = SystemClock.uptimeMillis() * 1000; final long rawRealtime = SystemClock.elapsedRealtime() * 1000; final long batteryUptime = getBatteryUptime(rawUptime); Loading Loading @@ -2046,7 +2054,7 @@ public abstract class BatteryStats implements Parcelable { } } BatteryStatsHelper helper = new BatteryStatsHelper(context, false); BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading Loading @@ -2315,9 +2323,17 @@ public abstract class BatteryStats implements Parcelable { printer.print(BatteryStatsHelper.makemAh(power)); } /** * Temporary for settings. */ public final void dumpLocked(Context context, PrintWriter pw, String prefix, int which, int reqUid) { dumpLocked(context, pw, prefix, which, reqUid, BatteryStatsHelper.checkWifiOnly(context)); } @SuppressWarnings("unused") public final void dumpLocked(Context context, PrintWriter pw, String prefix, final int which, int reqUid) { int reqUid, boolean wifiOnly) { final long rawUptime = SystemClock.uptimeMillis() * 1000; final long rawRealtime = SystemClock.elapsedRealtime() * 1000; final long batteryUptime = getBatteryUptime(rawUptime); Loading Loading @@ -2746,7 +2762,7 @@ public abstract class BatteryStats implements Parcelable { pw.println(); } BatteryStatsHelper helper = new BatteryStatsHelper(context, false); BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly); helper.create(this); helper.refreshStats(which, UserHandle.USER_ALL); List<BatterySipper> sippers = helper.getUsageList(); Loading Loading @@ -3723,6 +3739,7 @@ public abstract class BatteryStats implements Parcelable { public static final int DUMP_HISTORY_ONLY = 1<<2; public static final int DUMP_INCLUDE_HISTORY = 1<<3; public static final int DUMP_VERBOSE = 1<<4; public static final int DUMP_DEVICE_WIFI_ONLY = 1<<5; private void dumpHistoryLocked(PrintWriter pw, int flags, long histStart, boolean checkin) { final HistoryPrinter hprinter = new HistoryPrinter(); Loading Loading @@ -3918,12 +3935,14 @@ public abstract class BatteryStats implements Parcelable { pw.println("Statistics since last charge:"); pw.println(" System starts: " + getStartCount() + ", currently on battery: " + getIsOnBattery()); dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid); dumpLocked(context, pw, "", STATS_SINCE_CHARGED, reqUid, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); pw.println(); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { pw.println("Statistics since last unplugged:"); dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid); dumpLocked(context, pw, "", STATS_SINCE_UNPLUGGED, reqUid, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); } } Loading Loading @@ -4013,10 +4032,12 @@ public abstract class BatteryStats implements Parcelable { dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA, (Object[])lineArgs); } dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1); dumpCheckinLocked(context, pw, STATS_SINCE_CHARGED, -1, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); } if (!filtering || (flags&DUMP_UNPLUGGED_ONLY) != 0) { dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1); dumpCheckinLocked(context, pw, STATS_SINCE_UNPLUGGED, -1, (flags&DUMP_DEVICE_WIFI_ONLY) != 0); } } }
core/java/com/android/internal/os/BatteryStatsHelper.java +15 −3 Original line number Diff line number Diff line Loading @@ -74,6 +74,7 @@ public final class BatteryStatsHelper { final private Context mContext; final private boolean mCollectBatteryBroadcast; final private boolean mWifiOnly; private IBatteryStats mBatteryInfo; private BatteryStats mStats; Loading Loading @@ -123,6 +124,19 @@ public final class BatteryStatsHelper { public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast) { mContext = context; mCollectBatteryBroadcast = collectBatteryBroadcast; mWifiOnly = checkWifiOnly(context); } public BatteryStatsHelper(Context context, boolean collectBatteryBroadcast, boolean wifiOnly) { mContext = context; mCollectBatteryBroadcast = collectBatteryBroadcast; mWifiOnly = wifiOnly; } public static boolean checkWifiOnly(Context context) { ConnectivityManager cm = (ConnectivityManager)context.getSystemService( Context.CONNECTIVITY_SERVICE); return !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE); } public void storeStatsHistoryInFile(String fname) { Loading Loading @@ -870,9 +884,7 @@ public final class BatteryStatsHelper { addBluetoothUsage(); addIdleUsage(); // Not including cellular idle power // Don't compute radio usage if it's a wifi-only device ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService( Context.CONNECTIVITY_SERVICE); if (cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) { if (!mWifiOnly) { addRadioUsage(); } } Loading
core/java/com/android/internal/os/BatteryStatsImpl.java +256 −130 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/am/BatteryStatsService.java +4 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.telephony.TelephonyManager; import android.util.Slog; import com.android.internal.app.IBatteryStats; import com.android.internal.os.BatteryStatsHelper; import com.android.internal.os.BatteryStatsImpl; import com.android.internal.os.PowerProfile; import com.android.server.LocalServices; Loading Loading @@ -868,6 +869,9 @@ public final class BatteryStatsService extends IBatteryStats.Stub if (noOutput) { return; } if (BatteryStatsHelper.checkWifiOnly(mContext)) { flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY; } if (useCheckinFormat) { List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(0); if (isRealCheckin) { Loading
services/core/java/com/android/server/power/PowerManagerService.java +6 −3 Original line number Diff line number Diff line Loading @@ -862,7 +862,8 @@ public final class PowerManagerService extends com.android.server.SystemService } } private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws, String historyTag) { private void updateWakeLockWorkSourceInternal(IBinder lock, WorkSource ws, String historyTag, int callingUid) { synchronized (mLock) { int index = findWakeLockIndexLocked(lock); if (index < 0) { Loading @@ -870,7 +871,8 @@ public final class PowerManagerService extends com.android.server.SystemService Slog.d(TAG, "updateWakeLockWorkSourceInternal: lock=" + Objects.hashCode(lock) + " [not found], ws=" + ws); } throw new IllegalArgumentException("Wake lock not active"); throw new IllegalArgumentException("Wake lock not active: " + lock + " from uid " + callingUid); } WakeLock wakeLock = mWakeLocks.get(index); Loading Loading @@ -2834,9 +2836,10 @@ public final class PowerManagerService extends com.android.server.SystemService ws = null; } final int callingUid = Binder.getCallingUid(); final long ident = Binder.clearCallingIdentity(); try { updateWakeLockWorkSourceInternal(lock, ws, historyTag); updateWakeLockWorkSourceInternal(lock, ws, historyTag, callingUid); } finally { Binder.restoreCallingIdentity(ident); } Loading