minor code improvements
This commit is contained in:
@@ -33,6 +33,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.method.ScrollingMovementMethod;
|
import android.text.method.ScrollingMovementMethod;
|
||||||
@@ -218,9 +219,9 @@ public class MainActivity extends Activity implements NfcAdapter.ReaderCallback
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String saved_status_key = "textViewVPCDStatus";
|
private static final String saved_status_key = "textViewVPCDStatus";
|
||||||
@Override
|
@Override
|
||||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||||
super.onRestoreInstanceState(savedInstanceState);
|
super.onRestoreInstanceState(savedInstanceState);
|
||||||
textViewVPCDStatus.setText(savedInstanceState.getCharSequence(saved_status_key));
|
textViewVPCDStatus.setText(savedInstanceState.getCharSequence(saved_status_key));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ package com.vsmartcard.remotesmartcardreader.app;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
|
||||||
public class MessageSender {
|
class MessageSender {
|
||||||
public static final int MESSAGE_CONNECTED = 0;
|
public static final int MESSAGE_CONNECTED = 0;
|
||||||
public static final int MESSAGE_DISCONNECTED = 1;
|
public static final int MESSAGE_DISCONNECTED = 1;
|
||||||
public static final int MESSAGE_ERROR = 2;
|
public static final int MESSAGE_ERROR = 2;
|
||||||
@@ -32,7 +32,7 @@ public class MessageSender {
|
|||||||
public static final int MESSAGE_RESET = 6;
|
public static final int MESSAGE_RESET = 6;
|
||||||
public static final int MESSAGE_CAPDU = 7;
|
public static final int MESSAGE_CAPDU = 7;
|
||||||
public static final int MESSAGE_RAPDU = 8;
|
public static final int MESSAGE_RAPDU = 8;
|
||||||
private Handler handler;
|
private final Handler handler;
|
||||||
|
|
||||||
public MessageSender(Handler handler) {
|
public MessageSender(Handler handler) {
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
@@ -56,7 +56,7 @@ public class MessageSender {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendDisconnected(String details) {
|
public void sendDisconnected(String details) {
|
||||||
sendMessage(MESSAGE_DISCONNECTED, details);
|
sendMessage(MESSAGE_DISCONNECTED, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendError(String details) {
|
public void sendError(String details) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
public class Settings {
|
class Settings {
|
||||||
|
|
||||||
private static final String KEY_VPCD_HOST = "hostname";
|
private static final String KEY_VPCD_HOST = "hostname";
|
||||||
private static final String KEY_VPCD_PORT = "port";
|
private static final String KEY_VPCD_PORT = "port";
|
||||||
@@ -44,19 +44,11 @@ public class Settings {
|
|||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBoolean(String key, boolean value) {
|
// private void setBoolean(String key, boolean value) {
|
||||||
Editor editor = settings.edit();
|
// Editor editor = settings.edit();
|
||||||
editor.putBoolean(key, value);
|
// editor.putBoolean(key, value);
|
||||||
editor.apply();
|
// editor.apply();
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void setVPCDHost(String hostname) {
|
|
||||||
setString(KEY_VPCD_HOST, hostname);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVPCDPort(String port) {
|
|
||||||
setString(KEY_VPCD_PORT, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVPCDSettings(String hostname, String port) {
|
public void setVPCDSettings(String hostname, String port) {
|
||||||
Editor editor = settings.edit();
|
Editor editor = settings.edit();
|
||||||
|
|||||||
@@ -30,16 +30,16 @@ import java.io.OutputStream;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
public class VPCDWorker implements Runnable, Closeable {
|
class VPCDWorker implements Runnable, Closeable {
|
||||||
public static int DEFAULT_PORT = 35963;
|
public static final int DEFAULT_PORT = 35963;
|
||||||
private int port;
|
private final int port;
|
||||||
private String hostname;
|
private final String hostname;
|
||||||
private SCReader reader;
|
private final SCReader reader;
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
private InputStream inputStream;
|
private InputStream inputStream;
|
||||||
private OutputStream outputStream;
|
private OutputStream outputStream;
|
||||||
private boolean doRun;
|
private boolean doRun;
|
||||||
private MessageSender messageSender;
|
private final MessageSender messageSender;
|
||||||
|
|
||||||
public VPCDWorker(String hostname, int port, SCReader reader, Handler handler) {
|
public VPCDWorker(String hostname, int port, SCReader reader, Handler handler) {
|
||||||
this.hostname = hostname;
|
this.hostname = hostname;
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class NFCReader implements SCReader {
|
public class NFCReader implements SCReader {
|
||||||
|
|
||||||
private IsoDep card;
|
private final IsoDep card;
|
||||||
|
|
||||||
public NFCReader(IsoDep sc) throws IOException {
|
private NFCReader(IsoDep sc) throws IOException {
|
||||||
this.card = sc;
|
this.card = sc;
|
||||||
sc.connect();
|
sc.connect();
|
||||||
card.setTimeout(TIMEOUT);
|
card.setTimeout(TIMEOUT);
|
||||||
@@ -45,13 +45,13 @@ public class NFCReader implements SCReader {
|
|||||||
card.close();
|
card.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int TIMEOUT = 2500;
|
public static final int TIMEOUT = 2500;
|
||||||
@Override
|
@Override
|
||||||
public void powerOn() {
|
public void powerOn() {
|
||||||
/* should already be connected... */
|
/* should already be connected... */
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] SELECT_MF = {(byte) 0x00, (byte) 0xa4, (byte) 0x00, (byte) 0x0C};
|
private static final byte[] SELECT_MF = {(byte) 0x00, (byte) 0xa4, (byte) 0x00, (byte) 0x0C};
|
||||||
private void selectMF() throws IOException {
|
private void selectMF() throws IOException {
|
||||||
byte[] response = card.transceive(SELECT_MF);
|
byte[] response = card.transceive(SELECT_MF);
|
||||||
if (response.length == 2 && response[0] == 0x90 && response[1] == 0x00) {
|
if (response.length == 2 && response[0] == 0x90 && response[1] == 0x00) {
|
||||||
|
|||||||
@@ -23,18 +23,18 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public interface SCReader {
|
public interface SCReader {
|
||||||
|
|
||||||
public void eject() throws IOException;
|
void eject() throws IOException;
|
||||||
|
|
||||||
public void powerOn() throws IOException;
|
void powerOn() throws IOException;
|
||||||
public void powerOff() throws IOException;
|
void powerOff() throws IOException;
|
||||||
public void reset() throws IOException;
|
void reset() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receive ATR from the smart card.
|
* Receive ATR from the smart card.
|
||||||
*
|
*
|
||||||
* @return ATR on success or null in case of an error
|
* @return ATR on success or null in case of an error
|
||||||
*/
|
*/
|
||||||
public byte[] getATR();
|
byte[] getATR();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an APDU to the smart card
|
* Send an APDU to the smart card
|
||||||
@@ -42,5 +42,5 @@ public interface SCReader {
|
|||||||
* @param apdu Data to be sent
|
* @param apdu Data to be sent
|
||||||
* @return response data or null in case of an error
|
* @return response data or null in case of an error
|
||||||
*/
|
*/
|
||||||
public byte[] transmit(byte[] apdu) throws IOException;
|
byte[] transmit(byte[] apdu) throws IOException;
|
||||||
}
|
}
|
||||||
@@ -21,17 +21,12 @@
|
|||||||
<string name="status_off">Powered down the card (cold reset)</string>
|
<string name="status_off">Powered down the card (cold reset)</string>
|
||||||
<string name="status_reset">Resetted the card (warm reset)</string>
|
<string name="status_reset">Resetted the card (warm reset)</string>
|
||||||
<string name="status_unknown">Unable to perform unknown Event</string>
|
<string name="status_unknown">Unable to perform unknown Event</string>
|
||||||
<string name="status_tag_discovered">Contact-less card discovered</string>
|
|
||||||
<string name="status_dummy_start">Using a dummy card to test the connection</string>
|
<string name="status_dummy_start">Using a dummy card to test the connection</string>
|
||||||
<string name="status_default_port">Using default port</string>
|
<string name="status_default_port">Using default port</string>
|
||||||
|
|
||||||
<string name="action_settings">Settings</string>
|
|
||||||
<string name="action_copy">Copy Log</string>
|
<string name="action_copy">Copy Log</string>
|
||||||
<string name="action_delete">Clear Log</string>
|
<string name="action_delete">Clear Log</string>
|
||||||
|
|
||||||
<string name="verbose">Verbose logging</string>
|
|
||||||
<string name="error_tag_lost">Data transmission failed. Is the card still present?</string>
|
|
||||||
|
|
||||||
<string name="scheme_http">http</string>
|
<string name="scheme_http">http</string>
|
||||||
<string name="scheme_https">https</string>
|
<string name="scheme_https">https</string>
|
||||||
<string name="scheme_vpcd">vpcd</string>
|
<string name="scheme_vpcd">vpcd</string>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
<resources>
|
||||||
<tech-list>
|
<tech-list>
|
||||||
<!-- catches both, NfcA and NfcB -->
|
<!-- catches both, NfcA and NfcB -->
|
||||||
<tech>android.nfc.tech.IsoDep</tech>
|
<tech>android.nfc.tech.IsoDep</tech>
|
||||||
|
|||||||
Reference in New Issue
Block a user