Skip to content

[PlayerModel] [Fix] make timeFocusedAtMs thread safe#2025

Merged
jkasten2 merged 1 commit intoplayer-model-mainfrom
fix/player-model-null-timeFocusedAtMs
Mar 9, 2024
Merged

[PlayerModel] [Fix] make timeFocusedAtMs thread safe#2025
jkasten2 merged 1 commit intoplayer-model-mainfrom
fix/player-model-null-timeFocusedAtMs

Conversation

@jkasten2
Copy link
Copy Markdown
Member

@jkasten2 jkasten2 commented Mar 8, 2024

Description

One Line Summary

Fix rare null crash with timeFocusedAtMs by making it thread safe.

Details

Motivation

A few customers have seen a rare crash.

Scope

Only affects focus time calculations.

Crash Example

java.lang.NullPointerException: Attempt to invoke virtual method 'long java.lang.Long.longValue()' on a null object reference
  at com.onesignal.FocusTimeController.getTimeFocusedElapsed(FocusTimeController.java:98)
  at com.onesignal.FocusTimeController.appStopped(FocusTimeController.java:50)
  at com.onesignal.ActivityLifecycleHandler$1.run(ActivityLifecycleHandler.java:186)

Testing

Manual testing

Tested on an Android 14 emulator, ensuring the on_focus endpoint was called with the the correct time.

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
  • 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

Fixes rare cases where timeFocusedAtMs can become null right
after the null check in getTimeFocusedElapsed(). We have seen crashes in
the wild so it not just theoretical.
@jkasten2 jkasten2 merged commit b8e27cd into player-model-main Mar 9, 2024
@jkasten2 jkasten2 deleted the fix/player-model-null-timeFocusedAtMs branch March 9, 2024 01:10
@jkasten2 jkasten2 mentioned this pull request Mar 9, 2024
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.

3 participants