reformat files recently touched
This commit is contained in:
@@ -67,13 +67,21 @@ open class AuthWorker @AssistedInject constructor(
|
|||||||
when (tokenPair.second) {
|
when (tokenPair.second) {
|
||||||
AuthHelper.Token.AAS -> {
|
AuthHelper.Token.AAS -> {
|
||||||
Log.i(TAG, "Refreshing AuthData for personal account")
|
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 -> {
|
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)
|
val newToken = fetchAuthToken(email, tokenPair.first)
|
||||||
authProvider.buildGoogleAuthData(email, newToken, AuthHelper.Token.AAS).getOrThrow()
|
authProvider.buildGoogleAuthData(email, newToken, AuthHelper.Token.AAS)
|
||||||
|
.getOrThrow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,60 +298,61 @@ class DownloadWorker @AssistedInject constructor(
|
|||||||
* @param gFile A [GPlayFile] to download
|
* @param gFile A [GPlayFile] to download
|
||||||
* @return A [Boolean] indicating whether the file was downloaded or not.
|
* @return A [Boolean] indicating whether the file was downloaded or not.
|
||||||
*/
|
*/
|
||||||
private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean = withContext(Dispatchers.IO) {
|
private suspend fun downloadFile(packageName: String, gFile: GPlayFile): Boolean =
|
||||||
Log.i(TAG, "Downloading $packageName @ ${gFile.name}")
|
withContext(Dispatchers.IO) {
|
||||||
val file = PathUtil.getLocalFile(appContext, gFile, download)
|
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 and has integrity intact, no need to download again
|
||||||
if (file.exists() && verifyFile(gFile)) {
|
if (file.exists() && verifyFile(gFile)) {
|
||||||
Log.i(TAG, "$file is already downloaded!")
|
Log.i(TAG, "$file is already downloaded!")
|
||||||
downloadedBytes += file.length()
|
downloadedBytes += file.length()
|
||||||
return@withContext true
|
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<String, String>()
|
|
||||||
|
|
||||||
if (!isNewFile) {
|
|
||||||
Log.i(TAG, "$tmpFile has an unfinished download, resuming!")
|
|
||||||
downloadedBytes += tmpFile.length()
|
|
||||||
headers["Range"] = "bytes=${tmpFile.length()}-"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
okHttpClient.call(gFile.url, headers).body?.byteStream()?.use { input ->
|
try {
|
||||||
FileOutputStream(tmpFile, !isNewFile).use {
|
val tmpFileSuffix = ".tmp"
|
||||||
input.copyTo(it, gFile.size).collect { info -> onProgress(info) }
|
val tmpFile = File(file.absolutePath + tmpFileSuffix)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!tmpFile.renameTo(file)) {
|
// Download as a temporary file to avoid installing corrupted files
|
||||||
throw Exception("Failed to remove .tmp extension from $tmpFile")
|
val isNewFile = tmpFile.createNewFile()
|
||||||
}
|
|
||||||
|
|
||||||
return@withContext true
|
val okHttpClient = httpClient as HttpClient
|
||||||
} catch (exception: Exception) {
|
val headers = mutableMapOf<String, String>()
|
||||||
when (exception) {
|
|
||||||
is SocketException,
|
if (!isNewFile) {
|
||||||
is SocketTimeoutException,
|
Log.i(TAG, "$tmpFile has an unfinished download, resuming!")
|
||||||
is UnknownHostException -> {
|
downloadedBytes += tmpFile.length()
|
||||||
throw Exceptions.NoNetworkException()
|
headers["Range"] = "bytes=${tmpFile.length()}-"
|
||||||
}
|
}
|
||||||
|
|
||||||
is CancellationException -> {
|
okHttpClient.call(gFile.url, headers).body?.byteStream()?.use { input ->
|
||||||
throw Exceptions.DownloadCancelledException()
|
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.
|
* Updates the progress data of the download in the local database and notifies user.
|
||||||
|
|||||||
@@ -132,7 +132,12 @@ object NotificationUtil {
|
|||||||
builder.setContentIntent(getContentIntentForDetails(context, download.packageName))
|
builder.setContentIntent(getContentIntentForDetails(context, download.packageName))
|
||||||
|
|
||||||
// Show install action if app cannot be silently installed
|
// 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(
|
builder.addAction(
|
||||||
NotificationCompat.Action.Builder(
|
NotificationCompat.Action.Builder(
|
||||||
R.drawable.ic_install,
|
R.drawable.ic_install,
|
||||||
|
|||||||
Reference in New Issue
Block a user