15

I'm getting the following crash, but this only occurs on some Samsung devices (not all, we develop/test on Samsung devices)

Crash log:

java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10025 nor current process has android.permission.BLUETOOTH.
   at android.os.Parcel.readException(Parcel.java:1540)
   at android.os.Parcel.readException(Parcel.java:1493)
   at android.bluetooth.IBluetooth$Stub$Proxy.isEnabled(IBluetooth.java:1156)
   at android.bluetooth.BluetoothAdapter.isEnabled(BluetoothAdapter.java:697)
   at org.altbeacon.beacon.service.scanner.CycledLeScanner.finishScanCycle(CycledLeScanner.java:245)
   at org.altbeacon.beacon.service.scanner.CycledLeScanner.scheduleScanCycleStop(CycledLeScanner.java:234)
   at org.altbeacon.beacon.service.scanner.CycledLeScanner$1.run(CycledLeScanner.java:230)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:145)
   at android.app.ActivityThread.main(ActivityThread.java:5972)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

Here's my AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.myapp" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<!--
     The following two permissions are not required to use Google Maps Android API v2,
     but are recommended. We also require them for location updates.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<permission
    android:name=".permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name=".permission.C2D_MESSAGE" />

<application
    android:name=".myapp"
    android:allowBackup="true"
    android:icon="@drawable/appicon"
    android:label="@string/app_name"
    android:logo="@drawable/action_bar_pinwheel_back"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".activities.VerifyPinActivity"
        android:label="@string/title_activity_verify_pin"
        android:screenOrientation="portrait"
        android:theme="@style/NoActionBarDark"
        android:windowSoftInputMode="stateVisible|adjustPan" >
    </activity>
    ...(more activities here removed)
</application>
</manifest>

I really have no idea why it only occurs on a few devices; my initial guess is it has something to do with Samsung KNOX, and the (few) users that are crashing are KNOX users with a phone policy to disable Bluetooth.

Has anyone else run into this? Or does anyone have any idea what this might be?

Ramesh R
  • 7,009
  • 4
  • 25
  • 38
eric
  • 215
  • 2
  • 12
  • Even if you have uses-permition in your manifest an user can disable any permition for given application, maybe this is the case? A really wild guess. – Trynkiewicz Mariusz Oct 27 '15 at 16:04
  • Another guess: adding android.permission.BLUETOOTH_PRIVILEGED privilege. Maybe this answer (or even next one) http://stackoverflow.com/a/18322851/4618338 could help as well. – Trynkiewicz Mariusz Oct 27 '15 at 16:05
  • @TrynkiewiczMariusz That was my first guess as well. I was guessing something like installing the app into a KNOX sandboxed mode, and disabling Blueetooth within there? I'm not sure how KNOX works though – eric Oct 27 '15 at 17:17

5 Answers5

5

If you are sure the users met this problems only on Samsung KNOX,the following answer maybe will help you.

Thinking step by step is the way to solve your problem.

1.This only occurs on some Samsung devices.

So, it has nothing to do with your code,also the permission.There is something wrong with the Samsung devices.

2.Check the crash log:  
java.lang.SecurityException: Need BLUETOOTH permission: Neither user 10025 nor current process has android.permission.BLUETOOTH.

According to the experience,if you have met the log like "Neither user **** nor current process has *** permission.",this means that your app doesn't have the permission to do something in the system.This occurs often on that you do something need the system level permission.

If you are installed as system level app together with customized Android ROM,or you signed your app with the platform.x509.pem and platform.pk8 file of the customized Android ROM,and then you can have the permission.

Now check what is Samsung KNOX:

Samsung Knox (stylized Samsung KNOX) is an enterprise mobile security solution.

Bluetooth is one kind of data transmission way to the other's device.This will cause the security problem.

Check the offical website:
https://www.samsungknox.com

Search the key words 'Bluetooth',and we found this: https://www.samsungknox.com/en/faq/are-bluetooth-bluetooth-low-energy-and-nfc-available-inside-knox-container

KNOX 2.4+ — Bluetooth, Bluetooth Low Energy (GATT), and NFC are supported inside the KNOX container.

KNOX 2.3 or below — Bluetooth, Bluetooth GATT, and NFC aren't supported inside the KNOX container. If the device is connected to a peripheral (e.g. headphones) in the personal space, Bluetooth will remain connected, even if the user enters the KNOX container. Apps inside the KNOX container can't initiate a Bluetooth connection.

1.If your users are using KNOX 2.3 or below,and they can update their OS of device to KNOX 2.4+.tell your users who use Samsung KNOX update their OS of device.

2.If your users are using KNOX 2.3 or below,and they can't update their OS of device to KNOX 2.4+.your app will not work under this situation,the problem is not the problem,what you can do is only tell uses that:the OS of your device doesn't support Bluetooth,so it's not working.

3.If the above will not help you, you can contact with Samsung KNOX Official

Another tip:
To improve your user experience of your app, you need to prevent your app to be crashed.
Crashed is the worst user experience.
If you can not solve the problem,you can do this:

 try{
     You code related with Bluetooth.
    }catch (Exception e)
    {
    }

Remember:The offical always helps you to solve the problems better!


ifeegoo
  • 7,054
  • 3
  • 33
  • 38
1

You can look here. I'd guess this is your problem.

Are Bluetooth, Bluetooth Low Energy, and NFC available inside the KNOX container?

KNOX 2.4+ — Bluetooth, Bluetooth Low Energy (GATT), and NFC are supported inside the KNOX container.

KNOX 2.3 or below — Bluetooth, Bluetooth GATT, and NFC aren't supported inside the KNOX container. If the device is connected to a peripheral (e.g. headphones) in the personal space, Bluetooth will remain connected, even if the user enters the KNOX container. Apps inside the KNOX container can't initiate a Bluetooth connection.

I never had any hands-on experience with this, but I hope this helps.

Community
  • 1
  • 1
Assaf Gamliel
  • 11,935
  • 5
  • 41
  • 56
0

try to add below to your manifest

<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
fatboy
  • 2,107
  • 1
  • 12
  • 13
  • The Play Store already requires the bluetooth feature; it's automatically added when the bluetooth permission is requested. This might possibly work on forbidding it from being installed in a KNOX environment? I'm not even sure that KNOX is the problem here though. – eric Oct 30 '15 at 22:13
0

From SDK 23 onward you need to check the permission for bluetooth in case required.

   if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
         if (mContext.checkSelfPermission(Manifest.permission.BLUETOOTH) == PackageManager.PERMISSION_GRANTED) {
//TODO - Do the work
    }
  }
Madhukar Hebbar
  • 3,113
  • 5
  • 41
  • 69
0

From KNOX Premium v1.1 onwards, Samsung no longer needs to sign third-party app (APK) files so that they can run inside KNOX containers. Instead, the appropriate permissions are granted at runtime, after an app activates its ELM and KLM licenses successfully. for more info see this

Sulabh Deep Puri
  • 314
  • 1
  • 13