• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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.providers.contacts;
18 
19 import android.content.ContentValues;
20 import android.content.Context;
21 import android.database.sqlite.SQLiteDatabase;
22 import android.provider.ContactsContract.Profile;
23 
24 import com.android.providers.contacts.util.NeededForTesting;
25 
26 /**
27  * A separate version of the contacts database helper for storing the user's profile data.
28  */
29 public class ProfileDatabaseHelper extends ContactsDatabaseHelper {
30     private static final String TAG = "ProfileDatabaseHelper";
31 
32     private static final String DATABASE_NAME = "profile.db";
33 
34     // SQLite-standard table and columns for tracking autoincrement sequences.
35     private static final String SEQUENCE_TABLE = "sqlite_sequence";
36     private static final String SEQUENCE_NAME = "name";
37     private static final String SEQUENCE_SEQ = "seq";
38 
39     private static ProfileDatabaseHelper sSingleton = null;
40 
41     /**
42      * Returns a new instance for unit tests.
43      */
44     @NeededForTesting
getNewInstanceForTest(Context context, String filename)45     public static ProfileDatabaseHelper getNewInstanceForTest(Context context, String filename) {
46         return new ProfileDatabaseHelper(context, filename, false, /* isTestInstance=*/ true);
47     }
48 
ProfileDatabaseHelper( Context context, String databaseName, boolean optimizationEnabled, boolean isTestInstance)49     private ProfileDatabaseHelper(
50             Context context, String databaseName, boolean optimizationEnabled,
51             boolean isTestInstance) {
52         super(context, databaseName, optimizationEnabled, isTestInstance);
53     }
54 
getInstance(Context context)55     public static synchronized ProfileDatabaseHelper getInstance(Context context) {
56         if (sSingleton == null) {
57             sSingleton = new ProfileDatabaseHelper(context, DATABASE_NAME, true,
58                     /* isTestInstance=*/ false);
59         }
60         return sSingleton;
61     }
62 
63     @Override
dbForProfile()64     protected int dbForProfile() {
65         return 1;
66     }
67 
68     @Override
initializeAutoIncrementSequences(SQLiteDatabase db)69     protected void initializeAutoIncrementSequences(SQLiteDatabase db) {
70         for (String table : Tables.SEQUENCE_TABLES) {
71             ContentValues values = new ContentValues();
72             values.put(SEQUENCE_NAME, table);
73             values.put(SEQUENCE_SEQ, Profile.MIN_ID);
74             db.insert(SEQUENCE_TABLE, null, values);
75         }
76     }
77 
78     @Override
postOnCreate()79     protected void postOnCreate() {
80     }
81 
82     @Override
setDatabaseCreationTime(SQLiteDatabase db)83     protected void setDatabaseCreationTime(SQLiteDatabase db) {
84         // We don't need the creation time for the profile DB.
85     }
86 
87     @Override
loadDatabaseCreationTime(SQLiteDatabase db)88     protected void loadDatabaseCreationTime(SQLiteDatabase db) {
89         // We don't need the creation time for the profile DB.
90     }
91 
92     @Override
startListeningToDeviceConfigUpdates()93     protected void startListeningToDeviceConfigUpdates() {
94         // Do nothing for the profile DB.
95     }
96 
97     @Override
updateUseStrictPhoneNumberComparison()98     protected void updateUseStrictPhoneNumberComparison() {
99         // Do nothing for the profile DB.
100     }
101 }
102