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.ondevicepersonalization.services.data.events; 18 19 import android.provider.BaseColumns; 20 21 /** Contract for the events table. Defines the table. */ 22 public class EventsContract { EventsContract()23 private EventsContract() { 24 } 25 26 /** 27 * Table containing events. Each row in the table 28 * represents a single event. 29 */ 30 public static class EventsEntry implements BaseColumns { 31 public static final String TABLE_NAME = "events"; 32 33 /** The id of the event. */ 34 public static final String EVENT_ID = "eventId"; 35 36 /** The id of the query. */ 37 public static final String QUERY_ID = "queryId"; 38 39 /** Index of the slot for this event */ 40 public static final String SLOT_INDEX = "slotIndex"; 41 42 /** Id of the bidder for this event */ 43 public static final String BID_ID = "bidId"; 44 45 /** Name of the service package or this event */ 46 public static final String SERVICE_PACKAGE_NAME = "servicePackageName"; 47 48 /** The position of the event in the slot */ 49 public static final String SLOT_POSITION = "slotPosition"; 50 51 /** {@link EventType} defining the type of event */ 52 public static final String TYPE = "type"; 53 54 /** Time of the event in milliseconds. */ 55 public static final String TIME_MILLIS = "timeMillis"; 56 57 /** Id of the slot for this event */ 58 public static final String SLOT_ID = "slotId"; 59 60 /** Blob representing the event. */ 61 public static final String EVENT_DATA = "eventData"; 62 63 public static final String CREATE_TABLE_STATEMENT = 64 "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" 65 + EVENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," 66 + QUERY_ID + " INTEGER NOT NULL," 67 + SLOT_INDEX + " INTEGER NOT NULL," 68 + BID_ID + " TEXT NOT NULL," 69 + SERVICE_PACKAGE_NAME + " TEXT NOT NULL," 70 + SLOT_POSITION + " INTEGER NOT NULL," 71 + TYPE + " INTEGER NOT NULL," 72 + TIME_MILLIS + " INTEGER NOT NULL," 73 + SLOT_ID + " TEXT NULL," 74 + EVENT_DATA + " BLOB NOT NULL," 75 + "FOREIGN KEY(" + QUERY_ID + ") REFERENCES " 76 + QueriesContract.QueriesEntry.TABLE_NAME + "(" 77 + QueriesContract.QueriesEntry.QUERY_ID + ")," 78 + "UNIQUE(" + QUERY_ID + "," 79 + SLOT_INDEX + "," 80 + BID_ID + "," 81 + SERVICE_PACKAGE_NAME + "," 82 + SLOT_POSITION + "," 83 + TYPE + "))"; 84 EventsEntry()85 private EventsEntry() {} 86 } 87 } 88