summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Sungmin Choi <sungmin.choi@lge.com> 2013-01-16 12:57:36 +0900
committer Sungmin Choi <sungmin.choi@lge.com> 2013-07-24 23:36:07 -0700
commitc7e9e8b4f3e264375b416eff830739ecf0dc206c (patch)
treec85c2d3679f96fc3c51d543eb917cc2e7acf3d47
parentdbc51de44fe4f9a7f81528204250de32ec405d39 (diff)
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
-rw-r--r--core/java/android/os/BatteryStats.java16
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java6
2 files changed, 11 insertions, 11 deletions
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 499ec77e3d09..8804066ebeea 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -444,7 +444,7 @@ public abstract class BatteryStats implements Parcelable {
public byte batteryHealth;
public byte batteryPlugType;
- public char batteryTemperature;
+ public short batteryTemperature;
public char batteryVoltage;
// Constants from SCREEN_BRIGHTNESS_*
@@ -521,7 +521,7 @@ public abstract class BatteryStats implements Parcelable {
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 @@ public abstract class BatteryStats implements Parcelable {
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 @@ public abstract class BatteryStats implements Parcelable {
}
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 @@ public abstract class BatteryStats implements Parcelable {
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);
}
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 6375dbe6cf89..778693aba913 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -83,7 +83,7 @@ public final class BatteryStatsImpl extends BatteryStats {
private static final int MAGIC = 0xBA757475; // 'BATSTATS'
// Current on-disk Parcel version
- private static final int VERSION = 64 + (USE_OLD_HISTORY ? 1000 : 0);
+ private static final int VERSION = 65 + (USE_OLD_HISTORY ? 1000 : 0);
// Maximum number of items we will record in the history.
private static final int MAX_HISTORY_ITEMS = 2000;
@@ -4611,7 +4611,7 @@ public final class BatteryStatsImpl extends BatteryStats {
mHistoryCur.batteryStatus = (byte)status;
mHistoryCur.batteryHealth = (byte)health;
mHistoryCur.batteryPlugType = (byte)plugType;
- mHistoryCur.batteryTemperature = (char)temp;
+ mHistoryCur.batteryTemperature = (short)temp;
mHistoryCur.batteryVoltage = (char)volt;
setOnBatteryLocked(onBattery, oldStatus, level);
} else {
@@ -4634,7 +4634,7 @@ public final class BatteryStatsImpl extends BatteryStats {
}
if (temp >= (mHistoryCur.batteryTemperature+10)
|| temp <= (mHistoryCur.batteryTemperature-10)) {
- mHistoryCur.batteryTemperature = (char)temp;
+ mHistoryCur.batteryTemperature = (short)temp;
changed = true;
}
if (volt > (mHistoryCur.batteryVoltage+20)