Added more scan record results to JSON RPC server.
Added getDeviceName for advertisement data object.
Added includeDeviceName for advertisement builder object.
Added better debug messages to failed callbacks.
Changed api to accept Long for report delay milliseconds.

Change-Id: I6f8b4d0af488987b79c54b172a18b6329f5052e2
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java
index adbffaa..18f045f 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeAdvertiseFacade.java
@@ -25,6 +25,7 @@
 import android.bluetooth.BluetoothAdapter;
 import android.bluetooth.le.AdvertiseCallback;
 import android.bluetooth.le.AdvertiseData;
+import android.bluetooth.le.ScanCallback;
 import android.bluetooth.le.AdvertiseData.Builder;
 import android.bluetooth.le.AdvertiseSettings;
 import android.bluetooth.le.BluetoothLeAdvertiser;
@@ -434,6 +435,25 @@
     }
 
     /**
+     * Get ble advertisement data include device name
+     *
+     * @param index the advertise data object to use
+     * @return the advertisement data's include device name
+     * @throws Exception
+     */
+    @Rpc(description = "Get ble advertisement include device name")
+    public Boolean getAdvertiseDataIncludeDeviceName(
+            @RpcParameter(name = "index")
+            Integer index) throws Exception {
+        if (mAdvertiseDataList.get(index) != null) {
+            AdvertiseData mData = mAdvertiseDataList.get(index);
+            return mData.getIncludeDeviceName();
+        } else {
+            throw new Exception("Invalid index input:" + Integer.toString(index));
+        }
+    }
+
+    /**
      * Get ble advertisement Service Data
      *
      * @param index the advertise data object to use
@@ -613,10 +633,23 @@
 
         @Override
         public void onStartFailure(int errorCode) {
+            String errorString = "UNKNOWN_ERROR_CODE";
+            if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_ALREADY_STARTED) {
+                errorString = "ADVERTISE_FAILED_ALREADY_STARTED";
+            } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_DATA_TOO_LARGE) {
+                errorString = "ADVERTISE_FAILED_DATA_TOO_LARGE";
+            } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_FEATURE_UNSUPPORTED) {
+                errorString = "ADVERTISE_FAILED_FEATURE_UNSUPPORTED";
+            } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_INTERNAL_ERROR) {
+                errorString = "ADVERTISE_FAILED_INTERNAL_ERROR";
+            } else if (errorCode == AdvertiseCallback.ADVERTISE_FAILED_TOO_MANY_ADVERTISERS) {
+                errorString = "ADVERTISE_FAILED_TOO_MANY_ADVERTISERS";
+            }
             Log.d("bluetooth_le_advertisement onFailure " + mEventType + " "
-                    + index);
+                    + index + " error " + errorString);
             mResults.putString("Type", "onFailure");
             mResults.putInt("ErrorCode", errorCode);
+            mResults.putString("Error", errorString);
             mEventFacade.postEvent(mEventType + index + "onFailure",
                     mResults.clone());
             mResults.clear();
diff --git a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java
index 951b9f3..774c75b 100644
--- a/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/bluetooth/BluetoothLeScanFacade.java
@@ -373,7 +373,7 @@
             @RpcParameter(name = "callbackType")
             Integer callbackType,
             @RpcParameter(name = "reportDelayMillis")
-            Integer reportDelayMillis,
+            Long reportDelayMillis,
             @RpcParameter(name = "scanMode")
             Integer scanMode,
             @RpcParameter(name = "scanResultType")
@@ -838,10 +838,22 @@
 
         @Override
         public void onScanFailed(int errorCode) {
-            Log.d("bluetooth_le_scan change onScanFailed " + mEventType + " " + index);
+            String errorString = "UNKNOWN_ERROR_CODE";
+            if (errorCode == ScanCallback.SCAN_FAILED_ALREADY_STARTED) {
+                errorString = "SCAN_FAILED_ALREADY_STARTED";
+            } else if (errorCode == ScanCallback.SCAN_FAILED_APPLICATION_REGISTRATION_FAILED) {
+                errorString = "SCAN_FAILED_APPLICATION_REGISTRATION_FAILED";
+            } else if (errorCode == ScanCallback.SCAN_FAILED_FEATURE_UNSUPPORTED) {
+                errorString = "SCAN_FAILED_FEATURE_UNSUPPORTED";
+            } else if (errorCode == ScanCallback.SCAN_FAILED_INTERNAL_ERROR) {
+                errorString = "SCAN_FAILED_INTERNAL_ERROR";
+            }
+            Log.d("bluetooth_le_scan change onScanFailed " + mEventType + " " + index + " error "
+                    + errorString);
             mResults.putInt("ID", index);
             mResults.putString("Type", "onScanFailed");
             mResults.putInt("ErrorCode", errorCode);
+            mResults.putString("Error", errorString);
             mEventFacade.postEvent(mEventType + index + "onScanFailed",
                     mResults.clone());
             mResults.clear();
diff --git a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
index dff07fd..fb7f20e 100644
--- a/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
+++ b/Common/src/com/googlecode/android_scripting/jsonrpc/JsonBuilder.java
@@ -319,6 +319,27 @@
         JSONObject result = new JSONObject();
         result.put("rssi", scanResult.getRssi());
         result.put("timestampSeconds", scanResult.getTimestampNanos());
+        result.put("deviceName", scanResult.getScanRecord().getDeviceName());
+        result.put("txPowerLevel", scanResult.getScanRecord().getTxPowerLevel());
+        result.put("advertiseFlags", scanResult.getScanRecord().getAdvertiseFlags());
+        result.put("manufacturerId", scanResult.getScanRecord().getManufacturerId());
+        result.put("manufacturerSpecificData", ConvertUtils.convertByteArrayToString(scanResult
+                .getScanRecord().getManufacturerSpecificData()));
+        result.put("serviceData",
+                ConvertUtils.convertByteArrayToString(scanResult.getScanRecord().getServiceData()));
+        if (scanResult.getScanRecord().getServiceDataUuid() != null) {
+            result.put("serviceData", scanResult.getScanRecord().getServiceDataUuid().toString());
+        } else {
+            result.put("serviceData", scanResult.getScanRecord().getServiceDataUuid());
+        }
+        List<ParcelUuid> serviceUuids = scanResult.getScanRecord().getServiceUuids();
+        String serviceUuidsString = "";
+        if (serviceUuids != null && serviceUuids.size() > 0) {
+            for (ParcelUuid uuid : serviceUuids) {
+                serviceUuidsString = serviceUuidsString + "," + uuid;
+            }
+        }
+        result.put("serviceUuids", serviceUuidsString);
         result.put("scanRecord", build(ConvertUtils.convertByteArrayToString(
                 scanResult.getScanRecord().getBytes())));
         result.put("deviceInfo", build(scanResult.getDevice()));