-
Notifications
You must be signed in to change notification settings - Fork 625
Notification trigger API #4183
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
Notification trigger API #4183
Conversation
Coverage Report 1Affected Products
Test Logs |
The public api surface has changed for the subproject firebase-appdistribution-api: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
db7e5c0
to
db7fe42
Compare
The public api surface has changed for the subproject firebase-appdistribution-api: Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly. |
08ad235
to
1148499
Compare
deb39fe
to
87302ba
Compare
Size Report 1Affected Products
Test Logs |
87302ba
to
ca6ec70
Compare
ca6ec70
to
fd44b91
Compare
fd44b91
to
ae8db00
Compare
...tribution-api/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistribution.java
Show resolved
Hide resolved
...tribution-api/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistribution.java
Outdated
Show resolved
Hide resolved
.../java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionLifecycleNotifier.java
Outdated
Show resolved
Hide resolved
...va/com/google/firebase/appdistribution/impl/FirebaseAppDistributionNotificationsManager.java
Outdated
Show resolved
Hide resolved
...va/com/google/firebase/appdistribution/impl/FirebaseAppDistributionNotificationsManager.java
Show resolved
Hide resolved
...in/java/com/google/firebase/appdistribution/impl/TakeScreenshotAndStartFeedbackActivity.java
Show resolved
Hide resolved
...pp/src/main/java/com/googletest/firebase/appdistribution/testapp/AppDistroTestApplication.kt
Outdated
Show resolved
Hide resolved
...ution/test-app/src/main/java/com/googletest/firebase/appdistribution/testapp/MainActivity.kt
Show resolved
Hide resolved
@@ -221,9 +221,9 @@ class TakeScreenshotAndTriggerFeedbackActivity : Activity() { | |||
activity.openFileOutput(SCREENSHOT_FILE_NAME, Context.MODE_PRIVATE).use { outputStream -> | |||
bitmap.compress(Bitmap.CompressFormat.PNG, /* quality = */ 100, outputStream) | |||
} |
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.
Silly GitHub doesn't let me comment on line 213... Anyhow, should there be a finish()
at the end of onResume()
?
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.
True. Out of curiosity - any reason you split the behavior between onCreate and onResume? Or could it all go in the onCreate like it is in the SDK?
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.
No good reason. It was just the first thing that worked. So let's make it mirror what the SDK does since that's simpler.
* | ||
* <p>On Android 8 and above, the notification will be created in its own notification channel. | ||
* | ||
* @param infoTextResourceId string resource ID of text to display to the tester before collecting |
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.
Does the underlying api require a resource id? if not, do we want to restrict to only allow resource ids as opposed to allowing passing in custom strings like constants?
If resourceId is preferred, please make sure to annotate this param with @StringRes
.
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.
We alternatively allow them to pass in a CharSequence, below. Supporting resource id is mostly for convenience, so they don't have to call Context.getText()
or Context.getString()
. This matches the options we already provide with startFeedback(int)
vs startFeedback(CharSequence)
. If this is creating too much clutter in the API, maybe we just support CharSequence? It's not that big a deal to call getText.
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.
My preference is in the other direction. If we eliminate one, I'd vote for the overload with CharSequence
and only keep @StringRes int
. The latter is a best practice. Hard-coded strings are smelly. Or we keep both, but add JavaDoc which explains that @StringRes int
is preferred.
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.
That's a good point, Kai. I actually just noticed that if you use TextView.setText(CharSequence)
you get a compiler warning: "String literal in setText can not be translated. Use Android resources instead."
So I'm tempted to remove the CharSequence option, but that would prevent the dev from using format strings: https://developer.android.com/guide/topics/resources/string-resource#formatting-strings
I feel like we should support that.
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.
Would it make sense to add an overload that would mirror getResource(int, Object...)
? i.e. something like
void showFeedbackNotification(
@NonNull InterruptionLevel interruptionLevel, @StringRes int infoTextResourceId, Object... formatArgs);
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.
We could, but if they want to use a format string AND html elements like <a>
tags they would have to do some extra steps and then final pass us a styled CharSequence: https://developer.android.com/guide/topics/resources/string-resource#StylingWithHTML
This might seem like an edge case, but because this text will likely include links to terms and conditions I expect anyone who wants to use a format string will have to do this.
* NotificationChannel#setImportance}. On platforms below Android 8, the importance will be | ||
* translated into a comparable notification priority (see {@link |
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.
If we are doing some translation, would it make sense to create an enum as opposed to relying on the platform constants being passed in?
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 think that might make more sense, actually. I was thinking about the scenario where Android adds a new importance level. If we just accept an importance level here, the nice thing is devs could start using it immediately without any update from us. The downside is that we would fall back to PRIORITY_DEFAULT
on older devices. That might be significantly higher or lower priority than expected.
While the translation is super obvious (MIN -> MIN, DEFAULT -> DEFAULT, etc) it would still be nice to be explicit.
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.
Here's what that would look like: https://github.com/firebase/firebase-android-sdk/pull/4205/files
Let me know if you think we should go through an API review for this.
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 like it (just left one comment for simplification). I don't think we need an API review now. But after EAP we should go through an API review (again) for everything. Many small details changed - and might keep changing - e.g. whether to accept CharSequence
or @StringRes int
or both.
* translated into a comparable notification priority (see {@link | ||
* NotificationCompat.Builder#setPriority}). | ||
*/ | ||
void showFeedbackNotification(int infoTextResourceId, int importance); |
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.
For my understanding, what will happen if called from background? do Android background restrictions apply to it?
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.
Good question - I just tested it and it works, even after navigating away from the app. This makes sense - notifications are actually the recommended way for apps to present UI to the user when in the background: https://developer.android.com/guide/components/activities/background-starts#display-notification
// Store a reference to the previous activity in case the current activity is ignored | ||
previousActivity = currentActivity; |
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.
If the current activity is an ignored one, do you even need to store it?
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 should make this comment clearer - what I mean is that the currentActivity may be ignored later when applyToNullableForegroundActivity(classToIgnore, ...)
is called.
* Add InterruptionLevel to API * Move interruption and priority levels to InterruptionLevel enum * Mark interruptionLevel as @nonnull
* | ||
* <p>On Android 8 and above, the notification will be created in its own notification channel. | ||
* | ||
* @param infoTextResourceId string resource ID of text to display to the tester before collecting |
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.
Would it make sense to add an overload that would mirror getResource(int, Object...)
? i.e. something like
void showFeedbackNotification(
@NonNull InterruptionLevel interruptionLevel, @StringRes int infoTextResourceId, Object... formatArgs);
// Store a reference to the previous activity in case the current activity is ignored | ||
// later in call to applyToNullableForegroundActivity() | ||
previousActivity = currentActivity; |
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'm not sure if it's actually a problem in practice in you use case, but in general holding a reference to currentActivity
should be safe, while it's not necessarily the case with previousActivity
given that that activity may get destroyed while currentActivity
is active. Is that a possible scenario here? What would happen if you try to use that activity?
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.
That's not a possible scenario because if previousActivity
gets destroyed, we remove the reference to it on line 343 (in onActivityDestroyed
).
This adds a new API allowing developers to show a notification that, when tapped, will take a screenshot of the running application and open the feedback form. This way the developers don't need to add any new UI elements to their app to trigger feedback.
Other changes include: