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

Commit bc091da3 authored by Jack He's avatar Jack He Committed by Myles Watson
Browse files

MAP-MNS: Cleanup sdp record on service shutdown

* Obtain, check and save SdpManager instance
* Save SdpHandle and remove SDP record on stop()

Bug: 67753878
Test: build
Change-Id: I21f45c553ee1ff3fdf4bde71d4dcc1c0c62c3871
(cherry picked from commit 780f9cea48424646af1c5f9b3a53cabbe8e57d6c)
Merged-In: I21f45c553ee1ff3fdf4bde71d4dcc1c0c62c3871
parent 0069fef3
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -50,26 +50,49 @@ class MnsService {

    static private MapClientService mContext;
    private volatile boolean mShutdown = false;         // Used to interrupt socket accept thread
    private int mSdpHandle = -1;

    MnsService(MapClientService context) {
        if (VDBG) Log.v(TAG, "MnsService()");
        mContext = context;
        mAcceptThread = new SocketAcceptor();
        mServerSockets = ObexServerSockets.create(mAcceptThread);
        SdpManager.getDefaultManager().createMapMnsRecord(
                "MAP Message Notification Service", mServerSockets.getRfcommChannel(), -1,
                MNS_VERSION, MNS_FEATURE_BITS);
        SdpManager sdpManager = SdpManager.getDefaultManager();
        if (sdpManager == null) {
            Log.e(TAG, "SdpManager is null");
            return;
        }
        mSdpHandle = sdpManager.createMapMnsRecord("MAP Message Notification Service",
                mServerSockets.getRfcommChannel(), -1, MNS_VERSION, MNS_FEATURE_BITS);
    }

    void stop() {
        if (VDBG) Log.v(TAG, "stop()");
        mShutdown = true;
        cleanUpSdpRecord();
        if (mServerSockets != null) {
            mServerSockets.shutdown(false);
            mServerSockets = null;
        }
    }

    private void cleanUpSdpRecord() {
        if (mSdpHandle < 0) {
            Log.e(TAG, "cleanUpSdpRecord, SDP record never created");
            return;
        }
        int sdpHandle = mSdpHandle;
        mSdpHandle = -1;
        SdpManager sdpManager = SdpManager.getDefaultManager();
        if (sdpManager == null) {
            Log.e(TAG, "cleanUpSdpRecord failed, sdpManager is null, sdpHandle=" + sdpHandle);
            return;
        }
        Log.i(TAG, "cleanUpSdpRecord, mSdpHandle=" + sdpHandle);
        if (!sdpManager.removeSdpRecord(sdpHandle)) {
            Log.e(TAG, "cleanUpSdpRecord, removeSdpRecord failed, sdpHandle=" + sdpHandle);
        }
    }

    private class SocketAcceptor implements IObexConnectionHandler {