Laerdal / Laerdal.Dfu

Xamarin binding library around @NordicSemiconductor's DFU library.
BSD 3-Clause "New" or "Revised" License
18 stars 17 forks source link

Android SecurityException when starting update #30

Open Silverdark opened 6 months ago

Silverdark commented 6 months ago

Describe the bug When trying to start an update with DFU a SecurityException is thrown.

Java.Lang.RuntimeException: Unable to create service crc640fd658db7faaed21.DfuServiceDelegate: java.lang.SecurityException: com.appid: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
 ---> Java.Lang.SecurityException: com.appid: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
 ---> Android.OS.RemoteException: Remote stack trace:
    at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:14008)
    at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2585)
    at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2763)
    at android.os.Binder.execTransactInternal(Binder.java:1363)
    at android.os.Binder.execTransact(Binder.java:1304)
...

To Reproduce Steps to reproduce the behavior:

Call the Start method for the DFU installation:

var installation = new DfuInstallation(deviceId, file);
installation.Start(new DfuConfiguration());

Expected behavior Update with DFU should start.

Smartphone:

Additional context

As far as I understand this happens only if the target SDK level is at 34 and your phone has Android 14 installed. Looks like an issue with the Android Nordic library https://github.com/NordicSemiconductor/Android-DFU-Library/issues/412 maybe it is already fixed with an update.

ISSPRO-Eng commented 3 months ago

@Silverdark @ksidirop-laerdal Looks like Android Bindings package just needs to be updated to target the updated Nordic package since they released a fix a while ago

Silverdark commented 3 months ago

@ISSPRO-Eng I tried to update the Nordic package but it fails, see https://github.com/NordicSemiconductor/Android-DFU-Library/issues/428

ISSPRO-Eng commented 3 months ago

@Silverdark Okay will do. I am still pretty green to nuget packages so may be some time

christian-strydom commented 1 month ago

I managed to get the DFU library running smoothly on MAUI Android. But we're still busy porting our one Xamarin app to MAUI and will only be done next year due to the sheer size of the app. The deadlines seemed fine until we realised that we're not targeting Android 14 SDK yet, and need to do so before August 31st.

I've taken the DFU aar and gson jar that's on the MAUI package and built a new Xamarin bindings NuGet, but unfortunately still running into the RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED exception on Xamarin but not on MAUI. Also tried to build my own aar from the latest native Nordic Android library, but building a Xamarin bindings nuget with that unfortunately results in an exception when trying to build my project with the bindings nuget:

Error in obj\Debug\130\lp\154\jl\bin\classes.jar:no/nordicsemi/android/dfu/BaseButtonlessDfuImpl$ButtonlessBluetoothCallback.class:
java.lang.NullPointerException
 Cannot invoke "String.length()" because "<parameter1>" is null
Compilation failed with an internal error.
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\130\lp\154\jl\bin\classes.jar

I've been trying to warn the company ever since NET 8 official release that we need to start with porting sooner, knowing that we'd end up in a situation like this because none of the Xamarin libraries are maintained anymore. 😔

I don't mean to hijack this thread, but any advice would be greatly appreciated. Thanks in advance.