Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@W-16797266: [TRUST] Ensure all WorkManager Jobs have an associated tag or unique name #2629

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package com.salesforce.androidsdk.analytics
import android.content.Context
import androidx.work.Constraints
import androidx.work.ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE
import androidx.work.ExistingWorkPolicy.REPLACE
import androidx.work.ListenableWorker.Result.success
import androidx.work.NetworkType.CONNECTED
import androidx.work.OneTimeWorkRequest
Expand Down Expand Up @@ -127,7 +128,11 @@ internal class AnalyticsPublishingWorker(
).build().also { publishAnalyticsOneTimeWorkRequest ->
runCatching {
getInstance(context)
}.getOrNull()?.enqueue(publishAnalyticsOneTimeWorkRequest)
}.getOrNull()?.enqueueUniqueWork(
PUBLISH_ANALYTICS_WORK_NAME,
REPLACE,
publishAnalyticsOneTimeWorkRequest
)
}.id

PublishPeriodically -> PeriodicWorkRequest.Builder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import com.salesforce.androidsdk.push.PushMessaging.getRegistrationId
import com.salesforce.androidsdk.push.PushMessaging.setRegistrationId
import com.salesforce.androidsdk.push.PushMessaging.setRegistrationInfo
import com.salesforce.androidsdk.push.PushNotificationsRegistrationChangeWorker.PushNotificationsRegistrationAction
import com.salesforce.androidsdk.push.PushNotificationsRegistrationChangeWorker.PushNotificationsRegistrationAction.Deregister
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed this was an unused import. It wasn't used in the logic on dev in this source. It is used elsewhere, though.

import com.salesforce.androidsdk.push.PushNotificationsRegistrationChangeWorker.PushNotificationsRegistrationAction.Register
import com.salesforce.androidsdk.push.PushService.PushNotificationReRegistrationType.ReRegisterPeriodically
import com.salesforce.androidsdk.push.PushService.PushNotificationReRegistrationType.ReRegistrationDisabled
Expand Down Expand Up @@ -447,6 +446,12 @@ open class PushService {
protected const val UNREGISTRATION_STATUS_SUCCEEDED = 2
protected const val UNREGISTRATION_STATUS_FAILED = 3

/**
* The Android background tasks name of the push notifications
* unregistration work request
*/
private const val PUSH_NOTIFICATIONS_UNREGISTRATION_WORK_NAME = "SalesforcePushNotificationsUnregistrationWork"

/**
* The Android background tasks name of the push notifications
* registration work request
Expand Down Expand Up @@ -520,7 +525,11 @@ open class PushService {
.setInputData(workData)
.setConstraints(constraints)
.build().also { workRequest ->
workManager.enqueue(workRequest)
workManager.enqueueUniqueWork(
PUSH_NOTIFICATIONS_UNREGISTRATION_WORK_NAME,
REPLACE,
workRequest
)
}

// Send broadcast now to finish logout if we are offline.
Expand Down