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 com.android.adservices.data.adselection; 18 19 import android.annotation.NonNull; 20 21 import androidx.annotation.Nullable; 22 import androidx.room.Dao; 23 import androidx.room.Insert; 24 import androidx.room.OnConflictStrategy; 25 import androidx.room.Query; 26 27 import java.time.Instant; 28 import java.util.List; 29 30 /** Data Access Object interface for access to the local AdSelectionDebugReport data storage. */ 31 @Dao 32 public abstract class AdSelectionDebugReportDao { 33 34 /** 35 * Adds list of ad selection debug report entries into {@link 36 * DBAdSelectionDebugReport.TABLE_NAME} 37 * 38 * @param adSelectionDebugReports is the List of DBAdSelectionDebugReport to add to the table 39 * ad_selection_debug_report. 40 */ 41 @Insert(onConflict = OnConflictStrategy.REPLACE) persistAdSelectionDebugReporting( @onNull List<DBAdSelectionDebugReport> adSelectionDebugReports)42 public abstract void persistAdSelectionDebugReporting( 43 @NonNull List<DBAdSelectionDebugReport> adSelectionDebugReports); 44 45 /** 46 * Fetch all debug reports created before a specific timestamp. 47 * 48 * @param currentTime to compare against debug report creation time 49 * @param limit to specify how many debug reports should be selected from DB. 50 * @return All the debug reports 51 */ 52 @Query( 53 "SELECT * FROM ad_selection_debug_report WHERE creation_timestamp <= (:currentTime)" 54 + " LIMIT (:limit);") 55 @Nullable getDebugReportsBeforeTime( @onNull Instant currentTime, int limit)56 public abstract List<DBAdSelectionDebugReport> getDebugReportsBeforeTime( 57 @NonNull Instant currentTime, int limit); 58 59 /** 60 * deletes all debug reports before a specific timestamp. 61 * 62 * @param currentTime to compare against debug report creation time 63 */ 64 @Query("DELETE FROM ad_selection_debug_report WHERE creation_timestamp <= (:currentTime)") deleteDebugReportsBeforeTime(@onNull Instant currentTime)65 public abstract void deleteDebugReportsBeforeTime(@NonNull Instant currentTime); 66 } 67