28

Sorry for the sort of click-bait title; I couldn't think of a more concise way to say it.

In Android 13, if the user doesn't grant the "dangerous" POST_NOTIFICATION permission, then Foreground Service notifications are not shown in the Notification Drawer. Instead, for the user to see it, they have to navigate to the new Foreground Services Task Manager, according to the documentation:

If the user denies the notification permission, they still see notices related to these foreground services in the Foreground Services (FGS) Task Manager but don't see them in the notification drawer.

Now I haven't used the Android 13 Beta so I don't know exactly how "in the face" the FGS Task Manager will be when Foreground Services are running, but I thought the entire point of forcing Foreground Services to have a notification was so that the user would be aware when the application was running. This even has security consequences because Android restricts what background v.s. foreground processes can do using dangerous permissions (e.g. ACCESS_BACKGROUND_LOCATION). This change essentially allows an app to use foreground based permissions without clearly notifiying the user.

So, why did they decide to restrict Foreground Service notifications? I mean there is a whole other discussion about the addition of restricting notifications in the first place. But one would think that if Android forces you to use a notification, then there shouldn't be a way to get around it (i.e. never request the POST_NOTIFICATION permission or even just remove the permission programatically).

  • Well if the permission is denied, your app cannot send any notification to the system drawer but in case of a foreground service they are visible in the FGS Task Manager since the user has to know what process / app is running a long task and using up the system resources. As per the documentation, starting a Foreground Service does not require this runtime permission but the service must have a notification. – Darshan Jun 17 '22 at 20:15
  • 1
    Who knew that posting notifications was dangerous.... I think this will just make for more unstable app functionality.. I'm sure Google services will be exempt though .. – Mark Jun 17 '22 at 20:17
  • @DarShan couple things. First, the premise behind the question is that the FGS Task Manager doesn't really notify the user, as shown [here](https://developer.android.com/about/versions/13/changes/fgs-manager). Its more of menu that the user can choose to see. Second, you said "the service must a have a notification". While its true that you must give `startForeground()` a notification, is the notification ever presented to the user (outside of FGS Task Manager)? –  Jun 17 '22 at 20:21
  • @free_coupons_for_sale_1023 Correct, FGS would keep list of apps running in foreground, regardless of the permission state. Second, as per the docs the foreground service does require a notification but it won't be shown if the permission is denied. – Darshan Jun 17 '22 at 20:37
  • 1
    @DarShan - so if the user denies the permission, you can start a foreground service, from the foreground, and in the service post a notification using startForeground, and use the service as normal, except if the user denies this permission the only fallout is not showing a notification? Like with most Google "tinkering" it's worth just testing for yourself .. – Mark Jun 17 '22 at 20:53
  • 1
    @Mark Correct, at-least as per the docs. – Darshan Jun 18 '22 at 04:58

3 Answers3

9

The good side of this change is that you wont have the notification area full of icons. See here how it looks like in normal use. And see here how it looks when detailed.

If you want a better explanation, check here the documentation.

Marius Razvan Varvarei
  • 1,331
  • 1
  • 17
  • 21
4

From Docs

Starting in Android 13 (API level 33), users can dismiss the notification associated with a foreground service by default. To do so, users perform a swipe gesture on the notification. On previous versions of Android, the notification can't be dismissed unless the foreground service is either stopped or removed from the foreground.

If you would like the notification to be non-dismissable by the user, pass true into the setOngoing() method when you create your notification using Notification.Builder.

https://developer.android.com/guide/components/foreground-services#handle-user-initiated-stop

enter image description here

Asad Mahmood
  • 532
  • 1
  • 5
  • 15
0

So, why did they decide to restrict Foreground Service notifications?

No, they did not restrict Foreground Service notifications at all. Actually, they are always visible in the FGS Task Manager. Below Android 13, it was possible to hide the Foreground Service notifications, when the user forcefully turns them off in settings. But in Android 13, it is always visible (either in notification panel or in FGS Task Manager), no matter whether the user allowed notifications or not.

But one would think that if Android forces you to use a notification, then there shouldn't be a way to get around it

I think the permission is for presenting regular notifications, rather than foreground notifications. In this new way, the foreground services are never hidden (always visible in FGS Task Manager, while other regular notifications are presented according to the user's preference. In short, this method decouples the visibility of regular notifications and foreground service notifications rather than hiding both.

Ananta Raha
  • 1,011
  • 5
  • 14