summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorArtur Dryomov <artur.dryomov@gmail.com>2013-08-02 03:08:48 +0300
committerArtur Dryomov <artur.dryomov@gmail.com>2013-08-02 03:49:46 +0300
commitfa484c3b00a70ef00996f9bb694ac88da81cc91b (patch)
treeabb58fbf9e8454c6033ee9c2bffb3e9529839fe7 /android
parentd3cef7ed759d8e30f795c3346b5d71d428246c00 (diff)
Fix possible pin-related bug.
The latest LO release does not allow entering PIN-codes without leading zero. This change should solve possible issues from client-side. Change-Id: Ie2f2db9baa5d677cbbed772497d32668cdd5748f
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java56
1 files changed, 41 insertions, 15 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java
index daaeac7dcff7..505cdd65dd1e 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Protocol.java
@@ -18,21 +18,6 @@ final class Protocol {
public static final String CHARSET = "UTF-8";
- public static final class Pin {
- private Pin() {
- }
-
- private static final int NUMBERS_COUNT = 4;
-
- public static String generate() {
- Random aRandomGenerator = new Random();
- int aMaximumPin = (int) Math.pow(10, NUMBERS_COUNT) - 1;
- int aPinNumber = aRandomGenerator.nextInt(aMaximumPin);
-
- return String.format("%04d", aPinNumber);
- }
- }
-
public static final class Ports {
private Ports() {
}
@@ -91,6 +76,47 @@ final class Protocol {
return prepareCommand(aCommand);
}
}
+
+ public static final class Pin {
+ private static final int NUMBERS_COUNT = 4;
+
+ private Pin() {
+ }
+
+ public static String generate() {
+ return new Pin().generatePinText();
+ }
+
+ private String generatePinText() {
+ int aPin = preventLeadingZeros(generatePinNumber());
+
+ return String.format(buildPinFormat(), aPin);
+ }
+
+ private int generatePinNumber() {
+ int aMaximumPin = (int) Math.pow(10, NUMBERS_COUNT) - 1;
+
+ return new Random().nextInt(aMaximumPin);
+ }
+
+ private int preventLeadingZeros(int aPin) {
+ // Pin cannot have leading zeros.
+ // LibreOffice Impress doesn’t allow to enter leading zeros.
+ // Bug exists at least at LibreOffice 4.1.
+
+ int aMinimumPin = (int) Math.pow(10, NUMBERS_COUNT - 1);
+
+ if (aPin >= aMinimumPin) {
+ return aPin;
+ }
+
+ return aPin + aMinimumPin;
+ }
+
+ private String buildPinFormat() {
+ return String.format("%%0%sd", Integer.toString(NUMBERS_COUNT));
+ }
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */