Merge "Make DownloadBase public"
diff --git a/core/java/android/content/ContentValues.java b/core/java/android/content/ContentValues.java
index c04625d..75787cd 100644
--- a/core/java/android/content/ContentValues.java
+++ b/core/java/android/content/ContentValues.java
@@ -66,7 +66,7 @@
      * Creates a set of values copied from the given HashMap. This is used
      * by the Parcel unmarshalling code.
      *
-     * @param from the values to start with
+     * @param values the values to start with
      * {@hide}
      */
     private ContentValues(HashMap<String, Object> values) {
@@ -248,7 +248,7 @@
      */
     public String getAsString(String key) {
         Object value = mValues.get(key);
-        return value != null ? mValues.get(key).toString() : null;
+        return value != null ? value.toString() : null;
     }
 
     /**
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
index fb39ac0..2ad663d 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -301,18 +301,19 @@
              * enabled or disabled based on product resources.
              */
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
                 db.execSQL("DELETE FROM system WHERE name='"
                         + Settings.System.WINDOW_ANIMATION_SCALE + "'");
                 db.execSQL("DELETE FROM system WHERE name='"
                         + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadDefaultAnimationSettings(stmt);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 32;
         }
@@ -349,14 +350,15 @@
 
         if (upgradeVersion == 34) {
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
-                SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
+                stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
                         + " VALUES(?,?);");
                 loadSecure35Settings(stmt);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 35;
         }
@@ -391,15 +393,16 @@
 
         if (upgradeVersion == 37) {
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
-                SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+                stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
                         R.string.airplane_mode_toggleable_radios);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 38;
         }
@@ -440,18 +443,19 @@
              * All animations are now turned on by default!
              */
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
                 db.execSQL("DELETE FROM system WHERE name='"
                         + Settings.System.WINDOW_ANIMATION_SCALE + "'");
                 db.execSQL("DELETE FROM system WHERE name='"
                         + Settings.System.TRANSITION_ANIMATION_SCALE + "'");
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadDefaultAnimationSettings(stmt);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 41;
         }
@@ -461,16 +465,17 @@
              * Initialize newly public haptic feedback setting
              */
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
                 db.execSQL("DELETE FROM system WHERE name='"
                         + Settings.System.HAPTIC_FEEDBACK_ENABLED + "'");
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadDefaultHapticSettings(stmt);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 42;
         }
@@ -480,15 +485,16 @@
              * Initialize new notification pulse setting
              */
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
                         R.bool.def_notification_pulse);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 43;
         }
@@ -498,15 +504,16 @@
              * This upgrade stores bluetooth volume separately from voice volume
              */
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
-                SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+                stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadSetting(stmt, Settings.System.VOLUME_BLUETOOTH_SCO,
                         AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
             upgradeVersion = 44;
         }
@@ -585,14 +592,15 @@
             * New settings for new user interface noises.
             */
            db.beginTransaction();
+           SQLiteStatement stmt = null;
            try {
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadUISoundEffectsSettings(stmt);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
 
            upgradeVersion = 50;
@@ -603,15 +611,16 @@
             * New settings for set install location UI.
             */
            db.beginTransaction();
+           SQLiteStatement stmt = null;
            try {
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadBooleanSetting(stmt, Settings.System.SET_INSTALL_LOCATION,
                         R.bool.set_install_location);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
 
            upgradeVersion = 51;
@@ -637,15 +646,16 @@
         if (upgradeVersion == 52) {
             // new vibration/silent mode settings
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
-                SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                stmt = db.compileStatement("INSERT INTO system(name,value)"
                         + " VALUES(?,?);");
                 loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
                         R.bool.def_vibrate_in_silent);
-                stmt.close();
                 db.setTransactionSuccessful();
             } finally {
                 db.endTransaction();
+                if (stmt != null) stmt.close();
             }
 
             upgradeVersion = 53;
@@ -656,15 +666,16 @@
              * New settings for set install location UI.
              */
             db.beginTransaction();
+            SQLiteStatement stmt = null;
             try {
-                 SQLiteStatement stmt = db.compileStatement("INSERT INTO system(name,value)"
+                 stmt = db.compileStatement("INSERT INTO system(name,value)"
                          + " VALUES(?,?);");
                  loadIntegerSetting(stmt, Settings.System.DEFAULT_INSTALL_LOCATION,
                          R.integer.def_install_location);
-                 stmt.close();
                  db.setTransactionSuccessful();
              } finally {
                  db.endTransaction();
+                 if (stmt != null) stmt.close();
              }
 
             upgradeVersion = 54;
@@ -844,47 +855,50 @@
      * @param db the database to insert the volume levels into
      */
     private void loadVolumeLevels(SQLiteDatabase db) {
-        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
-                + " VALUES(?,?);");
-
-        loadSetting(stmt, Settings.System.VOLUME_MUSIC,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
-        loadSetting(stmt, Settings.System.VOLUME_RING,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
-        loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
-        loadSetting(
-                stmt,
-                Settings.System.VOLUME_VOICE,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
-        loadSetting(stmt, Settings.System.VOLUME_ALARM,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
-        loadSetting(
-                stmt,
-                Settings.System.VOLUME_NOTIFICATION,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
-        loadSetting(
-                stmt,
-                Settings.System.VOLUME_BLUETOOTH_SCO,
-                AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
-
-        loadSetting(stmt, Settings.System.MODE_RINGER,
-                AudioManager.RINGER_MODE_NORMAL);
-
-        loadVibrateSetting(db, false);
-
-        // By default, only the ring/notification and system streams are affected
-        loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
-                (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) |
-                (1 << AudioManager.STREAM_SYSTEM) | (1 << AudioManager.STREAM_SYSTEM_ENFORCED));
-
-        loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
-                ((1 << AudioManager.STREAM_MUSIC) |
-                 (1 << AudioManager.STREAM_RING) |
-                 (1 << AudioManager.STREAM_NOTIFICATION) |
-                 (1 << AudioManager.STREAM_SYSTEM)));
-
-        stmt.close();
+        SQLiteStatement stmt = null;
+        try {
+            stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+                    + " VALUES(?,?);");
+    
+            loadSetting(stmt, Settings.System.VOLUME_MUSIC,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_MUSIC]);
+            loadSetting(stmt, Settings.System.VOLUME_RING,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_RING]);
+            loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_SYSTEM]);
+            loadSetting(
+                    stmt,
+                    Settings.System.VOLUME_VOICE,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_VOICE_CALL]);
+            loadSetting(stmt, Settings.System.VOLUME_ALARM,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_ALARM]);
+            loadSetting(
+                    stmt,
+                    Settings.System.VOLUME_NOTIFICATION,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_NOTIFICATION]);
+            loadSetting(
+                    stmt,
+                    Settings.System.VOLUME_BLUETOOTH_SCO,
+                    AudioManager.DEFAULT_STREAM_VOLUME[AudioManager.STREAM_BLUETOOTH_SCO]);
+    
+            loadSetting(stmt, Settings.System.MODE_RINGER,
+                    AudioManager.RINGER_MODE_NORMAL);
+    
+            loadVibrateSetting(db, false);
+    
+            // By default, only the ring/notification and system streams are affected
+            loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
+                    (1 << AudioManager.STREAM_RING) | (1 << AudioManager.STREAM_NOTIFICATION) |
+                    (1 << AudioManager.STREAM_SYSTEM) | (1 << AudioManager.STREAM_SYSTEM_ENFORCED));
+    
+            loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
+                    ((1 << AudioManager.STREAM_MUSIC) |
+                     (1 << AudioManager.STREAM_RING) |
+                     (1 << AudioManager.STREAM_NOTIFICATION) |
+                     (1 << AudioManager.STREAM_SYSTEM)));
+        } finally {
+            if (stmt != null) stmt.close();
+        }
     }
 
     private void loadVibrateSetting(SQLiteDatabase db, boolean deleteOld) {
@@ -892,17 +906,21 @@
             db.execSQL("DELETE FROM system WHERE name='" + Settings.System.VIBRATE_ON + "'");
         }
 
-        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
-                + " VALUES(?,?);");
-
-        // Vibrate off by default for ringer, on for notification
-        int vibrate = 0;
-        vibrate = AudioService.getValueForVibrateSetting(vibrate,
-                AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
-        vibrate = AudioService.getValueForVibrateSetting(vibrate,
-                AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
-        loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
-        stmt.close();
+        SQLiteStatement stmt = null;
+        try {
+            stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+                    + " VALUES(?,?);");
+    
+            // Vibrate off by default for ringer, on for notification
+            int vibrate = 0;
+            vibrate = AudioService.getValueForVibrateSetting(vibrate,
+                    AudioManager.VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_ON);
+            vibrate = AudioService.getValueForVibrateSetting(vibrate,
+                    AudioManager.VIBRATE_TYPE_RINGER, AudioManager.VIBRATE_SETTING_OFF);
+            loadSetting(stmt, Settings.System.VIBRATE_ON, vibrate);
+        } finally {
+            if (stmt != null) stmt.close();
+        }
     }
 
     private void loadSettings(SQLiteDatabase db) {
@@ -911,69 +929,72 @@
     }
 
     private void loadSystemSettings(SQLiteDatabase db) {
-        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
-                + " VALUES(?,?);");
-
-        loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
-                R.bool.def_dim_screen);
-        loadSetting(stmt, Settings.System.STAY_ON_WHILE_PLUGGED_IN,
-                "1".equals(SystemProperties.get("ro.kernel.qemu")) ? 1 : 0);
-        loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
-                R.integer.def_screen_off_timeout);
-
-        // Set default cdma emergency tone
-        loadSetting(stmt, Settings.System.EMERGENCY_TONE, 0);
-
-        // Set default cdma call auto retry
-        loadSetting(stmt, Settings.System.CALL_AUTO_RETRY, 0);
-
-        // 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);
-
-        loadBooleanSetting(stmt, Settings.System.AIRPLANE_MODE_ON,
-                R.bool.def_airplane_mode_on);
-
-        loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_RADIOS,
-                R.string.def_airplane_mode_radios);
-
-        loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
-                R.string.airplane_mode_toggleable_radios);
-
-        loadBooleanSetting(stmt, Settings.System.AUTO_TIME,
-                R.bool.def_auto_time); // Sync time to NITZ
-
-        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);
-        loadBooleanSetting(stmt, Settings.System.SET_INSTALL_LOCATION,
-                R.bool.set_install_location);
-        loadIntegerSetting(stmt, Settings.System.DEFAULT_INSTALL_LOCATION,
-                R.integer.def_install_location);
-
-        loadUISoundEffectsSettings(stmt);
-
-        loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
-                R.bool.def_vibrate_in_silent);
-
-        stmt.close();
+        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);
+            loadSetting(stmt, Settings.System.STAY_ON_WHILE_PLUGGED_IN,
+                    "1".equals(SystemProperties.get("ro.kernel.qemu")) ? 1 : 0);
+            loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
+                    R.integer.def_screen_off_timeout);
+    
+            // Set default cdma emergency tone
+            loadSetting(stmt, Settings.System.EMERGENCY_TONE, 0);
+    
+            // Set default cdma call auto retry
+            loadSetting(stmt, Settings.System.CALL_AUTO_RETRY, 0);
+    
+            // 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);
+    
+            loadBooleanSetting(stmt, Settings.System.AIRPLANE_MODE_ON,
+                    R.bool.def_airplane_mode_on);
+    
+            loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_RADIOS,
+                    R.string.def_airplane_mode_radios);
+    
+            loadStringSetting(stmt, Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
+                    R.string.airplane_mode_toggleable_radios);
+    
+            loadBooleanSetting(stmt, Settings.System.AUTO_TIME,
+                    R.bool.def_auto_time); // Sync time to NITZ
+    
+            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);
+            loadBooleanSetting(stmt, Settings.System.SET_INSTALL_LOCATION,
+                    R.bool.set_install_location);
+            loadIntegerSetting(stmt, Settings.System.DEFAULT_INSTALL_LOCATION,
+                    R.integer.def_install_location);
+    
+            loadUISoundEffectsSettings(stmt);
+    
+            loadBooleanSetting(stmt, Settings.System.VIBRATE_IN_SILENT,
+                    R.bool.def_vibrate_in_silent);
+        } finally {
+            if (stmt != null) stmt.close();
+        }
     }
 
     private void loadUISoundEffectsSettings(SQLiteStatement stmt) {
@@ -1014,79 +1035,82 @@
     }
 
     private void loadSecureSettings(SQLiteDatabase db) {
-        SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
-                + " VALUES(?,?);");
-
-        loadBooleanSetting(stmt, Settings.Secure.BLUETOOTH_ON,
-                R.bool.def_bluetooth_on);
-
-        // Data roaming default, based on build
-        loadSetting(stmt, Settings.Secure.DATA_ROAMING,
-                "true".equalsIgnoreCase(
-                        SystemProperties.get("ro.com.android.dataroaming",
-                                "false")) ? 1 : 0);
-
-        loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
-                R.bool.def_install_non_market_apps);
-
-        loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
-                R.string.def_location_providers_allowed);
-
-        loadBooleanSetting(stmt, Settings.Secure.ASSISTED_GPS_ENABLED,
-                R.bool.assisted_gps_enabled);
-
-        loadIntegerSetting(stmt, Settings.Secure.NETWORK_PREFERENCE,
-                R.integer.def_network_preference);
-
-        loadBooleanSetting(stmt, Settings.Secure.USB_MASS_STORAGE_ENABLED,
-                R.bool.def_usb_mass_storage_enabled);
-
-        loadBooleanSetting(stmt, Settings.Secure.WIFI_ON,
-                R.bool.def_wifi_on);
-        loadBooleanSetting(stmt, Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
-                R.bool.def_networks_available_notification_on);
-
-        String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
-        if (!TextUtils.isEmpty(wifiWatchList)) {
-            loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
+        SQLiteStatement stmt = null;
+        try {
+            stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
+                    + " VALUES(?,?);");
+    
+            loadBooleanSetting(stmt, Settings.Secure.BLUETOOTH_ON,
+                    R.bool.def_bluetooth_on);
+    
+            // Data roaming default, based on build
+            loadSetting(stmt, Settings.Secure.DATA_ROAMING,
+                    "true".equalsIgnoreCase(
+                            SystemProperties.get("ro.com.android.dataroaming",
+                                    "false")) ? 1 : 0);
+    
+            loadBooleanSetting(stmt, Settings.Secure.INSTALL_NON_MARKET_APPS,
+                    R.bool.def_install_non_market_apps);
+    
+            loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
+                    R.string.def_location_providers_allowed);
+    
+            loadBooleanSetting(stmt, Settings.Secure.ASSISTED_GPS_ENABLED,
+                    R.bool.assisted_gps_enabled);
+    
+            loadIntegerSetting(stmt, Settings.Secure.NETWORK_PREFERENCE,
+                    R.integer.def_network_preference);
+    
+            loadBooleanSetting(stmt, Settings.Secure.USB_MASS_STORAGE_ENABLED,
+                    R.bool.def_usb_mass_storage_enabled);
+    
+            loadBooleanSetting(stmt, Settings.Secure.WIFI_ON,
+                    R.bool.def_wifi_on);
+            loadBooleanSetting(stmt, Settings.Secure.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+                    R.bool.def_networks_available_notification_on);
+    
+            String wifiWatchList = SystemProperties.get("ro.com.android.wifi-watchlist");
+            if (!TextUtils.isEmpty(wifiWatchList)) {
+                loadSetting(stmt, Settings.Secure.WIFI_WATCHDOG_WATCH_LIST, wifiWatchList);
+            }
+    
+            // Set the preferred network mode to 0 = Global, CDMA default
+            int type = SystemProperties.getInt("ro.telephony.default_network",
+                    RILConstants.PREFERRED_NETWORK_MODE);
+            loadSetting(stmt, Settings.Secure.PREFERRED_NETWORK_MODE, type);
+    
+            // Enable or disable Cell Broadcast SMS
+            loadSetting(stmt, Settings.Secure.CDMA_CELL_BROADCAST_SMS,
+                    RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
+    
+            // Set the preferred cdma subscription to 0 = Subscription from RUIM, when available
+            loadSetting(stmt, Settings.Secure.PREFERRED_CDMA_SUBSCRIPTION,
+                    RILConstants.PREFERRED_CDMA_SUBSCRIPTION);
+    
+            // Don't do this.  The SystemServer will initialize ADB_ENABLED from a
+            // persistent system property instead.
+            //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
+    
+            // Allow mock locations default, based on build
+            loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
+                    "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
+    
+            loadSecure35Settings(stmt);
+    
+            loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
+                    R.bool.def_mount_play_notification_snd);
+    
+            loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
+                    R.bool.def_mount_ums_autostart);
+    
+            loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
+                    R.bool.def_mount_ums_prompt);
+    
+            loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
+                    R.bool.def_mount_ums_notify_enabled);
+        } finally {
+            if (stmt != null) stmt.close();
         }
-
-        // Set the preferred network mode to 0 = Global, CDMA default
-        int type = SystemProperties.getInt("ro.telephony.default_network",
-                RILConstants.PREFERRED_NETWORK_MODE);
-        loadSetting(stmt, Settings.Secure.PREFERRED_NETWORK_MODE, type);
-
-        // Enable or disable Cell Broadcast SMS
-        loadSetting(stmt, Settings.Secure.CDMA_CELL_BROADCAST_SMS,
-                RILConstants.CDMA_CELL_BROADCAST_SMS_DISABLED);
-
-        // Set the preferred cdma subscription to 0 = Subscription from RUIM, when available
-        loadSetting(stmt, Settings.Secure.PREFERRED_CDMA_SUBSCRIPTION,
-                RILConstants.PREFERRED_CDMA_SUBSCRIPTION);
-
-        // Don't do this.  The SystemServer will initialize ADB_ENABLED from a
-        // persistent system property instead.
-        //loadSetting(stmt, Settings.Secure.ADB_ENABLED, 0);
-
-        // Allow mock locations default, based on build
-        loadSetting(stmt, Settings.Secure.ALLOW_MOCK_LOCATION,
-                "1".equals(SystemProperties.get("ro.allow.mock.location")) ? 1 : 0);
-
-        loadSecure35Settings(stmt);
-
-        loadBooleanSetting(stmt, Settings.Secure.MOUNT_PLAY_NOTIFICATION_SND,
-                R.bool.def_mount_play_notification_snd);
-
-        loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_AUTOSTART,
-                R.bool.def_mount_ums_autostart);
-
-        loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_PROMPT,
-                R.bool.def_mount_ums_prompt);
-
-        loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED,
-                R.bool.def_mount_ums_notify_enabled);
-
-        stmt.close();
     }
 
     private void loadSecure35Settings(SQLiteStatement stmt) {
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index a4703de..10920fa 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -100,6 +100,7 @@
         public static final int OpFailedMediaCorrupt           = 403;
         public static final int OpFailedVolNotMounted          = 404;
         public static final int OpFailedStorageBusy            = 405;
+        public static final int OpFailedStorageNotFound        = 406;
 
         /*
          * 600 series - Unsolicited broadcasts.
@@ -1290,21 +1291,22 @@
         waitForReady();
         warnOnNotMounted();
 
-        ArrayList<String> rsp = mConnector.doCommand("asec path " + id);
-
-        for (String line : rsp) {
-            String []tok = line.split(" ");
+        try {
+            ArrayList<String> rsp = mConnector.doCommand(String.format("asec path %s", id));
+            String []tok = rsp.get(0).split(" ");
             int code = Integer.parseInt(tok[0]);
-            if (code == VoldResponseCode.AsecPathResult) {
-                return tok[1];
+            if (code != VoldResponseCode.AsecPathResult) {
+                throw new IllegalStateException(String.format("Unexpected response code %d", code));
+            }
+            return tok[1];
+        } catch (NativeDaemonConnectorException e) {
+            int code = e.getCode();
+            if (code == VoldResponseCode.OpFailedStorageNotFound) {
+                throw new IllegalArgumentException(String.format("Container '%s' not found", id));
             } else {
-                Log.e(TAG, String.format("Unexpected response code %d", code));
-                return "";
+                throw new IllegalStateException(String.format("Unexpected response code %d", code));
             }
         }
-
-        Log.e(TAG, "Got an empty response");
-        return "";
     }
 
     public void finishMediaUpdate() {
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index f9e1963..28fcef8 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -9572,11 +9572,10 @@
        if (doGc) {
            Runtime.getRuntime().gc();
        }
-       // Delete any stale containers if needed.
+       // List stale containers.
        if (removeCids != null) {
            for (String cid : removeCids) {
-               Log.i(TAG, "Destroying stale container : " + cid);
-               PackageHelper.destroySdDir(cid);
+               Log.w(TAG, "Container " + cid + " is stale");
            }
        }
    }
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index 166b6b6..5e1b82f 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -91,7 +91,6 @@
     private static final String DNS_DEFAULT_SERVER2 = "4.2.2.2";
 
     private boolean mDunRequired;  // configuration info - must use DUN apn on 3g
-    private boolean mUseHiPri;
 
     private HierarchicalStateMachine mTetherMasterSM;
 
@@ -1052,13 +1051,12 @@
                 return false;
             }
             protected int turnOnMobileConnection() {
-                Log.d(TAG, "turnonMobileConnection with mUseHiPri="+mUseHiPri);
                 IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
                 IConnectivityManager service = IConnectivityManager.Stub.asInterface(b);
                 int retValue = Phone.APN_REQUEST_FAILED;
                 try {
                     retValue = service.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                            (mUseHiPri ? Phone.FEATURE_ENABLE_HIPRI : Phone.FEATURE_ENABLE_DUN),
+                            (mDunRequired ? Phone.FEATURE_ENABLE_DUN : Phone.FEATURE_ENABLE_HIPRI),
                             new Binder());
                 } catch (Exception e) {
                 }
@@ -1083,8 +1081,8 @@
                             IConnectivityManager.Stub.asInterface(b);
                     try {
                         service.stopUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
-                                (mUseHiPri ? Phone.FEATURE_ENABLE_HIPRI :
-                                             Phone.FEATURE_ENABLE_DUN));
+                                (mDunRequired? Phone.FEATURE_ENABLE_DUN :
+                                             Phone.FEATURE_ENABLE_HIPRI));
                     } catch (Exception e) {
                         return false;
                     }
@@ -1175,57 +1173,51 @@
                 IBinder b = ServiceManager.getService(Context.CONNECTIVITY_SERVICE);
                 IConnectivityManager cm = IConnectivityManager.Stub.asInterface(b);
                 mConnectionRequested = false;
-                mUseHiPri = false;
                 Log.d(TAG, "chooseUpstreamType(" + tryCell + "),  dunRequired ="
                         + mDunRequired + ", iface=" + iface);
-                if (mDunRequired) {
-                    // check if Dun is on
+                if (iface != null) {
                     try {
-                        NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE_DUN);
-                        if (info.isConnected()) {
-                            Log.d(TAG, "setting dun ifacename =" + iface);
-                            notifyTetheredOfNewIface(iface);
-                            // even if we're already connected - it may be somebody else's
-                            // refcount, so add our own
-                            turnOnMobileConnection();
-                        }
-                    } catch (RemoteException e) {
-                        Log.e(TAG, "RemoteException calling ConnectivityManager");
-                        notifyTetheredOfNewIface(null);
-                    }
-                    if (tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) {
-                        turnOnMobileConnection();
-                    }
-                } else {
-                    if (iface == null) {
-                        if (tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) {
-                            Log.d(TAG, "turning on hipri");
-                            mUseHiPri = true;
-                            turnOnMobileConnection(); // try to turn on hipri
-                        }
-
-                    } else {
-                        try {
+                        if (mDunRequired) {
+                            // check if Dun is on - we can use that
+                            NetworkInfo info = cm.getNetworkInfo(
+                                    ConnectivityManager.TYPE_MOBILE_DUN);
+                            if (info.isConnected()) {
+                                Log.d(TAG, "setting dun ifacename =" + iface);
+                                // even if we're already connected - it may be somebody else's
+                                // refcount, so add our own
+                                turnOnMobileConnection();
+                            } else {
+                                // verify the iface is not the default mobile - can't use that!
+                                info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
+                                if (info.isConnected()) {
+                                    iface = null; // can't accept this one
+                                }
+                            }
+                        } else {
                             Log.d(TAG, "checking if hipri brought us this connection");
                             NetworkInfo info = cm.getNetworkInfo(
                                     ConnectivityManager.TYPE_MOBILE_HIPRI);
                             if (info.isConnected()) {
                                 Log.d(TAG, "yes - hipri in use");
-                                mUseHiPri = true;
+                                // even if we're already connected - it may be sombody else's
+                                // refcount, so add our own
                                 turnOnMobileConnection();
                             }
-                        } catch (RemoteException e) {
-                            Log.e(TAG, "RemoteException calling ConnectivityManager");
                         }
-                        // we don't require Dun and have an iface that satisfies, so use it
-                        Log.d(TAG, "setting non-dun iface =" + iface);
-                        notifyTetheredOfNewIface(iface);
+                    } catch (RemoteException e) {
+                        Log.e(TAG, "RemoteException calling ConnectivityManager " + e);
+                        iface = null;
                     }
                 }
-                if (iface == null) {
+                // may have been set to null in the if above
+                if (iface == null ) {
+                    if (tryCell == TRY_TO_SETUP_MOBILE_CONNECTION) {
+                        turnOnMobileConnection();
+                    }
                     // wait for things to settle and retry
                     sendMessageDelayed(CMD_RETRY_UPSTREAM, UPSTREAM_SETTLE_TIME_MS);
                 }
+                notifyTetheredOfNewIface(iface);
             }
             protected void notifyTetheredOfNewIface(String ifaceName) {
                 Log.d(TAG, "notifying tethered with iface =" + ifaceName);
@@ -1240,7 +1232,6 @@
         class InitialState extends TetherMasterUtilState {
             @Override
             public void enter() {
-                mUseHiPri = false;
                 mConnectionRequested = false;
             }
             @Override
diff --git a/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java b/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java
index f2f7743..fa7b9ff 100755
--- a/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/AppCacheTest.java
@@ -136,9 +136,7 @@
         if(localLOGV || TRACKING) Log.i(TAG, "blks3="+blks3);
         verifyTestFiles1(cacheDir, "testtmpdir", 5);
     }
-    
-    // TODO: flaky test
-    // @LargeTest
+
     public void testFreeApplicationCacheSomeFiles() throws Exception {
         StatFs st = new StatFs("/data");
         long blks1 = getFreeStorageBlks(st);
diff --git a/tests/AndroidTests/src/com/android/unit_tests/AsecTests.java b/tests/AndroidTests/src/com/android/unit_tests/AsecTests.java
index 9aed363..9a75047 100755
--- a/tests/AndroidTests/src/com/android/unit_tests/AsecTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/AsecTests.java
@@ -259,6 +259,17 @@
         }
     }
 
+    public void testNonExistPath() {
+        IMountService ms = getMs();
+        try {
+            String path = ms.getSecureContainerPath("jparks.broke.it");
+            failStr(path);
+        } catch (IllegalArgumentException e) {
+        } catch (Exception e) {
+            failStr(e);
+        }
+    }
+
     public void testUnmountBusyContainer() {
         IMountService ms = getMs();
         try {
diff --git a/tests/LocationTracker/src/com/android/locationtracker/TrackerService.java b/tests/LocationTracker/src/com/android/locationtracker/TrackerService.java
index 5b75653..e2332bf 100644
--- a/tests/LocationTracker/src/com/android/locationtracker/TrackerService.java
+++ b/tests/LocationTracker/src/com/android/locationtracker/TrackerService.java
@@ -193,11 +193,11 @@
     }
 
     private boolean doDebugLogging() {
-        return getPreferences().getBoolean(DEBUG_PREF, true);
+        return getPreferences().getBoolean(DEBUG_PREF, false);
     }
 
     private boolean trackSignalStrength() {
-        return getPreferences().getBoolean(SIGNAL_PREF, true);
+        return getPreferences().getBoolean(SIGNAL_PREF, false);
     }
 
     private float getLocationMinDistance() {