android-project/app/src/main/java/org/libsdl/app/HIDDeviceBLESteamController.java
changeset 12389 5817dbd75619
parent 12307 461ef7221483
equal deleted inserted replaced
12388:69af2eac84e9 12389:5817dbd75619
    10 import android.bluetooth.BluetoothProfile;
    10 import android.bluetooth.BluetoothProfile;
    11 import android.bluetooth.BluetoothGattService;
    11 import android.bluetooth.BluetoothGattService;
    12 import android.os.Handler;
    12 import android.os.Handler;
    13 import android.os.Looper;
    13 import android.os.Looper;
    14 import android.util.Log;
    14 import android.util.Log;
       
    15 import android.os.*;
    15 
    16 
    16 //import com.android.internal.util.HexDump;
    17 //import com.android.internal.util.HexDump;
    17 
    18 
    18 import java.lang.Runnable;
    19 import java.lang.Runnable;
    19 import java.lang.reflect.InvocationTargetException;
       
    20 import java.lang.reflect.Method;
       
    21 import java.util.Arrays;
    20 import java.util.Arrays;
    22 import java.util.LinkedList;
    21 import java.util.LinkedList;
    23 import java.util.UUID;
    22 import java.util.UUID;
    24 
    23 
    25 class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDevice {
    24 class HIDDeviceBLESteamController extends BluetoothGattCallback implements HIDDevice {
   184     }
   183     }
   185 
   184 
   186     // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
   185     // Because on Chromebooks we show up as a dual-mode device, it will attempt to connect TRANSPORT_AUTO, which will use TRANSPORT_BREDR instead
   187     // of TRANSPORT_LE.  Let's force ourselves to connect low energy.
   186     // of TRANSPORT_LE.  Let's force ourselves to connect low energy.
   188     private BluetoothGatt connectGatt(boolean managed) {
   187     private BluetoothGatt connectGatt(boolean managed) {
   189         try {
   188         if (Build.VERSION.SDK_INT >= 23) {
   190             Method m = mDevice.getClass().getDeclaredMethod("connectGatt", Context.class, boolean.class, BluetoothGattCallback.class, int.class);
   189             try {
   191             return (BluetoothGatt) m.invoke(mDevice, mManager.getContext(), managed, this, TRANSPORT_LE);
   190                 return mDevice.connectGatt(mManager.getContext(), managed, this, TRANSPORT_LE);
   192         } catch (Exception e) {
   191             } catch (Exception e) {
       
   192                 return mDevice.connectGatt(mManager.getContext(), managed, this);
       
   193             }
       
   194         } else {
   193             return mDevice.connectGatt(mManager.getContext(), managed, this);
   195             return mDevice.connectGatt(mManager.getContext(), managed, this);
   194         }
   196         }
   195     }
   197     }
   196 
   198 
   197     private BluetoothGatt connectGatt() {
   199     private BluetoothGatt connectGatt() {