android / privacy-sandbox-samples

Apache License 2.0
130 stars 52 forks source link

Calling "fetchAndJoinCustomAudience" does't do anything and ignores: OutcomeReceiver #84

Closed guybashan closed 9 months ago

guybashan commented 10 months ago

I am trying to test the fetchAndJoinCustomAudience function.

After overcoming as sort of obstacles, the function seems to be properly called without any exception, but also without doing anything and ignoring the OutcomeReceiver I assigned to it. I did all the detailed steps in the documents. This is the code I am trying to run:


    @NonNull
    public ListenableFuture<Void> fetchAndJoinCustomAudience() {
        return CallbackToFutureAdapter.getFuture(
                completer -> {

                    final Instant activationTime = Instant.now();
                    final Instant expirationTime = activationTime.plus(Duration.ofDays(30));
                    final String name = "shoes";

                    AdSelectionSignals adSelectionSignals = AdSelectionSignals.EMPTY;

                    FetchAndJoinCustomAudienceRequest request =
                            new FetchAndJoinCustomAudienceRequest.Builder(
                                    Uri.parse(mockServer + "/audience")
                            )
                                    .setName(name)
                                    .setFetchUri(Uri.parse(mockServer + "/audience"))
                                    .setActivationTime(activationTime)
                                    .setExpirationTime(expirationTime)
                                    .build();

                    customAudienceManager.fetchAndJoinCustomAudience(
                            request,
                            executor,
                            new OutcomeReceiver<Object, Exception>() {
                                @Override
                                public void onResult(Object ignoredResult) {
                                    Log.i(TAG, "Fetch and join executed successfully");
                                    completer.set(null);
                                }

                                @Override
                                public void onError(Exception error) {
                                    Log.e(TAG, "Failed while doing fetch and join", error);
                                    completer.setException(error);
                                }
                            });

                    return "fetchAndJoinCustomAudience";
                });
    }
guybashan commented 10 months ago

I did notice that when calling it several times I get the following exception:

Failed while doing fetch and join (Ask Studio Bot)
                                                                                                    android.os.LimitExceededException: API rate limit exceeded.
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:199)
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:210)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2.lambda$onFailure$1(CustomAudienceManager.java:255)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2$$ExternalSyntheticLambda1.run(Unknown Source:4)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)

So I was wondering, maybe the request is only queued for later usage? If YES, do I have a way of sending it ASAP?

guybashan commented 10 months ago

I did a single call to the function, then after almost 30 seconds I noticed the log is filled with several exception of: IllegalStateException

Failed while doing fetch and join (Ask Studio Bot)
                                                                                                    java.lang.IllegalStateException
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:203)
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:210)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2.lambda$onFailure$1(CustomAudienceManager.java:255)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2$$ExternalSyntheticLambda1.run(Unknown Source:4)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-18 17:25:47.079 10407-10554 MainActivity            com.youappi.dsp.protectedaudience    E  Error when fetching audience (Ask Studio Bot)
                                                                                                    java.lang.IllegalStateException
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:203)
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:210)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2.lambda$onFailure$1(CustomAudienceManager.java:255)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2$$ExternalSyntheticLambda1.run(Unknown Source:4)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-18 17:26:47.121 10407-10571 FetchAndJoin            com.youappi.dsp.protectedaudience    E  Failed while doing fetch and join (Ask Studio Bot)
                                                                                                    java.lang.IllegalStateException
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:203)
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:210)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2.lambda$onFailure$1(CustomAudienceManager.java:255)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2$$ExternalSyntheticLambda1.run(Unknown Source:4)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
2023-10-18 17:26:47.123 10407-10572 MainActivity            com.youappi.dsp.protectedaudience    E  Error when fetching audience (Ask Studio Bot)
                                                                                                    java.lang.IllegalStateException
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:203)
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:210)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2.lambda$onFailure$1(CustomAudienceManager.java:255)
                                                                                                        at android.adservices.customaudience.CustomAudienceManager$2$$ExternalSyntheticLambda1.run(Unknown Source:4)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
guybashan commented 9 months ago

This problem is no longer an issue as for the latest Canary release on Android Studio and working with the latest Android images.