OneSignal-Android-SDK icon indicating copy to clipboard operation
OneSignal-Android-SDK copied to clipboard

WIP: Fix ANR on some devices when calling addTags

Open jinliu9508 opened this issue 1 year ago • 1 comments

Description

One Line Summary

Fix an ANR issue triggered by delays in accessing shared preferences when invoking the addTags function

Details

Motivation

Some ANR stack traces reveals that often time the main thread is waiting for the lock on models to release, but it was occupied and waiting for the shared preference "save" operation that takes unexpectedly long time. By removing the shared preference usage out of the lock allows us to release the lock early.

Scope

All ModelStores changes that trigger persist() to save the changes.

Testing

Unit testing

I have added a test unit to ensure the lock on models is released before accessing preference when calling persist()

Affected code checklist

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

Checklist

Overview

  • [x] I have filled out all REQUIRED sections above
  • [X] 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
  • [x] Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • [x] 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
  • [x] I have personally tested this on my device, or explained why that is not possible

Final pass

  • [x] 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.
  • [x] 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

jinliu9508 avatar Apr 26 '24 04:04 jinliu9508

@jkasten2 The testing unit has some issue related to the matching of any(). Could you assist in getting it operational?

jinliu9508 avatar Apr 26 '24 04:04 jinliu9508