1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.adservices.signals; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.net.Uri; 22 23 import com.android.adservices.flags.Flags; 24 25 import java.util.Objects; 26 27 /** 28 * The request object for updateSignals. 29 * 30 * <p>{@code updateUri} is the only parameter. It represents the URI that the service will reach out 31 * to retrieve the signals updates. 32 */ 33 @FlaggedApi(Flags.FLAG_PROTECTED_SIGNALS_ENABLED) 34 public final class UpdateSignalsRequest { 35 @NonNull private final Uri mUpdateUri; 36 UpdateSignalsRequest(@onNull Uri updateUri)37 private UpdateSignalsRequest(@NonNull Uri updateUri) { 38 Objects.requireNonNull(updateUri, "updateUri must not be null in UpdateSignalsRequest"); 39 40 mUpdateUri = updateUri; 41 } 42 43 /** 44 * @return the {@link Uri} from which the signal updates will be fetched. 45 */ 46 @NonNull getUpdateUri()47 public Uri getUpdateUri() { 48 return mUpdateUri; 49 } 50 51 /** 52 * @return {@code true} if and only if the other object is {@link UpdateSignalsRequest} with the 53 * same update URI. 54 */ 55 @Override equals(Object o)56 public boolean equals(Object o) { 57 if (!(o instanceof UpdateSignalsRequest)) return false; 58 UpdateSignalsRequest other = (UpdateSignalsRequest) o; 59 return mUpdateUri.equals(other.mUpdateUri); 60 } 61 62 /** 63 * @return the hash of the {@link UpdateSignalsRequest} object's data. 64 */ 65 @Override hashCode()66 public int hashCode() { 67 return Objects.hash(mUpdateUri); 68 } 69 70 /** 71 * @return a human-readable representation of {@link UpdateSignalsRequest}. 72 */ 73 @Override toString()74 public String toString() { 75 return "UpdateSignalsRequest{" + "updateUri=" + mUpdateUri + '}'; 76 } 77 78 /** Builder for {@link UpdateSignalsRequest} objects. */ 79 public static final class Builder { 80 @NonNull private Uri mUpdateUri; 81 82 /** 83 * Instantiates a {@link Builder} with the {@link Uri} from which the signal updates will be 84 * fetched. 85 */ Builder(@onNull Uri updateUri)86 public Builder(@NonNull Uri updateUri) { 87 Objects.requireNonNull(updateUri); 88 this.mUpdateUri = updateUri; 89 } 90 91 /** 92 * Sets the {@link Uri} from which the JSON is to be fetched. 93 * 94 * <p>See {@link #getUpdateUri()} ()} for details. 95 */ 96 @NonNull setUpdateUri(@onNull Uri updateUri)97 public Builder setUpdateUri(@NonNull Uri updateUri) { 98 Objects.requireNonNull(updateUri, "updateUri must not be null in UpdateSignalsRequest"); 99 this.mUpdateUri = updateUri; 100 return this; 101 } 102 103 /** 104 * Builds an instance of a {@link UpdateSignalsRequest}. 105 * 106 * @throws NullPointerException if any non-null parameter is null. 107 */ 108 @NonNull build()109 public UpdateSignalsRequest build() { 110 return new UpdateSignalsRequest(mUpdateUri); 111 } 112 } 113 } 114