Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit daa37a0

Browse files
misteriosojopetreeftime
authored andcommitted
Added Java method BluetoothDevice::remove()
Now it's possible to remove a single device calling directly the method "remove" from Java. Signed-off-by: Jorge Esteves <[email protected]>
1 parent 7f2a22f commit daa37a0

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

api/tinyb/BluetoothDevice.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ friend class tinyb::BluetoothNotificationHandler;
135135
*/
136136
bool pair (
137137
);
138+
139+
/** Remove the current device (like an unpair).
140+
* @return true if the device has been removed from the system.
141+
*/
142+
bool remove_device(
143+
);
138144

139145
/** Cancels an initiated pairing operation
140146
* @return TRUE if the paring is cancelled successfully

java/BluetoothDevice.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ public BluetoothGattService find(String UUID) {
9898
* @return TRUE if the device connected and paired
9999
*/
100100
public native boolean pair() throws BluetoothException;
101+
102+
/** Remove this device from the system (like an unpair).
103+
* @return TRUE if the device has been removed
104+
* @throws BluetoothException
105+
*/
106+
public native boolean remove() throws BluetoothException;
101107

102108
/** Cancels an initiated pairing operation
103109
* @return TRUE if the paring is cancelled successfully

java/jni/BluetoothDevice.cxx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ jboolean Java_tinyb_BluetoothDevice_pair(JNIEnv *env, jobject obj)
176176
return JNI_FALSE;
177177
}
178178

179+
jboolean Java_tinyb_BluetoothDevice_remove(JNIEnv *env, jobject obj)
180+
{
181+
try {
182+
BluetoothDevice *obj_device = getInstance<BluetoothDevice>(env, obj);
183+
184+
return obj_device->remove_device() ? JNI_TRUE : JNI_FALSE;
185+
} catch (std::bad_alloc &e) {
186+
raise_java_oom_exception(env, e);
187+
} catch (BluetoothException &e) {
188+
raise_java_bluetooth_exception(env, e);
189+
} catch (std::runtime_error &e) {
190+
raise_java_runtime_exception(env, e);
191+
} catch (std::invalid_argument &e) {
192+
raise_java_invalid_arg_exception(env, e);
193+
} catch (std::exception &e) {
194+
raise_java_exception(env, e);
195+
}
196+
return JNI_FALSE;
197+
}
198+
179199
jboolean Java_tinyb_BluetoothDevice_cancelPairing(JNIEnv *env, jobject obj)
180200
{
181201
try {

src/BluetoothDevice.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ bool BluetoothDevice::pair ()
298298
return result;
299299
}
300300

301+
// Remove the device (like an unpair)
302+
bool BluetoothDevice::remove_device(){
303+
BluetoothAdapter ba = get_adapter();
304+
return ba.remove_device(get_object_path());
305+
}
306+
301307
bool BluetoothDevice::cancel_pairing ()
302308
{
303309
GError *error = NULL;

0 commit comments

Comments
 (0)