work: appContext -> context
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -35,14 +35,14 @@ import kotlin.coroutines.suspendCoroutine
|
|||||||
@HiltWorker
|
@HiltWorker
|
||||||
open class AuthWorker @AssistedInject constructor(
|
open class AuthWorker @AssistedInject constructor(
|
||||||
private val authProvider: AuthProvider,
|
private val authProvider: AuthProvider,
|
||||||
@Assisted private val appContext: Context,
|
@Assisted private val context: Context,
|
||||||
@Assisted workerParams: WorkerParameters
|
@Assisted workerParams: WorkerParameters
|
||||||
) : CoroutineWorker(appContext, workerParams) {
|
) : CoroutineWorker(context, workerParams) {
|
||||||
|
|
||||||
private val TAG = AuthWorker::class.java.simpleName
|
private val TAG = AuthWorker::class.java.simpleName
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
if (!AccountProvider.isLoggedIn(appContext)) {
|
if (!AccountProvider.isLoggedIn(context)) {
|
||||||
Log.i(TAG, "User has logged out!")
|
Log.i(TAG, "User has logged out!")
|
||||||
return Result.failure()
|
return Result.failure()
|
||||||
}
|
}
|
||||||
@@ -54,11 +54,11 @@ open class AuthWorker @AssistedInject constructor(
|
|||||||
|
|
||||||
// Generate and validate new auth
|
// Generate and validate new auth
|
||||||
try {
|
try {
|
||||||
val accountType = AccountProvider.getAccountType(appContext)
|
val accountType = AccountProvider.getAccountType(context)
|
||||||
val authData = when (accountType) {
|
val authData = when (accountType) {
|
||||||
AccountType.GOOGLE -> {
|
AccountType.GOOGLE -> {
|
||||||
val email = AccountProvider.getLoginEmail(appContext)
|
val email = AccountProvider.getLoginEmail(context)
|
||||||
val tokenPair = AccountProvider.getLoginToken(appContext)
|
val tokenPair = AccountProvider.getLoginToken(context)
|
||||||
|
|
||||||
if (email == null || tokenPair == null) {
|
if (email == null || tokenPair == null) {
|
||||||
throw Exception()
|
throw Exception()
|
||||||
@@ -128,14 +128,14 @@ open class AuthWorker @AssistedInject constructor(
|
|||||||
try {
|
try {
|
||||||
if (oldToken != null) {
|
if (oldToken != null) {
|
||||||
// Invalidate the old token before requesting a new one
|
// Invalidate the old token before requesting a new one
|
||||||
AccountManager.get(appContext)
|
AccountManager.get(context)
|
||||||
.invalidateAuthToken(
|
.invalidateAuthToken(
|
||||||
GOOGLE_ACCOUNT_TYPE,
|
GOOGLE_ACCOUNT_TYPE,
|
||||||
oldToken
|
oldToken
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountManager.get(appContext)
|
AccountManager.get(context)
|
||||||
.getAuthToken(
|
.getAuthToken(
|
||||||
Account(email, GOOGLE_ACCOUNT_TYPE),
|
Account(email, GOOGLE_ACCOUNT_TYPE),
|
||||||
GOOGLE_PLAY_AUTH_TOKEN_TYPE,
|
GOOGLE_PLAY_AUTH_TOKEN_TYPE,
|
||||||
@@ -160,7 +160,7 @@ open class AuthWorker @AssistedInject constructor(
|
|||||||
return if (authData.authToken.isNotEmpty() && authData.deviceConfigToken.isNotEmpty()) {
|
return if (authData.authToken.isNotEmpty() && authData.deviceConfigToken.isNotEmpty()) {
|
||||||
authProvider.saveAuthData(authData)
|
authProvider.saveAuthData(authData)
|
||||||
AccountProvider.login(
|
AccountProvider.login(
|
||||||
appContext,
|
context,
|
||||||
authData.email,
|
authData.email,
|
||||||
authData.aasToken.ifBlank { authData.authToken },
|
authData.aasToken.ifBlank { authData.authToken },
|
||||||
if (authData.aasToken.isBlank()) AuthHelper.Token.AUTH else AuthHelper.Token.AAS,
|
if (authData.aasToken.isBlank()) AuthHelper.Token.AUTH else AuthHelper.Token.AAS,
|
||||||
@@ -168,8 +168,8 @@ open class AuthWorker @AssistedInject constructor(
|
|||||||
)
|
)
|
||||||
authData
|
authData
|
||||||
} else {
|
} else {
|
||||||
authProvider.removeAuthData(appContext)
|
authProvider.removeAuthData(context)
|
||||||
AccountProvider.logout(appContext)
|
AccountProvider.logout(context)
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import kotlin.time.toDuration
|
|||||||
*/
|
*/
|
||||||
@HiltWorker
|
@HiltWorker
|
||||||
class CacheWorker @AssistedInject constructor(
|
class CacheWorker @AssistedInject constructor(
|
||||||
@Assisted private val appContext: Context,
|
@Assisted private val context: Context,
|
||||||
@Assisted workerParams: WorkerParameters
|
@Assisted workerParams: WorkerParameters
|
||||||
) : CoroutineWorker(appContext, workerParams) {
|
) : CoroutineWorker(context, workerParams) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "CleanCacheWorker"
|
private const val TAG = "CleanCacheWorker"
|
||||||
@@ -58,12 +58,12 @@ class CacheWorker @AssistedInject constructor(
|
|||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
Log.i(TAG, "Cleaning cache")
|
Log.i(TAG, "Cleaning cache")
|
||||||
|
|
||||||
PathUtil.getOldDownloadDirectories(appContext).filter { it.exists() }.forEach { dir -> // Downloads
|
PathUtil.getOldDownloadDirectories(context).filter { it.exists() }.forEach { dir -> // Downloads
|
||||||
Log.i(TAG, "Deleting old unused download directory: $dir")
|
Log.i(TAG, "Deleting old unused download directory: $dir")
|
||||||
dir.deleteRecursively()
|
dir.deleteRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
PathUtil.getDownloadDirectory(appContext).listFiles()?.forEach { download -> // com.example.app
|
PathUtil.getDownloadDirectory(context).listFiles()?.forEach { download -> // com.example.app
|
||||||
// Delete if the download directory is empty
|
// Delete if the download directory is empty
|
||||||
if (download.listFiles().isNullOrEmpty()) {
|
if (download.listFiles().isNullOrEmpty()) {
|
||||||
Log.i(TAG, "Removing empty download directory for ${download.name}")
|
Log.i(TAG, "Removing empty download directory for ${download.name}")
|
||||||
|
|||||||
@@ -69,13 +69,13 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
private val appInstaller: AppInstaller,
|
private val appInstaller: AppInstaller,
|
||||||
private val httpClient: IHttpClient,
|
private val httpClient: IHttpClient,
|
||||||
private val purchaseHelper: PurchaseHelper,
|
private val purchaseHelper: PurchaseHelper,
|
||||||
@Assisted private val appContext: Context,
|
@Assisted private val context: Context,
|
||||||
@Assisted workerParams: WorkerParameters
|
@Assisted workerParams: WorkerParameters
|
||||||
) : AuthWorker(authProvider, appContext, workerParams) {
|
) : AuthWorker(authProvider, context, workerParams) {
|
||||||
|
|
||||||
private lateinit var download: Download
|
private lateinit var download: Download
|
||||||
|
|
||||||
private val notificationManager = appContext.getSystemService<NotificationManager>()!!
|
private val notificationManager = context.getSystemService<NotificationManager>()!!
|
||||||
|
|
||||||
private var icon: Bitmap? = null
|
private var icon: Bitmap? = null
|
||||||
private var totalBytes by Delegates.notNull<Long>()
|
private var totalBytes by Delegates.notNull<Long>()
|
||||||
@@ -85,11 +85,11 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
private val TAG = DownloadWorker::class.java.simpleName
|
private val TAG = DownloadWorker::class.java.simpleName
|
||||||
private val NOTIFICATION_ID: Int = 200
|
private val NOTIFICATION_ID: Int = 200
|
||||||
|
|
||||||
inner class NoNetworkException : Exception(appContext.getString(R.string.title_no_network))
|
inner class NoNetworkException : Exception(context.getString(R.string.title_no_network))
|
||||||
inner class NothingToDownloadException : Exception(appContext.getString(R.string.purchase_no_file))
|
inner class NothingToDownloadException : Exception(context.getString(R.string.purchase_no_file))
|
||||||
inner class DownloadFailedException : Exception(appContext.getString(R.string.download_failed))
|
inner class DownloadFailedException : Exception(context.getString(R.string.download_failed))
|
||||||
inner class DownloadCancelledException : Exception(appContext.getString(R.string.download_canceled))
|
inner class DownloadCancelledException : Exception(context.getString(R.string.download_canceled))
|
||||||
inner class VerificationFailedException : Exception(appContext.getString(R.string.verification_failed))
|
inner class VerificationFailedException : Exception(context.getString(R.string.verification_failed))
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
super.doWork()
|
super.doWork()
|
||||||
@@ -120,7 +120,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
if (download.fileList.isEmpty()) return onFailure(NothingToDownloadException())
|
if (download.fileList.isEmpty()) return onFailure(NothingToDownloadException())
|
||||||
|
|
||||||
// Create dirs & generate download request for files and shared libs (if any)
|
// Create dirs & generate download request for files and shared libs (if any)
|
||||||
PathUtil.getAppDownloadDir(appContext, download.packageName, download.versionCode).mkdirs()
|
PathUtil.getAppDownloadDir(context, download.packageName, download.versionCode).mkdirs()
|
||||||
|
|
||||||
// Create OBB dir if required
|
// Create OBB dir if required
|
||||||
if (download.fileList.requiresObbDir()) {
|
if (download.fileList.requiresObbDir()) {
|
||||||
@@ -134,7 +134,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
download.sharedLibs.forEach {
|
download.sharedLibs.forEach {
|
||||||
// Create shared lib download dir
|
// Create shared lib download dir
|
||||||
PathUtil.getLibDownloadDir(
|
PathUtil.getLibDownloadDir(
|
||||||
appContext,
|
context,
|
||||||
download.packageName,
|
download.packageName,
|
||||||
download.versionCode,
|
download.versionCode,
|
||||||
it.packageName
|
it.packageName
|
||||||
@@ -226,7 +226,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
notifyStatus(DownloadStatus.FAILED)
|
notifyStatus(DownloadStatus.FAILED)
|
||||||
AuroraApp.events.send(InstallerEvent.Failed(download.packageName).apply {
|
AuroraApp.events.send(InstallerEvent.Failed(download.packageName).apply {
|
||||||
extra =
|
extra =
|
||||||
exception.message ?: appContext.getString(R.string.download_failed)
|
exception.message ?: context.getString(R.string.download_failed)
|
||||||
error = exception.stackTraceToString()
|
error = exception.stackTraceToString()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
packageName,
|
packageName,
|
||||||
versionCode,
|
versionCode,
|
||||||
offerType,
|
offerType,
|
||||||
CertUtil.getEncodedCertificateHashes(appContext, download.packageName).last()
|
CertUtil.getEncodedCertificateHashes(context, download.packageName).last()
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
purchaseHelper.purchase(packageName, versionCode, offerType)
|
purchaseHelper.purchase(packageName, versionCode, offerType)
|
||||||
@@ -274,7 +274,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean =
|
private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
Log.i(TAG, "Downloading $packageName @ ${gFile.name}")
|
Log.i(TAG, "Downloading $packageName @ ${gFile.name}")
|
||||||
val file = PathUtil.getLocalFile(appContext, gFile, download)
|
val file = PathUtil.getLocalFile(context, gFile, download)
|
||||||
|
|
||||||
// If file exists and has integrity intact, no need to download again
|
// If file exists and has integrity intact, no need to download again
|
||||||
if (file.exists() && verifyFile(gFile)) {
|
if (file.exists() && verifyFile(gFile)) {
|
||||||
@@ -372,9 +372,9 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
|
|
||||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||||
val notification = if (this::download.isInitialized) {
|
val notification = if (this::download.isInitialized) {
|
||||||
NotificationUtil.getDownloadNotification(appContext, download, icon)
|
NotificationUtil.getDownloadNotification(context, download, icon)
|
||||||
} else {
|
} else {
|
||||||
NotificationUtil.getDownloadNotification(appContext)
|
NotificationUtil.getDownloadNotification(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (isQAndAbove) {
|
return if (isQAndAbove) {
|
||||||
@@ -406,7 +406,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
val notification = NotificationUtil.getDownloadNotification(appContext, download, icon)
|
val notification = NotificationUtil.getDownloadNotification(context, download, icon)
|
||||||
notificationManager.notify(
|
notificationManager.notify(
|
||||||
if (isProgress) NOTIFICATION_ID else download.packageName.hashCode(),
|
if (isProgress) NOTIFICATION_ID else download.packageName.hashCode(),
|
||||||
notification
|
notification
|
||||||
@@ -419,7 +419,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
*/
|
*/
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
private suspend fun verifyFile(gFile: GPlayFile): Boolean {
|
private suspend fun verifyFile(gFile: GPlayFile): Boolean {
|
||||||
val file = PathUtil.getLocalFile(appContext, gFile, download)
|
val file = PathUtil.getLocalFile(context, gFile, download)
|
||||||
Log.i(TAG, "Verifying $file")
|
Log.i(TAG, "Verifying $file")
|
||||||
|
|
||||||
val algorithm = if (gFile.sha256.isBlank()) Algorithm.SHA1 else Algorithm.SHA256
|
val algorithm = if (gFile.sha256.isBlank()) Algorithm.SHA1 else Algorithm.SHA256
|
||||||
@@ -447,7 +447,7 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteFile(file: GPlayFile) {
|
private fun deleteFile(file: GPlayFile) {
|
||||||
val apkFile = PathUtil.getLocalFile(appContext, file, download)
|
val apkFile = PathUtil.getLocalFile(context, file, download)
|
||||||
if (apkFile.exists()) {
|
if (apkFile.exists()) {
|
||||||
apkFile.delete()
|
apkFile.delete()
|
||||||
Log.i(TAG, "Deleted Apk: $apkFile")
|
Log.i(TAG, "Deleted Apk: $apkFile")
|
||||||
|
|||||||
@@ -31,9 +31,9 @@ import androidx.core.net.toUri
|
|||||||
*/
|
*/
|
||||||
@HiltWorker
|
@HiltWorker
|
||||||
class ExportWorker @AssistedInject constructor(
|
class ExportWorker @AssistedInject constructor(
|
||||||
@Assisted private val appContext: Context,
|
@Assisted private val context: Context,
|
||||||
@Assisted workerParams: WorkerParameters
|
@Assisted workerParams: WorkerParameters
|
||||||
) : CoroutineWorker(appContext, workerParams) {
|
) : CoroutineWorker(context, workerParams) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "ExportWorker"
|
private const val TAG = "ExportWorker"
|
||||||
@@ -101,7 +101,7 @@ class ExportWorker @AssistedInject constructor(
|
|||||||
val displayName = inputData.getString(DISPLAY_NAME)
|
val displayName = inputData.getString(DISPLAY_NAME)
|
||||||
val versionCode = inputData.getInt(VERSION_CODE, -1)
|
val versionCode = inputData.getInt(VERSION_CODE, -1)
|
||||||
|
|
||||||
notificationManager = appContext.getSystemService<NotificationManager>()!!
|
notificationManager = context.getSystemService<NotificationManager>()!!
|
||||||
|
|
||||||
if (packageName.isNullOrEmpty() || isDownload && versionCode == -1) {
|
if (packageName.isNullOrEmpty() || isDownload && versionCode == -1) {
|
||||||
Log.e(TAG, "Input data is corrupt, bailing out!")
|
Log.e(TAG, "Input data is corrupt, bailing out!")
|
||||||
@@ -128,7 +128,7 @@ class ExportWorker @AssistedInject constructor(
|
|||||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||||
return ForegroundInfo(
|
return ForegroundInfo(
|
||||||
NOTIFICATION_ID_FGS,
|
NOTIFICATION_ID_FGS,
|
||||||
NotificationUtil.getExportNotification(appContext)
|
NotificationUtil.getExportNotification(context)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ class ExportWorker @AssistedInject constructor(
|
|||||||
notificationManager.notify(
|
notificationManager.notify(
|
||||||
NOTIFICATION_ID,
|
NOTIFICATION_ID,
|
||||||
NotificationUtil.getExportStatusNotification(
|
NotificationUtil.getExportStatusNotification(
|
||||||
appContext,
|
context,
|
||||||
packageName,
|
packageName,
|
||||||
uri,
|
uri,
|
||||||
success
|
success
|
||||||
@@ -145,7 +145,7 @@ class ExportWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun copyInstalledApp(packageName: String, uri: Uri) {
|
private fun copyInstalledApp(packageName: String, uri: Uri) {
|
||||||
val packageInfo = getPackageInfo(appContext, packageName, PackageManager.GET_META_DATA)
|
val packageInfo = getPackageInfo(context, packageName, PackageManager.GET_META_DATA)
|
||||||
val fileList: MutableList<File?> = mutableListOf()
|
val fileList: MutableList<File?> = mutableListOf()
|
||||||
|
|
||||||
fileList.add(File(packageInfo.applicationInfo!!.sourceDir))
|
fileList.add(File(packageInfo.applicationInfo!!.sourceDir))
|
||||||
@@ -158,7 +158,7 @@ class ExportWorker @AssistedInject constructor(
|
|||||||
|
|
||||||
private fun copyDownloadedApp(packageName: String, versionCode: Int, uri: Uri) {
|
private fun copyDownloadedApp(packageName: String, versionCode: Int, uri: Uri) {
|
||||||
return bundleAllAPKs(
|
return bundleAllAPKs(
|
||||||
PathUtil.getAppDownloadDir(appContext, packageName, versionCode).listFiles()!!.toList(),
|
PathUtil.getAppDownloadDir(context, packageName, versionCode).listFiles()!!.toList(),
|
||||||
uri
|
uri
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ class ExportWorker @AssistedInject constructor(
|
|||||||
* @param uri [Uri] of the file to write the APKs
|
* @param uri [Uri] of the file to write the APKs
|
||||||
*/
|
*/
|
||||||
private fun bundleAllAPKs(fileList: List<File>, uri: Uri) {
|
private fun bundleAllAPKs(fileList: List<File>, uri: Uri) {
|
||||||
ZipOutputStream(appContext.contentResolver.openOutputStream(uri)).use { zipOutput ->
|
ZipOutputStream(context.contentResolver.openOutputStream(uri)).use { zipOutput ->
|
||||||
fileList.forEach { file ->
|
fileList.forEach { file ->
|
||||||
file.inputStream().use { input ->
|
file.inputStream().use { input ->
|
||||||
val zipEntry = ZipEntry(file.name)
|
val zipEntry = ZipEntry(file.name)
|
||||||
|
|||||||
@@ -53,26 +53,26 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
private val downloadHelper: DownloadHelper,
|
private val downloadHelper: DownloadHelper,
|
||||||
private val authProvider: AuthProvider,
|
private val authProvider: AuthProvider,
|
||||||
private val appDetailsHelper: AppDetailsHelper,
|
private val appDetailsHelper: AppDetailsHelper,
|
||||||
@Assisted private val appContext: Context,
|
@Assisted private val context: Context,
|
||||||
@Assisted workerParams: WorkerParameters
|
@Assisted workerParams: WorkerParameters
|
||||||
) : AuthWorker(authProvider, appContext, workerParams) {
|
) : AuthWorker(authProvider, context, workerParams) {
|
||||||
|
|
||||||
private val TAG = UpdateWorker::class.java.simpleName
|
private val TAG = UpdateWorker::class.java.simpleName
|
||||||
|
|
||||||
private val notificationID = 100
|
private val notificationID = 100
|
||||||
|
|
||||||
private val canSelfUpdate = !CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID) &&
|
private val canSelfUpdate = !CertUtil.isFDroidApp(context, BuildConfig.APPLICATION_ID) &&
|
||||||
!CertUtil.isAppGalleryApp(appContext, BuildConfig.APPLICATION_ID) &&
|
!CertUtil.isAppGalleryApp(context, BuildConfig.APPLICATION_ID) &&
|
||||||
BuildType.CURRENT != BuildType.DEBUG
|
BuildType.CURRENT != BuildType.DEBUG
|
||||||
|
|
||||||
private val isAuroraOnlyFilterEnabled: Boolean
|
private val isAuroraOnlyFilterEnabled: Boolean
|
||||||
get() = Preferences.getBoolean(appContext, Preferences.PREFERENCE_FILTER_AURORA_ONLY, false)
|
get() = Preferences.getBoolean(context, Preferences.PREFERENCE_FILTER_AURORA_ONLY, false)
|
||||||
|
|
||||||
private val isFDroidFilterEnabled: Boolean
|
private val isFDroidFilterEnabled: Boolean
|
||||||
get() = Preferences.getBoolean(appContext, Preferences.PREFERENCE_FILTER_FDROID)
|
get() = Preferences.getBoolean(context, Preferences.PREFERENCE_FILTER_FDROID)
|
||||||
|
|
||||||
private val isExtendedUpdateEnabled: Boolean
|
private val isExtendedUpdateEnabled: Boolean
|
||||||
get() = Preferences.getBoolean(appContext, Preferences.PREFERENCE_UPDATES_EXTENDED)
|
get() = Preferences.getBoolean(context, Preferences.PREFERENCE_UPDATES_EXTENDED)
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
super.doWork()
|
super.doWork()
|
||||||
@@ -81,13 +81,13 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
val updateMode = UpdateMode.entries[inputData.getInt(
|
val updateMode = UpdateMode.entries[inputData.getInt(
|
||||||
UpdateHelper.UPDATE_MODE,
|
UpdateHelper.UPDATE_MODE,
|
||||||
Preferences.getInteger(
|
Preferences.getInteger(
|
||||||
appContext,
|
context,
|
||||||
PREFERENCE_UPDATES_AUTO,
|
PREFERENCE_UPDATES_AUTO,
|
||||||
UpdateMode.CHECK_AND_INSTALL.ordinal
|
UpdateMode.CHECK_AND_INSTALL.ordinal
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
|
|
||||||
if (updateMode == UpdateMode.DISABLED || !AccountProvider.isLoggedIn(appContext)) {
|
if (updateMode == UpdateMode.DISABLED || !AccountProvider.isLoggedIn(context)) {
|
||||||
Log.i(TAG, "Updates are disabled, bailing out!")
|
Log.i(TAG, "Updates are disabled, bailing out!")
|
||||||
return Result.failure()
|
return Result.failure()
|
||||||
}
|
}
|
||||||
@@ -108,7 +108,7 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 || !context.isIgnoringBatteryOptimizations()) {
|
||||||
Log.i(TAG, "Found ${updates.size} updates, notifying!")
|
Log.i(TAG, "Found ${updates.size} updates, notifying!")
|
||||||
notifyUpdates(updates)
|
notifyUpdates(updates)
|
||||||
return Result.success()
|
return Result.success()
|
||||||
@@ -117,9 +117,9 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
// Clean the update list to prepare for installing
|
// Clean the update list to prepare for installing
|
||||||
val filteredUpdates = updates
|
val filteredUpdates = updates
|
||||||
.filter { it.hasValidCert }
|
.filter { it.hasValidCert }
|
||||||
.filterNot { it.isSelfUpdate(appContext) }
|
.filterNot { it.isSelfUpdate(context) }
|
||||||
.partition {
|
.partition {
|
||||||
AppInstaller.canInstallSilently(appContext, it.packageName, it.targetSdk)
|
AppInstaller.canInstallSilently(context, it.packageName, it.targetSdk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify about apps that cannot be auto-updated
|
// Notify about apps that cannot be auto-updated
|
||||||
@@ -139,7 +139,7 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||||
return ForegroundInfo(
|
return ForegroundInfo(
|
||||||
notificationID,
|
notificationID,
|
||||||
NotificationUtil.getUpdateNotification(appContext)
|
NotificationUtil.getUpdateNotification(context)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,25 +148,25 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
*/
|
*/
|
||||||
private suspend fun checkUpdates(): List<Update> {
|
private suspend fun checkUpdates(): List<Update> {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
val packages = PackageUtil.getAllValidPackages(appContext)
|
val packages = PackageUtil.getAllValidPackages(context)
|
||||||
.filterNot { blacklistProvider.isBlacklisted(it.packageName) }
|
.filterNot { blacklistProvider.isBlacklisted(it.packageName) }
|
||||||
.filter { if (!isExtendedUpdateEnabled) it.applicationInfo!!.enabled else true }
|
.filter { if (!isExtendedUpdateEnabled) it.applicationInfo!!.enabled else true }
|
||||||
|
|
||||||
// Filter out packages based on user's preferences
|
// Filter out packages based on user's preferences
|
||||||
val filteredPackages = if (isAuroraOnlyFilterEnabled) {
|
val filteredPackages = if (isAuroraOnlyFilterEnabled) {
|
||||||
packages.filter { CertUtil.isAuroraStoreApp(appContext, it.packageName) }
|
packages.filter { CertUtil.isAuroraStoreApp(context, it.packageName) }
|
||||||
} else {
|
} else {
|
||||||
packages.filterNot { if (isFDroidFilterEnabled) CertUtil.isFDroidApp(appContext, it.packageName) else false }
|
packages.filterNot { if (isFDroidFilterEnabled) CertUtil.isFDroidApp(context, 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(context, it.packageName, it.versionCode.toLong()) }
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
|
if (canSelfUpdate) getSelfUpdate()?.let { updates.add(it) }
|
||||||
|
|
||||||
return@withContext updates.map { Update.fromApp(appContext, it) }
|
return@withContext updates.map { Update.fromApp(context, it) }
|
||||||
.sortedBy { it.displayName.lowercase(Locale.getDefault()) }
|
.sortedBy { it.displayName.lowercase(Locale.getDefault()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,12 +199,12 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
if (CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID)) {
|
if (CertUtil.isFDroidApp(context, BuildConfig.APPLICATION_ID)) {
|
||||||
if (selfUpdate.fdroidBuild.isNotEmpty()) {
|
if (selfUpdate.fdroidBuild.isNotEmpty()) {
|
||||||
return@withContext SelfUpdate.toApp(selfUpdate, appContext)
|
return@withContext SelfUpdate.toApp(selfUpdate, context)
|
||||||
}
|
}
|
||||||
} else if (selfUpdate.auroraBuild.isNotEmpty()) {
|
} else if (selfUpdate.auroraBuild.isNotEmpty()) {
|
||||||
return@withContext SelfUpdate.toApp(selfUpdate, appContext)
|
return@withContext SelfUpdate.toApp(selfUpdate, context)
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "Update file is missing!")
|
Log.e(TAG, "Update file is missing!")
|
||||||
return@withContext null
|
return@withContext null
|
||||||
@@ -221,10 +221,10 @@ class UpdateWorker @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyUpdates(updates: List<Update>) {
|
private fun notifyUpdates(updates: List<Update>) {
|
||||||
with(appContext.getSystemService<NotificationManager>()!!) {
|
with(context.getSystemService<NotificationManager>()!!) {
|
||||||
notify(
|
notify(
|
||||||
notificationID,
|
notificationID,
|
||||||
NotificationUtil.getUpdateNotification(appContext, updates)
|
NotificationUtil.getUpdateNotification(context, updates)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user