Loading core/java/android/bluetooth/BluetoothHeadset.java +25 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,31 @@ public class BluetoothHeadset { return -1; } /** * 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 Loading core/java/android/bluetooth/HeadsetBase.java +15 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 " + Loading Loading @@ -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); } } core/java/android/bluetooth/IBluetoothHeadset.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,5 @@ interface IBluetoothHeadset { boolean stopVoiceRecognition(); boolean setPriority(in String address, int priority); int getPriority(in String address); int getBatteryUsageHint(); } core/java/android/server/BluetoothDeviceService.java +2 −0 Original line number Diff line number Diff line Loading @@ -1039,6 +1039,8 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { break; } pw.println("getHeadsetAddress() = " + headset.getHeadsetAddress()); pw.println("getBatteryUsageHint() = " + headset.getBatteryUsageHint()); headset.close(); } Loading Loading
core/java/android/bluetooth/BluetoothHeadset.java +25 −0 Original line number Diff line number Diff line Loading @@ -331,6 +331,31 @@ public class BluetoothHeadset { return -1; } /** * 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 Loading
core/java/android/bluetooth/HeadsetBase.java +15 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 " + Loading Loading @@ -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); } }
core/java/android/bluetooth/IBluetoothHeadset.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -31,4 +31,5 @@ interface IBluetoothHeadset { boolean stopVoiceRecognition(); boolean setPriority(in String address, int priority); int getPriority(in String address); int getBatteryUsageHint(); }
core/java/android/server/BluetoothDeviceService.java +2 −0 Original line number Diff line number Diff line Loading @@ -1039,6 +1039,8 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { break; } pw.println("getHeadsetAddress() = " + headset.getHeadsetAddress()); pw.println("getBatteryUsageHint() = " + headset.getBatteryUsageHint()); headset.close(); } Loading