0

i have the following service running on the sonny erricson xperia Ray 2.3 android which runns perfectly. it is designed to automatically disable bluetooth and WiFi when ever the user try to switch on.

this runs on the boot.

But when i runs on the Galaxy tab 10.2 android 3.2 it works for wifi but on bluetooth it gets force closed.

Service is as follows

IntentFilter filterb = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED);
BroadcastReceiver mReceiverb = new StatusReceiver();
registerReceiver(mReceiverb, filterb);

Broadcast is as follows

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter.isEnabled()) {
    mBluetoothAdapter.disable();
}

permission is given as follows

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

just got the logcat

E/AndroidRuntime( 9217): FATAL EXCEPTION: main
E/AndroidRuntime( 9217): java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.STATE_CHANGED flg=0x10000010 (has extras) } in google.android.disable.StatusReceiver@407bbc40
E/AndroidRuntime( 9217):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:734)
E/AndroidRuntime( 9217):    at android.os.Handler.handleCallback(Handler.java:587)
E/AndroidRuntime( 9217):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 9217):    at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime( 9217):    at android.app.ActivityThread.main(ActivityThread.java:4126)
E/AndroidRuntime( 9217):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 9217):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime( 9217):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
E/AndroidRuntime( 9217):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
E/AndroidRuntime( 9217):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 9217): Caused by: java.lang.SecurityException: Calling uid 10097 gave packageandroid which is owned by uid 1000
E/AndroidRuntime( 9217):    at android.os.Parcel.readException(Parcel.java:1321)
E/AndroidRuntime( 9217):    at android.os.Parcel.readException(Parcel.java:1275)
E/AndroidRuntime( 9217):    at android.bluetooth.IBluetooth$Stub$Proxy.disable(IBluetooth.java:806)
E/AndroidRuntime( 9217):    at android.bluetooth.BluetoothAdapter.disable(BluetoothAdapter.java:496)
E/AndroidRuntime( 9217):    at google.android.disable.StatusReceiver.onReceive(StatusReceiver.java:26)
E/AndroidRuntime( 9217):    at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:725)
E/AndroidRuntime( 9217):    ... 9 more
Loshi
  • 221
  • 1
  • 5
  • 19

1 Answers1

0

The Android reference states that you should not call BluetoothAdapter.disable() without explicit user action. This means you should not call this method automatically when the device boots. This may be the reason for your error.

Reference: http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#disable()

Ian Newson
  • 7,679
  • 2
  • 47
  • 80
  • But how come it runns perfectly on the sonyerricson Ray and not on Galaxy tab? and it is specifically on Bluetooth only. not even on wifi – Loshi Jun 27 '12 at 07:53
  • I assume the underlying framework code changed around Android 3 to enforce the restriction. Wifi simply doesn't have this restriction. However, the point remains that the documentation explicitly states that you shouldn't do what you're trying to do, so you shouldn't expect it to work. – Ian Newson Jun 27 '12 at 08:10
  • :/ ohh well there should be some thing that will work on it right? – Loshi Jun 27 '12 at 09:22
  • I think the only way you'll get this to work is if you prompt the user first. A notification which opens an activity might work. If you let me know the overall picture of what you're trying to achieve (is this a power saving app? perhaps you're trying to lock down the devices for marketing purposes?) then maybe I can suggest a better alternative. – Ian Newson Jun 27 '12 at 09:44
  • NOpe this is an security application use for corporate given TABs and all the settings an applicatoins will be again lock with an app locker as well. – Loshi Jun 27 '12 at 09:49
  • Look in to MDM: http://www.samsungmobileb2b.com/solutions/common/security/mdm.do I've never used it myself, but it seems to offer remote Bluetooth management. – Ian Newson Jun 27 '12 at 09:58