Try to always print time stamp in battery history.

Also fix printing of string pool to quote the strings
and escape characters, and change history time stamps
to print starting at 0 and going up.

Change-Id: I2d0c080f2b5de7b27b20a7357c2c0cf481c82d8c
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 4c11fa9..eaedba5 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -5580,13 +5580,13 @@
             if (end) {
                 Slog.w(TAG, "New history ends before old history!");
             } else if (!out.same(mHistoryReadTmp)) {
-                long now = getHistoryBaseTime() + SystemClock.elapsedRealtime();
                 PrintWriter pw = new FastPrintWriter(new LogWriter(android.util.Log.WARN, TAG));
                 pw.println("Histories differ!");
                 pw.println("Old history:");
-                (new HistoryPrinter()).printNextItem(pw, out, now, false, true);
+                (new HistoryPrinter()).printNextItem(pw, out, 0, false, true);
                 pw.println("New history:");
-                (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, now, false, true);
+                (new HistoryPrinter()).printNextItem(pw, mHistoryReadTmp, 0, false,
+                        true);
                 pw.flush();
             }
         }
@@ -5664,7 +5664,12 @@
             return false;
         }
 
+        final long lastRealtime = out.time;
+        final long lastWalltime = out.currentTime;
         readHistoryDelta(mHistoryBuffer, out);
+        if (out.cmd != HistoryItem.CMD_CURRENT_TIME && lastWalltime != 0) {
+            out.currentTime = lastWalltime + (out.time - lastRealtime);
+        }
         return true;
     }