Skip to content

Commit 07f5b3c

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
Removed calling getResponseInfo() on UI Thread since that is not required by the Android SDK.
PiperOrigin-RevId: 769942067
1 parent f84c89d commit 07f5b3c

File tree

5 files changed

+16
-106
lines changed

5 files changed

+16
-106
lines changed

source/android-library/app/src/main/java/com/google/unity/ads/Banner.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,10 @@ private Insets getSafeInsets() {
585585
/** Returns the request response info. */
586586
@Nullable
587587
public ResponseInfo getResponseInfo() {
588-
FutureTask<ResponseInfo> task = new FutureTask<>(() -> adView.getResponseInfo());
589-
unityPlayerActivity.runOnUiThread(task);
590-
591-
ResponseInfo result = null;
592-
try {
593-
result = task.get();
594-
} catch (InterruptedException | ExecutionException exception) {
595-
Log.e(PluginUtils.LOGTAG,
596-
String.format("Unable to check banner response info: %s",
597-
exception.getLocalizedMessage()));
588+
if (adView == null) {
589+
Log.e(PluginUtils.LOGTAG, "Tried to get response info before it was ready. Returning null.");
590+
return null;
598591
}
599-
return result;
592+
return adView.getResponseInfo();
600593
}
601594
}

source/android-library/app/src/main/java/com/google/unity/ads/Interstitial.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import com.google.android.gms.ads.ResponseInfo;
3030
import com.google.android.gms.ads.interstitial.InterstitialAd;
3131
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
32-
import java.util.concurrent.Callable;
33-
import java.util.concurrent.ExecutionException;
34-
import java.util.concurrent.FutureTask;
3532

3633
/**
3734
* Native interstitial implementation for the Google Mobile Ads Unity plugin.
@@ -220,27 +217,11 @@ public String getAdUnitId() {
220217
/** Returns the request response info. */
221218
@Nullable
222219
public ResponseInfo getResponseInfo() {
223-
FutureTask<ResponseInfo> task = new FutureTask<>(new Callable<ResponseInfo>() {
224-
@Override
225-
public ResponseInfo call() {
226-
return interstitialAd.getResponseInfo();
227-
}
228-
});
229-
activity.runOnUiThread(task);
230-
231-
ResponseInfo result = null;
232-
try {
233-
result = task.get();
234-
} catch (InterruptedException exception) {
235-
Log.e(PluginUtils.LOGTAG,
236-
String.format("Unable to check interstitial response info: %s",
237-
exception.getLocalizedMessage()));
238-
} catch (ExecutionException exception) {
239-
Log.e(PluginUtils.LOGTAG,
240-
String.format("Unable to check interstitial response info: %s",
241-
exception.getLocalizedMessage()));
220+
if (interstitialAd == null) {
221+
Log.e(PluginUtils.LOGTAG, "Tried to get response info before it was ready. Returning null.");
222+
return null;
242223
}
243-
return result;
224+
return interstitialAd.getResponseInfo();
244225
}
245226

246227
/**

source/android-library/app/src/main/java/com/google/unity/ads/UnityAppOpenAd.java

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
import com.google.android.gms.ads.ResponseInfo;
3131
import com.google.android.gms.ads.appopen.AppOpenAd;
3232
import com.google.android.gms.ads.appopen.AppOpenAd.AppOpenAdLoadCallback;
33-
import java.util.concurrent.Callable;
34-
import java.util.concurrent.ExecutionException;
35-
import java.util.concurrent.FutureTask;
3633

3734
/**
3835
* Native app open ad implementation for the Google Mobile Ads Unity plugin.
@@ -222,30 +219,10 @@ public String getAdUnitId() {
222219
@Nullable
223220
public ResponseInfo getResponseInfo() {
224221
if (appOpenAd == null) {
222+
Log.e(PluginUtils.LOGTAG, "Tried to get response info before it was ready. Returning null.");
225223
return null;
226224
}
227-
228-
FutureTask<ResponseInfo> task =
229-
new FutureTask<>(
230-
new Callable<ResponseInfo>() {
231-
@Override
232-
public ResponseInfo call() {
233-
return appOpenAd.getResponseInfo();
234-
}
235-
});
236-
activity.runOnUiThread(task);
237-
238-
ResponseInfo result = null;
239-
try {
240-
result = task.get();
241-
} catch (ExecutionException | InterruptedException exception) {
242-
Log.e(
243-
PluginUtils.LOGTAG,
244-
String.format(
245-
"Unable to check Unity app open ad response info: %s",
246-
exception.getLocalizedMessage()));
247-
}
248-
return result;
225+
return appOpenAd.getResponseInfo();
249226
}
250227

251228
/**

source/android-library/app/src/main/java/com/google/unity/ads/UnityRewardedAd.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -249,27 +249,11 @@ public String getAdUnitId() {
249249
/** Returns the request response info. */
250250
@Nullable
251251
public ResponseInfo getResponseInfo() {
252-
FutureTask<ResponseInfo> task = new FutureTask<>(new Callable<ResponseInfo>() {
253-
@Override
254-
public ResponseInfo call() {
255-
return rewardedAd.getResponseInfo();
256-
}
257-
});
258-
activity.runOnUiThread(task);
259-
260-
ResponseInfo result = null;
261-
try {
262-
result = task.get();
263-
} catch (InterruptedException exception) {
264-
Log.e(PluginUtils.LOGTAG,
265-
String.format("Unable to check unity rewarded ad response info: %s",
266-
exception.getLocalizedMessage()));
267-
} catch (ExecutionException exception) {
268-
Log.e(PluginUtils.LOGTAG,
269-
String.format("Unable to check unity rewarded ad response info: %s",
270-
exception.getLocalizedMessage()));
252+
if (rewardedAd == null) {
253+
Log.e(PluginUtils.LOGTAG, "Tried to get response info before it was ready. Returning null.");
254+
return null;
271255
}
272-
return result;
256+
return rewardedAd.getResponseInfo();
273257
}
274258

275259
@Nullable

source/android-library/app/src/main/java/com/google/unity/ads/UnityRewardedInterstitialAd.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -262,35 +262,10 @@ public String getAdUnitId() {
262262
@Nullable
263263
public ResponseInfo getResponseInfo() {
264264
if (rewardedInterstitialAd == null) {
265+
Log.e(PluginUtils.LOGTAG, "Tried to get response info before it was ready. Returning null.");
265266
return null;
266267
}
267-
FutureTask<ResponseInfo> task =
268-
new FutureTask<>(
269-
new Callable<ResponseInfo>() {
270-
@Override
271-
public ResponseInfo call() {
272-
return rewardedInterstitialAd.getResponseInfo();
273-
}
274-
});
275-
activity.runOnUiThread(task);
276-
277-
ResponseInfo result = null;
278-
try {
279-
result = task.get();
280-
} catch (InterruptedException exception) {
281-
Log.e(
282-
PluginUtils.LOGTAG,
283-
String.format(
284-
"Unable to check unity rewarded interstitial ad response info: %s",
285-
exception.getLocalizedMessage()));
286-
} catch (ExecutionException exception) {
287-
Log.e(
288-
PluginUtils.LOGTAG,
289-
String.format(
290-
"Unable to check unity rewarded interstitial ad response info: %s",
291-
exception.getLocalizedMessage()));
292-
}
293-
return result;
268+
return rewardedInterstitialAd.getResponseInfo();
294269
}
295270

296271
@Nullable

0 commit comments

Comments
 (0)