• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.SQLiteException;
20 
21 /**
22  * Provides {@link SQLiteDatabase} instances to ExoPlayer components, which may read and write
23  * tables prefixed with {@link #TABLE_PREFIX}.
24  */
25 public interface DatabaseProvider {
26 
27   /** Prefix for tables that can be read and written by ExoPlayer components. */
28   String TABLE_PREFIX = "ExoPlayer";
29 
30   /**
31    * Creates and/or opens a database that will be used for reading and writing.
32    *
33    * <p>Once opened successfully, the database is cached, so you can call this method every time you
34    * need to write to the database. Errors such as bad permissions or a full disk may cause this
35    * method to fail, but future attempts may succeed if the problem is fixed.
36    *
37    * @throws SQLiteException If the database cannot be opened for writing.
38    * @return A read/write database object.
39    */
getWritableDatabase()40   SQLiteDatabase getWritableDatabase();
41 
42   /**
43    * Creates and/or opens a database. This will be the same object returned by {@link
44    * #getWritableDatabase()} unless some problem, such as a full disk, requires the database to be
45    * opened read-only. In that case, a read-only database object will be returned. If the problem is
46    * fixed, a future call to {@link #getWritableDatabase()} may succeed, in which case the read-only
47    * database object will be closed and the read/write object will be returned in the future.
48    *
49    * <p>Once opened successfully, the database is cached, so you can call this method every time you
50    * need to read from the database.
51    *
52    * @throws SQLiteException If the database cannot be opened.
53    * @return A database object valid until {@link #getWritableDatabase()} is called.
54    */
getReadableDatabase()55   SQLiteDatabase getReadableDatabase();
56 }
57