From 6ce04df28c8b5d6043340efe6fdc229b51dd8c36 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 18 Feb 2013 22:13:03 +0200 Subject: Handle gracefully the remote end closing the RFCOMM channel Avoids a crash if one presses the "back" key on the Android remote control. Change-Id: Icc7562676a79910b77c7f95d76ce07c348ec2b22 --- sd/source/ui/remotecontrol/BluetoothServer.cxx | 11 +++++++++++ sd/source/ui/remotecontrol/OSXBluetooth.mm | 7 ++++++- sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'sd') diff --git a/sd/source/ui/remotecontrol/BluetoothServer.cxx b/sd/source/ui/remotecontrol/BluetoothServer.cxx index b9736a20a746..ad6dadf14a61 100644 --- a/sd/source/ui/remotecontrol/BluetoothServer.cxx +++ b/sd/source/ui/remotecontrol/BluetoothServer.cxx @@ -189,6 +189,10 @@ sal_Int32 OSXBluetoothWrapper::write( const void* pBuffer, sal_uInt32 n ) char* ptr = (char*)pBuffer; sal_uInt32 nBytesWritten = 0; + + if (mpChannel == nil) + return 0; + while( nBytesWritten < n ) { int toWrite = n - nBytesWritten; @@ -222,6 +226,13 @@ void OSXBluetoothWrapper::appendData(void* pBuffer, size_t len) } } +void OSXBluetoothWrapper::channelClosed() +{ + SAL_INFO( "sdremote.bluetooth", "OSXBluetoothWrapper::channelClosed()" ); + + mpChannel = nil; +} + void incomingCallback( void *userRefCon, IOBluetoothUserNotificationRef inRef, IOBluetoothObjectRef objectRef ) diff --git a/sd/source/ui/remotecontrol/OSXBluetooth.mm b/sd/source/ui/remotecontrol/OSXBluetooth.mm index ef1b7000eab4..f364389df78e 100644 --- a/sd/source/ui/remotecontrol/OSXBluetooth.mm +++ b/sd/source/ui/remotecontrol/OSXBluetooth.mm @@ -37,7 +37,12 @@ { (void) rfcommChannel; - // TODO: broadcast premature closing of data channel + SAL_INFO( "sdremote.bluetooth", "ChannelDelegate::rfcommChannelClosed()\n"); + + if ( pSocket ) + { + pSocket->channelClosed(); + } pCommunicator = NULL; pSocket = NULL; } diff --git a/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx b/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx index 6a61a24bc97b..cecaa7a8b1e5 100644 --- a/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx +++ b/sd/source/ui/remotecontrol/OSXBluetoothWrapper.hxx @@ -32,6 +32,7 @@ namespace sd virtual sal_Int32 readLine( rtl::OString& aLine ); virtual sal_Int32 write( const void* pBuffer, sal_uInt32 len ); void appendData(void* pBuffer, size_t len ); + void channelClosed(); }; } -- cgit