Merge "FTP: Handle FTP registration on SSR."
diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpReceiver.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpReceiver.java
index eb57b4c..f29f957 100644
--- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpReceiver.java
+++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpReceiver.java
@@ -59,6 +59,8 @@
                      * Other than Tranistioning state, start the FTP service whenever
                      * BT transitioned to OFF/ON, or Adapter returns error
                      */
+                   if(V) Log.v(TAG,"BluetoothFtpReceiver  Action: " + intent.getAction()
+                                 + "STATE: "+state);
                     if ((state == BluetoothAdapter.STATE_TURNING_ON)
                         || (state == BluetoothAdapter.STATE_OFF)) {
                         startService = false;
@@ -69,6 +71,8 @@
                  if (adapter == null || !adapter.isEnabled()) {
                     startService = false;
                  }
+                   if(V) Log.v(TAG,"BluetoothFtpReceiver  Action: " + intent.getAction()
+                                 + "startSeervice : "+startService);
             }
 
             if (startService) {
diff --git a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
index 9fe8c63..c5cf81f 100644
--- a/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
+++ b/src/org/codeaurora/bluetooth/ftp/BluetoothFtpService.java
@@ -240,16 +240,16 @@
     public void onCreate() {
         super.onCreate();
         if (VERBOSE) Log.v(TAG, "Ftp Service onCreate");
-        Log.i(TAG, "FFFFFtp Service onCreate");
 
         mAdapter = BluetoothAdapter.getDefaultAdapter();
 
         if (!mHasStarted) {
-            mHasStarted = true;
-            if (VERBOSE) Log.v(TAG, "Starting FTP service");
 
             int state = mAdapter.getState();
+            if (VERBOSE) Log.v(TAG, "FTP service not started Adapter STATE: "+state);
             if (state == BluetoothAdapter.STATE_ON) {
+                if (VERBOSE) Log.v(TAG, "FTP service start listener");
+                mHasStarted = true;
                 mSessionStatusHandler.sendMessage(mSessionStatusHandler
                         .obtainMessage(MSG_INTERNAL_START_LISTENER));
             }
@@ -285,7 +285,7 @@
             Log.e(TAG, "Unexpected error! action is null");
             return;
         }
-        if (VERBOSE) Log.v(TAG, "action: " + action);
+        if (VERBOSE) Log.v(TAG, "PARSE INTENT action: " + action);
 
         int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
         boolean removeTimeoutMsg = true;
@@ -303,7 +303,13 @@
                 }
                 // Release all resources
                 closeService();
-            }
+            } else if (state == BluetoothAdapter.STATE_ON && !mHasStarted ) {
+
+                if (VERBOSE) Log.v(TAG, "FTP service start listener");
+                mHasStarted = true;
+                mSessionStatusHandler.sendMessage(mSessionStatusHandler
+                        .obtainMessage(MSG_INTERNAL_START_LISTENER));
+           }
         } else if (action.equals(ACCESS_ALLOWED_ACTION)) {
             if (!isWaitingAuthorization) {
                 // this reply is not for us