Prevent crash in Gatt service due to null pointer in
BluetoothGattCharacteristic from framework

Bug 16899517

Change-Id: Ib30ddefee07c2953f9a7faeb4eaa823feeebdc8f
diff --git a/core/java/android/bluetooth/BluetoothGattServer.java b/core/java/android/bluetooth/BluetoothGattServer.java
index 5a39dd6..c8df60e 100644
--- a/core/java/android/bluetooth/BluetoothGattServer.java
+++ b/core/java/android/bluetooth/BluetoothGattServer.java
@@ -519,6 +519,7 @@
      * @param characteristic The local characteristic that has been updated
      * @param confirm true to request confirmation from the client (indication),
      *                false to send a notification
+     * @throws IllegalArgumentException
      * @return true, if the notification has been triggered successfully
      */
     public boolean notifyCharacteristicChanged(BluetoothDevice device,
@@ -529,6 +530,11 @@
         BluetoothGattService service = characteristic.getService();
         if (service == null) return false;
 
+        if (characteristic.getValue() == null) {
+            throw new IllegalArgumentException("Chracteristic value is empty. Use "
+                    + "BluetoothGattCharacteristic#setvalue to update");
+        }
+
         try {
             mService.sendNotification(mServerIf, device.getAddress(),
                     service.getType(), service.getInstanceId(),