android / privacy-sandbox-samples

Apache License 2.0
130 stars 52 forks source link

Getting an exception while calling: customAudienceManager.joinCustomAudience #82

Closed guybashan closed 9 months ago

guybashan commented 11 months ago

Hi, I am trying to run the following command: customAudienceManager.joinCustomAudience

I am using the following device: Pixel 7 Pro with: UpsideDownPrivacySandbox

I ran all the instructions on this page: https://developer.android.com/design-for-safety/privacy-sandbox/setup-device-access?version=preview#deactivate-enrollment

I am still getting an error while running this command, which might be related: adb shell cmd jobscheduler run -f com.google.android.adservices.api 14

I did configure my manifest file to have:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_ADSERVICES_CUSTOM_AUDIENCE" />

this is how my gradle looks like:

android {
    namespace 'com.youappi.dsp.protectedaudience'
    compileSdk 35

    defaultConfig {
        applicationId "com.youappi.dsp.protectedaudience"
        minSdk 34
        targetSdk 35
        versionCode 1
        versionName "1.0"

        compileSdkPreview "UpsideDownCakePrivacySandbox"
        targetSdkPreview "UpsideDownCakePrivacySandbox"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
...
}

This is how my code looks like:


    @NonNull
    public ListenableFuture<Void> joinCustomAudience(CustomAudience customAudience) {
        return CallbackToFutureAdapter.getFuture(
                completer -> {
                    JoinCustomAudienceRequest request =
                            new JoinCustomAudienceRequest.Builder()
                                    .setCustomAudience(customAudience)
                                    .build();
                    customAudienceManager.joinCustomAudience(
                            request,
                            executor,
                            new OutcomeReceiver<Object, Exception>() {
                                @Override
                                public void onResult(Object ignoredResult) {
                                    completer.set(null);
                                }

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

The code returns the following exception:

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)

Not sure what exactly I am missing.
Can anyone please help my to figure out?
guybashan commented 11 months ago

Another interesting issues that I can see:

guybashan commented 10 months ago

This is how my looks like config file looks like:

<ad-services-config>
   <!-- Attribution API -->
   <attribution allowAllToAccess="true" />

   <!-- Topics API -->
   <topics allowAllToAccess="true" />

   <!-- Protected Audience on Android API -->
   <custom-audiences allowAllToAccess="true" />
</ad-services-config>
guybashan commented 10 months ago

I am working with the latest Canary Android Studio: Build #AI-232.9921.47.2321.10905494, built on October 5, 2023

Here is the device I am working with:

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
guybashan commented 10 months ago

@erintwalsh it will be great of someone could help with this one..🙏

siran-work commented 10 months ago

Hi, did you ran all the commands mentioned in this page: https://github.com/android/privacy-sandbox-samples/tree/dev-preview-main/Fledge/FledgeJava#launching-the-app

guybashan commented 10 months ago

Hi, Thanks for your answer. Indeed, a lot of times. The device seems to "forget" them after a while.

These are all the commands that I ran:

adb shell device_config put adservices ppapi_app_allow_list \"\*\"
adb shell device_config put adservices ppapi_app_signature_allow_list \"\*\"
adb shell device_config put adservices adservice_system_service_enabled true
adb shell device_config put adservices adservice_enabled true
adb shell device_config put adservices adservice_enable_status true
adb shell device_config put adservices fledge_js_isolate_enforce_max_heap_size false
adb shell device_config put adservices global_kill_switch false
adb shell setprop debug.adservices.disable_fledge_enrollment_check true
adb shell device_config put adservices fledge_custom_audience_service_kill_switch false
adb shell device_config put adservices fledge_select_ads_kill_switch false
adb shell device_config put adservices disable_fledge_enrollment_check true
adb shell device_config put adservices disable_topics_enrollment_check true
adb shell setprop debug.adservices.consent_manager_debug_mode true
adb shell device_config put adservices disable_sdk_sandbox false
adb shell device_config put adservices mdd_measurement_manifest_file_url "https://www.gstatic.com/mdi-serving/rubidium-adservices-adtech-enrollment/1429/f36ebfc0696c1bc69736b8878af97ee19d0cafba"
adb shell device_config put adservices fledge_fetch_custom_audience_enabled true

Yesterday night something interesting happened. I upgraded to the latest Canary IDE and the latest device images. Then I tried to check it again (as I always do after an upgrade). It ran the commands and did nothing as it always does. But then something different happened. Usually after 30 minutes I was getting an Illegal state exception. Now after 30 minutes I got a new exception and I see that the server mock was actually called. This is the new exception:

2023-10-24 15:46:11.946 29545-29545 FetchAndJoin            com.youappi.dsp.protectedaudience    I  Building Fetch and Join request
2023-10-24 15:46:11.946 29545-29545 FetchAndJoin            com.youappi.dsp.protectedaudience    I  Executing Fetch and Join request
2023-10-24 15:46:12.048 29545-29545 Compatibil...geReporter com.youappi.dsp.protectedaudience    D  Compat change id reported: 147798919; UID 10185; state: ENABLED
2023-10-24 16:15:48.155 29545-30994 FetchAndJoin            com.youappi.dsp.protectedaudience    E  Failed while doing fetch and join
                                                                                                    java.io.InvalidObjectException: The service received an invalid object from the server.
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:201)
                                                                                                        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-24 16:15:48.159 29545-30995 MainActivity            com.youappi.dsp.protectedaudience    E  Error when fetching audience
                                                                                                    java.io.InvalidObjectException: The service received an invalid object from the server.
                                                                                                        at android.adservices.common.AdServicesStatusUtils.asException(AdServicesStatusUtils.java:201)
                                                                                                        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)

It seems like it actually tried to fetch the JSON object and failed parsing it. So I think it is kinda breakthrough. It is still strange that I got the exception, since I copied and pasted to the mock server the exact JSON on Google Docs (I made sure they are a valid JSON).

Anyway it is a good direction and at least I have something to work with. I was wondering if I can trigger the request to the server faster though.. no sure what is the reasoning behind waiting 30 minutes before sanding it (I am sure there is..).

guybashan commented 9 months ago

This issue has gone with the latest Canaray release of Android Studio IDE and the latest Android images.