Skip to content

Conversation

@jinliu9508
Copy link
Contributor

@jinliu9508 jinliu9508 commented Dec 4, 2025

Description

One Line Summary

Fix NPE from SyncJobService introduced on 5.4.0 caused by incompleted / failed OneSignal initialization during onStartJob.

Details

Motivation

Address the new NPE introduced on 5.4.0.

Scope

After 5.4, onStartJob calls initWithContext in background. That introduced a small possibility when onStopJob is called before the initialization completes in the background. When that happens, OneSignal.getService will run into a NPE. In that case, we just need to omit the job and do not reschedule.

Testing

Unit testing

Add several test cases covering SyncJobService.kt

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

@jinliu9508 jinliu9508 force-pushed the fix-bug-syncjobservice-onstop branch from 640e1e2 to 908126f Compare December 4, 2025 17:20
@jinliu9508 jinliu9508 force-pushed the fix-bug-syncjobservice-onstop branch from 135f6eb to fc40248 Compare December 4, 2025 18:47
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

To be clear, this PR address two 5.4.0 bugs then:

  1. Throwing on onStopJob
  2. Not closing the SyncJobService wakelock if the OneSignal initialization fails.

@jinliu9508 jinliu9508 force-pushed the fix-bug-syncjobservice-onstop branch from 238a809 to 69e37a8 Compare December 5, 2025 16:50
@jinliu9508
Copy link
Contributor Author

Addressed some flaky tests

@jinliu9508 jinliu9508 merged commit 1bd49af into main Dec 5, 2025
1 check passed
@jinliu9508 jinliu9508 deleted the fix-bug-syncjobservice-onstop branch December 5, 2025 17:05
abdulraqeeb33 pushed a commit that referenced this pull request Dec 9, 2025
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.

4 participants