Search in sources :

Example 26 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseHelper method loadSystemSettings.

private void loadSystemSettings(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" + " VALUES(?,?);");
        loadBooleanSetting(stmt, Settings.System.DIM_SCREEN, R.bool.def_dim_screen);
        loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, R.integer.def_screen_off_timeout);
        // Set default cdma DTMF type
        loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
        // Set default hearing aid
        loadSetting(stmt, Settings.System.HEARING_AID, 0);
        // Set default tty mode
        loadSetting(stmt, Settings.System.TTY_MODE, 0);
        loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS, R.integer.def_screen_brightness);
        loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE, R.bool.def_screen_brightness_automatic_mode);
        loadDefaultAnimationSettings(stmt);
        loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION, R.bool.def_accelerometer_rotation);
        loadDefaultHapticSettings(stmt);
        loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE, R.bool.def_notification_pulse);
        final boolean isShowPassword = mContext.getResources().getBoolean(R.bool.config_show_password_on);
        if (isShowPassword) {
            loadBooleanSetting(stmt, Settings.System.TEXT_SHOW_PASSWORD, R.bool.def_show_password_on);
        }
        loadUISoundEffectsSettings(stmt);
        loadIntegerSetting(stmt, Settings.System.POINTER_SPEED, R.integer.def_pointer_speed);
    /*
             * IMPORTANT: Do not add any more upgrade steps here as the global,
             * secure, and system settings are no longer stored in a database
             * but are kept in memory and persisted to XML.
             *
             * See: SettingsProvider.UpgradeController#onUpgradeLocked
             */
    } finally {
        if (stmt != null)
            stmt.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 27 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseHelper method movePrefixedSettingsToNewTable.

/**
     * Move any settings with the given prefixes from the source table to the
     * destination table.
     */
private void movePrefixedSettingsToNewTable(SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
    SQLiteStatement insertStmt = null;
    SQLiteStatement deleteStmt = null;
    db.beginTransaction();
    try {
        insertStmt = db.compileStatement("INSERT INTO " + destTable + " (name,value) SELECT name,value FROM " + sourceTable + " WHERE substr(name,0,?)=?");
        deleteStmt = db.compileStatement("DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
        for (String prefix : prefixesToMove) {
            insertStmt.bindLong(1, prefix.length() + 1);
            insertStmt.bindString(2, prefix);
            insertStmt.execute();
            deleteStmt.bindLong(1, prefix.length() + 1);
            deleteStmt.bindString(2, prefix);
            deleteStmt.execute();
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        if (insertStmt != null) {
            insertStmt.close();
        }
        if (deleteStmt != null) {
            deleteStmt.close();
        }
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 28 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseHelper method loadVibrateWhenRingingSetting.

private void loadVibrateWhenRingingSetting(SQLiteDatabase db) {
    // The default should be off. VIBRATE_SETTING_ONLY_SILENT should also be ignored here.
    // Phone app should separately check whether AudioManager#getRingerMode() returns
    // RINGER_MODE_VIBRATE, with which the device should vibrate anyway.
    int vibrateSetting = getIntValueFromSystem(db, Settings.System.VIBRATE_ON, AudioManager.VIBRATE_SETTING_OFF);
    boolean vibrateWhenRinging = ((vibrateSetting & 3) == AudioManager.VIBRATE_SETTING_ON);
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" + " VALUES(?,?);");
        loadSetting(stmt, Settings.System.VIBRATE_WHEN_RINGING, vibrateWhenRinging ? 1 : 0);
    } finally {
        if (stmt != null)
            stmt.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 29 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by ResurrectionRemix.

the class DatabaseHelper method loadVolumeLevels.

/**
     * Loads the default volume levels. It is actually inserting the index of
     * the volume array for each of the volume controls.
     *
     * @param db the database to insert the volume levels into
     */
private void loadVolumeLevels(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" + " VALUES(?,?);");
        loadSetting(stmt, Settings.System.VOLUME_MUSIC, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
        loadSetting(stmt, Settings.System.VOLUME_RING, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
        loadSetting(stmt, Settings.System.VOLUME_SYSTEM, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
        loadSetting(stmt, Settings.System.VOLUME_VOICE, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
        loadSetting(stmt, Settings.System.VOLUME_ALARM, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
        loadSetting(stmt, Settings.System.VOLUME_NOTIFICATION, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
        loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO, AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
        // By default:
        // - ringtones, notification, system and music streams are affected by ringer mode
        // on non voice capable devices (tablets)
        // - ringtones, notification and system streams are affected by ringer mode
        // on voice capable devices (phones)
        int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) | (1 << AudioManager.STREAM_SYSTEM) | (1 << AudioManager.STREAM_SYSTEM_ENFORCED);
        if (!mContext.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable)) {
            ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
        }
        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED, ringerModeAffectedStreams);
        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED, AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
    } finally {
        if (stmt != null)
            stmt.close();
    }
    loadVibrateWhenRingingSetting(db);
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 30 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project android_frameworks_base by DirtyUnicorns.

the class DatabaseStatementTest method testStatementStringBinding.

@MediumTest
public void testStatementStringBinding() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num TEXT);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (long i = 0; i < 10; i++) {
        statement.bindString(1, Long.toHexString(i));
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, null);
    int numCol = c.getColumnIndexOrThrow("num");
    c.moveToFirst();
    for (long i = 0; i < 10; i++) {
        String num = c.getString(numCol);
        assertEquals(Long.toHexString(i), num);
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)249 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 SQLException (android.database.SQLException)21 Test (org.junit.Test)20 Date (java.util.Date)12 TargetApi (android.annotation.TargetApi)8 SQLiteDoneException (android.database.sqlite.SQLiteDoneException)8 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)7 SdkSuppress (android.support.test.filters.SdkSuppress)7 ArrayList (java.util.ArrayList)5 SQLiteException (android.database.sqlite.SQLiteException)4 SQLiteFullException (android.database.sqlite.SQLiteFullException)4 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 ContentValues (android.content.ContentValues)2 VisibleForTesting (android.support.annotation.VisibleForTesting)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2