Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -7,7 +7,6 @@

import android.content.Context;
import android.content.ContextWrapper;
import android.util.Log;
import android.webkit.WebSettings;
import androidx.annotation.Keep;

Expand All @@ -16,9 +15,17 @@ public class ModuleDescriptor {
public static final String MODULE_ID = "com.google.android.gms.ads.dynamite";
public static final int MODULE_VERSION = 230500001;

public static void init(ContextWrapper context) {
Context baseContext = context.getBaseContext();
WebSettings.getDefaultUserAgent(baseContext);
Log.d("ModuleDescriptor", "init: context: " + baseContext);
/**
* The ads module might try to access the user agent, requiring initialization on the main thread,
* which may result in deadlocks when invoked from any other thread. This only happens with microG,
* because we don't use the highly privileged SELinux Sandbox that regular Play Services uses
* (which allows apps to read the user-agent from Play Services instead of the WebView). To prevent
* the issue we pre-emptively initialize the WebView.
*/
public static void init(Context context) {
if (context instanceof ContextWrapper) {
context = ((ContextWrapper) context).getBaseContext();
}
WebSettings.getDefaultUserAgent(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import java.util.Collection;
import java.util.Collections;

import static android.content.Context.CONTEXT_IGNORE_SECURITY;
import static android.content.Context.CONTEXT_INCLUDE_CODE;
import android.content.ContextWrapper;
import android.content.Context;

public class DynamiteModuleInfo {
private Class<?> descriptor;
Expand Down Expand Up @@ -53,9 +51,9 @@ public Collection<String> getMergedClasses() {
}
}

public void init(ContextWrapper dynamiteContext) {
public void init(Context dynamiteContext) {
try {
descriptor.getMethod("init", ContextWrapper.class).invoke(null, dynamiteContext);
descriptor.getMethod("init", Context.class).invoke(null, dynamiteContext);
} catch (Exception e) {
// Ignore
}
Expand Down
Loading