1 /* 2 * Copyright (C) 2018 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 package com.google.android.exoplayer2.database; 17 18 import android.database.sqlite.SQLiteDatabase; 19 import android.database.sqlite.SQLiteOpenHelper; 20 21 /** A {@link DatabaseProvider} that provides instances obtained from a {@link SQLiteOpenHelper}. */ 22 public final class DefaultDatabaseProvider implements DatabaseProvider { 23 24 private final SQLiteOpenHelper sqliteOpenHelper; 25 26 /** 27 * @param sqliteOpenHelper An {@link SQLiteOpenHelper} from which to obtain database instances. 28 */ DefaultDatabaseProvider(SQLiteOpenHelper sqliteOpenHelper)29 public DefaultDatabaseProvider(SQLiteOpenHelper sqliteOpenHelper) { 30 this.sqliteOpenHelper = sqliteOpenHelper; 31 } 32 33 @Override getWritableDatabase()34 public SQLiteDatabase getWritableDatabase() { 35 return sqliteOpenHelper.getWritableDatabase(); 36 } 37 38 @Override getReadableDatabase()39 public SQLiteDatabase getReadableDatabase() { 40 return sqliteOpenHelper.getReadableDatabase(); 41 } 42 } 43