summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBhasker Neti <bneti@codeaurora.org>2013-11-08 16:49:22 +0530
committerBhasker Neti <bneti@codeaurora.org>2013-12-09 19:02:19 +0530
commite347e590f019ac4f813df0fea30777245aa81371 (patch)
tree303088a01aa249e0382e0883be9e72e49c1d9420
parentf53d911a854cd24a0143769ef3d01f19090ad045 (diff)
downloadandroid_packages_apps_Bluetooth-e347e590f019ac4f813df0fea30777245aa81371.tar.gz
android_packages_apps_Bluetooth-e347e590f019ac4f813df0fea30777245aa81371.tar.bz2
android_packages_apps_Bluetooth-e347e590f019ac4f813df0fea30777245aa81371.zip
Bluetooth: Acquire wake lock to avoid power collapse
This ensures that target wont go into power save mode when there is an acl is active and timer are running. Change-Id: I9789c8ae0781a1ca4d33d364efd583ea16e9ee21 CRs-fixed: 576239
-rw-r--r--jni/com_android_bluetooth_btservice_AdapterService.cpp18
-rw-r--r--jni/com_android_bluetooth_btservice_QAdapterService.cpp1
-rw-r--r--src/com/android/bluetooth/btservice/JniCallbacks.java6
-rw-r--r--src/com/android/bluetooth/btservice/RemoteDevices.java25
4 files changed, 47 insertions, 3 deletions
diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp
index 55c37b364..2ef387d51 100644
--- a/jni/com_android_bluetooth_btservice_AdapterService.cpp
+++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp
@@ -45,6 +45,7 @@ static jmethodID method_bondStateChangeCallback;
static jmethodID method_aclStateChangeCallback;
static jmethodID method_discoveryStateChangeCallback;
static jmethodID method_deviceMasInstancesFoundCallback;
+static jmethodID method_wakeStateChangeCallback;
static const bt_interface_t *sBluetoothInterface = NULL;
static const btsock_interface_t *sBluetoothSocketInterface = NULL;
@@ -349,7 +350,20 @@ static void discovery_state_changed_callback(bt_discovery_state_t state) {
checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
}
+static void wake_state_changed_callback(bt_state_t state) {
+ if (!checkCallbackThread()) {
+ ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);
+ return;
+ }
+
+ ALOGV("%s: WakeState:%d ", __FUNCTION__, state);
+
+ callbackEnv->CallVoidMethod(sJniCallbacksObj, method_wakeStateChangeCallback,
+ (jint)state);
+
+ checkAndClearExceptionFromCallback(callbackEnv, __FUNCTION__);
+}
static void pin_request_callback(bt_bdaddr_t *bd_addr, bt_bdname_t *bdname, uint32_t cod, uint8_t secure) {
jbyteArray addr, devname;
if (!checkCallbackThread()) {
@@ -451,6 +465,7 @@ bt_callbacks_t sBluetoothCallbacks = {
remote_device_properties_callback,
device_found_callback,
discovery_state_changed_callback,
+ wake_state_changed_callback,
pin_request_callback,
ssp_request_callback,
bond_state_changed_callback,
@@ -554,7 +569,8 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
"([I[[B)V");
method_discoveryStateChangeCallback = env->GetMethodID(jniCallbackClass,
"discoveryStateChangeCallback", "(I)V");
-
+ method_wakeStateChangeCallback = env->GetMethodID(jniCallbackClass,
+ "wakeStateChangeCallback", "(I)V");
method_devicePropertyChangedCallback = env->GetMethodID(jniCallbackClass,
"devicePropertyChangedCallback",
"([B[I[[B)V");
diff --git a/jni/com_android_bluetooth_btservice_QAdapterService.cpp b/jni/com_android_bluetooth_btservice_QAdapterService.cpp
index 7f7155dc4..5a183e65c 100644
--- a/jni/com_android_bluetooth_btservice_QAdapterService.cpp
+++ b/jni/com_android_bluetooth_btservice_QAdapterService.cpp
@@ -233,6 +233,7 @@ bt_callbacks_t sQBluetoothCallbacks = {
NULL,
NULL,
NULL,
+ NULL,
le_extended_scan_result_callbacks,
le_lpp_write_rssi_thresh_callbacks,
le_lpp_read_rssi_thresh_callbacks,
diff --git a/src/com/android/bluetooth/btservice/JniCallbacks.java b/src/com/android/bluetooth/btservice/JniCallbacks.java
index a41e7cff5..95a3480c2 100644
--- a/src/com/android/bluetooth/btservice/JniCallbacks.java
+++ b/src/com/android/bluetooth/btservice/JniCallbacks.java
@@ -68,9 +68,11 @@ final class JniCallbacks {
}
void aclStateChangeCallback(int status, byte[] address, int newState) {
- mRemoteDevices.aclStateChangeCallback(status, address, newState);
+ mRemoteDevices.aclStateChangeCallback(status, address, newState);
+ }
+ void wakeStateChangeCallback(int state) {
+ mRemoteDevices.wakeStateChangeCallback(state);
}
-
void stateChangeCallback(int status) {
mAdapterStateMachine.stateChangeCallback(status);
}
diff --git a/src/com/android/bluetooth/btservice/RemoteDevices.java b/src/com/android/bluetooth/btservice/RemoteDevices.java
index 8a603935a..f9ba00ead 100644
--- a/src/com/android/bluetooth/btservice/RemoteDevices.java
+++ b/src/com/android/bluetooth/btservice/RemoteDevices.java
@@ -49,6 +49,7 @@ final class RemoteDevices {
/* The WakeLock is used for bringing up the LCD during a pairing request
* from remote device when Android is in Suspend state.*/
private PowerManager.WakeLock mWakeLock;
+ private PowerManager.WakeLock mWakeLock_stack;
private Object mObject = new Object();
private static final int UUID_INTENT_DELAY = 6000;
@@ -70,6 +71,10 @@ final class RemoteDevices {
mWakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
| PowerManager.ON_AFTER_RELEASE, TAG);
mWakeLock.setReferenceCounted(false);
+ //WakeLock instantiation in RemoteDevices class
+ mWakeLock_stack = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
+ | PowerManager.ON_AFTER_RELEASE, TAG);
+ mWakeLock_stack.setReferenceCounted(false);
}
@@ -83,6 +88,13 @@ final class RemoteDevices {
if (mDevices != null)
mDevices.clear();
+
+ if ((mWakeLock_stack != null) && // we have a WakeLock
+ (mWakeLock_stack.isHeld() == true)) { // we hold it
+ mWakeLock_stack.release ();
+ mWakeLock_stack = null;
+ }
+
}
public Object Clone() throws CloneNotSupportedException {
@@ -529,6 +541,19 @@ final class RemoteDevices {
sendMasInstanceIntent(device, instances);
}
+ void wakeStateChangeCallback(int state) {
+ if (state == 0x01) {
+ // Acquire wakelock to not allow Device to go into power collapse
+ mWakeLock_stack.acquire();
+ debugLog("Wake lock Aquired");
+ } else if (state == 0x00){
+ // Release wakelock to allow Device to go into power collapse.
+ mWakeLock_stack.release();
+ debugLog("Wake lock released");
+ } else
+ errorLog("Wake lock WRONG STATE ***** ");
+
+ }
void fetchUuids(BluetoothDevice device) {
if (mSdpTracker.contains(device)) return;