UpdateWorker: Only auto-update apps when possible
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -63,6 +63,19 @@ class AppInstaller @Inject constructor(
|
|||||||
const val EXTRA_VERSION_CODE = "com.aurora.store.data.installer.AppInstaller.EXTRA_VERSION_CODE"
|
const val EXTRA_VERSION_CODE = "com.aurora.store.data.installer.AppInstaller.EXTRA_VERSION_CODE"
|
||||||
const val EXTRA_DISPLAY_NAME = "com.aurora.store.data.installer.AppInstaller.EXTRA_DISPLAY_NAME"
|
const val EXTRA_DISPLAY_NAME = "com.aurora.store.data.installer.AppInstaller.EXTRA_DISPLAY_NAME"
|
||||||
|
|
||||||
|
enum class Installer {
|
||||||
|
SESSION,
|
||||||
|
NATIVE,
|
||||||
|
ROOT,
|
||||||
|
SERVICE,
|
||||||
|
AM,
|
||||||
|
SHIZUKU
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCurrentInstaller(context: Context): Installer {
|
||||||
|
return Installer.entries[Preferences.getInteger(context, PREFERENCE_INSTALLER_ID)]
|
||||||
|
}
|
||||||
|
|
||||||
fun getAvailableInstallersInfo(context: Context): List<InstallerInfo> {
|
fun getAvailableInstallersInfo(context: Context): List<InstallerInfo> {
|
||||||
val installers = mutableListOf(
|
val installers = mutableListOf(
|
||||||
SessionInstaller.getInstallerInfo(context),
|
SessionInstaller.getInstallerInfo(context),
|
||||||
@@ -162,20 +175,19 @@ class AppInstaller @Inject constructor(
|
|||||||
get() = sessionInstaller
|
get() = sessionInstaller
|
||||||
|
|
||||||
fun getPreferredInstaller(): IInstaller {
|
fun getPreferredInstaller(): IInstaller {
|
||||||
return when (Preferences.getInteger(context, PREFERENCE_INSTALLER_ID)) {
|
return when (getCurrentInstaller(context)) {
|
||||||
0 -> sessionInstaller
|
Installer.SESSION -> sessionInstaller
|
||||||
1 -> nativeInstaller
|
Installer.NATIVE -> nativeInstaller
|
||||||
2 -> if (hasRootAccess()) rootInstaller else defaultInstaller
|
Installer.ROOT -> if (hasRootAccess()) rootInstaller else defaultInstaller
|
||||||
3 -> if (hasAuroraService(context)) serviceInstaller else defaultInstaller
|
Installer.SERVICE -> if (hasAuroraService(context)) serviceInstaller else defaultInstaller
|
||||||
4 -> if (hasAppManager(context)) amInstaller else defaultInstaller
|
Installer.AM -> if (hasAppManager(context)) amInstaller else defaultInstaller
|
||||||
5 -> {
|
Installer.SHIZUKU -> {
|
||||||
if (isOAndAbove() && hasShizukuOrSui(context) && hasShizukuPerm()) {
|
if (isOAndAbove() && hasShizukuOrSui(context) && hasShizukuPerm()) {
|
||||||
shizukuInstaller
|
shizukuInstaller
|
||||||
} else {
|
} else {
|
||||||
defaultInstaller
|
defaultInstaller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> defaultInstaller
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,13 @@ import androidx.work.WorkManager
|
|||||||
import androidx.work.WorkerParameters
|
import androidx.work.WorkerParameters
|
||||||
import com.aurora.extensions.isIgnoringBatteryOptimizations
|
import com.aurora.extensions.isIgnoringBatteryOptimizations
|
||||||
import com.aurora.extensions.isMAndAbove
|
import com.aurora.extensions.isMAndAbove
|
||||||
|
import com.aurora.extensions.isOAndAbove
|
||||||
|
import com.aurora.extensions.isSAndAbove
|
||||||
|
import com.aurora.store.data.installer.AppInstaller
|
||||||
|
import com.aurora.store.data.installer.AppInstaller.Companion.Installer
|
||||||
import com.aurora.store.data.providers.AuthProvider
|
import com.aurora.store.data.providers.AuthProvider
|
||||||
import com.aurora.store.util.AppUtil
|
import com.aurora.store.util.AppUtil
|
||||||
|
import com.aurora.store.util.CertUtil
|
||||||
import com.aurora.store.util.DownloadWorkerUtil
|
import com.aurora.store.util.DownloadWorkerUtil
|
||||||
import com.aurora.store.util.NotificationUtil
|
import com.aurora.store.util.NotificationUtil
|
||||||
import com.aurora.store.util.Preferences
|
import com.aurora.store.util.Preferences
|
||||||
@@ -120,8 +125,24 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (appContext.isIgnoringBatteryOptimizations()) {
|
if (appContext.isIgnoringBatteryOptimizations()) {
|
||||||
Log.i(TAG, "Found updates, updating!")
|
// Trigger download for apps if they can be auto-updated (if any)
|
||||||
updatesList.forEach { downloadWorkerUtil.enqueueApp(it) }
|
updatesList.filter { canAutoUpdate(it.packageName) }.let { list ->
|
||||||
|
if (list.isEmpty()) return@let
|
||||||
|
|
||||||
|
Log.i(TAG, "Found auto-update enabled apps, updating!")
|
||||||
|
list.forEach { downloadWorkerUtil.enqueueApp(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify about remaining apps (if any)
|
||||||
|
updatesList.filterNot { canAutoUpdate(it.packageName) }.let { list ->
|
||||||
|
if (list.isEmpty()) return@let
|
||||||
|
|
||||||
|
Log.i(TAG, "Found apps that cannot be auto-updated, notifying!")
|
||||||
|
notifyManager.notify(
|
||||||
|
notificationID,
|
||||||
|
NotificationUtil.getUpdateNotification(appContext, list)
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fallback to notification if battery optimizations are enabled
|
// Fallback to notification if battery optimizations are enabled
|
||||||
Log.i(TAG, "Found updates, but battery optimizations are enabled!")
|
Log.i(TAG, "Found updates, but battery optimizations are enabled!")
|
||||||
@@ -143,4 +164,16 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
return Result.success()
|
return Result.success()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun canAutoUpdate(packageName: String): Boolean {
|
||||||
|
return when (AppInstaller.getCurrentInstaller(appContext)) {
|
||||||
|
Installer.SESSION -> isSAndAbove() && CertUtil.isAuroraStoreApp(appContext, packageName)
|
||||||
|
Installer.NATIVE -> false
|
||||||
|
Installer.ROOT -> AppInstaller.hasRootAccess()
|
||||||
|
Installer.SERVICE -> AppInstaller.hasAuroraService(appContext)
|
||||||
|
Installer.AM -> false // We cannot check if AppManager has ability to auto-update
|
||||||
|
Installer.SHIZUKU -> isOAndAbove() && AppInstaller.hasShizukuOrSui(appContext) &&
|
||||||
|
AppInstaller.hasShizukuPerm()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.content.pm.PackageInfo
|
|||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.aurora.Constants
|
||||||
import com.aurora.extensions.generateX509Certificate
|
import com.aurora.extensions.generateX509Certificate
|
||||||
import com.aurora.extensions.getInstallerPackageNameCompat
|
import com.aurora.extensions.getInstallerPackageNameCompat
|
||||||
import com.aurora.extensions.isPAndAbove
|
import com.aurora.extensions.isPAndAbove
|
||||||
@@ -35,6 +36,10 @@ object CertUtil {
|
|||||||
|
|
||||||
private val TAG = "CertUtil"
|
private val TAG = "CertUtil"
|
||||||
|
|
||||||
|
fun isAuroraStoreApp(context: Context, packageName: String): Boolean {
|
||||||
|
return context.packageManager.getInstallerPackageNameCompat(packageName) == context.packageName
|
||||||
|
}
|
||||||
|
|
||||||
fun isFDroidApp(context: Context, packageName: String): Boolean {
|
fun isFDroidApp(context: Context, packageName: String): Boolean {
|
||||||
return isInstalledByFDroid(context, packageName) || isSignedByFDroid(context, packageName)
|
return isInstalledByFDroid(context, packageName) || isSignedByFDroid(context, packageName)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user