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

Commit a8746d3f authored by Hemant Gupta's avatar Hemant Gupta Committed by Roman Birg
Browse files

BT: Fix following issues in data profiles

 - Add handling to remove sdp record from SAP and OPP
   profiles when BT is turning off, so that the enteries can be
   removed from stack's security database.

 - CleanUp for unnecssary server socket references from OppService.

 - Add NULL checks in OPP code.

Change-Id: I2a596dcc9a0f0731e80175a26bcf294a5e9e6f0e
CRs-Fixed: 968880
parent b521323f
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -54,7 +54,10 @@ public class OolConnManager {

    public static void setSdpInitiatedAddress(BluetoothDevice remBtDev) {

        if (remBtDev != null)
            mAddress = remBtDev.getAddress();
        else
            mAddress = null;
        Log.d(TAG,"setSdpInitiatedAddress "+ mAddress);

    }
@@ -63,9 +66,9 @@ public class OolConnManager {

        int waitCount = 0;
        int channelNo = -1;
        while(!sdpDone && waitCount < 20) {
        while(!sdpDone && waitCount < 100) {
           try {
               Thread.sleep(500);
               Thread.sleep(100);
           } catch (InterruptedException e) {
               Log.e(TAG, "Interrupted", e);
           }
+6 −4
Original line number Diff line number Diff line
@@ -277,10 +277,11 @@ public class BluetoothMapMasInstance implements IObexConnectionHandler {
                Log.e(TAG, "Failed to start the listeners");
                return;
            }
            if(mSdpHandle >= 0) {
                SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
            if (mSdpHandle >= 0 && SdpManager.getDefaultManager() != null) {
                if(V) Log.d(TAG, "Removing SDP record for MAS instance: " + mMasInstanceId +
                    " Object reference: " + this + "SDP handle: " + mSdpHandle);
                SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
                mSdpHandle = -1;
            }
            mSdpHandle = createMasSdpRecord(mServerSockets.getRfcommChannel(),
                    mServerSockets.getL2capPsm());
@@ -407,10 +408,11 @@ public class BluetoothMapMasInstance implements IObexConnectionHandler {
            mObserver.deinit();
            mObserver = null;
        }
        if (mSdpHandle >= 0) {
            SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
        if (mSdpHandle >= 0 && SdpManager.getDefaultManager() != null) {
            if(V) Log.d(TAG, "Removing SDP record for MAS instance: " + mMasInstanceId +
                " Object reference: " + this + "SDP handle: " + mSdpHandle);
            SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
            mSdpHandle = -1;
        }

        closeConnectionSocket();
+5 −5
Original line number Diff line number Diff line
@@ -115,9 +115,6 @@ public class BluetoothOppL2capListener {
                        while (!mInterrupted) {
                            try {
                                if (V) Log.v(TAG, "Accepting connection...");
                                if (mBtServerSocket == null) {

                                }
                                BluetoothServerSocket sSocket = mBtServerSocket;
                                if (sSocket ==null) {
                                    mInterrupted = true;
@@ -192,10 +189,13 @@ public class BluetoothOppL2capListener {
        }
    }

    public int getL2capChannel() {
            Log.d(TAG,"L2C channel is " +mBtServerSocket.getChannel());
    public int getL2capPsm() {
        if (mBtServerSocket != null) {
            Log.d(TAG, "L2CAP psm is " + mBtServerSocket.getChannel());
            return mBtServerSocket.getChannel();
        }
        return -1;
    }

    public BluetoothServerSocket openL2capSocket(){

+19 −24
Original line number Diff line number Diff line
@@ -139,8 +139,6 @@ public class BluetoothOppService extends Service {
    private int mIncomingRetries = 0;

    private ObexTransport mPendingConnection = null;
    private BluetoothServerSocket mBtRfcServerSocket = null;
    private BluetoothServerSocket mBtL2cServerSocket = null;
    private int mOppSdpHandle = -1;

    /*
@@ -237,6 +235,12 @@ public class BluetoothOppService extends Service {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case STOP_LISTENER:
                    if (mOppSdpHandle >= 0 &&
                        SdpManager.getDefaultManager() != null) {
                        if (D) Log.d(TAG, "Removing SDP record");
                        SdpManager.getDefaultManager().removeSdpRecord(mOppSdpHandle);
                        mOppSdpHandle = -1;
                    }
                    if(mSocketListener != null){
                        mSocketListener.stop();
                    }
@@ -357,30 +361,21 @@ public class BluetoothOppService extends Service {
    private void startSocketListener() {

       if (V) Log.v(TAG, "start Socket Listeners");
       if (mSocketListener != null ) {
           mBtRfcServerSocket = mSocketListener.openRfcommSocket();
       }

       if (mL2cSocketListener != null) {
           mBtL2cServerSocket = mL2cSocketListener.openL2capSocket();
       }
       if (mSocketListener != null && mL2cSocketListener != null) {

       if (mBtRfcServerSocket != null && mBtL2cServerSocket != null) {
           mOppSdpHandle = SdpManager.getDefaultManager().createOppOpsRecord("OBEX Object Push",
              mBtRfcServerSocket.getChannel(), mBtL2cServerSocket.getChannel(),
                 0x0102, SdpManager.OPP_FORMAT_ALL);
           if ( ( mSocketListener.openRfcommSocket() != null) &&
                ( mL2cSocketListener.openL2capSocket() != null) &&
                SdpManager.getDefaultManager() != null) {
               mOppSdpHandle = SdpManager.getDefaultManager()
                   .createOppOpsRecord("OBEX Object Push", mSocketListener.getRfcommChannel(),
                        mL2cSocketListener.getL2capPsm(), 0x0102, SdpManager.OPP_FORMAT_ALL);
              mSocketListener.start(mHandler);
              mL2cSocketListener.start(mHandler);
           } else {
               Log.e(TAG, "ERROR:serversocket object is NULL");
           }

       if (mSocketListener != null) {
          mSocketListener.start(mHandler);
       }

       if (mL2cSocketListener != null) {
          mL2cSocketListener.start(mHandler);
       }

    }

    @Override
+8 −2
Original line number Diff line number Diff line
@@ -153,9 +153,10 @@ 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 (mSdpHandle >= 0 && SdpManager.getDefaultManager() != null) {
                    if (DEBUG) Log.d(TAG, "Removing SDP record");
                    SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
                    mSdpHandle = -1;
                }
                mSdpHandle = SdpManager.getDefaultManager().createSapsRecord(SDP_SAP_SERVICE_NAME,
                        mServerSocket.getChannel(), SDP_SAP_VERSION);
@@ -732,6 +733,11 @@ public class SapService extends ProfileService {
            mIsWaitingAuthorization = false;
            cancelUserTimeoutAlarm();
        }
        if (mSdpHandle >= 0 && SdpManager.getDefaultManager() != null) {
            if (DEBUG) Log.d(TAG, "Removing SDP record");
            SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle);
            mSdpHandle = -1;
        }
        if (mSessionStatusHandler != null) {
            mSessionStatusHandler.removeCallbacksAndMessages(null);
            // Request release of all resources