MAP: Handle ANR caused from socket close and accept thread.

Perform  connection and server socket close  before
AcceptThread shutdown to handle ANR caused from AcceptThread
blocked for socket close.

Change-Id: I65e67ccae5075c723b06e1c163f8a76a92d9d676
CRs-fixed: 535008
diff --git a/src/org/codeaurora/bluetooth/map/BluetoothMasService.java b/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
index 08e518d..cbdbdba 100755
--- a/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
+++ b/src/org/codeaurora/bluetooth/map/BluetoothMasService.java
@@ -801,9 +801,10 @@
         }
 
       private final void closeRfcommSocket(boolean server, boolean accept) throws IOException {
+          if (VERBOSE) Log.v(TAG, "closeRfcommSocket server: "+server + "  conn: " +accept);
           if (server == true) {
             // Stop the possible trying to init serverSocket
-            mInterrupted = false;
+            mInterrupted = true;
 
              if (mServerSocket != null) {
                  mServerSocket.close();
@@ -821,6 +822,11 @@
 
         public void closeConnection() {
             if (VERBOSE) Log.v(TAG, "Mas connection closing");
+            try {
+                closeRfcommSocket(true, true);
+            } catch (IOException ex) {
+                Log.e(TAG, "CloseSocket error: " + ex);
+            }
 
             if (mAcceptThread != null) {
                 try {
@@ -837,11 +843,6 @@
                 mServerSession.close();
                 mServerSession = null;
             }
-            try {
-                closeRfcommSocket(true, true);
-            } catch (IOException ex) {
-                Log.e(TAG, "CloseSocket error: " + ex);
-            }
 
             if (VERBOSE) Log.v(TAG, "Mas connection closed");
         }