Skip to content

Commit 7547280

Browse files
skjolberCopilot
andauthored
Improve bulk transceive metadata (#64)
* Improve bulk transceive metadata * Fix typos * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Adjust * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix * Adjust --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d2156b7 commit 7547280

44 files changed

Lines changed: 468 additions & 198 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎nfc/core/src/main/java/no/entur/android/nfc/hce/protocol/ResponseAdpuProtocolIsoDep.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public <T> T transceive(Parcelable data) throws IOException {
6060
}
6161

6262
@Override
63-
public boolean supportsTransceive(Class c) throws IOException {
64-
return false;
63+
public <T> T transceiveMetadata(Parcelable c) throws IOException {
64+
return null;
6565
}
6666

6767
@Override

‎nfc/external-acs/src/main/java/no/entur/android/nfc/external/acs/reader/command/ACRReaderBluetoothTechnology.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.entur.android.nfc.external.acs.reader.command;
22

3+
import android.os.Parcelable;
34
import android.os.RemoteException;
45

56
import no.entur.android.nfc.external.service.tag.ReaderTechnology;
@@ -53,8 +54,7 @@ public int reconnect(int handle) throws RemoteException {
5354
}
5455

5556
@Override
56-
public boolean supportsTransceiveParcelable(String className) {
57-
return false;
57+
public Parcelable transceiveMetadata(Parcelable parcelable) {
58+
return null;
5859
}
59-
6060
}

‎nfc/external-acs/src/main/java/no/entur/android/nfc/external/acs/reader/command/ACRReaderTechnology.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.entur.android.nfc.external.acs.reader.command;
22

3+
import android.os.Parcelable;
34
import android.os.RemoteException;
45

56
import com.acs.smartcard.ReaderException;
@@ -73,8 +74,7 @@ public int reconnect(int handle) throws RemoteException {
7374
}
7475

7576
@Override
76-
public boolean supportsTransceiveParcelable(String className) {
77-
return false;
77+
public Parcelable transceiveMetadata(Parcelable parcelable) {
78+
return null;
7879
}
79-
8080
}

‎nfc/external-minova/src/main/java/no/entur/android/nfc/external/minova/reader/MinovaReaderTechnology.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.entur.android.nfc.external.minova.reader;
22

3+
import android.os.Parcelable;
34
import android.os.RemoteException;
45

56
import no.entur.android.nfc.external.service.tag.ReaderTechnology;
@@ -53,7 +54,7 @@ public int reconnect(int handle) throws RemoteException {
5354
}
5455

5556
@Override
56-
public boolean supportsTransceiveParcelable(String className) {
57-
return false;
57+
public Parcelable transceiveMetadata(Parcelable parcelable) {
58+
return null;
5859
}
5960
}

‎nfc/external/src/main/java/no/entur/android/nfc/external/service/tag/INFcTagBinder.java‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no.entur.android.nfc.external.service.tag;
22

33
import android.nfc.NdefMessage;
4+
import android.os.Parcelable;
45
import android.os.RemoteException;
56

67
import org.slf4j.Logger;
@@ -13,6 +14,8 @@
1314
import no.entur.android.nfc.wrapper.ErrorCodes;
1415
import no.entur.android.nfc.wrapper.INfcTag;
1516
import no.entur.android.nfc.wrapper.ParcelableTransceive;
17+
import no.entur.android.nfc.wrapper.ParcelableTransceiveMetadata;
18+
import no.entur.android.nfc.wrapper.ParcelableTransceiveMetadataResult;
1619
import no.entur.android.nfc.wrapper.ParcelableTransceiveResult;
1720
import no.entur.android.nfc.wrapper.TagImpl;
1821
import no.entur.android.nfc.wrapper.TransceiveResult;
@@ -125,11 +128,14 @@ public ParcelableTransceiveResult parcelableTranscieve(int nativeHandle, Parcela
125128
}
126129

127130
@Override
128-
public boolean supportsTransceiveParcelable(String className) throws RemoteException {
131+
public ParcelableTransceiveMetadataResult parcelableTransceiveMetadata(ParcelableTransceiveMetadata data) throws RemoteException {
129132
if (readerTechnology == null) {
130133
throw new RemoteException(NO_READER_MSG);
131134
}
132-
return readerTechnology.supportsTransceiveParcelable(className);
135+
136+
Parcelable parcelable = readerTechnology.transceiveMetadata(data.getRequestData());
137+
138+
return new ParcelableTransceiveMetadataResult(parcelable);
133139
}
134140

135141
public int getMaxTransceiveLength(int technology) throws RemoteException {

‎nfc/external/src/main/java/no/entur/android/nfc/external/service/tag/ReaderTechnology.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.entur.android.nfc.external.service.tag;
22

3+
import android.os.Parcelable;
34
import android.os.RemoteException;
45

56
public interface ReaderTechnology {
@@ -18,5 +19,5 @@ public interface ReaderTechnology {
1819

1920
int reconnect(int handle) throws RemoteException;
2021

21-
boolean supportsTransceiveParcelable(String className);
22+
Parcelable transceiveMetadata(Parcelable parcelable);
2223
}

‎nfc/wrapper-test/src/main/java/no/entur/android/nfc/wrapper/test/binder/DefaultINFcTagBinder.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import no.entur.android.nfc.wrapper.INfcTag;
77
import no.entur.android.nfc.wrapper.ParcelableTransceive;
8+
import no.entur.android.nfc.wrapper.ParcelableTransceiveMetadata;
9+
import no.entur.android.nfc.wrapper.ParcelableTransceiveMetadataResult;
810
import no.entur.android.nfc.wrapper.ParcelableTransceiveResult;
911
import no.entur.android.nfc.wrapper.TagImpl;
1012
import no.entur.android.nfc.wrapper.TransceiveResult;
@@ -147,8 +149,8 @@ public ParcelableTransceiveResult parcelableTranscieve(int nativeHandle, Parcela
147149
}
148150

149151
@Override
150-
public boolean supportsTransceiveParcelable(String className) throws RemoteException {
151-
return delegate.supportsTransceiveParcelable(className);
152+
public ParcelableTransceiveMetadataResult parcelableTransceiveMetadata(ParcelableTransceiveMetadata data) throws RemoteException {
153+
return delegate.parcelableTransceiveMetadata(data);
152154
}
153155

154156
public boolean isLost() {

‎nfc/wrapper-test/src/main/java/no/entur/android/nfc/wrapper/test/binder/INFcTagBinder.java‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.List;
1010

1111
import no.entur.android.nfc.wrapper.ParcelableTransceive;
12+
import no.entur.android.nfc.wrapper.ParcelableTransceiveMetadata;
13+
import no.entur.android.nfc.wrapper.ParcelableTransceiveMetadataResult;
1214
import no.entur.android.nfc.wrapper.ParcelableTransceiveResult;
1315
import no.entur.android.nfc.wrapper.test.tech.MockBasicTagTechnology;
1416
import no.entur.android.nfc.wrapper.test.tech.MockIsoDep;
@@ -315,20 +317,15 @@ public ParcelableTransceiveResult parcelableTranscieve(ParcelableTransceive data
315317
return new ParcelableTransceiveResult(TransceiveResult.RESULT_FAILURE, null);
316318
}
317319

318-
public boolean supportsTransceiveParcelable(String className) throws RemoteException {
319-
if(connected == -1) {
320-
throw new RemoteException("No connected tag technology");
321-
}
322-
320+
public ParcelableTransceiveMetadataResult parcelableTransceiveMetadata(ParcelableTransceiveMetadata data) {
323321
try {
324-
if(connected == TagTechnology.ISO_DEP) {
325-
return isoDep.supportsTransceiveParcelable(className);
326-
}
322+
Parcelable transceive = isoDep.transceiveMetadata(data.getRequestData());
323+
324+
return new ParcelableTransceiveMetadataResult(transceive);
327325
} catch (Exception e) {
328326
Log.d(LOG_TAG, "Transceive problem", e);
329327
}
330-
return false;
331-
}
332-
333328

329+
return new ParcelableTransceiveMetadataResult();
330+
}
334331
}

‎nfc/wrapper-test/src/main/java/no/entur/android/nfc/wrapper/test/tech/MockIsoDep.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
public class MockIsoDep extends MockBasicTagTechnologyImpl {
1111

12-
private static final String LOG_TAG = MockIsoDep.class.getName();
13-
1412
private byte[] hiLayerResponse;
1513
private byte[] historicalBytes;
1614

@@ -41,12 +39,11 @@ public void setMockParcelableTransceive(MockParcelableTransceive mockParcelableT
4139
this.mockParcelableTransceive = mockParcelableTransceive;
4240
}
4341

44-
4542
public <T> T transceive(Parcelable parcelable) throws IOException {
46-
return (T)this.mockParcelableTransceive.parcelableTranscieve(parcelable);
43+
return (T)this.mockParcelableTransceive.transceive(parcelable);
4744
}
4845

49-
public boolean supportsTransceiveParcelable(String cls) throws IOException {
50-
return this.mockParcelableTransceive.supportsTransceiveParcelable(cls);
46+
public <T> T transceiveMetadata(Parcelable parcelable) throws IOException {
47+
return (T)this.mockParcelableTransceive.transceiveMetadata(parcelable);
5148
}
5249
}

‎nfc/wrapper-test/src/main/java/no/entur/android/nfc/wrapper/test/tech/transceive/ListMockParcelableTransceive.java‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,19 @@ public static class Builder {
5151

5252
private byte[] errorResponse;
5353

54-
private Predicate<String> supportedClass = (c) -> true ;
54+
private Parcelable parcelableMetadata = null;
5555

5656
public Builder withErrorResponse(byte[] errorResponse) {
5757
this.errorResponse = errorResponse;
5858
return this;
5959
}
6060

61-
public Builder withSupportedClass(Predicate<String> supportedClass) {
62-
this.supportedClass = supportedClass;
61+
public Builder withParcelableMetadata(Parcelable parcelableMetadata) {
62+
this.parcelableMetadata = parcelableMetadata;
6363
return this;
6464
}
6565

66+
6667
public Builder withErrorResponse(String errorResponse) {
6768
this.errorResponse = MockBasicTagTechnologyImpl.hex(errorResponse);
6869
return this;
@@ -151,7 +152,7 @@ public ListMockParcelableTransceive build() {
151152
if(errorResponse == null) {
152153
throw new IllegalStateException();
153154
}
154-
return new ListMockParcelableTransceive(transceiveList, errorResponse, supportedClass);
155+
return new ListMockParcelableTransceive(transceiveList, errorResponse, parcelableMetadata);
155156
}
156157

157158
}
@@ -161,12 +162,11 @@ public ListMockParcelableTransceive build() {
161162
private final List<Transceive> transceiveList;
162163
private int index = 0;
163164

164-
private Predicate<String> supportedClass;
165-
166-
public ListMockParcelableTransceive(List<Transceive> transceiveList, byte[] errorResponse, Predicate<String> supportedClass) {
165+
private Parcelable parcelableMetadata;
166+
public ListMockParcelableTransceive(List<Transceive> transceiveList, byte[] errorResponse, Parcelable parcelableMetadata) {
167167
this.transceiveList = transceiveList;
168168
this.errorResponse = errorResponse;
169-
this.supportedClass = supportedClass;
169+
this.parcelableMetadata = parcelableMetadata;
170170
}
171171

172172
public byte[] transceive(byte[] data, boolean raw) throws IOException {
@@ -190,7 +190,7 @@ public byte[] transceive(byte[] data, boolean raw) throws IOException {
190190
}
191191

192192
@Override
193-
public <T> T parcelableTranscieve(Parcelable data) throws IOException {
193+
public <T> T transceive(Parcelable data) throws IOException {
194194
if (index >= transceiveList.size()) {
195195
index = 0;
196196
return null;
@@ -211,8 +211,8 @@ public <T> T parcelableTranscieve(Parcelable data) throws IOException {
211211
}
212212

213213
@Override
214-
public boolean supportsTransceiveParcelable(String className) throws IOException {
215-
return supportedClass.test(className);
214+
public Parcelable transceiveMetadata(Parcelable data) {
215+
return parcelableMetadata;
216216
}
217217

218218
}

0 commit comments

Comments
 (0)