// Path: IOIO/iOIOLibAndroid/src/main/java/ioio/lib/api/IOIOConnection.java
// public interface IOIOConnection {
//     void waitForConnect() throws ConnectionLostException;
// 
//     void disconnect();
// 
//     InputStream getInputStream() throws ConnectionLostException;
// 
//     OutputStream getOutputStream() throws ConnectionLostException;
// 
//     /**
//      * Can this connection be closed. Normally the answer would be "true", but
//      * some weird connections cannot be closed and need the higher layer to do
//      * a "soft close" instead.
//      *
//      * @return true This connection can be closed.
//      */
//     boolean canClose();
// }
// 
// Path: IOIO/iOIOLibAndroid/src/main/java/ioio/lib/spi/IOIOConnectionBootstrap.java
// public interface IOIOConnectionBootstrap {
//     public void getFactories(Collection<IOIOConnectionFactory> result);
// }
// 
// Path: IOIO/iOIOLibAndroid/src/main/java/ioio/lib/spi/IOIOConnectionFactory.java
// public interface IOIOConnectionFactory {
//     /**
//      * A unique name of the connection type. Typically a fully-qualified
//      * name of the connection class.
//      */
//     public String getType();
// 
//     /**
//      * Extra information on the connection. This is specific to the
//      * connection type. For example, for a Bluetooth connection, this is an
//      * array containing the name and the Bluetooth address of the remote
//      * IOIO.
//      */
//     public Object getExtra();
// 
//     public IOIOConnection createConnection();
// }


import android.util.Log;
import java.util.Collection;
import java.util.Set;
import ioio.lib.api.IOIOConnection;
import ioio.lib.spi.IOIOConnectionBootstrap;
import ioio.lib.spi.IOIOConnectionFactory;
import ioio.lib.spi.NoRuntimeSupportException;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
            adapter_ = BluetoothAdapter.getDefaultAdapter();
            if (adapter_ != null) {
                return;
            }
        } catch (Throwable e) {
        }
        throw new NoRuntimeSupportException(
                "Bluetooth is not supported on this device.");
    }

    @Override
    public void getFactories(Collection<IOIOConnectionFactory> result) {
        try {
            Set<BluetoothDevice> bondedDevices = adapter_.getBondedDevices();
            for (final BluetoothDevice device : bondedDevices) {
                if (device.getName().startsWith("IOIO")) {
                    result.add(new IOIOConnectionFactory() {
                        @Override
                        public String getType() {
                            return BluetoothIOIOConnection.class
                                    .getCanonicalName();
                        }

                        @Override
                        public Object getExtra() {
                            return new Object[]{device.getName(),
                                    device.getAddress()};
                        }

                        @Override
// Path: IOIO/iOIOLibAndroid/src/main/java/ioio/lib/api/IOIOConnection.java
// public interface IOIOConnection {
//     void waitForConnect() throws ConnectionLostException;
// 
//     void disconnect();
// 
//     InputStream getInputStream() throws ConnectionLostException;
// 
//     OutputStream getOutputStream() throws ConnectionLostException;
// 
//     /**
//      * Can this connection be closed. Normally the answer would be "true", but
//      * some weird connections cannot be closed and need the higher layer to do
//      * a "soft close" instead.
//      *
//      * @return true This connection can be closed.
//      */
//     boolean canClose();
// }
// 
// Path: IOIO/iOIOLibAndroid/src/main/java/ioio/lib/spi/IOIOConnectionBootstrap.java
// public interface IOIOConnectionBootstrap {
//     public void getFactories(Collection<IOIOConnectionFactory> result);
// }
// 
// Path: IOIO/iOIOLibAndroid/src/main/java/ioio/lib/spi/IOIOConnectionFactory.java
// public interface IOIOConnectionFactory {
//     /**
//      * A unique name of the connection type. Typically a fully-qualified
//      * name of the connection class.
//      */
//     public String getType();
// 
//     /**
//      * Extra information on the connection. This is specific to the
//      * connection type. For example, for a Bluetooth connection, this is an
//      * array containing the name and the Bluetooth address of the remote
//      * IOIO.
//      */
//     public Object getExtra();
// 
//     public IOIOConnection createConnection();
// }


// Path: IOIO/iOIOLibBT/src/main/java/ioio/lib/android/bluetooth/BluetoothIOIOConnectionBootstrap.java
import android.util.Log;
import java.util.Collection;
import java.util.Set;
import ioio.lib.api.IOIOConnection;
import ioio.lib.spi.IOIOConnectionBootstrap;
import ioio.lib.spi.IOIOConnectionFactory;
import ioio.lib.spi.NoRuntimeSupportException;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;

            adapter_ = BluetoothAdapter.getDefaultAdapter();
            if (adapter_ != null) {
                return;
            }
        } catch (Throwable e) {
        }
        throw new NoRuntimeSupportException(
                "Bluetooth is not supported on this device.");
    }

    @Override
    public void getFactories(Collection<IOIOConnectionFactory> result) {
        try {
            Set<BluetoothDevice> bondedDevices = adapter_.getBondedDevices();
            for (final BluetoothDevice device : bondedDevices) {
                if (device.getName().startsWith("IOIO")) {
                    result.add(new IOIOConnectionFactory() {
                        @Override
                        public String getType() {
                            return BluetoothIOIOConnection.class
                                    .getCanonicalName();
                        }

                        @Override
                        public Object getExtra() {
                            return new Object[]{device.getName(),
                                    device.getAddress()};
                        }

                        @Override
                        public IOIOConnection createConnection() {