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

notif: Handle when app in background, too (on Android) #352

Merged
merged 3 commits into from
Nov 1, 2023

Conversation

gnprice
Copy link
Member

@gnprice gnprice commented Nov 1, 2023

This completes the core functionality of showing notifications on
Android, #320.

Sadly this does not work very well if the app isn't running at all:
e.g., if you terminate the app by swiping it away in the app switcher.
In that case the notification can be quite a bit delayed.

But fixing that seems likely to require some deeper debugging, and
getting our hands into Java or Kotlin code for I think the first time
in zulip-flutter. So we'll deal with that as a followup issue, #342.
Details there.

Fixes: #320

@gnprice gnprice added a-Android Issues specific to Android, or requiring Android-specific work a-notifications labels Nov 1, 2023
Copy link
Collaborator

@chrisbobbe chrisbobbe left a comment

Choose a reason for hiding this comment

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

Thanks! Small comments below, then please merge at will.

Sadly this does not work very well if the app isn't running at all:
e.g., if you terminate the app by swiping it away in the app switcher.
In that case the notification can be quite a bit delayed.

FWIW, in some brief testing on the office Android device (Samsung Galaxy S9 running Android 9), I don't notice long delays in the case where the app isn't running at all. After I swipe it away in the app switcher, I can send myself DMs from a test account and still get a notification for each one within a few seconds.

Comment on lines 250 to 254
/// Controls [TestZulipBinding.firebaseMessagingOnBackgroundMessage].
///
/// Calling [StreamController.add] on this will cause a call
/// to any handler registered through the latter.
StreamController<RemoteMessage> onBackgroundMessage = StreamController.broadcast();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm getting lost about what "the latter" refers to. I'm not sure what the corresponding "former" is. Would it be accurate to replace "the latter" with [TestZulipBinding.firebaseMessagingOnBackgroundMessage]? But "the latter" doesn't seem like the right label for that, because nothing is mentioned before it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm yeah. That is indeed what I meant it to refer to — basically I didn't want to repeat that very long name. :-)

Maybe I'll say "registered through that method"; that's at least accurate, it's potentially ambiguous with StreamController.add, but hopefully it's clear enough which of the two mentioned methods is meant.

Comment on lines +114 to +118
assert(() {
debugLogEnabled = true;
return true;
}());
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason for setting debugLogEnabled to true here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as in main (the one in lib/main.dart) — it causes the debugLog calls to be active when running a debug build of the app, so that you get them in flutter run output.

Or perhaps the question is: why does this code need to do that, when the whole rest of the app is covered by main doing so? That's because it's in a separate isolate, as mentioned in _onBackgroundMessage; same reason it needs the LiveZulipBinding.ensureInitialized and NotificationDisplayManager._init calls.

I'll add a comment pointing out the comparison to main.

@gnprice
Copy link
Member Author

gnprice commented Nov 1, 2023

FWIW, in some brief testing on the office Android device (Samsung Galaxy S9 running Android 9), I don't notice long delays in the case where the app isn't running at all. After I swipe it away in the app switcher, I can send myself DMs from a test account and still get a notification for each one within a few seconds.

Great! Well, maybe the symptoms of #342 vary between devices, then; perhaps it even only affects relatively few devices.

One thing I wonder is if that's a difference in the app switcher UI — if maybe the one in Samsung's Android 9 leaves the app still in the background, in a way that the one in Google/Pixel's Android 13 doesn't.

This has the same effect at present, but it seems a bit cleaner
in that we'll end up rerunning the normal initializer for each
field, rather than having to duplicate them here.
This completes the core functionality of showing notifications on
Android, zulip#320.

Sadly this does not work very well if the app isn't running at all:
e.g., if you terminate the app by swiping it away in the app switcher.
In that case the notification can be quite a bit delayed.

But fixing that seems likely to require some deeper debugging, and
getting our hands into Java or Kotlin code for I think the first time
in zulip-flutter.  So we'll deal with that as a followup issue, zulip#342.
Details there.

Fixes: zulip#320
@gnprice gnprice merged commit 9be01bd into zulip:main Nov 1, 2023
@gnprice
Copy link
Member Author

gnprice commented Nov 1, 2023

Thanks for the review! Merged with those tweaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-Android Issues specific to Android, or requiring Android-specific work a-notifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show notifications on Android
2 participants