diff --git a/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java b/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java index e882fda..e6aad8b 100644 --- a/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java +++ b/android-scanner/src/main/java/com/meerkat/laura/fakescannerapp/MainActivity.java @@ -3,6 +3,7 @@ package com.meerkat.laura.fakescannerapp; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Color; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; @@ -35,7 +36,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe SharedPreferences sharedPref; Button scanBtn; - TextView formatTxt, contentTxt, responseTxt; + TextView formatTxt, contentTxt, responseTxt, serverStatus; PollingStationScanner.ScannerClient scannerClient; DigitalSignatureGenerator signer; @@ -63,6 +64,24 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe String pscUrlString = sharedPref.getString(SettingsActivity.PSC_URL, ""); scannerClient = new ScannerClientAPI(signer); + + serverStatus.setTextColor(Color.BLUE); + serverStatus.setText("Connecting to " + pscUrlString); + + PollingStation.ConnectionServerData serverData = PollingStation.ConnectionServerData.newBuilder() + .setServerUrl(pscUrlString) + .setNonce(0) + .build(); + + boolean res = scannerClient.connect(serverData); + if (res) { + serverStatus.setTextColor(Color.GREEN); + serverStatus.setText("Connected to " + pscUrlString); + } else { + serverStatus.setTextColor(Color.RED); + serverStatus.setText("Connection failed: " + pscUrlString); + } + } @Override @@ -83,6 +102,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe formatTxt = (TextView)findViewById(R.id.scan_format); contentTxt = (TextView)findViewById(R.id.scan_content); responseTxt = (TextView)findViewById(R.id.server_response); + serverStatus = (TextView) findViewById(R.id.serverStatus); signer = new ECDSADeterministicSignature(); diff --git a/android-scanner/src/main/res/layout/activity_main.xml b/android-scanner/src/main/res/layout/activity_main.xml index cdd6ec9..baa314e 100644 --- a/android-scanner/src/main/res/layout/activity_main.xml +++ b/android-scanner/src/main/res/layout/activity_main.xml @@ -47,5 +47,12 @@ android:textIsSelectable="true" android:layout_centerHorizontal="true" android:layout_marginTop="44dp" /> + diff --git a/meerkat-common/src/main/java/meerkat/crypto/concrete/GlobalCryptoSetup.java b/meerkat-common/src/main/java/meerkat/crypto/concrete/GlobalCryptoSetup.java index 4e7f4ce..5333a25 100644 --- a/meerkat-common/src/main/java/meerkat/crypto/concrete/GlobalCryptoSetup.java +++ b/meerkat-common/src/main/java/meerkat/crypto/concrete/GlobalCryptoSetup.java @@ -33,6 +33,8 @@ public final class GlobalCryptoSetup { // For now we just check if the java version is at least 8 String[] version = System.getProperty("java.version").split("\\."); int major = Integer.parseInt(version[0]); + if (version.length < 2) + return false; int minor = Integer.parseInt(version[1]); return ((major > 1) || ((major > 0) && (minor > 7))); }