use of android.database.sqlite.SQLiteException in project Shuttle by timusus.
the class MusicService method saveBookmarkIfNeeded.
private void saveBookmarkIfNeeded() {
try {
if (isPodcast()) {
long pos = getPosition();
long bookmark = getBookmark();
long duration = getDuration();
if ((pos < bookmark && (pos + 10000) > bookmark) || (pos > bookmark && (pos - 10000) < bookmark)) {
// position, so don't update it.
return;
}
if (pos < 15000 || (pos + 10000) > duration) {
// If we're near the start or end, clear the bookmark
pos = 0;
}
// Write 'pos' to the bookmark field
ContentValues values = new ContentValues();
values.put(MediaStore.Audio.Media.BOOKMARK, pos);
Uri uri = ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, currentSong.id);
if (uri != null) {
getContentResolver().update(uri, values, null, null);
}
}
} catch (SQLiteException ignored) {
}
}
use of android.database.sqlite.SQLiteException in project stetho by facebook.
the class Database method getDatabaseTableNames.
@ChromeDevtoolsMethod
public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params) throws JsonRpcException {
GetDatabaseTableNamesRequest request = mObjectMapper.convertValue(params, GetDatabaseTableNamesRequest.class);
String databaseId = request.databaseId;
DatabaseDriver databaseDriver = getDatabasePeer(databaseId);
try {
GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse();
response.tableNames = databaseDriver.getTableNames(request.databaseId);
return response;
} catch (SQLiteException e) {
throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INVALID_REQUEST, e.toString(), null));
}
}
use of android.database.sqlite.SQLiteException in project android_frameworks_base by DirtyUnicorns.
the class DrmManagerClient method convertUriToPath.
/**
* This method expects uri in the following format
* content://media/<table_name>/<row_index> (or)
* file://sdcard/test.mp4
* http://test.com/test.mp4
*
* Here <table_name> shall be "video" or "audio" or "images"
* <row_index> the index of the content in given table
*/
private String convertUriToPath(Uri uri) {
String path = null;
if (null != uri) {
String scheme = uri.getScheme();
if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
path = uri.getPath();
} else if (scheme.equals("http")) {
path = uri.toString();
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
String[] projection = new String[] { MediaStore.MediaColumns.DATA };
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
throw new IllegalArgumentException("Given Uri could not be found" + " in media store");
}
int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(pathIndex);
} catch (SQLiteException e) {
throw new IllegalArgumentException("Given Uri is not formatted in a way " + "so that it can be found in media store.");
} finally {
if (null != cursor) {
cursor.close();
}
}
} else {
throw new IllegalArgumentException("Given Uri scheme is not supported");
}
}
return path;
}
use of android.database.sqlite.SQLiteException in project android_frameworks_base by AOSPA.
the class DrmManagerClient method convertUriToPath.
/**
* This method expects uri in the following format
* content://media/<table_name>/<row_index> (or)
* file://sdcard/test.mp4
* http://test.com/test.mp4
*
* Here <table_name> shall be "video" or "audio" or "images"
* <row_index> the index of the content in given table
*/
private String convertUriToPath(Uri uri) {
String path = null;
if (null != uri) {
String scheme = uri.getScheme();
if (null == scheme || scheme.equals("") || scheme.equals(ContentResolver.SCHEME_FILE)) {
path = uri.getPath();
} else if (scheme.equals("http")) {
path = uri.toString();
} else if (scheme.equals(ContentResolver.SCHEME_CONTENT)) {
String[] projection = new String[] { MediaStore.MediaColumns.DATA };
Cursor cursor = null;
try {
cursor = mContext.getContentResolver().query(uri, projection, null, null, null);
if (null == cursor || 0 == cursor.getCount() || !cursor.moveToFirst()) {
throw new IllegalArgumentException("Given Uri could not be found" + " in media store");
}
int pathIndex = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
path = cursor.getString(pathIndex);
} catch (SQLiteException e) {
throw new IllegalArgumentException("Given Uri is not formatted in a way " + "so that it can be found in media store.");
} finally {
if (null != cursor) {
cursor.close();
}
}
} else {
throw new IllegalArgumentException("Given Uri scheme is not supported");
}
}
return path;
}
use of android.database.sqlite.SQLiteException in project android_frameworks_base by AOSPA.
the class DatabaseErrorHandlerTest method testDatabaseIsCorrupt.
public void testDatabaseIsCorrupt() throws IOException {
mDatabase.execSQL("create table t (i int);");
// write junk into the database file
BufferedWriter writer = new BufferedWriter(new FileWriter(mDatabaseFile.getPath()));
writer.write("blah");
writer.close();
assertTrue(mDatabaseFile.exists());
// should trigger call to MyDatabaseCorruptionHandler.onCorruption
try {
mDatabase.execSQL("select * from t;");
fail("expected exception");
} catch (SQLiteDiskIOException e) {
// expected
if (mDatabaseFile.exists()) {
mDatabaseFile.delete();
}
} catch (SQLiteException e) {
}
// database file should be gone
assertFalse(mDatabaseFile.exists());
// after corruption handler is called, the database file should be free of
// database corruption
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(mDatabaseFile.getPath(), null, new MyDatabaseCorruptionHandler());
assertTrue(db.isDatabaseIntegrityOk());
}
Aggregations