Skip to content

Commit

Permalink
remove services from manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
newhinton committed Nov 9, 2023
1 parent 8cf16b8 commit 3115e28
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 43 deletions.
6 changes: 0 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@
android:name=".Services.ReportService"
android:foregroundServiceType="dataSync" />

<service android:name=".workmanager.SyncManager"
android:foregroundServiceType="dataSync" />

<service android:name=".workmanager.SyncWorker"
android:foregroundServiceType="dataSync" />

<receiver android:name=".BroadcastReceivers.DownloadCancelAction" />
<receiver android:name=".BroadcastReceivers.UploadCancelAction" />
<receiver android:name=".BroadcastReceivers.ServeCancelAction" />
Expand Down
68 changes: 31 additions & 37 deletions app/src/main/java/ca/pkay/rcloneexplorer/workmanager/SyncWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,53 +85,47 @@ class SyncWorker (private var mContext: Context, workerParams: WorkerParameters)


override suspend fun doWork(): Result {
return try {
prepareNotifications()
registerBroadcastReceivers()
prepareNotifications()
registerBroadcastReceivers()

updateForegroundNotification(mNotificationManager.updateSyncNotification(
mTitle,
mTitle,
ArrayList(),
0,
ongoingNotificationID
))
updateForegroundNotification(mNotificationManager.updateSyncNotification(
mTitle,
mTitle,
ArrayList(),
0,
ongoingNotificationID
))


var ephemeralTask: Task? = null
var ephemeralTask: Task? = null

if(inputData.keyValueMap.containsKey(TASK_ID)){
val id = inputData.getLong(TASK_ID, -1)
ephemeralTask = mDatabase.getTask(id)
}
if(inputData.keyValueMap.containsKey(TASK_ID)){
val id = inputData.getLong(TASK_ID, -1)
ephemeralTask = mDatabase.getTask(id)
}

if(inputData.keyValueMap.containsKey(TASK_EPHEMERAL)){
val taskString = inputData.getString(TASK_EPHEMERAL) ?: ""
if(taskString.isNotEmpty()) {
try {
ephemeralTask = Json.decodeFromString<Task>(taskString)
} catch (e: Exception) {
log("Could not deserialize")
}
if(inputData.keyValueMap.containsKey(TASK_EPHEMERAL)){
val taskString = inputData.getString(TASK_EPHEMERAL) ?: ""
if(taskString.isNotEmpty()) {
try {
ephemeralTask = Json.decodeFromString<Task>(taskString)
} catch (e: Exception) {
log("Could not deserialize")
}
}
}

if (ephemeralTask != null) {
mTask = ephemeralTask
handleTask()
postSync()
} else {
postSync()
return Result.failure()
}

// Indicate whether the work finished successfully with the Result
return Result.success()
} catch (e: CancellationException) {
Log.e(TAG, "cancel")
// here clean up
if (ephemeralTask != null) {
mTask = ephemeralTask
handleTask()
postSync()
} else {
postSync()
return Result.failure()
}

// Indicate whether the work finished successfully with the Result
return Result.success()
}

fun onStop() {
Expand Down

0 comments on commit 3115e28

Please sign in to comment.