Skip to content

Commit a827295

Browse files
authored
fix: crash around com.onesignal.SyncJobService (#2515)
1 parent a4ba2a8 commit a827295

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

OneSignalSDK/onesignal/core/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
android:permission="android.permission.BIND_JOB_SERVICE"
1111
android:exported="false" />
1212

13+
<!-- Temporary shim for old OneSignal v4 jobs pointing to com.onesignal.SyncJobService -->
14+
<service
15+
android:name="com.onesignal.SyncJobService"
16+
android:permission="android.permission.BIND_JOB_SERVICE"
17+
android:exported="false">
18+
</service>
19+
1320
<activity android:name="com.onesignal.core.activities.PermissionsActivity"
1421
android:theme="@android:style/Theme.Translucent.NoTitleBar"
1522
android:exported="false" />
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.onesignal
2+
3+
import android.app.job.JobParameters
4+
import android.app.job.JobService
5+
6+
/**
7+
* Temporary shim for old OneSignal v4 jobs pointing to com.onesignal.SyncJobService.
8+
*
9+
* The v4 SyncJobService was used to run background sync; v5 has moved to a new architecture,
10+
* but scheduled jobs from the old service can still be lingering in JobScheduler on devices
11+
* that previously had v4 installed. When those old jobs fire, the system tries to instantiate
12+
* com.onesignal.SyncJobService. Since the class isn’t in the v5 SDK anymore, we will get a
13+
* ClassNotFoundException and a crash.
14+
*
15+
* Providing a no-op implementation with the same fully qualified name lets those old jobs run
16+
* once, do nothing, and finish, which clears them out. This is intentionally a no-op and
17+
* finishes immediately.
18+
*/
19+
class SyncJobService : JobService() {
20+
21+
override fun onStartJob(params: JobParameters?): Boolean {
22+
// Job finishes immediately, nothing to do.
23+
jobFinished(params, false)
24+
return false // No more work on a background thread.
25+
}
26+
27+
override fun onStopJob(params: JobParameters?): Boolean {
28+
// Don't reschedule the job.
29+
return false
30+
}
31+
}

0 commit comments

Comments
 (0)