Search in sources :

Example 71 with SQLiteDatabase

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();
        }
    };
}
Also used : Context(android.content.Context) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) UserManager(android.os.UserManager) UserInfo(android.content.pm.UserInfo) File(java.io.File) ContextWrapper(android.content.ContextWrapper)

Example 72 with SQLiteDatabase

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();
        }
    }
}
Also used : KeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 73 with SQLiteDatabase

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();
        }
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 74 with SQLiteDatabase

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

Example 75 with SQLiteDatabase

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);
}
Also used : ContentValues(android.content.ContentValues) AlphaPickerQuiz(com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz) Quiz(com.google.samples.apps.topeka.model.quiz.Quiz) MultiSelectQuiz(com.google.samples.apps.topeka.model.quiz.MultiSelectQuiz) FillTwoBlanksQuiz(com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz) FillBlankQuiz(com.google.samples.apps.topeka.model.quiz.FillBlankQuiz) TrueFalseQuiz(com.google.samples.apps.topeka.model.quiz.TrueFalseQuiz) SelectItemQuiz(com.google.samples.apps.topeka.model.quiz.SelectItemQuiz) ToggleTranslateQuiz(com.google.samples.apps.topeka.model.quiz.ToggleTranslateQuiz) PickerQuiz(com.google.samples.apps.topeka.model.quiz.PickerQuiz) FourQuarterQuiz(com.google.samples.apps.topeka.model.quiz.FourQuarterQuiz) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Aggregations

SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1658 Cursor (android.database.Cursor)527 ContentValues (android.content.ContentValues)350 ArrayList (java.util.ArrayList)111 File (java.io.File)65 Test (org.junit.Test)59 SQLiteException (android.database.sqlite.SQLiteException)48 SQLException (android.database.SQLException)44 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)44 Uri (android.net.Uri)44 IOException (java.io.IOException)43 ServiceStatus (com.vodafone360.people.service.ServiceStatus)42 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)38 RemoteException (android.os.RemoteException)36 Pair (android.util.Pair)31 MediumTest (android.test.suitebuilder.annotation.MediumTest)30 Account (android.accounts.Account)29 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)25 ContactDetail (com.vodafone360.people.datatypes.ContactDetail)22 HashMap (java.util.HashMap)21