Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreground service in Android O #1355

Closed
LvWind opened this issue Aug 23, 2017 · 25 comments

Comments

@LvWind
Copy link

commented Aug 23, 2017

After update to Android O, it always shows a notification "shadowsocks is running in the background"
What i know is before API 26, A foreground service without a notification shows the "running". But Shadowsocks has a notification with status and usages. So why it start appearing in O, i'm totally no idea.
What do you think about it? @madeye
device-2017-08-23-140128

Environment

  • Android version: 8.0
  • Device: Nexux 5X
  • Shadowsocks version: 4.1.8
@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

I also noticed it months ago. Currently, I assume it's a bug of Android OS. 😃

@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

It looks a low priority notification of foreground service would still cause this "status and usage" notification shows up.

@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

Another example can be found in the same screenshot, where ADB is listed in the "status and usage" notification.

@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 23, 2017

Once startForeground() method is called in Android O, the "running" notification will show if your app is not in foreground.
A VpnService has already promotes itself to the foreground. So stop using this method may fix this issue.

refer: https://developer.android.com/about/versions/oreo/background.html#services chapter"Background Service Limitations"

@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

Interesting.

@Mygod What do you think?

@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 23, 2017

I mean, showing notifications just with NotificationManager.notify() and setOngoing = true

@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

Weird, After removing startForeground(), I got ANR in the VPN service after starting the service.

@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 23, 2017

oops, i found in that link:
"If the app does not call startForeground() within the time limit, the system stops the service and declares the app to be ANR."
Maybe the "running" notification can not be removed in O

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

I have implemented everything accordingly. I have no idea what caused that behavior. IIRC it didn't show up on emulators and I don't have a Oreo device to test it.

Maybe try calling stopService before startForeground? Just a guess.

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Aug 23, 2017

Wait I already have replaced startService with startForegroundService haven't I? :/

In that case maybe it's because of priority.

@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2017

@Mygod Yes, we're using startForegroundService for API >= 26.

@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 24, 2017

screenshot 2017-08-24 11 49 21

My emulator also has this notify. And i tried to set NotificationChannel's importance to IMPORTANCE_HIGH, nothing different.
@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 24, 2017

But IMPORTANCE_MAX worked. (I tested in my own project, not this one)
Maybe not the same situation.

@madeye

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2017

Hmm. as a trade-off, I suggest keep our current priority. IMPORTANCE_MAX would show an icon on the status bar.

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2017

@WordlessEcho

This comment has been minimized.

Copy link

commented Aug 28, 2017

Is it concerned about this issue?

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Aug 28, 2017

Thanks @LvWind!

So I did some reading and the answer is no. As long as the app is not on top and is not a system app (source) this notification will be shown. Therefore the only solution for AOSP may be moving this app to system, unless somebody can think of a smart hack.

@Mygod Mygod closed this Aug 28, 2017
@Mygod

This comment has been minimized.

Copy link
Contributor

commented Aug 28, 2017

A tasker script that snoozes this notification as a workaround: https://www.xda-developers.com/hide-app-running-background-notification-android-oreo/

@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 29, 2017

wow
I think it is using NotificationListenerService.snoozeNotification() to
snooze this notification for a looooong time.

@LvWind

This comment has been minimized.

Copy link
Author

commented Aug 29, 2017

Tried to make a standalone tool to snooze it.
Need someone's help to test.
https://github.com/LvWind/NotRunningInBg/releases/tag/v0.1

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Nov 3, 2017

Interestingly I just tried Adguard and it somehow managed to dodge this bullet.

EDIT: Never mind. AdguardTeam/AdguardForAndroid#1427

@WordlessEcho

This comment has been minimized.

Copy link

commented Dec 3, 2017

Other way:
Change notification importance to medium+

@Mygod

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2019

It seems like this notification has been removed in Android 9: aosp-mirror/platform_frameworks_base@070d142

@madeye Thoughts?

@madeye

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2019

If so, I think we can put back our notification to lowest priority on Android 9+.

Mygod added a commit that referenced this issue Jul 19, 2019
Refine #1355.
This commit also deprecates hiding non-VPN service notification on lockscreen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.