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

RemoteServiceException: CannotPostForegroundServiceNotificationException #18495

Closed
AjeshRPai opened this issue May 23, 2023 · 13 comments
Closed

Comments

@AjeshRPai
Copy link
Contributor

Crash: Sentry link

android.app.RemoteServiceException$CannotPostForegroundServiceNotificationException: Bad notification for startForeground
    at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2222)
    at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2508)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at android.app.ActivityThread.main(ActivityThread.java:8757)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
@AjeshRPai
Copy link
Contributor Author

Hey @irfano

I noticed this issue in Sentry and its happening only on Android 13. Since you were the DRI for Android 13 migration, i figured you might have more context or knowledge about this crash. Please feel free to un-assign if you feel this is not related to Android 13/ its an already known issue.

Thanks in Advance.

@irfano
Copy link
Member

irfano commented Jun 12, 2023

Hello, @AjeshRPai! I was AFK for the entire week when you messaged me. Unfortunately, I missed the notification when I returned. I will look into this issue this week.

@irfano
Copy link
Member

irfano commented Jun 18, 2023

This exception tells us we are trying to show notifications without creating a notification channel.

This issue was happening on PhaseFour, PhaseNewUsers, and PhaseSelfHostedUsers in the migration because notifications were disabled in these phases. So, we did not create notification channels, yet we were attempting to show media upload notifications even though we didn't create notification channels.

I'm closing the issue without any development because we're already in the last phase. The next step will be removing all migration settings and this issue won't occur again.

There are still some new crashes coming recently, but not many. They may have stale, cached remote flags.

To reproduce:
(We need to manipulate feature flag

  1. In Android Studio, update shouldShowNotifications(). It should return false to mimic PhaseFour, PhaseNewUsers, and PhaseSelfHostedUsers.
  2. Make a clean install of the WP app.
  3. Log in.
  4. Create a post.
  5. Add a video block and a video.
  6. Notice it will crash when the video is being uploaded.

Sentry link: https://a8c.sentry.io/issues/3909129591/?query=CannotPostForegroundServiceNotificationException&referrer=issue-stream&statsPeriod=90d&stream_index=0

@irfano irfano closed this as completed Jun 18, 2023
Copy link

sentry-io bot commented Nov 22, 2023

Sentry issue: WORDPRESS-ANDROID-2H8Q

@derekblank
Copy link
Contributor

derekblank commented Nov 22, 2023

There are still some new crashes coming recently, but not many. They may have stale, cached remote flags.

Hey @irfano 👋 We're still receiving Sentry event reports for this in 23.6, but it looks like they are from the same 3 - 4 users. Given the comment above, I just wanted to double check if this is expected or not, as it's currently the third-highest WPAndroid crash.

@irfano
Copy link
Member

irfano commented Nov 27, 2023

I have shared how I reproduced this issue previously (#18495 (comment)). However, it appears that Sentry crashes do not come from that case.
This crash always occurs after the log i/WordPress-MAIN: UploadService > Destroyed. Following the destruction of UploadService, [UploadService.startForeground()](https://github.com/wordpress-mobile/WordPress-Android/blob/trunk/WordPress/src/main/java/org/wordpress/android/ui/uploads/PostUploadNotifier.java#L138) is invoked, and leading to the crash. The underlying issue lies in the destruction of UploadService, which occurs subsequent to an upload error.

So, I believe the root cause of this crash is a media upload issue that results in the destruction of UploadService. I was unable to reproduce the issue, but I anticipate that fixing media upload issues and migrating UploadService to Workmanager will address this crash. Internal issue: https://github.com/Automattic/jetpack-mobile-roadmap/issues/1

I am reopening the issue as it's still active.

@irfano irfano reopened this Nov 27, 2023
@irfano irfano removed their assignment Nov 27, 2023
Copy link

sentry-io bot commented Jan 11, 2024

Sentry issue: WORDPRESS-ANDROID-2KJW

@antonis
Copy link

antonis commented Feb 7, 2024

This crash always occurs after the log i/WordPress-MAIN: UploadService > Destroyed. Following the destruction of UploadService, UploadService.startForeground() is invoked, and leading to the crash. The underlying issue lies in the destruction of UploadService, which occurs subsequent to an upload error.

Based on this I believe that the UploadService fix might have covered this too #19987
I'll monitor 24.1+ to verify if this is the case or there is a regression.

@antonis
Copy link

antonis commented Feb 8, 2024

Based on this I believe that the UploadService fix might have covered this too #19987
I'll monitor 24.1+ to verify if this is the case or there is a regression.

Unfortunately this is not the case :( The issue persist in 24.1 and 11 new crashes of WORDPRESS-ANDROID-2H8Q in this version were recorded.

@antonis antonis self-assigned this Feb 9, 2024
Copy link

sentry-io bot commented Feb 9, 2024

Sentry issue: WORDPRESS-ANDROID-2TA3

Copy link

sentry-io bot commented Feb 9, 2024

Sentry issue: JETPACK-ANDROID-8P6

@antonis
Copy link

antonis commented Feb 9, 2024

Unfortunately this is not the case :( The issue persist in 24.1 and 11 new crashes of WORDPRESS-ANDROID-2H8Q in this version were recorded.

At the time of writing 11 crashes were recorder in 24.1 by 2 users all in the WordPress app:

I have shared how I reproduced this issue previously (#18495 (comment)). However, it appears that Sentry crashes do not come from that case.

I was able to reproduce this type of crash only with the steps @irfano provided above.

So, we did not create notification channels, yet we were attempting to show media upload notifications even though we didn't create notification channels.

Given that I could not find any other reproducible case for the error I proceeded with a fix covering this case assuming that on some edge cases (e.g. the client failed to load the latest migration phase from the server) this might still occur.

On the stack trace two No Channel found errors occur for the transient and normal channels just berore the crash:

No Channel found for pkg=org.wordpress.android.beta, channelId=wpandroid_notification_transient_channel_id, id=369571377, tag=null, opPkg=org.wordpress.android.beta, callingUid=10659, userId=0, incomingUserId=0, notificationUid=10659, notification=Notification(channel=wpandroid_notification_transient_channel_id shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x8 color=0xff0675c4 vis=PRIVATE)
...
No Channel found for pkg=org.wordpress.android.beta, channelId=wpandroid_notification_normal_channel_id, id=2, tag=null, opPkg=org.wordpress.android.beta, callingUid=10659, userId=0, incomingUserId=0, notificationUid=10659, notification=Notification(channel=wpandroid_notification_normal_channel_id shortcut=null contentView=null vibrate=null sound=null defaults=0x0 flags=0x18 color=0xffc9356e actions=1 vis=PRIVATE)
FATAL EXCEPTION: main
Process: org.wordpress.android.beta, PID: 12180
android.app.RemoteServiceException$CannotPostForegroundServiceNotificationException: Bad notification for startForeground
	at android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2078)
	at android.app.ActivityThread.-$$Nest$mthrowRemoteServiceException(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2369)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8177)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

By experimenting I defined that only the transient channel is necessary to prevent this crash and prepared a fix in #20168

@antonis
Copy link

antonis commented Feb 19, 2024

Marking the issue as resolved in 24.2 with #20168. We can reopen if the issue reoccurs.

@antonis antonis closed this as completed Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants