Home | History | Annotate | Download | only in database
      1 /*
      2  * Copyright (C) 2017 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.dialer.phonelookup.database;
     18 
     19 import android.content.Context;
     20 import android.database.sqlite.SQLiteDatabase;
     21 import android.database.sqlite.SQLiteOpenHelper;
     22 import android.os.SystemClock;
     23 import com.android.dialer.common.LogUtil;
     24 import com.android.dialer.phonelookup.database.contract.PhoneLookupHistoryContract.PhoneLookupHistory;
     25 
     26 /** {@link SQLiteOpenHelper} for the PhoneLookupHistory database. */
     27 class PhoneLookupHistoryDatabaseHelper extends SQLiteOpenHelper {
     28 
     29   PhoneLookupHistoryDatabaseHelper(Context appContext) {
     30     super(appContext, "phone_lookup_history.db", null, 1);
     31   }
     32 
     33   // TODO(zachh): LAST_MODIFIED is no longer read and can be deleted.
     34   private static final String CREATE_TABLE_SQL =
     35       "create table if not exists "
     36           + PhoneLookupHistory.TABLE
     37           + " ("
     38           + (PhoneLookupHistory.NORMALIZED_NUMBER + " text primary key not null, ")
     39           + (PhoneLookupHistory.PHONE_LOOKUP_INFO + " blob not null, ")
     40           + (PhoneLookupHistory.LAST_MODIFIED + " long not null")
     41           + ");";
     42 
     43   private static final String CREATE_INDEX_ON_LAST_MODIFIED_SQL =
     44       "create index last_modified_index on "
     45           + PhoneLookupHistory.TABLE
     46           + " ("
     47           + PhoneLookupHistory.LAST_MODIFIED
     48           + ");";
     49 
     50   @Override
     51   public void onCreate(SQLiteDatabase db) {
     52     LogUtil.enterBlock("PhoneLookupHistoryDatabaseHelper.onCreate");
     53     long startTime = SystemClock.uptimeMillis();
     54     db.execSQL(CREATE_TABLE_SQL);
     55     db.execSQL(CREATE_INDEX_ON_LAST_MODIFIED_SQL);
     56     // TODO(zachh): Consider logging impression.
     57     LogUtil.i(
     58         "PhoneLookupHistoryDatabaseHelper.onCreate",
     59         "took: %dms",
     60         SystemClock.uptimeMillis() - startTime);
     61   }
     62 
     63   @Override
     64   public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
     65 }
     66