summaryrefslogtreecommitdiffstats
path: root/hiddtestapp
diff options
context:
space:
mode:
authorHemant Gupta <hemantg@codeaurora.org>2014-03-14 12:02:13 +0530
committerHemant Gupta <hemantg@codeaurora.org>2014-03-17 21:29:15 +0530
commitd7be30ccfcc26a42d2bf80e61300d04af21957ff (patch)
tree8557316aaca980d534778354cf3827695c9e45ce /hiddtestapp
parent5254d40bb2b36cd42a10f4ad3c63ba5923b4e1dc (diff)
downloadandroid_packages_apps_BluetoothExt-d7be30ccfcc26a42d2bf80e61300d04af21957ff.tar.gz
android_packages_apps_BluetoothExt-d7be30ccfcc26a42d2bf80e61300d04af21957ff.tar.bz2
android_packages_apps_BluetoothExt-d7be30ccfcc26a42d2bf80e61300d04af21957ff.zip
Bluetooth: HID-D: Send battery update only when it changes
This patch sends battery level update to remote HID host only when battery level changes from the last update sent to remote device. Without this change it was observed, that DUT was unnecessarily sending battery level updates even when there was no change in battery level. Change-Id: I4472d9c8d8c99b3a6189b7f667c72ab196424fb4 CRs-Fixed: 624627
Diffstat (limited to 'hiddtestapp')
-rw-r--r--hiddtestapp/src/org/codeaurora/bluetooth/hiddtestapp/HidWrapperService.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/hiddtestapp/src/org/codeaurora/bluetooth/hiddtestapp/HidWrapperService.java b/hiddtestapp/src/org/codeaurora/bluetooth/hiddtestapp/HidWrapperService.java
index 718a580..5057605 100644
--- a/hiddtestapp/src/org/codeaurora/bluetooth/hiddtestapp/HidWrapperService.java
+++ b/hiddtestapp/src/org/codeaurora/bluetooth/hiddtestapp/HidWrapperService.java
@@ -86,6 +86,8 @@ public class HidWrapperService extends Service {
private float mBatteryLevel = 0;
+ private float mCurrentBatteryLevel = 0;
+
private int mConnectionState = BluetoothHidDevice.STATE_DISCONNECTED;
private MouseWrapper mMouseWrapper = new MouseWrapper();
@@ -274,6 +276,7 @@ public class HidWrapperService extends Service {
mInputReportCache.clear();
mOutputReportCache.clear();
mBatteryWrapper.update(mBatteryLevel);
+ mCurrentBatteryLevel = mBatteryLevel;
mEventListener.onProtocolModeState(
mProtocol == BluetoothHidDevice.PROTOCOL_BOOT_MODE);
break;
@@ -368,8 +371,11 @@ public class HidWrapperService extends Service {
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
mBatteryLevel = (float) level / (float) scale;
-
- mBatteryWrapper.update(mBatteryLevel);
+ if (mCurrentBatteryLevel != mBatteryLevel) {
+ Log.v(TAG, "ACTION_BATTERY_CHANGED, mBatteryLevel = " + mBatteryLevel);
+ mBatteryWrapper.update(mBatteryLevel);
+ mCurrentBatteryLevel = mBatteryLevel;
+ }
}
}
@@ -514,6 +520,7 @@ public class HidWrapperService extends Service {
private byte[] mBuffer = new byte[1];
public synchronized void update(float level) {
+ Log.v(TAG, "BatteryWrapper: update: level = " + level);
if (mConnectionState != BluetoothHidDevice.STATE_CONNECTED) {
// battery update will not trigger reconnection
return;
@@ -524,8 +531,10 @@ public class HidWrapperService extends Service {
return;
int val = (int) (level * 255);
+ Log.v(TAG, "BatteryWrapper: update: val = " + val);
mBuffer[0] = (byte) (val & 0xff);
+ Log.v(TAG, "BatteryWrapper: update: mBuffer[0] = " + mBuffer[0]);
if (mHidDevice != null) {
storeReport(HidConsts.BATTERY_REPORT_ID, mBuffer, true);