SAP: Handle ACL_DISCONNECT from the client

This change will handle ACL_DISCONNECT coming
from the client and authorization is not pending anymore.

Change-Id: I92de8edcb5c34a1d2cbf3c2b2e4c5510216f3082
CRs-Fixed: 589990
diff --git a/src/org/codeaurora/bluetooth/sap/BluetoothSapService.java b/src/org/codeaurora/bluetooth/sap/BluetoothSapService.java
index d96e8e3..10dfd88 100644
--- a/src/org/codeaurora/bluetooth/sap/BluetoothSapService.java
+++ b/src/org/codeaurora/bluetooth/sap/BluetoothSapService.java
@@ -450,18 +450,22 @@
             } else {
                 removeTimeoutMsg = false;
             }
-        } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED) &&
-                                 mIsWaitingAuthorization) {
+        } else if (action.equals(BluetoothDevice.ACTION_ACL_DISCONNECTED)) {
             if (mRemoteDevice == null) {
-               Log.e(TAG, "Unexpected error!");
-               return;
+                Log.e(TAG, "Unexpected error!");
+                return;
             }
             if (mSapHandler != null) {
-               /* Let the user timeout handle this case as well */
-               mSapHandler.sendMessage(mSapHandler.obtainMessage(MESSAGE_SAP_USER_TIMEOUT));
-               removeTimeoutMsg = false;
+                /* Let the user timeout handle this case as well */
+                if (mIsWaitingAuthorization) {
+                    mSapHandler.sendMessage(mSapHandler.obtainMessage(MESSAGE_SAP_USER_TIMEOUT));
+                    removeTimeoutMsg = false;
+                } else {
+                    mSapHandler.sendMessage(mSapHandler.obtainMessage(SAP_CRTL_MSG_DISCONNECT_REQ));
+                    closeRfcommSocket();
+                    startRfcommListenerThread();
+                }
             }
-
         }  else if (action.equals(SAP_ACCESS_ALLOWED_ACTION)) {
             if (mRemoteDevice == null) {
                Log.e(TAG, "Unexpected error!");