Fix favorites sync and backup/restore crashing on older devices

This commit is contained in:
NerdNumber9 2019-04-20 14:01:18 -04:00
parent b06f253f83
commit 895191814e
3 changed files with 15 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.os.PowerManager import android.os.PowerManager
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
@ -180,13 +181,17 @@ class BackupRestoreService : Service() {
subscription = Observable.using( subscription = Observable.using(
{ {
// Pause auto-gallery-update during restore // Pause auto-gallery-update during restore
EHentaiUpdateWorker.cancelBackground(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
EHentaiUpdateWorker.cancelBackground(this)
}
db.lowLevel().beginTransaction() db.lowLevel().beginTransaction()
}, },
{ getRestoreObservable(uri).doOnNext { db.lowLevel().setTransactionSuccessful() } }, { getRestoreObservable(uri).doOnNext { db.lowLevel().setTransactionSuccessful() } },
{ {
// Resume auto-gallery-update // Resume auto-gallery-update
EHentaiUpdateWorker.scheduleBackground(this) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
EHentaiUpdateWorker.scheduleBackground(this)
}
executor.execute { db.lowLevel().endTransaction() } executor.execute { db.lowLevel().endTransaction() }
}) })
.doAfterTerminate { stopSelf(startId) } .doAfterTerminate { stopSelf(startId) }

View File

@ -249,6 +249,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
} }
} }
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
companion object { companion object {
private const val MAX_UPDATE_FAILURES = 5 private const val MAX_UPDATE_FAILURES = 5

View File

@ -2,6 +2,7 @@ package exh.favorites
import android.content.Context import android.content.Context
import android.net.wifi.WifiManager import android.net.wifi.WifiManager
import android.os.Build
import android.os.PowerManager import android.os.PowerManager
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
@ -114,7 +115,9 @@ class FavoritesSyncHelper(val context: Context) {
} }
// Do not update galleries while syncing favorites // Do not update galleries while syncing favorites
EHentaiUpdateWorker.cancelBackground(context) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
EHentaiUpdateWorker.cancelBackground(context)
}
storage.getRealm().use { realm -> storage.getRealm().use { realm ->
realm.trans { realm.trans {
@ -167,7 +170,9 @@ class FavoritesSyncHelper(val context: Context) {
} }
// Update galleries again! // Update galleries again!
EHentaiUpdateWorker.scheduleBackground(context) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
EHentaiUpdateWorker.scheduleBackground(context)
}
} }
if(errorList.isEmpty()) if(errorList.isEmpty())