diff options
Diffstat (limited to 'adservices/framework/java/android')
8 files changed, 108 insertions, 62 deletions
diff --git a/adservices/framework/java/android/adservices/AdServicesVersion.java b/adservices/framework/java/android/adservices/AdServicesVersion.java index 51edf2f0d1..947ca0b6a1 100644 --- a/adservices/framework/java/android/adservices/AdServicesVersion.java +++ b/adservices/framework/java/android/adservices/AdServicesVersion.java @@ -19,7 +19,7 @@ package android.adservices; import android.annotation.SuppressLint; /** - * Information about the current AdServices API version. + * This class specifies the current version of the AdServices API. */ public class AdServicesVersion { diff --git a/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java b/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java index d24f8ef9e8..6fd5b2b730 100644 --- a/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java +++ b/adservices/framework/java/android/adservices/adselection/AdSelectionManager.java @@ -19,6 +19,7 @@ package android.adservices.adselection; import static android.adservices.common.AdServicesPermissions.ACCESS_ADSERVICES_CUSTOM_AUDIENCE; import android.adservices.common.AdServicesStatusUtils; +import android.adservices.common.CallerMetadata; import android.adservices.common.FledgeErrorResponse; import android.annotation.CallbackExecutor; import android.annotation.NonNull; @@ -28,6 +29,7 @@ import android.content.Context; import android.os.LimitExceededException; import android.os.OutcomeReceiver; import android.os.RemoteException; +import android.os.SystemClock; import android.os.TransactionTooLargeException; import com.android.adservices.AdServicesCommon; @@ -140,6 +142,9 @@ public class AdSelectionManager { .setAdSelectionConfig(adSelectionConfig) .setCallerPackageName(getCallerPackageName()) .build(), + new CallerMetadata.Builder() + .setBinderElapsedTimestamp(SystemClock.elapsedRealtime()) + .build(), new AdSelectionCallback.Stub() { @Override public void onSuccess(AdSelectionResponse resultParcel) { diff --git a/adservices/framework/java/android/adservices/adselection/AdSelectionService.aidl b/adservices/framework/java/android/adservices/adselection/AdSelectionService.aidl index 5d1387d36b..a634010712 100644 --- a/adservices/framework/java/android/adservices/adselection/AdSelectionService.aidl +++ b/adservices/framework/java/android/adservices/adselection/AdSelectionService.aidl @@ -18,11 +18,12 @@ package android.adservices.adselection; import android.adservices.adselection.AdSelectionCallback; import android.adservices.adselection.AdSelectionConfig; -import android.adservices.common.AdSelectionSignals; import android.adservices.adselection.ReportImpressionInput; import android.adservices.adselection.AdSelectionInput; import android.adservices.adselection.ReportImpressionCallback; import android.adservices.adselection.AdSelectionOverrideCallback; +import android.adservices.common.AdSelectionSignals; +import android.adservices.common.CallerMetadata; /** * This is the Ad Selection Service, which defines the interface used for the Ad selection workflow @@ -65,7 +66,7 @@ interface AdSelectionService { * * {@hide} */ - void runAdSelection(in AdSelectionInput request, in AdSelectionCallback callback); + void runAdSelection(in AdSelectionInput request, in CallerMetadata callerMetadata, in AdSelectionCallback callback); /** * Notifies PPAPI that there is a new impression to report for the diff --git a/adservices/framework/java/android/adservices/common/AdServicesStatusUtils.java b/adservices/framework/java/android/adservices/common/AdServicesStatusUtils.java index fb53de22c9..97e32d1511 100644 --- a/adservices/framework/java/android/adservices/common/AdServicesStatusUtils.java +++ b/adservices/framework/java/android/adservices/common/AdServicesStatusUtils.java @@ -115,6 +115,13 @@ public class AdServicesStatusUtils { * <p>This error may be considered similar to {@link java.util.concurrent.TimeoutException} */ public static final int STATUS_TIMEOUT = 13; + /** + * The device is not running a version of WebView that supports JSSandbox, required for FLEDGE + * Ad Selection. + * + * <p>This error may be considered similar to {@link IllegalStateException}. + */ + public static final int STATUS_JS_SANDBOX_UNAVAILABLE = 14; /** The error message to be returned along with {@link IllegalStateException}. */ public static final String ILLEGAL_STATE_EXCEPTION_ERROR_MESSAGE = "Service is not available."; @@ -164,6 +171,7 @@ public class AdServicesStatusUtils { return new IOException(); case STATUS_KILLSWITCH_ENABLED: // Intentional fallthrough case STATUS_USER_CONSENT_REVOKED: // Intentional fallthrough + case STATUS_JS_SANDBOX_UNAVAILABLE: return new IllegalStateException(ILLEGAL_STATE_EXCEPTION_ERROR_MESSAGE); case STATUS_PERMISSION_NOT_REQUESTED: return new SecurityException( @@ -212,7 +220,8 @@ public class AdServicesStatusUtils { STATUS_CALLER_NOT_ALLOWED, STATUS_BACKGROUND_CALLER, STATUS_UNAUTHORIZED, - STATUS_TIMEOUT + STATUS_TIMEOUT, + STATUS_JS_SANDBOX_UNAVAILABLE }) @Retention(RetentionPolicy.SOURCE) public @interface StatusCode {} diff --git a/adservices/framework/java/android/adservices/measurement/RegistrationRequest.java b/adservices/framework/java/android/adservices/measurement/RegistrationRequest.java index 8f71375ceb..303be59578 100644 --- a/adservices/framework/java/android/adservices/measurement/RegistrationRequest.java +++ b/adservices/framework/java/android/adservices/measurement/RegistrationRequest.java @@ -51,7 +51,6 @@ public final class RegistrationRequest implements Parcelable { private final @RegistrationType int mRegistrationType; private final Uri mRegistrationUri; - private final Uri mTopOriginUri; private final InputEvent mInputEvent; private final String mPackageName; private final long mRequestTime; @@ -60,7 +59,6 @@ public final class RegistrationRequest implements Parcelable { private RegistrationRequest(@NonNull Builder builder) { mRegistrationType = builder.mRegistrationType; mRegistrationUri = builder.mRegistrationUri; - mTopOriginUri = builder.mTopOriginUri; mInputEvent = builder.mInputEvent; mPackageName = builder.mPackageName; mRequestTime = builder.mRequestTime; @@ -73,7 +71,6 @@ public final class RegistrationRequest implements Parcelable { private RegistrationRequest(Parcel in) { mRegistrationType = in.readInt(); mRegistrationUri = Uri.CREATOR.createFromParcel(in); - mTopOriginUri = Uri.CREATOR.createFromParcel(in); mPackageName = in.readString(); boolean hasInputEvent = in.readBoolean(); if (hasInputEvent) { @@ -113,7 +110,6 @@ public final class RegistrationRequest implements Parcelable { Objects.requireNonNull(out); out.writeInt(mRegistrationType); mRegistrationUri.writeToParcel(out, flags); - mTopOriginUri.writeToParcel(out, flags); out.writeString(mPackageName); if (mInputEvent != null) { out.writeBoolean(true); @@ -133,13 +129,6 @@ public final class RegistrationRequest implements Parcelable { } /** - * Top level origin of the App / Publisher. - */ - public @NonNull Uri getTopOriginUri() { - return mTopOriginUri; - } - - /** * Source URI of the App / Publisher. */ public @NonNull Uri getRegistrationUri() { @@ -173,7 +162,6 @@ public final class RegistrationRequest implements Parcelable { public static final class Builder { private @RegistrationType int mRegistrationType; private Uri mRegistrationUri; - private Uri mTopOriginUri; private InputEvent mInputEvent; private String mPackageName; private long mRequestTime; @@ -198,15 +186,6 @@ public final class RegistrationRequest implements Parcelable { } /** - * See {@link RegistrationRequest#getTopOriginUri}. - */ - public @NonNull Builder setTopOriginUri(@NonNull Uri origin) { - Objects.requireNonNull(origin); - mTopOriginUri = origin; - return this; - } - - /** * See {@link RegistrationRequest#getRegistrationUri}. */ public @NonNull Builder setRegistrationUri(@NonNull Uri uri) { @@ -265,12 +244,6 @@ public final class RegistrationRequest implements Parcelable { throw new IllegalArgumentException("packageName unset"); } - // Check if topOrigin has been set. - // However, if it's not set, caller package is defaulted - if (mTopOriginUri == null) { - mTopOriginUri = Uri.parse("android-app://" + mPackageName); - } - return new RegistrationRequest(this); } } diff --git a/adservices/framework/java/android/adservices/topics/GetTopicsParam.java b/adservices/framework/java/android/adservices/topics/GetTopicsParam.java index 201ee133d4..ce80436ae0 100644 --- a/adservices/framework/java/android/adservices/topics/GetTopicsParam.java +++ b/adservices/framework/java/android/adservices/topics/GetTopicsParam.java @@ -17,6 +17,7 @@ package android.adservices.topics; import static android.adservices.topics.TopicsManager.EMPTY_SDK; +import static android.adservices.topics.TopicsManager.RECORD_OBSERVATION_DEFAULT; import android.annotation.NonNull; import android.annotation.Nullable; @@ -32,20 +33,24 @@ public final class GetTopicsParam implements Parcelable { private final String mSdkName; private final String mSdkPackageName; private final String mAppPackageName; + private final boolean mRecordObservation; private GetTopicsParam( @NonNull String sdkName, @Nullable String sdkPackageName, - @NonNull String appPackageName) { + @NonNull String appPackageName, + boolean recordObservation) { mSdkName = sdkName; mSdkPackageName = sdkPackageName; mAppPackageName = appPackageName; + mRecordObservation = recordObservation; } private GetTopicsParam(@NonNull Parcel in) { mSdkName = in.readString(); mSdkPackageName = in.readString(); mAppPackageName = in.readString(); + mRecordObservation = in.readBoolean(); } public static final @NonNull Creator<GetTopicsParam> CREATOR = @@ -71,6 +76,7 @@ public final class GetTopicsParam implements Parcelable { out.writeString(mSdkName); out.writeString(mSdkPackageName); out.writeString(mAppPackageName); + out.writeBoolean(mRecordObservation); } /** Get the Sdk Name. This is the name in the <sdk-library> tag of the Manifest. */ @@ -91,11 +97,17 @@ public final class GetTopicsParam implements Parcelable { return mAppPackageName; } + /** Get the Record Observation. */ + public boolean shouldRecordObservation() { + return mRecordObservation; + } + /** Builder for {@link GetTopicsParam} objects. */ public static final class Builder { private String mSdkName; private String mSdkPackageName; private String mAppPackageName; + private boolean mRecordObservation = RECORD_OBSERVATION_DEFAULT; public Builder() {} @@ -123,6 +135,16 @@ public final class GetTopicsParam implements Parcelable { return this; } + /** + * Set the Record Observation. Whether to record that the caller has observed the topics of + * the host app or not. This will be used to determine if the caller can receive the topic + * in the next epoch. + */ + public @NonNull Builder setShouldRecordObservation(boolean recordObservation) { + mRecordObservation = recordObservation; + return this; + } + /** Builds a {@link GetTopicsParam} instance. */ public @NonNull GetTopicsParam build() { if (mSdkName == null) { @@ -142,7 +164,8 @@ public final class GetTopicsParam implements Parcelable { throw new IllegalArgumentException("App PackageName must not be empty or null"); } - return new GetTopicsParam(mSdkName, mSdkPackageName, mAppPackageName); + return new GetTopicsParam( + mSdkName, mSdkPackageName, mAppPackageName, mRecordObservation); } } } diff --git a/adservices/framework/java/android/adservices/topics/GetTopicsRequest.java b/adservices/framework/java/android/adservices/topics/GetTopicsRequest.java index 5a396e3deb..cc8e51bdf6 100644 --- a/adservices/framework/java/android/adservices/topics/GetTopicsRequest.java +++ b/adservices/framework/java/android/adservices/topics/GetTopicsRequest.java @@ -15,9 +15,10 @@ */ package android.adservices.topics; +import static android.adservices.topics.TopicsManager.EMPTY_SDK; +import static android.adservices.topics.TopicsManager.RECORD_OBSERVATION_DEFAULT; import android.annotation.NonNull; -import android.annotation.Nullable; /** Get Topics Request. */ public final class GetTopicsRequest { @@ -25,8 +26,12 @@ public final class GetTopicsRequest { /** Name of Ads SDK that is involved in this request. */ private final String mAdsSdkName; - private GetTopicsRequest(@Nullable String adsSdkName) { - mAdsSdkName = adsSdkName; + /** Whether to record that the caller has observed the topics of the host app or not. */ + private final boolean mRecordObservation; + + private GetTopicsRequest(@NonNull Builder builder) { + mAdsSdkName = builder.mAdsSdkName; + mRecordObservation = builder.mRecordObservation; } /** Get the Sdk Name. */ @@ -35,33 +40,58 @@ public final class GetTopicsRequest { return mAdsSdkName; } - /** - * Builds a {@link GetTopicsRequest} instance. - * - * <p>This should be called by either the app itself or by SDK running inside the Sandbox. - */ - @NonNull - public static GetTopicsRequest create() { - return new GetTopicsRequest(/* adsSdkName */ null); + /** Get Record Observation. */ + public boolean shouldRecordObservation() { + return mRecordObservation; } - /** - * Create a {@link GetTopicsRequest} instance with the provided Ads Sdk Name. - * - * <p>This should be called by SDKs running outside of the Sandbox. - * - * @param adsSdkName the Ads Sdk Name. - */ - @NonNull - public static GetTopicsRequest createWithAdsSdkName(@NonNull String adsSdkName) { - // This is the case the SDK calling without the Sandbox. - // Check if the caller set the adsSdkName - if (adsSdkName == null) { - throw new IllegalArgumentException( - "When calling Topics API outside of the Sandbox, caller should set Ads Sdk" - + " Name"); + /** Builder for {@link GetTopicsRequest} objects. */ + public static final class Builder { + private String mAdsSdkName = EMPTY_SDK; + private boolean mRecordObservation = RECORD_OBSERVATION_DEFAULT; + + /** Creates a {@link Builder} for {@link GetTopicsRequest} objects. */ + public Builder() {} + + /** + * Set Ads Sdk Name. + * + * <p>This must be called by SDKs running outside of the Sandbox. Other clients must not + * call it. + * + * @param adsSdkName the Ads Sdk Name. + */ + @NonNull + public Builder setAdsSdkName(@NonNull String adsSdkName) { + // This is the case the SDK calling from outside of the Sandbox. + // Check if the caller set the adsSdkName + if (adsSdkName == null) { + throw new IllegalArgumentException( + "When calling Topics API outside of the Sandbox, caller should set Ads Sdk" + + " Name"); + } + + mAdsSdkName = adsSdkName; + return this; + } + + /** + * Set the Record Observation. + * + * @param recordObservation whether to record that the caller has observed the topics of the + * host app or not. This will be used to determine if the caller can receive the topic + * in the next epoch. + */ + @NonNull + public Builder setShouldRecordObservation(boolean recordObservation) { + mRecordObservation = recordObservation; + return this; } - return new GetTopicsRequest(adsSdkName); + /** Builds a {@link GetTopicsRequest} instance. */ + @NonNull + public GetTopicsRequest build() { + return new GetTopicsRequest(this); + } } -}
\ No newline at end of file +} diff --git a/adservices/framework/java/android/adservices/topics/TopicsManager.java b/adservices/framework/java/android/adservices/topics/TopicsManager.java index 0a5c3964a1..6a583cb953 100644 --- a/adservices/framework/java/android/adservices/topics/TopicsManager.java +++ b/adservices/framework/java/android/adservices/topics/TopicsManager.java @@ -30,6 +30,7 @@ import android.os.LimitExceededException; import android.os.OutcomeReceiver; import android.os.RemoteException; import android.os.SystemClock; +import android.text.TextUtils; import com.android.adservices.AdServicesCommon; import com.android.adservices.LogUtil; @@ -59,6 +60,9 @@ public final class TopicsManager { // When an app calls the Topics API directly, it sets the SDK name to empty string. static final String EMPTY_SDK = ""; + // Default value is true to record SDK's Observation when it calls Topics API. + static final boolean RECORD_OBSERVATION_DEFAULT = true; + private Context mContext; private ServiceBinder<ITopicsService> mServiceBinder; @@ -136,7 +140,7 @@ public final class TopicsManager { sdkPackageName = sandboxedSdkContext.getSdkPackageName(); appPackageName = sandboxedSdkContext.getClientPackageName(); - if (sdkName != null) { + if (!TextUtils.isEmpty(sdkName)) { throw new IllegalArgumentException( "When calling Topics API from Sandbox, caller should not set Ads Sdk Name"); } @@ -163,6 +167,7 @@ public final class TopicsManager { .setAppPackageName(appPackageName) .setSdkName(sdkName) .setSdkPackageName(sdkPackageName) + .setShouldRecordObservation(getTopicsRequest.shouldRecordObservation()) .build(), callerMetadata, new IGetTopicsCallback.Stub() { |