Conversation
Using a combination of a started and bound service is overly complex for what we are trying to achieve and there is no need since we are not doing cross process communication. Now DropInService is a started service that we can access through a static registry and we are in full control of it's lifecycle.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request refactors DropInService to simplify its lifecycle management by moving from a bound service to a started service that uses a static registry. This change effectively addresses the described memory leak. My review focuses on ensuring the new implementation is robust and thread-safe. I've identified a potential race condition in DropInServiceRegistry and a possibility of app crashes in DropInServiceManager under certain conditions. Addressing these points will make the new implementation more resilient.
| // Implement a queue similar in functionality to one in v5 DropInActivity. | ||
| suspend fun requestOnSubmit(state: PaymentComponentState<*>): CheckoutResult { | ||
| return binder?.requestOnSubmit(state) ?: error("Service is not bound") | ||
| return DropInServiceRegistry.get()?.onSubmit(state) ?: error("Service is not available") |
There was a problem hiding this comment.
Calling error() will crash the application if the service is not available. This could happen if this method is called before the service is fully initialized. A more robust approach is to return a CheckoutResult.Error. This prevents a crash and allows the UI to handle the error gracefully.
| return DropInServiceRegistry.get()?.onSubmit(state) ?: error("Service is not available") | |
| return DropInServiceRegistry.get()?.onSubmit(state) ?: CheckoutResult.Error("Service is not available") |
|
|
||
| suspend fun requestOnAdditionalDetails(data: ActionComponentData): CheckoutResult { | ||
| return binder?.requestOnAdditionalDetails(data) ?: error("Service is not bound") | ||
| return DropInServiceRegistry.get()?.onAdditionalDetails(data) ?: error("Service is not available") |
There was a problem hiding this comment.
Calling error() will crash the application if the service is not available. This could happen if this method is called before the service is fully initialized. A more robust approach is to return a CheckoutResult.Error. This prevents a crash and allows the UI to handle the error gracefully.
| return DropInServiceRegistry.get()?.onAdditionalDetails(data) ?: error("Service is not available") | |
| return DropInServiceRegistry.get()?.onAdditionalDetails(data) ?: CheckoutResult.Error("Service is not available") |
| import com.adyen.checkout.dropin.DropInService | ||
|
|
||
| internal object DropInServiceRegistry { | ||
| private var service: DropInService? = null |
There was a problem hiding this comment.
The service property can be accessed from multiple threads. register() and unregister() are called on the main thread, but get() can be called from background threads. To ensure visibility of changes to service across threads and prevent potential race conditions, it should be marked as @Volatile.
| private var service: DropInService? = null | |
| @Volatile private var service: DropInService? = null |
🚫 Public API changesdrop-in@@ -69,9 +69,11 @@ public abstract interface class com/adyen/checkout/dropin/DropInResultCallback {
public abstract class com/adyen/checkout/dropin/DropInService : androidx/lifecycle/LifecycleService {
public static final field $stable I
public fun <init> ()V
+ public abstract fun onAdditionalDetails (Lcom/adyen/checkout/core/action/data/ActionComponentData;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun onCreate ()V
public fun onDestroy ()V
public fun onStartCommand (Landroid/content/Intent;II)I
+ public abstract fun onSubmit (Lcom/adyen/checkout/core/components/paymentmethod/PaymentComponentState;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
public final class com/adyen/checkout/dropin/internal/ui/ComposableSingletons$ConfirmationDialogKt {If these changes are intentional run |
|


Description
This PR fixes a memory caused by DropInService by simplifying it's lifecycle management. Using a combination of a started and bound service is overly complex for what we are trying to achieve and there is no need since we are not doing cross process communication. Now DropInService is a started service that we can access through a static registry and we are in full control of it's lifecycle.