Merge change 7961 into donut

* changes:
  Bluetooth at command tracking.
This commit is contained in:
Android (Google) Code Review
2009-07-20 17:42:21 -07:00
4 changed files with 87 additions and 9 deletions

View File

@@ -507,6 +507,19 @@ public abstract class BatteryStats implements Parcelable {
*/ */
public abstract long getBatteryUptime(long curTime); public abstract long getBatteryUptime(long curTime);
/**
* @deprecated use getRadioDataUptime
*/
public long getRadioDataUptimeMs() {
return getRadioDataUptime() / 1000;
}
/**
* Returns the time that the radio was on for data transfers.
* @return the uptime in microseconds while unplugged
*/
public abstract long getRadioDataUptime();
/** /**
* Returns the current battery realtime in microseconds. * Returns the current battery realtime in microseconds.
* *
@@ -1128,7 +1141,14 @@ public abstract class BatteryStats implements Parcelable {
} }
if (!didOne) sb.append("No activity"); if (!didOne) sb.append("No activity");
pw.println(sb.toString()); pw.println(sb.toString());
sb.setLength(0);
sb.append(prefix);
sb.append(" Radio data uptime when unplugged: ");
sb.append(getRadioDataUptime() / 1000);
sb.append(" ms");
pw.println(sb.toString());
sb.setLength(0); sb.setLength(0);
sb.append(prefix); sb.append(prefix);
sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000); sb.append(" Wifi on: "); formatTimeMs(sb, wifiOnTime / 1000);

View File

@@ -16,6 +16,7 @@
package com.android.internal.os; package com.android.internal.os;
import android.bluetooth.BluetoothHeadset;
import android.os.BatteryStats; import android.os.BatteryStats;
import android.os.NetStat; import android.os.NetStat;
import android.os.Parcel; import android.os.Parcel;
@@ -128,7 +129,10 @@ public final class BatteryStatsImpl extends BatteryStats {
boolean mBluetoothOn; boolean mBluetoothOn;
StopwatchTimer mBluetoothOnTimer; StopwatchTimer mBluetoothOnTimer;
/** Bluetooth headset object */
BluetoothHeadset mBtHeadset;
/** /**
* These provide time bases that discount the time the device is plugged * These provide time bases that discount the time the device is plugged
* in to power. * in to power.
@@ -160,6 +164,9 @@ public final class BatteryStatsImpl extends BatteryStats {
private long mRadioDataUptime; private long mRadioDataUptime;
private long mRadioDataStart; private long mRadioDataStart;
private int mBluetoothPingCount;
private int mBluetoothPingStart = -1;
/* /*
* Holds a SamplingTimer associated with each kernel wakelock name being tracked. * Holds a SamplingTimer associated with each kernel wakelock name being tracked.
*/ */
@@ -920,14 +927,18 @@ public final class BatteryStatsImpl extends BatteryStats {
dataTransfer[STATS_UNPLUGGED] = currentBytes; dataTransfer[STATS_UNPLUGGED] = currentBytes;
} }
private long getCurrentRadioDataUptimeMs() { /**
* Radio uptime in microseconds when transferring data. This value is very approximate.
* @return
*/
private long getCurrentRadioDataUptime() {
try { try {
File awakeTimeFile = new File("/sys/devices/virtual/net/rmnet0/awake_time_ms"); File awakeTimeFile = new File("/sys/devices/virtual/net/rmnet0/awake_time_ms");
if (!awakeTimeFile.exists()) return 0; if (!awakeTimeFile.exists()) return 0;
BufferedReader br = new BufferedReader(new FileReader(awakeTimeFile)); BufferedReader br = new BufferedReader(new FileReader(awakeTimeFile));
String line = br.readLine(); String line = br.readLine();
br.close(); br.close();
return Long.parseLong(line); return Long.parseLong(line) * 1000;
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
// Nothing // Nothing
} catch (IOException ioe) { } catch (IOException ioe) {
@@ -936,14 +947,44 @@ public final class BatteryStatsImpl extends BatteryStats {
return 0; return 0;
} }
/**
* @deprecated use getRadioDataUptime
*/
public long getRadioDataUptimeMs() { public long getRadioDataUptimeMs() {
return getRadioDataUptime() / 1000;
}
/**
* Returns the duration that the cell radio was up for data transfers.
*/
public long getRadioDataUptime() {
if (mRadioDataStart == -1) { if (mRadioDataStart == -1) {
return mRadioDataUptime; return mRadioDataUptime;
} else { } else {
return getCurrentRadioDataUptimeMs() - mRadioDataStart; return getCurrentRadioDataUptime() - mRadioDataStart;
} }
} }
private int getCurrentBluetoothPingCount() {
if (mBtHeadset != null) {
return mBtHeadset.getBatteryUsageHint();
}
return -1;
}
public int getBluetoothPingCount() {
if (mBluetoothPingStart == -1) {
return mBluetoothPingCount;
} else if (mBtHeadset != null) {
return getCurrentBluetoothPingCount() - mBluetoothPingStart;
}
return -1;
}
public void setBtHeadset(BluetoothHeadset headset) {
mBtHeadset = headset;
}
public void doUnplug(long batteryUptime, long batteryRealtime) { public void doUnplug(long batteryUptime, long batteryRealtime) {
for (int iu = mUidStats.size() - 1; iu >= 0; iu--) { for (int iu = mUidStats.size() - 1; iu >= 0; iu--) {
Uid u = mUidStats.valueAt(iu); Uid u = mUidStats.valueAt(iu);
@@ -961,8 +1002,11 @@ public final class BatteryStatsImpl extends BatteryStats {
doDataUnplug(mTotalDataRx, NetStat.getTotalRxBytes()); doDataUnplug(mTotalDataRx, NetStat.getTotalRxBytes());
doDataUnplug(mTotalDataTx, NetStat.getTotalTxBytes()); doDataUnplug(mTotalDataTx, NetStat.getTotalTxBytes());
// Track radio awake time // Track radio awake time
mRadioDataStart = getCurrentRadioDataUptimeMs(); mRadioDataStart = getCurrentRadioDataUptime();
mRadioDataUptime = 0; mRadioDataUptime = 0;
// Track bt headset ping count
mBluetoothPingStart = getCurrentBluetoothPingCount();
mBluetoothPingCount = 0;
} }
public void doPlug(long batteryUptime, long batteryRealtime) { public void doPlug(long batteryUptime, long batteryRealtime) {
@@ -985,8 +1029,12 @@ public final class BatteryStatsImpl extends BatteryStats {
doDataPlug(mTotalDataRx, NetStat.getTotalRxBytes()); doDataPlug(mTotalDataRx, NetStat.getTotalRxBytes());
doDataPlug(mTotalDataTx, NetStat.getTotalTxBytes()); doDataPlug(mTotalDataTx, NetStat.getTotalTxBytes());
// Track radio awake time // Track radio awake time
mRadioDataUptime = getRadioDataUptimeMs(); mRadioDataUptime = getRadioDataUptime();
mRadioDataStart = -1; mRadioDataStart = -1;
// Track bt headset ping count
mBluetoothPingCount = getBluetoothPingCount();
mBluetoothPingStart = -1;
} }
public void noteStartGps(int uid) { public void noteStartGps(int uid) {
@@ -3335,6 +3383,9 @@ public final class BatteryStatsImpl extends BatteryStats {
mRadioDataUptime = in.readLong(); mRadioDataUptime = in.readLong();
mRadioDataStart = -1; mRadioDataStart = -1;
mBluetoothPingCount = in.readInt();
mBluetoothPingStart = -1;
mKernelWakelockStats.clear(); mKernelWakelockStats.clear();
int NKW = in.readInt(); int NKW = in.readInt();
for (int ikw = 0; ikw < NKW; ikw++) { for (int ikw = 0; ikw < NKW; ikw++) {
@@ -3415,7 +3466,9 @@ public final class BatteryStatsImpl extends BatteryStats {
out.writeLong(getTotalTcpBytesSent(STATS_UNPLUGGED)); out.writeLong(getTotalTcpBytesSent(STATS_UNPLUGGED));
// Write radio uptime for data // Write radio uptime for data
out.writeLong(getRadioDataUptimeMs()); out.writeLong(getRadioDataUptime());
out.writeInt(getBluetoothPingCount());
out.writeInt(mKernelWakelockStats.size()); out.writeInt(mKernelWakelockStats.size());
for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) { for (Map.Entry<String, SamplingTimer> ent : mKernelWakelockStats.entrySet()) {

View File

@@ -86,6 +86,11 @@ public class PowerProfile {
*/ */
public static final String POWER_BLUETOOTH_ACTIVE = "bluetooth.active"; public static final String POWER_BLUETOOTH_ACTIVE = "bluetooth.active";
/**
* Power consumption when Bluetooth driver gets an AT command.
*/
public static final String POWER_BLUETOOTH_AT_CMD = "bluetooth.at";
/** /**
* Power consumption when screen is on, not including the backlight power. * Power consumption when screen is on, not including the backlight power.
*/ */

View File

@@ -41,7 +41,7 @@ public final class BatteryStatsService extends IBatteryStats.Stub {
final BatteryStatsImpl mStats; final BatteryStatsImpl mStats;
Context mContext; Context mContext;
BatteryStatsService(String filename) { BatteryStatsService(String filename) {
mStats = new BatteryStatsImpl(filename); mStats = new BatteryStatsImpl(filename);
} }