Merge "Allow external packages to open the RedactionInsterstitial." into lmp-dev
diff --git a/res/drawable-hdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-hdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..428b2f4
--- /dev/null
+++ b/res/drawable-hdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-hdpi/setup_illustration_tile.jpg b/res/drawable-hdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..ed6575c
--- /dev/null
+++ b/res/drawable-hdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-hdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-hdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..fccea72
--- /dev/null
+++ b/res/drawable-hdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-mdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..52e7993
--- /dev/null
+++ b/res/drawable-mdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_tile.jpg b/res/drawable-mdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..9dbe131
--- /dev/null
+++ b/res/drawable-mdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-mdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-mdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..f21dffb
--- /dev/null
+++ b/res/drawable-mdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-nodpi/setup_illustration_tile.png b/res/drawable-nodpi/setup_illustration_tile.png
deleted file mode 100644
index ae6d244..0000000
--- a/res/drawable-nodpi/setup_illustration_tile.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-nodpi/setup_illustration_wifi_image.jpg b/res/drawable-nodpi/setup_illustration_wifi_image.jpg
index 2579225..a27c93e 100644
--- a/res/drawable-nodpi/setup_illustration_wifi_image.jpg
+++ b/res/drawable-nodpi/setup_illustration_wifi_image.jpg
Binary files differ
diff --git a/res/drawable-nodpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-nodpi/setup_illustration_wifi_wide_image.jpg
deleted file mode 100644
index b876fa6..0000000
--- a/res/drawable-nodpi/setup_illustration_wifi_wide_image.jpg
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-xhdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..2733f8e
--- /dev/null
+++ b/res/drawable-xhdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_tile.jpg b/res/drawable-xhdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..71dabd5
--- /dev/null
+++ b/res/drawable-xhdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-xhdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-xhdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..3d1b3f3
--- /dev/null
+++ b/res/drawable-xhdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-xxhdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..aec8d0f
--- /dev/null
+++ b/res/drawable-xxhdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_tile.jpg b/res/drawable-xxhdpi/setup_illustration_tile.jpg
new file mode 100644
index 0000000..46b3d02
--- /dev/null
+++ b/res/drawable-xxhdpi/setup_illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-xxhdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-xxhdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..6a590b7
--- /dev/null
+++ b/res/drawable-xxhdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/illustration_tile.jpg b/res/drawable-xxxhdpi/illustration_tile.jpg
new file mode 100644
index 0000000..ab3899e
--- /dev/null
+++ b/res/drawable-xxxhdpi/illustration_tile.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/setup_illustration_horizontal_tile.jpg b/res/drawable-xxxhdpi/setup_illustration_horizontal_tile.jpg
new file mode 100644
index 0000000..448a651
--- /dev/null
+++ b/res/drawable-xxxhdpi/setup_illustration_horizontal_tile.jpg
Binary files differ
diff --git a/res/drawable-xxxhdpi/setup_illustration_wifi_wide_image.jpg b/res/drawable-xxxhdpi/setup_illustration_wifi_wide_image.jpg
new file mode 100644
index 0000000..d6f2f82
--- /dev/null
+++ b/res/drawable-xxxhdpi/setup_illustration_wifi_wide_image.jpg
Binary files differ
diff --git a/res/drawable/setup_illustration_wifi_wide.xml b/res/drawable/setup_illustration_wifi_wide.xml
index 3af3561..33ee2f6 100644
--- a/res/drawable/setup_illustration_wifi_wide.xml
+++ b/res/drawable/setup_illustration_wifi_wide.xml
@@ -15,6 +15,19 @@
      limitations under the License.
 -->
 
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
-    android:autoMirrored="true"
-    android:src="@drawable/setup_illustration_wifi_wide_image" />
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
+    android:autoMirrored="true">
+
+    <item>
+        <bitmap android:src="@drawable/setup_illustration_horizontal_tile"
+            android:gravity="top"
+            android:tileModeX="repeat"
+            android:tileModeY="disabled" />
+    </item>
+
+    <item android:id="@+id/illustration_image">
+        <bitmap android:src="@drawable/setup_illustration_wifi_wide_image"
+            android:gravity="top|start" />
+    </item>
+
+</layer-list>
\ No newline at end of file
diff --git a/res/layout-land/setup_preference.xml b/res/layout-land/setup_preference.xml
index b2e1cc7..ce655d6 100644
--- a/res/layout-land/setup_preference.xml
+++ b/res/layout-land/setup_preference.xml
@@ -33,13 +33,14 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:text="@string/wifi_setup_wizard_title" />
+
     </FrameLayout>
 
     <TextView
         android:id="@+id/wifi_required_info"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:layout_marginBottom="6dip"
+        android:layout_marginBottom="6dp"
         android:textAppearance="?android:attr/textAppearanceMedium"
         android:text="@string/wifi_required_info_text"
         android:visibility="gone" />
diff --git a/res/layout-sw600dp-land/setup_preference.xml b/res/layout-sw600dp-land/setup_preference.xml
index 3d4db3d..431ac29 100644
--- a/res/layout-sw600dp-land/setup_preference.xml
+++ b/res/layout-sw600dp-land/setup_preference.xml
@@ -37,13 +37,14 @@
             <TextView
                 android:id="@+id/title"
                 style="@style/SetupCardTitle"
-                android:layout_width="0dp"
+                android:layout_width="1dp"
                 android:layout_height="wrap_content"
+                android:layout_marginTop="@dimen/setup_wizard_tablet_illustration_height"
                 android:layout_weight="6"
                 android:text="@string/wifi_setup_wizard_title"/>
 
             <LinearLayout
-                android:layout_width="0dp"
+                android:layout_width="1dp"
                 android:layout_height="match_parent"
                 android:layout_marginTop="@dimen/setup_wizard_card_land_margin_top"
                 android:layout_weight="8"
diff --git a/res/layout-sw720dp-port/setup_preference.xml b/res/layout-sw600dp/setup_preference.xml
similarity index 94%
rename from res/layout-sw720dp-port/setup_preference.xml
rename to res/layout-sw600dp/setup_preference.xml
index 8d1f53b..1e772d9 100644
--- a/res/layout-sw720dp-port/setup_preference.xml
+++ b/res/layout-sw600dp/setup_preference.xml
@@ -15,9 +15,7 @@
     limitations under the License.
 -->
 
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
@@ -28,12 +26,12 @@
         android:layout_height="0dp"
         android:layout_weight="1"
         android:background="@drawable/setup_illustration_bg"
-        android:foreground="@drawable/setup_illustration_wifi_wide"
-        settings:aspectRatio="4.0">
+        android:foreground="@drawable/setup_illustration_wifi_wide">
 
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="match_parent"
+            android:layout_marginTop="@dimen/setup_wizard_tablet_illustration_height"
             android:orientation="vertical"
             android:paddingLeft="@dimen/setup_wizard_card_port_margin_sides"
             android:paddingRight="@dimen/setup_wizard_card_port_margin_sides">
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
index 1aa4b55..5f524af 100755
--- a/res/values-land/dimens.xml
+++ b/res/values-land/dimens.xml
@@ -45,7 +45,6 @@
     <!-- Dashboard tile image margin start / end -->
     <dimen name="dashboard_tile_image_margin_start">12dp</dimen>
 
-    <dimen name="setup_wizard_card_title_margin_top">256dp</dimen>
     <dimen name="setup_wizard_card_title_padding_end">32dp</dimen>
     <dimen name="setup_wizard_card_title_padding_start">56dp</dimen>
     <dimen name="setup_wizard_card_title_padding_top">24dp</dimen>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 18306ca..fcfd5bc 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -50,7 +50,7 @@
     <dimen name="setup_add_network_item_height">56dp</dimen>
     <dimen name="setup_wizard_card_corner_radius">2dp</dimen>
     <dimen name="setup_wizard_card_elevation">5dp</dimen>
-    <dimen name="setup_wizard_card_title_margin_top">0dp</dimen>
+    <dimen name="setup_wizard_tablet_illustration_height">256dp</dimen>
     <dimen name="setup_wizard_card_title_padding_end">0dp</dimen>
     <dimen name="setup_wizard_card_title_padding_start">0dp</dimen>
     <dimen name="setup_wizard_card_title_padding_top">16dp</dimen>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2377fe4..d75824e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1273,7 +1273,7 @@
     <string name="bluetooth_device_advanced_online_mode_title">Connect</string>
     <!-- Bluetooth settings.  Connection options screen.  The summary of the online mode checkbox.  This describes what the setting does in the context of the screen. -->
     <string name="bluetooth_device_advanced_online_mode_summary">Connect to Bluetooth device</string>
-    <!-- Bluetooth settings.  Connection options screen.  The title of the header that is above all of the profiles. 
+    <!-- Bluetooth settings.  Connection options screen.  The title of the header that is above all of the profiles.
          When a user decides what Bluetooth capabilities to use with the device.  -->
     <string name="bluetooth_device_advanced_profile_header_title">Use for</string>
     <!-- Bluetooth settings. Connection options screen. Title for option to rename the device. [CHAR LIMIT=30] -->
@@ -2493,6 +2493,10 @@
     <string name="master_clear_confirm_title">Reset?</string>
     <!-- Error message for users that aren't allowed to factory reset [CHAR LIMIT=none] -->
     <string name="master_clear_not_available">Factory reset is not available for this user</string>
+    <!-- Master clear progress screen title [CHAR LIMIT=30] -->
+    <string name="master_clear_progress_title" >Erasing</string>
+    <!-- Master clear progress screen text [CHAR LIMIT=75] -->
+    <string name="master_clear_progress_text">Please wait...</string>
 
     <!-- Media Format -->
     <!-- SD card & phone storage settings screen, setting option name under Internal phone storage heading [CHAR LIMIT=25] -->
@@ -4834,11 +4838,14 @@
     <string name="show_all_anrs_summary">Show App Not Responding dialog
         for background apps</string>
 
+    <!-- UI debug setting: webview data reduction proxy [CHAR LIMIT=100] -->
+    <string name="dev_settings_use_google_settings">Please use GoogleSettings app for this operation</string>
+
     <!-- UI debug setting: webview data reduction proxy [CHAR LIMIT=50] -->
     <string name="webview_data_reduction_proxy">Reduce WebView Network Usage</string>
     <!-- UI debug setting: webview data reduction proxy summary [CHAR LIMIT=200] -->
     <string name="webview_data_reduction_proxy_summary">Reduce network usage by
-        proxying WebView connections through Google compression servers (Experimental)</string>
+        proxying WebView connections through Google compression servers</string>
 
     <!-- Activity title for network data usage summary. [CHAR LIMIT=25] -->
     <string name="data_usage_summary_title">Data usage</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 3f5f39d..c3d2564 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -176,7 +176,6 @@
 
     <!-- Alternate title style used for some tablet layouts -->
     <style name="SetupCardTitle">
-        <item name="android:layout_marginTop">@dimen/setup_wizard_card_title_margin_top</item>
         <item name="android:paddingBottom">@dimen/setup_wizard_card_title_padding_bottom</item>
         <item name="android:paddingEnd">@dimen/setup_wizard_card_title_padding_end</item>
         <item name="android:paddingStart">@dimen/setup_wizard_card_title_padding_start</item>
diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java
index 2cffe28..d801ae0 100644
--- a/src/com/android/settings/DevelopmentSettings.java
+++ b/src/com/android/settings/DevelopmentSettings.java
@@ -31,7 +31,9 @@
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.pm.ResolveInfo;
+import android.database.Cursor;
 import android.hardware.usb.IUsbManager;
+import android.net.Uri;
 import android.net.wifi.WifiManager;
 import android.os.AsyncTask;
 import android.os.BatteryManager;
@@ -153,6 +155,9 @@
     private static final String SHOW_ALL_ANRS_KEY = "show_all_anrs";
 
     private static final String WEBVIEW_DATA_REDUCTION_PROXY_KEY = "webview_data_reduction_proxy";
+    // GoogleSetting name for the data reduction proxy setting.
+    // Setting type: int ( 0 = disallow, 1 = allow )
+    private static final String WEBVIEW_DATA_REDUCTION_PROXY = "use_webview_data_reduction_proxy";
 
     private static final String PROCESS_STATS = "proc_stats";
 
@@ -166,6 +171,11 @@
 
     private static final String PERSISTENT_DATA_BLOCK_PROP = "ro.frp.pst";
 
+    // The setting Uri. Used when querying GoogleSettings.
+    private static final Uri GOOGLE_SETTINGS_CONTENT_URI = Uri.parse("content://com.google.settings/partner");
+    private static final String GOOGLE_SETTINGS_COMPONENT = "com.google.android.gms";
+    private static final String GOOGLE_SETTINGS_ACTIVITY = ".app.settings.GoogleSettingsActivity";
+
     private static String DEFAULT_LOG_RING_BUFFER_SIZE_IN_BYTES = "262144"; // 256K
 
     private IWindowManager mWindowManager;
@@ -372,6 +382,13 @@
         mAllPrefs.add(mProcessStats);
 
         mWebViewDataReductionProxy = findAndInitCheckboxPref(WEBVIEW_DATA_REDUCTION_PROXY_KEY);
+        mWebViewDataReductionProxy.setOnPreferenceChangeListener(
+                new Preference.OnPreferenceChangeListener() {
+                    @Override
+                    public boolean onPreferenceChange(Preference preference, Object newValue) {
+                        return handleDataReductionProxyPreferenceChange();
+                    }
+                });
     }
 
     private ListPreference addListPreference(String prefKey) {
@@ -1277,6 +1294,50 @@
             getActivity().getContentResolver(), Settings.Secure.ANR_SHOW_BACKGROUND, 0) != 0);
     }
 
+    // Reads the googlesetting and converts to an int. Throws an exception if GoogleSettings
+    // provider does not exist or if the setting name cannot be found.
+    private int getGoogleSettingValue(String name) throws Exception {
+        String value = null;
+        Cursor c = null;
+        try {
+            ContentResolver resolver = getActivity().getContentResolver();
+            c = resolver.query(GOOGLE_SETTINGS_CONTENT_URI, new String[] { "value" },
+                    "name=?", new String[]{ name }, null);
+            if (c != null && c.moveToNext()) value = c.getString(0);
+        } finally {
+            if (c != null) c.close();
+        }
+        // Throw an exception if value is null. This will indicate that setting is not found.
+        return Integer.parseInt(value);
+    }
+
+    private boolean handleDataReductionProxyPreferenceChange() {
+        int val;
+        try {
+            val = getGoogleSettingValue(WEBVIEW_DATA_REDUCTION_PROXY);
+        } catch (Exception e) {
+            // Accessing GoogleSettings failed. Use the developer setting.
+            return true;
+        }
+
+        Intent i = new Intent();
+        i.setClassName(GOOGLE_SETTINGS_COMPONENT,
+                GOOGLE_SETTINGS_COMPONENT + GOOGLE_SETTINGS_ACTIVITY);
+        try {
+            startActivity(i);
+        } catch (android.content.ActivityNotFoundException ex) {
+            // We found the GoogleSetting but for some reason activity not found.
+            // Do our best and put an alert dialog
+            new AlertDialog.Builder(getActivity()).setMessage(
+                    getActivity().getResources().getString(
+                        R.string.dev_settings_use_google_settings))
+                        .setPositiveButton(android.R.string.ok, this)
+                        .show();
+        }
+        // Use GoogleSettings to set.
+        return false;
+    }
+
     private void writeWebViewDataReductionProxyOptions() {
         Settings.Secure.putInt(getActivity().getContentResolver(),
                 Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY,
@@ -1287,9 +1348,17 @@
     }
 
     private void updateWebViewDataReductionProxyOptions() {
-        updateCheckBox(mWebViewDataReductionProxy, Settings.Secure.getInt(
-                getActivity().getContentResolver(),
-                Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, 0) != 0);
+        int val = -1;
+        try {
+              val = getGoogleSettingValue(WEBVIEW_DATA_REDUCTION_PROXY);
+        } catch (Exception e) {
+            // Accessing GoogleSettings failed. Use the developer setting
+        }
+        if (val == -1) {
+            val = Settings.Secure.getInt(getActivity().getContentResolver(),
+                    Settings.Secure.WEBVIEW_DATA_REDUCTION_PROXY, 0);
+        }
+        updateCheckBox(mWebViewDataReductionProxy, val != 0);
     }
 
     @Override
diff --git a/src/com/android/settings/MasterClearConfirm.java b/src/com/android/settings/MasterClearConfirm.java
index d14ad39..0455d74 100644
--- a/src/com/android/settings/MasterClearConfirm.java
+++ b/src/com/android/settings/MasterClearConfirm.java
@@ -16,22 +16,21 @@
 
 package com.android.settings;
 
+import android.app.ProgressDialog;
 import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.os.AsyncTask;
 import android.service.persistentdata.PersistentDataBlockManager;
 import com.android.internal.os.storage.ExternalStorageFormatter;
-import com.android.internal.widget.LockPatternUtils;
 
-import android.app.Activity;
 import android.app.Fragment;
 import android.content.Intent;
-import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.UserManager;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
-import android.widget.CheckBox;
 
 /**
  * Confirm and execute a reset of the device to a clean "just out of the box"
@@ -47,7 +46,6 @@
 
     private View mContentView;
     private boolean mEraseSdCard;
-    private Button mFinalButton;
 
     /**
      * The user has gone through the multiple confirmation, so now we go ahead
@@ -61,33 +59,68 @@
                 return;
             }
 
-            PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
+            final PersistentDataBlockManager pdbManager = (PersistentDataBlockManager)
                     getActivity().getSystemService(Context.PERSISTENT_DATA_BLOCK_SERVICE);
 
             if (pdbManager != null) {
                 // if OEM unlock is enabled, this will be wiped during FR process.
                 if (!pdbManager.getOemUnlockEnabled()) {
-                    pdbManager.wipe();
-                }
-            }
+                    final ProgressDialog progressDialog = getProgressDialog();
+                    progressDialog.show();
 
-            if (mEraseSdCard) {
-                Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
-                intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
-                getActivity().startService(intent);
+                    // need to prevent orientation changes as we're about to go into
+                    // a long IO request, so we won't be able to access inflate resources on flash
+                    final int oldOrientation = getActivity().getRequestedOrientation();
+                    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
+                    new AsyncTask<Void, Void, Void>() {
+                        @Override
+                        protected Void doInBackground(Void... params) {
+                            pdbManager.wipe();
+                            return null;
+                        }
+
+                        @Override
+                        protected void onPostExecute(Void aVoid) {
+                            progressDialog.hide();
+                            getActivity().setRequestedOrientation(oldOrientation);
+                            doMasterClear();
+                        }
+                    }.execute();
+                }
             } else {
-                getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
-                // Intent handling is asynchronous -- assume it will happen soon.
+                doMasterClear();
             }
         }
+
+        private ProgressDialog getProgressDialog() {
+            final ProgressDialog progressDialog = new ProgressDialog(getActivity());
+            progressDialog.setIndeterminate(true);
+            progressDialog.setCancelable(false);
+            progressDialog.setTitle(
+                    getActivity().getString(R.string.master_clear_progress_title));
+            progressDialog.setMessage(
+                    getActivity().getString(R.string.master_clear_progress_text));
+            return progressDialog;
+        }
     };
 
+    private void doMasterClear() {
+        if (mEraseSdCard) {
+            Intent intent = new Intent(ExternalStorageFormatter.FORMAT_AND_FACTORY_RESET);
+            intent.setComponent(ExternalStorageFormatter.COMPONENT_NAME);
+            getActivity().startService(intent);
+        } else {
+            getActivity().sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
+            // Intent handling is asynchronous -- assume it will happen soon.
+        }
+    }
+
     /**
      * Configure the UI for the final confirmation interaction
      */
     private void establishFinalConfirmationState() {
-        mFinalButton = (Button) mContentView.findViewById(R.id.execute_master_clear);
-        mFinalButton.setOnClickListener(mFinalClickListener);
+        mContentView.findViewById(R.id.execute_master_clear)
+                .setOnClickListener(mFinalClickListener);
     }
 
     @Override
@@ -107,6 +140,6 @@
         super.onCreate(savedInstanceState);
 
         Bundle args = getArguments();
-        mEraseSdCard = args != null ? args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA) : false;
+        mEraseSdCard = args != null && args.getBoolean(MasterClear.ERASE_EXTERNAL_EXTRA);
     }
 }
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index ce3164d..ab7e28b 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -130,7 +130,7 @@
             // Check for carrier apps that can handle provisioning first
             Intent provisioningIntent = new Intent(TelephonyIntents.ACTION_CARRIER_SETUP);
             List<String> carrierPackages =
-                    mTm.getCarrierPackageNamesForBroadcastIntent(provisioningIntent);
+                    mTm.getCarrierPackageNamesForIntent(provisioningIntent);
             if (carrierPackages != null && !carrierPackages.isEmpty()) {
                 if (carrierPackages.size() != 1) {
                     Log.w(TAG, "Multiple matching carrier apps found, launching the first.");
diff --git a/src/com/android/settings/widget/SetupWizardIllustration.java b/src/com/android/settings/widget/SetupWizardIllustration.java
index fa8dd80..acdb5b3 100644
--- a/src/com/android/settings/widget/SetupWizardIllustration.java
+++ b/src/com/android/settings/widget/SetupWizardIllustration.java
@@ -20,9 +20,11 @@
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
+import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.view.Gravity;
 import android.widget.FrameLayout;
 
 import com.android.settings.R;
@@ -42,7 +44,8 @@
     private float mBaselineGridSize;
     private Drawable mBackground;
     private Drawable mForeground;
-    private int mForegroundHeight = 0;
+    private final Rect mViewBounds = new Rect();
+    private final Rect mForegroundBounds = new Rect();
     private float mScale = 1.0f;
     private float mAspectRatio = 0.0f;
 
@@ -112,36 +115,35 @@
         final int layoutWidth = right - left;
         final int layoutHeight = bottom - top;
         if (mForeground != null) {
-            final float intrinsicWidth = mForeground.getIntrinsicWidth();
-            final float intrinsicHeight = mForeground.getIntrinsicHeight();
-            if (intrinsicWidth <= 0 || intrinsicHeight <= 0) {
-                Log.e(TAG, "Foreground drawable intrinsic size must be defined and positive");
-                mForeground = null;
-                mForegroundHeight = 0;
-                mScale = 1.0f;
-            } else {
-                // Scale the foreground to fill the width of the view
-                mScale = layoutWidth / intrinsicWidth;
-                mForegroundHeight = (int) (intrinsicHeight * mScale);
-                mForeground.setBounds(0, 0, layoutWidth, mForegroundHeight);
+            int intrinsicWidth = mForeground.getIntrinsicWidth();
+            int intrinsicHeight = mForeground.getIntrinsicHeight();
+            final int layoutDirection = getLayoutDirection();
+
+            mViewBounds.set(0, 0, layoutWidth, layoutHeight);
+            if (mAspectRatio != 0f) {
+                mScale = layoutWidth / (float) intrinsicWidth;
+                intrinsicWidth = layoutWidth;
+                intrinsicHeight = (int) (intrinsicHeight * mScale);
             }
+            Gravity.apply(Gravity.FILL_HORIZONTAL | Gravity.TOP, intrinsicWidth, intrinsicHeight,
+                    mViewBounds, mForegroundBounds, layoutDirection);
+            mForeground.setBounds(mForegroundBounds);
         }
         if (mBackground != null) {
             // Scale the bounds by mScale to compensate for the scale done to the canvas before
             // drawing.
             mBackground.setBounds(0, 0, (int) Math.ceil(layoutWidth / mScale),
-                    (int) Math.ceil((layoutHeight - mForegroundHeight) / mScale));
+                    (int) Math.ceil((layoutHeight - mForegroundBounds.height()) / mScale));
         }
         super.onLayout(changed, left, top, right, bottom);
     }
 
     @Override
     public void onDraw(Canvas canvas) {
-        canvas.save();
         if (mBackground != null) {
             canvas.save();
             // Draw the background filling parts not covered by the illustration
-            canvas.translate(0, mForegroundHeight);
+            canvas.translate(0, mForegroundBounds.height());
             // Scale the background so its size matches the foreground
             canvas.scale(mScale, mScale, 0, 0);
             mBackground.draw(canvas);
@@ -153,7 +155,6 @@
             mForeground.draw(canvas);
             canvas.restore();
         }
-        canvas.restore();
         super.onDraw(canvas);
     }
 }