summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-28 22:17:35 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-28 22:21:14 +0200
commit9ca3b5366211e998599c2cf7a7818ca38e3d74a0 (patch)
tree638b8f78b2cab9d212b7363c489085460faa0a0e /android
parent571a7cba185788bcf9e91599da8e16fb050681df (diff)
Saving of authorised remotes.
Change-Id: I4cf6542352ac4213e66e2bbd6cc54d4f9372de62
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java3
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java40
2 files changed, 34 insertions, 9 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 {