Sto eseguendo la compilazione di SDK 10 (2.3.3):Quando si annulla il socket del server bluetooth prima di accettare, l'intero processo muore. Perché?
android:minSdkVersion="10"
android:targetSdkVersion="16"
sto testando su due smartphone Sony Ericsson. Uno ha Android 2.3.7 su di esso e l'altro 4.0.1.
Sto usando listenUsingInsecureRfcommWithServiceRecord
per aprire un nuovo socket server su bluetooth e ascoltare le connessioni.
Se la connessione viene accettata correttamente, tutto funziona correttamente. Posso anche provare a cancellare il socket del server, ma questo non sembra disturbare il socket di connessione appena creato.
MA quando voglio annullare la presa del server prima di aver accettato qualsiasi connessione non appena viene eseguita la riga bluetoothServerSocket.close();
l'intera attività si chiude e il processo muore. E inoltre questo è non un'eccezione regolare che potrei gestire.
In realtà anche lo stesso logcat si chiude !! e devo eseguire rapidamente di nuovo al fine di afferrare gli errori potete vedere qui sotto:
Zygote D Process 25471 terminated by signal (11)
295 InputDispatcher W channel '2c2e20a8 com.pligor.test/activities.MainActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
295 InputDispatcher E channel '2c2e20a8 com.pligor.test/activities.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
295 dalvikvm D GC_FOR_ALLOC freed 1299K, 21% free 13252K/16583K, paused 93ms
295 InputDispatcher W Attempted to unregister already 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 for pid 25471
132 SurfaceFlinger D Release buffer at 0x61c08
295 WindowManager I WINDOW DIED Window{2c2e20a8 com.pligor.test/activities.MainActivity paused=false}
295 ActivityManager I Process com.pligor.test (pid 25471) has died.
295 ActivityManager W Force removing ActivityRecord{2c021800 com.pligor.test/activities.MainActivity}: app died, no saved state
295 WindowManager W Failed looking up window
295 WindowManager W java.lang.IllegalArgumentException: Requested window [email protected] does not exist
295 WindowManager W at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7165)
295 WindowManager W at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7156)
295 WindowManager W at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1545)
295 WindowManager W at android.os.BinderProxy.sendDeathNotice(Binder.java:417)
295 WindowManager W at dalvik.system.NativeStart.run(Native Method)
295 WindowManager I 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 to pid 25471 uid 10040
Nota: Processo terminato dal segnale (11) significa Segmentation fault (http://en.wikipedia.org/wiki/SIGSEGV).
EDIT
ho creare il socket server di Bluetooth utilizzando il seguente codice (Scala
):
private val bluetoothServerSocket: BluetoothServerSocket = try {
bluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord(MY_SERVICE_NAME_INSECURE, MY_UUID_INSECURE);
}
catch {
case e: IOException => throw new ServerSocketException;
}
Io uso questo codice per chiudere la Bluetooth presa:
try {
isCancelled = true;
bluetoothServerSocket.close();
} catch {
case e: IOException => throw new NotClosedException;
}
Ho fatto una piccola ricerca, e sembra che le interruzioni del segnale (11) siano causate da programmi che accedono alla memoria a cui non dovrebbero accedere o che non esistono. Non so perché il tuo programma utilizzi una memoria eccessiva, ma potresti voler controllare quanto sta usando. Pubblicare il codice può essere utile per noi cercando di risolvere i problemi qui. – hBrent
Ok sicuro di non avere problemi. Ma quale parte del codice vorresti che aggiungessi esattamente? –
Chiama a 'bluetoothServerSocket.close();' genera un'eccezione quando non è stata stabilita alcuna connessione? – Houf