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 com.android.adservices.service.enrollment; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 22 import com.android.internal.annotations.VisibleForTesting; 23 24 import java.util.ArrayList; 25 import java.util.Arrays; 26 import java.util.Collections; 27 import java.util.List; 28 import java.util.Objects; 29 30 /** POJO for Adtech EnrollmentData, store the data download using MDD. */ 31 public class EnrollmentData { 32 @VisibleForTesting public static String SEPARATOR = " "; 33 34 private String mEnrollmentId; 35 private String mCompanyId; 36 private List<String> mSdkNames; 37 private List<String> mAttributionSourceRegistrationUrl; 38 private List<String> mAttributionTriggerRegistrationUrl; 39 private List<String> mAttributionReportingUrl; 40 private List<String> mRemarketingResponseBasedRegistrationUrl; 41 private List<String> mEncryptionKeyUrl; 42 EnrollmentData()43 private EnrollmentData() { 44 mEnrollmentId = null; 45 mCompanyId = null; 46 mSdkNames = new ArrayList<>(); 47 mAttributionSourceRegistrationUrl = new ArrayList<>(); 48 mAttributionTriggerRegistrationUrl = new ArrayList<>(); 49 mAttributionReportingUrl = new ArrayList<>(); 50 mRemarketingResponseBasedRegistrationUrl = new ArrayList<>(); 51 mEncryptionKeyUrl = new ArrayList<>(); 52 } 53 54 @Override equals(Object obj)55 public boolean equals(Object obj) { 56 if (!(obj instanceof EnrollmentData)) { 57 return false; 58 } 59 EnrollmentData enrollmentData = (EnrollmentData) obj; 60 return Objects.equals(mEnrollmentId, enrollmentData.mEnrollmentId) 61 && Objects.equals(mCompanyId, enrollmentData.mCompanyId) 62 && Objects.equals(mSdkNames, enrollmentData.mSdkNames) 63 && Objects.equals( 64 mAttributionSourceRegistrationUrl, 65 enrollmentData.mAttributionSourceRegistrationUrl) 66 && Objects.equals( 67 mAttributionTriggerRegistrationUrl, 68 enrollmentData.mAttributionTriggerRegistrationUrl) 69 && Objects.equals(mAttributionReportingUrl, enrollmentData.mAttributionReportingUrl) 70 && Objects.equals( 71 mRemarketingResponseBasedRegistrationUrl, 72 enrollmentData.mRemarketingResponseBasedRegistrationUrl) 73 && Objects.equals(mEncryptionKeyUrl, enrollmentData.mEncryptionKeyUrl); 74 } 75 76 @Override hashCode()77 public int hashCode() { 78 return Objects.hash( 79 mEnrollmentId, 80 mCompanyId, 81 mSdkNames, 82 mAttributionSourceRegistrationUrl, 83 mAttributionTriggerRegistrationUrl, 84 mAttributionReportingUrl, 85 mRemarketingResponseBasedRegistrationUrl, 86 mEncryptionKeyUrl); 87 } 88 89 /** Returns ID provided to the Adtech at the end of the enrollment process. */ getEnrollmentId()90 public String getEnrollmentId() { 91 return mEnrollmentId; 92 } 93 94 /** Returns ID assigned to the Parent Company. */ getCompanyId()95 public String getCompanyId() { 96 return mCompanyId; 97 } 98 99 /** List of SDKs belonging to the same enrollment. */ getSdkNames()100 public List<String> getSdkNames() { 101 return mSdkNames; 102 } 103 104 /** Returns URLs used to register attribution sources for measurement. */ getAttributionSourceRegistrationUrl()105 public List<String> getAttributionSourceRegistrationUrl() { 106 return mAttributionSourceRegistrationUrl; 107 } 108 109 /** Returns URLs used to register triggers for measurement. */ getAttributionTriggerRegistrationUrl()110 public List<String> getAttributionTriggerRegistrationUrl() { 111 return mAttributionTriggerRegistrationUrl; 112 } 113 114 /** Returns URLs that the Measurement module will send Attribution reports to. */ getAttributionReportingUrl()115 public List<String> getAttributionReportingUrl() { 116 return mAttributionReportingUrl; 117 } 118 119 /** Returns URLs used for response-based-registration for joinCustomAudience. */ getRemarketingResponseBasedRegistrationUrl()120 public List<String> getRemarketingResponseBasedRegistrationUrl() { 121 return mRemarketingResponseBasedRegistrationUrl; 122 } 123 124 /** Returns URLs used to fetch public/private keys for encrypting API requests. */ getEncryptionKeyUrl()125 public List<String> getEncryptionKeyUrl() { 126 return mEncryptionKeyUrl; 127 } 128 129 /** 130 * Returns the given {@code input} as a list of values split by the separator value used for all 131 * enrollment data. 132 */ 133 @NonNull splitEnrollmentInputToList(@ullable String input)134 public static List<String> splitEnrollmentInputToList(@Nullable String input) { 135 if (input == null || input.trim().isEmpty()) { 136 return Collections.emptyList(); 137 } 138 139 return Arrays.asList(input.trim().split(SEPARATOR)); 140 } 141 142 /** Builder for {@link EnrollmentData}. */ 143 public static final class Builder { 144 private final EnrollmentData mBuilding; 145 Builder()146 public Builder() { 147 mBuilding = new EnrollmentData(); 148 } 149 150 /** See {@link EnrollmentData#getEnrollmentId()}. */ setEnrollmentId(String enrollmentId)151 public Builder setEnrollmentId(String enrollmentId) { 152 mBuilding.mEnrollmentId = enrollmentId; 153 return this; 154 } 155 156 /** See {@link EnrollmentData#getCompanyId()}. */ setCompanyId(String companyId)157 public Builder setCompanyId(String companyId) { 158 mBuilding.mCompanyId = companyId; 159 return this; 160 } 161 162 /** See {@link EnrollmentData#getSdkNames()} */ setSdkNames(List<String> sdkNames)163 public Builder setSdkNames(List<String> sdkNames) { 164 mBuilding.mSdkNames = sdkNames; 165 return this; 166 } 167 168 /** See {@link EnrollmentData#getSdkNames()} */ setSdkNames(String sdkNames)169 public Builder setSdkNames(String sdkNames) { 170 mBuilding.mSdkNames = splitEnrollmentInputToList(sdkNames); 171 return this; 172 } 173 174 /** See {@link EnrollmentData#getAttributionSourceRegistrationUrl()}. */ setAttributionSourceRegistrationUrl( List<String> attributionSourceRegistrationUrl)175 public Builder setAttributionSourceRegistrationUrl( 176 List<String> attributionSourceRegistrationUrl) { 177 mBuilding.mAttributionSourceRegistrationUrl = attributionSourceRegistrationUrl; 178 return this; 179 } 180 181 /** See {@link EnrollmentData#getAttributionSourceRegistrationUrl()}. */ setAttributionSourceRegistrationUrl( String attributionSourceRegistrationUrl)182 public Builder setAttributionSourceRegistrationUrl( 183 String attributionSourceRegistrationUrl) { 184 mBuilding.mAttributionSourceRegistrationUrl = 185 splitEnrollmentInputToList(attributionSourceRegistrationUrl); 186 return this; 187 } 188 189 /** See {@link EnrollmentData#getAttributionTriggerRegistrationUrl()}. */ setAttributionTriggerRegistrationUrl( List<String> attributionTriggerRegistrationUrl)190 public Builder setAttributionTriggerRegistrationUrl( 191 List<String> attributionTriggerRegistrationUrl) { 192 mBuilding.mAttributionTriggerRegistrationUrl = attributionTriggerRegistrationUrl; 193 return this; 194 } 195 196 /** See {@link EnrollmentData#getAttributionTriggerRegistrationUrl()}. */ setAttributionTriggerRegistrationUrl( String attributionTriggerRegistrationUrl)197 public Builder setAttributionTriggerRegistrationUrl( 198 String attributionTriggerRegistrationUrl) { 199 mBuilding.mAttributionTriggerRegistrationUrl = 200 splitEnrollmentInputToList(attributionTriggerRegistrationUrl); 201 return this; 202 } 203 204 /** See {@link EnrollmentData#getAttributionReportingUrl()}. */ setAttributionReportingUrl(List<String> attributionReportingUrl)205 public Builder setAttributionReportingUrl(List<String> attributionReportingUrl) { 206 mBuilding.mAttributionReportingUrl = attributionReportingUrl; 207 return this; 208 } 209 210 /** See {@link EnrollmentData#getAttributionReportingUrl()}. */ setAttributionReportingUrl(String attributionReportingUrl)211 public Builder setAttributionReportingUrl(String attributionReportingUrl) { 212 mBuilding.mAttributionReportingUrl = 213 splitEnrollmentInputToList(attributionReportingUrl); 214 return this; 215 } 216 217 /** See {@link EnrollmentData#getRemarketingResponseBasedRegistrationUrl()}. */ setRemarketingResponseBasedRegistrationUrl( List<String> remarketingResponseBasedRegistrationUrl)218 public Builder setRemarketingResponseBasedRegistrationUrl( 219 List<String> remarketingResponseBasedRegistrationUrl) { 220 mBuilding.mRemarketingResponseBasedRegistrationUrl = 221 remarketingResponseBasedRegistrationUrl; 222 return this; 223 } 224 225 /** See {@link EnrollmentData#getRemarketingResponseBasedRegistrationUrl()}. */ setRemarketingResponseBasedRegistrationUrl( String remarketingResponseBasedRegistrationUrl)226 public Builder setRemarketingResponseBasedRegistrationUrl( 227 String remarketingResponseBasedRegistrationUrl) { 228 mBuilding.mRemarketingResponseBasedRegistrationUrl = 229 splitEnrollmentInputToList(remarketingResponseBasedRegistrationUrl); 230 return this; 231 } 232 233 /** See {@link EnrollmentData#getEncryptionKeyUrl()}. */ setEncryptionKeyUrl(List<String> encryptionKeyUrl)234 public Builder setEncryptionKeyUrl(List<String> encryptionKeyUrl) { 235 mBuilding.mEncryptionKeyUrl = encryptionKeyUrl; 236 return this; 237 } 238 239 /** See {@link EnrollmentData#getEncryptionKeyUrl()}. */ setEncryptionKeyUrl(String encryptionKeyUrl)240 public Builder setEncryptionKeyUrl(String encryptionKeyUrl) { 241 mBuilding.mEncryptionKeyUrl = splitEnrollmentInputToList(encryptionKeyUrl); 242 return this; 243 } 244 245 /** Builder the {@link EnrollmentData}. */ build()246 public EnrollmentData build() { 247 return mBuilding; 248 } 249 } 250 } 251