Search in sources :

Example 61 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseStatementTest method testStatementClearBindings.

@MediumTest
public void testStatementClearBindings() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num) VALUES (?)");
    for (long i = 0; i < 10; i++) {
        statement.bindLong(1, i);
        statement.clearBindings();
        statement.execute();
    }
    statement.close();
    Cursor c = mDatabase.query("test", null, null, null, null, null, "ROWID");
    int numCol = c.getColumnIndexOrThrow("num");
    assertTrue(c.moveToFirst());
    for (long i = 0; i < 10; i++) {
        assertTrue(c.isNull(numCol));
        c.moveToNext();
    }
    c.close();
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) Cursor(android.database.Cursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 62 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseStatementTest method testStatementMultiThreaded.

@MediumTest
public void testStatementMultiThreaded() throws Exception {
    mDatabase.execSQL("CREATE TABLE test (num INTEGER, str TEXT);");
    SQLiteStatement statement = mDatabase.compileStatement("INSERT INTO test (num, str) VALUES (?, ?)");
    StatementTestThread thread = new StatementTestThread(mDatabase, statement);
    thread.start();
    try {
        thread.join();
    } finally {
        statement.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 63 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseHelper method loadGlobalSettings.

private void loadGlobalSettings(SQLiteDatabase db) {
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)" + " VALUES(?,?);");
        // --- Previously in 'system'
        loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON, R.bool.def_airplane_mode_on);
        loadBooleanSetting(stmt, Settings.Global.THEATER_MODE_ON, R.bool.def_theater_mode_on);
        loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_RADIOS, R.string.def_airplane_mode_radios);
        loadStringSetting(stmt, Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS, R.string.airplane_mode_toggleable_radios);
        loadBooleanSetting(stmt, Settings.Global.ASSISTED_GPS_ENABLED, R.bool.assisted_gps_enabled);
        loadBooleanSetting(stmt, Settings.Global.AUTO_TIME, // Sync time to NITZ
        R.bool.def_auto_time);
        loadBooleanSetting(stmt, Settings.Global.AUTO_TIME_ZONE, // Sync timezone to NITZ
        R.bool.def_auto_time_zone);
        loadSetting(stmt, Settings.Global.STAY_ON_WHILE_PLUGGED_IN, ("1".equals(SystemProperties.get("ro.kernel.qemu")) || mContext.getResources().getBoolean(R.bool.def_stay_on_while_plugged_in)) ? 1 : 0);
        loadIntegerSetting(stmt, Settings.Global.WIFI_SLEEP_POLICY, R.integer.def_wifi_sleep_policy);
        loadSetting(stmt, Settings.Global.MODE_RINGER, AudioManager.RINGER_MODE_NORMAL);
        // --- Previously in 'secure'
        loadBooleanSetting(stmt, Settings.Global.PACKAGE_VERIFIER_ENABLE, R.bool.def_package_verifier_enable);
        loadBooleanSetting(stmt, Settings.Global.WIFI_ON, R.bool.def_wifi_on);
        loadBooleanSetting(stmt, Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON, R.bool.def_networks_available_notification_on);
        loadBooleanSetting(stmt, Settings.Global.BLUETOOTH_ON, R.bool.def_bluetooth_on);
        // Enable or disable Cell Broadcast SMS
        loadSetting(stmt, Settings.Global.CDMA_CELL_BROADCAST_SMS, RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
        // Data roaming default, based on build
        loadSetting(stmt, Settings.Global.DATA_ROAMING, "true".equalsIgnoreCase(SystemProperties.get("ro.com.android.dataroaming", "false")) ? 1 : 0);
        loadBooleanSetting(stmt, Settings.Global.DEVICE_PROVISIONED, R.bool.def_device_provisioned);
        final int maxBytes = mContext.getResources().getInteger(R.integer.def_download_manager_max_bytes_over_mobile);
        if (maxBytes > 0) {
            loadSetting(stmt, Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE, Integer.toString(maxBytes));
        }
        final int recommendedMaxBytes = mContext.getResources().getInteger(R.integer.def_download_manager_recommended_max_bytes_over_mobile);
        if (recommendedMaxBytes > 0) {
            loadSetting(stmt, Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE, Integer.toString(recommendedMaxBytes));
        }
        // Mobile Data default, based on build
        loadSetting(stmt, Settings.Global.MOBILE_DATA, "true".equalsIgnoreCase(SystemProperties.get("ro.com.android.mobiledata", "true")) ? 1 : 0);
        loadBooleanSetting(stmt, Settings.Global.NETSTATS_ENABLED, R.bool.def_netstats_enabled);
        loadBooleanSetting(stmt, Settings.Global.USB_MASS_STORAGE_ENABLED, R.bool.def_usb_mass_storage_enabled);
        loadIntegerSetting(stmt, Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT, R.integer.def_max_dhcp_retries);
        loadBooleanSetting(stmt, Settings.Global.WIFI_DISPLAY_ON, R.bool.def_wifi_display_on);
        loadStringSetting(stmt, Settings.Global.LOCK_SOUND, R.string.def_lock_sound);
        loadStringSetting(stmt, Settings.Global.UNLOCK_SOUND, R.string.def_unlock_sound);
        loadStringSetting(stmt, Settings.Global.TRUSTED_SOUND, R.string.def_trusted_sound);
        loadIntegerSetting(stmt, Settings.Global.POWER_SOUNDS_ENABLED, R.integer.def_power_sounds_enabled);
        loadStringSetting(stmt, Settings.Global.LOW_BATTERY_SOUND, R.string.def_low_battery_sound);
        loadIntegerSetting(stmt, Settings.Global.DOCK_SOUNDS_ENABLED, R.integer.def_dock_sounds_enabled);
        loadStringSetting(stmt, Settings.Global.DESK_DOCK_SOUND, R.string.def_desk_dock_sound);
        loadStringSetting(stmt, Settings.Global.DESK_UNDOCK_SOUND, R.string.def_desk_undock_sound);
        loadStringSetting(stmt, Settings.Global.CAR_DOCK_SOUND, R.string.def_car_dock_sound);
        loadStringSetting(stmt, Settings.Global.CAR_UNDOCK_SOUND, R.string.def_car_undock_sound);
        loadStringSetting(stmt, Settings.Global.WIRELESS_CHARGING_STARTED_SOUND, R.string.def_wireless_charging_started_sound);
        loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, R.integer.def_dock_audio_media_enabled);
        loadSetting(stmt, Settings.Global.SET_INSTALL_LOCATION, 0);
        loadSetting(stmt, Settings.Global.DEFAULT_INSTALL_LOCATION, PackageHelper.APP_INSTALL_AUTO);
        // Set default cdma emergency tone
        loadSetting(stmt, Settings.Global.EMERGENCY_TONE, 0);
        // Set default cdma call auto retry
        loadSetting(stmt, Settings.Global.CALL_AUTO_RETRY, 0);
        // Set the preferred network mode to target desired value or Default
        // value defined in RILConstants
        int type;
        type = RILConstants.PREFERRED_NETWORK_MODE;
        loadSetting(stmt, Settings.Global.PREFERRED_NETWORK_MODE, type);
        // Set the preferred cdma subscription source to target desired value or default
        // value defined in CdmaSubscriptionSourceManager
        type = SystemProperties.getInt("ro.telephony.default_cdma_sub", CdmaSubscriptionSourceManager.PREFERRED_CDMA_SUBSCRIPTION);
        loadSetting(stmt, Settings.Global.CDMA_SUBSCRIPTION_MODE, type);
        loadIntegerSetting(stmt, Settings.Global.LOW_BATTERY_SOUND_TIMEOUT, R.integer.def_low_battery_sound_timeout);
        loadIntegerSetting(stmt, Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, R.integer.def_wifi_scan_always_available);
        loadIntegerSetting(stmt, Global.HEADS_UP_NOTIFICATIONS_ENABLED, R.integer.def_heads_up_enabled);
        loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
        loadSetting(stmt, Settings.Global.ENHANCED_4G_MODE_ENABLED, ImsConfig.FeatureValueConstants.ON);
    /*
             * 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 64 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseHelper method loadVibrateSetting.

private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
    if (deleteOld) {
        db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
    }
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)" + " VALUES(?,?);");
        // Vibrate on by default for ringer, on for notification
        int vibrate = 0;
        vibrate = AudioSystem.getValueForVibrateSetting(vibrate, AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
        vibrate |= AudioSystem.getValueForVibrateSetting(vibrate, AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_ONLY_SILENT);
        loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
    } finally {
        if (stmt != null)
            stmt.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Example 65 with SQLiteStatement

use of android.database.sqlite.SQLiteStatement in project platform_frameworks_base by android.

the class DatabaseHelper method upgradeScreenTimeout.

private void upgradeScreenTimeout(SQLiteDatabase db) {
    // Change screen timeout to current default
    db.beginTransaction();
    SQLiteStatement stmt = null;
    try {
        stmt = db.compileStatement("INSERT OR REPLACE INTO system(name,value)" + " VALUES(?,?);");
        loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT, R.integer.def_screen_off_timeout);
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
        if (stmt != null)
            stmt.close();
    }
}
Also used : SQLiteStatement(android.database.sqlite.SQLiteStatement)

Aggregations

SQLiteStatement (android.database.sqlite.SQLiteStatement)252 Cursor (android.database.Cursor)62 MediumTest (android.test.suitebuilder.annotation.MediumTest)49 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)24 Test (org.junit.Test)22 SQLException (android.database.SQLException)21 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 SQLException (java.sql.SQLException)4 Timing (com.newsrob.util.Timing)3 ContactIdInfo (com.vodafone360.people.database.tables.ContactsTable.ContactIdInfo)3 IOException (java.io.IOException)3 Savepoint (java.sql.Savepoint)3 ContentValues (android.content.ContentValues)2