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 queries table. Defines the table. */
22 public class QueriesContract {
QueriesContract()23     private QueriesContract() {
24     }
25 
26     /**
27      * Table containing queries. Each row in the table represents a single query.
28      */
29     public static class QueriesEntry implements BaseColumns {
30         public static final String TABLE_NAME = "queries";
31 
32         /** The id of the query. */
33         public static final String QUERY_ID = "queryId";
34 
35         /** Time of the query in milliseconds. */
36         public static final String TIME_MILLIS = "timeMillis";
37 
38         /** Name of the app that invoked ODP. */
39         public static final String APP_PACKAGE_NAME = "appPackageName";
40 
41         /** Component Name of the service that handled the request */
42         public static final String SERVICE_NAME = "serviceName";
43 
44         /** Hash of the signing key of the service. */
45         public static final String SERVICE_CERT_DIGEST = "serviceCertDigest";
46 
47         /** Blob representing the common query fields. */
48         public static final String QUERY_DATA = "queryData";
49 
50         public static final String CREATE_TABLE_STATEMENT =
51                 "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " ("
52                     + QUERY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
53                     + TIME_MILLIS + " INTEGER NOT NULL,"
54                     + APP_PACKAGE_NAME + " TEXT NOT NULL,"
55                     + SERVICE_NAME + " TEXT NOT NULL,"
56                     + SERVICE_CERT_DIGEST + " TEXT NOT NULL,"
57                     + QUERY_DATA + " BLOB NOT NULL)";
58 
59         public static final String UPGRADE_V1_TO_V2_STATEMENT =
60                 "ALTER TABLE " + TABLE_NAME
61                 + " ADD COLUMN " + APP_PACKAGE_NAME + " TEXT NOT NULL DEFAULT ''";
62 
63         public static final String UPGRADE_V2_TO_V3_STATEMENT =
64                 "ALTER TABLE " + TABLE_NAME
65                 + " ADD COLUMN " + SERVICE_CERT_DIGEST + " TEXT NOT NULL DEFAULT ''";
66 
QueriesEntry()67         private QueriesEntry() {}
68     }
69 }
70