Skip to content

Android 13 requires runtime POST_NOTIFICATIONS permission for DownloadService notifications #10884

Open

Description

@yoobi

Reading though Android 13 changes, I've noticed that we now need to add android.permission.POST_NOTIFICATIONS in the manifest.

As Exoplayer provides a DownloadService should the next versions of Exoplayer/Media3 add this permission and implements something about it ?

Activity

  1. marcbaechinger commented on Jan 3, 2023

    @marcbaechinger
    Contributor

    I'm not sure if it's the right thing to do to add this permission to a manifest of the library that then is automatically merged into an app manifest. Not every app may use the DownloadService.

    I think an app that includes the DownloadService wants to add this permission, but I also think it should be left to the app to do that.

    I agree though that we should add this permission to the AndroidManifest.xml of the main demo app as an example to do the right thing. Is this what you are asking for?

  2. yoobi commented on Jan 3, 2023

    @yoobi
    ContributorAuthor

    It was an open question whether a comment should be added to the abstract class DownloadService in order to specify that if the permission is not asked for A13+ it won't prompt the notification.
    I agree that handling the permission should fall upon the app using `DownloadService, also yes the demo might need an update regarding this permission.

  3. marcbaechinger commented on Jan 3, 2023

    @marcbaechinger
    Contributor

    Ok, makes sense. Currently the main demo app does never show a notification when downloading (when on targetSdkVersion 33). On API 33 it not only requires the permission to be added to the manifest, but instead the permission also needs to be requested at runtime. Aside: The session demo app is not affected by this change because its notification is exempted because it is attached to a media session.

    I think we need to do the following things:

    1. Document in DownloadService that an app with targetSdkVersion 33+ needs to add the android.permission.POST_NOTIFICATIONS to the manifest.
    2. Document that such an app also needs to request Manifest.permission.POST_NOTIFICATIONS at runtime in order to notification to be shown. It's at the app's discretion when to do this, like when the app starts or when a download is triggered.
    3. Do point 1) and 2) for the main demo app.
  4. marcbaechinger commented on Jan 3, 2023

    @marcbaechinger
    Contributor

    Marking this issue as a bug (in the main demo app) on API 33.

  5. changed the title [-]Android 13 POST_NOTIFICATIONS[/-] [+]Android 13 requires runtime POST_NOTIFICATIONS permission for DownloadService notifications[/+] on Jan 9, 2023
  6. mhernand40 commented on Feb 28, 2023

    @mhernand40

    I am in the process of updating to Android Gradle Plugin 7.4. The project I am working on does use ExoPlayer but it does not use DownloadService. However, there appears to be a new lint rule added in Android Gradle Plugin 7.4 that is failing for us due to our dependency on ExoPlayer:

    Error:   /*****/app/src/main/AndroidManifest.xml: Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission (usage from com.google.android.exoplayer2.offline.DownloadService.ForegroundNotificationUpdater) [NotificationPermission]
    

    It feels odd to me to have to specify this permission in the app's manifest if the app does not use DownloadService at all. We could suppress the lint violation for now but that also seems a little odd to me. 🤷‍♂️

    Here is a similar/related comment:
    digitalservicebund/useid-app-android#132 (comment)

  7. marcbaechinger commented on Mar 1, 2023

    @marcbaechinger
    Contributor

    Thanks for reporting. I can repro this. Looks like the linter is a bit aggressive. Not sure what we can do. I filed a bug internally (internal bug-ref: b/271249297).

    Repro steps

    1. Download AS Electric Eel.
    2. Create a new project.
    3. Choose 'File - Project structure' and use AGP 7.4 (or greater)
    4. Add dependency implementation 'com.google.android.exoplayer:exoplayer-core:2.18.3'
    5. On the command line run ./gradlew build

    Observed result

    Build fails with error message below

    Expected result

    App can be built without lint errors.

    > Task :app:lintReportDebug
    Wrote HTML report to file:///usr/local/google/home/bachinger/StudioProjects/MyApplication/app/build/reports/lint-results-debug.html
    
    > Task :app:lintDebug FAILED
    Lint found 1 errors, 4 warnings. First failure:
    
    /usr/local/google/home/bachinger/StudioProjects/MyApplication/app/src/main/AndroidManifest.xml: Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission (usage from com.google.android.exoplayer2.offline.DownloadService.ForegroundNotificationUpdater) [NotificationPermission]
    
       Explanation for issues of type "NotificationPermission":
       When targeting Android 13 and higher, posting permissions requires holding
       the runtime permission android.permission.POST_NOTIFICATIONS.
    
    
    The full lint text report is located at:
      /usr/local/google/home/bachinger/StudioProjects/MyApplication/app/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:lintDebug'.
    >                 Lint found errors in the project; aborting build.
      
                      Fix the issues identified by lint, or create a baseline to see only new errors:
                      ```
                      android {
                          lint {
                              baseline = file("lint-baseline.xml")
                          }
                      }
                      ```
      
                      For more details, see https://developer.android.com/studio/write/lint#snapshot
      
                      Lint found 1 errors, 4 warnings. First failure:
      
      /usr/local/google/home/bachinger/StudioProjects/MyApplication/app/src/main/AndroidManifest.xml: Error: When targeting Android 13 or higher, posting a permission requires holding the POST_NOTIFICATIONS permission (usage from com.google.android.exoplayer2.offline.DownloadService.ForegroundNotificationUpdater) [NotificationPermission]
      
         Explanation for issues of type "NotificationPermission":
         When targeting Android 13 and higher, posting permissions requires holding
         the runtime permission android.permission.POST_NOTIFICATIONS.
      
      
      The full lint text report is located at:
        /usr/local/google/home/bachinger/StudioProjects/MyApplication/app/build/intermediates/lint_intermediate_text_report/debug/lint-results-debug.txt
    
  8. added a commit that references this issue on Mar 21, 2023
  9. added a commit that references this issue on Jun 22, 2023
  10. Biplovkumar commented on Aug 21, 2023

    @Biplovkumar

    @marcbaechinger IllegalArgumentException: Unknown permission: android.permission.POST_NOTIFICATIONS with below version. Please suggest?

    Nexus 5X
    Model:Nexus 5X
    
    Android
    Version:6.0.1
    
  11. marcbaechinger commented on Aug 21, 2023

    @marcbaechinger
    Contributor

    @Biplovkumar

    You probably need a bit more context to make this actionable for us.

    Best is if you can repro this with the demo app.
    Tell us what you do, the repro steps, the expected result and the observed result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions