1 /* 2 * Copyright (C) 2024 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.data.kanon; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 import androidx.room.ColumnInfo; 22 import androidx.room.Entity; 23 import androidx.room.PrimaryKey; 24 import androidx.room.TypeConverters; 25 26 import com.android.adservices.data.common.FledgeRoomConverters; 27 28 import com.google.auto.value.AutoValue; 29 import com.google.auto.value.AutoValue.CopyAnnotations; 30 31 import java.time.Instant; 32 import java.util.UUID; 33 34 @Entity(tableName = DBClientParameters.TABLE_NAME) 35 @TypeConverters({FledgeRoomConverters.class}) 36 @AutoValue 37 @CopyAnnotations 38 public abstract class DBClientParameters { 39 public static final String TABLE_NAME = "client_parameters"; 40 41 /** Client public parameters in byte array. */ 42 @NonNull 43 @CopyAnnotations 44 @ColumnInfo(name = "client_public_parameters", typeAffinity = ColumnInfo.BLOB) 45 @SuppressWarnings({"AutoValueImmutableFields", "AutoValueMutable"}) getClientPublicParameters()46 public abstract byte[] getClientPublicParameters(); 47 48 /** Client private parameters in byte array. */ 49 @NonNull 50 @CopyAnnotations 51 @ColumnInfo(name = "client_private_parameters", typeAffinity = ColumnInfo.BLOB) 52 @SuppressWarnings({"AutoValueImmutableFields", "AutoValueMutable"}) getClientPrivateParameters()53 public abstract byte[] getClientPrivateParameters(); 54 55 /** 56 * Expiry instant of client parameters, this field is returned in the register client response. 57 */ 58 @NonNull 59 @CopyAnnotations 60 @ColumnInfo(name = "expiry_instant") getClientParametersExpiryInstant()61 public abstract Instant getClientParametersExpiryInstant(); 62 63 /** Client id that generated and registered this client parameters. */ 64 @NonNull 65 @CopyAnnotations 66 @ColumnInfo(name = "client_id") getClientId()67 public abstract UUID getClientId(); 68 69 /** Client Parameters id, primary key for this table. */ 70 @ColumnInfo(name = "client_parameters_id") 71 @PrimaryKey(autoGenerate = true) 72 @Nullable 73 @CopyAnnotations getClientParametersId()74 public abstract Long getClientParametersId(); 75 76 /** 77 * Client params version of the client parameters. This field is returned in the register client 78 * parameters. * 79 */ 80 @NonNull 81 @CopyAnnotations 82 @ColumnInfo(name = "client_params_version") getClientParamsVersion()83 public abstract String getClientParamsVersion(); 84 85 /** Returns a builder for {@link DBClientParameters} */ builder()86 public static DBClientParameters.Builder builder() { 87 return new AutoValue_DBClientParameters.Builder(); 88 } 89 90 /** Creates and returns a {@link DBClientParameters} */ create( @onNull String clientParamsVersion, @NonNull long clientParametersId, @NonNull UUID clientId, @NonNull Instant clientParametersExpiryInstant, @NonNull byte[] clientPrivateParameters, @NonNull byte[] clientPublicParameters)91 public static DBClientParameters create( 92 @NonNull String clientParamsVersion, 93 @NonNull long clientParametersId, 94 @NonNull UUID clientId, 95 @NonNull Instant clientParametersExpiryInstant, 96 @NonNull byte[] clientPrivateParameters, 97 @NonNull byte[] clientPublicParameters) { 98 return builder() 99 .setClientParamsVersion(clientParamsVersion) 100 .setClientParametersId(clientParametersId) 101 .setClientId(clientId) 102 .setClientPrivateParameters(clientPrivateParameters) 103 .setClientPublicParameters(clientPublicParameters) 104 .setClientParametersExpiryInstant(clientParametersExpiryInstant) 105 .build(); 106 } 107 108 /** Builder class for {@link DBClientParameters} */ 109 @AutoValue.Builder 110 public abstract static class Builder { 111 112 /** Sets the client params version. */ setClientParamsVersion(String clientParamsVersion)113 public abstract Builder setClientParamsVersion(String clientParamsVersion); 114 115 /** 116 * Sets the client parameters id. This ID is only used internally and does not need to be 117 * stable or reproducible. It is auto-generated by Room if set to {@code null} on insertion. 118 */ 119 @NonNull setClientParametersId(@ullable Long clientParametersId)120 public abstract Builder setClientParametersId(@Nullable Long clientParametersId); 121 122 /** Sets the client id. */ 123 @NonNull setClientId(UUID clientId)124 public abstract Builder setClientId(UUID clientId); 125 126 /** Sets the client params expiry instant. */ 127 @NonNull setClientParametersExpiryInstant( Instant clientParametersExpiryInstant)128 public abstract Builder setClientParametersExpiryInstant( 129 Instant clientParametersExpiryInstant); 130 131 /** Sets the client public params. */ 132 @NonNull setClientPublicParameters(byte[] clientPublicParameters)133 public abstract Builder setClientPublicParameters(byte[] clientPublicParameters); 134 135 /** Sets the client private parameters. */ 136 @NonNull setClientPrivateParameters(byte[] clientPrivateParameters)137 public abstract Builder setClientPrivateParameters(byte[] clientPrivateParameters); 138 139 /** Builds the {@link DBClientParameters} object */ 140 @NonNull build()141 public abstract DBClientParameters build(); 142 } 143 } 144