Offer selfupdate for nightlies
This commit is contained in:
@@ -29,6 +29,7 @@ import com.aurora.store.util.NotificationUtil
|
|||||||
import com.aurora.store.util.PackageUtil
|
import com.aurora.store.util.PackageUtil
|
||||||
import com.aurora.store.util.Preferences
|
import com.aurora.store.util.Preferences
|
||||||
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_AUTO
|
import com.aurora.store.util.Preferences.PREFERENCE_UPDATES_AUTO
|
||||||
|
import com.aurora.store.util.save
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
@@ -155,12 +156,24 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
val filteredPackages = if (isAuroraOnlyFilterEnabled) {
|
val filteredPackages = if (isAuroraOnlyFilterEnabled) {
|
||||||
packages.filter { CertUtil.isAuroraStoreApp(appContext, it.packageName) }
|
packages.filter { CertUtil.isAuroraStoreApp(appContext, it.packageName) }
|
||||||
} else {
|
} else {
|
||||||
packages.filterNot { if (isFDroidFilterEnabled) CertUtil.isFDroidApp(appContext, it.packageName) else false }
|
packages.filterNot {
|
||||||
|
if (isFDroidFilterEnabled)
|
||||||
|
CertUtil.isFDroidApp(appContext, it.packageName)
|
||||||
|
else
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val updates = appDetailsHelper.getAppByPackageName(filteredPackages.map { it.packageName })
|
val updates =
|
||||||
|
appDetailsHelper.getAppByPackageName(filteredPackages.map { it.packageName })
|
||||||
.filter { it.displayName.isNotEmpty() }
|
.filter { it.displayName.isNotEmpty() }
|
||||||
.filter { PackageUtil.isUpdatable(appContext, it.packageName, it.versionCode.toLong()) }
|
.filter {
|
||||||
|
PackageUtil.isUpdatable(
|
||||||
|
appContext,
|
||||||
|
it.packageName,
|
||||||
|
it.versionCode.toLong()
|
||||||
|
)
|
||||||
|
}
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
|
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
|
||||||
@@ -191,13 +204,30 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
SelfUpdate::class.java
|
SelfUpdate::class.java
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val lastSelfUpdate = gson.fromJson(
|
||||||
|
Preferences.getString(
|
||||||
|
appContext,
|
||||||
|
Preferences.PREFERENCE_SELF_UPDATE,
|
||||||
|
"{}"
|
||||||
|
),
|
||||||
|
SelfUpdate::class.java
|
||||||
|
)
|
||||||
|
|
||||||
|
if (lastSelfUpdate.versionCode == 0) {
|
||||||
|
Log.i(TAG, "No old self-updates entry found, saving current!")
|
||||||
|
saveSelfUpdate(selfUpdate)
|
||||||
|
return@withContext null
|
||||||
|
}
|
||||||
|
|
||||||
val isUpdate = when (BuildType.CURRENT) {
|
val isUpdate = when (BuildType.CURRENT) {
|
||||||
BuildType.NIGHTLY,
|
BuildType.NIGHTLY -> selfUpdate.timestamp > lastSelfUpdate.timestamp
|
||||||
BuildType.RELEASE -> selfUpdate.versionCode > BuildConfig.VERSION_CODE
|
BuildType.RELEASE -> selfUpdate.versionCode > BuildConfig.VERSION_CODE
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
|
saveSelfUpdate(selfUpdate)
|
||||||
|
|
||||||
if (CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID)) {
|
if (CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID)) {
|
||||||
if (selfUpdate.fdroidBuild.isNotEmpty()) {
|
if (selfUpdate.fdroidBuild.isNotEmpty()) {
|
||||||
return@withContext SelfUpdate.toApp(selfUpdate, appContext)
|
return@withContext SelfUpdate.toApp(selfUpdate, appContext)
|
||||||
@@ -208,6 +238,9 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
Log.e(TAG, "Update file is missing!")
|
Log.e(TAG, "Update file is missing!")
|
||||||
return@withContext null
|
return@withContext null
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "No self-updates found!")
|
||||||
|
return@withContext null
|
||||||
}
|
}
|
||||||
} catch (exception: Exception) {
|
} catch (exception: Exception) {
|
||||||
Log.e(TAG, "Failed to check self-updates", exception)
|
Log.e(TAG, "Failed to check self-updates", exception)
|
||||||
@@ -219,6 +252,13 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun saveSelfUpdate(selfUpdate: SelfUpdate) {
|
||||||
|
appContext.save(
|
||||||
|
Preferences.PREFERENCE_SELF_UPDATE,
|
||||||
|
gson.toJson(selfUpdate)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun notifyUpdates(updates: List<Update>) {
|
private fun notifyUpdates(updates: List<Update>) {
|
||||||
with(appContext.getSystemService<NotificationManager>()!!) {
|
with(appContext.getSystemService<NotificationManager>()!!) {
|
||||||
notify(
|
notify(
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ object Preferences {
|
|||||||
const val PREFERENCE_UPDATES_AUTO = "PREFERENCE_UPDATES_AUTO"
|
const val PREFERENCE_UPDATES_AUTO = "PREFERENCE_UPDATES_AUTO"
|
||||||
const val PREFERENCE_UPDATES_CHECK_INTERVAL = "PREFERENCE_UPDATES_CHECK_INTERVAL"
|
const val PREFERENCE_UPDATES_CHECK_INTERVAL = "PREFERENCE_UPDATES_CHECK_INTERVAL"
|
||||||
|
|
||||||
|
const val PREFERENCE_SELF_UPDATE = "PREFERENCE_SELF_UPDATE"
|
||||||
|
|
||||||
const val PREFERENCE_MIGRATION_VERSION = "PREFERENCE_MIGRATION_VERSION"
|
const val PREFERENCE_MIGRATION_VERSION = "PREFERENCE_MIGRATION_VERSION"
|
||||||
|
|
||||||
private var prefs: SharedPreferences? = null
|
private var prefs: SharedPreferences? = null
|
||||||
|
|||||||
Reference in New Issue
Block a user