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 17package com.android.providers.contacts; 18 19import android.content.ContentValues; 20import android.content.Context; 21import android.database.sqlite.SQLiteDatabase; 22import android.provider.ContactsContract.Profile; 23 24import 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 */ 29public 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 45 public static ProfileDatabaseHelper getNewInstanceForTest(Context context, String filename) { 46 return new ProfileDatabaseHelper(context, filename, false, /* isTestInstance=*/ true); 47 } 48 49 private ProfileDatabaseHelper( 50 Context context, String databaseName, boolean optimizationEnabled, 51 boolean isTestInstance) { 52 super(context, databaseName, optimizationEnabled, isTestInstance); 53 } 54 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 64 protected int dbForProfile() { 65 return 1; 66 } 67 68 @Override 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 79 protected void postOnCreate() { 80 } 81 82 @Override 83 protected void setDatabaseCreationTime(SQLiteDatabase db) { 84 // We don't need the creation time for the profile DB. 85 } 86 87 @Override 88 protected void loadDatabaseCreationTime(SQLiteDatabase db) { 89 // We don't need the creation time for the profile DB. 90 } 91} 92