code-with-the-italians / bundel

A digital wellbeing Android app that helps minimise distractions when you don't want them. Watch us live code it at https://cwti.link/twitch or catch up on YouTube at https://cwti.link/yt. Merch available at https://cwti.link/spaccio.
https://codewiththeitalians.it
Apache License 2.0
288 stars 26 forks source link

App crashes at startup #18

Closed ZianeA closed 3 years ago

ZianeA commented 3 years ago

Describe the bug The app crashes on startup with the following exception:

java.lang.NullPointerException: getString(context.contentResolver, "enabled_notification_listeners") must not be null
at dev.sebastiano.bundel.notifications.NotificationServiceHelpersKt.needsNotificationsPermission(NotificationServiceHelpers.kt:9)

To Reproduce I was able to get the app to start by making the following changes:

internal fun needsNotificationsPermission(context: Context): Boolean {
    val pkgName = context.packageName
    val enabledListeners = Settings.Secure.getString(context.contentResolver, "enabled_notification_listeners")
        ?.split(":")
    if (enabledListeners != null && enabledListeners.isEmpty()) return false

    return enabledListeners == null || enabledListeners
        .map { listenerPackageName -> ComponentName.unflattenFromString(listenerPackageName) }
        .none { pkgName == it?.packageName }
}

However, after the fix, I couldn't reproduce the error by simply uninstalling the app. I had to wipe the device data for the error to recur.

Desktop (please complete the following information):

Smartphone (please complete the following information):

rock3r commented 3 years ago

Thanks for the report! I've never seen it on the API 30 Emulator, and I don't really know how it can happen, but if it's just a matter of using null-safe accessors, that's an easy fix I reckon.