summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorNick Pelly <npelly@google.com>2009-06-19 10:08:09 -0700
committerNick Pelly <npelly@google.com>2009-06-19 10:08:09 -0700
commit6c901db72dbaf57d8fdf26adae6721de14ecae22 (patch)
treef49c0fa11e6fd06ab20abe870456d041aaee433b /core/java/android
parentfd5f087536dcb04ac9c46f2b19f87a37455390b0 (diff)
downloadframeworks_base-6c901db72dbaf57d8fdf26adae6721de14ecae22.zip
frameworks_base-6c901db72dbaf57d8fdf26adae6721de14ecae22.tar.gz
frameworks_base-6c901db72dbaf57d8fdf26adae6721de14ecae22.tar.bz2
Add getBatteryUsageHint() to BluetoothHeadset for power monitoring.
This is a monotonically increasing integer. Wraps to 0 at Integer.MAX_INT, and at boot. Current implementation returns the number of AT commands handled since boot. This is a good indicator for spammy headset/handsfree units that can keep the device awake by polling for cellular status updates. As a rule of thumb, each AT command prevents the CPU from sleeping for 500 ms
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/bluetooth/BluetoothHeadset.java25
-rw-r--r--core/java/android/bluetooth/HeadsetBase.java16
-rw-r--r--core/java/android/bluetooth/IBluetoothHeadset.aidl1
-rw-r--r--core/java/android/server/BluetoothDeviceService.java2
4 files changed, 43 insertions, 1 deletions
diff --git a/core/java/android/bluetooth/BluetoothHeadset.java b/core/java/android/bluetooth/BluetoothHeadset.java
index e198435..fe1e09a 100644
--- a/core/java/android/bluetooth/BluetoothHeadset.java
+++ b/core/java/android/bluetooth/BluetoothHeadset.java
@@ -332,6 +332,31 @@ public class BluetoothHeadset {
}
/**
+ * Get battery usage hint for Bluetooth Headset service.
+ * This is a monotonically increasing integer. Wraps to 0 at
+ * Integer.MAX_INT, and at boot.
+ * Current implementation returns the number of AT commands handled since
+ * boot. This is a good indicator for spammy headset/handsfree units that
+ * can keep the device awake by polling for cellular status updates. As a
+ * rule of thumb, each AT command prevents the CPU from sleeping for 500 ms
+ * @return monotonically increasing battery usage hint, or a negative error
+ * code on error
+ * @hide
+ */
+ public int getBatteryUsageHint() {
+ if (DBG) log("getBatteryUsageHint()");
+ if (mService != null) {
+ try {
+ return mService.getBatteryUsageHint();
+ } catch (RemoteException e) {Log.e(TAG, e.toString());}
+ } else {
+ Log.w(TAG, "Proxy not attached to service");
+ if (DBG) Log.d(TAG, Log.getStackTraceString(new Throwable()));
+ }
+ return -1;
+ }
+
+ /**
* Check class bits for possible HSP or HFP support.
* This is a simple heuristic that tries to guess if a device with the
* given class bits might support HSP or HFP. It is not accurate for all
diff --git a/core/java/android/bluetooth/HeadsetBase.java b/core/java/android/bluetooth/HeadsetBase.java
index f31e7a2..f987ffd 100644
--- a/core/java/android/bluetooth/HeadsetBase.java
+++ b/core/java/android/bluetooth/HeadsetBase.java
@@ -40,6 +40,8 @@ public class HeadsetBase {
public static final int DIRECTION_INCOMING = 1;
public static final int DIRECTION_OUTGOING = 2;
+ private static int sAtInputCount = 0; /* TODO: Consider not using a static variable */
+
private final BluetoothDevice mBluetooth;
private final String mAddress;
private final int mRfcommChannel;
@@ -109,6 +111,14 @@ public class HeadsetBase {
acquireWakeLock();
long timestamp;
+ synchronized(HeadsetBase.class) {
+ if (sAtInputCount == Integer.MAX_VALUE) {
+ sAtInputCount = 0;
+ } else {
+ sAtInputCount++;
+ }
+ }
+
if (DBG) timestamp = System.currentTimeMillis();
AtCommandResult result = mAtParser.process(input);
if (DBG) Log.d(TAG, "Processing " + input + " took " +
@@ -279,7 +289,11 @@ public class HeadsetBase {
}
}
- private void log(String msg) {
+ public static int getAtInputCount() {
+ return sAtInputCount;
+ }
+
+ private static void log(String msg) {
Log.d(TAG, msg);
}
}
diff --git a/core/java/android/bluetooth/IBluetoothHeadset.aidl b/core/java/android/bluetooth/IBluetoothHeadset.aidl
index 582d4e3..5f42fd6 100644
--- a/core/java/android/bluetooth/IBluetoothHeadset.aidl
+++ b/core/java/android/bluetooth/IBluetoothHeadset.aidl
@@ -31,4 +31,5 @@ interface IBluetoothHeadset {
boolean stopVoiceRecognition();
boolean setPriority(in String address, int priority);
int getPriority(in String address);
+ int getBatteryUsageHint();
}
diff --git a/core/java/android/server/BluetoothDeviceService.java b/core/java/android/server/BluetoothDeviceService.java
index 3a89abd..8c843ef 100644
--- a/core/java/android/server/BluetoothDeviceService.java
+++ b/core/java/android/server/BluetoothDeviceService.java
@@ -1224,6 +1224,8 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {
break;
}
pw.println("getHeadsetAddress() = " + headset.getHeadsetAddress());
+ pw.println("getBatteryUsageHint() = " + headset.getBatteryUsageHint());
+
headset.close();
}