// Path: DeviceService/src/com/ratio/exceptions/DeviceManagerException.java
// public class DeviceManagerException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceManagerException(String s) {
// 		super(s);
// 	}
// 	public DeviceManagerException(String error, String errorValue) {
//     	super(String.format("%s %s", error, errorValue));
// 	}
// }
// 
// Path: DeviceService/src/com/ratio/exceptions/DeviceNameNotFoundException.java
// public class DeviceNameNotFoundException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceNameNotFoundException(String s) {
// 		super(s);
// 	}
// }


import java.util.ArrayList;
import java.util.UUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;
import com.ratio.deviceService.IDeviceCommand;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
		broadcastIntent.putExtra(EXTRA_RSSI, rssi);
		broadcastIntent.putExtra(EXTRA_STATUS, status);
		sendBroadcast(broadcastIntent);	
	}
	
	// broadcast an error message.
	public void onError(int errorCode, String error, String deviceAddress) {
		broadcastError(errorCode, error, deviceAddress);
	}
    
    protected void broadcastError(int errorCode, final String error, String deviceAddress) {
    	final Intent intent = new Intent(ACTION_ERROR);
    	intent.putExtra(EXTRA_ERROR_MESSAGE, error);
    	intent.putExtra(EXTRA_ERROR_CODE, errorCode);
    	intent.putExtra(EXTRA_DEVICE_ADDRESS, deviceAddress);
    	sendBroadcast(intent);
    }

    // implementation of the AIDL interface.  Pretty much just a pass-through to the BTLDeviceManager.
    public class DeviceCommandImpl extends IDeviceCommand.Stub {

		@Override
		public void scanDevices(String[] advertisedServiceUUIDList, int periodMsec) throws RemoteException {
			// broadcast to the receiver responsible for resetting the adapter that we have initiated disabling
			// the bluetooth adapter.
			Intent broadcastIntent = new Intent(RESET_ADAPTER);
			sendBroadcast(broadcastIntent);
			DeviceService.mPeriodMsec = periodMsec;
			if (advertisedServiceUUIDList != null) {
				DeviceService.mAdvertisedServices = new UUID[advertisedServiceUUIDList.length];
// Path: DeviceService/src/com/ratio/exceptions/DeviceManagerException.java
// public class DeviceManagerException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceManagerException(String s) {
// 		super(s);
// 	}
// 	public DeviceManagerException(String error, String errorValue) {
//     	super(String.format("%s %s", error, errorValue));
// 	}
// }
// 
// Path: DeviceService/src/com/ratio/exceptions/DeviceNameNotFoundException.java
// public class DeviceNameNotFoundException extends Exception { 
// 	static final long serialVersionUID = 0;
// 	
// 	public DeviceNameNotFoundException(String s) {
// 		super(s);
// 	}
// }


// Path: DeviceService/src/com/ratio/deviceService/DeviceService.java
import java.util.ArrayList;
import java.util.UUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;
import com.ratio.deviceService.IDeviceCommand;
import android.app.Service;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

		broadcastIntent.putExtra(EXTRA_RSSI, rssi);
		broadcastIntent.putExtra(EXTRA_STATUS, status);
		sendBroadcast(broadcastIntent);	
	}
	
	// broadcast an error message.
	public void onError(int errorCode, String error, String deviceAddress) {
		broadcastError(errorCode, error, deviceAddress);
	}
    
    protected void broadcastError(int errorCode, final String error, String deviceAddress) {
    	final Intent intent = new Intent(ACTION_ERROR);
    	intent.putExtra(EXTRA_ERROR_MESSAGE, error);
    	intent.putExtra(EXTRA_ERROR_CODE, errorCode);
    	intent.putExtra(EXTRA_DEVICE_ADDRESS, deviceAddress);
    	sendBroadcast(intent);
    }

    // implementation of the AIDL interface.  Pretty much just a pass-through to the BTLDeviceManager.
    public class DeviceCommandImpl extends IDeviceCommand.Stub {

		@Override
		public void scanDevices(String[] advertisedServiceUUIDList, int periodMsec) throws RemoteException {
			// broadcast to the receiver responsible for resetting the adapter that we have initiated disabling
			// the bluetooth adapter.
			Intent broadcastIntent = new Intent(RESET_ADAPTER);
			sendBroadcast(broadcastIntent);
			DeviceService.mPeriodMsec = periodMsec;
			if (advertisedServiceUUIDList != null) {
				DeviceService.mAdvertisedServices = new UUID[advertisedServiceUUIDList.length];
				for (int i = 0; i < advertisedServiceUUIDList.length; i++) {