Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abce10c9 authored by Zhihai Xu's avatar Zhihai Xu Committed by Android Git Automerger
Browse files

am e061a83b: Device cannot go to sleep while connected to HBM-570 BT headset

* commit 'e061a83b':
  Device cannot go to sleep while connected to HBM-570 BT headset
parents f0e15e66 e061a83b
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -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 {
+33 −0
Original line number Diff line number Diff line
@@ -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;
            }