summaryrefslogtreecommitdiff
path: root/adservices/service-core/java/com/android/adservices/data/measurement/MeasurementTables.java
blob: 6e8873191eae5659b6f61cb87fa2740b4de118e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.adservices.data.measurement;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Container class for Measurement PPAPI table definitions and constants.
 */
public final class MeasurementTables {
    public static final String MSMT_TABLE_PREFIX = "msmt_";
    public static final String INDEX_PREFIX = "idx_";

    /**
     * Array of all Measurement related tables. The AdTechUrls table is not included in the
     * Measurement tables because it will be used for a more general purpose.
     */
    // TODO(b/237306788): Move AdTechUrls tables to common tables and add method to delete common
    //  tables.
    public static final String[] ALL_MSMT_TABLES = {
        MeasurementTables.SourceContract.TABLE,
        MeasurementTables.TriggerContract.TABLE,
        MeasurementTables.EventReportContract.TABLE,
        MeasurementTables.AggregateReport.TABLE,
        MeasurementTables.AggregateEncryptionKey.TABLE,
        MeasurementTables.AttributionContract.TABLE,
        MeasurementTables.AsyncRegistrationContract.TABLE
    };

    /** Contract for asynchronous Registration. */
    public interface AsyncRegistrationContract {
        String TABLE = MSMT_TABLE_PREFIX + "async_registration_contract";
        String ID = "_id";
        String REGISTRATION_URI = "registration_uri";
        String TOP_ORIGIN = "top_origin";
        String INPUT_EVENT = "input_event";
        String REDIRECT = "redirect";
        String REGISTRANT = "registrant";
        String SCHEDULE_TIME = "scheduled_time";
        String RETRY_COUNT = "retry_count";
        String LAST_TIME_PROCESSING = "last_processing_time";
        String TYPE = "type";
        String WEB_DESTINATION = "web_destination";
        String OS_DESTINATION = "os_destination";
        String VERIFIED_DESTINATION = "verified_destination";
    }

    /** Contract for Source. */
    public interface SourceContract {
        String TABLE = MSMT_TABLE_PREFIX + "source";
        String ID = "_id";
        String EVENT_ID = "event_id";
        String PUBLISHER = "publisher";
        String PUBLISHER_TYPE = "publisher_type";
        String APP_DESTINATION = "app_destination";
        String WEB_DESTINATION = "web_destination";
        String DEDUP_KEYS = "dedup_keys";
        String EVENT_TIME = "event_time";
        String EXPIRY_TIME = "expiry_time";
        String PRIORITY = "priority";
        String STATUS = "status";
        String SOURCE_TYPE = "source_type";
        String ENROLLMENT_ID = "enrollment_id";
        String REGISTRANT = "registrant";
        String ATTRIBUTION_MODE = "attribution_mode";
        String INSTALL_ATTRIBUTION_WINDOW = "install_attribution_window";
        String INSTALL_COOLDOWN_WINDOW = "install_cooldown_window";
        String IS_INSTALL_ATTRIBUTED = "is_install_attributed";
        String FILTER_DATA = "filter_data";
        String AGGREGATE_SOURCE = "aggregate_source";
        String AGGREGATE_CONTRIBUTIONS = "aggregate_contributions";
        String DEBUG_KEY = "debug_key";
    }

    /** Contract for Trigger. */
    public interface TriggerContract {
        String TABLE = MSMT_TABLE_PREFIX + "trigger";
        String ID = "_id";
        String ATTRIBUTION_DESTINATION = "attribution_destination";
        String DESTINATION_TYPE = "destination_type";
        String TRIGGER_TIME = "trigger_time";
        String STATUS = "status";
        String REGISTRANT = "registrant";
        String ENROLLMENT_ID = "enrollment_id";
        String EVENT_TRIGGERS = "event_triggers";
        String AGGREGATE_TRIGGER_DATA = "aggregate_trigger_data";
        String AGGREGATE_VALUES = "aggregate_values";
        String FILTERS = "filters";
        String DEBUG_KEY = "debug_key";
    }

    /** Contract for EventReport. */
    public interface EventReportContract {
        String TABLE = MSMT_TABLE_PREFIX + "event_report";
        String ID = "_id";
        String SOURCE_ID = "source_id";
        String ATTRIBUTION_DESTINATION = "attribution_destination";
        String REPORT_TIME = "report_time";
        String TRIGGER_DATA = "trigger_data";
        String TRIGGER_PRIORITY = "trigger_priority";
        String TRIGGER_DEDUP_KEY = "trigger_dedup_key";
        String TRIGGER_TIME = "trigger_time";
        String STATUS = "status";
        String SOURCE_TYPE = "source_type";
        String ENROLLMENT_ID = "enrollment_id";
        String RANDOMIZED_TRIGGER_RATE = "randomized_trigger_rate";
        String SOURCE_DEBUG_KEY = "source_debug_key";
        String TRIGGER_DEBUG_KEY = "trigger_debug_key";
    }

    /** Contract for Attribution rate limit. */
    public interface AttributionContract {
        String TABLE = MSMT_TABLE_PREFIX + "attribution";
        String ID = "_id";
        String SOURCE_SITE = "source_site";
        String SOURCE_ORIGIN = "source_origin";
        String DESTINATION_SITE = "attribution_destination_site";
        String DESTINATION_ORIGIN = "destination_origin";
        String TRIGGER_TIME = "trigger_time";
        String REGISTRANT = "registrant";
        String ENROLLMENT_ID = "enrollment_id";
    }

    /** Contract for Unencrypted aggregate payload. */
    public interface AggregateReport {
        String TABLE = MSMT_TABLE_PREFIX + "aggregate_report";
        String ID = "_id";
        String PUBLISHER = "publisher";
        String ATTRIBUTION_DESTINATION = "attribution_destination";
        String SOURCE_REGISTRATION_TIME = "source_registration_time";
        String SCHEDULED_REPORT_TIME = "scheduled_report_time";
        String ENROLLMENT_ID = "enrollment_id";
        String DEBUG_CLEARTEXT_PAYLOAD = "debug_cleartext_payload";
        String STATUS = "status";
        String API_VERSION = "api_version";
        String SOURCE_DEBUG_KEY = "source_debug_key";
        String TRIGGER_DEBUG_KEY = "trigger_debug_key";
    }

    /** Contract for aggregate encryption key. */
    public interface AggregateEncryptionKey {
        String TABLE = MSMT_TABLE_PREFIX + "aggregate_encryption_key";
        String ID = "_id";
        String KEY_ID = "key_id";
        String PUBLIC_KEY = "public_key";
        String EXPIRY = "expiry";
    }

    public static final String CREATE_TABLE_ASYNC_REGISTRATION_V1 =
            "CREATE TABLE "
                    + AsyncRegistrationContract.TABLE
                    + " ("
                    + AsyncRegistrationContract.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + AsyncRegistrationContract.REGISTRATION_URI
                    + " TEXT, "
                    + AsyncRegistrationContract.WEB_DESTINATION
                    + " TEXT, "
                    + AsyncRegistrationContract.OS_DESTINATION
                    + " TEXT, "
                    + AsyncRegistrationContract.VERIFIED_DESTINATION
                    + " TEXT, "
                    + AsyncRegistrationContract.TOP_ORIGIN
                    + " TEXT, "
                    + AsyncRegistrationContract.REDIRECT
                    + " INTEGER, "
                    + AsyncRegistrationContract.INPUT_EVENT
                    + " INTEGER, "
                    + AsyncRegistrationContract.REGISTRANT
                    + " TEXT, "
                    + AsyncRegistrationContract.SCHEDULE_TIME
                    + " INTEGER, "
                    + AsyncRegistrationContract.RETRY_COUNT
                    + " INTEGER, "
                    + AsyncRegistrationContract.LAST_TIME_PROCESSING
                    + " INTEGER, "
                    + AsyncRegistrationContract.TYPE
                    + " INTEGER "
                    + ")";

    public static final String CREATE_TABLE_SOURCE_V1 =
            "CREATE TABLE "
                    + SourceContract.TABLE
                    + " ("
                    + SourceContract.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + SourceContract.EVENT_ID
                    + " INTEGER, "
                    + SourceContract.PUBLISHER
                    + " TEXT, "
                    + SourceContract.PUBLISHER_TYPE
                    + " INTEGER, "
                    + SourceContract.APP_DESTINATION
                    + " TEXT, "
                    + SourceContract.ENROLLMENT_ID
                    + " TEXT, "
                    + SourceContract.EVENT_TIME
                    + " INTEGER, "
                    + SourceContract.EXPIRY_TIME
                    + " INTEGER, "
                    + SourceContract.PRIORITY
                    + " INTEGER, "
                    + SourceContract.STATUS
                    + " INTEGER, "
                    + SourceContract.DEDUP_KEYS
                    + " TEXT, "
                    + SourceContract.SOURCE_TYPE
                    + " TEXT, "
                    + SourceContract.REGISTRANT
                    + " TEXT, "
                    + SourceContract.ATTRIBUTION_MODE
                    + " INTEGER, "
                    + SourceContract.INSTALL_ATTRIBUTION_WINDOW
                    + " INTEGER, "
                    + SourceContract.INSTALL_COOLDOWN_WINDOW
                    + " INTEGER, "
                    + SourceContract.IS_INSTALL_ATTRIBUTED
                    + " INTEGER, "
                    + SourceContract.FILTER_DATA
                    + " TEXT, "
                    + SourceContract.AGGREGATE_SOURCE
                    + " TEXT, "
                    + SourceContract.AGGREGATE_CONTRIBUTIONS
                    + " INTEGER, "
                    + SourceContract.WEB_DESTINATION
                    + " TEXT, "
                    + SourceContract.DEBUG_KEY
                    + " INTEGER "
                    + ")";

    public static final String CREATE_TABLE_TRIGGER_V1 =
            "CREATE TABLE "
                    + TriggerContract.TABLE
                    + " ("
                    + TriggerContract.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + TriggerContract.ATTRIBUTION_DESTINATION
                    + " TEXT, "
                    + TriggerContract.DESTINATION_TYPE
                    + " INTEGER, "
                    + TriggerContract.ENROLLMENT_ID
                    + " TEXT, "
                    + TriggerContract.TRIGGER_TIME
                    + " INTEGER, "
                    + TriggerContract.EVENT_TRIGGERS
                    + " TEXT, "
                    + TriggerContract.STATUS
                    + " INTEGER, "
                    + TriggerContract.REGISTRANT
                    + " TEXT, "
                    + TriggerContract.AGGREGATE_TRIGGER_DATA
                    + " TEXT, "
                    + TriggerContract.AGGREGATE_VALUES
                    + " TEXT, "
                    + TriggerContract.FILTERS
                    + " TEXT, "
                    + TriggerContract.DEBUG_KEY
                    + " INTEGER "
                    + ")";

    public static final String CREATE_TABLE_EVENT_REPORT_V1 =
            "CREATE TABLE "
                    + EventReportContract.TABLE
                    + " ("
                    + EventReportContract.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + EventReportContract.SOURCE_ID
                    + " INTEGER, "
                    + EventReportContract.ENROLLMENT_ID
                    + " TEXT, "
                    + EventReportContract.ATTRIBUTION_DESTINATION
                    + " TEXT, "
                    + EventReportContract.REPORT_TIME
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_DATA
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_PRIORITY
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_DEDUP_KEY
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_TIME
                    + " INTEGER, "
                    + EventReportContract.STATUS
                    + " INTEGER, "
                    + EventReportContract.SOURCE_TYPE
                    + " TEXT, "
                    + EventReportContract.RANDOMIZED_TRIGGER_RATE
                    + " DOUBLE "
                    + ")";

    public static final String CREATE_TABLE_EVENT_REPORT_V2 =
            "CREATE TABLE "
                    + EventReportContract.TABLE
                    + " ("
                    + EventReportContract.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + EventReportContract.SOURCE_ID
                    + " INTEGER, "
                    + EventReportContract.ENROLLMENT_ID
                    + " TEXT, "
                    + EventReportContract.ATTRIBUTION_DESTINATION
                    + " TEXT, "
                    + EventReportContract.REPORT_TIME
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_DATA
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_PRIORITY
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_DEDUP_KEY
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_TIME
                    + " INTEGER, "
                    + EventReportContract.STATUS
                    + " INTEGER, "
                    + EventReportContract.SOURCE_TYPE
                    + " TEXT, "
                    + EventReportContract.RANDOMIZED_TRIGGER_RATE
                    + " DOUBLE, "
                    + EventReportContract.SOURCE_DEBUG_KEY
                    + " INTEGER, "
                    + EventReportContract.TRIGGER_DEBUG_KEY
                    + " INTEGER "
                    + ")";

    public static final String CREATE_TABLE_ATTRIBUTION_V1 =
            "CREATE TABLE "
                    + AttributionContract.TABLE
                    + " ("
                    + AttributionContract.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + AttributionContract.SOURCE_SITE
                    + " TEXT, "
                    + AttributionContract.SOURCE_ORIGIN
                    + " TEXT, "
                    + AttributionContract.DESTINATION_SITE
                    + " TEXT, "
                    + AttributionContract.DESTINATION_ORIGIN
                    + " TEXT, "
                    + AttributionContract.ENROLLMENT_ID
                    + " TEXT, "
                    + AttributionContract.TRIGGER_TIME
                    + " INTEGER, "
                    + AttributionContract.REGISTRANT
                    + " TEXT "
                    + ")";

    public static final String CREATE_TABLE_AGGREGATE_REPORT_V1 =
            "CREATE TABLE "
                    + AggregateReport.TABLE
                    + " ("
                    + AggregateReport.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + AggregateReport.PUBLISHER
                    + " TEXT, "
                    + AggregateReport.ATTRIBUTION_DESTINATION
                    + " TEXT, "
                    + AggregateReport.SOURCE_REGISTRATION_TIME
                    + " INTEGER, "
                    + AggregateReport.SCHEDULED_REPORT_TIME
                    + " INTEGER, "
                    + AggregateReport.ENROLLMENT_ID
                    + " TEXT, "
                    + AggregateReport.DEBUG_CLEARTEXT_PAYLOAD
                    + " TEXT, "
                    + AggregateReport.STATUS
                    + " INTEGER, "
                    + AggregateReport.API_VERSION
                    + " TEXT "
                    + ")";

    public static final String CREATE_TABLE_AGGREGATE_REPORT_V2 =
            "CREATE TABLE "
                    + AggregateReport.TABLE
                    + " ("
                    + AggregateReport.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + AggregateReport.PUBLISHER
                    + " TEXT, "
                    + AggregateReport.ATTRIBUTION_DESTINATION
                    + " TEXT, "
                    + AggregateReport.SOURCE_REGISTRATION_TIME
                    + " INTEGER, "
                    + AggregateReport.SCHEDULED_REPORT_TIME
                    + " INTEGER, "
                    + AggregateReport.ENROLLMENT_ID
                    + " TEXT, "
                    + AggregateReport.DEBUG_CLEARTEXT_PAYLOAD
                    + " TEXT, "
                    + AggregateReport.STATUS
                    + " INTEGER, "
                    + AggregateReport.API_VERSION
                    + " TEXT, "
                    + AggregateReport.SOURCE_DEBUG_KEY
                    + " INTEGER, "
                    + AggregateReport.TRIGGER_DEBUG_KEY
                    + " INTEGER "
                    + ")";

    public static final String CREATE_TABLE_AGGREGATE_ENCRYPTION_KEY_V1 =
            "CREATE TABLE "
                    + AggregateEncryptionKey.TABLE
                    + " ("
                    + AggregateEncryptionKey.ID
                    + " TEXT PRIMARY KEY NOT NULL, "
                    + AggregateEncryptionKey.KEY_ID
                    + " TEXT, "
                    + AggregateEncryptionKey.PUBLIC_KEY
                    + " TEXT, "
                    + AggregateEncryptionKey.EXPIRY
                    + " INTEGER "
                    + ")";

    public static final String[] CREATE_INDEXES = {
        "CREATE INDEX "
                + INDEX_PREFIX
                + SourceContract.TABLE
                + "_ad_ei_et "
                + "ON "
                + SourceContract.TABLE
                + "( "
                + SourceContract.APP_DESTINATION
                + ", "
                + SourceContract.ENROLLMENT_ID
                + ", "
                + SourceContract.EXPIRY_TIME
                + " DESC "
                + ")",
        "CREATE INDEX "
                + INDEX_PREFIX
                + SourceContract.TABLE
                + "_et "
                + "ON "
                + SourceContract.TABLE
                + "("
                + SourceContract.EXPIRY_TIME
                + ")",
        "CREATE INDEX "
                + INDEX_PREFIX
                + SourceContract.TABLE
                + "_p_ad_wd_s_et "
                + "ON "
                + SourceContract.TABLE
                + "("
                + SourceContract.PUBLISHER
                + ", "
                + SourceContract.APP_DESTINATION
                + ", "
                + SourceContract.WEB_DESTINATION
                + ", "
                + SourceContract.STATUS
                + ", "
                + SourceContract.EVENT_TIME
                + ")",
        "CREATE INDEX "
                + INDEX_PREFIX
                + TriggerContract.TABLE
                + "_ad_ei_tt "
                + "ON "
                + TriggerContract.TABLE
                + "( "
                + TriggerContract.ATTRIBUTION_DESTINATION
                + ", "
                + TriggerContract.ENROLLMENT_ID
                + ", "
                + TriggerContract.TRIGGER_TIME
                + " ASC)",
        "CREATE INDEX "
                + INDEX_PREFIX
                + TriggerContract.TABLE
                + "_tt "
                + "ON "
                + TriggerContract.TABLE
                + "("
                + TriggerContract.TRIGGER_TIME
                + ")",
        "CREATE INDEX "
                + INDEX_PREFIX
                + AttributionContract.TABLE
                + "_ss_so_ds_do_ei_tt"
                + " ON "
                + AttributionContract.TABLE
                + "("
                + AttributionContract.SOURCE_SITE
                + ", "
                + AttributionContract.SOURCE_ORIGIN
                + ", "
                + AttributionContract.DESTINATION_SITE
                + ", "
                + AttributionContract.DESTINATION_ORIGIN
                + ", "
                + AttributionContract.ENROLLMENT_ID
                + ", "
                + AttributionContract.TRIGGER_TIME
                + ")"
    };

    // Consolidated list of create statements for all tables.
    public static final List<String> CREATE_STATEMENTS =
            Collections.unmodifiableList(
                    Arrays.asList(
                            CREATE_TABLE_SOURCE_V1,
                            CREATE_TABLE_TRIGGER_V1,
                            CREATE_TABLE_EVENT_REPORT_V2,
                            CREATE_TABLE_ATTRIBUTION_V1,
                            CREATE_TABLE_AGGREGATE_REPORT_V2,
                            CREATE_TABLE_AGGREGATE_ENCRYPTION_KEY_V1,
                            CREATE_TABLE_ASYNC_REGISTRATION_V1));

    // Private constructor to prevent instantiation.
    private MeasurementTables() {
    }
}