MAP Client Only connect MNS in connected state

Only allow the MNS to connect when the MAS client is in the connected
state, this prevents the possibility of the MNS client from connecting
if the MAS fails to connect.

Bug: 135088863
Test: disallow MAS connection and verify MNS notifications don't arrive.
Change-Id: I75de88e74708283ebbaef70251f7575c0da0c4d4
(cherry picked from commit ac9715de616a2e8de421d72dbb2fd1ef6a55842c)

Merged-In: I75de88e74708283ebbaef70251f7575c0da0c4d4
Change-Id: I3103c679d37a0664da4f6e777d9d5f42af257f51
diff --git a/src/com/android/bluetooth/mapclient/MnsService.java b/src/com/android/bluetooth/mapclient/MnsService.java
index c1ab39e..b3317df 100644
--- a/src/com/android/bluetooth/mapclient/MnsService.java
+++ b/src/com/android/bluetooth/mapclient/MnsService.java
@@ -17,6 +17,7 @@
 package com.android.bluetooth.mapclient;
 
 import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothProfile;
 import android.bluetooth.BluetoothServerSocket;
 import android.bluetooth.BluetoothSocket;
 import android.os.Handler;
@@ -129,6 +130,11 @@
                 Log.e(TAG, "Error: NO statemachine for device: " + device.getAddress()
                         + " (name: " + device.getName());
                 return false;
+            } else if (stateMachine.getState() != BluetoothProfile.STATE_CONNECTED) {
+                Log.e(TAG, "Error: statemachine for device: " + device.getAddress()
+                        + " (name: " + device.getName() + ") is not currently CONNECTED : "
+                        + stateMachine.getCurrentState());
+                return false;
             }
             MnsObexServer srv = new MnsObexServer(stateMachine, sServerSockets);
             BluetoothObexTransport transport = new BluetoothObexTransport(socket);