Skip to content

Commit 65db10f

Browse files
committed
remove NFC support
1 parent 12051aa commit 65db10f

File tree

7 files changed

+3
-225
lines changed

7 files changed

+3
-225
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<uses-permission android:name="android.permission.CAMERA" />
1313
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
1414
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
15-
<uses-permission android:name="android.permission.NFC" />
1615
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
1716

1817
<application
Lines changed: 1 addition & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
11
package io.scalaproject.vault;
22

3-
import android.app.PendingIntent;
43
import android.content.Context;
5-
import android.content.Intent;
6-
import android.net.Uri;
7-
import android.nfc.FormatException;
8-
import android.nfc.NdefMessage;
9-
import android.nfc.NdefRecord;
10-
import android.nfc.NfcAdapter;
11-
import android.nfc.Tag;
12-
import android.nfc.tech.Ndef;
13-
import android.os.AsyncTask;
14-
import android.os.Bundle;
154
import android.os.Handler;
165
import android.os.Looper;
176
import android.os.PowerManager;
7+
188
import androidx.annotation.CallSuper;
19-
import androidx.annotation.Nullable;
20-
import androidx.fragment.app.Fragment;
21-
import android.widget.Toast;
229

2310
import io.scalaproject.vault.data.BarcodeData;
2411
import io.scalaproject.vault.dialog.ProgressDialog;
25-
import io.scalaproject.vault.fragment.send.SendFragment;
2612
import io.scalaproject.vault.ledger.Ledger;
2713
import io.scalaproject.vault.ledger.LedgerProgressDialog;
2814

29-
import java.io.IOException;
3015

3116
import timber.log.Timber;
3217

@@ -122,175 +107,9 @@ void releaseWakeLock() {
122107
Timber.d("WakeLock released");
123108
}
124109

125-
126-
@Override
127-
protected void onCreate(@Nullable Bundle savedInstanceState) {
128-
super.onCreate(savedInstanceState);
129-
initNfc();
130-
}
131-
132-
@Override
133-
protected void onPostResume() {
134-
super.onPostResume();
135-
if (nfcAdapter != null) {
136-
nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, null, null);
137-
// intercept all techs so we can tell the user their tag is no good
138-
}
139-
}
140-
141-
@Override
142-
protected void onPause() {
143-
Timber.d("onPause()");
144-
if (nfcAdapter != null)
145-
nfcAdapter.disableForegroundDispatch(this);
146-
super.onPause();
147-
}
148-
149-
@Override
150-
protected void onNewIntent(Intent intent) {
151-
super.onNewIntent(intent);
152-
processNfcIntent(intent);
153-
}
154-
155-
// NFC stuff
156-
private NfcAdapter nfcAdapter;
157-
private PendingIntent nfcPendingIntent;
158-
159-
public void initNfc() {
160-
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
161-
if (nfcAdapter == null) // no NFC support
162-
return;
163-
164-
nfcPendingIntent = PendingIntent.getActivity(this, 0,
165-
new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
166-
PendingIntent.FLAG_IMMUTABLE);
167-
}
168-
169-
private void processNfcIntent(Intent intent) {
170-
String action = intent.getAction();
171-
Timber.d("ACTION=%s", action);
172-
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)
173-
|| NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
174-
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
175-
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
176-
Ndef ndef = Ndef.get(tag);
177-
if (ndef == null) {
178-
Toast.makeText(this, getString(R.string.nfc_tag_unsupported), Toast.LENGTH_LONG).show();
179-
return;
180-
}
181-
182-
Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
183-
if (f instanceof ReceiveFragment) {
184-
// We want to write a Tag from the ReceiveFragment
185-
BarcodeData bc = ((ReceiveFragment) f).getBarcodeData();
186-
if (bc != null) {
187-
new AsyncWriteTag(ndef, bc.getUri()).execute();
188-
} // else wallet is not loaded yet or receive is otherwise not ready - ignore
189-
} else if (f instanceof SendFragment) {
190-
// We want to read a Tag for the SendFragment
191-
NdefMessage ndefMessage = ndef.getCachedNdefMessage();
192-
if (ndefMessage == null) {
193-
Toast.makeText(this, getString(R.string.nfc_tag_read_undef), Toast.LENGTH_LONG).show();
194-
return;
195-
}
196-
NdefRecord firstRecord = ndefMessage.getRecords()[0];
197-
Uri uri = firstRecord.toUri(); // we insist on the first record
198-
if (uri == null) {
199-
Toast.makeText(this, getString(R.string.nfc_tag_read_undef), Toast.LENGTH_LONG).show();
200-
} else {
201-
BarcodeData.fromString(uri.toString(), data -> runOnUiThread(() -> {
202-
if (data == null)
203-
Toast.makeText(BaseActivity.this, getString(R.string.nfc_tag_read_undef), Toast.LENGTH_LONG).show();
204-
else
205-
onUriScanned(data);
206-
}));
207-
}
208-
}
209-
}
210-
}
211-
212110
// this gets called only if we get data
213111
@CallSuper
214112
void onUriScanned(BarcodeData barcodeData) {
215113
// do nothing by default yet
216114
}
217-
218-
private BarcodeData barcodeData = null;
219-
220-
private BarcodeData popBarcodeData() {
221-
BarcodeData popped = barcodeData;
222-
barcodeData = null;
223-
return popped;
224-
}
225-
226-
private class AsyncWriteTag extends AsyncTask<Void, Void, Boolean> {
227-
228-
Ndef ndef;
229-
Uri uri;
230-
String errorMessage = null;
231-
232-
AsyncWriteTag(Ndef ndef, Uri uri) {
233-
this.ndef = ndef;
234-
this.uri = uri;
235-
}
236-
237-
@Override
238-
protected void onPreExecute() {
239-
super.onPreExecute();
240-
showProgressDialog(R.string.progress_nfc_write);
241-
}
242-
243-
@Override
244-
protected Boolean doInBackground(Void... params) {
245-
if (params.length != 0) return false;
246-
try {
247-
writeNdef(ndef, uri);
248-
return true;
249-
} catch (IOException | FormatException ex) {
250-
Timber.e(ex);
251-
} catch (IllegalArgumentException ex) {
252-
errorMessage = ex.getMessage();
253-
Timber.d(errorMessage);
254-
} finally {
255-
try {
256-
ndef.close();
257-
} catch (IOException ex) {
258-
Timber.e(ex);
259-
}
260-
}
261-
return false;
262-
}
263-
264-
@Override
265-
protected void onPostExecute(Boolean result) {
266-
super.onPostExecute(result);
267-
if (isDestroyed()) {
268-
return;
269-
}
270-
dismissProgressDialog();
271-
if (!result) {
272-
if (errorMessage != null)
273-
Toast.makeText(getApplicationContext(), errorMessage, Toast.LENGTH_LONG).show();
274-
else
275-
Toast.makeText(getApplicationContext(), getString(R.string.nfc_write_failed), Toast.LENGTH_LONG).show();
276-
} else {
277-
Toast.makeText(getApplicationContext(), getString(R.string.nfc_write_successful), Toast.LENGTH_SHORT).show();
278-
}
279-
}
280-
}
281-
282-
void writeNdef(Ndef ndef, Uri uri) throws IOException, FormatException {
283-
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
284-
if (nfcAdapter == null) return; // no NFC support here
285-
286-
NdefRecord recordNFC = NdefRecord.createUri(uri);
287-
NdefMessage message = new NdefMessage(recordNFC);
288-
ndef.connect();
289-
int tagSize = ndef.getMaxSize();
290-
int msgSize = message.getByteArrayLength();
291-
Timber.d("tagSize=%d, msgSIze=%d, uriSize=%d", tagSize, msgSize, uri.toString().length());
292-
if (tagSize < msgSize)
293-
throw new IllegalArgumentException(getString(R.string.nfc_tag_size, tagSize, msgSize));
294-
ndef.writeNdefMessage(message);
295-
}
296115
}

app/src/main/java/io/scalaproject/vault/ReceiveFragment.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import android.graphics.Canvas;
2828
import android.graphics.drawable.BitmapDrawable;
2929
import android.net.Uri;
30-
import android.nfc.NfcManager;
3130
import android.os.AsyncTask;
3231
import android.os.Bundle;
3332
import androidx.annotation.Nullable;
@@ -237,11 +236,6 @@ public void onClick(View v) {
237236
}
238237
}
239238

240-
View tvNfc = view.findViewById(R.id.tvNfc);
241-
NfcManager manager = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE);
242-
if ((manager != null) && (manager.getDefaultAdapter() != null))
243-
tvNfc.setVisibility(View.VISIBLE);
244-
245239
return view;
246240
}
247241

app/src/main/java/io/scalaproject/vault/WalletActivity.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,12 +1097,9 @@ public void setOnUriScannedListener(OnUriScannedListener onUriScannedListener) {
10971097
@Override
10981098
void onUriScanned(BarcodeData barcodeData) {
10991099
super.onUriScanned(barcodeData);
1100-
boolean processed = false;
1100+
11011101
if (onUriScannedListener != null) {
1102-
processed = onUriScannedListener.onUriScanned(barcodeData);
1103-
}
1104-
if (!processed || (onUriScannedListener == null)) {
1105-
Toast.makeText(this, getString(R.string.nfc_tag_read_what), Toast.LENGTH_LONG).show();
1102+
onUriScannedListener.onUriScanned(barcodeData);
11061103
}
11071104
}
11081105

app/src/main/java/io/scalaproject/vault/fragment/send/SendAddressWizardFragment.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
package io.scalaproject.vault.fragment.send;
2323

2424
import android.content.Context;
25-
import android.nfc.NfcManager;
2625
import android.os.Bundle;
2726
import com.google.android.material.textfield.TextInputLayout;
2827
import androidx.cardview.widget.CardView;
@@ -250,11 +249,6 @@ public void onClick(View v) {
250249
etDummy.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
251250
etDummy.requestFocus();
252251

253-
View tvNfc = view.findViewById(R.id.tvNfc);
254-
NfcManager manager = (NfcManager) getContext().getSystemService(Context.NFC_SERVICE);
255-
if ((manager != null) && (manager.getDefaultAdapter() != null))
256-
tvNfc.setVisibility(View.VISIBLE);
257-
258252
return view;
259253
}
260254

app/src/main/res/layout/fragment_receive.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
116116
android:layout_width="wrap_content"
117117
android:layout_height="match_parent"
118-
android:layout_above="@id/tvNfc"
119118
android:layout_alignParentTop="true"
120119
android:layout_centerHorizontal="true"
121120
android:layout_margin="16dp"
@@ -146,18 +145,6 @@
146145
android:adjustViewBounds="true"
147146
android:background="@color/bg_body" />
148147
</androidx.cardview.widget.CardView>
149-
150-
<TextView
151-
android:id="@+id/tvNfc"
152-
android:layout_width="wrap_content"
153-
android:layout_height="wrap_content"
154-
android:layout_alignParentBottom="true"
155-
android:layout_centerHorizontal="true"
156-
android:drawableStart="@drawable/ic_nfc_black_24dp"
157-
android:drawablePadding="8dp"
158-
android:gravity="center"
159-
android:text="@string/nfc_tag_tap"
160-
android:visibility="visible" />
161148
</RelativeLayout>
162149
</LinearLayout>
163150

app/src/main/res/layout/fragment_send_address.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,6 @@
162162
android:text="@string/send_qr_hint"
163163
android:textSize="20dp" />
164164
</androidx.cardview.widget.CardView>
165-
166-
<TextView
167-
android:id="@+id/tvNfc"
168-
android:layout_width="wrap_content"
169-
android:layout_height="wrap_content"
170-
android:layout_gravity="center"
171-
android:layout_marginTop="8dp"
172-
android:drawableStart="@drawable/ic_nfc_black_24dp"
173-
android:drawablePadding="8dp"
174-
android:gravity="center"
175-
android:text="@string/nfc_tag_tap"
176-
android:visibility="visible" />
177165
</LinearLayout>
178166
</LinearLayout>
179167
</ScrollView>

0 commit comments

Comments
 (0)