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

Commit 45c43e8e authored by Zhihai Xu's avatar Zhihai Xu
Browse files

MAP: fix problem with MNS not disconnecting correctly

MNS is needed to disconnect with the MSE but did not.
This patch fixes that by re-adding a disconnect() that was wrongfully removed during review.
Patch set 2:
-----------
 - Split disconnect and shutdown for MNS connection
bug: 11161674
Change-Id: Idd09fc774584dfdb171b0d00be0f7711ae57b853
parent b71626a9
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -263,7 +263,7 @@ public class BluetoothMapService extends ProfileService {
        }
        }


        if (mBluetoothMnsObexClient != null) {
        if (mBluetoothMnsObexClient != null) {
            mBluetoothMnsObexClient.disconnect();
            mBluetoothMnsObexClient.shutdown();
            mBluetoothMnsObexClient = null;
            mBluetoothMnsObexClient = null;
        }
        }


@@ -324,7 +324,7 @@ public class BluetoothMapService extends ProfileService {
        mAcceptThread = null;
        mAcceptThread = null;


        if(mBluetoothMnsObexClient != null) {
        if(mBluetoothMnsObexClient != null) {
            mBluetoothMnsObexClient.disconnect();
            mBluetoothMnsObexClient.shutdown();
            mBluetoothMnsObexClient = null;
            mBluetoothMnsObexClient = null;
        }
        }
        closeConnectionSocket();
        closeConnectionSocket();
@@ -515,7 +515,7 @@ public class BluetoothMapService extends ProfileService {
                        mServerSession = null;
                        mServerSession = null;
                    }
                    }
                    if(mBluetoothMnsObexClient != null) {
                    if(mBluetoothMnsObexClient != null) {
                        mBluetoothMnsObexClient.disconnect(); //FIXME should use shutdown when implemented
                        mBluetoothMnsObexClient.shutdown();
                        mBluetoothMnsObexClient = null;
                        mBluetoothMnsObexClient = null;
                    }
                    }
                    closeConnectionSocket();
                    closeConnectionSocket();
+27 −12
Original line number Original line Diff line number Diff line
@@ -112,19 +112,11 @@ public class BluetoothMnsObexClient {
        return mConnected;
        return mConnected;
    }
    }


    public void disconnect() {
    /**
        /* should shutdown handler thread first to make sure
     * Disconnect the connection to MNS server.
         * handleRegistration won't be called when disconnet
     * Call this when the MAS client requests a de-registration on events.
     */
     */
        if (mHandler != null) {
    public void disconnect() {
            // Shut down the thread
            mHandler.removeCallbacksAndMessages(null);
            Looper looper = mHandler.getLooper();
            if (looper != null) {
                looper.quit();
            }
            mHandler = null;
        }
        try {
        try {
            if (mClientSession != null) {
            if (mClientSession != null) {
                mClientSession.disconnect(null);
                mClientSession.disconnect(null);
@@ -154,6 +146,28 @@ public class BluetoothMnsObexClient {
                Log.e(TAG, "mTransport.close error: " + e.getMessage());
                Log.e(TAG, "mTransport.close error: " + e.getMessage());
            }
            }
        }
        }
    }

    /**
     * Shutdown the MNS.
     */
    public void shutdown() {
        /* should shutdown handler thread first to make sure
         * handleRegistration won't be called when disconnet
         */
        if (mHandler != null) {
            // Shut down the thread
            mHandler.removeCallbacksAndMessages(null);
            Looper looper = mHandler.getLooper();
            if (looper != null) {
                looper.quit();
            }
            mHandler = null;
        }

        /* Disconnect if connected */
        disconnect();

        if(mObserverRegistered) {
        if(mObserverRegistered) {
            mObserver.unregisterObserver();
            mObserver.unregisterObserver();
            mObserverRegistered = false;
            mObserverRegistered = false;
@@ -180,6 +194,7 @@ public class BluetoothMnsObexClient {
            if(mObserverRegistered == true) {
            if(mObserverRegistered == true) {
                mObserver.unregisterObserver();
                mObserver.unregisterObserver();
                mObserverRegistered = false;
                mObserverRegistered = false;
                disconnect();
            }
            }
        } else if(notificationStatus == BluetoothMapAppParams.NOTIFICATION_STATUS_YES) {
        } else if(notificationStatus == BluetoothMapAppParams.NOTIFICATION_STATUS_YES) {
            /* Connect if we do not have a connection, and start the content observers providing
            /* Connect if we do not have a connection, and start the content observers providing