use of android.database.sqlite.SQLiteException in project android_frameworks_base by ParanoidAndroid.
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 ParanoidAndroid.
the class SyncStorageEngine method readAndDeleteLegacyAccountInfoLocked.
/**
* Load sync engine state from the old syncmanager database, and then
* erase it. Note that we don't deal with pending operations, active
* sync, or history.
*/
private void readAndDeleteLegacyAccountInfoLocked() {
// Look for old database to initialize from.
File file = mContext.getDatabasePath("syncmanager.db");
if (!file.exists()) {
return;
}
String path = file.getPath();
SQLiteDatabase db = null;
try {
db = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) {
}
if (db != null) {
final boolean hasType = db.getVersion() >= 11;
// Copy in all of the status information, as well as accounts.
if (DEBUG_FILE)
Log.v(TAG, "Reading legacy sync accounts db");
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables("stats, status");
HashMap<String, String> map = new HashMap<String, String>();
map.put("_id", "status._id as _id");
map.put("account", "stats.account as account");
if (hasType) {
map.put("account_type", "stats.account_type as account_type");
}
map.put("authority", "stats.authority as authority");
map.put("totalElapsedTime", "totalElapsedTime");
map.put("numSyncs", "numSyncs");
map.put("numSourceLocal", "numSourceLocal");
map.put("numSourcePoll", "numSourcePoll");
map.put("numSourceServer", "numSourceServer");
map.put("numSourceUser", "numSourceUser");
map.put("lastSuccessSource", "lastSuccessSource");
map.put("lastSuccessTime", "lastSuccessTime");
map.put("lastFailureSource", "lastFailureSource");
map.put("lastFailureTime", "lastFailureTime");
map.put("lastFailureMesg", "lastFailureMesg");
map.put("pending", "pending");
qb.setProjectionMap(map);
qb.appendWhere("stats._id = status.stats_id");
Cursor c = qb.query(db, null, null, null, null, null, null);
while (c.moveToNext()) {
String accountName = c.getString(c.getColumnIndex("account"));
String accountType = hasType ? c.getString(c.getColumnIndex("account_type")) : null;
if (accountType == null) {
accountType = "com.google";
}
String authorityName = c.getString(c.getColumnIndex("authority"));
AuthorityInfo authority = this.getOrCreateAuthorityLocked(new Account(accountName, accountType), 0, /* legacy is single-user */
authorityName, -1, false);
if (authority != null) {
int i = mSyncStatus.size();
boolean found = false;
SyncStatusInfo st = null;
while (i > 0) {
i--;
st = mSyncStatus.valueAt(i);
if (st.authorityId == authority.ident) {
found = true;
break;
}
}
if (!found) {
st = new SyncStatusInfo(authority.ident);
mSyncStatus.put(authority.ident, st);
}
st.totalElapsedTime = getLongColumn(c, "totalElapsedTime");
st.numSyncs = getIntColumn(c, "numSyncs");
st.numSourceLocal = getIntColumn(c, "numSourceLocal");
st.numSourcePoll = getIntColumn(c, "numSourcePoll");
st.numSourceServer = getIntColumn(c, "numSourceServer");
st.numSourceUser = getIntColumn(c, "numSourceUser");
st.numSourcePeriodic = 0;
st.lastSuccessSource = getIntColumn(c, "lastSuccessSource");
st.lastSuccessTime = getLongColumn(c, "lastSuccessTime");
st.lastFailureSource = getIntColumn(c, "lastFailureSource");
st.lastFailureTime = getLongColumn(c, "lastFailureTime");
st.lastFailureMesg = c.getString(c.getColumnIndex("lastFailureMesg"));
st.pending = getIntColumn(c, "pending") != 0;
}
}
c.close();
// Retrieve the settings.
qb = new SQLiteQueryBuilder();
qb.setTables("settings");
c = qb.query(db, null, null, null, null, null, null);
while (c.moveToNext()) {
String name = c.getString(c.getColumnIndex("name"));
String value = c.getString(c.getColumnIndex("value"));
if (name == null)
continue;
if (name.equals("listen_for_tickles")) {
setMasterSyncAutomatically(value == null || Boolean.parseBoolean(value), 0);
} else if (name.startsWith("sync_provider_")) {
String provider = name.substring("sync_provider_".length(), name.length());
int i = mAuthorities.size();
while (i > 0) {
i--;
AuthorityInfo authority = mAuthorities.valueAt(i);
if (authority.authority.equals(provider)) {
authority.enabled = value == null || Boolean.parseBoolean(value);
authority.syncable = 1;
}
}
}
}
c.close();
db.close();
(new File(path)).delete();
}
}
use of android.database.sqlite.SQLiteException in project Anki-Android by Ramblurr.
the class MetaDB method getIntentInformation.
public static ArrayList<HashMap<String, String>> getIntentInformation(Context context) {
openDBIfClosed(context);
Cursor cursor = null;
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
try {
cursor = mMetaDb.query("intentInformation", new String[] { "id", "fields" }, null, null, null, null, "id");
while (cursor.moveToNext()) {
HashMap<String, String> item = new HashMap<String, String>();
item.put("id", Integer.toString(cursor.getInt(0)));
String fields = cursor.getString(1);
String[] split = Utils.splitFields(fields);
String source = null;
String target = null;
for (int i = 0; i < split.length; i++) {
if (source == null || source.length() == 0) {
source = split[i];
} else if (target == null || target.length() == 0) {
target = split[i];
} else {
break;
}
}
item.put("source", source);
item.put("target", target);
item.put("fields", fields);
list.add(item);
}
} catch (SQLiteException e) {
upgradeDB(mMetaDb, DATABASE_VERSION);
Log.e(AnkiDroidApp.TAG, "Error while querying intentInformation", e);
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return list;
}
use of android.database.sqlite.SQLiteException in project Anki-Android by Ramblurr.
the class MetaDB method storeWidgetStatus.
/**
* Stores the current state of the widget.
* <p>
* It replaces any stored state for the widget.
*
* @param decks an array of {@link DeckStatus} objects, one for each of the know decks.
*/
public static void storeWidgetStatus(Context context, DeckStatus[] decks) {
openDBIfClosed(context);
try {
mMetaDb.beginTransaction();
try {
// First clear all the existing content.
mMetaDb.execSQL("DELETE FROM widgetStatus");
for (DeckStatus deck : decks) {
mMetaDb.execSQL("INSERT INTO widgetStatus(deckId, deckName, newCards, lrnCards, dueCards, progress, eta) " + "VALUES (?, ?, ?, ?, ?, ?, ?)", new Object[] { deck.mDeckId, deck.mDeckName, deck.mNewCards, deck.mLrnCards, deck.mDueCards, deck.mProgress, deck.mEta });
}
mMetaDb.setTransactionSuccessful();
} finally {
mMetaDb.endTransaction();
}
} catch (IllegalStateException e) {
Log.e(AnkiDroidApp.TAG, "MetaDB.storeWidgetStatus: failed", e);
} catch (SQLiteException e) {
Log.e(AnkiDroidApp.TAG, "MetaDB.storeWidgetStatus: failed", e);
closeDB();
Log.i(AnkiDroidApp.TAG, "Trying to reset Widget: " + resetWidget(context));
}
}
use of android.database.sqlite.SQLiteException in project Anki-Android by Ramblurr.
the class MetaDB method getWidgetSmallStatus.
/**
* Return the current status of the widget.
*
* @return an int array, containing due, progress, eta
*/
public static int[] getWidgetSmallStatus(Context context) {
openDBIfClosed(context);
Cursor cursor = null;
try {
cursor = mMetaDb.query("smallWidgetStatus", new String[] { "progress", "left", "eta" }, null, null, null, null, null);
while (cursor.moveToNext()) {
return (new int[] { cursor.getInt(0), cursor.getInt(1), cursor.getInt(2) });
}
} catch (SQLiteException e) {
Log.e(AnkiDroidApp.TAG, "Error while querying widgetStatus", e);
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
return null;
}
Aggregations