Bluetooth: correcting return value from cancelDiscovery

BluetoothAdapter.cancelDiscovery was previously always
returning false.

Change-Id: Ic1fd134d4b710438d95c5b8ca009104529dd1bf5
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index e1c9044..26707c9 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -699,7 +699,7 @@
     public boolean cancelDiscovery() {
         if (getState() != STATE_ON) return false;
         try {
-            mService.cancelDiscovery();
+            return mService.cancelDiscovery();
         } catch (RemoteException e) {Log.e(TAG, "", e);}
         return false;
     }
diff --git a/core/jni/android_server_BluetoothService.cpp b/core/jni/android_server_BluetoothService.cpp
index 5c6958a..ac75634 100644
--- a/core/jni/android_server_BluetoothService.cpp
+++ b/core/jni/android_server_BluetoothService.cpp
@@ -250,15 +250,15 @@
 #endif
 }
 
-static void stopDiscoveryNative(JNIEnv *env, jobject object) {
-    LOGV("%s", __FUNCTION__);
+static jboolean stopDiscoveryNative(JNIEnv *env, jobject object) {
+    LOGV(__FUNCTION__);
 #ifdef HAVE_BLUETOOTH
     DBusMessage *msg = NULL;
     DBusMessage *reply = NULL;
     DBusError err;
     const char *name;
-    jstring ret;
     native_data_t *nat;
+    jboolean ret = JNI_FALSE;
 
     dbus_error_init(&err);
 
@@ -288,11 +288,16 @@
         } else {
             LOG_AND_FREE_DBUS_ERROR_WITH_MSG(&err, msg);
         }
+        goto done;
     }
 
+    ret = JNI_TRUE;
 done:
     if (msg) dbus_message_unref(msg);
     if (reply) dbus_message_unref(reply);
+    return ret;
+#else
+    return JNI_FALSE;
 #endif
 }
 
diff --git a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
index f1dd8fe..5f4c226 100644
--- a/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
+++ b/core/tests/bluetoothtests/src/android/bluetooth/BluetoothTestUtils.java
@@ -678,8 +678,7 @@
         BluetoothReceiver receiver = getBluetoothReceiver(mask);
 
         long start = System.currentTimeMillis();
-        // TODO: put assertTrue() around cancelDiscovery() once it starts returning true.
-        adapter.cancelDiscovery();
+        assertTrue(adapter.cancelDiscovery());
 
         while (System.currentTimeMillis() - start < START_STOP_SCAN_TIMEOUT) {
             if (!adapter.isDiscovering() && ((receiver.getFiredFlags() & mask) == mask)) {