mirror of
				https://github.com/libsdl-org/SDL.git
				synced 2025-11-04 01:34:38 +00:00 
			
		
		
		
	Fixed bug 4320 - Android remove reflection for HIDDeviceBLESteamController
Sylvain Uneeded use of reflection to access connectGatt method in HIDDeviceBLESteamController.java The method is API 23 https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html#connectGatt(android.content.Context,%20boolean,%20android.bluetooth.BluetoothGattCallback,%20int)
This commit is contained in:
		@@ -12,12 +12,11 @@ import android.bluetooth.BluetoothGattService;
 | 
				
			|||||||
import android.os.Handler;
 | 
					import android.os.Handler;
 | 
				
			||||||
import android.os.Looper;
 | 
					import android.os.Looper;
 | 
				
			||||||
import android.util.Log;
 | 
					import android.util.Log;
 | 
				
			||||||
 | 
					import android.os.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//import com.android.internal.util.HexDump;
 | 
					//import com.android.internal.util.HexDump;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.lang.Runnable;
 | 
					import java.lang.Runnable;
 | 
				
			||||||
import java.lang.reflect.InvocationTargetException;
 | 
					 | 
				
			||||||
import java.lang.reflect.Method;
 | 
					 | 
				
			||||||
import java.util.Arrays;
 | 
					import java.util.Arrays;
 | 
				
			||||||
import java.util.LinkedList;
 | 
					import java.util.LinkedList;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
@@ -186,10 +185,13 @@ class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDe
 | 
				
			|||||||
    // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
 | 
					    // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
 | 
				
			||||||
    // of TRANSPORT_LE.  Let's force ourselves to connect low energy.
 | 
					    // of TRANSPORT_LE.  Let's force ourselves to connect low energy.
 | 
				
			||||||
    private BluetoothGatt connectGatt(boolean managed) {
 | 
					    private BluetoothGatt connectGatt(boolean managed) {
 | 
				
			||||||
        try {
 | 
					        if (Build.VERSION.SDK_INT >= 23) {
 | 
				
			||||||
            Method m = mDevice.getClass().getDeclaredMethod("connectGatt", Context.class, boolean.class, BluetoothGattCallback.class, int.class);
 | 
					            try {
 | 
				
			||||||
            return (BluetoothGatt) m.invoke(mDevice, mManager.getContext(), managed, this, TRANSPORT_LE);
 | 
					                return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
 | 
				
			||||||
        } catch (Exception e) {
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                return mDevice.connectGatt(mManager.getContext(), managed, this);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
            return mDevice.connectGatt(mManager.getContext(), managed, this);
 | 
					            return mDevice.connectGatt(mManager.getContext(), managed, this);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user