schildbach/bitcoin-wallet — pull request #137 by javgh (2014-09-22 20:05:45+00:00)
Title: Deal with Bluetooth listening exception more gracefully

Occasionally I received crash reports like these:

````
java.lang.RuntimeException: Unable to create service
com.hivewallet.androidclient.wallet.offline.AcceptBluetoothService:
java.lang.RuntimeException: java.io.IOException: Error: -1
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2723)
at android.app.ActivityThread.access$1900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1347)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.io.IOException: Error: -1
at
com.hivewallet.androidclient.wallet.offline.AcceptBluetoothThread.listen(AcceptBluetoothThread.java:271)
at
com.hivewallet.androidclient.wallet.offline.AcceptBluetoothThread$ClassicBluetoothThread.(AcceptBluetoothThread.java:64)
at
com.hivewallet.androidclient.wallet.offline.AcceptBluetoothService$1.(AcceptBluetoothService.java:95)
at
com.hivewallet.androidclient.wallet.offline.AcceptBluetoothService.onCreate(AcceptBluetoothService.java:94)
````

I'm not sure why the Bluetooth service cannot be created, even though Bluetooth availability was checked before. But I decided to change the code so that the service wouldn't be created in the constructor, but instead as part of the run() method where the exception can be easier dealt with. The new code should prevent crashes, when listening via Bluetooth is for some reason not possible.

I think this change would be nice to see upstream. Submitted for your consideration. =) Cheers!