-
Notifications
You must be signed in to change notification settings - Fork 368
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
Fix Crash when tapping on Notification action button in Android 12 #1548
Fix Crash when tapping on Notification action button in Android 12 #1548
Conversation
a142257
to
e105cac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR I left some comments in-line on the code. Also could you include the Android versions you have tested on? Does the Notification Shade still close when clicking on an action button?
OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedProcessor.java
Outdated
Show resolved
Hide resolved
OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationOpenedProcessor.java
Outdated
Show resolved
Hide resolved
@jkasten2 I didn't particularly tested with the sdk but I made a sample project to replicate the behavior. It will close the notification shade on Android 11 and lower. But it won't on Android 12. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vincent-paing Thanks for the fix ups, sorry for the delay. This looks good to me to fix the crash.
Since you noted the behavior on Android 12 is that the shade does not close when tapping on a notification button this still needs to be addressed, however I consider this a much lower priority than crashing and therefore can be followed up in another PR.
@nan-li or @Jeasmine could you take a quick review as well and merge in if you think it looks good too.
Hi @vincent-paing,
I did some very basic testing with just this SDK's example app, and for the flows I tried, tapping on an action button does close the notification shade for Android 12 as well. It also appeared that Can you share anything about your sample project or what you tried, that had the behavior of not closing the notification shade on Android 12? Here's a screencast of an Android 12 emulator with action.button.short.clip.sdk.31.api.31.mov |
@nan-li Are you starting an activity on pressing action? In that case, it will close the shade and launch that activity. |
@nan-li I made a demo repo where I reproduce the dismiss behavior on pressing an action (https://github.com/vincent-paing/NotificationDemo). I believe in your code, pressing an action sends intent to Here's a video recording (left is Android 11, right is Android 12), you can observe
one_signal_dismiss_demo.mov@jkasten2 As far as my research goes, there's no way to close the system dialog starting from Android 12 unless you run an accessibility service. I don't think it's possible to address a workaround for the OS changes |
@nan-li @vincent-paing Thanks for testing! Accessibility Service Work around
I agree, we don't wan to use it as it isn't what it is for. Google's docs state the following:
Details on auto closeThis automatic close of the notification shade noted here is interesting, however it states "...showing a window that is on top the notification shade" in Google's docs.
However in your testing @nan-li it seems even though the the |
If it's helpful, In my test if you replace |
@vincent-paing Thanks for confirming! |
Ah, this was probably the whole reason for PR #18 added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with jkasten2 and appreciate the thoroughness @vincent-paing!
I am merging this PR.
Description
One Line Summary
Fixes a crash in Android 12 when interacting with action button due to notification drawer behavior changes
Details
Motivation
This PR addresses the issue #1543 and fixes the crash.
Scope
This will impact the functionality of dismiss on action press. By default, it will remove this close drawer feature completely since it's no longer supported starting from Android 12+. However, if the consumer of the lib uses
overrideLibrary
flag to change the lib's target sdk, the behavior will still works up to Android 11. But on Android 12, it will does a silent no-op and log the error.Testing
Unit testing
Not sure if I need to update unit test for this, let me know if it need changes.
Affected code checklist
This change is