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

fix: isAppInForeground #603

Merged
merged 4 commits into from
Dec 5, 2022
Merged

Conversation

mieszko4
Copy link
Contributor

@mieszko4 mieszko4 commented Dec 3, 2022

This PR fixes two issues:

  1. Issue with registering in test_react_native/example.
    Because AndroidFlags was imported with '@notifee/react-native/src' and everything else was imported '@notifee/react-native' it caused double initialization of NotifeeApiModule which caused the following errors showing when yarn tests_rn:android:test is run:
WARN  registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'app.notifee.foreground-service-headless-task'
WARN  registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'app.notifee.notification-event'
WARN  [notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.
  1. Issue with Quick Action tap not being handled on Android 12 because of bug in isAppInForeground.
    The issue started to show in Android 12 because that version Android for some reason considers IMPORTANCE_FOREGROUND for importance of the running app even if app is minimized.

Closes #404

Fixes issue with registering:
WARN  registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'app.notifee.foreground-service-headless-task'
WARN  registerHeadlessTask or registerCancellableHeadlessTask called multiple times for same key 'app.notifee.notification-event'
WARN  [notifee] no background event handler has been set. Set a handler via the "onBackgroundEvent" method.
@CLAassistant
Copy link

CLAassistant commented Dec 3, 2022

CLA assistant check
All committers have signed the CLA.

return true;
ReactContext reactContext = getReactContext();
if (reactContext == null) {
return false;
}
Copy link
Contributor Author

@mieszko4 mieszko4 Dec 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the purpose of this code was, but it was always failing with ClassCastException

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm, this is a part of code I've not dealt with much. What you've done with using getReactContext() makes sense

@@ -4,8 +4,8 @@ import {
AndroidLaunchActivityFlag,
AndroidCategory,
AndroidImportance,
AndroidFlags,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes double loading of module which caused that onBackgroundEvent was not properly registered

Copy link
Member

@helenaford helenaford Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you, this is a fix for the testing app only, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly.

Comment on lines +281 to +287
// Manual steps:
// 1. Minimize app
// 2. Open notification drawer
// 3. Tap on 'First Action'
// 4. Make sure you see:
// > WARN Received a ACTION_PRESS Background event in JS mode.
// > WARN Notification Cancelled first_action
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you guys test notification tapping. On Android it is possible to simulate some actions with adb but that's not robust since you need to know exact point for tapping, e.g.:

adb shell input keyevent KEYCODE_HOME
adb shell cmd statusbar expand-notifications
adb shell input tap 990 1269

Note that on Android 9 this test passes without the fix in isAppInForeground.
On Android 12, however, the fix is necessary for this test to pass.
Hence the fix is needed for this test to pass on both Android 7 and Android 12

@codecov
Copy link

codecov bot commented Dec 5, 2022

Codecov Report

Merging #603 (67c8cb6) into main (6dfc923) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #603   +/-   ##
=======================================
  Coverage   77.24%   77.24%           
=======================================
  Files          34       34           
  Lines        1700     1700           
  Branches      546      546           
=======================================
  Hits         1313     1313           
  Misses        386      386           
  Partials        1        1           

@helenaford helenaford merged commit 4f07f48 into invertase:main Dec 5, 2022
@helenaford
Copy link
Member

@mieszko4 thank you for this fix! And, I appreciate the thorough testing and detailed explanation!

@mieszko4 mieszko4 deleted the fix/is-app-in-foreground branch December 6, 2022 06:56
mieszko4 added a commit to rune/notifee that referenced this pull request Dec 7, 2022
mieszko4 added a commit to rune/notifee that referenced this pull request Dec 7, 2022
mieszko4 added a commit to rune/notifee that referenced this pull request Dec 7, 2022
mieszko4 added a commit to rune/notifee that referenced this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android: onBackgroundEvent not fired when quick action is pressed
3 participants