Search in sources :

Example 26 with SQLiteException

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) {
    }
}
Also used : ContentValues(android.content.ContentValues) SQLiteException(android.database.sqlite.SQLiteException) Uri(android.net.Uri)

Example 27 with SQLiteException

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));
    }
}
Also used : JsonRpcError(com.facebook.stetho.inspector.jsonrpc.protocol.JsonRpcError) SQLiteException(android.database.sqlite.SQLiteException) JsonRpcException(com.facebook.stetho.inspector.jsonrpc.JsonRpcException) ChromeDevtoolsMethod(com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod)

Example 28 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 29 with SQLiteException

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;
}
Also used : Cursor(android.database.Cursor) SQLiteException(android.database.sqlite.SQLiteException)

Example 30 with SQLiteException

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());
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) FileWriter(java.io.FileWriter) SQLiteDiskIOException(android.database.sqlite.SQLiteDiskIOException) SQLiteException(android.database.sqlite.SQLiteException) BufferedWriter(java.io.BufferedWriter)

Aggregations

SQLiteException (android.database.sqlite.SQLiteException)100 Cursor (android.database.Cursor)64 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)33 ContentValues (android.content.ContentValues)10 File (java.io.File)9 HashMap (java.util.HashMap)8 Account (android.accounts.Account)7 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)7 SyncStatusInfo (android.content.SyncStatusInfo)6 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)6 BufferedWriter (java.io.BufferedWriter)6 FileWriter (java.io.FileWriter)6 Uri (android.net.Uri)5 SuppressLint (android.annotation.SuppressLint)4 ArrayList (java.util.ArrayList)4 SQLiteStatement (android.database.sqlite.SQLiteStatement)3 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)3 SingleResultSet (io.requery.android.sqlite.SingleResultSet)3 Date (java.util.Date)3 SQLiteDoneException (android.database.sqlite.SQLiteDoneException)2