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

Fix leaking activity context #109

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ploboda
Copy link

@ploboda ploboda commented May 13, 2024

Despite clear instructions in Superwall SDK's docs to pass the application context to the Superwall.configure() method, given no type safe distinction between activity context and application context, it's possible to mistakenly pass an activity context, like in the example app. That can lead to memory leaks, as the SDK holds a reference to the context for its whole lifecycle that is longer than lifecycle of an Activity.
It can also cause app crashes, for example when initialising JavaScriptSandbox after the activity is finished.
Steps to reproduce the crash in Example application:

  • Disable Paywalls preloading, e.g. in Superwall options
  • Finish MainActivity when navigating to HomeActivity
  • Run Example app
  • Click "Log in" and "Launch Feature" to initialise JavaScriptSandbox after MainActivity is finished.

Logs:

FATAL EXCEPTION: ExpressionEvaluator
Process: com.superwall.superapp, PID: 21254
java.lang.RuntimeException: bindService() returned false Intent { cmp=com.google.android.webview/org.chromium.android_webview.js_sandbox.service.JsSandboxService0 }
	at androidx.javascriptengine.JavaScriptSandbox.lambda$bindToServiceWithCallback$1(JavaScriptSandbox.java:423)
	at androidx.javascriptengine.JavaScriptSandbox$$ExternalSyntheticLambda0.attachCompleter(Unknown Source:6)
	at androidx.concurrent.futures.CallbackToFutureAdapter.getFuture(CallbackToFutureAdapter.java:102)
	at androidx.javascriptengine.JavaScriptSandbox.bindToServiceWithCallback(JavaScriptSandbox.java:410)
	at androidx.javascriptengine.JavaScriptSandbox.createConnectedInstanceAsync(JavaScriptSandbox.java:358)
	at com.superwall.sdk.paywall.presentation.rule_logic.expression_evaluator.ExpressionEvaluator$1.invokeSuspend(ExpressionEvaluator.kt:54)

To avoid errors, the SDK can precautionary get application context from the context passed into Superwall.configure() method.
Given that, the SDK requirements could get relaxed to allow initialisation with activity context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant