From e96577b4e7c3f692d38f6c20f21c2bc1b24077a0 Mon Sep 17 00:00:00 2001 From: nicolas-meilan Date: Wed, 25 Sep 2024 00:08:01 -0300 Subject: [PATCH] Fix @ledgerhq/react-native-hid for android sdk34 issue: https://github.com/LedgerHQ/ledger-live/issues/7786 --- .changeset/three-lions-smoke.md | 9 +++++++++ .../java/com/ledgerwallet/hid/ReactHIDModule.java | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/three-lions-smoke.md diff --git a/.changeset/three-lions-smoke.md b/.changeset/three-lions-smoke.md new file mode 100644 index 000000000000..f0e4d7623a18 --- /dev/null +++ b/.changeset/three-lions-smoke.md @@ -0,0 +1,9 @@ +--- +"@ledgerhq/react-native-hid": patch +--- + +Android sdk 34 give the following error when use transporter from the lib @ledger/react-native-hid: + +One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts. + +To fix this bug is needed call getReactApplicationContext() with the Context.RECEIVER_NOT_EXPORTED attribute. https://github.com/LedgerHQ/ledger-live/issues/7786 diff --git a/libs/ledgerjs/packages/react-native-hid/android/src/main/java/com/ledgerwallet/hid/ReactHIDModule.java b/libs/ledgerjs/packages/react-native-hid/android/src/main/java/com/ledgerwallet/hid/ReactHIDModule.java index 349bf3982c88..3acc5c859ade 100755 --- a/libs/ledgerjs/packages/react-native-hid/android/src/main/java/com/ledgerwallet/hid/ReactHIDModule.java +++ b/libs/ledgerjs/packages/react-native-hid/android/src/main/java/com/ledgerwallet/hid/ReactHIDModule.java @@ -7,6 +7,7 @@ import android.content.IntentFilter; import android.hardware.usb.UsbDevice; import android.hardware.usb.UsbManager; +import android.os.Build; import androidx.annotation.NonNull; @@ -58,6 +59,11 @@ public void onReceive(Context context, Intent intent) { .emit(event, buildMapFromDevice(device)); } }; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getReactApplicationContext().registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED); + return; + } + getReactApplicationContext().registerReceiver(receiver, filter); } @@ -213,7 +219,12 @@ public void onReceive(Context context, Intent intent) { unregisterReceiver(this); } }; - getReactApplicationContext().registerReceiver(receiver, intFilter); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + getReactApplicationContext().registerReceiver(receiver, intFilter, Context.RECEIVER_NOT_EXPORTED); + return; + } + + getReactApplicationContext().registerReceiver(receiver, intFilter, Context.RECEIVER_NOT_EXPORTED); } private void unregisterReceiver(BroadcastReceiver receiver) {