Crash on DFU update on Android 12 - mutable flag missing on PendingIntent
See original GitHub issueDFU Bootloader version (please complete the following information):
- SDK version: 31
- Bonding used: yes
- Library version: 1.11.1
Device information (please complete the following information):
- Device: Pixel 4A
- OS: Android 12
Describe the bug When the app tries to trigger the flow, the app crashes as a pending intent is missing mandatory flags (see stack trace below):
private fun startDfuService(
deviceAddress: String,
deviceName: String?
) {
DfuServiceInitiator.createDfuNotificationChannel(context.applicationContext)
val dfuServiceInitiator = DfuServiceInitiator(deviceAddress)
.setKeepBond(true)
.setRestoreBond(true)
.setPrepareDataObjectDelay(300L)
.setNumberOfRetries(3)
.setUnsafeExperimentalButtonlessServiceInSecureDfuEnabled(true)
.setZip(R.raw.v3957_b01)
if (deviceName != null) {
dfuServiceInitiator.setDeviceName(deviceName)
}
dfuServiceInitiator.start(context.applicationContext, BleFirmwareUpgradeService::class.java)
DfuServiceListenerHelper.registerProgressListener(
context.applicationContext,
this,
deviceAddress
)
logger.logServiceStarting()
}
Logs
10-27 13:02:39.006 26997 27424 E AndroidRuntime: FATAL EXCEPTION: IntentService[DfuBaseService]
10-27 13:02:39.006 26997 27424 E AndroidRuntime: Process: [REDACTED], PID: 26997
10-27 13:02:39.006 26997 27424 E AndroidRuntime: java.lang.IllegalArgumentException: [REDACTED]: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
10-27 13:02:39.006 26997 27424 E AndroidRuntime: Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.app.PendingIntent.getActivity(PendingIntent.java:444)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.app.PendingIntent.getActivity(PendingIntent.java:408)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at no.nordicsemi.android.dfu.DfuBaseService.startForeground(DfuBaseService.java:1862)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at no.nordicsemi.android.dfu.DfuBaseService.onHandleIntent(DfuBaseService.java:1142)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288)
10-27 13:02:39.006 26997 27424 E AndroidRuntime: at android.os.HandlerThread.run(HandlerThread.java:67)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to resolve "Missing PendingIntent mutability flag" lint ...
You can set your pending intent as val updatedPendingIntent = PendingIntent.getActivity( applicationContext, NOTIFICATION_REQUEST_CODE ...
Read more >Android 12, PendingIntent Mutability, and Geofences
Apps that target Android 12 (SDK31) must now specify a mutability flag for any pending intents. The documentation and the errors in Android...
Read more >Android 12 PendingIntent Crash Error : r/cn1 - Reddit
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs ...
Read more >Bug - Android 12 App crashes on startup due to error with ...
Starting Android 12, any Pending Intents creation needs Mutability flags. Look if any updates published for those plugins to get it resolved ...
Read more >Android - CVE - Search Results
Internal paths to the Nextcloud Android app files are not properly protected. ... Services SDK incorrectly had the mutability flag set to PendingIntents...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It took a couple of days for it to appear in repo. Thanks!
The PR has already been merged, I’ll release a version tomorrow. #313