From dfc10ef708e6669ebbe19e910f1c4e3121c23238 Mon Sep 17 00:00:00 2001 From: berile Date: Thu, 16 Feb 2023 14:34:34 -0800 Subject: [PATCH 1/5] Java style and AndroidManifest changes --- gma/integration_test/AndroidManifest.xml | 4 +- .../gma/internal/cpp/AdInspectorHelper.java | 8 +- .../gma/internal/cpp/AdRequestHelper.java | 2 + .../gma/internal/cpp/AdViewHelper.java | 613 +++++++++--------- .../gma/internal/cpp/ConstantsHelper.java | 2 + .../internal/cpp/GmaInitializationHelper.java | 16 +- .../internal/cpp/InterstitialAdHelper.java | 278 ++++---- .../gma/internal/cpp/RewardedAdHelper.java | 296 +++++---- 8 files changed, 618 insertions(+), 601 deletions(-) diff --git a/gma/integration_test/AndroidManifest.xml b/gma/integration_test/AndroidManifest.xml index c45d3ff5e5..fd9ee96155 100644 --- a/gma/integration_test/AndroidManifest.xml +++ b/gma/integration_test/AndroidManifest.xml @@ -23,12 +23,14 @@ - + By invoking the listener callback here, hooked into the draw loop, the AdViewHelper - * object can be sure that any movements of mAdView have been completed and the layout and screen - * position have been recalculated by the time the notification happens, preventing stale data - * from getting to the Listener. + *

By invoking the listener callback here, hooked into the draw loop, the AdViewHelper object + * can be sure that any movements of adView have been completed and the layout and screen position + * have been recalculated by the time the notification happens, preventing stale data from getting + * to the Listener. */ @Override public boolean onPreDraw() { - if (mNotifyBoundingBoxListenerOnNextDraw.compareAndSet(true, false)) { - if (mAdView != null && mAdViewInternalPtr != CPP_NULLPTR) { - notifyBoundingBoxChanged(mAdViewInternalPtr); + if (notifyBoundingBoxListenerOnNextDraw.compareAndSet(true, false)) { + if (adView != null && adViewInternalPtr != CPP_NULLPTR) { + notifyBoundingBoxChanged(adViewInternalPtr); } } // Returning true tells Android to continue the draw as normal. return true; } - /** - * Native callback to instruct the C++ wrapper to complete the corresponding future. - */ + /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ public static native void completeAdViewFutureCallback( long nativeInternalPtr, int errorCode, String errorMessage); - /** - * Native callback to instruct the C++ wrapper to release its global reference on this - * object. - */ + /** Native callback to instruct the C++ wrapper to release its global reference on this object. */ public static native void releaseAdViewGlobalReferenceCallback(long nativeInternalPtr); - /** - * Native callback invoked upon successfully loading an ad. - */ - public static native void completeAdViewLoadedAd(long nativeInternalPtr, long mAdViewInternalPtr, - int width, int height, ResponseInfo responseInfo); + /** Native callback invoked upon successfully loading an ad. */ + public static native void completeAdViewLoadedAd( + long nativeInternalPtr, + long mAdViewInternalPtr, + int width, + int height, + ResponseInfo responseInfo); /** - * Native callback upon encountering an error loading an Ad Request. Returns - * Android Google Mobile Ads SDK error codes. - **/ + * Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile + * Ads SDK error codes. + */ public static native void completeAdViewLoadAdError( long nativeInternalPtr, LoadAdError error, int errorCode, String errorMessage); /** - * Native callback upon encountering a wrapper/internal error when - * processing a Load Ad Request. Returns an integer representing - * firebase::gma::AdError codes. + * Native callback upon encountering a wrapper/internal error when processing a Load Ad Request. + * Returns an integer representing firebase::gma::AdError codes. */ public static native void completeAdViewLoadAdInternalError( long nativeInternalPtr, int gmaErrorCode, String errorMessage); - /** - * Native callback to notify the C++ wrapper that the Ad's Bounding Box has changed. - */ + /** Native callback to notify the C++ wrapper that the Ad's Bounding Box has changed. */ public static native void notifyBoundingBoxChanged(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad clicked event - */ + /** Native callback to notify the C++ wrapper of an ad clicked event */ public static native void notifyAdClicked(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad closed event - */ + /** Native callback to notify the C++ wrapper of an ad closed event */ public static native void notifyAdClosed(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad impression event - */ + /** Native callback to notify the C++ wrapper of an ad impression event */ public static native void notifyAdImpression(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad opened event - */ + /** Native callback to notify the C++ wrapper of an ad opened event */ public static native void notifyAdOpened(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper that a paid event has occurred. - */ + /** Native callback to notify the C++ wrapper that a paid event has occurred. */ public static native void notifyPaidEvent( long nativeInternalPtr, String currencyCode, int precisionType, long valueMicros); } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java index 2056275293..1abc0d4b1e 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java @@ -84,4 +84,6 @@ public final class ConstantsHelper { public static final int AD_VIEW_POSITION_BOTTOM_LEFT = 4; public static final int AD_VIEW_POSITION_BOTTOM_RIGHT = 5; + + private ConstantsHelper() {} } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java index 85aee3c383..ccde0268d9 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java @@ -24,14 +24,18 @@ /** Helper class for initializing the Google Mobile Ads SDK. */ public final class GmaInitializationHelper { public static void initializeGma(Context context) { - MobileAds.initialize(context, new OnInitializationCompleteListener() { - @Override - public void onInitializationComplete(InitializationStatus initializationStatus) { - initializationCompleteCallback(initializationStatus); - } - }); + MobileAds.initialize( + context, + new OnInitializationCompleteListener() { + @Override + public void onInitializationComplete(InitializationStatus initializationStatus) { + initializationCompleteCallback(initializationStatus); + } + }); } public static native void initializationCompleteCallback( InitializationStatus initializationStatus); + + private GmaInitializationHelper() {} } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java index e08d82345a..b63c5d5ccc 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java @@ -17,7 +17,6 @@ package com.google.firebase.gma.internal.cpp; import android.app.Activity; -import android.util.Log; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdValue; @@ -39,34 +38,32 @@ public class InterstitialAdHelper { // Pointer to the InterstitialAdInternalAndroid object that created this // object. - private long mInterstitialAdInternalPtr; + private long interstitialAdInternalPtr; // The GMA SDK {@link InterstitialAd} associated with this helper. - private InterstitialAd mInterstitial; + private InterstitialAd interstitial; // Synchronization object for thread safe access to: - // * mInterstitial - // * mInterstitialAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mInterstitialLock; + // * interstitial + // * interstitialAdInternalPtr + // * loadAdCallbackDataPtr + private final Object interstitialLock; // The {@link Activity} this helper uses to display its // {@link InterstitialAd}. - private Activity mActivity; + private Activity activity; // The ad unit ID to use for the {@link InterstitialAd}. - private String mAdUnitId; + private String adUnitId; // Pointer to a FutureCallbackData in the C++ wrapper that will be used to // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; + private long loadAdCallbackDataPtr; - /** - * Constructor. - */ + /** Constructor. */ public InterstitialAdHelper(long interstitialAdInternalPtr) { - mInterstitialAdInternalPtr = interstitialAdInternalPtr; - mInterstitialLock = new Object(); + this.interstitialAdInternalPtr = interstitialAdInternalPtr; + interstitialLock = new Object(); // Test the callbacks and fail quickly if something's wrong. completeInterstitialAdFutureCallback( @@ -78,176 +75,191 @@ public InterstitialAdHelper(long interstitialAdInternalPtr) { * InterstitialAd} object and sets it up. */ public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - if (mInterstitial == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - mInterstitial = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + this.activity = activity; + + this.activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + int errorCode; + String errorMessage; + if (interstitial == null) { + try { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + } catch (IllegalStateException e) { + interstitial = null; + // This exception can be thrown if the ad unit ID was already set. + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + } + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + } + completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - }); + }); } /** Disconnect the helper from the interstital ad. */ public void disconnect() { - synchronized (mInterstitialLock) { - mInterstitialAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; + synchronized (interstitialLock) { + interstitialAdInternalPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } - if (mActivity == null) { + if (activity == null) { return; } - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mInterstitialLock) { - if (mInterstitial != null) { - mInterstitial.setFullScreenContentCallback(null); - mInterstitial.setOnPaidEventListener(null); - mInterstitial = null; + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + synchronized (interstitialLock) { + if (interstitial != null) { + interstitial.setFullScreenContentCallback(null); + interstitial.setOnPaidEventListener(null); + interstitial = null; + } + } } - } - } - }); + }); } /** Loads an ad for the underlying {@link InterstitialAd} object. */ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { + if (activity == null) { return; } - synchronized (mInterstitialLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadAdInternalError(callbackDataPtr, + synchronized (interstitialLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { + completeInterstitialLoadAdInternalError( + callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; } - mLoadAdCallbackDataPtr = callbackDataPtr; + loadAdCallbackDataPtr = callbackDataPtr; } - mAdUnitId = adUnitId; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (mActivity == null) { - synchronized (mInterstitialLock) { - completeInterstitialLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } - } else { - try { - InterstitialAd.load(mActivity, mAdUnitId, request, new InterstitialAdListener()); - } catch (IllegalStateException e) { - synchronized (mInterstitialLock) { - completeInterstitialLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + this.adUnitId = adUnitId; + + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + if (activity == null) { + synchronized (interstitialLock) { + completeInterstitialLoadAdInternalError( + loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; + } + } else { + try { + InterstitialAd.load( + activity, + InterstitialAdHelper.this.adUnitId, + request, + new InterstitialAdListener()); + } catch (IllegalStateException e) { + synchronized (interstitialLock) { + completeInterstitialLoadAdInternalError( + loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; + } + } } } - } - } - }); + }); } /** Shows a previously loaded ad. */ public void show(final long callbackDataPtr) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mInterstitialLock) { - int errorCode; - String errorMessage; - if (mAdUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mInterstitial == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - mInterstitial.show(mActivity); + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + synchronized (interstitialLock) { + int errorCode; + String errorMessage; + if (adUnitId == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; + } else if (interstitial == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + interstitial.show(activity); + } + completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + } } - completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); + }); } - private class InterstitialAdFullScreenContentListener - extends FullScreenContentCallback implements OnPaidEventListener { + private class InterstitialAdFullScreenContentListener extends FullScreenContentCallback + implements OnPaidEventListener { @Override public void onAdClicked() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdClickedFullScreenContentEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdClickedFullScreenContentEvent(interstitialAdInternalPtr); } } } @Override public void onAdDismissedFullScreenContent() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdDismissedFullScreenContentEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdDismissedFullScreenContentEvent(interstitialAdInternalPtr); } } } @Override public void onAdFailedToShowFullScreenContent(AdError error) { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdFailedToShowFullScreenContentEvent(mInterstitialAdInternalPtr, error); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdFailedToShowFullScreenContentEvent(interstitialAdInternalPtr, error); } } } @Override public void onAdImpression() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdImpressionEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdImpressionEvent(interstitialAdInternalPtr); } } } @Override public void onAdShowedFullScreenContent() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdShowedFullScreenContentEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdShowedFullScreenContentEvent(interstitialAdInternalPtr); } } } + @Override public void onPaidEvent(AdValue value) { - synchronized (mInterstitialLock) { - notifyPaidEvent(mInterstitialAdInternalPtr, value.getCurrencyCode(), - value.getPrecisionType(), value.getValueMicros()); + synchronized (interstitialLock) { + notifyPaidEvent( + interstitialAdInternalPtr, + value.getCurrencyCode(), + value.getPrecisionType(), + value.getValueMicros()); } } } @@ -255,26 +267,26 @@ public void onPaidEvent(AdValue value) { private class InterstitialAdListener extends InterstitialAdLoadCallback { @Override public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mInterstitialLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { + synchronized (interstitialLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { completeInterstitialLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } @Override public void onAdLoaded(InterstitialAd ad) { - synchronized (mInterstitialLock) { - mInterstitial = ad; + synchronized (interstitialLock) { + interstitial = ad; InterstitialAdFullScreenContentListener listener = new InterstitialAdFullScreenContentListener(); - mInterstitial.setFullScreenContentCallback(listener); - mInterstitial.setOnPaidEventListener(listener); - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadedAd(mLoadAdCallbackDataPtr, ad.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + interstitial.setFullScreenContentCallback(listener); + interstitial.setOnPaidEventListener(listener); + if (loadAdCallbackDataPtr != CPP_NULLPTR) { + completeInterstitialLoadedAd(loadAdCallbackDataPtr, ad.getResponseInfo()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java index 3e78901d2f..414ff6c4f9 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java @@ -17,7 +17,6 @@ package com.google.firebase.gma.internal.cpp; import android.app.Activity; -import android.util.Log; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdValue; @@ -42,32 +41,32 @@ public class RewardedAdHelper { // Pointer to the RewardedAdInternalAndroid object that created this // object. - private long mRewardedAdInternalPtr; + private long rewardedAdInternalPtr; // The GMA SDK {@link RewardedAd} associated with this helper. - private RewardedAd mRewarded; + private RewardedAd rewarded; // Synchronization object for thread safe access to: - // * mRewarded - // * mRewardedAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mRewardedLock; + // * rewarded + // * rewardedAdInternalPtr + // * loadAdCallbackDataPtr + private final Object rewardedLock; // The {@link Activity} this helper uses to display its // {@link RewardedAd}. - private Activity mActivity; + private Activity activity; // The ad unit ID to use for the {@link RewardedAd}. - private String mAdUnitId; + private String adUnitId; // Pointer to a FutureCallbackData in the C++ wrapper that will be used to // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; + private long loadAdCallbackDataPtr; /** Constructor. */ public RewardedAdHelper(long rewardedAdInternalPtr) { - mRewardedAdInternalPtr = rewardedAdInternalPtr; - mRewardedLock = new Object(); + this.rewardedAdInternalPtr = rewardedAdInternalPtr; + rewardedLock = new Object(); // Test the callbacks and fail quickly if something's wrong. completeRewardedAdFutureCallback(CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); @@ -78,198 +77,211 @@ public RewardedAdHelper(long rewardedAdInternalPtr) { * object and sets it up. */ public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - synchronized (mRewardedLock) { - if (mRewarded == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - mRewarded = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + this.activity = activity; + + this.activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + int errorCode; + String errorMessage; + synchronized (rewardedLock) { + if (rewarded == null) { + try { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + } catch (IllegalStateException e) { + rewarded = null; + // This exception can be thrown if the ad unit ID was already set. + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + } + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + } + completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; } - completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); + }); } /** Disconnect the helper from the interstital ad. */ public void disconnect() { - synchronized (mRewardedLock) { - mRewardedAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; + synchronized (rewardedLock) { + rewardedAdInternalPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } - if (mActivity == null) { + if (activity == null) { return; } - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mRewardedLock) { - if (mRewarded != null) { - mRewarded.setFullScreenContentCallback(null); - mRewarded.setOnPaidEventListener(null); - mRewarded = null; + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + synchronized (rewardedLock) { + if (rewarded != null) { + rewarded.setFullScreenContentCallback(null); + rewarded.setOnPaidEventListener(null); + rewarded = null; + } + } } - } - } - }); + }); } /** Loads an ad for the underlying {@link RewardedAd} object. */ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { + if (activity == null) { return; } - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeRewardedLoadAdInternalError(callbackDataPtr, + synchronized (rewardedLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { + completeRewardedLoadAdInternalError( + callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; } - mLoadAdCallbackDataPtr = callbackDataPtr; + loadAdCallbackDataPtr = callbackDataPtr; } - mAdUnitId = adUnitId; - - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mRewardedLock) { - if (mActivity == null) { - completeRewardedLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; - } else { - try { - RewardedAd.load(mActivity, mAdUnitId, request, new RewardedAdListener()); - } catch (IllegalStateException e) { - completeRewardedLoadAdInternalError(mLoadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + this.adUnitId = adUnitId; + + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + synchronized (rewardedLock) { + if (activity == null) { + completeRewardedLoadAdInternalError( + loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; + } else { + try { + RewardedAd.load( + activity, RewardedAdHelper.this.adUnitId, request, new RewardedAdListener()); + } catch (IllegalStateException e) { + completeRewardedLoadAdInternalError( + loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; + } + } } } - } - } - }); + }); } - /** - * Shows a previously loaded ad. - */ - public void show(final long callbackDataPtr, final String verificationCustomData, + /** Shows a previously loaded ad. */ + public void show( + final long callbackDataPtr, + final String verificationCustomData, final String verificationUserId) { - mActivity.runOnUiThread(new Runnable() { - @Override - public void run() { - synchronized (mRewardedLock) { - int errorCode; - String errorMessage; - if (mAdUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mRewarded == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - if (!verificationCustomData.isEmpty() || !verificationUserId.isEmpty()) { - ServerSideVerificationOptions options = new ServerSideVerificationOptions.Builder() - .setCustomData(verificationCustomData) - .setUserId(verificationUserId) - .build(); - mRewarded.setServerSideVerificationOptions(options); + activity.runOnUiThread( + new Runnable() { + @Override + public void run() { + synchronized (rewardedLock) { + int errorCode; + String errorMessage; + if (adUnitId == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; + } else if (rewarded == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + if (!verificationCustomData.isEmpty() || !verificationUserId.isEmpty()) { + ServerSideVerificationOptions options = + new ServerSideVerificationOptions.Builder() + .setCustomData(verificationCustomData) + .setUserId(verificationUserId) + .build(); + rewarded.setServerSideVerificationOptions(options); + } + rewarded.show(activity, new UserEarnedRewardListener()); + } + completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); } - mRewarded.show(mActivity, new UserEarnedRewardListener()); } - completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } - } - }); + }); } private class UserEarnedRewardListener implements OnUserEarnedRewardListener { @Override public void onUserEarnedReward(RewardItem rewardItem) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { notifyUserEarnedRewardEvent( - mRewardedAdInternalPtr, rewardItem.getType(), rewardItem.getAmount()); + rewardedAdInternalPtr, rewardItem.getType(), rewardItem.getAmount()); } } } } - private class RewardedAdFullScreenContentListener - extends FullScreenContentCallback implements OnPaidEventListener { + private class RewardedAdFullScreenContentListener extends FullScreenContentCallback + implements OnPaidEventListener { @Override public void onAdClicked() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdClickedFullScreenContentEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdClickedFullScreenContentEvent(rewardedAdInternalPtr); } } } @Override public void onAdDismissedFullScreenContent() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdDismissedFullScreenContentEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdDismissedFullScreenContentEvent(rewardedAdInternalPtr); } } } @Override public void onAdFailedToShowFullScreenContent(AdError error) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdFailedToShowFullScreenContentEvent(mRewardedAdInternalPtr, error); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdFailedToShowFullScreenContentEvent(rewardedAdInternalPtr, error); } } } @Override public void onAdImpression() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdImpressionEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdImpressionEvent(rewardedAdInternalPtr); } } } @Override public void onAdShowedFullScreenContent() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdShowedFullScreenContentEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdShowedFullScreenContentEvent(rewardedAdInternalPtr); } } } + @Override public void onPaidEvent(AdValue value) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyPaidEvent(mRewardedAdInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyPaidEvent( + rewardedAdInternalPtr, + value.getCurrencyCode(), + value.getPrecisionType(), value.getValueMicros()); } } @@ -279,25 +291,25 @@ public void onPaidEvent(AdValue value) { private class RewardedAdListener extends RewardedAdLoadCallback { @Override public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { + synchronized (rewardedLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { completeRewardedLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } @Override public void onAdLoaded(RewardedAd ad) { - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - mRewarded = ad; + synchronized (rewardedLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { + rewarded = ad; RewardedAdFullScreenContentListener listener = new RewardedAdFullScreenContentListener(); - mRewarded.setFullScreenContentCallback(listener); - mRewarded.setOnPaidEventListener(listener); - completeRewardedLoadedAd(mLoadAdCallbackDataPtr, mRewarded.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + rewarded.setFullScreenContentCallback(listener); + rewarded.setOnPaidEventListener(listener); + completeRewardedLoadedAd(loadAdCallbackDataPtr, rewarded.getResponseInfo()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } From 7bedf16f607d6e80dcb8a1e0bb0ecc33b4e8bf00 Mon Sep 17 00:00:00 2001 From: berile Date: Thu, 16 Feb 2023 15:38:16 -0800 Subject: [PATCH 2/5] Clang-tidy fixes --- .../gma/internal/cpp/AdViewHelper.java | 269 ++++++++---------- .../internal/cpp/GmaInitializationHelper.java | 14 +- .../internal/cpp/InterstitialAdHelper.java | 173 ++++++----- .../gma/internal/cpp/RewardedAdHelper.java | 183 ++++++------ scripts/format_code.py | 6 +- 5 files changed, 296 insertions(+), 349 deletions(-) diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java index 48c71826ae..710df8f4db 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java @@ -138,53 +138,48 @@ public void destroy(final long callbackDataPtr, final boolean destructorInvocati // If the Activity isn't initialized, or already Destroyed, then there's // nothing to destroy. if (activity != null) { - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - // Stop any attempts to show the popup window. - synchronized (popUpLock) { - popUpRunnable = null; - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + // Stop any attempts to show the popup window. + synchronized (popUpLock) { + popUpRunnable = null; + } - if (adView != null) { - adView.setAdListener(null); - adView.setOnPaidEventListener(null); - adView.destroy(); - adView = null; - } + if (adView != null) { + adView.setAdListener(null); + adView.setOnPaidEventListener(null); + adView.destroy(); + adView = null; + } - synchronized (popUpLock) { - if (popUp != null) { - popUp.dismiss(); - popUp = null; - } - } - synchronized (adViewLock) { - if (destructorInvocation == false) { - notifyBoundingBoxChanged(adViewInternalPtr); - } - adViewInternalPtr = CPP_NULLPTR; - } - activity = null; - if (destructorInvocation) { - // AdViews's C++ destructor does not pass a future - // to callback and complete, but the reference to this object - // which should be released. - releaseAdViewGlobalReferenceCallback(callbackDataPtr); - } else { - completeAdViewFutureCallback( - callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_NONE, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); - } + synchronized (popUpLock) { + if (popUp != null) { + popUp.dismiss(); + popUp = null; + } + } + synchronized (adViewLock) { + if (destructorInvocation == false) { + notifyBoundingBoxChanged(adViewInternalPtr); } - }); + adViewInternalPtr = CPP_NULLPTR; + } + activity = null; + if (destructorInvocation) { + // AdViews's C++ destructor does not pass a future + // to callback and complete, but the reference to this object + // which should be released. + releaseAdViewGlobalReferenceCallback(callbackDataPtr); + } else { + completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); + } + } + }); } else { if (callbackDataPtr != CPP_NULLPTR) { - completeAdViewFutureCallback( - callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_NONE, + completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); } } @@ -198,8 +193,7 @@ public void loadAd(long callbackDataPtr, final AdRequest request) { synchronized (adViewLock) { if (loadAdCallbackDataPtr != CPP_NULLPTR) { - completeAdViewLoadAdInternalError( - callbackDataPtr, + completeAdViewLoadAdInternalError(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; @@ -209,8 +203,7 @@ public void loadAd(long callbackDataPtr, final AdRequest request) { if (adView == null) { synchronized (adViewLock) { - completeAdViewLoadAdInternalError( - loadAdCallbackDataPtr, + completeAdViewLoadAdInternalError(loadAdCallbackDataPtr, ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); loadAdCallbackDataPtr = CPP_NULLPTR; @@ -262,9 +255,7 @@ public void pause(final long callbackDataPtr) { } else if (adView != null) { adView.pause(); } - completeAdViewFutureCallback( - callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_NONE, + completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); } @@ -276,9 +267,7 @@ public void resume(final long callbackDataPtr) { adView.resume(); } - completeAdViewFutureCallback( - callbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_NONE, + completeAdViewFutureCallback(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_NONE, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); } @@ -378,94 +367,91 @@ private boolean updatePopUpLocation(final long callbackDataPtr) { synchronized (popUpLock) { if (popUp != null) { - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - synchronized (popUpLock) { - // Any change in visibility or position results in the dismissal of the popup (if - // one is being displayed) and creation of a fresh one. - popUp.dismiss(); - popUp = null; - } - } - }); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (popUpLock) { + // Any change in visibility or position results in the dismissal of the popup (if + // one is being displayed) and creation of a fresh one. + popUp.dismiss(); + popUp = null; + } + } + }); } popUpShowRetryCount = 0; - popUpRunnable = - new Runnable() { - @Override - public void run() { - int errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - String errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - // If the Activity's window doesn't currently have focus it's not - // possible to display the popup window. Poll the focus after a delay of 10ms and try - // to show the popup again. - if (!activity.hasWindowFocus()) { - synchronized (popUpLock) { - if (popUpRunnable == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else { - if (popUpShowRetryCount < POPUP_SHOW_RETRY_COUNT) { - popUpShowRetryCount++; - new Handler().postDelayed(popUpRunnable, 10); - return; - } - errorCode = ConstantsHelper.CALLBACK_ERROR_NO_WINDOW_TOKEN; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NO_WINDOW_TOKEN; - } - } - } - - if (adView == null) { + popUpRunnable = new Runnable() { + @Override + public void run() { + int errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + String errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + // If the Activity's window doesn't currently have focus it's not + // possible to display the popup window. Poll the focus after a delay of 10ms and try + // to show the popup again. + if (!activity.hasWindowFocus()) { + synchronized (popUpLock) { + if (popUpRunnable == null) { errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } - - if (errorCode != ConstantsHelper.CALLBACK_ERROR_NONE) { - completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); - return; - } else if (popUp == null) { - popUp = - new PopupWindow(adView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - popUp.setBackgroundDrawable(new ColorDrawable(0xFF000000)); // Black - adView.getViewTreeObserver().addOnPreDrawListener(AdViewHelper.this); - - if (shouldUseXYForPosition) { - popUp.showAtLocation(root, Gravity.NO_GRAVITY, desiredX, desiredY); - } else { - switch (desiredPosition) { - case ConstantsHelper.AD_VIEW_POSITION_TOP: - popUp.showAtLocation(root, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_BOTTOM: - popUp.showAtLocation(root, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_TOP_LEFT: - popUp.showAtLocation(root, Gravity.TOP | Gravity.LEFT, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_TOP_RIGHT: - popUp.showAtLocation(root, Gravity.TOP | Gravity.RIGHT, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_BOTTOM_LEFT: - popUp.showAtLocation(root, Gravity.BOTTOM | Gravity.LEFT, 0, 0); - break; - case ConstantsHelper.AD_VIEW_POSITION_BOTTOM_RIGHT: - popUp.showAtLocation(root, Gravity.BOTTOM | Gravity.RIGHT, 0, 0); - break; - default: - popUp.showAtLocation(root, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); - break; - } + } else { + if (popUpShowRetryCount < POPUP_SHOW_RETRY_COUNT) { + popUpShowRetryCount++; + new Handler().postDelayed(popUpRunnable, 10); + return; } + errorCode = ConstantsHelper.CALLBACK_ERROR_NO_WINDOW_TOKEN; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NO_WINDOW_TOKEN; } + } + } + + if (adView == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; + } - completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); - notifyBoundingBoxListenerOnNextDraw.set(true); + if (errorCode != ConstantsHelper.CALLBACK_ERROR_NONE) { + completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); + return; + } else if (popUp == null) { + popUp = new PopupWindow(adView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + popUp.setBackgroundDrawable(new ColorDrawable(0xFF000000)); // Black + adView.getViewTreeObserver().addOnPreDrawListener(AdViewHelper.this); + + if (shouldUseXYForPosition) { + popUp.showAtLocation(root, Gravity.NO_GRAVITY, desiredX, desiredY); + } else { + switch (desiredPosition) { + case ConstantsHelper.AD_VIEW_POSITION_TOP: + popUp.showAtLocation(root, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); + break; + case ConstantsHelper.AD_VIEW_POSITION_BOTTOM: + popUp.showAtLocation(root, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); + break; + case ConstantsHelper.AD_VIEW_POSITION_TOP_LEFT: + popUp.showAtLocation(root, Gravity.TOP | Gravity.LEFT, 0, 0); + break; + case ConstantsHelper.AD_VIEW_POSITION_TOP_RIGHT: + popUp.showAtLocation(root, Gravity.TOP | Gravity.RIGHT, 0, 0); + break; + case ConstantsHelper.AD_VIEW_POSITION_BOTTOM_LEFT: + popUp.showAtLocation(root, Gravity.BOTTOM | Gravity.LEFT, 0, 0); + break; + case ConstantsHelper.AD_VIEW_POSITION_BOTTOM_RIGHT: + popUp.showAtLocation(root, Gravity.BOTTOM | Gravity.RIGHT, 0, 0); + break; + default: + popUp.showAtLocation(root, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); + break; + } } - }; + } + + completeAdViewFutureCallback(callbackDataPtr, errorCode, errorMessage); + notifyBoundingBoxListenerOnNextDraw.set(true); + } + }; } // TODO(b/31391149): This delay is a workaround for b/31391149, and should be removed once @@ -529,12 +515,8 @@ public void onAdLoaded() { } if (loadAdCallbackDataPtr != CPP_NULLPTR) { AdSize adSize = adView.getAdSize(); - completeAdViewLoadedAd( - loadAdCallbackDataPtr, - adViewInternalPtr, - adSize.getWidth(), - adSize.getHeight(), - adView.getResponseInfo()); + completeAdViewLoadedAd(loadAdCallbackDataPtr, adViewInternalPtr, adSize.getWidth(), + adSize.getHeight(), adView.getResponseInfo()); loadAdCallbackDataPtr = CPP_NULLPTR; } // Only update the bounding box if the banner view is already visible. @@ -561,10 +543,7 @@ public void onAdOpened() { public void onPaidEvent(AdValue value) { synchronized (adViewLock) { if (adViewInternalPtr != CPP_NULLPTR) { - notifyPaidEvent( - adViewInternalPtr, - value.getCurrencyCode(), - value.getPrecisionType(), + notifyPaidEvent(adViewInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), value.getValueMicros()); } } @@ -601,12 +580,8 @@ public static native void completeAdViewFutureCallback( public static native void releaseAdViewGlobalReferenceCallback(long nativeInternalPtr); /** Native callback invoked upon successfully loading an ad. */ - public static native void completeAdViewLoadedAd( - long nativeInternalPtr, - long mAdViewInternalPtr, - int width, - int height, - ResponseInfo responseInfo); + public static native void completeAdViewLoadedAd(long nativeInternalPtr, long mAdViewInternalPtr, + int width, int height, ResponseInfo responseInfo); /** * Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java index ccde0268d9..f1cab85410 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java @@ -24,14 +24,12 @@ /** Helper class for initializing the Google Mobile Ads SDK. */ public final class GmaInitializationHelper { public static void initializeGma(Context context) { - MobileAds.initialize( - context, - new OnInitializationCompleteListener() { - @Override - public void onInitializationComplete(InitializationStatus initializationStatus) { - initializationCompleteCallback(initializationStatus); - } - }); + MobileAds.initialize(context, new OnInitializationCompleteListener() { + @Override + public void onInitializationComplete(InitializationStatus initializationStatus) { + initializationCompleteCallback(initializationStatus); + } + }); } public static native void initializationCompleteCallback( diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java index b63c5d5ccc..c81ebc8dad 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java @@ -77,29 +77,28 @@ public InterstitialAdHelper(long interstitialAdInternalPtr) { public void initialize(final long callbackDataPtr, Activity activity) { this.activity = activity; - this.activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - if (interstitial == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - interstitial = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + this.activity.runOnUiThread(new Runnable() { + @Override + public void run() { + int errorCode; + String errorMessage; + if (interstitial == null) { + try { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + } catch (IllegalStateException e) { + interstitial = null; + // This exception can be thrown if the ad unit ID was already set. + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; } - }); + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; + } + completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + } + }); } /** Disconnect the helper from the interstital ad. */ @@ -113,19 +112,18 @@ public void disconnect() { return; } - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - synchronized (interstitialLock) { - if (interstitial != null) { - interstitial.setFullScreenContentCallback(null); - interstitial.setOnPaidEventListener(null); - interstitial = null; - } - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (interstitialLock) { + if (interstitial != null) { + interstitial.setFullScreenContentCallback(null); + interstitial.setOnPaidEventListener(null); + interstitial = null; } - }); + } + } + }); } /** Loads an ad for the underlying {@link InterstitialAd} object. */ @@ -135,8 +133,7 @@ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest reques } synchronized (interstitialLock) { if (loadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadAdInternalError( - callbackDataPtr, + completeInterstitialLoadAdInternalError(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; @@ -146,67 +143,60 @@ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest reques this.adUnitId = adUnitId; - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - if (activity == null) { - synchronized (interstitialLock) { - completeInterstitialLoadAdInternalError( - loadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - loadAdCallbackDataPtr = CPP_NULLPTR; - } - } else { - try { - InterstitialAd.load( - activity, - InterstitialAdHelper.this.adUnitId, - request, - new InterstitialAdListener()); - } catch (IllegalStateException e) { - synchronized (interstitialLock) { - completeInterstitialLoadAdInternalError( - loadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - loadAdCallbackDataPtr = CPP_NULLPTR; - } - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (activity == null) { + synchronized (interstitialLock) { + completeInterstitialLoadAdInternalError(loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; + } + } else { + try { + InterstitialAd.load(activity, InterstitialAdHelper.this.adUnitId, request, + new InterstitialAdListener()); + } catch (IllegalStateException e) { + synchronized (interstitialLock) { + completeInterstitialLoadAdInternalError(loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; } } - }); + } + } + }); } /** Shows a previously loaded ad. */ public void show(final long callbackDataPtr) { - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - synchronized (interstitialLock) { - int errorCode; - String errorMessage; - if (adUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (interstitial == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - interstitial.show(activity); - } - completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (interstitialLock) { + int errorCode; + String errorMessage; + if (adUnitId == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; + } else if (interstitial == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + interstitial.show(activity); } - }); + completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + } + } + }); } - private class InterstitialAdFullScreenContentListener extends FullScreenContentCallback - implements OnPaidEventListener { + private class InterstitialAdFullScreenContentListener + extends FullScreenContentCallback implements OnPaidEventListener { @Override public void onAdClicked() { synchronized (interstitialLock) { @@ -255,11 +245,8 @@ public void onAdShowedFullScreenContent() { @Override public void onPaidEvent(AdValue value) { synchronized (interstitialLock) { - notifyPaidEvent( - interstitialAdInternalPtr, - value.getCurrencyCode(), - value.getPrecisionType(), - value.getValueMicros()); + notifyPaidEvent(interstitialAdInternalPtr, value.getCurrencyCode(), + value.getPrecisionType(), value.getValueMicros()); } } } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java index 414ff6c4f9..038c2d5cfb 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java @@ -79,31 +79,30 @@ public RewardedAdHelper(long rewardedAdInternalPtr) { public void initialize(final long callbackDataPtr, Activity activity) { this.activity = activity; - this.activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - int errorCode; - String errorMessage; - synchronized (rewardedLock) { - if (rewarded == null) { - try { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - } catch (IllegalStateException e) { - rewarded = null; - // This exception can be thrown if the ad unit ID was already set. - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; - } - completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + this.activity.runOnUiThread(new Runnable() { + @Override + public void run() { + int errorCode; + String errorMessage; + synchronized (rewardedLock) { + if (rewarded == null) { + try { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + } catch (IllegalStateException e) { + rewarded = null; + // This exception can be thrown if the ad unit ID was already set. + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; } + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; } - }); + completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + } + } + }); } /** Disconnect the helper from the interstital ad. */ @@ -117,19 +116,18 @@ public void disconnect() { return; } - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - synchronized (rewardedLock) { - if (rewarded != null) { - rewarded.setFullScreenContentCallback(null); - rewarded.setOnPaidEventListener(null); - rewarded = null; - } - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (rewardedLock) { + if (rewarded != null) { + rewarded.setFullScreenContentCallback(null); + rewarded.setOnPaidEventListener(null); + rewarded = null; } - }); + } + } + }); } /** Loads an ad for the underlying {@link RewardedAd} object. */ @@ -139,8 +137,7 @@ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest reques } synchronized (rewardedLock) { if (loadAdCallbackDataPtr != CPP_NULLPTR) { - completeRewardedLoadAdInternalError( - callbackDataPtr, + completeRewardedLoadAdInternalError(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; @@ -150,69 +147,62 @@ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest reques this.adUnitId = adUnitId; - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - synchronized (rewardedLock) { - if (activity == null) { - completeRewardedLoadAdInternalError( - loadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - loadAdCallbackDataPtr = CPP_NULLPTR; - } else { - try { - RewardedAd.load( - activity, RewardedAdHelper.this.adUnitId, request, new RewardedAdListener()); - } catch (IllegalStateException e) { - completeRewardedLoadAdInternalError( - loadAdCallbackDataPtr, - ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, - ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - loadAdCallbackDataPtr = CPP_NULLPTR; - } - } + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (rewardedLock) { + if (activity == null) { + completeRewardedLoadAdInternalError(loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; + } else { + try { + RewardedAd.load( + activity, RewardedAdHelper.this.adUnitId, request, new RewardedAdListener()); + } catch (IllegalStateException e) { + completeRewardedLoadAdInternalError(loadAdCallbackDataPtr, + ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, + ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); + loadAdCallbackDataPtr = CPP_NULLPTR; } } - }); + } + } + }); } /** Shows a previously loaded ad. */ - public void show( - final long callbackDataPtr, - final String verificationCustomData, + public void show(final long callbackDataPtr, final String verificationCustomData, final String verificationUserId) { - activity.runOnUiThread( - new Runnable() { - @Override - public void run() { - synchronized (rewardedLock) { - int errorCode; - String errorMessage; - if (adUnitId == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (rewarded == null) { - errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; - } else { - errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; - errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - if (!verificationCustomData.isEmpty() || !verificationUserId.isEmpty()) { - ServerSideVerificationOptions options = - new ServerSideVerificationOptions.Builder() - .setCustomData(verificationCustomData) - .setUserId(verificationUserId) - .build(); - rewarded.setServerSideVerificationOptions(options); - } - rewarded.show(activity, new UserEarnedRewardListener()); - } - completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + synchronized (rewardedLock) { + int errorCode; + String errorMessage; + if (adUnitId == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; + } else if (rewarded == null) { + errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; + } else { + errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; + errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; + if (!verificationCustomData.isEmpty() || !verificationUserId.isEmpty()) { + ServerSideVerificationOptions options = new ServerSideVerificationOptions.Builder() + .setCustomData(verificationCustomData) + .setUserId(verificationUserId) + .build(); + rewarded.setServerSideVerificationOptions(options); } + rewarded.show(activity, new UserEarnedRewardListener()); } - }); + completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); + } + } + }); } private class UserEarnedRewardListener implements OnUserEarnedRewardListener { @@ -227,8 +217,8 @@ public void onUserEarnedReward(RewardItem rewardItem) { } } - private class RewardedAdFullScreenContentListener extends FullScreenContentCallback - implements OnPaidEventListener { + private class RewardedAdFullScreenContentListener + extends FullScreenContentCallback implements OnPaidEventListener { @Override public void onAdClicked() { synchronized (rewardedLock) { @@ -278,10 +268,7 @@ public void onAdShowedFullScreenContent() { public void onPaidEvent(AdValue value) { synchronized (rewardedLock) { if (rewardedAdInternalPtr != CPP_NULLPTR) { - notifyPaidEvent( - rewardedAdInternalPtr, - value.getCurrencyCode(), - value.getPrecisionType(), + notifyPaidEvent(rewardedAdInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), value.getValueMicros()); } } diff --git a/scripts/format_code.py b/scripts/format_code.py index 49db3cabcb..3aa9c935c6 100755 --- a/scripts/format_code.py +++ b/scripts/format_code.py @@ -73,7 +73,7 @@ def get_formatting_diff_lines(filename): be printed individually or joined into a single string using something like os.linesep.join(diff_lines), where `diff_lines` is the return value. """ - args = ['clang-format', '-style=file', filename] + args = ['/usr/bin/clang-format', '-style=file', filename] result = subprocess.run(args, stdout=subprocess.PIPE, check=True) formatted_lines = [line.rstrip('\r\n') @@ -94,7 +94,7 @@ def does_file_need_formatting(filename): bool: True if the file requires format changes, False if formatting would produce an identical file. """ - args = ['clang-format', '-style=file', '-output-replacements-xml', filename] + args = ['/usr/bin/clang-format', '-style=file', '-output-replacements-xml', filename] result = subprocess.run(args, stdout=subprocess.PIPE, check=True) for line in result.stdout.decode('utf-8').splitlines(): if line.strip().startswith(" Date: Thu, 16 Feb 2023 16:01:31 -0800 Subject: [PATCH 3/5] Remove changes accidentally added to the scripts/format_code.py --- scripts/format_code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/format_code.py b/scripts/format_code.py index 3aa9c935c6..49db3cabcb 100755 --- a/scripts/format_code.py +++ b/scripts/format_code.py @@ -73,7 +73,7 @@ def get_formatting_diff_lines(filename): be printed individually or joined into a single string using something like os.linesep.join(diff_lines), where `diff_lines` is the return value. """ - args = ['/usr/bin/clang-format', '-style=file', filename] + args = ['clang-format', '-style=file', filename] result = subprocess.run(args, stdout=subprocess.PIPE, check=True) formatted_lines = [line.rstrip('\r\n') @@ -94,7 +94,7 @@ def does_file_need_formatting(filename): bool: True if the file requires format changes, False if formatting would produce an identical file. """ - args = ['/usr/bin/clang-format', '-style=file', '-output-replacements-xml', filename] + args = ['clang-format', '-style=file', '-output-replacements-xml', filename] result = subprocess.run(args, stdout=subprocess.PIPE, check=True) for line in result.stdout.decode('utf-8').splitlines(): if line.strip().startswith(" Date: Wed, 22 Feb 2023 11:48:43 -0800 Subject: [PATCH 4/5] Removes var type that caused build errors --- .../com/google/firebase/gma/internal/cpp/AdViewHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java index 710df8f4db..1d98cfa321 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/AdViewHelper.java @@ -245,7 +245,7 @@ public void show(final long callbackDataPtr) { if (activity == null) { return; } - var unused = updatePopUpLocation(callbackDataPtr); + boolean unused = updatePopUpLocation(callbackDataPtr); } /** Pauses the {@link AdView}. */ @@ -282,7 +282,7 @@ public void moveTo(final long callbackDataPtr, int x, int y) { desiredX = x; desiredY = y; if (popUp != null) { - var unused = updatePopUpLocation(callbackDataPtr); + boolean unused = updatePopUpLocation(callbackDataPtr); } } } @@ -297,7 +297,7 @@ public void moveTo(final long callbackDataPtr, final int position) { shouldUseXYForPosition = false; desiredPosition = position; if (popUp != null) { - var unused = updatePopUpLocation(callbackDataPtr); + boolean unused = updatePopUpLocation(callbackDataPtr); } } } From a9231f35e27604be0911e54dbaacabdece83df21 Mon Sep 17 00:00:00 2001 From: Beril Erkin Date: Wed, 1 Mar 2023 14:14:00 -0800 Subject: [PATCH 5/5] AndroidManifest.xml must set exported to true --- gma/integration_test/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gma/integration_test/AndroidManifest.xml b/gma/integration_test/AndroidManifest.xml index fd9ee96155..c78d377fae 100644 --- a/gma/integration_test/AndroidManifest.xml +++ b/gma/integration_test/AndroidManifest.xml @@ -30,7 +30,7 @@ android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-3940256099942544~3347511713"/>