Java 类android.database.sqlite.SQLiteReadOnlyDatabaseException 实例源码

项目:Trebuchet    文件:IconCache.java   
/**
 * Updates {@param values} to contain versoning information and adds it to the DB.
 * @param values {@link ContentValues} containing icon & title
 */
private void addIconToDB(ContentValues values, ComponentName key,
        PackageInfo info, long userSerial) {
    values.put(IconDB.COLUMN_COMPONENT, key.flattenToString());
    values.put(IconDB.COLUMN_USER, userSerial);
    values.put(IconDB.COLUMN_LAST_UPDATED, info.lastUpdateTime);
    values.put(IconDB.COLUMN_VERSION, info.versionCode);
    try {
        mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values,
                SQLiteDatabase.CONFLICT_REPLACE);
    } catch (SQLiteReadOnlyDatabaseException e) {
        Log.e(TAG, "Can't add icon to read only db", e);
    }
}
项目:PEP---Notes    文件:DbHelper.java   
public SQLiteDatabase getDatabase(boolean forceWritable) {
    try {
        SQLiteDatabase db = getReadableDatabase();
        if (forceWritable && db.isReadOnly()) {
            throw new SQLiteReadOnlyDatabaseException("Required writable database, obtained read-only");
        }
        return db;
    } catch (IllegalStateException e) {
        return this.db;
    }
}
项目:LB-Launcher    文件:WidgetPreviewLoader.java   
public WidgetPreviewLoader(Context context) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    mContext = context;
    mAppIconSize = grid.iconSizePx;
    mIconCache = app.getIconCache();
    mManager = AppWidgetManagerCompat.getInstance(context);

    mDb = app.getWidgetPreviewCacheDb();

    SharedPreferences sp = context.getSharedPreferences(
            LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    final String lastVersionName = sp.getString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, null);
    final String versionName = android.os.Build.VERSION.INCREMENTAL;
    final boolean isLollipopOrGreater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
    if (!versionName.equals(lastVersionName)) {
        try {
            // clear all the previews whenever the system version changes, to ensure that
            // previews are up-to-date for any apps that might have been updated with the system
            clearDb();
        } catch (SQLiteReadOnlyDatabaseException e) {
            if (isLollipopOrGreater) {
                // Workaround for Bug. 18554839, if we fail to clear the db due to the read-only
                // issue, then ignore this error and leave the old previews
            } else {
                throw e;
            }
        } finally {
            SharedPreferences.Editor editor = sp.edit();
            editor.putString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, versionName);
            editor.commit();
        }
    }
}
项目:LeanLauncher    文件:WidgetPreviewLoader.java   
public WidgetPreviewLoader(Context context) {
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    mContext = context;
    mAppIconSize = grid.iconSizePx;
    mIconCache = app.getIconCache();
    mManager = AppWidgetManagerCompat.getInstance(context);

    mDb = app.getWidgetPreviewCacheDb();

    SharedPreferences sp = context.getSharedPreferences(
            LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
    final String lastVersionName = sp.getString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, null);
    final String versionName = android.os.Build.VERSION.INCREMENTAL;
    if (!versionName.equals(lastVersionName)) {
        try {
            // clear all the previews whenever the system version changes, to ensure that
            // previews are up-to-date for any apps that might have been updated with the system
            clearDb();
        } catch (SQLiteReadOnlyDatabaseException e) {
            Log.e(TAG, "Error clearing widget preview db : " + e);
        } finally {
            SharedPreferences.Editor editor = sp.edit();
            editor.putString(ANDROID_INCREMENTAL_VERSION_NAME_KEY, versionName);
            editor.apply();
        }
    }
}