Don't crash if the app doesn't have Bluetooth permissions
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Aug 2018 11:07:56 -0700
changeset 1212670315808397f
parent 12125 12035d408935
child 12127 f92fd2c57780
Don't crash if the app doesn't have Bluetooth permissions
android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java
     1.1 --- a/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java	Tue Aug 21 10:37:26 2018 -0700
     1.2 +++ b/android-project/app/src/main/java/org/libsdl/app/HIDDeviceManager.java	Tue Aug 21 11:07:56 2018 -0700
     1.3 @@ -11,6 +11,7 @@
     1.4  import android.content.Intent;
     1.5  import android.content.IntentFilter;
     1.6  import android.content.SharedPreferences;
     1.7 +import android.content.pm.PackageManager;
     1.8  import android.hardware.usb.*;
     1.9  import android.os.Handler;
    1.10  import android.os.Looper;
    1.11 @@ -316,6 +317,11 @@
    1.12      protected void initializeBluetooth() {
    1.13          Log.d(TAG, "Initializing Bluetooth");
    1.14  
    1.15 +        if (mContext.getPackageManager().checkPermission(android.Manifest.permission.BLUETOOTH, mContext.getPackageName()) != PackageManager.PERMISSION_GRANTED) {
    1.16 +            Log.d(TAG, "Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH");
    1.17 +            return;
    1.18 +        }
    1.19 +
    1.20          // Find bonded bluetooth controllers and create SteamControllers for them
    1.21          mBluetoothManager = (BluetoothManager)mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    1.22          if (mBluetoothManager == null) {