Skip to content
Open
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 @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
Expand All @@ -13,6 +14,7 @@
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.util.Supplier;
import androidx.webkit.WebViewCompat;
import com.getcapacitor.JSObject;
import com.getcapacitor.PluginCall;
import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
Expand All @@ -34,6 +36,9 @@ public class BannerExecutor extends Executor {
private AdView mAdView;
private ViewGroup mViewGroup;

// https://issues.chromium.org/issues/40699457
private static final int WEBVIEW_VERSION_WITH_SAFE_AREA_FIX = 140;

public BannerExecutor(
Supplier<Context> contextSupplier,
Supplier<Activity> activitySupplier,
Expand Down Expand Up @@ -103,8 +108,9 @@ public void showBanner(final PluginCall call) {
break;
}

// set Safe Area only for Android 15+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
// set Safe Area only for Android WebView version 140+ due to the following issue:
// https://issues.chromium.org/issues/40699457
if (getWebViewMajorVersion() >= WEBVIEW_VERSION_WITH_SAFE_AREA_FIX) {
View rootView = activitySupplier.get().getWindow().getDecorView();
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
int bottomInset = insets.getSystemWindowInsetBottom();
Expand Down Expand Up @@ -300,4 +306,18 @@ public void onAdImpression() {
mViewGroup.addView(mAdViewLayout);
});
}

private Integer getWebViewMajorVersion() {
try {
PackageInfo info = WebViewCompat.getCurrentWebViewPackage(contextSupplier.get());
if (info != null && info.versionName != null) {
String[] versionSegments = info.versionName.split("\\.");
return Integer.valueOf(versionSegments[0]);
}
} catch (Throwable ignored) {
// WebViewCompat can fail to initialize in local JVM unit tests.
}

return 0;
}
}
Loading