@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) {
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);
@Override
public int onAbort(HeaderSet request, HeaderSet reply) {
if (D) Log.d(TAG, "onAbort(): enter.");
+ notifyUpdateWakeLock();
sIsAborted = true;
return ResponseCodes.OBEX_HTTP_OK;
}
@Override
public int onPut(final Operation op) {
if (D) Log.d(TAG, "onPut(): not support PUT request.");
+ notifyUpdateWakeLock();
return ResponseCodes.OBEX_HTTP_BAD_REQUEST;
}
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 {
@Override
public int onGet(Operation op) {
+ notifyUpdateWakeLock();
sIsAborted = false;
HeaderSet request = null;
HeaderSet reply = new HeaderSet();
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 {
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;
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;
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!");
}
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();
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;
}