1 /* 2 * Copyright (C) 2019 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.car.dialer.storage; 18 19 import android.content.Context; 20 21 import androidx.room.Database; 22 import androidx.room.Room; 23 import androidx.room.RoomDatabase; 24 import androidx.room.TypeConverters; 25 26 /** Defines the database for the {@link FavoriteNumberEntity}s. */ 27 @Database(entities = {FavoriteNumberEntity.class}, exportSchema = false, version = 1) 28 @TypeConverters(CipherConverter.class) 29 public abstract class FavoriteNumberDatabase extends RoomDatabase { 30 31 /** Returns the data access object to interact with the favorite number database. */ favoriteNumberDao()32 public abstract FavoriteNumberDao favoriteNumberDao(); 33 34 private static volatile FavoriteNumberDatabase sFavoriteNumberDatabase; 35 getDatabase(final Context context)36 static FavoriteNumberDatabase getDatabase(final Context context) { 37 if (sFavoriteNumberDatabase == null) { 38 synchronized (FavoriteNumberDatabase.class) { 39 if (sFavoriteNumberDatabase == null) { 40 sFavoriteNumberDatabase = Room.databaseBuilder(context.getApplicationContext(), 41 FavoriteNumberDatabase.class, "favorite_number_database").build(); 42 } 43 } 44 } 45 return sFavoriteNumberDatabase; 46 } 47 } 48