From 075c6e1c05596367d39633191e0af9e18c599b92 Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Mon, 17 Mar 2025 14:07:25 +0800 Subject: [PATCH] work: appContext -> context Signed-off-by: Aayush Gupta --- .../com/aurora/store/data/work/AuthWorker.kt | 22 ++++----- .../com/aurora/store/data/work/CacheWorker.kt | 8 ++-- .../aurora/store/data/work/DownloadWorker.kt | 36 +++++++-------- .../aurora/store/data/work/ExportWorker.kt | 16 +++---- .../aurora/store/data/work/UpdateWorker.kt | 46 +++++++++---------- 5 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/com/aurora/store/data/work/AuthWorker.kt b/app/src/main/java/com/aurora/store/data/work/AuthWorker.kt index c97741f19..22e0fb38f 100644 --- a/app/src/main/java/com/aurora/store/data/work/AuthWorker.kt +++ b/app/src/main/java/com/aurora/store/data/work/AuthWorker.kt @@ -35,14 +35,14 @@ import kotlin.coroutines.suspendCoroutine @HiltWorker open class AuthWorker @AssistedInject constructor( private val authProvider: AuthProvider, - @Assisted private val appContext: Context, + @Assisted private val context: Context, @Assisted workerParams: WorkerParameters -) : CoroutineWorker(appContext, workerParams) { +) : CoroutineWorker(context, workerParams) { private val TAG = AuthWorker::class.java.simpleName override suspend fun doWork(): Result { - if (!AccountProvider.isLoggedIn(appContext)) { + if (!AccountProvider.isLoggedIn(context)) { Log.i(TAG, "User has logged out!") return Result.failure() } @@ -54,11 +54,11 @@ open class AuthWorker @AssistedInject constructor( // Generate and validate new auth try { - val accountType = AccountProvider.getAccountType(appContext) + val accountType = AccountProvider.getAccountType(context) val authData = when (accountType) { AccountType.GOOGLE -> { - val email = AccountProvider.getLoginEmail(appContext) - val tokenPair = AccountProvider.getLoginToken(appContext) + val email = AccountProvider.getLoginEmail(context) + val tokenPair = AccountProvider.getLoginToken(context) if (email == null || tokenPair == null) { throw Exception() @@ -128,14 +128,14 @@ open class AuthWorker @AssistedInject constructor( try { if (oldToken != null) { // Invalidate the old token before requesting a new one - AccountManager.get(appContext) + AccountManager.get(context) .invalidateAuthToken( GOOGLE_ACCOUNT_TYPE, oldToken ) } - AccountManager.get(appContext) + AccountManager.get(context) .getAuthToken( Account(email, GOOGLE_ACCOUNT_TYPE), GOOGLE_PLAY_AUTH_TOKEN_TYPE, @@ -160,7 +160,7 @@ open class AuthWorker @AssistedInject constructor( return if (authData.authToken.isNotEmpty() && authData.deviceConfigToken.isNotEmpty()) { authProvider.saveAuthData(authData) AccountProvider.login( - appContext, + context, authData.email, authData.aasToken.ifBlank { authData.authToken }, if (authData.aasToken.isBlank()) AuthHelper.Token.AUTH else AuthHelper.Token.AAS, @@ -168,8 +168,8 @@ open class AuthWorker @AssistedInject constructor( ) authData } else { - authProvider.removeAuthData(appContext) - AccountProvider.logout(appContext) + authProvider.removeAuthData(context) + AccountProvider.logout(context) null } } diff --git a/app/src/main/java/com/aurora/store/data/work/CacheWorker.kt b/app/src/main/java/com/aurora/store/data/work/CacheWorker.kt index 77309345c..45af60afb 100644 --- a/app/src/main/java/com/aurora/store/data/work/CacheWorker.kt +++ b/app/src/main/java/com/aurora/store/data/work/CacheWorker.kt @@ -23,9 +23,9 @@ import kotlin.time.toDuration */ @HiltWorker class CacheWorker @AssistedInject constructor( - @Assisted private val appContext: Context, + @Assisted private val context: Context, @Assisted workerParams: WorkerParameters -) : CoroutineWorker(appContext, workerParams) { +) : CoroutineWorker(context, workerParams) { companion object { private const val TAG = "CleanCacheWorker" @@ -58,12 +58,12 @@ class CacheWorker @AssistedInject constructor( override suspend fun doWork(): Result { 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") 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 if (download.listFiles().isNullOrEmpty()) { Log.i(TAG, "Removing empty download directory for ${download.name}") diff --git a/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt b/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt index e95f3ae14..a0e4118c1 100644 --- a/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt +++ b/app/src/main/java/com/aurora/store/data/work/DownloadWorker.kt @@ -69,13 +69,13 @@ class DownloadWorker @AssistedInject constructor( private val appInstaller: AppInstaller, private val httpClient: IHttpClient, private val purchaseHelper: PurchaseHelper, - @Assisted private val appContext: Context, + @Assisted private val context: Context, @Assisted workerParams: WorkerParameters -) : AuthWorker(authProvider, appContext, workerParams) { +) : AuthWorker(authProvider, context, workerParams) { private lateinit var download: Download - private val notificationManager = appContext.getSystemService()!! + private val notificationManager = context.getSystemService()!! private var icon: Bitmap? = null private var totalBytes by Delegates.notNull() @@ -85,11 +85,11 @@ class DownloadWorker @AssistedInject constructor( private val TAG = DownloadWorker::class.java.simpleName private val NOTIFICATION_ID: Int = 200 - inner class NoNetworkException : Exception(appContext.getString(R.string.title_no_network)) - inner class NothingToDownloadException : Exception(appContext.getString(R.string.purchase_no_file)) - inner class DownloadFailedException : Exception(appContext.getString(R.string.download_failed)) - inner class DownloadCancelledException : Exception(appContext.getString(R.string.download_canceled)) - inner class VerificationFailedException : Exception(appContext.getString(R.string.verification_failed)) + inner class NoNetworkException : Exception(context.getString(R.string.title_no_network)) + inner class NothingToDownloadException : Exception(context.getString(R.string.purchase_no_file)) + inner class DownloadFailedException : Exception(context.getString(R.string.download_failed)) + inner class DownloadCancelledException : Exception(context.getString(R.string.download_canceled)) + inner class VerificationFailedException : Exception(context.getString(R.string.verification_failed)) override suspend fun doWork(): Result { super.doWork() @@ -120,7 +120,7 @@ class DownloadWorker @AssistedInject constructor( if (download.fileList.isEmpty()) return onFailure(NothingToDownloadException()) // 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 if (download.fileList.requiresObbDir()) { @@ -134,7 +134,7 @@ class DownloadWorker @AssistedInject constructor( download.sharedLibs.forEach { // Create shared lib download dir PathUtil.getLibDownloadDir( - appContext, + context, download.packageName, download.versionCode, it.packageName @@ -226,7 +226,7 @@ class DownloadWorker @AssistedInject constructor( notifyStatus(DownloadStatus.FAILED) AuroraApp.events.send(InstallerEvent.Failed(download.packageName).apply { extra = - exception.message ?: appContext.getString(R.string.download_failed) + exception.message ?: context.getString(R.string.download_failed) error = exception.stackTraceToString() }) } @@ -254,7 +254,7 @@ class DownloadWorker @AssistedInject constructor( packageName, versionCode, offerType, - CertUtil.getEncodedCertificateHashes(appContext, download.packageName).last() + CertUtil.getEncodedCertificateHashes(context, download.packageName).last() ) } else { purchaseHelper.purchase(packageName, versionCode, offerType) @@ -274,7 +274,7 @@ class DownloadWorker @AssistedInject constructor( private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean = withContext(Dispatchers.IO) { 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() && verifyFile(gFile)) { @@ -372,9 +372,9 @@ class DownloadWorker @AssistedInject constructor( override suspend fun getForegroundInfo(): ForegroundInfo { val notification = if (this::download.isInitialized) { - NotificationUtil.getDownloadNotification(appContext, download, icon) + NotificationUtil.getDownloadNotification(context, download, icon) } else { - NotificationUtil.getDownloadNotification(appContext) + NotificationUtil.getDownloadNotification(context) } return if (isQAndAbove) { @@ -406,7 +406,7 @@ class DownloadWorker @AssistedInject constructor( else -> {} } - val notification = NotificationUtil.getDownloadNotification(appContext, download, icon) + val notification = NotificationUtil.getDownloadNotification(context, download, icon) notificationManager.notify( if (isProgress) NOTIFICATION_ID else download.packageName.hashCode(), notification @@ -419,7 +419,7 @@ class DownloadWorker @AssistedInject constructor( */ @OptIn(ExperimentalStdlibApi::class) 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") val algorithm = if (gFile.sha256.isBlank()) Algorithm.SHA1 else Algorithm.SHA256 @@ -447,7 +447,7 @@ class DownloadWorker @AssistedInject constructor( } private fun deleteFile(file: GPlayFile) { - val apkFile = PathUtil.getLocalFile(appContext, file, download) + val apkFile = PathUtil.getLocalFile(context, file, download) if (apkFile.exists()) { apkFile.delete() Log.i(TAG, "Deleted Apk: $apkFile") diff --git a/app/src/main/java/com/aurora/store/data/work/ExportWorker.kt b/app/src/main/java/com/aurora/store/data/work/ExportWorker.kt index 019a882b4..caf8cb9f1 100644 --- a/app/src/main/java/com/aurora/store/data/work/ExportWorker.kt +++ b/app/src/main/java/com/aurora/store/data/work/ExportWorker.kt @@ -31,9 +31,9 @@ import androidx.core.net.toUri */ @HiltWorker class ExportWorker @AssistedInject constructor( - @Assisted private val appContext: Context, + @Assisted private val context: Context, @Assisted workerParams: WorkerParameters -) : CoroutineWorker(appContext, workerParams) { +) : CoroutineWorker(context, workerParams) { companion object { private const val TAG = "ExportWorker" @@ -101,7 +101,7 @@ class ExportWorker @AssistedInject constructor( val displayName = inputData.getString(DISPLAY_NAME) val versionCode = inputData.getInt(VERSION_CODE, -1) - notificationManager = appContext.getSystemService()!! + notificationManager = context.getSystemService()!! if (packageName.isNullOrEmpty() || isDownload && versionCode == -1) { Log.e(TAG, "Input data is corrupt, bailing out!") @@ -128,7 +128,7 @@ class ExportWorker @AssistedInject constructor( override suspend fun getForegroundInfo(): ForegroundInfo { return ForegroundInfo( NOTIFICATION_ID_FGS, - NotificationUtil.getExportNotification(appContext) + NotificationUtil.getExportNotification(context) ) } @@ -136,7 +136,7 @@ class ExportWorker @AssistedInject constructor( notificationManager.notify( NOTIFICATION_ID, NotificationUtil.getExportStatusNotification( - appContext, + context, packageName, uri, success @@ -145,7 +145,7 @@ class ExportWorker @AssistedInject constructor( } 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 = mutableListOf() fileList.add(File(packageInfo.applicationInfo!!.sourceDir)) @@ -158,7 +158,7 @@ class ExportWorker @AssistedInject constructor( private fun copyDownloadedApp(packageName: String, versionCode: Int, uri: Uri) { return bundleAllAPKs( - PathUtil.getAppDownloadDir(appContext, packageName, versionCode).listFiles()!!.toList(), + PathUtil.getAppDownloadDir(context, packageName, versionCode).listFiles()!!.toList(), uri ) } @@ -169,7 +169,7 @@ class ExportWorker @AssistedInject constructor( * @param uri [Uri] of the file to write the APKs */ private fun bundleAllAPKs(fileList: List, uri: Uri) { - ZipOutputStream(appContext.contentResolver.openOutputStream(uri)).use { zipOutput -> + ZipOutputStream(context.contentResolver.openOutputStream(uri)).use { zipOutput -> fileList.forEach { file -> file.inputStream().use { input -> val zipEntry = ZipEntry(file.name) diff --git a/app/src/main/java/com/aurora/store/data/work/UpdateWorker.kt b/app/src/main/java/com/aurora/store/data/work/UpdateWorker.kt index 47761e94d..4142c7d08 100644 --- a/app/src/main/java/com/aurora/store/data/work/UpdateWorker.kt +++ b/app/src/main/java/com/aurora/store/data/work/UpdateWorker.kt @@ -53,26 +53,26 @@ class UpdateWorker @AssistedInject constructor( private val downloadHelper: DownloadHelper, private val authProvider: AuthProvider, private val appDetailsHelper: AppDetailsHelper, - @Assisted private val appContext: Context, + @Assisted private val context: Context, @Assisted workerParams: WorkerParameters -) : AuthWorker(authProvider, appContext, workerParams) { +) : AuthWorker(authProvider, context, workerParams) { private val TAG = UpdateWorker::class.java.simpleName private val notificationID = 100 - private val canSelfUpdate = !CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID) && - !CertUtil.isAppGalleryApp(appContext, BuildConfig.APPLICATION_ID) && + private val canSelfUpdate = !CertUtil.isFDroidApp(context, BuildConfig.APPLICATION_ID) && + !CertUtil.isAppGalleryApp(context, BuildConfig.APPLICATION_ID) && BuildType.CURRENT != BuildType.DEBUG 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 - get() = Preferences.getBoolean(appContext, Preferences.PREFERENCE_FILTER_FDROID) + get() = Preferences.getBoolean(context, Preferences.PREFERENCE_FILTER_FDROID) 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 { super.doWork() @@ -81,13 +81,13 @@ class UpdateWorker @AssistedInject constructor( val updateMode = UpdateMode.entries[inputData.getInt( UpdateHelper.UPDATE_MODE, Preferences.getInteger( - appContext, + context, PREFERENCE_UPDATES_AUTO, 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!") 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 - if (updateMode == UpdateMode.CHECK_AND_NOTIFY || !appContext.isIgnoringBatteryOptimizations()) { + if (updateMode == UpdateMode.CHECK_AND_NOTIFY || !context.isIgnoringBatteryOptimizations()) { Log.i(TAG, "Found ${updates.size} updates, notifying!") notifyUpdates(updates) return Result.success() @@ -117,9 +117,9 @@ class UpdateWorker @AssistedInject constructor( // Clean the update list to prepare for installing val filteredUpdates = updates .filter { it.hasValidCert } - .filterNot { it.isSelfUpdate(appContext) } + .filterNot { it.isSelfUpdate(context) } .partition { - AppInstaller.canInstallSilently(appContext, it.packageName, it.targetSdk) + AppInstaller.canInstallSilently(context, it.packageName, it.targetSdk) } // Notify about apps that cannot be auto-updated @@ -139,7 +139,7 @@ class UpdateWorker @AssistedInject constructor( override suspend fun getForegroundInfo(): ForegroundInfo { return ForegroundInfo( notificationID, - NotificationUtil.getUpdateNotification(appContext) + NotificationUtil.getUpdateNotification(context) ) } @@ -148,25 +148,25 @@ class UpdateWorker @AssistedInject constructor( */ private suspend fun checkUpdates(): List { return withContext(Dispatchers.IO) { - val packages = PackageUtil.getAllValidPackages(appContext) + val packages = PackageUtil.getAllValidPackages(context) .filterNot { blacklistProvider.isBlacklisted(it.packageName) } .filter { if (!isExtendedUpdateEnabled) it.applicationInfo!!.enabled else true } // Filter out packages based on user's preferences val filteredPackages = if (isAuroraOnlyFilterEnabled) { - packages.filter { CertUtil.isAuroraStoreApp(appContext, it.packageName) } + packages.filter { CertUtil.isAuroraStoreApp(context, it.packageName) } } 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 }) .filter { it.displayName.isNotEmpty() } - .filter { PackageUtil.isUpdatable(appContext, it.packageName, it.versionCode.toLong()) } + .filter { PackageUtil.isUpdatable(context, it.packageName, it.versionCode.toLong()) } .toMutableList() 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()) } } } @@ -199,12 +199,12 @@ class UpdateWorker @AssistedInject constructor( } if (isUpdate) { - if (CertUtil.isFDroidApp(appContext, BuildConfig.APPLICATION_ID)) { + if (CertUtil.isFDroidApp(context, BuildConfig.APPLICATION_ID)) { if (selfUpdate.fdroidBuild.isNotEmpty()) { - return@withContext SelfUpdate.toApp(selfUpdate, appContext) + return@withContext SelfUpdate.toApp(selfUpdate, context) } } else if (selfUpdate.auroraBuild.isNotEmpty()) { - return@withContext SelfUpdate.toApp(selfUpdate, appContext) + return@withContext SelfUpdate.toApp(selfUpdate, context) } else { Log.e(TAG, "Update file is missing!") return@withContext null @@ -221,10 +221,10 @@ class UpdateWorker @AssistedInject constructor( } private fun notifyUpdates(updates: List) { - with(appContext.getSystemService()!!) { + with(context.getSystemService()!!) { notify( notificationID, - NotificationUtil.getUpdateNotification(appContext, updates) + NotificationUtil.getUpdateNotification(context, updates) ) } }