Skip to content
Snippets Groups Projects
Commit 9c61e4e0 authored by akwizgran's avatar akwizgran
Browse files

Cleaned up Bluetooth reflection code.

parent 927d4110
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ class InsecureBluetooth { ...@@ -40,7 +40,7 @@ class InsecureBluetooth {
try { try {
if(LOG.isLoggable(INFO)) LOG.info("Listening via reflection"); if(LOG.isLoggable(INFO)) LOG.info("Listening via reflection");
// Find an available channel // Find an available channel
String className = BluetoothAdapter.class.getName() String className = BluetoothAdapter.class.getCanonicalName()
+ ".RfcommChannelPicker"; + ".RfcommChannelPicker";
Class<?> channelPickerClass = null; Class<?> channelPickerClass = null;
Class<?>[] children = BluetoothAdapter.class.getDeclaredClasses(); Class<?>[] children = BluetoothAdapter.class.getDeclaredClasses();
...@@ -54,8 +54,7 @@ class InsecureBluetooth { ...@@ -54,8 +54,7 @@ class InsecureBluetooth {
throw new IOException("Can't find channel picker class"); throw new IOException("Can't find channel picker class");
Constructor<?> constructor = Constructor<?> constructor =
channelPickerClass.getDeclaredConstructor(UUID.class); channelPickerClass.getDeclaredConstructor(UUID.class);
if(constructor == null) constructor.setAccessible(true);
throw new IOException("Can't find channel picker constructor");
Object channelPicker = constructor.newInstance(uuid); Object channelPicker = constructor.newInstance(uuid);
Method nextChannel = Method nextChannel =
channelPickerClass.getDeclaredMethod("nextChannel"); channelPickerClass.getDeclaredMethod("nextChannel");
...@@ -109,8 +108,6 @@ class InsecureBluetooth { ...@@ -109,8 +108,6 @@ class InsecureBluetooth {
Constructor<BluetoothServerSocket> constructor = Constructor<BluetoothServerSocket> constructor =
BluetoothServerSocket.class.getDeclaredConstructor( BluetoothServerSocket.class.getDeclaredConstructor(
int.class, boolean.class, boolean.class, int.class); int.class, boolean.class, boolean.class, int.class);
if(constructor == null)
throw new IOException("Can't find server socket constructor");
constructor.setAccessible(true); constructor.setAccessible(true);
BluetoothServerSocket socket = constructor.newInstance(TYPE_RFCOMM, BluetoothServerSocket socket = constructor.newInstance(TYPE_RFCOMM,
false, false, port); false, false, port);
...@@ -156,8 +153,6 @@ class InsecureBluetooth { ...@@ -156,8 +153,6 @@ class InsecureBluetooth {
BluetoothSocket.class.getDeclaredConstructor(int.class, BluetoothSocket.class.getDeclaredConstructor(int.class,
int.class, boolean.class, boolean.class, int.class, boolean.class, boolean.class,
BluetoothDevice.class, int.class, ParcelUuid.class); BluetoothDevice.class, int.class, ParcelUuid.class);
if(constructor == null)
throw new IOException("Can't find socket constructor");
constructor.setAccessible(true); constructor.setAccessible(true);
return constructor.newInstance(TYPE_RFCOMM, -1, false, true, device, return constructor.newInstance(TYPE_RFCOMM, -1, false, true, device,
-1, new ParcelUuid(uuid)); -1, new ParcelUuid(uuid));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment