UpdateWorker: Make CHECK_ONLY as a valid update mode

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-11-06 00:49:56 +05:30
parent 20e7b13851
commit 2ea42ae113
4 changed files with 8 additions and 10 deletions

View File

@@ -43,7 +43,6 @@ class UpdateHelper @Inject constructor(
companion object {
const val UPDATE_MODE = "UPDATE_MODE"
const val UPDATE_SHOULD_NOTIFY = "UPDATE_SHOULD_NOTIFY"
private const val UPDATE_WORKER = "UPDATE_WORKER"
private const val EXPEDITED_UPDATE_WORKER = "EXPEDITED_UPDATE_WORKER"
@@ -93,8 +92,7 @@ class UpdateHelper @Inject constructor(
*/
fun checkUpdatesNow() {
val inputData = Data.Builder()
.putInt(UPDATE_MODE, UpdateMode.CHECK_AND_NOTIFY.ordinal)
.putBoolean(UPDATE_SHOULD_NOTIFY, false)
.putInt(UPDATE_MODE, UpdateMode.CHECK_ONLY.ordinal)
.build()
val work = OneTimeWorkRequestBuilder<UpdateWorker>()

View File

@@ -3,5 +3,6 @@ package com.aurora.store.data.model
enum class UpdateMode {
DISABLED,
CHECK_AND_NOTIFY,
CHECK_AND_INSTALL
CHECK_AND_INSTALL,
CHECK_ONLY,
}

View File

@@ -16,7 +16,6 @@ import com.aurora.gplayapi.network.IHttpClient
import com.aurora.store.BuildConfig
import com.aurora.store.data.helper.DownloadHelper
import com.aurora.store.data.helper.UpdateHelper
import com.aurora.store.data.helper.UpdateHelper.Companion.UPDATE_SHOULD_NOTIFY
import com.aurora.store.data.installer.AppInstaller
import com.aurora.store.data.model.BuildType
import com.aurora.store.data.model.SelfUpdate
@@ -70,7 +69,6 @@ class UpdateWorker @AssistedInject constructor(
else -> BuildType.DEBUG
}
private val shouldNotify = inputData.getBoolean(UPDATE_SHOULD_NOTIFY, true)
private val canSelfUpdate = !CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID) &&
!CertUtil.isAppGalleryApp(appContext, BuildConfig.APPLICATION_ID) &&
buildType != BuildType.DEBUG
@@ -102,14 +100,14 @@ class UpdateWorker @AssistedInject constructor(
.also { updateDao.insertUpdates(it) }
.filter { if (!isExtendedUpdateEnabled) it.hasValidCert else true }
if (updates.isEmpty()) {
Log.i(TAG, "No updates found!")
if (updates.isEmpty() || updateMode == UpdateMode.CHECK_ONLY) {
Log.i(TAG, "Found ${updates.size} updates")
return Result.success()
}
// Notify and exit if we are only checking for updates or if battery optimizations are enabled
if (updateMode == UpdateMode.CHECK_AND_NOTIFY || !appContext.isIgnoringBatteryOptimizations()) {
Log.i(TAG, "Found updates, notifying!")
Log.i(TAG, "Found ${updates.size} updates, notifying!")
notifyUpdates(updates)
return Result.success()
}
@@ -219,7 +217,6 @@ class UpdateWorker @AssistedInject constructor(
}
private fun notifyUpdates(updates: List<Update>) {
if (!shouldNotify) return
with(appContext.getSystemService<NotificationManager>()!!) {
notify(
notificationID,

View File

@@ -86,6 +86,8 @@ class UpdatesPreference : BasePreferenceFragment() {
false
}
}
else -> false
}
}