Saturday, 15 September 2012

android - When cancelling the bluetooth server socket before accepting, the whole process dies. Why? -



android - When cancelling the bluetooth server socket before accepting, the whole process dies. Why? -

i compiling sdk 10 (2.3.3):

android:minsdkversion="10" android:targetsdkversion="16"

i testing on 2 sony ericsson smartphones. 1 has android 2.3.7 on , other 4.0.1.

i using listenusinginsecurerfcommwithservicerecord open new server socket on bluetooth , hear connections.

if connection accepted works fine. can seek cancel server socket not seem bother connection socket created.

but when want cancel server socket before having accepted connections line bluetoothserversocket.close(); gets executed entire activity closes , process dies. , furthermore not regular exception handle.

actually logcat quits!! , have execute 1 time again in order grab errors can see below:

zygote d process 25471 terminated signal (11) 295 inputdispatcher w channel '2c2e20a8 com.pligor.test/activities.mainactivity (server)' ~ consumer closed input channel or error occurred. events=0x8 295 inputdispatcher e channel '2c2e20a8 com.pligor.test/activities.mainactivity (server)' ~ channel unrecoverably broken , disposed! 295 dalvikvm d gc_for_alloc freed 1299k, 21% free 13252k/16583k, paused 93ms 295 inputdispatcher w attempted unregister unregistered input channel '2c2e20a8 com.pligor.test/activities.mainactivity (server)' 295 bluetoothservice d tracked app 25471 diedtype:10 295 bluetoothservice d removing service record 10009 pid 25471 132 surfaceflinger d release buffer @ 0x61c08 295 windowmanager window died window{2c2e20a8 com.pligor.test/activities.mainactivity paused=false} 295 activitymanager process com.pligor.test (pid 25471) has died. 295 activitymanager w forcefulness removing activityrecord{2c021800 com.pligor.test/activities.mainactivity}: app died, no saved state 295 windowmanager w failed looking window 295 windowmanager w java.lang.illegalargumentexception: requested window android.os.binderproxy@2bf3e798 not exist 295 windowmanager w @ com.android.server.wm.windowmanagerservice.windowforclientlocked(windowmanagerservice.java:7165) 295 windowmanager w @ com.android.server.wm.windowmanagerservice.windowforclientlocked(windowmanagerservice.java:7156) 295 windowmanager w @ com.android.server.wm.windowstate$deathrecipient.binderdied(windowstate.java:1545) 295 windowmanager w @ android.os.binderproxy.senddeathnotice(binder.java:417) 295 windowmanager w @ dalvik.system.nativestart.run(native method) 295 windowmanager win death: null 295 bluetootheventloop d property changed: uuids : 11 295 hadapterstatemachine d bluetoothon process message: 51 295 inputmanagerservice w got remoteexception sending setactive(false) notification pid 25471 uid 10040

note: process terminated signal (11) means segmentation fault (http://en.wikipedia.org/wiki/sigsegv).

edit

i create bluetooth server socket using next code (scala):

private val bluetoothserversocket: bluetoothserversocket = seek { bluetoothadapter.listenusinginsecurerfcommwithservicerecord(my_service_name_inse‌​cure, my_uuid_insecure); } grab { case e: ioexception => throw new serversocketexception; }

i utilize code close bluetooth socket:

try { iscancelled = true; bluetoothserversocket.close(); } grab { case e: ioexception => throw new notclosedexception; }

i have experienced similar issue , root cause of problem calling close on socket more once. right problem, wrapped bluetooth sockets in special class prevent close method beingness called more once.

be aware closing streams created bluetooth socket capable of calling close on socket. next solves problem.

public class closeoncebluetoothsocket { private final bluetoothsocket msocket; private boolean misclosed; public closeoncebluetoothsocket(bluetoothsocket socket) { this.msocket = socket; } public void connect() throws ioexception { msocket.connect(); } public inputstream getinputstream() throws ioexception { homecoming new filterinputstream(msocket.getinputstream()) { @override public void close() throws ioexception { closeoncebluetoothsocket.this.close(); } }; } public outputstream getoutputstream() throws ioexception { homecoming new filteroutputstream(msocket.getoutputstream()) { @override public void close() throws ioexception { closeoncebluetoothsocket.this.close(); } }; } public void close() throws ioexception { synchronized (msocket) { if (!misclosed) { msocket.close(); misclosed = true; } } } }

android bluetooth serversocket

No comments:

Post a Comment