Skip to content

Commit 8e3216e

Browse files
authored
Fix potential memory leak in NfcSmartCardReaderManager callback. (#19)
NFC-119 Fix potential memory leak in NfcSmartCardReaderManager callback.
1 parent bbbdd86 commit 8e3216e

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

libs/smart-card-reader-lib/src/main/java/ee/ria/DigiDoc/smartcardreader/nfc/NfcSmartCardReaderManager.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void disableNfcReaderMode() {
4747
}
4848
this.nfcAdapter = null;
4949
this.currentActivity = null;
50+
this.clientCallback = null;
5051
}
5152

5253
/**
@@ -96,20 +97,14 @@ public NfcStatus detectNfcStatus(Activity activity) {
9697
* @return - status if the NFC is available / enabled / active
9798
*/
9899
public NfcStatus startDiscovery(Activity activity, NfcSmartCardReaderCallback callback) {
99-
this.currentActivity = activity;
100-
this.nfcAdapter = NfcAdapter.getDefaultAdapter(this.currentActivity);
101-
102-
if (this.nfcAdapter == null) {
103-
return NfcStatus.NFC_NOT_SUPPORTED;
104-
}
105-
106-
if (!this.nfcAdapter.isEnabled()) {
107-
return NfcStatus.NFC_NOT_ACTIVE;
108-
}
100+
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity);
101+
if (adapter == null) return NfcStatus.NFC_NOT_SUPPORTED;
102+
if (!adapter.isEnabled()) return NfcStatus.NFC_NOT_ACTIVE;
109103

104+
this.currentActivity = activity;
105+
this.nfcAdapter = adapter;
110106
this.clientCallback = callback;
111-
this.nfcAdapter.enableReaderMode(
112-
this.currentActivity, this, NfcAdapter.FLAG_READER_NFC_A, null);
107+
adapter.enableReaderMode(activity, this, NfcAdapter.FLAG_READER_NFC_A, null);
113108
return NfcStatus.NFC_ACTIVE;
114109
}
115110

0 commit comments

Comments
 (0)