diff --git a/android/src/main/java/com/getcapacitor/community/admob/consent/AdConsentExecutor.java b/android/src/main/java/com/getcapacitor/community/admob/consent/AdConsentExecutor.java index a0a85d6e..7692988b 100644 --- a/android/src/main/java/com/getcapacitor/community/admob/consent/AdConsentExecutor.java +++ b/android/src/main/java/com/getcapacitor/community/admob/consent/AdConsentExecutor.java @@ -5,7 +5,6 @@ import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; - import androidx.core.util.Supplier; import com.getcapacitor.JSArray; import com.getcapacitor.JSObject; @@ -19,7 +18,6 @@ import com.google.android.ump.ConsentRequestParameters; import com.google.android.ump.FormError; import com.google.android.ump.UserMessagingPlatform; - import java.util.ArrayList; import java.util.List; @@ -36,13 +34,13 @@ public AdConsentExecutor( super(contextSupplier, activitySupplier, notifyListenersFunction, pluginLogTag, "AdConsentExecutor"); } - public boolean canShowPersonalizedAds(){ + public boolean canShowPersonalizedAds() { Context context = contextSupplier.get(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); String purposeConsent = prefs.getString("IABTCF_PurposeConsents", ""); - String vendorConsent = prefs.getString("IABTCF_VendorConsents",""); - String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests",""); - String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests",""); + String vendorConsent = prefs.getString("IABTCF_VendorConsents", ""); + String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests", ""); + String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests", ""); int googleId = 755; boolean hasGoogleVendorConsent = hasAttribute(vendorConsent, googleId); @@ -59,17 +57,19 @@ public boolean canShowPersonalizedAds(){ indexesLI.add(9); indexesLI.add(10); - return hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent) - && hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI); - + return ( + hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent) && + hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI) + ); } - public boolean canShowAds(){ + + public boolean canShowAds() { Context context = contextSupplier.get(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); String purposeConsent = prefs.getString("IABTCF_PurposeConsents", ""); - String vendorConsent = prefs.getString("IABTCF_VendorConsents",""); - String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests",""); - String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests",""); + String vendorConsent = prefs.getString("IABTCF_VendorConsents", ""); + String vendorLI = prefs.getString("IABTCF_VendorLegitimateInterests", ""); + String purposeLI = prefs.getString("IABTCF_PurposeLegitimateInterests", ""); int googleId = 755; boolean hasGoogleVendorConsent = hasAttribute(vendorConsent, googleId); @@ -84,9 +84,10 @@ public boolean canShowAds(){ indexesLI.add(9); indexesLI.add(10); - return hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent) - && hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI); - + return ( + hasConsentFor(indexes, purposeConsent, hasGoogleVendorConsent) && + hasConsentOrLegitimateInterestFor(indexesLI, purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI) + ); } @PluginMethod @@ -206,11 +207,11 @@ private void ensureConsentInfo() { private boolean hasAttribute(String input, int index) { if (input == null) return false; - return input.length() >= index && input.charAt(index-1) == '1'; + return input.length() >= index && input.charAt(index - 1) == '1'; } private boolean hasConsentFor(List indexes, String purposeConsent, boolean hasVendorConsent) { - for (Integer p: indexes) { + for (Integer p : indexes) { if (!hasAttribute(purposeConsent, p)) { return false; } @@ -218,12 +219,18 @@ private boolean hasConsentFor(List indexes, String purposeConsent, bool return hasVendorConsent; } - private boolean hasConsentOrLegitimateInterestFor(List indexes, String purposeConsent, String purposeLI, boolean hasVendorConsent, boolean hasVendorLI){ - for (Integer p: indexes) { + private boolean hasConsentOrLegitimateInterestFor( + List indexes, + String purposeConsent, + String purposeLI, + boolean hasVendorConsent, + boolean hasVendorLI + ) { + for (Integer p : indexes) { boolean purposeAndVendorLI = hasAttribute(purposeLI, p) && hasVendorLI; boolean purposeConsentAndVendorConsent = hasAttribute(purposeConsent, p) && hasVendorConsent; boolean isOk = purposeAndVendorLI || purposeConsentAndVendorConsent; - if (!isOk){ + if (!isOk) { return false; } } diff --git a/package-lock.json b/package-lock.json index 9a31d9d8..e8589308 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "@capacitor-community/admob", + "name": "@ququplay/admob", "version": "6.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@capacitor-community/admob", + "name": "@ququplay/admob", "version": "6.0.0", "license": "MIT", "dependencies": { @@ -33,7 +33,7 @@ "typescript": "~4.1.5" }, "engines": { - "node": ">=16.0.0" + "node": ">=18.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": {