Fix file exporter worker on devices running android < 12

This commit is contained in:
Rahul Patel
2024-08-11 00:19:24 +05:30
committed by Aayush Gupta
parent 7957a04ecf
commit 33b398cb3b
4 changed files with 25 additions and 6 deletions

View File

@@ -304,7 +304,7 @@ class DownloadWorker @AssistedInject constructor(
Log.e(TAG, "Incorrect hash for ${request.file}") Log.e(TAG, "Incorrect hash for ${request.file}")
throw Exception("Incorrect hash") throw Exception("Incorrect hash")
} }
} catch (exception: Exception) { } catch (exception: Exception) {
Log.e(TAG, "Failed to download ${request.file}!", exception) Log.e(TAG, "Failed to download ${request.file}!", exception)
notifyStatus(DownloadStatus.FAILED) notifyStatus(DownloadStatus.FAILED)
@@ -357,6 +357,7 @@ class DownloadWorker @AssistedInject constructor(
} else { } else {
NotificationUtil.getDownloadNotification(appContext) NotificationUtil.getDownloadNotification(appContext)
} }
return if (isQAndAbove()) { return if (isQAndAbove()) {
ForegroundInfo(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC) ForegroundInfo(NOTIFICATION_ID, notification, FOREGROUND_SERVICE_TYPE_DATA_SYNC)
} else { } else {
@@ -441,7 +442,7 @@ class DownloadWorker @AssistedInject constructor(
} }
return proxy return proxy
} else { } else {
Log.i(TAG,"Proxy is disabled") Log.i(TAG, "Proxy is disabled")
return null return null
} }
} }

View File

@@ -9,11 +9,11 @@ import android.util.Log
import androidx.hilt.work.HiltWorker import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker import androidx.work.CoroutineWorker
import androidx.work.Data import androidx.work.Data
import androidx.work.ForegroundInfo
import androidx.work.OneTimeWorkRequestBuilder import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkManager import androidx.work.WorkManager
import androidx.work.WorkerParameters import androidx.work.WorkerParameters
import com.aurora.gplayapi.data.models.App
import com.aurora.store.data.model.MinimalApp import com.aurora.store.data.model.MinimalApp
import com.aurora.store.data.room.download.Download import com.aurora.store.data.room.download.Download
import com.aurora.store.util.NotificationUtil import com.aurora.store.util.NotificationUtil
@@ -104,7 +104,7 @@ class ExportWorker @AssistedInject constructor(
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!")
notifyStatus(displayName?: String(), uri, false) notifyStatus(displayName ?: String(), uri, false)
return Result.failure() return Result.failure()
} }
@@ -117,13 +117,20 @@ class ExportWorker @AssistedInject constructor(
notifyStatus(displayName ?: packageName, uri) notifyStatus(displayName ?: packageName, uri)
} catch (exception: Exception) { } catch (exception: Exception) {
Log.e(TAG, "Failed to export $packageName", exception) Log.e(TAG, "Failed to export $packageName", exception)
notifyStatus(displayName?: packageName, uri, false) notifyStatus(displayName ?: packageName, uri, false)
return Result.failure() return Result.failure()
} }
return Result.success() return Result.success()
} }
override suspend fun getForegroundInfo(): ForegroundInfo {
return ForegroundInfo(
NOTIFICATION_ID,
NotificationUtil.getExportNotification(appContext)
)
}
private fun notifyStatus(packageName: String, uri: Uri, success: Boolean = true) { private fun notifyStatus(packageName: String, uri: Uri, success: Boolean = true) {
notificationManager.notify( notificationManager.notify(
NOTIFICATION_ID, NOTIFICATION_ID,

View File

@@ -19,7 +19,6 @@ import androidx.navigation.NavDeepLinkBuilder
import androidx.work.WorkManager import androidx.work.WorkManager
import com.aurora.Constants import com.aurora.Constants
import com.aurora.extensions.getStyledAttributeColor import com.aurora.extensions.getStyledAttributeColor
import com.aurora.gplayapi.data.models.App
import com.aurora.store.MainActivity import com.aurora.store.MainActivity
import com.aurora.store.R import com.aurora.store.R
import com.aurora.store.data.activity.InstallActivity import com.aurora.store.data.activity.InstallActivity
@@ -252,6 +251,16 @@ object NotificationUtil {
.build() .build()
} }
fun getExportNotification(context: Context): Notification {
return NotificationCompat.Builder(context, Constants.NOTIFICATION_CHANNEL_ALERT)
.setSmallIcon(R.drawable.ic_file_copy)
.setColor(context.getStyledAttributeColor(R.color.colorAccent))
.setContentTitle(context.getString(R.string.export_app_title))
.setContentText(context.getString(R.string.export_app_summary))
.setOngoing(false)
.build()
}
fun getExportStatusNotification( fun getExportStatusNotification(
context: Context, context: Context,
displayName: String, displayName: String,

View File

@@ -470,6 +470,8 @@
<string name="toast_fav_export_success">Favourites exported!</string> <string name="toast_fav_export_success">Favourites exported!</string>
<!-- ExportWorker --> <!-- ExportWorker -->
<string name="export_app_title">File Exporter</string>
<string name="export_app_summary">Hold on, exporting your file</string>
<string name="export_app_summary_success">Successfully exported app bundle</string> <string name="export_app_summary_success">Successfully exported app bundle</string>
<string name="export_app_summary_fail">Failed to exported app bundle</string> <string name="export_app_summary_fail">Failed to exported app bundle</string>