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

Commit 8063fd5e authored by Ashwini Munigala's avatar Ashwini Munigala Committed by Linux Build Service Account
Browse files

MAP: Fix following for MapService shutdown:

- Mark MAPService state to stopped while
closeService is ongoing. This will avoid
extra shutdown message in stop() and
fix a relevant NPE.
- Donot block for AcceptThread(s) cleanup
during shutdown. Fix the handler thread blocking
to handle BT TURN OFF timeout exception.
- Avoid setState for MAPProfile everytime and
set state changed only if not already done.

Change-Id: I065a13193200d3aa358abe5d82f1343244b05b97
parent 765cbf19
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -239,7 +239,9 @@ public class ObexServerSockets {
     * Signal to the {@link IObexConnectionHandler} that an error have occurred.
     * Signal to the {@link IObexConnectionHandler} that an error have occurred.
     */
     */
    synchronized private void onAcceptFailed() {
    synchronized private void onAcceptFailed() {
        shutdown(true);
        //Donot block for Accept thread cleanup.
        //Fix Handler Thread block during BT Turn OFF.
        shutdown(false);
        BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
        if((mAdapter != null) && (mAdapter.getState() == BluetoothAdapter.STATE_ON)) {
        if((mAdapter != null) && (mAdapter.getState() == BluetoothAdapter.STATE_ON)) {
            Log.d(TAG,"onAcceptFailed() calling shutdown...");
            Log.d(TAG,"onAcceptFailed() calling shutdown...");
+3 −2
Original line number Original line Diff line number Diff line
@@ -419,8 +419,9 @@ public class BluetoothMapMasInstance implements IObexConnectionHandler {
        removeSdpRecord();
        removeSdpRecord();


        closeConnectionSocket();
        closeConnectionSocket();

        //Donot block for Accept thread cleanup.
        closeServerSockets(true);
        //Fix Handler Thread block during BT Turn OFF.
        closeServerSockets(false);
    }
    }


    /**
    /**
+44 −8
Original line number Original line Diff line number Diff line
@@ -152,6 +152,7 @@ public class BluetoothMapService extends ProfileService {
    private boolean mSdpSearchInitiated = false;
    private boolean mSdpSearchInitiated = false;
    SdpMnsRecord mMnsRecord = null;
    SdpMnsRecord mMnsRecord = null;
    private MapServiceMessageHandler mSessionStatusHandler;
    private MapServiceMessageHandler mSessionStatusHandler;
    /**Indicate MAPService internal state: started or stopped*/
    private boolean mStartError = true;
    private boolean mStartError = true;


    private boolean mSmsCapable = true;
    private boolean mSmsCapable = true;
@@ -174,7 +175,8 @@ public class BluetoothMapService extends ProfileService {


    private synchronized void closeService() {
    private synchronized void closeService() {
        if (DEBUG) Log.d(TAG, "MAP Service closeService in");
        if (DEBUG) Log.d(TAG, "MAP Service closeService in");

        // Mark MapService stop while shutdown ongoing.
        mStartError = true;
        if (mBluetoothMnsObexClient != null) {
        if (mBluetoothMnsObexClient != null) {
            mBluetoothMnsObexClient.shutdown();
            mBluetoothMnsObexClient.shutdown();
            mBluetoothMnsObexClient = null;
            mBluetoothMnsObexClient = null;
@@ -188,8 +190,11 @@ public class BluetoothMapService extends ProfileService {


        mIsWaitingAuthorization = false;
        mIsWaitingAuthorization = false;
        mPermission = BluetoothDevice.ACCESS_UNKNOWN;
        mPermission = BluetoothDevice.ACCESS_UNKNOWN;
        // TODO: setState Intent ignored while BT Turning off.
        // This as no significance as of now as CloseService is invoked during BT TURN OFF.
        if (getState() != BluetoothMap.STATE_DISCONNECTED) {
            setState(BluetoothMap.STATE_DISCONNECTED);
            setState(BluetoothMap.STATE_DISCONNECTED);

        }
        if (mWakeLock != null) {
        if (mWakeLock != null) {
            mWakeLock.release();
            mWakeLock.release();
            if (VERBOSE) Log.v(TAG, "CloseService(): Release Wake Lock");
            if (VERBOSE) Log.v(TAG, "CloseService(): Release Wake Lock");
@@ -847,25 +852,46 @@ public class BluetoothMapService extends ProfileService {
        //Stop MapProfile if already started.
        //Stop MapProfile if already started.
        //TODO: Check if the profile state can be retreived from ProfileService or AdapterService.
        //TODO: Check if the profile state can be retreived from ProfileService or AdapterService.
        if (!isMapStarted()) {
        if (!isMapStarted()) {
            if (DEBUG) Log.d(TAG, "Service Not Available to STOP, ignoring");
            if (DEBUG) Log.d(TAG, "Service Not Available to STOP or Shutdown already" +
                " in progress - Ignoring");
            return true;
            return true;
        } else {
        } else {
            if (VERBOSE) Log.d(TAG, "Service Stoping()");
            if (VERBOSE) Log.d(TAG, "Service Stoping()");
        }
        }
        // setState Disconnect already handled from closeService.
        // Handle it otherwise - Redundant for backup?
        if (getState() != BluetoothMap.STATE_DISCONNECTED) {
            setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
        }
        if (mSessionStatusHandler != null) {
        if (mSessionStatusHandler != null) {
            sendShutdownMessage();
            sendShutdownMessage();
        }
        }
        mStartError = true;
        mStartError = true;
        setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
        return true;
        return true;
    }
    }


    public boolean cleanup()  {
    public boolean cleanup()  {
        if (DEBUG) Log.d(TAG, "cleanup()");
        if (DEBUG) Log.d(TAG, "cleanup()");
        //Stop MapProfile if already started.
        //TODO: Check if the profile state can be retreived from ProfileService or AdapterService.
        if (!isMapStarted()) {
            if (DEBUG) Log.d(TAG, "Service Not Available to STOP or Shutdown already" +
                " in progress - Ignoring");
            return true;
        } else {
            if (VERBOSE) Log.d(TAG, "Service Stoping()");
        }
        // SetState Disconnect already handled from closeService.
        // Handle it otherwise. Redundant for backup ?
        if (getState() != BluetoothMap.STATE_DISCONNECTED) {
            setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
            setState(BluetoothMap.STATE_DISCONNECTED, BluetoothMap.RESULT_CANCELED);
        }
        //Cleanup already handled in Stop().
        //Cleanup already handled in Stop().
        //Move this  extra check to Handler.
        //Move this  extra check to Handler.
        if (mSessionStatusHandler != null) {
            sendShutdownMessage();
            sendShutdownMessage();
        }
        mStartError = true;
        return true;
        return true;
    }
    }


@@ -1057,7 +1083,17 @@ public class BluetoothMapService extends ProfileService {
                                               BluetoothAdapter.ERROR);
                                               BluetoothAdapter.ERROR);
                if (state == BluetoothAdapter.STATE_TURNING_OFF) {
                if (state == BluetoothAdapter.STATE_TURNING_OFF) {
                    if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF");
                    if (DEBUG) Log.d(TAG, "STATE_TURNING_OFF");
                    //Stop MapProfile if already started.
                   if (!isMapStarted()) {
                       if (DEBUG) Log.d(TAG, "Service Not Available to STOP or Shutdown already" +
                           " in progress - Ignoring");
                   } else if (mSessionStatusHandler != null) {
                       if (VERBOSE) Log.d(TAG, "Service Stoping()");
                       sendShutdownMessage();
                       sendShutdownMessage();
                   } else {
                       if (DEBUG) Log.d(TAG, "Unable to perform STOP or Shutdown already" +
                           " in progress - Ignoring");
                   }
                } else if (state == BluetoothAdapter.STATE_ON) {
                } else if (state == BluetoothAdapter.STATE_ON) {
                    if (DEBUG) Log.d(TAG, "STATE_ON");
                    if (DEBUG) Log.d(TAG, "STATE_ON");
                    // start ServerSocket listener threads
                    // start ServerSocket listener threads