use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.
the class LockSettingsStorageTests method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
mStorageDir = new File(getContext().getFilesDir(), "locksettings");
mDb = getContext().getDatabasePath("locksettings.db");
assertTrue(mStorageDir.exists() || mStorageDir.mkdirs());
assertTrue(FileUtils.deleteContents(mStorageDir));
assertTrue(!mDb.exists() || mDb.delete());
final Context ctx = getContext();
setContext(new ContextWrapper(ctx) {
@Override
public Object getSystemService(String name) {
if (USER_SERVICE.equals(name)) {
return new UserManager(ctx, null) {
@Override
public UserInfo getProfileParent(int userHandle) {
if (userHandle == 2) {
// User 2 is a profile of user 1.
return new UserInfo(1, "name", 0);
}
if (userHandle == 3) {
// User 3 is a profile of user 0.
return new UserInfo(0, "name", 0);
}
return null;
}
};
}
return super.getSystemService(name);
}
});
mStorage = new LockSettingsStorage(getContext(), new LockSettingsStorage.Callback() {
@Override
public void initialize(SQLiteDatabase db) {
mStorage.writeKeyValue(db, "initializedKey", "initialValue", 0);
}
}) {
@Override
String getLockPatternFilename(int userId) {
return new File(mStorageDir, super.getLockPatternFilename(userId).replace('/', '-')).getAbsolutePath();
}
@Override
String getLockPasswordFilename(int userId) {
return new File(mStorageDir, super.getLockPasswordFilename(userId).replace('/', '-')).getAbsolutePath();
}
@Override
String getChildProfileLockFile(int userId) {
return new File(mStorageDir, super.getChildProfileLockFile(userId).replace('/', '-')).getAbsolutePath();
}
};
}
use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.
the class DatabaseHelper method deleteKeyphraseSoundModel.
/**
* Deletes the sound model and associated keyphrases.
*/
public boolean deleteKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale) {
// Sanitize the locale to guard against SQL injection.
bcp47Locale = Locale.forLanguageTag(bcp47Locale).toLanguageTag();
synchronized (this) {
KeyphraseSoundModel soundModel = getKeyphraseSoundModel(keyphraseId, userHandle, bcp47Locale);
if (soundModel == null) {
return false;
}
// Delete all sound models for the given keyphrase and specified user.
SQLiteDatabase db = getWritableDatabase();
String soundModelClause = SoundModelContract.KEY_MODEL_UUID + "='" + soundModel.uuid.toString() + "'";
try {
return db.delete(SoundModelContract.TABLE, soundModelClause, null) != 0;
} finally {
db.close();
}
}
}
use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.
the class SoundTriggerDbHelper method deleteGenericSoundModel.
public boolean deleteGenericSoundModel(UUID model_uuid) {
synchronized (this) {
GenericSoundModel soundModel = getGenericSoundModel(model_uuid);
if (soundModel == null) {
return false;
}
// Delete all sound models for the given keyphrase and specified user.
SQLiteDatabase db = getWritableDatabase();
String soundModelClause = GenericSoundModelContract.KEY_MODEL_UUID + "='" + soundModel.uuid.toString() + "'";
try {
return db.delete(GenericSoundModelContract.TABLE, soundModelClause, null) != 0;
} finally {
db.close();
}
}
}
use of android.database.sqlite.SQLiteDatabase in project android-topeka by googlesamples.
the class TopekaDatabaseHelper method reset.
/**
* Resets the contents of Topeka's database to it's initial state.
*
* @param context The context this is running in.
*/
public static void reset(Context context) {
SQLiteDatabase writableDatabase = getWritableDatabase(context);
writableDatabase.delete(CategoryTable.NAME, null, null);
writableDatabase.delete(QuizTable.NAME, null, null);
getInstance(context).preFillDatabase(writableDatabase);
}
use of android.database.sqlite.SQLiteDatabase in project android-topeka by googlesamples.
the class TopekaDatabaseHelper method updateCategory.
/**
* Updates values for a category.
*
* @param context The context this is running in.
* @param category The category to update.
*/
public static void updateCategory(Context context, Category category) {
if (mCategories != null && mCategories.contains(category)) {
final int location = mCategories.indexOf(category);
mCategories.remove(location);
mCategories.add(location, category);
}
SQLiteDatabase writableDatabase = getWritableDatabase(context);
ContentValues categoryValues = createContentValuesFor(category);
writableDatabase.update(CategoryTable.NAME, categoryValues, CategoryTable.COLUMN_ID + "=?", new String[] { category.getId() });
final List<Quiz> quizzes = category.getQuizzes();
updateQuizzes(writableDatabase, quizzes);
}
Aggregations