You've already forked vsmartcard
mirror of
https://github.com/librekeys/vsmartcard.git
synced 2026-04-14 08:46:17 -07:00
minor code improvements
This commit is contained in:
+3
-2
@@ -33,6 +33,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.Editable;
|
||||
import android.text.Layout;
|
||||
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
|
||||
public void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
textViewVPCDStatus.setText(savedInstanceState.getCharSequence(saved_status_key));
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ package com.vsmartcard.remotesmartcardreader.app;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
public class MessageSender {
|
||||
class MessageSender {
|
||||
public static final int MESSAGE_CONNECTED = 0;
|
||||
public static final int MESSAGE_DISCONNECTED = 1;
|
||||
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_CAPDU = 7;
|
||||
public static final int MESSAGE_RAPDU = 8;
|
||||
private Handler handler;
|
||||
private final Handler handler;
|
||||
|
||||
public MessageSender(Handler handler) {
|
||||
this.handler = handler;
|
||||
@@ -56,7 +56,7 @@ public class MessageSender {
|
||||
}
|
||||
|
||||
public void sendDisconnected(String details) {
|
||||
sendMessage(MESSAGE_DISCONNECTED, details);
|
||||
sendMessage(MESSAGE_DISCONNECTED, "");
|
||||
}
|
||||
|
||||
public void sendError(String details) {
|
||||
|
||||
+6
-14
@@ -24,7 +24,7 @@ import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
public class Settings {
|
||||
class Settings {
|
||||
|
||||
private static final String KEY_VPCD_HOST = "hostname";
|
||||
private static final String KEY_VPCD_PORT = "port";
|
||||
@@ -44,19 +44,11 @@ public class Settings {
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void setBoolean(String key, boolean value) {
|
||||
Editor editor = settings.edit();
|
||||
editor.putBoolean(key, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public void setVPCDHost(String hostname) {
|
||||
setString(KEY_VPCD_HOST, hostname);
|
||||
}
|
||||
|
||||
public void setVPCDPort(String port) {
|
||||
setString(KEY_VPCD_PORT, port);
|
||||
}
|
||||
// private void setBoolean(String key, boolean value) {
|
||||
// Editor editor = settings.edit();
|
||||
// editor.putBoolean(key, value);
|
||||
// editor.apply();
|
||||
// }
|
||||
|
||||
public void setVPCDSettings(String hostname, String port) {
|
||||
Editor editor = settings.edit();
|
||||
|
||||
+6
-6
@@ -30,16 +30,16 @@ import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
public class VPCDWorker implements Runnable, Closeable {
|
||||
public static int DEFAULT_PORT = 35963;
|
||||
private int port;
|
||||
private String hostname;
|
||||
private SCReader reader;
|
||||
class VPCDWorker implements Runnable, Closeable {
|
||||
public static final int DEFAULT_PORT = 35963;
|
||||
private final int port;
|
||||
private final String hostname;
|
||||
private final SCReader reader;
|
||||
private Socket socket;
|
||||
private InputStream inputStream;
|
||||
private OutputStream outputStream;
|
||||
private boolean doRun;
|
||||
private MessageSender messageSender;
|
||||
private final MessageSender messageSender;
|
||||
|
||||
public VPCDWorker(String hostname, int port, SCReader reader, Handler handler) {
|
||||
this.hostname = hostname;
|
||||
|
||||
+4
-4
@@ -32,9 +32,9 @@ import java.io.IOException;
|
||||
|
||||
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;
|
||||
sc.connect();
|
||||
card.setTimeout(TIMEOUT);
|
||||
@@ -45,13 +45,13 @@ public class NFCReader implements SCReader {
|
||||
card.close();
|
||||
}
|
||||
|
||||
public static int TIMEOUT = 2500;
|
||||
public static final int TIMEOUT = 2500;
|
||||
@Override
|
||||
public void powerOn() {
|
||||
/* 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 {
|
||||
byte[] response = card.transceive(SELECT_MF);
|
||||
if (response.length == 2 && response[0] == 0x90 && response[1] == 0x00) {
|
||||
|
||||
+6
-6
@@ -23,18 +23,18 @@ import java.io.IOException;
|
||||
|
||||
public interface SCReader {
|
||||
|
||||
public void eject() throws IOException;
|
||||
void eject() throws IOException;
|
||||
|
||||
public void powerOn() throws IOException;
|
||||
public void powerOff() throws IOException;
|
||||
public void reset() throws IOException;
|
||||
void powerOn() throws IOException;
|
||||
void powerOff() throws IOException;
|
||||
void reset() throws IOException;
|
||||
|
||||
/**
|
||||
* Receive ATR from the smart card.
|
||||
*
|
||||
* @return ATR on success or null in case of an error
|
||||
*/
|
||||
public byte[] getATR();
|
||||
byte[] getATR();
|
||||
|
||||
/**
|
||||
* Send an APDU to the smart card
|
||||
@@ -42,5 +42,5 @@ public interface SCReader {
|
||||
* @param apdu Data to be sent
|
||||
* @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_reset">Resetted the card (warm reset)</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_default_port">Using default port</string>
|
||||
|
||||
<string name="action_settings">Settings</string>
|
||||
<string name="action_copy">Copy 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_https">https</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>
|
||||
<!-- catches both, NfcA and NfcB -->
|
||||
<tech>android.nfc.tech.IsoDep</tech>
|
||||
|
||||
Reference in New Issue
Block a user