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

Commit 0e088360 authored by Hemant Gupta's avatar Hemant Gupta Committed by Andre Eisenbach
Browse files

SAP: Remove sdp record while BT is being turned off to prevent leak

Remove sdp record created dynamically for SAP server during BT off state.
Without this call, there is leak in sdp layer in stack as sdp record is
never removed, even though the socket is closed.
Also proper checks are added to prevent call to remove sdp record when
adapter is null.

Change-Id: I739cc3115f6cd7fedf9085e8522c96da257e9568
parent 8731128a
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -121,7 +121,14 @@ public class SapService extends ProfileService {
        }
    }


    private void removeSdpRecord() {
        if (mAdapter != null && mSdpHandle >= 0 &&
                                SdpManager.getDefaultManager() != null) {
            if(VERBOSE) Log.d(TAG, "Removing SDP record handle: " + mSdpHandle);
            boolean status = SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
            mSdpHandle = -1;
        }
    }

    private void startRfcommSocketListener() {
        if (VERBOSE) Log.v(TAG, "Sap Service startRfcommSocketListener");
@@ -148,10 +155,7 @@ public class SapService extends ProfileService {
                //       for multiple connections.
                mServerSocket = mAdapter.listenUsingRfcommOn(
                        BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true, true);
                if (mSdpHandle >= 0) {
                    SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
                    if (VERBOSE) Log.d(TAG, "Removing SDP record");
                }
                removeSdpRecord();
                mSdpHandle = SdpManager.getDefaultManager().createSapsRecord(SDP_SAP_SERVICE_NAME,
                        mServerSocket.getChannel(), SDP_SAP_VERSION);
            } catch (IOException e) {
@@ -656,6 +660,7 @@ public class SapService extends ProfileService {
            mIsWaitingAuthorization = false;
            cancelUserTimeoutAlarm();
        }
        removeSdpRecord();
        mSessionStatusHandler.removeCallbacksAndMessages(null);
        // Request release of all resources
        mSessionStatusHandler.obtainMessage(SHUTDOWN).sendToTarget();