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

Remove the usages of WorkManager's SettableFuture #2650

Closed
kuanyingchou opened this issue Apr 10, 2024 · 3 comments · Fixed by #2656
Closed

Remove the usages of WorkManager's SettableFuture #2650

kuanyingchou opened this issue Apr 10, 2024 · 3 comments · Fixed by #2656

Comments

@kuanyingchou
Copy link

kuanyingchou commented Apr 10, 2024

Problem description

Hi, we would like to remove SettableFuture from WorkManager but found that LeakCanary is using it:

/~https://github.com/search?q=repo%3Asquare%2Fleakcanary%20settablefuture&type=code

Potential solutions

Is it possible to remove the usages of SettableFuture as it's WorkManager's internal API?

Additional information

Here's our change in WorkManager: https://android-review.googlesource.com/c/platform/frameworks/support/+/3000016/1

@pyricau
Copy link
Member

pyricau commented Apr 17, 2024

@kuanyingchou Do you have a suggestion on what to replace it with? I don't mind updating, just need some guidance on how to implement getForegroundInfoAsync(): ListenableFuture<ForegroundInfo>. I suspect I did this based on some example implementation I found, no idea where though.

That being said, even after updating, it'll still be in older releases of LeakCanary.

I'm also surprised because that class has @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP), I wonder why the compiler didn't yell at me.

@pyricau
Copy link
Member

pyricau commented Apr 17, 2024

Conversation in ASG for anyone who has access: https://androidstudygroup.slack.com/archives/CAYMXJE0H/p1713384243471319

@kuanyingchou
Copy link
Author

kuanyingchou commented Apr 17, 2024

Hi, @pyricau , thanks for the reply! I think it can be replaced with getFuture() or launchFuture() (for suspend functions) from androidx.concurrent (some examples here and here), but it may introduce a new dependency.

I'm not sure about the update path either. Let's see what the folks on ASG say.

pyricau added a commit that referenced this issue Apr 17, 2024
Updating the WorkManager version to `2.8.0` which added `Worker.getForegroundInfo` ([release notes](https://developer.android.com/jetpack/androidx/releases/work#2.8.0)) which removes the need to mess with `ListenableFuture`.

Fixes #2650
pyricau added a commit that referenced this issue Apr 17, 2024
Updating the WorkManager version to `2.8.0` which added `Worker.getForegroundInfo` ([release notes](https://developer.android.com/jetpack/androidx/releases/work#2.8.0)) which removes the need to mess with `ListenableFuture`.

Fixes #2650
pyricau added a commit that referenced this issue Apr 17, 2024
Updating the WorkManager version to `2.9.0` which added `Worker.getForegroundInfo` ([release notes](https://developer.android.com/jetpack/androidx/releases/work#2.8.0)) which removes the need to mess with `ListenableFuture`.

Also add (implicit in 2.9.0) dependency on futures so that we can use `CallbackToFutureAdapter` when extending `RemoteListenableWorker` which does not offer a `getForegroundInfo` implementation.

Fixes #2650
pyricau added a commit that referenced this issue Apr 17, 2024
Updating the WorkManager version to `2.9.0` which added `Worker.getForegroundInfo` ([release notes](https://developer.android.com/jetpack/androidx/releases/work#2.8.0)) which removes the need to mess with `ListenableFuture`.

Also add (implicit in 2.9.0) dependency on futures so that we can use `CallbackToFutureAdapter` when extending `RemoteListenableWorker` which does not offer a `getForegroundInfo` implementation.

Fixes #2650
pyricau added a commit that referenced this issue Apr 17, 2024
Updating the WorkManager version to `2.9.0` which added `Worker.getForegroundInfo` ([release notes](https://developer.android.com/jetpack/androidx/releases/work#2.8.0)) which removes the need to mess with `ListenableFuture`.

Also add (implicit in 2.9.0) dependency on futures so that we can use `CallbackToFutureAdapter` when extending `RemoteListenableWorker` which does not offer a `getForegroundInfo` implementation.

Fixes #2650
pyricau added a commit that referenced this issue Apr 17, 2024
Updating the WorkManager version to `2.9.0` which added `Worker.getForegroundInfo` ([release notes](https://developer.android.com/jetpack/androidx/releases/work#2.8.0)) which removes the need to mess with `ListenableFuture`.

Also add (implicit in 2.9.0) dependency on futures so that we can use `CallbackToFutureAdapter` when extending `RemoteListenableWorker` which does not offer a `getForegroundInfo` implementation.

Fixes #2650
pyricau added a commit that referenced this issue Apr 18, 2024
Adding `LazyImmediateFuture` which removes the need to use `SettableFuture`.

Fixes #2650
pyricau added a commit that referenced this issue Apr 18, 2024
Adding `LazyImmediateFuture` which removes the need to use `SettableFuture`.

Fixes #2650
@pyricau pyricau added this to the 2.14 milestone Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants