summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java3
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java40
-rw-r--r--officecfg/registry/schema/org/openoffice/Office/Impress.xcs21
-rw-r--r--sd/source/ui/remotecontrol/Server.cxx64
4 files changed, 116 insertions, 12 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 89b94dd5ccea..214103a0a993 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -86,8 +86,7 @@ public class CommunicationService extends Service implements Runnable {
mState = State.CONNECTING;
switch (mServerDesired.getProtocol()) {
case NETWORK:
- mClient = new NetworkClient(
- mServerDesired.getAddress(), this);
+ mClient = new NetworkClient(mServerDesired, this);
break;
case BLUETOOTH:
mClient = new BluetoothClient(
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java
index 47e0e3779616..dcb88a56f877 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java
@@ -17,6 +17,8 @@ import java.util.Random;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.support.v4.content.LocalBroadcastManager;
/**
@@ -30,20 +32,16 @@ public class NetworkClient extends Client {
private Socket mSocket;
- public NetworkClient(String ipAddress, Context aContext) {
+ public NetworkClient(Server aServer, Context aContext) {
super(aContext);
try {
- mSocket = new Socket(ipAddress, PORT);
+ mSocket = new Socket(aServer.getAddress(), PORT);
mInputStream = mSocket.getInputStream();
mReader = new BufferedReader(new InputStreamReader(mInputStream,
CHARSET));
mOutputStream = mSocket.getOutputStream();
// Pairing.
- Random aRandom = new Random();
- String aPin = "" + (aRandom.nextInt(9000) + 1000);
- while (aPin.length() < 4) {
- aPin = "0" + aPin; // Add leading zeros if necessary
- }
+ String aPin = setupPin(aServer);
Intent aIntent = new Intent(
CommunicationService.MSG_PAIRING_STARTED);
aIntent.putExtra("PIN", aPin);
@@ -82,6 +80,34 @@ public class NetworkClient extends Client {
}
+ private String setupPin(Server aServer) {
+ // Get settings
+ SharedPreferences aPreferences = mContext.getSharedPreferences(
+ "sdremote_authorisedremotes",
+ android.content.Context.MODE_PRIVATE);
+ if (aPreferences.contains(aServer.getName())) {
+ return aPreferences.getString(aServer.getName(), "");
+ } else {
+ String aPin = generatePin();
+
+ Editor aEdit = aPreferences.edit();
+ aEdit.putString(aServer.getName(), aPin);
+ aEdit.commit();
+
+ return aPin;
+ }
+
+ }
+
+ private String generatePin() {
+ Random aRandom = new Random();
+ String aPin = "" + (aRandom.nextInt(9000) + 1000);
+ while (aPin.length() < 4) {
+ aPin = "0" + aPin; // Add leading zeros if necessary
+ }
+ return aPin;
+ }
+
@Override
public void closeConnection() {
try {
diff --git a/officecfg/registry/schema/org/openoffice/Office/Impress.xcs b/officecfg/registry/schema/org/openoffice/Office/Impress.xcs
index cb8c31a92e62..6ad225f8ba94 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Impress.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Impress.xcs
@@ -2,7 +2,7 @@
<!--***********************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
+ *
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
@@ -90,6 +90,19 @@
</info>
</prop>
</group>
+ <group oor:name="AuthorisedRemote">
+ <info>
+ <author>ajrhunt</author>
+ <desc>
+ A Remote Control Device that has been authorised for connection.
+ </desc>
+ </info>
+ <prop oor:name="PIN" oor:type="xs:string">
+ <info>
+ <desc>The PIN used by the device for authentication.</desc>
+ </info>
+ </prop>
+ </group>
</templates>
<component>
<group oor:name="Layout">
@@ -655,6 +668,12 @@
<value>5000</value>
</prop>
</group>
+ <set oor:name="AuthorisedRemotes" oor:node-type="AuthorisedRemote">
+ <info>
+ <author>ajrhunt</author>
+ <desc>Contains a list of remote control devices that can connect without user confirmation.</desc>
+ </info>
+ </set>
</group>
<group oor:name="Snap">
<info>
diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 34f85b3aa0e5..757a65bab9c5 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -11,7 +11,14 @@
#include <vector>
#include "officecfg/Office/Common.hxx"
+#include "officecfg/Office/Impress.hxx"
+
+#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/uno/Sequence.hxx>
+
#include <comphelper/processfactory.hxx>
+#include <comphelper/configuration.hxx>
#include "sddll.hxx"
@@ -25,8 +32,13 @@
using namespace std;
using namespace sd;
using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
using rtl::OString;
using namespace ::osl;
+using namespace ::comphelper;
// struct ClientInfoInternal:
// ClientInfo
@@ -89,10 +101,11 @@ void RemoteServer::execute()
OUString aAddress = aClientAddr.getHostname();
MutexGuard aGuard( mDataMutex );
- mAvailableClients.push_back( new ClientInfoInternal(
+ ClientInfoInternal* pClient = new ClientInfoInternal(
OStringToOUString( aName, RTL_TEXTENCODING_UTF8 ),
aAddress, pSocket, OStringToOUString( aPin,
- RTL_TEXTENCODING_UTF8 ) ) );
+ RTL_TEXTENCODING_UTF8 ) );
+ mAvailableClients.push_back( pClient );
// Read off any additional non-empty lines
do
@@ -100,6 +113,27 @@ void RemoteServer::execute()
pSocket->readLine( aLine );
}
while ( aLine.getLength() > 0 );
+
+ // Check if we already have this server.
+ Reference< XNameAccess > xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get();
+ Sequence< OUString > aNames = xConfig->getElementNames();
+ for ( int i = 0; i < aNames.getLength(); i++ )
+ {
+ if ( aNames[i].equals( pClient->mName ) )
+ {
+ Reference<XNameAccess> xSetItem( xConfig->getByName(aNames[i]), UNO_QUERY );
+ Any axPin(xSetItem->getByName("PIN"));
+ OUString sPin;
+ axPin >>= sPin;
+
+ if ( ! sPin.equals( pClient->mPin ) ) {
+ break;
+ }
+ connectClient( pClient, sPin );
+ break;
+ }
+
+ }
} else {
delete pSocket;
}
@@ -180,6 +214,32 @@ sal_Bool RemoteServer::connectClient( ClientInfo* pClient, rtl::OUString aPin )
ClientInfoInternal *apClient = (ClientInfoInternal*) pClient;
if ( apClient->mPin.equals( aPin ) )
{
+ // Save in settings first
+ boost::shared_ptr< ConfigurationChanges > aChanges = ConfigurationChanges::create();
+ Reference< XNameContainer > xConfig = officecfg::Office::Impress::Misc::AuthorisedRemotes::get( aChanges );
+
+ Reference<XSingleServiceFactory> xChildFactory (
+ xConfig, UNO_QUERY);
+ Reference<XNameReplace> xChild( xChildFactory->createInstance(), UNO_QUERY);
+ Any aValue;
+ if (xChild.is())
+ {
+ // Check whether the client is already saved
+ Sequence< OUString > aNames = xConfig->getElementNames();
+ for ( int i = 0; i < aNames.getLength(); i++ )
+ {
+ if ( aNames[i].equals( apClient->mName ) )
+ xConfig->replaceByName( apClient->mName, makeAny( xChild ) );
+ else
+ xConfig->insertByName( apClient->mName, makeAny( xChild ) );
+ }
+
+ aValue <<= OUString( apClient->mPin );
+ xChild->replaceByName("PIN", aValue);
+ aChanges->commit();
+ }
+
+
Communicator* pCommunicator = new Communicator( apClient->mpStreamSocket );
MutexGuard aGuard( spServer->mDataMutex );