1 /* 2 * Copyright (C) 2022 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.adselection; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.Objects; 25 26 /** 27 * Represents input parameters to the {@link 28 * com.android.adservices.service.adselection.AdSelectionServiceImpl#selectAdsFromOutcomes} API. 29 * 30 * @hide 31 */ 32 public final class AdSelectionFromOutcomesInput implements Parcelable { 33 @NonNull private final AdSelectionFromOutcomesConfig mAdSelectionFromOutcomesConfig; 34 @NonNull private final String mCallerPackageName; 35 36 @NonNull 37 public static final Creator<AdSelectionFromOutcomesInput> CREATOR = 38 new Creator<AdSelectionFromOutcomesInput>() { 39 @Override 40 public AdSelectionFromOutcomesInput createFromParcel(@NonNull Parcel source) { 41 return new AdSelectionFromOutcomesInput(source); 42 } 43 44 @Override 45 public AdSelectionFromOutcomesInput[] newArray(int size) { 46 return new AdSelectionFromOutcomesInput[size]; 47 } 48 }; 49 AdSelectionFromOutcomesInput( @onNull AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig, @NonNull String callerPackageName)50 private AdSelectionFromOutcomesInput( 51 @NonNull AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig, 52 @NonNull String callerPackageName) { 53 Objects.requireNonNull(adSelectionFromOutcomesConfig); 54 Objects.requireNonNull(callerPackageName); 55 56 this.mAdSelectionFromOutcomesConfig = adSelectionFromOutcomesConfig; 57 this.mCallerPackageName = callerPackageName; 58 } 59 AdSelectionFromOutcomesInput(@onNull Parcel in)60 private AdSelectionFromOutcomesInput(@NonNull Parcel in) { 61 Objects.requireNonNull(in); 62 63 this.mAdSelectionFromOutcomesConfig = 64 AdSelectionFromOutcomesConfig.CREATOR.createFromParcel(in); 65 this.mCallerPackageName = in.readString(); 66 } 67 68 @NonNull getAdSelectionFromOutcomesConfig()69 public AdSelectionFromOutcomesConfig getAdSelectionFromOutcomesConfig() { 70 return mAdSelectionFromOutcomesConfig; 71 } 72 73 @NonNull getCallerPackageName()74 public String getCallerPackageName() { 75 return mCallerPackageName; 76 } 77 78 @Override equals(Object o)79 public boolean equals(Object o) { 80 if (this == o) return true; 81 if (!(o instanceof AdSelectionFromOutcomesInput)) return false; 82 AdSelectionFromOutcomesInput that = (AdSelectionFromOutcomesInput) o; 83 return Objects.equals( 84 this.mAdSelectionFromOutcomesConfig, that.mAdSelectionFromOutcomesConfig) 85 && Objects.equals(this.mCallerPackageName, that.mCallerPackageName); 86 } 87 88 @Override hashCode()89 public int hashCode() { 90 return Objects.hash(mAdSelectionFromOutcomesConfig, mCallerPackageName); 91 } 92 93 /** 94 * Describe the kinds of special objects contained in this Parcelable instance's marshaled 95 * representation. For example, if the object will include a file descriptor in the output of 96 * {@link #writeToParcel(Parcel, int)}, the return value of this method must include the {@link 97 * #CONTENTS_FILE_DESCRIPTOR} bit. 98 * 99 * @return a bitmask indicating the set of special object types marshaled by this Parcelable 100 * object instance. 101 */ 102 @Override describeContents()103 public int describeContents() { 104 return 0; 105 } 106 107 /** 108 * Flatten this object in to a Parcel. 109 * 110 * @param dest The Parcel in which the object should be written. 111 * @param flags Additional flags about how the object should be written. May be 0 or {@link 112 * #PARCELABLE_WRITE_RETURN_VALUE}. 113 */ 114 @Override writeToParcel(@onNull Parcel dest, int flags)115 public void writeToParcel(@NonNull Parcel dest, int flags) { 116 Objects.requireNonNull(dest); 117 118 mAdSelectionFromOutcomesConfig.writeToParcel(dest, flags); 119 dest.writeString(mCallerPackageName); 120 } 121 122 /** 123 * Builder for {@link AdSelectionFromOutcomesInput} objects. 124 * 125 * @hide 126 */ 127 public static final class Builder { 128 @Nullable private AdSelectionFromOutcomesConfig mAdSelectionFromOutcomesConfig; 129 @Nullable private String mCallerPackageName; 130 Builder()131 public Builder() {} 132 133 /** Sets the {@link AdSelectionFromOutcomesConfig}. */ 134 @NonNull setAdSelectionFromOutcomesConfig( @onNull AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig)135 public AdSelectionFromOutcomesInput.Builder setAdSelectionFromOutcomesConfig( 136 @NonNull AdSelectionFromOutcomesConfig adSelectionFromOutcomesConfig) { 137 Objects.requireNonNull(adSelectionFromOutcomesConfig); 138 139 this.mAdSelectionFromOutcomesConfig = adSelectionFromOutcomesConfig; 140 return this; 141 } 142 143 /** Sets the caller's package name. */ 144 @NonNull setCallerPackageName( @onNull String callerPackageName)145 public AdSelectionFromOutcomesInput.Builder setCallerPackageName( 146 @NonNull String callerPackageName) { 147 Objects.requireNonNull(callerPackageName); 148 149 this.mCallerPackageName = callerPackageName; 150 return this; 151 } 152 153 /** Builds a {@link AdSelectionFromOutcomesInput} instance. */ 154 @NonNull build()155 public AdSelectionFromOutcomesInput build() { 156 Objects.requireNonNull(mAdSelectionFromOutcomesConfig); 157 Objects.requireNonNull(mCallerPackageName); 158 159 return new AdSelectionFromOutcomesInput( 160 mAdSelectionFromOutcomesConfig, mCallerPackageName); 161 } 162 } 163 } 164