BatteryStats: Record doze wake locks

Doze wake locks don't actually hold the CPU awake, so we should record them
separately from full wakelocks, which is what we did before.

Bug:21949905
Change-Id: Ib4db3399069e0ad11f1f0dc6925a87ad0ad21ff9
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index eb6e1c2..593f804 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -65,7 +65,7 @@
      * A constant indicating a window wake lock timer.
      */
     public static final int WAKE_TYPE_WINDOW = 2;
-    
+
     /**
      * A constant indicating a sensor timer.
      */
@@ -142,6 +142,11 @@
     public static final int CAMERA_TURNED_ON = 17;
 
     /**
+     * A constant indicating a doze wake lock timer.
+     */
+    public static final int WAKE_TYPE_DOZE = 18;
+
+    /**
      * Include all of the data in the stats, including previously saved data.
      */
     public static final int STATS_SINCE_CHARGED = 0;
@@ -3834,6 +3839,7 @@
             final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks
                     = u.getWakelockStats();
             long totalFullWakelock = 0, totalPartialWakelock = 0, totalWindowWakelock = 0;
+            long totalDozeWakelock = 0;
             int countWakelock = 0;
             for (int iw=wakelocks.size()-1; iw>=0; iw--) {
                 final Uid.Wakelock wl = wakelocks.valueAt(iw);
@@ -3848,19 +3854,21 @@
                         "partial", which, linePrefix);
                 linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime,
                         "window", which, linePrefix);
-                if (true || !linePrefix.equals(": ")) {
-                    sb.append(" realtime");
-                    // Only print out wake locks that were held
-                    pw.println(sb.toString());
-                    uidActivity = true;
-                    countWakelock++;
-                }
+                linePrefix = printWakeLock(sb, wl.getWakeTime(WAKE_TYPE_DOZE), rawRealtime,
+                        "doze", which, linePrefix);
+                sb.append(" realtime");
+                pw.println(sb.toString());
+                uidActivity = true;
+                countWakelock++;
+
                 totalFullWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_FULL),
                         rawRealtime, which);
                 totalPartialWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_PARTIAL),
                         rawRealtime, which);
                 totalWindowWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_WINDOW),
                         rawRealtime, which);
+                totalDozeWakelock += computeWakeLock(wl.getWakeTime(WAKE_TYPE_DOZE),
+                        rawRealtime, which);
             }
             if (countWakelock > 1) {
                 if (totalFullWakelock != 0 || totalPartialWakelock != 0
@@ -3890,6 +3898,14 @@
                         formatTimeMs(sb, totalWindowWakelock);
                         sb.append("window");
                     }
+                    if (totalDozeWakelock != 0) {
+                        if (needComma) {
+                            sb.append(",");
+                        }
+                        needComma = true;
+                        formatTimeMs(sb, totalDozeWakelock);
+                        sb.append("doze");
+                    }
                     sb.append(" realtime");
                     pw.println(sb.toString());
                 }