summaryrefslogtreecommitdiff
path: root/sd/source
diff options
context:
space:
mode:
Diffstat (limited to 'sd/source')
-rw-r--r--sd/source/ui/dlg/RemoteDialog.cxx21
-rw-r--r--sd/source/ui/dlg/RemoteDialog.hxx2
-rw-r--r--sd/source/ui/inc/RemoteServer.hxx6
-rw-r--r--sd/source/ui/remotecontrol/BluetoothServer.cxx36
-rw-r--r--sd/source/ui/remotecontrol/BluetoothServer.hxx13
-rw-r--r--sd/source/ui/remotecontrol/Server.cxx14
6 files changed, 52 insertions, 40 deletions
diff --git a/sd/source/ui/dlg/RemoteDialog.cxx b/sd/source/ui/dlg/RemoteDialog.cxx
index fd6089570a98..f9cff1bc9385 100644
--- a/sd/source/ui/dlg/RemoteDialog.cxx
+++ b/sd/source/ui/dlg/RemoteDialog.cxx
@@ -22,22 +22,12 @@ RemoteDialog::RemoteDialog( Window *pWindow ) :
ModalDialog( pWindow, SdResId( DLG_PAIR_REMOTE ) ),
mButtonConnect( this, SdResId( BTN_CONNECT ) ),
mButtonCancel( this, SdResId( BTN_CANCEL ) ),
- mClientBox( this, NULL, SdResId( LB_SERVERS ) ),
- mPreviouslyDiscoverable()
+ mClientBox( this, NULL, SdResId( LB_SERVERS ) )
{
- (void) mPreviouslyDiscoverable; // avoid warnings about unused member
-
FreeResource();
#ifdef ENABLE_SDREMOTE
-
-#ifdef ENABLE_SDREMOTE_BLUETOOTH
- mPreviouslyDiscoverable = RemoteServer::isBluetoothDiscoverable();
- if ( !mPreviouslyDiscoverable )
- RemoteServer::setBluetoothDiscoverable( true );
-#else
- RemoteServer::setBluetoothDiscoverable( false );
-#endif
+ RemoteServer::ensureDiscoverable();
vector<ClientInfo*> aClients( RemoteServer::getClients() );
@@ -80,12 +70,7 @@ IMPL_LINK_NOARG(RemoteDialog, HandleConnectButton)
IMPL_LINK_NOARG( RemoteDialog, CloseHdl )
{
-#if defined(ENABLE_SDREMOTE) && defined(ENABLE_SDREMOTE_BLUETOOTH)
- if ( !mPreviouslyDiscoverable )
- {
- RemoteServer::setBluetoothDiscoverable( false );
- }
-#endif
+ RemoteServer::restoreDiscoverable();
Close();
return 0;
}
diff --git a/sd/source/ui/dlg/RemoteDialog.hxx b/sd/source/ui/dlg/RemoteDialog.hxx
index bc4831bd4ab6..882b9c21c343 100644
--- a/sd/source/ui/dlg/RemoteDialog.hxx
+++ b/sd/source/ui/dlg/RemoteDialog.hxx
@@ -27,8 +27,6 @@ private:
OKButton mButtonConnect;
CancelButton mButtonCancel;
ClientBox mClientBox;
- // Whether discoverability was enabled befor the dialog started.
- bool mPreviouslyDiscoverable;
DECL_DLLPRIVATE_LINK( HandleConnectButton, void * );
DECL_LINK( CloseHdl, void * );
diff --git a/sd/source/ui/inc/RemoteServer.hxx b/sd/source/ui/inc/RemoteServer.hxx
index 740465c2934c..f209561fcd49 100644
--- a/sd/source/ui/inc/RemoteServer.hxx
+++ b/sd/source/ui/inc/RemoteServer.hxx
@@ -66,8 +66,10 @@ namespace sd
SD_DLLPUBLIC static sal_Bool connectClient( ClientInfo *pClient,
rtl::OUString aPin );
- SD_DLLPUBLIC static bool isBluetoothDiscoverable();
- SD_DLLPUBLIC static void setBluetoothDiscoverable( bool aDiscoverable );
+ /// ensure that discoverability (eg. for Bluetooth) is enabled
+ SD_DLLPUBLIC static void ensureDiscoverable();
+ /// restore the state of discoverability from before ensureDiscoverable
+ SD_DLLPUBLIC static void restoreDiscoverable();
// For the communicator
static void removeCommunicator( Communicator* pCommunicator );
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.cxx b/sd/source/ui/remotecontrol/BluetoothServer.cxx
index 4d948663b9bd..d140c1e523d1 100644
--- a/sd/source/ui/remotecontrol/BluetoothServer.cxx
+++ b/sd/source/ui/remotecontrol/BluetoothServer.cxx
@@ -267,7 +267,8 @@ void incomingCallback( void *userRefCon,
BluetoothServer::BluetoothServer( std::vector<Communicator*>* pCommunicators )
- : mpCommunicators( pCommunicators )
+ : meWasDiscoverable( UNKNOWN ),
+ mpCommunicators( pCommunicators )
{
}
@@ -275,6 +276,27 @@ BluetoothServer::~BluetoothServer()
{
}
+
+void BluetoothServer::ensureDiscoverable()
+{
+ if( !spServer || spServer->meWasDiscoverable != UNKNOWN )
+ return;
+
+ bool bDiscoverable = spServer->isDiscoverable();
+ spServer->meWasDiscoverable = bDiscoverable ? DISCOVERABLE : NOT_DISCOVERABLE;
+ spServer->setDiscoverable( true );
+}
+
+void BluetoothServer::restoreDiscoverable()
+{
+ if(!spServer)
+ return;
+
+ if ( spServer->meWasDiscoverable == NOT_DISCOVERABLE )
+ spServer->setDiscoverable( false );
+ spServer->meWasDiscoverable = UNKNOWN;
+}
+
bool BluetoothServer::isDiscoverable()
{
#if (defined(LINUX) && !defined(__FreeBSD_kernel__)) && defined(ENABLE_DBUS)
@@ -328,7 +350,7 @@ bool BluetoothServer::isDiscoverable()
#endif
}
-void BluetoothServer::setDiscoverable( bool aDiscoverable )
+void BluetoothServer::setDiscoverable( bool bDiscoverable )
{
#if (defined(LINUX) && !defined(__FreeBSD_kernel__)) && defined(ENABLE_DBUS)
SAL_INFO( "sdremote.bluetooth", "BluetoothServer::isDiscoverable called" );
@@ -398,12 +420,12 @@ void BluetoothServer::setDiscoverable( bool aDiscoverable )
return;
}
- GValue aDiscoverableGValue = G_VALUE_INIT;
- g_value_init( &aDiscoverableGValue, G_TYPE_BOOLEAN );
- g_value_set_boolean( &aDiscoverableGValue, aDiscoverable );
+ GValue bDiscoverableGValue = G_VALUE_INIT;
+ g_value_init( &bDiscoverableGValue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &bDiscoverableGValue, bDiscoverable );
aResult = dbus_g_proxy_call( aAdapter, "SetProperty", &aError,
G_TYPE_STRING, "Discoverable",
- G_TYPE_VALUE, &aDiscoverableGValue, G_TYPE_INVALID, G_TYPE_INVALID);
+ G_TYPE_VALUE, &bDiscoverableGValue, G_TYPE_INVALID, G_TYPE_INVALID);
if ( !aResult || aError )
{
SAL_WARN( "sdremote.bluetooth", "SetProperty(Discoverable) failed" );
@@ -418,7 +440,7 @@ void BluetoothServer::setDiscoverable( bool aDiscoverable )
g_object_unref( G_OBJECT( aAdapter ));
dbus_g_connection_unref( aConnection );
#else // defined(LINUX) && defined(ENABLE_DBUS)
- (void) aDiscoverable; // avoid warnings
+ (void) bDiscoverable; // avoid warnings
#endif
}
diff --git a/sd/source/ui/remotecontrol/BluetoothServer.hxx b/sd/source/ui/remotecontrol/BluetoothServer.hxx
index d8c9879ab59b..5b986fae210c 100644
--- a/sd/source/ui/remotecontrol/BluetoothServer.hxx
+++ b/sd/source/ui/remotecontrol/BluetoothServer.hxx
@@ -22,18 +22,25 @@ namespace sd
public:
static void setup( std::vector<Communicator*>* pCommunicators );
- static bool isDiscoverable();
- static void setDiscoverable( bool aDiscoverable );
+ /// ensure that Bluetooth discoverability is on
+ static void ensureDiscoverable();
+ /// restore the state of discoverability from before ensureDiscoverable
+ static void restoreDiscoverable();
+
void addCommunicator( Communicator* pCommunicator );
private:
BluetoothServer( std::vector<Communicator*>* pCommunicators );
~BluetoothServer();
+
+ bool isDiscoverable();
+ void setDiscoverable( bool bDiscoverable );
+
+ enum { UNKNOWN, DISCOVERABLE, NOT_DISCOVERABLE } meWasDiscoverable;
static BluetoothServer *spServer;
virtual void SAL_CALL run();
std::vector<Communicator*>* mpCommunicators;
-
};
}
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 9989ed05bb57..561dac149cb6 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -318,21 +318,19 @@ void SdDLL::RegisterRemotes()
sd::DiscoveryService::setup();
}
-bool RemoteServer::isBluetoothDiscoverable()
+void RemoteServer::ensureDiscoverable()
{
+ // FIXME: we could also enable listening on our WiFi
+ // socket here to significantly reduce the attack surface.
#ifdef ENABLE_SDREMOTE_BLUETOOTH
- return BluetoothServer::isDiscoverable();
-#else
- return false;
+ BluetoothServer::ensureDiscoverable();
#endif
}
-void RemoteServer::setBluetoothDiscoverable( bool aDiscoverable )
+void RemoteServer::restoreDiscoverable()
{
#ifdef ENABLE_SDREMOTE_BLUETOOTH
- BluetoothServer::setDiscoverable( aDiscoverable );
-#else
- (void) aDiscoverable;
+ BluetoothServer::restoreDiscoverable();
#endif
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */