summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2015-06-15 17:19:07 -0700
committerAdam Lesinski <adamlesinski@google.com>2015-06-15 17:19:07 -0700
commit8a351373881e2e11c2636d6f9445f9df9accbace (patch)
treead3c76e045398bddc3b2fda0bb76b25d4d3546c0
parent2d4dc8db64d0f75e530451acb2c0bea97b9264ff (diff)
downloadframeworks_base-8a351373881e2e11c2636d6f9445f9df9accbace.zip
frameworks_base-8a351373881e2e11c2636d6f9445f9df9accbace.tar.gz
frameworks_base-8a351373881e2e11c2636d6f9445f9df9accbace.tar.bz2
Bluetooth energy: fix overflow in calculation
Use longs instead of ints, because the energy values can get pretty high. Change-Id: I43e696ad9e5965c2e616b11920db5bfae5db1671
-rw-r--r--core/java/android/bluetooth/BluetoothActivityEnergyInfo.java40
-rw-r--r--services/core/java/com/android/server/am/BatteryStatsService.java4
-rw-r--r--wifi/java/android/net/wifi/WifiActivityEnergyInfo.java47
3 files changed, 47 insertions, 44 deletions
diff --git a/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java b/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java
index 161c339..834a587 100644
--- a/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java
+++ b/core/java/android/bluetooth/BluetoothActivityEnergyInfo.java
@@ -28,10 +28,10 @@ import android.os.Parcelable;
public final class BluetoothActivityEnergyInfo implements Parcelable {
private final long mTimestamp;
private final int mBluetoothStackState;
- private final int mControllerTxTimeMs;
- private final int mControllerRxTimeMs;
- private final int mControllerIdleTimeMs;
- private final int mControllerEnergyUsed;
+ private final long mControllerTxTimeMs;
+ private final long mControllerRxTimeMs;
+ private final long mControllerIdleTimeMs;
+ private final long mControllerEnergyUsed;
public static final int BT_STACK_STATE_INVALID = 0;
public static final int BT_STACK_STATE_STATE_ACTIVE = 1;
@@ -39,7 +39,7 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
public static final int BT_STACK_STATE_STATE_IDLE = 3;
public BluetoothActivityEnergyInfo(long timestamp, int stackState,
- int txTime, int rxTime, int idleTime, int energyUsed) {
+ long txTime, long rxTime, long idleTime, long energyUsed) {
mTimestamp = timestamp;
mBluetoothStackState = stackState;
mControllerTxTimeMs = txTime;
@@ -65,10 +65,10 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
public BluetoothActivityEnergyInfo createFromParcel(Parcel in) {
long timestamp = in.readLong();
int stackState = in.readInt();
- int txTime = in.readInt();
- int rxTime = in.readInt();
- int idleTime = in.readInt();
- int energyUsed = in.readInt();
+ long txTime = in.readLong();
+ long rxTime = in.readLong();
+ long idleTime = in.readLong();
+ long energyUsed = in.readLong();
return new BluetoothActivityEnergyInfo(timestamp, stackState,
txTime, rxTime, idleTime, energyUsed);
}
@@ -80,10 +80,10 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
public void writeToParcel(Parcel out, int flags) {
out.writeLong(mTimestamp);
out.writeInt(mBluetoothStackState);
- out.writeInt(mControllerTxTimeMs);
- out.writeInt(mControllerRxTimeMs);
- out.writeInt(mControllerIdleTimeMs);
- out.writeInt(mControllerEnergyUsed);
+ out.writeLong(mControllerTxTimeMs);
+ out.writeLong(mControllerRxTimeMs);
+ out.writeLong(mControllerIdleTimeMs);
+ out.writeLong(mControllerEnergyUsed);
}
public int describeContents() {
@@ -100,21 +100,21 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
/**
* @return tx time in ms
*/
- public int getControllerTxTimeMillis() {
+ public long getControllerTxTimeMillis() {
return mControllerTxTimeMs;
}
/**
* @return rx time in ms
*/
- public int getControllerRxTimeMillis() {
+ public long getControllerRxTimeMillis() {
return mControllerRxTimeMs;
}
/**
* @return idle time in ms
*/
- public int getControllerIdleTimeMillis() {
+ public long getControllerIdleTimeMillis() {
return mControllerIdleTimeMs;
}
@@ -122,7 +122,7 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
* product of current(mA), voltage(V) and time(ms)
* @return energy used
*/
- public int getControllerEnergyUsed() {
+ public long getControllerEnergyUsed() {
return mControllerEnergyUsed;
}
@@ -137,8 +137,8 @@ public final class BluetoothActivityEnergyInfo implements Parcelable {
* @return if the record is valid
*/
public boolean isValid() {
- return ((getControllerTxTimeMillis() !=0) ||
- (getControllerRxTimeMillis() !=0) ||
- (getControllerIdleTimeMillis() !=0));
+ return ((mControllerTxTimeMs !=0) ||
+ (mControllerRxTimeMs !=0) ||
+ (mControllerIdleTimeMs !=0));
}
}
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java
index b56e326..c973386 100644
--- a/services/core/java/com/android/server/am/BatteryStatsService.java
+++ b/services/core/java/com/android/server/am/BatteryStatsService.java
@@ -1167,6 +1167,10 @@ public final class BatteryStatsService extends IBatteryStats.Stub
BluetoothActivityEnergyInfo info = adapter.getControllerActivityEnergyInfo(
BluetoothAdapter.ACTIVITY_ENERGY_INFO_REFRESHED);
if (info != null && info.isValid()) {
+ if (info.getControllerEnergyUsed() < 0 || info.getControllerIdleTimeMillis() < 0 ||
+ info.getControllerRxTimeMillis() < 0 || info.getControllerTxTimeMillis() < 0) {
+ Slog.wtf(TAG, "Bluetooth energy data is invalid: " + info);
+ }
return info;
}
}
diff --git a/wifi/java/android/net/wifi/WifiActivityEnergyInfo.java b/wifi/java/android/net/wifi/WifiActivityEnergyInfo.java
index 0f73342..035317e 100644
--- a/wifi/java/android/net/wifi/WifiActivityEnergyInfo.java
+++ b/wifi/java/android/net/wifi/WifiActivityEnergyInfo.java
@@ -39,22 +39,22 @@ public final class WifiActivityEnergyInfo implements Parcelable {
/**
* @hide
*/
- public int mControllerTxTimeMs;
+ public long mControllerTxTimeMs;
/**
* @hide
*/
- public int mControllerRxTimeMs;
+ public long mControllerRxTimeMs;
/**
* @hide
*/
- public int mControllerIdleTimeMs;
+ public long mControllerIdleTimeMs;
/**
* @hide
*/
- public int mControllerEnergyUsed;
+ public long mControllerEnergyUsed;
public static final int STACK_STATE_INVALID = 0;
public static final int STACK_STATE_STATE_ACTIVE = 1;
@@ -62,7 +62,7 @@ public final class WifiActivityEnergyInfo implements Parcelable {
public static final int STACK_STATE_STATE_IDLE = 3;
public WifiActivityEnergyInfo(long timestamp, int stackState,
- int txTime, int rxTime, int idleTime, int energyUsed) {
+ long txTime, long rxTime, long idleTime, long energyUsed) {
mTimestamp = timestamp;
mStackState = stackState;
mControllerTxTimeMs = txTime;
@@ -88,10 +88,10 @@ public final class WifiActivityEnergyInfo implements Parcelable {
public WifiActivityEnergyInfo createFromParcel(Parcel in) {
long timestamp = in.readLong();
int stackState = in.readInt();
- int txTime = in.readInt();
- int rxTime = in.readInt();
- int idleTime = in.readInt();
- int energyUsed = in.readInt();
+ long txTime = in.readLong();
+ long rxTime = in.readLong();
+ long idleTime = in.readLong();
+ long energyUsed = in.readLong();
return new WifiActivityEnergyInfo(timestamp, stackState,
txTime, rxTime, idleTime, energyUsed);
}
@@ -103,10 +103,10 @@ public final class WifiActivityEnergyInfo implements Parcelable {
public void writeToParcel(Parcel out, int flags) {
out.writeLong(mTimestamp);
out.writeInt(mStackState);
- out.writeInt(mControllerTxTimeMs);
- out.writeInt(mControllerRxTimeMs);
- out.writeInt(mControllerIdleTimeMs);
- out.writeInt(mControllerEnergyUsed);
+ out.writeLong(mControllerTxTimeMs);
+ out.writeLong(mControllerRxTimeMs);
+ out.writeLong(mControllerIdleTimeMs);
+ out.writeLong(mControllerEnergyUsed);
}
public int describeContents() {
@@ -123,30 +123,29 @@ public final class WifiActivityEnergyInfo implements Parcelable {
/**
* @return tx time in ms
*/
- public int getControllerTxTimeMillis() {
- return (int)mControllerTxTimeMs;
+ public long getControllerTxTimeMillis() {
+ return mControllerTxTimeMs;
}
/**
* @return rx time in ms
*/
- public int getControllerRxTimeMillis() {
- return (int)mControllerRxTimeMs;
+ public long getControllerRxTimeMillis() {
+ return mControllerRxTimeMs;
}
/**
* @return idle time in ms
*/
- public int getControllerIdleTimeMillis() {
- return (int)mControllerIdleTimeMs;
+ public long getControllerIdleTimeMillis() {
+ return mControllerIdleTimeMs;
}
-
/**
* product of current(mA), voltage(V) and time(ms)
* @return energy used
*/
- public int getControllerEnergyUsed() {
+ public long getControllerEnergyUsed() {
return mControllerEnergyUsed;
}
/**
@@ -160,8 +159,8 @@ public final class WifiActivityEnergyInfo implements Parcelable {
* @return if the record is valid
*/
public boolean isValid() {
- return ((getControllerTxTimeMillis() !=0) ||
- (getControllerRxTimeMillis() !=0) ||
- (getControllerIdleTimeMillis() !=0));
+ return ((mControllerTxTimeMs !=0) ||
+ (mControllerRxTimeMs !=0) ||
+ (mControllerIdleTimeMs !=0));
}
}