/** * 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); } }
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; } }
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(); } } }
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(); } } }