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 56b18abfa..c97741f19 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 @@ -67,13 +67,21 @@ open class AuthWorker @AssistedInject constructor( when (tokenPair.second) { AuthHelper.Token.AAS -> { Log.i(TAG, "Refreshing AuthData for personal account") - authProvider.buildGoogleAuthData(email, tokenPair.first, AuthHelper.Token.AAS).getOrThrow() + authProvider.buildGoogleAuthData( + email, + tokenPair.first, + AuthHelper.Token.AAS + ).getOrThrow() } AuthHelper.Token.AUTH -> { - Log.i(TAG, "Refreshing AuthData for personal account using AccountManager") + Log.i( + TAG, + "Refreshing AuthData for personal account using AccountManager" + ) val newToken = fetchAuthToken(email, tokenPair.first) - authProvider.buildGoogleAuthData(email, newToken, AuthHelper.Token.AAS).getOrThrow() + authProvider.buildGoogleAuthData(email, newToken, AuthHelper.Token.AAS) + .getOrThrow() } } } 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 26efe0fe2..647d898ca 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 @@ -298,60 +298,61 @@ class DownloadWorker @AssistedInject constructor( * @param gFile A [GPlayFile] to download * @return A [Boolean] indicating whether the file was downloaded or not. */ - 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) + 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) - // If file exists and has integrity intact, no need to download again - if (file.exists() && verifyFile(gFile)) { - Log.i(TAG, "$file is already downloaded!") - downloadedBytes += file.length() - return@withContext true - } - - try { - val tmpFileSuffix = ".tmp" - val tmpFile = File(file.absolutePath + tmpFileSuffix) - - // Download as a temporary file to avoid installing corrupted files - val isNewFile = tmpFile.createNewFile() - - val okHttpClient = httpClient as HttpClient - val headers = mutableMapOf() - - if (!isNewFile) { - Log.i(TAG, "$tmpFile has an unfinished download, resuming!") - downloadedBytes += tmpFile.length() - headers["Range"] = "bytes=${tmpFile.length()}-" + // If file exists and has integrity intact, no need to download again + if (file.exists() && verifyFile(gFile)) { + Log.i(TAG, "$file is already downloaded!") + downloadedBytes += file.length() + return@withContext true } - okHttpClient.call(gFile.url, headers).body?.byteStream()?.use { input -> - FileOutputStream(tmpFile, !isNewFile).use { - input.copyTo(it, gFile.size).collect { info -> onProgress(info) } - } - } + try { + val tmpFileSuffix = ".tmp" + val tmpFile = File(file.absolutePath + tmpFileSuffix) - if (!tmpFile.renameTo(file)) { - throw Exception("Failed to remove .tmp extension from $tmpFile") - } + // Download as a temporary file to avoid installing corrupted files + val isNewFile = tmpFile.createNewFile() - return@withContext true - } catch (exception: Exception) { - when (exception) { - is SocketException, - is SocketTimeoutException, - is UnknownHostException -> { - throw Exceptions.NoNetworkException() + val okHttpClient = httpClient as HttpClient + val headers = mutableMapOf() + + if (!isNewFile) { + Log.i(TAG, "$tmpFile has an unfinished download, resuming!") + downloadedBytes += tmpFile.length() + headers["Range"] = "bytes=${tmpFile.length()}-" } - is CancellationException -> { - throw Exceptions.DownloadCancelledException() + okHttpClient.call(gFile.url, headers).body?.byteStream()?.use { input -> + FileOutputStream(tmpFile, !isNewFile).use { + input.copyTo(it, gFile.size).collect { info -> onProgress(info) } + } } - else -> throw exception + if (!tmpFile.renameTo(file)) { + throw Exception("Failed to remove .tmp extension from $tmpFile") + } + + return@withContext true + } catch (exception: Exception) { + when (exception) { + is SocketException, + is SocketTimeoutException, + is UnknownHostException -> { + throw Exceptions.NoNetworkException() + } + + is CancellationException -> { + throw Exceptions.DownloadCancelledException() + } + + else -> throw exception + } } } - } /** * Updates the progress data of the download in the local database and notifies user. diff --git a/app/src/main/java/com/aurora/store/util/NotificationUtil.kt b/app/src/main/java/com/aurora/store/util/NotificationUtil.kt index a4338c860..21533141e 100644 --- a/app/src/main/java/com/aurora/store/util/NotificationUtil.kt +++ b/app/src/main/java/com/aurora/store/util/NotificationUtil.kt @@ -132,7 +132,12 @@ object NotificationUtil { builder.setContentIntent(getContentIntentForDetails(context, download.packageName)) // Show install action if app cannot be silently installed - if (!AppInstaller.canInstallSilently(context, download.packageName, download.targetSdk)) { + if (!AppInstaller.canInstallSilently( + context, + download.packageName, + download.targetSdk + ) + ) { builder.addAction( NotificationCompat.Action.Builder( R.drawable.ic_install,