mirror of
https://github.com/minibits-cash/minibits_wallet.git
synced 2026-08-11 17:07:44 +00:00
83 lines
3.5 KiB
Diff
83 lines
3.5 KiB
Diff
diff --git a/node_modules/react-native-hce/android/build.gradle b/node_modules/react-native-hce/android/build.gradle
|
|
index 25c6ac4..c997455 100644
|
|
--- a/node_modules/react-native-hce/android/build.gradle
|
|
+++ b/node_modules/react-native-hce/android/build.gradle
|
|
@@ -4,7 +4,8 @@ buildscript {
|
|
|
|
repositories {
|
|
google()
|
|
- jcenter()
|
|
+ //jcenter()
|
|
+ mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
@@ -52,7 +53,7 @@ android {
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
- jcenter()
|
|
+ //jcenter()
|
|
google()
|
|
|
|
def found = false
|
|
diff --git a/node_modules/react-native-hce/android/src/main/java/com/reactnativehce/HceModule.java b/node_modules/react-native-hce/android/src/main/java/com/reactnativehce/HceModule.java
|
|
index 73179ad..b607148 100644
|
|
--- a/node_modules/react-native-hce/android/src/main/java/com/reactnativehce/HceModule.java
|
|
+++ b/node_modules/react-native-hce/android/src/main/java/com/reactnativehce/HceModule.java
|
|
@@ -6,8 +6,11 @@
|
|
|
|
package com.reactnativehce;
|
|
|
|
+import android.app.Activity;
|
|
import android.content.ComponentName;
|
|
import android.content.pm.PackageManager;
|
|
+import android.nfc.NfcAdapter;
|
|
+import android.nfc.cardemulation.CardEmulation;
|
|
|
|
import com.facebook.react.bridge.Arguments;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -109,13 +112,41 @@ public class HceModule extends ReactContextBaseJavaModule {
|
|
}
|
|
|
|
private void enableHceService(Boolean enabled) {
|
|
+ ComponentName cardServiceComponent =
|
|
+ new ComponentName(reactContext.getApplicationContext(), CardService.class);
|
|
+
|
|
reactContext.getApplicationContext().getPackageManager()
|
|
.setComponentEnabledSetting(
|
|
- new ComponentName(reactContext.getApplicationContext(), CardService.class),
|
|
+ cardServiceComponent,
|
|
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
PackageManager.DONT_KILL_APP
|
|
);
|
|
|
|
+ // Claim foreground HCE routing priority while sharing is active (and release it when
|
|
+ // it stops). The AID we emulate (NFC Forum NDEF Tag App, D2760000850101) is also
|
|
+ // registered by other tag/wallet apps (Numo, Google Pay "embedded tag"). Without a
|
|
+ // preferred service the OS can't decide which HostApduService should answer the
|
|
+ // reader's SELECT AID and shows the "Select an app to use" disambiguation dialog on
|
|
+ // this (the emulating) device, which collapses the RF session and fails the read.
|
|
+ // setPreferredService routes the AID to us while our Activity is in the foreground,
|
|
+ // overriding conflict resolution and suppressing that dialog. Best-effort: if the
|
|
+ // adapter/activity is unavailable (e.g. service re-enabled from the constructor with
|
|
+ // no resumed Activity) HCE still works, just without chooser suppression.
|
|
+ try {
|
|
+ NfcAdapter adapter = NfcAdapter.getDefaultAdapter(reactContext.getApplicationContext());
|
|
+ Activity activity = getCurrentActivity();
|
|
+ if (adapter != null && activity != null) {
|
|
+ CardEmulation cardEmulation = CardEmulation.getInstance(adapter);
|
|
+ if (enabled) {
|
|
+ cardEmulation.setPreferredService(activity, cardServiceComponent);
|
|
+ } else {
|
|
+ cardEmulation.unsetPreferredService(activity);
|
|
+ }
|
|
+ }
|
|
+ } catch (Exception e) {
|
|
+ // ignore — preferred-service is an enhancement, not required for HCE to function
|
|
+ }
|
|
+
|
|
this.hceModel.getLastState()
|
|
.postValue(enabled ? HceViewModel.HCE_STATE_ENABLED : HceViewModel.HCE_STATE_DISABLED);
|
|
}
|