• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.user;
18 
19 import android.provider.BaseColumns;
20 
21 /** Container class for definitions and constants of user data tables. */
22 public final class UserDataTables implements BaseColumns {
23     public static final String USER_TABLE_PREFIX = "user_";
24     public static final String INDEX_PREFIX = "index_";
25 
26     /** Location history table. */
27     public static class LocationHistory implements BaseColumns {
28         /** The name of location history table. */
29         public static final String TABLE_NAME = USER_TABLE_PREFIX + "location_history";
30 
31         /** The name of location history index. */
32         public static final String INDEX_NAME = INDEX_PREFIX + TABLE_NAME;
33 
34         /** The time that the location is retrieved in seconds. */
35         public static final String TIME_SEC = "time_sec";
36 
37         /** The latitude of the location in the format of "[+-]DDD.DDDDD". */
38         public static final String LATITUDE = "latitude";
39 
40         /** The Longitude of the location in the format of "[+-]DDD.DDDDD". */
41         public static final String LONGITUDE = "longitude";
42 
43         /** The source of location signal. */
44         public static final String SOURCE = "source";
45 
46         /** Is the location accuracy precise or coarse. */
47         public static final String IS_PRECISE = "is_precise";
48 
49         public static final String CREATE_TABLE_STATEMENT = "CREATE TABLE IF NOT EXISTS "
50                 + TABLE_NAME + " ("
51                 + _ID + " INTEGER PRIMARY KEY, "
52                 + TIME_SEC + " INTEGER NOT NULL, "
53                 + LATITUDE + " TEXT NOT NULL, "
54                 + LONGITUDE + " TEXT NOT NULL, "
55                 + SOURCE + " INTEGER NOT NULL, "
56                 + IS_PRECISE + " INTEGER NOT NULL)";
57 
58         public static final String CREATE_INDEXES_STATEMENT = "CREATE INDEX IF NOT EXISTS "
59                 + INDEX_NAME + " ON "
60                 + TABLE_NAME + "("
61                 + TIME_SEC + ")";
62     }
63 
64     /** App usage stats history table. */
65     public static class AppUsageHistory implements BaseColumns {
66         /** The name of app usage stats table. */
67         public static final String TABLE_NAME = USER_TABLE_PREFIX + "app_usage_history";
68 
69         /** The package/app name of a usage activity. */
70         public static final String PACKAGE_NAME = "package_name";
71 
72         /** Activity starting time of the app in seconds. */
73         public static final String STARTING_TIME_SEC = "starting_time_sec";
74 
75         /** Activity ending time of the app in seconds. */
76         public static final String ENDING_TIME_SEC = "ending_time_sec";
77 
78         /** Total activity time (on the foreground) of the app in seconds. */
79         public static final String TOTAL_TIME_USED_SEC = "total_time_used_sec";
80 
81         /** The index name of app usage stats table based on starting timestamp. */
82         public static final String STARTING_TIME_SEC_INDEX_NAME = INDEX_PREFIX
83                 + TABLE_NAME + STARTING_TIME_SEC;
84 
85         /** The index name of app usage stats table based on ending timestamp. */
86         public static final String ENDING_TIME_SEC_INDEX_NAME = INDEX_PREFIX
87                 + TABLE_NAME + ENDING_TIME_SEC;
88 
89         /** The index name of app usage stats table based on total time spent. */
90         public static final String TOTAL_TIME_USED_SEC_INDEX_NAME = INDEX_PREFIX
91                 + TABLE_NAME + TOTAL_TIME_USED_SEC;
92 
93         public static final String CREATE_TABLE_STATEMENT = "CREATE TABLE IF NOT EXISTS "
94                 + TABLE_NAME + " ("
95                 + _ID + " INTEGER PRIMARY KEY, "
96                 + PACKAGE_NAME + " TEXT NOT NULL, "
97                 + STARTING_TIME_SEC + " INTEGER NOT NULL, "
98                 + ENDING_TIME_SEC + " INTEGER NOT NULL, "
99                 + TOTAL_TIME_USED_SEC + " INTEGER NOT NULL)";
100 
101         // All timestamp-related fields could be of interests of FA queries.
102         public static final String CREATE_STARTING_TIME_SEC_INDEX_STATEMENT =
103                 "CREATE INDEX IF NOT EXISTS "
104                 + STARTING_TIME_SEC_INDEX_NAME + " ON "
105                 + TABLE_NAME + "("
106                 + STARTING_TIME_SEC + ")";
107 
108         public static final String CREATE_ENDING_TIME_SEC_INDEX_STATEMENT =
109                 "CREATE INDEX IF NOT EXISTS "
110                 + ENDING_TIME_SEC_INDEX_NAME + " ON "
111                 + TABLE_NAME + "("
112                 + ENDING_TIME_SEC + ")";
113 
114         public static final String CREATE_TOTAL_TIME_USED_SEC_INDEX_STATEMENT =
115                 "CREATE INDEX IF NOT EXISTS "
116                 + TOTAL_TIME_USED_SEC_INDEX_NAME + " ON "
117                 + TABLE_NAME + "("
118                 + TOTAL_TIME_USED_SEC + ")";
119     }
120 
121     // Private constructor to prevent instantiation.
UserDataTables()122     private UserDataTables() {}
123 }
124