UpdateWorker: Make CHECK_ONLY as a valid update mode
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -43,7 +43,6 @@ class UpdateHelper @Inject constructor(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val UPDATE_MODE = "UPDATE_MODE"
|
const val UPDATE_MODE = "UPDATE_MODE"
|
||||||
const val UPDATE_SHOULD_NOTIFY = "UPDATE_SHOULD_NOTIFY"
|
|
||||||
|
|
||||||
private const val UPDATE_WORKER = "UPDATE_WORKER"
|
private const val UPDATE_WORKER = "UPDATE_WORKER"
|
||||||
private const val EXPEDITED_UPDATE_WORKER = "EXPEDITED_UPDATE_WORKER"
|
private const val EXPEDITED_UPDATE_WORKER = "EXPEDITED_UPDATE_WORKER"
|
||||||
@@ -93,8 +92,7 @@ class UpdateHelper @Inject constructor(
|
|||||||
*/
|
*/
|
||||||
fun checkUpdatesNow() {
|
fun checkUpdatesNow() {
|
||||||
val inputData = Data.Builder()
|
val inputData = Data.Builder()
|
||||||
.putInt(UPDATE_MODE, UpdateMode.CHECK_AND_NOTIFY.ordinal)
|
.putInt(UPDATE_MODE, UpdateMode.CHECK_ONLY.ordinal)
|
||||||
.putBoolean(UPDATE_SHOULD_NOTIFY, false)
|
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val work = OneTimeWorkRequestBuilder<UpdateWorker>()
|
val work = OneTimeWorkRequestBuilder<UpdateWorker>()
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ package com.aurora.store.data.model
|
|||||||
enum class UpdateMode {
|
enum class UpdateMode {
|
||||||
DISABLED,
|
DISABLED,
|
||||||
CHECK_AND_NOTIFY,
|
CHECK_AND_NOTIFY,
|
||||||
CHECK_AND_INSTALL
|
CHECK_AND_INSTALL,
|
||||||
|
CHECK_ONLY,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import com.aurora.gplayapi.network.IHttpClient
|
|||||||
import com.aurora.store.BuildConfig
|
import com.aurora.store.BuildConfig
|
||||||
import com.aurora.store.data.helper.DownloadHelper
|
import com.aurora.store.data.helper.DownloadHelper
|
||||||
import com.aurora.store.data.helper.UpdateHelper
|
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.installer.AppInstaller
|
||||||
import com.aurora.store.data.model.BuildType
|
import com.aurora.store.data.model.BuildType
|
||||||
import com.aurora.store.data.model.SelfUpdate
|
import com.aurora.store.data.model.SelfUpdate
|
||||||
@@ -70,7 +69,6 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
else -> BuildType.DEBUG
|
else -> BuildType.DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
private val shouldNotify = inputData.getBoolean(UPDATE_SHOULD_NOTIFY, true)
|
|
||||||
private val canSelfUpdate = !CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID) &&
|
private val canSelfUpdate = !CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID) &&
|
||||||
!CertUtil.isAppGalleryApp(appContext, BuildConfig.APPLICATION_ID) &&
|
!CertUtil.isAppGalleryApp(appContext, BuildConfig.APPLICATION_ID) &&
|
||||||
buildType != BuildType.DEBUG
|
buildType != BuildType.DEBUG
|
||||||
@@ -102,14 +100,14 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
.also { updateDao.insertUpdates(it) }
|
.also { updateDao.insertUpdates(it) }
|
||||||
.filter { if (!isExtendedUpdateEnabled) it.hasValidCert else true }
|
.filter { if (!isExtendedUpdateEnabled) it.hasValidCert else true }
|
||||||
|
|
||||||
if (updates.isEmpty()) {
|
if (updates.isEmpty() || updateMode == UpdateMode.CHECK_ONLY) {
|
||||||
Log.i(TAG, "No updates found!")
|
Log.i(TAG, "Found ${updates.size} updates")
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify and exit if we are only checking for updates or if battery optimizations are enabled
|
// Notify and exit if we are only checking for updates or if battery optimizations are enabled
|
||||||
if (updateMode == UpdateMode.CHECK_AND_NOTIFY || !appContext.isIgnoringBatteryOptimizations()) {
|
if (updateMode == UpdateMode.CHECK_AND_NOTIFY || !appContext.isIgnoringBatteryOptimizations()) {
|
||||||
Log.i(TAG, "Found updates, notifying!")
|
Log.i(TAG, "Found ${updates.size} updates, notifying!")
|
||||||
notifyUpdates(updates)
|
notifyUpdates(updates)
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
@@ -219,7 +217,6 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyUpdates(updates: List<Update>) {
|
private fun notifyUpdates(updates: List<Update>) {
|
||||||
if (!shouldNotify) return
|
|
||||||
with(appContext.getSystemService<NotificationManager>()!!) {
|
with(appContext.getSystemService<NotificationManager>()!!) {
|
||||||
notify(
|
notify(
|
||||||
notificationID,
|
notificationID,
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class UpdatesPreference : BasePreferenceFragment() {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user