android / privacy-sandbox-samples

Apache License 2.0
130 stars 52 forks source link

fetchAndJoinCustomAudience expiration date is not respected #97

Closed guybashan closed 6 months ago

guybashan commented 7 months ago

I am properly setting an audience using fetchAndJoinCustomAudience:

 final Instant activationTime = Instant.now();
 final Instant expirationTime = activationTime.plus(Duration.ofSeconds(30))

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

                    final Instant activationTime = Instant.now();
                    final Instant expirationTime = activationTime.plus(Duration.ofSeconds(30));//activationTime.plus(Duration.ofDays(3));
                    final String name = "running-shoes";

                    AdSelectionSignals adSelectionSignals = AdSelectionSignals.EMPTY;

                    Log.i(TAG, "Building Fetch and Join request");

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

                    Log.i(TAG, "Executing Fetch and Join request");
                    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";
                });
    }

Am I missing anything?

Thanks

cshmerling commented 7 months ago

Which version of the SDK are you using so I can look in to this further?

Was this on a fresh device, or is it possible there were other audiences on the device that would return the same ad? There should be no delay between expiry and the audience no longer being considered in the auction.

guybashan commented 7 months ago

It was not a fresh device. I did ran the fetchAndJoin multiple times on the device. But it is my assumption that by running it with the same name, it overrides the previous audience. The name of the audience that I create is always the same.

About this: "There should be no delay between expiry and the audience no longer being considered in the auction". That's good to know. Thanks for the info.

In addition, is there a way of actually debugging the ad selection process? For example: I can debug a WebView in Android on Chrome. Any similar tools giving me visibility to the methods being called, the values of the params that are being passed?

This is the full device info:

avd.ini.displayname              Pixel 7 API UpsideDownCakePrivacySandbox
avd.ini.encoding                 UTF-8
AvdId                            Pixel_7_API_UpsideDownCakePrivacySandbox
disk.dataPartition.size          6442450944
fastboot.chosenSnapshotFile      
fastboot.forceChosenSnapshotBoot no
fastboot.forceColdBoot           no
fastboot.forceFastBoot           yes
hw.accelerometer                 yes
hw.arc                           false
hw.audioInput                    yes
hw.battery                       yes
hw.camera.back                   virtualscene
hw.camera.front                  emulated
hw.cpu.ncore                     4
hw.device.hash2                  MD5:3db3250dab5d0d93b29353040181c7e9
hw.device.manufacturer           Google
hw.device.name                   pixel_7
hw.dPad                          no
hw.gps                           yes
hw.gpu.enabled                   yes
hw.gpu.mode                      auto
hw.initialOrientation            Portrait
hw.keyboard                      yes
hw.lcd.density                   420
hw.lcd.height                    2400
hw.lcd.width                     1080
hw.mainKeys                      no
hw.ramSize                       2048
hw.sdCard                        yes
hw.sensors.orientation           yes
hw.sensors.proximity             yes
hw.trackBall                     no
image.androidVersion.api         34
image.androidVersion.codename    UpsideDownCakePrivacySandbox
image.sysdir.1                   system-images/android-UpsideDownCakePrivacySandbox/google_apis_playstore/arm64-v8a/
PlayStore.enabled                true
runtime.network.latency          none
runtime.network.speed            full
showDeviceFrame                  yes
skin.dynamic                     yes
tag.display                      Google Play
tag.id                           google_apis_playstore
vm.heapSize                      256

I keep getting this error every few seconds. Not sure if it is related.

image

I opened a new device and after a day I started getting the error again every time.

guybashan commented 7 months ago

An update: It seems like this audience "running-shoes" that I created on the device, simply got stuck on it. I even cannot remove it using this code:

 customAudienceManager.leaveCustomAudience(new LeaveCustomAudienceRequest.Builder()
                            .setBuyer(buyer)
                            .setName("running-shoes")
                            .build(),
                            executor,
                            new OutcomeReceiver<Object, Exception>() {
                                @Override
                                public void onResult(Object ignoredResult) {
                                    completer.set(null);
                                }

                                @Override
                                public void onError(Exception error) {
                                    completer.setException(error);
                                }
                            });

I can easily create additional audiences and remove then using the above code. But this initial audience that I create on the device seems to be unremovable. Maybe it is related that I gave the audience its name in the Android code and not in the response payload?

cshmerling commented 6 months ago

Are you calling the above code from the same package that created the audience?

guybashan commented 6 months ago

Yes, I ran all the tests from the same method. The new audiences were deleted properly. The initial was still there..

guybashan commented 6 months ago

Closing this issue, since problem has seems to be resolved after the latest device update.