Skip to content

Simplify custom notification trigger example and move to activity #4255

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

Merged
merged 2 commits into from
Oct 31, 2022

Conversation

lfkellogg
Copy link
Contributor

@lfkellogg lfkellogg commented Oct 28, 2022

image

@lfkellogg lfkellogg marked this pull request as ready for review October 28, 2022 14:09
@lfkellogg lfkellogg force-pushed the lk/custom-notification-activity branch from 071f82e to cb38a28 Compare October 28, 2022 14:10
@lfkellogg lfkellogg requested a review from kaibolay October 28, 2022 14:11
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 28, 2022

Coverage Report 1

Affected Products

  • firebase-appdistribution

    Overall coverage changed from ? (9d3bed7) to 77.68% (ecb32c1) by ?.

    40 individual files with coverage change

    FilenameBase (9d3bed7)Merge (ecb32c1)Diff
    AabUpdater.java?98.68%?
    ApkInstaller.java?96.88%?
    ApkUpdater.java?93.75%?
    AppDistributionReleaseImpl.java?100.00%?
    AppDistributionReleaseInternal.java?100.00%?
    AppIconSource.java?85.71%?
    AutoValue_AppDistributionReleaseImpl.java?65.45%?
    AutoValue_AppDistributionReleaseInternal.java?66.67%?
    AutoValue_ImageUtils_ImageSize.java?35.00%?
    AutoValue_TesterApiDisabledErrorDetails.java?29.41%?
    AutoValue_TesterApiDisabledErrorDetails_HelpLink.java?54.17%?
    AutoValue_UpdateProgressImpl.java?65.96%?
    ErrorMessages.java?0.00%?
    FeedbackActivity.java?1.69%?
    FeedbackSender.java?90.91%?
    FirebaseAppDistributionExceptions.java?80.00%?
    FirebaseAppDistributionFileProvider.java?0.00%?
    FirebaseAppDistributionImpl.java?91.92%?
    FirebaseAppDistributionLifecycleNotifier.java?96.67%?
    FirebaseAppDistributionNotificationsManager.java?80.95%?
    FirebaseAppDistributionRegistrar.java?82.05%?
    FirebaseAppDistributionTesterApiClient.java?87.63%?
    HttpsUrlConnectionFactory.java?50.00%?
    ImageUtils.java?100.00%?
    InstallActivity.java?2.53%?
    LogWrapper.java?68.75%?
    NewReleaseFetcher.java?77.55%?
    PackageInfoUtils.java?42.86%?
    ReleaseIdentifier.java?88.00%?
    ReleaseUtils.java?83.33%?
    ScreenshotTaker.java?62.16%?
    SignInResultActivity.java?0.00%?
    SignInStorage.java?42.86%?
    TakeScreenshotAndStartFeedbackActivity.java?0.00%?
    TaskUtils.java?96.30%?
    TesterApiDisabledErrorDetails.java?93.75%?
    TesterApiHttpClient.java?89.47%?
    TesterSignInManager.java?93.62%?
    UpdateProgressImpl.java?100.00%?
    UpdateTaskImpl.java?75.71%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/i15OoTLhUW.html

@lfkellogg lfkellogg force-pushed the lk/custom-notification-activity branch from cb38a28 to 7e3e9cf Compare October 28, 2022 14:22
@lfkellogg lfkellogg force-pushed the lk/custom-notification-activity branch from 7e3e9cf to 252336e Compare October 28, 2022 14:27
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Oct 28, 2022

return
}
fun showNotification(activity: Activity) {
synchronized(this) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See below, removing

Log.d(TAG, "setting current activity")
activityToScreenshot = activity
fun cancelNotification() {
synchronized(this) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See below, removing

if (activity == null) {
Log.e(TAG, "Can't take screenshot because activity is unknown")
return
synchronized(CustomNotificationFeedbackTrigger) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? Also, I think this synchronizes on the class - not the instance like the other two synchronize blocks.

Maybe this is an attempt to somehow protect modifications to activityToScreenshot, but I think read/writes to reference variables are atomic.

The assignment to the local variable activity on line 109 makes sure that the value doesn't change between the null check on line 110 and line 114. Inlining CustomNotificationFeedbackTrigger.activityToScreenshot without synchronization would indeed be a problem.

So I think we should add a comment to the assignment on line 109 talking about this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe this is an attempt to somehow protect modifications to activityToScreenshot, but I think read/writes to reference variables are atomic.

I wasn't trying to protect the actual reference and assignment, but rather the surrounding logic that depends on the reference being set to a particular activity, or to null. For example what if we copied CustomNotificationFeedbackTrigger.activityToScreenshot into a non-nullable reference, and then the activity is destroyed before we try to capture the screenshot. However looking again that particular failure case isn't a concern because onCreate and onDestroy will both be called on the main thread. Or maybe I was concerned about someone calling showNotification multiple times in rapid succession from a different thread, but even that wouldn't be a problem AFAICT... After the weekend I can't remember. Comments would have been helpful :) Either way I'll remove these synchronized blocks.

I think this synchronizes on the class - not the instance like the other two synchronize blocks

They all synchronize on the CustomNotificationFeedbackTrigger object. Above we are in the context of the object, hence synchronized(this), and here we are not, so we synchronize on the object reference, synchronized(CustomNotificationFeedbackTrigger). I see how this could be confusing so maybe in cases like this I should just use the latter everywhere.

@lfkellogg lfkellogg merged commit 71aee3f into fad/in-app-feedback Oct 31, 2022
@lfkellogg lfkellogg deleted the lk/custom-notification-activity branch October 31, 2022 15:33
lfkellogg added a commit that referenced this pull request Nov 21, 2022
)

* Simplify custom notification trigger example and move to activity

* Remove synchronized blocks
@firebase firebase locked and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants