handle negative temperature

When the battery temperature drops to below zero, BatteryLevelInit()
fails to show negative temperature. Because the type is unsigned
and the size of bit field is 10 bits.
So to handle negative temperature, change the type of battery temperature
from "char" to "short". And extend the size of temperature bit field
from 10 to 11 bits, which first bit is used for the sign bit.

Before:
31             24                    14                 0
+---------------+---------------------+-----------------+
| Battery Level | Battery temperature | Battery Voltage |
+---------------+---------------------+-----------------+

After:
31           25                      14                 0
+-------------+-----------------------+-----------------+
|Battery Level|  Battery temperature  | Battery Voltage |
+-------------+-----------------------+-----------------+

Bits 31..25: battery level percentage (7 bits unsigned)
Bits 24..14: battery temperature (11 bits signed)
    First bit is used for the sign and others for the temperature
Bits 13..0: battery voltage in 0.001 volt units (14 bits unsigned)

Becuase of changing the format, let the BatteryStatsImpl.VERSION field
increment.

Bug: 8009514
Change-Id: Iaa12f4d3f14e6cf4d73bc1a23d81c60f9677a499
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 499ec77..8804066 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -444,7 +444,7 @@
         public byte batteryHealth;
         public byte batteryPlugType;
         
-        public char batteryTemperature;
+        public short batteryTemperature;
         public char batteryVoltage;
         
         // Constants from SCREEN_BRIGHTNESS_*
@@ -521,7 +521,7 @@
             batteryHealth = (byte)((bat>>20)&0xf);
             batteryPlugType = (byte)((bat>>24)&0xf);
             bat = src.readInt();
-            batteryTemperature = (char)(bat&0xffff);
+            batteryTemperature = (short)(bat&0xffff);
             batteryVoltage = (char)((bat>>16)&0xffff);
             states = src.readInt();
         }
@@ -590,7 +590,7 @@
                 if (DEBUG) Slog.i(TAG, "WRITE DELTA: batteryToken=0x"
                         + Integer.toHexString(batteryLevelInt)
                         + " batteryLevel=" + batteryLevel
-                        + " batteryTemp=" + (int)batteryTemperature
+                        + " batteryTemp=" + batteryTemperature
                         + " batteryVolt=" + (int)batteryVoltage);
             }
             if (stateIntChanged) {
@@ -605,8 +605,8 @@
         }
         
         private int buildBatteryLevelInt() {
-            return ((((int)batteryLevel)<<24)&0xff000000)
-                    | ((((int)batteryTemperature)<<14)&0x00ffc000)
+            return ((((int)batteryLevel)<<25)&0xfe000000)
+                    | ((((int)batteryTemperature)<<14)&0x01ffc000)
                     | (((int)batteryVoltage)&0x00003fff);
         }
         
@@ -642,13 +642,13 @@
             
             if ((firstToken&DELTA_BATTERY_LEVEL_FLAG) != 0) {
                 int batteryLevelInt = src.readInt();
-                batteryLevel = (byte)((batteryLevelInt>>24)&0xff);
-                batteryTemperature = (char)((batteryLevelInt>>14)&0x3ff);
+                batteryLevel = (byte)((batteryLevelInt>>25)&0x7f);
+                batteryTemperature = (short)((batteryLevelInt<<7)>>21);
                 batteryVoltage = (char)(batteryLevelInt&0x3fff);
                 if (DEBUG) Slog.i(TAG, "READ DELTA: batteryToken=0x"
                         + Integer.toHexString(batteryLevelInt)
                         + " batteryLevel=" + batteryLevel
-                        + " batteryTemp=" + (int)batteryTemperature
+                        + " batteryTemp=" + batteryTemperature
                         + " batteryVolt=" + (int)batteryVoltage);
             }