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] ANRs for callbacks and when backgrounding app #602

Merged
merged 2 commits into from
May 12, 2023

Conversation

jkasten2
Copy link
Member

@jkasten2 jkasten2 commented May 12, 2023

Description

One Line Summary

Fix rare Android ANRs when OneSignal callbacks fire and when the app is backgrounded.

Details

Motivation

The time spent on the main thread in this scenario is significantly contributing to ANRs. The Google Play store penalizes apps with ANRs with lower search rankings and possibly some other negatives.

Scope

Only effects Android and threading used for callbacks, observers, and events like click.

Dependent OneSignal-Android-SDK PRs

These are the two PRs that were included in the OneSignal-Android-SDK 4.8.6 release this PR depends on:

Testing

Unit testing

None

Manual testing

Tested on Samsung S21 with Android 13. Ensured SetExternalUserId's callback still fires in the example app here.
Also ensured the threading preference value did change by printing its value back in C#.

var preferenceValue = callbackThreadManagerCompanionClass.Call<AndroidJavaObject>("getPreference");
UnityEngine.Debug.Log("preferenceValue: " + preferenceValue.Call<string>("toString"));

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

Update to the OneSignal-Android-SDK 4.8.6 which includes both a fix for
ANRs the can happen when backgrounding the app and also provides a new
API to control which thread is used for fire callbacks.

By default the OneSignal-Android-SDK continues to fire callbacks on the
Main UI thread, however this SDK update introduces a new API
CallbackThreadManager to allow configuring these to a background thread
@jkasten2 jkasten2 merged commit cda6e8c into main May 12, 2023
1 check passed
@jkasten2 jkasten2 deleted the fix/anrs_callbacks_and_background_app branch May 12, 2023 17:43
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.

None yet

2 participants