0

We created an extension function for checking the new notification permission for Android 13

fun hasNotificationPermission(context: Context): Boolean {
    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
        ContextCompat.checkSelfPermission(context, POST_NOTIFICATION) ==
                PackageManager.PERMISSION_GRANTED
    else
        true // Android 12 and below has no runtime permission thus return true
}

The SonarLint warn us with S1125 Redundant Boolean literals should be removed from expressions to improve readability.. But looking at the code I don't think there is a redundant happening here?

The code will only check if permission is granted or not when it is running on Android 13, else it will always return true for Android 12 and below. Is this a false positive?

Bitwise DEVS
  • 2,858
  • 4
  • 24
  • 67
  • A little bit late answer but this is a false positive. It is not related to Android. The second hidden if (`ContextCompat... == ...`) tricks Sonar. – ocos Aug 19 '22 at 14:34
  • @ocos thanks, the warning was fixed after adding brackets in if and else – Bitwise DEVS Aug 19 '22 at 20:44

0 Answers0