Android 14 nordic DFU library

hello,

I'm try to fit my application to Android 14.

my application implement nordic DFU library ( for nrf52833 running  freeRTOS firmware SDK 16 ) version 2.5.0

while running DFU the process run but crash and the complition:

dfu run method:

    private void runDfuOnDevice(BluetoothDevice device) {
DfuServiceInitiator.createDfuNotificationChannel(getActivity().getApplicationContext());
mDfustarter = new DfuServiceInitiator(device.getAddress())
.setDeviceName(device.getName())
.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)
.setKeepBond(false);
//mDfustarter.setPrepareDataObjectDelay(300L);

mDfustarter.setZip(mPath+"/"+mChosenFile);
mDfustarter.setScope(DfuServiceInitiator.SCOPE_APPLICATION);

UIhandler.post(new Runnable() {
@Override
public void run() {
mDfuProgressText.setText(getString(R.string.dfu_starting));
}
});

mDfustarter.start(getActivity(), DfuService.class);
}

and getting:

E FATAL EXCEPTION: main
Process: com.application, PID: 6846
android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{f55800f u0 com.application/.DfuService}
at android.app.ActivityThread.generateForegroundServiceDidNotStartInTimeException(ActivityThread.java:2273)
at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2244)
at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2538)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:222)
at android.os.Looper.loop(Looper.java:314)
at android.app.ActivityThread.main(ActivityThread.java:8671)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:565)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
Caused by: android.app.StackTrace: Last startServiceCommon() call for this service was made here
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1963)
at android.app.ContextImpl.startForegroundService(ContextImpl.java:1917)
at android.content.ContextWrapper.startForegroundService(ContextWrapper.java:841)
at no.nordicsemi.android.dfu.DfuServiceInitiator.start(SourceFile:876)
at com.application.feature.DeviceDFUFrag.runDfuOnDevice(SourceFile:399)
at com.application.feature.DeviceDFUFrag.access$2000(SourceFile:73)
at com.application.feature.DeviceDFUFrag$10.run(SourceFile:511)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
at java.lang.Thread.run(Thread.java:1012)

same code worked on previous android versions and  previous dfu library version

Parents Reply
  • I used dfu version 1.1.0 and android 12.

    It seems like in the dfu Library there is the DFUBaseService class calling startForground service method, it changed in the android 14 so it need to be updated.

    Found a workaround that I don't know if it is the correct way to operate the DFU but I have set the dfu initiator object not to work on the foreground, but i suspect it currpting the DFU process.

Children
Related