diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java
index e922600..66289b0 100644
--- a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java
+++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/MainActivity.java
@@ -29,6 +29,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.LocalBroadcastManager;
@@ -96,9 +97,13 @@ public class MainActivity extends AppCompatActivity {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- Snackbar.make(view, "Scheduled re-installation of all applets...", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show();
- SimulatorService.destroySimulator(getApplicationContext());
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+ String emulator = SP.getString("emulator", "");
+ if (emulator != getString(R.string.vicc)) {
+ Snackbar.make(view, "Scheduled re-installation of all applets...", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show();
+ SimulatorService.destroySimulator(getApplicationContext());
+ }
}
});
diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SettingsActivity.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SettingsActivity.java
index 2329571..b3adc73 100644
--- a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SettingsActivity.java
+++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SettingsActivity.java
@@ -175,11 +175,16 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
// to their values. When their values change, their summaries are
// updated to reflect the new value, per the Android Design
// guidelines.
+ bindPreferenceSummaryToValue(findPreference("emulator"));
+
bindPreferenceSummaryToValue(findPreference("activate_helloworld"));
bindPreferenceSummaryToValue(findPreference("activate_openpgp"));
bindPreferenceSummaryToValue(findPreference("activate_oath"));
bindPreferenceSummaryToValue(findPreference("activate_isoapplet"));
bindPreferenceSummaryToValue(findPreference("activate_gidsapplet"));
+
+ bindPreferenceSummaryToValue(findPreference("hostname"));
+ bindPreferenceSummaryToValue(findPreference("port"));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
diff --git a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java
index ae8b7c3..9cbf2ad 100644
--- a/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java
+++ b/ACardEmulator/app/src/main/java/com/vsmartcard/acardemulator/SimulatorService.java
@@ -47,10 +47,8 @@ import com.mysmartlogon.gidsApplet.GidsApplet;
public class SimulatorService extends HostApduService {
- private static final boolean useVPCD = false;
public static final int DEFAULT_PORT = 35963;
- private static final String hostname = "192.168.42.158";
- private int port = DEFAULT_PORT;
+ private static final String DEFAULT_HOSTNAME = "10.0.2.2";
private static Socket socket;
private static InputStream inputStream;
@@ -66,6 +64,25 @@ public class SimulatorService extends HostApduService {
private static Simulator simulator = null;
private static boolean do_destroy = false;
+ private boolean useVPCD() {
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
+ String emulator = SP.getString("emulator", "");
+ if (emulator.equals(getString(R.string.vicc)))
+ return true;
+
+ return false;
+ }
+
+ private int port() {
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
+ return Integer.parseInt(SP.getString("port", Integer.toString(DEFAULT_PORT)));
+ }
+
+ private String hostname() {
+ SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
+ return SP.getString("hostname", DEFAULT_HOSTNAME);
+ }
+
private void createSimulator() {
String aid, name, extra_install = "", extra_error = "";
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(this);
@@ -154,7 +171,7 @@ public class SimulatorService extends HostApduService {
do_destroy();
Log.d("", "Begin transaction");
- if (useVPCD) {
+ if (useVPCD()) {
if (socket == null) {
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
@@ -202,7 +219,7 @@ public class SimulatorService extends HostApduService {
i.putExtra(EXTRA_CAPDU, Util.byteArrayToHexString(capdu));
try {
- if (useVPCD) {
+ if (useVPCD()) {
rapdu = transmit(capdu);
} else {
rapdu = simulator.transmitCommand(capdu);
@@ -231,7 +248,7 @@ public class SimulatorService extends HostApduService {
switch (reason) {
case DEACTIVATION_LINK_LOSS:
i.putExtra(EXTRA_DESELECT, "link lost");
- if (useVPCD)
+ if (useVPCD())
try {
sendPowerOff();
} catch (IOException e) {
@@ -241,7 +258,7 @@ public class SimulatorService extends HostApduService {
break;
case DEACTIVATION_DESELECTED:
i.putExtra(EXTRA_DESELECT, "deactivated");
- if (useVPCD)
+ if (useVPCD())
try {
sendReset();
} catch (IOException e) {
@@ -250,7 +267,7 @@ public class SimulatorService extends HostApduService {
}
break;
}
- if (useVPCD) {
+ if (useVPCD()) {
//vpcdDisconnect();
}
@@ -316,6 +333,8 @@ public class SimulatorService extends HostApduService {
}
private void vpcdConnect() throws IOException {
+ String hostname = hostname();
+ int port = port();
Log.d("", "Connecting to " + hostname + ":" + Integer.toString(port));
socket = new Socket(InetAddress.getByName(hostname), port);
outputStream = socket.getOutputStream();
diff --git a/ACardEmulator/app/src/main/res/values/strings.xml b/ACardEmulator/app/src/main/res/values/strings.xml
index c87a240..515bae0 100644
--- a/ACardEmulator/app/src/main/res/values/strings.xml
+++ b/ACardEmulator/app/src/main/res/values/strings.xml
@@ -38,5 +38,14 @@
\n
Place your device on a contact-less reader. When the reader issues a SELECT command for one of the application identifiers above, the emulator creates the appropriate applet. The emulated applet will then handle all subsequent APDUs.
Settings
+
+ - @string/jcardsim
+ - @string/vicc
+
+ Builtin Java Card Simulator
+ Remote Virtual Smart Card
+ If you choose the virtual smart card (VICC) as emulator, you need to start the it on your computer with the `--reversed` flag and configure the connection parameters here accordingly.
+ VICC Port
+ VICC Hostname
diff --git a/ACardEmulator/app/src/main/res/xml/settings.xml b/ACardEmulator/app/src/main/res/xml/settings.xml
index 8cafba9..22034c6 100644
--- a/ACardEmulator/app/src/main/res/xml/settings.xml
+++ b/ACardEmulator/app/src/main/res/xml/settings.xml
@@ -1,8 +1,17 @@
+
+
+ android:title="@string/jcardsim"
+ android:key="jc_settings"
+ >
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file