Compare commits

Author SHA1 Message Date
Andrea Franz ee5c3709c6 add CardManager thread 2018-09-07 19:47:40 +02:00
Andrea Franz 74b0ea6a07 make textview text selectable 2018-09-07 16:38:19 +02:00
Andrea Franz d56d2df760 remove old cap file 2018-09-07 15:19:19 +02:00
Bitgamma 8480ff4173 Merge pull request #1 from status-im/performance-tests
Performance tests
2018-09-07 14:47:00 +03:00
7 changed files with 65 additions and 6 deletions
@@ -39,7 +39,7 @@ public class APDUResponse {
public APDUResponse checkOK() throws APDUException {
if (!isOK()) {
throw new APDUException("Unexpected error SW");
throw new APDUException(this.getSw(), "Unexpected error SW");
}
return this;
@@ -29,6 +29,7 @@ public class MainActivity extends AppCompatActivity implements NfcAdapter.Reader
private Button buttonPerfTest;
private Tag tag;
private boolean installationAttempted;
private TagManager tagManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -36,6 +37,8 @@ public class MainActivity extends AppCompatActivity implements NfcAdapter.Reader
setContentView(R.layout.activity_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
Logger.setListener(this);
this.tagManager = new TagManager(nfcAdapter);
this.tagManager.start();
textView = (TextView) findViewById(R.id.textView);
textView.setMovementMethod(new ScrollingMovementMethod());
buttonInstall = (Button) findViewById(R.id.buttonInstall);
@@ -102,7 +105,7 @@ public class MainActivity extends AppCompatActivity implements NfcAdapter.Reader
public void onResume() {
super.onResume();
if (nfcAdapter != null) {
nfcAdapter.enableReaderMode(this, this,
nfcAdapter.enableReaderMode(this, this.tagManager,
NfcAdapter.FLAG_READER_NFC_A |
NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK,
null);
@@ -119,6 +122,7 @@ public class MainActivity extends AppCompatActivity implements NfcAdapter.Reader
@Override
public void onTagDiscovered(Tag tag) {
Logger.log("tag found");
try {
start(tag);
} catch (final IOException e) {
@@ -133,7 +137,6 @@ public class MainActivity extends AppCompatActivity implements NfcAdapter.Reader
private void start(Tag tag) throws IOException {
this.tag = tag;
Logger.log("--------------------------\ntag found");
this.enableButtons();
}
@@ -0,0 +1,54 @@
package im.status.applet_installer_test.appletinstaller;
import android.nfc.NfcAdapter;
import android.nfc.Tag;
import android.nfc.tech.IsoDep;
import android.util.Log;
import java.io.IOException;
public class TagManager extends Thread implements NfcAdapter.ReaderCallback {
NfcAdapter nfcAdapter;
IsoDep isoDep;
public TagManager(NfcAdapter nfcAdapter) {
this.nfcAdapter = nfcAdapter;
}
public boolean isConnected() {
return this.isoDep != null && this.isoDep.isConnected();
}
public void run() {
boolean connected = this.isConnected();
while(true) {
boolean newConnected = this.isConnected();
if (newConnected != connected) {
connected = newConnected;
Logger.log("tag " + (connected ? "connected" : "disconnected"));
if (!newConnected) {
this.isoDep = null;
}
}
try {
this.sleep(50);
} catch (InterruptedException e) {
Logger.log("error in TagManager thread: " + e.getMessage());
this.interrupt();
}
}
}
@Override
public void onTagDiscovered(Tag tag) {
this.isoDep = IsoDep.get(tag);
try {
this.isoDep.connect();
} catch (IOException e) {
Logger.log("error connecting to tag");
}
}
}
@@ -299,7 +299,7 @@ public class SecureChannelSession {
* @return the raw card response
* @throws IOException communication error
*/
public void unpairOthers(CardChannel apduChannel) throws IOException {
public void unpairOthers(CardChannel apduChannel) throws IOException, APDUException {
for (int i = 0; i < PAIRING_MAX_CLIENT_COUNT; i++) {
if (i != pairingIndex) {
APDUCommand openSecureChannel = protectedCommand(0x80, INS_UNPAIR, i, 0, new byte[0]);
@@ -1,6 +1,7 @@
package im.status.applet_installer_test.appletinstaller.apducommands;
import im.status.applet_installer_test.appletinstaller.APDUCommand;
import im.status.applet_installer_test.appletinstaller.APDUException;
import im.status.applet_installer_test.appletinstaller.APDUResponse;
import im.status.applet_installer_test.appletinstaller.CardChannel;
import org.spongycastle.jce.interfaces.ECPrivateKey;
@@ -143,7 +144,7 @@ public class WalletAppletCommandSet {
/**
* Unpair all other clients.
*/
public void unpairOthers() throws IOException {
public void unpairOthers() throws IOException, APDUException {
secureChannel.unpairOthers(apduChannel);
}
+2 -1
View File
@@ -15,7 +15,8 @@
android:text="\n"
android:scrollbars="vertical"
android:padding="10dp"
android:gravity="bottom" />
android:gravity="bottom"
android:textIsSelectable="true" />
<Button
Binary file not shown.