summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhihai Xu <zhihaixu@google.com>2013-10-14 12:16:39 -0700
committerVineeta Srivastava <vsrivastava@google.com>2014-03-06 09:35:56 -0800
commite061a83b8cbd872cd9f0fea33717aa57112e6228 (patch)
tree4bf92608b363d4aa9753f44b569622d0cc9c97f2
parent3f298ffe0add6b60e8d6265670928f84ce7d7338 (diff)
downloadandroid_packages_apps_Bluetooth-e061a83b8cbd872cd9f0fea33717aa57112e6228.tar.gz
android_packages_apps_Bluetooth-e061a83b8cbd872cd9f0fea33717aa57112e6228.tar.bz2
android_packages_apps_Bluetooth-e061a83b8cbd872cd9f0fea33717aa57112e6228.zip
Device cannot go to sleep while connected to HBM-570 BT headset
The headset never disconnect the Obex connection for PBAP, so in this case, we never release the wakelock. Our PBAP implementation won't release wakelock until the Obex is disconnected by the remote device To better control the wake lock, we should only acquire the wakelock when we receive the reqeust from the remote device will release the wakelock after we send the response packets. bug:10957699 Change-Id: I85e0609e36788d9c36334dd804ec52c90b90615b
-rwxr-xr-xsrc/com/android/bluetooth/pbap/BluetoothPbapObexServer.java14
-rwxr-xr-xsrc/com/android/bluetooth/pbap/BluetoothPbapService.java33
2 files changed, 45 insertions, 2 deletions
diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java b/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java
index f5c48ed26..9fc8f1e82 100755
--- a/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java
+++ b/src/com/android/bluetooth/pbap/BluetoothPbapObexServer.java
@@ -181,6 +181,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
@Override
public int onConnect(final HeaderSet request, HeaderSet reply) {
if (V) logHeader(request);
+ notifyUpdateWakeLock();
try {
byte[] uuid = (byte[])request.getHeader(HeaderSet.TARGET);
if (uuid == null) {
@@ -229,7 +230,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
public void onDisconnect(final HeaderSet req, final HeaderSet resp) {
if (D) Log.d(TAG, "onDisconnect(): enter");
if (V) logHeader(req);
-
+ notifyUpdateWakeLock();
resp.responseCode = ResponseCodes.OBEX_HTTP_OK;
if (mCallback != null) {
Message msg = Message.obtain(mCallback);
@@ -242,6 +243,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
@Override
public int onAbort(HeaderSet request, HeaderSet reply) {
if (D) Log.d(TAG, "onAbort(): enter.");
+ notifyUpdateWakeLock();
sIsAborted = true;
return ResponseCodes.OBEX_HTTP_OK;
}
@@ -249,6 +251,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
@Override
public int onPut(final Operation op) {
if (D) Log.d(TAG, "onPut(): not support PUT request.");
+ notifyUpdateWakeLock();
return ResponseCodes.OBEX_HTTP_BAD_REQUEST;
}
@@ -257,7 +260,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
final boolean create) {
if (V) logHeader(request);
if (D) Log.d(TAG, "before setPath, mCurrentPath == " + mCurrentPath);
-
+ notifyUpdateWakeLock();
String current_path_tmp = mCurrentPath;
String tmp_path = null;
try {
@@ -308,6 +311,7 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
@Override
public int onGet(Operation op) {
+ notifyUpdateWakeLock();
sIsAborted = false;
HeaderSet request = null;
HeaderSet reply = new HeaderSet();
@@ -1021,6 +1025,12 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
result.append("\"/>");
}
+ private void notifyUpdateWakeLock() {
+ Message msg = Message.obtain(mCallback);
+ msg.what = BluetoothPbapService.MSG_ACQUIRE_WAKE_LOCK;
+ msg.sendToTarget();
+ }
+
public static final void logHeader(HeaderSet hs) {
Log.v(TAG, "Dumping HeaderSet " + hs.toString());
try {
diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java
index 2f577d50f..865b2f16f 100755
--- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java
+++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java
@@ -121,6 +121,10 @@ public class BluetoothPbapService extends Service {
public static final int MSG_OBEX_AUTH_CHALL = 5003;
+ public static final int MSG_ACQUIRE_WAKE_LOCK = 5004;
+
+ public static final int MSG_RELEASE_WAKE_LOCK = 5005;
+
private static final String BLUETOOTH_PERM = android.Manifest.permission.BLUETOOTH;
private static final String BLUETOOTH_ADMIN_PERM = android.Manifest.permission.BLUETOOTH_ADMIN;
@@ -134,6 +138,7 @@ public class BluetoothPbapService extends Service {
private static final int USER_CONFIRM_TIMEOUT_VALUE = 30000;
+ private static final int RELEASE_WAKE_LOCK_DELAY = 10000;
// Ensure not conflict with Opp notification ID
private static final int NOTIFICATION_ID_ACCESS = -1000001;
@@ -470,6 +475,11 @@ public class BluetoothPbapService extends Service {
BluetoothPbapRfcommTransport transport = new BluetoothPbapRfcommTransport(mConnSocket);
mServerSession = new ServerSession(transport, mPbapServer, mAuth);
setState(BluetoothPbap.STATE_CONNECTED);
+
+ mSessionStatusHandler.removeMessages(MSG_RELEASE_WAKE_LOCK);
+ mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler
+ .obtainMessage(MSG_RELEASE_WAKE_LOCK), RELEASE_WAKE_LOCK_DELAY);
+
if (VERBOSE) {
Log.v(TAG, "startObexServerSession() success!");
}
@@ -478,6 +488,8 @@ public class BluetoothPbapService extends Service {
private void stopObexServerSession() {
if (VERBOSE) Log.v(TAG, "Pbap Service stopObexServerSession");
+ mSessionStatusHandler.removeMessages(MSG_ACQUIRE_WAKE_LOCK);
+ mSessionStatusHandler.removeMessages(MSG_RELEASE_WAKE_LOCK);
// Release the wake lock if obex transaction is over
if (mWakeLock != null) {
mWakeLock.release();
@@ -660,6 +672,27 @@ public class BluetoothPbapService extends Service {
mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler
.obtainMessage(AUTH_TIMEOUT), USER_CONFIRM_TIMEOUT_VALUE);
break;
+ case MSG_ACQUIRE_WAKE_LOCK:
+ if (mWakeLock == null) {
+ PowerManager pm = (PowerManager)getSystemService(
+ Context.POWER_SERVICE);
+ mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
+ "StartingObexPbapTransaction");
+ mWakeLock.setReferenceCounted(false);
+ mWakeLock.acquire();
+ Log.w(TAG, "Acquire Wake Lock");
+ }
+ mSessionStatusHandler.removeMessages(MSG_RELEASE_WAKE_LOCK);
+ mSessionStatusHandler.sendMessageDelayed(mSessionStatusHandler
+ .obtainMessage(MSG_RELEASE_WAKE_LOCK), RELEASE_WAKE_LOCK_DELAY);
+ break;
+ case MSG_RELEASE_WAKE_LOCK:
+ if (mWakeLock != null) {
+ mWakeLock.release();
+ mWakeLock = null;
+ Log.w(TAG, "Release Wake Lock");
+ }
+ break;
default:
break;
}