// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/exceptions/BluetoothAdapterException.java
// public class BluetoothAdapterException extends Exception {
//     public BluetoothAdapterException() {
//         super();
//     }
// 
//     public BluetoothAdapterException(String detailMessage) {
//         super(detailMessage);
//     }
// 
//     public BluetoothAdapterException(String detailMessage, Throwable throwable) {
//         super(detailMessage, throwable);
//     }
// 
//     public BluetoothAdapterException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/exceptions/DeviceConnectionException.java
// public class DeviceConnectionException extends Exception {
//     public DeviceConnectionException() {
//         super();
//     }
// 
//     public DeviceConnectionException(String detailMessage) {
//         super(detailMessage);
//     }
// 
//     public DeviceConnectionException(String detailMessage, Throwable throwable) {
//         super(detailMessage, throwable);
//     }
// 
//     public DeviceConnectionException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/exceptions/DeviceNotFoundException.java
// public class DeviceNotFoundException extends Exception {
//     public DeviceNotFoundException() {
//         super();
//     }
// 
//     public DeviceNotFoundException(String detailMessage) {
//         super(detailMessage);
//     }
// 
//     public DeviceNotFoundException(String detailMessage, Throwable throwable) {
//         super(detailMessage, throwable);
//     }
// 
//     public DeviceNotFoundException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/connection/service/ConnectionService.java
// public interface ConnectionService {
//     Collection<?> getAllDevices(Context context) throws DeviceConnectionException;
//     Object getDevice(Context context, String deviceName) throws DeviceNotFoundException, DeviceConnectionException;
//     Object getConnection(Context context, Object device) throws DeviceConnectionException;
// }


import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import com.hoho.android.usbserial.driver.UsbSerialDriver;
import uk.gov.nhs.digital.telehealth.exceptions.BluetoothAdapterException;
import uk.gov.nhs.digital.telehealth.exceptions.DeviceConnectionException;
import uk.gov.nhs.digital.telehealth.exceptions.DeviceNotFoundException;
import uk.gov.nhs.digital.telehealth.connection.service.ConnectionService;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
        UsbSerialDriver driver = null;
        List<UsbSerialDriver> availableDrivers = (List<UsbSerialDriver>) getAllDevices(context);
        for (UsbSerialDriver availableDriver : availableDrivers) {
            if(availableDriver.getDevice().getDeviceName().equalsIgnoreCase(deviceName)) {
                driver = availableDriver;
            }
        }
        if(driver == null) {
            throw new DeviceNotFoundException("No device found with name '" + deviceName + "'");
        }
        return driver;
    }

    @Override
    public Object getDevice(Context context, String deviceName) throws DeviceNotFoundException, DeviceConnectionException {
        BluetoothDevice device = null;
        Set<BluetoothDevice> availableDevices = (Set<BluetoothDevice>) getAllDevices(context);
        for (BluetoothDevice availableDevice : availableDevices) {
            if(availableDevice.getName().equalsIgnoreCase(deviceName)) {
                device = availableDevice;
            }
        }
        if(device == null) {
            throw new DeviceNotFoundException("No device found with name '" + deviceName + "'");
        }
        return device;
    }

    @Override
    public Object getConnection(Context context, Object device) throws DeviceConnectionException {
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/exceptions/BluetoothAdapterException.java
// public class BluetoothAdapterException extends Exception {
//     public BluetoothAdapterException() {
//         super();
//     }
// 
//     public BluetoothAdapterException(String detailMessage) {
//         super(detailMessage);
//     }
// 
//     public BluetoothAdapterException(String detailMessage, Throwable throwable) {
//         super(detailMessage, throwable);
//     }
// 
//     public BluetoothAdapterException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/exceptions/DeviceConnectionException.java
// public class DeviceConnectionException extends Exception {
//     public DeviceConnectionException() {
//         super();
//     }
// 
//     public DeviceConnectionException(String detailMessage) {
//         super(detailMessage);
//     }
// 
//     public DeviceConnectionException(String detailMessage, Throwable throwable) {
//         super(detailMessage, throwable);
//     }
// 
//     public DeviceConnectionException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/exceptions/DeviceNotFoundException.java
// public class DeviceNotFoundException extends Exception {
//     public DeviceNotFoundException() {
//         super();
//     }
// 
//     public DeviceNotFoundException(String detailMessage) {
//         super(detailMessage);
//     }
// 
//     public DeviceNotFoundException(String detailMessage, Throwable throwable) {
//         super(detailMessage, throwable);
//     }
// 
//     public DeviceNotFoundException(Throwable throwable) {
//         super(throwable);
//     }
// }
// 
// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/connection/service/ConnectionService.java
// public interface ConnectionService {
//     Collection<?> getAllDevices(Context context) throws DeviceConnectionException;
//     Object getDevice(Context context, String deviceName) throws DeviceNotFoundException, DeviceConnectionException;
//     Object getConnection(Context context, Object device) throws DeviceConnectionException;
// }


// Path: Android/app/src/main/java/uk/gov/nhs/digital/telehealth/connection/service/BluetoothConnectionService.java
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import com.hoho.android.usbserial.driver.UsbSerialDriver;
import uk.gov.nhs.digital.telehealth.exceptions.BluetoothAdapterException;
import uk.gov.nhs.digital.telehealth.exceptions.DeviceConnectionException;
import uk.gov.nhs.digital.telehealth.exceptions.DeviceNotFoundException;
import uk.gov.nhs.digital.telehealth.connection.service.ConnectionService;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;

        UsbSerialDriver driver = null;
        List<UsbSerialDriver> availableDrivers = (List<UsbSerialDriver>) getAllDevices(context);
        for (UsbSerialDriver availableDriver : availableDrivers) {
            if(availableDriver.getDevice().getDeviceName().equalsIgnoreCase(deviceName)) {
                driver = availableDriver;
            }
        }
        if(driver == null) {
            throw new DeviceNotFoundException("No device found with name '" + deviceName + "'");
        }
        return driver;
    }

    @Override
    public Object getDevice(Context context, String deviceName) throws DeviceNotFoundException, DeviceConnectionException {
        BluetoothDevice device = null;
        Set<BluetoothDevice> availableDevices = (Set<BluetoothDevice>) getAllDevices(context);
        for (BluetoothDevice availableDevice : availableDevices) {
            if(availableDevice.getName().equalsIgnoreCase(deviceName)) {
                device = availableDevice;
            }
        }
        if(device == null) {
            throw new DeviceNotFoundException("No device found with name '" + deviceName + "'");
        }
        return device;
    }

    @Override
    public Object getConnection(Context context, Object device) throws DeviceConnectionException {
        BluetoothSocket bluetoothSocket = null;