Merge "CEC: Pass port ID for set_audio_return_channel" into lmp-mr1-dev
diff --git a/api/current.txt b/api/current.txt
index 725c27d..1f86b03 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -25657,10 +25657,6 @@
   public static final class Telephony.Mms.Intents {
     field public static final java.lang.String CONTENT_CHANGED_ACTION = "android.intent.action.CONTENT_CHANGED";
     field public static final java.lang.String DELETED_CONTENTS = "deleted_contents";
-    field public static final java.lang.String EXTRA_MMS_CONTENT_URI = "android.provider.Telephony.extra.MMS_CONTENT_URI";
-    field public static final java.lang.String EXTRA_MMS_LOCATION_URL = "android.provider.Telephony.extra.MMS_LOCATION_URL";
-    field public static final java.lang.String MMS_DOWNLOAD_ACTION = "android.provider.Telephony.MMS_DOWNLOAD";
-    field public static final java.lang.String MMS_SEND_ACTION = "android.provider.Telephony.MMS_SEND";
   }
 
   public static final class Telephony.Mms.Outbox implements android.provider.Telephony.BaseMmsColumns {
@@ -25765,10 +25761,8 @@
     field public static final java.lang.String SMS_CB_RECEIVED_ACTION = "android.provider.Telephony.SMS_CB_RECEIVED";
     field public static final java.lang.String SMS_DELIVER_ACTION = "android.provider.Telephony.SMS_DELIVER";
     field public static final java.lang.String SMS_EMERGENCY_CB_RECEIVED_ACTION = "android.provider.Telephony.SMS_EMERGENCY_CB_RECEIVED";
-    field public static final java.lang.String SMS_FILTER_ACTION = "android.provider.Telephony.SMS_FILTER";
     field public static final java.lang.String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";
     field public static final java.lang.String SMS_REJECTED_ACTION = "android.provider.Telephony.SMS_REJECTED";
-    field public static final java.lang.String SMS_SEND_ACTION = "android.provider.Telephony.SMS_SEND";
     field public static final java.lang.String SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED_ACTION = "android.provider.Telephony.SMS_SERVICE_CATEGORY_PROGRAM_DATA_RECEIVED";
     field public static final java.lang.String WAP_PUSH_DELIVER_ACTION = "android.provider.Telephony.WAP_PUSH_DELIVER";
     field public static final java.lang.String WAP_PUSH_RECEIVED_ACTION = "android.provider.Telephony.WAP_PUSH_RECEIVED";
@@ -28511,9 +28505,6 @@
     method public void sendMultimediaMessage(android.content.Context, android.net.Uri, java.lang.String, android.os.Bundle, android.app.PendingIntent);
     method public void sendMultipartTextMessage(java.lang.String, java.lang.String, java.util.ArrayList<java.lang.String>, java.util.ArrayList<android.app.PendingIntent>, java.util.ArrayList<android.app.PendingIntent>);
     method public void sendTextMessage(java.lang.String, java.lang.String, java.lang.String, android.app.PendingIntent, android.app.PendingIntent);
-    method public void updateMmsDownloadStatus(android.content.Context, int, int, android.net.Uri);
-    method public void updateMmsSendStatus(android.content.Context, int, byte[], int, android.net.Uri);
-    method public void updateSmsSendStatus(int, boolean);
     field public static final java.lang.String EXTRA_MMS_DATA = "android.telephony.extra.MMS_DATA";
     field public static final java.lang.String EXTRA_MMS_HTTP_STATUS = "android.telephony.extra.MMS_HTTP_STATUS";
     field public static final java.lang.String MMS_CONFIG_ALIAS_ENABLED = "aliasEnabled";
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 3d7bacb..80b57b7 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -3055,6 +3055,11 @@
          * Apply any necessary background to smallIcons being used in the largeIcon spot.
          */
         private void processSmallIconAsLarge(int largeIconId, RemoteViews contentView) {
+            if (!isLegacy()) {
+                contentView.setDrawableParameters(R.id.icon, false, -1,
+                        0xFFFFFFFF,
+                        PorterDuff.Mode.SRC_ATOP, -1);
+            }
             if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, largeIconId)) {
                 applyLargeIconBackground(contentView);
             }
@@ -3102,11 +3107,12 @@
          */
         private void processSmallRightIcon(int smallIconDrawableId,
                 RemoteViews contentView) {
-            if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, smallIconDrawableId)) {
+            if (!isLegacy()) {
                 contentView.setDrawableParameters(R.id.right_icon, false, -1,
                         0xFFFFFFFF,
                         PorterDuff.Mode.SRC_ATOP, -1);
-
+            }
+            if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, smallIconDrawableId)) {
                 contentView.setInt(R.id.right_icon,
                         "setBackgroundResource",
                         R.drawable.notification_icon_legacy_bg);
@@ -3771,8 +3777,24 @@
         }
 
         private RemoteViews makeBigContentView() {
+
+            // Replace mLargeIcon with mBigLargeIcon if mBigLargeIconSet
+            // This covers the following cases:
+            //   1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides
+            //          mLargeIcon
+            //   2. !mBigLargeIconSet -> mLargeIcon applies
+            Bitmap oldLargeIcon = null;
+            if (mBigLargeIconSet) {
+                oldLargeIcon = mBuilder.mLargeIcon;
+                mBuilder.mLargeIcon = mBigLargeIcon;
+            }
+
             RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource());
 
+            if (mBigLargeIconSet) {
+                mBuilder.mLargeIcon = oldLargeIcon;
+            }
+
             contentView.setImageViewBitmap(R.id.big_picture, mPicture);
 
             applyTopPadding(contentView);
@@ -3803,6 +3825,7 @@
             super.restoreFromExtras(extras);
 
             if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) {
+                mBigLargeIconSet = true;
                 mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG);
             }
             mPicture = extras.getParcelable(EXTRA_PICTURE);
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index ead89b3..1211260 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -2797,6 +2797,8 @@
     /**
      * Called by the profile owner of a managed profile so that some intents sent in the managed
      * profile can also be resolved in the parent, or vice versa.
+     * Only activity intents are supported.
+     *
      * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
      * @param filter The {@link IntentFilter} the intent has to match to be also resolved in the
      * other profile
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 555f64c..838686a 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -5924,6 +5924,18 @@
        public static final String WIFI_REENABLE_DELAY_MS = "wifi_reenable_delay";
 
        /**
+        * Timeout for ephemeral networks when all known BSSIDs go out of range. We will disconnect
+        * from an ephemeral network if there is no BSSID for that network with a non-null score that
+        * has been seen in this time period.
+        *
+        * If this is less than or equal to zero, we use a more conservative behavior and only check
+        * for a non-null score from the currently connected or target BSSID.
+        * @hide
+        */
+       public static final String WIFI_EPHEMERAL_OUT_OF_RANGE_TIMEOUT_MS =
+               "wifi_ephemeral_out_of_range_timeout_ms";
+
+       /**
         * The number of milliseconds to delay when checking for data stalls during
         * non-aggressive detection. (screen is turned off.)
         * @hide
diff --git a/core/res/res/values-da/strings.xml b/core/res/res/values-da/strings.xml
index 84cbf78..1670857 100644
--- a/core/res/res/values-da/strings.xml
+++ b/core/res/res/values-da/strings.xml
@@ -47,7 +47,7 @@
     <string name="defaultVoiceMailAlphaTag" msgid="2660020990097733077">"Telefonsvarer"</string>
     <string name="defaultMsisdnAlphaTag" msgid="2850889754919584674">"MSISDN1"</string>
     <string name="mmiError" msgid="5154499457739052907">"Forbindelsesproblemer eller ugyldigt MMI-nummer."</string>
-    <string name="mmiFdnError" msgid="5224398216385316471">"Du kan kun foretage handlinger med faste opkaldsnumre."</string>
+    <string name="mmiFdnError" msgid="5224398216385316471">"Du kan kun foretage handlinger med dine numre til begrænset opkald."</string>
     <string name="serviceEnabled" msgid="8147278346414714315">"Tjenesten blev aktiveret."</string>
     <string name="serviceEnabledFor" msgid="6856228140453471041">"Tjenesten blev aktiveret for:"</string>
     <string name="serviceDisabled" msgid="1937553226592516411">"Tjenesten er deaktiveret."</string>
diff --git a/core/res/res/values-fr/strings.xml b/core/res/res/values-fr/strings.xml
index 031b4d9..fd2b6cc 100644
--- a/core/res/res/values-fr/strings.xml
+++ b/core/res/res/values-fr/strings.xml
@@ -1287,7 +1287,7 @@
     <string name="force_close" msgid="8346072094521265605">"OK"</string>
     <string name="report" msgid="4060218260984795706">"Rapport"</string>
     <string name="wait" msgid="7147118217226317732">"Attendre"</string>
-    <string name="webpage_unresponsive" msgid="3272758351138122503">"La page ne répond pas.\n \nVoulez-vous la fermer ?"</string>
+    <string name="webpage_unresponsive" msgid="3272758351138122503">"La page ne répond pas.\n \nVoulez-vous quitter ?"</string>
     <string name="launch_warning_title" msgid="1547997780506713581">"Application redirigée"</string>
     <string name="launch_warning_replace" msgid="6202498949970281412">"<xliff:g id="APP_NAME">%1$s</xliff:g> est maintenant lancée."</string>
     <string name="launch_warning_original" msgid="188102023021668683">"Application lancée initialement : <xliff:g id="APP_NAME">%1$s</xliff:g>."</string>
diff --git a/docs/html/sdk/exploring.jd b/docs/html/sdk/exploring.jd
deleted file mode 100644
index b34c1cf..0000000
--- a/docs/html/sdk/exploring.jd
+++ /dev/null
@@ -1,10 +0,0 @@
-page.title=Exploring the SDK
-excludeFromSuggestions=true
-walkthru=1
-
-@jd:body
-
-
-
-
-
diff --git a/docs/html/sdk/index.jd b/docs/html/sdk/index.jd
index 3324c2d..5350fe2 100644
--- a/docs/html/sdk/index.jd
+++ b/docs/html/sdk/index.jd
@@ -90,7 +90,7 @@
     display:block;
     padding:0;
     white-space: nowrap;
-    text-indent: 10000px;
+    text-indent: -10000px;
     font-size:0px;
     background: url(../images/tools/studio-logo.png);
     background-image: -webkit-image-set(url(../images/tools/studio-logo.png) 1x, url(../images/tools/studio-logo_2x.png) 2x);
diff --git a/docs/html/tools/help/adt.jd b/docs/html/tools/help/adt.jd
index 0130524..8abe1b4 100644
--- a/docs/html/tools/help/adt.jd
+++ b/docs/html/tools/help/adt.jd
@@ -509,10 +509,10 @@
 revision of the Android SDK Tools. If such dependencies exist, you will need to
 update the SDK Tools package of the SDK after installing the new revision of
 ADT. To update the SDK Tools package, use the Android SDK Manager, as
-described in <a href="{@docRoot}sdk/exploring.html">Exploring the SDK</a>.</p>
+described in <a href="{@docRoot}sdk/installing/adding-packages.html">Adding SDK Packages</a>.</p>
 
 <p>To learn about new features of each ADT revision and also any dependencies on
-the SDK Tools, see the listings in the <a href="#notes">Revisions</a>
+the SDK Tools, see the listings in the <a href="{@docRoot}tools/revisions/index.html">Revisions</a>
 section. To determine the version currently installed, open the
 Eclipse Installed Software window using <strong>Help</strong>
 &gt; <strong>Software Updates</strong> and refer to the version listed for
diff --git a/docs/html/tools/help/monkey.jd b/docs/html/tools/help/monkey.jd
index b6300a7..941f5d9 100644
--- a/docs/html/tools/help/monkey.jd
+++ b/docs/html/tools/help/monkey.jd
@@ -12,7 +12,7 @@
 <a name="overview"></a>
 <h2>Overview</h2>
 
-<p>The Monkey is a command-line tool that that you can run on any emulator
+<p>The Monkey is a command-line tool that you can run on any emulator
 instance or on a device.  It sends a pseudo-random stream of 
 user events into the system, which acts as a stress test on the application software you are 
 developing.</p>
diff --git a/docs/html/tools/sdk/tools-notes.jd b/docs/html/tools/sdk/tools-notes.jd
index ed48887..11e3ec7 100644
--- a/docs/html/tools/sdk/tools-notes.jd
+++ b/docs/html/tools/sdk/tools-notes.jd
@@ -898,7 +898,7 @@
             <li>Added a flag that sets <em>jumbo mode</em> for DEX files, which allows a larger
               number of strings in the DEX files. Enable this mode by adding the following line to
               the {@code project.properties} file of your project:
-              <pre>set dex.force.jumbo=true</pre></li>
+              <pre>dex.force.jumbo=true</pre></li>
             <li>Improved the build time by pre-dexing libraries (both JAR files and library
               projects).</li>
             <li>Updated the build to generate {@code R} resource classes for library projects
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index f0150d4..8a543ce 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -1841,12 +1841,22 @@
     }
 
     public void setRingerModeExternal(int ringerMode, String caller) {
-        setRingerMode(ringerMode, caller, true /*external*/);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            setRingerMode(ringerMode, caller, true /*external*/);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     public void setRingerModeInternal(int ringerMode, String caller) {
         enforceSelfOrSystemUI("setRingerModeInternal");
-        setRingerMode(ringerMode, caller, false /*external*/);
+        final long identity = Binder.clearCallingIdentity();
+        try {
+            setRingerMode(ringerMode, caller, false /*external*/);
+        } finally {
+            Binder.restoreCallingIdentity(identity);
+        }
     }
 
     private void setRingerMode(int ringerMode, String caller, boolean external) {
@@ -1860,26 +1870,28 @@
         if ((ringerMode == AudioManager.RINGER_MODE_VIBRATE) && !mHasVibrator) {
             ringerMode = AudioManager.RINGER_MODE_SILENT;
         }
-        final int ringerModeInternal = getRingerModeInternal();
-        final int ringerModeExternal = getRingerModeExternal();
-        if (external) {
-            setRingerModeExt(ringerMode);
-            if (mRingerModeDelegate != null) {
-                ringerMode = mRingerModeDelegate.onSetRingerModeExternal(ringerModeExternal,
-                        ringerMode, caller, ringerModeInternal);
+        synchronized (mSettingsLock) {
+            final int ringerModeInternal = getRingerModeInternal();
+            final int ringerModeExternal = getRingerModeExternal();
+            if (external) {
+                setRingerModeExt(ringerMode);
+                if (mRingerModeDelegate != null) {
+                    ringerMode = mRingerModeDelegate.onSetRingerModeExternal(ringerModeExternal,
+                            ringerMode, caller, ringerModeInternal);
+                }
+                if (ringerMode != ringerModeInternal) {
+                    setRingerModeInt(ringerMode, true /*persist*/);
+                }
+            } else /*internal*/ {
+                if (ringerMode != ringerModeInternal) {
+                    setRingerModeInt(ringerMode, true /*persist*/);
+                }
+                if (mRingerModeDelegate != null) {
+                    ringerMode = mRingerModeDelegate.onSetRingerModeInternal(ringerModeInternal,
+                            ringerMode, caller, ringerModeExternal);
+                }
+                setRingerModeExt(ringerMode);
             }
-            if (ringerMode != ringerModeInternal) {
-                setRingerModeInt(ringerMode, true /*persist*/);
-            }
-        } else /*internal*/ {
-            if (ringerMode != ringerModeInternal) {
-                setRingerModeInt(ringerMode, true /*persist*/);
-            }
-            if (mRingerModeDelegate != null) {
-                ringerMode = mRingerModeDelegate.onSetRingerModeInternal(ringerModeInternal,
-                        ringerMode, caller, ringerModeExternal);
-            }
-            setRingerModeExt(ringerMode);
         }
     }
 
@@ -1968,10 +1980,10 @@
         switch (getVibrateSetting(vibrateType)) {
 
             case AudioManager.VIBRATE_SETTING_ON:
-                return getRingerModeInternal() != AudioManager.RINGER_MODE_SILENT;
+                return getRingerModeExternal() != AudioManager.RINGER_MODE_SILENT;
 
             case AudioManager.VIBRATE_SETTING_ONLY_SILENT:
-                return getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE;
+                return getRingerModeExternal() == AudioManager.RINGER_MODE_VIBRATE;
 
             case AudioManager.VIBRATE_SETTING_OFF:
                 // return false, even for incoming calls
diff --git a/packages/CaptivePortalLogin/assets/locked_page.png b/packages/CaptivePortalLogin/assets/locked_page.png
new file mode 100644
index 0000000..91e1291
--- /dev/null
+++ b/packages/CaptivePortalLogin/assets/locked_page.png
Binary files differ
diff --git a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
index 7253579..06e8574 100644
--- a/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
+++ b/packages/CaptivePortalLogin/src/com/android/captiveportallogin/CaptivePortalLoginActivity.java
@@ -28,6 +28,7 @@
 import android.net.NetworkRequest;
 import android.net.Proxy;
 import android.net.Uri;
+import android.net.http.SslError;
 import android.os.Bundle;
 import android.provider.Settings;
 import android.provider.Settings.Global;
@@ -37,6 +38,7 @@
 import android.view.MenuItem;
 import android.view.View;
 import android.view.Window;
+import android.webkit.SslErrorHandler;
 import android.webkit.WebChromeClient;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
@@ -251,6 +253,19 @@
             }
             testForCaptivePortal();
         }
+
+        // A web page consisting of a large broken lock icon to indicate SSL failure.
+        final static String SSL_ERROR_HTML = "<!DOCTYPE html><html><head><style>" +
+                "html { width:100%; height:100%; " +
+                "       background:url(locked_page.png) center center no-repeat; }" +
+                "</style></head><body></body></html>";
+
+        @Override
+        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
+            Log.w(TAG, "SSL error; displaying broken lock icon.");
+            view.loadDataWithBaseURL("file:///android_asset/", SSL_ERROR_HTML, "text/HTML",
+                    "UTF-8", null);
+        }
     }
 
     private class MyWebChromeClient extends WebChromeClient {
diff --git a/packages/SystemUI/res/values-en-rGB/strings.xml b/packages/SystemUI/res/values-en-rGB/strings.xml
index e1cd73a..f61724d 100644
--- a/packages/SystemUI/res/values-en-rGB/strings.xml
+++ b/packages/SystemUI/res/values-en-rGB/strings.xml
@@ -266,7 +266,7 @@
     <string name="quick_settings_tethering_label" msgid="7153452060448575549">"Tethering"</string>
     <string name="quick_settings_hotspot_label" msgid="6046917934974004879">"Hotspot"</string>
     <string name="quick_settings_notifications_label" msgid="4818156442169154523">"Notifications"</string>
-    <string name="quick_settings_flashlight_label" msgid="2133093497691661546">"Flashlight"</string>
+    <string name="quick_settings_flashlight_label" msgid="2133093497691661546">"Torch"</string>
     <string name="quick_settings_cellular_detail_title" msgid="8575062783675171695">"Mobile data"</string>
     <string name="quick_settings_cellular_detail_data_usage" msgid="1964260360259312002">"Data usage"</string>
     <string name="quick_settings_cellular_detail_remaining_data" msgid="722715415543541249">"Remaining data"</string>
diff --git a/packages/SystemUI/res/values-en-rIN/strings.xml b/packages/SystemUI/res/values-en-rIN/strings.xml
index e1cd73a..f61724d 100644
--- a/packages/SystemUI/res/values-en-rIN/strings.xml
+++ b/packages/SystemUI/res/values-en-rIN/strings.xml
@@ -266,7 +266,7 @@
     <string name="quick_settings_tethering_label" msgid="7153452060448575549">"Tethering"</string>
     <string name="quick_settings_hotspot_label" msgid="6046917934974004879">"Hotspot"</string>
     <string name="quick_settings_notifications_label" msgid="4818156442169154523">"Notifications"</string>
-    <string name="quick_settings_flashlight_label" msgid="2133093497691661546">"Flashlight"</string>
+    <string name="quick_settings_flashlight_label" msgid="2133093497691661546">"Torch"</string>
     <string name="quick_settings_cellular_detail_title" msgid="8575062783675171695">"Mobile data"</string>
     <string name="quick_settings_cellular_detail_data_usage" msgid="1964260360259312002">"Data usage"</string>
     <string name="quick_settings_cellular_detail_remaining_data" msgid="722715415543541249">"Remaining data"</string>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationTemplateViewWrapper.java
index fbcba0b..59b62e5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationTemplateViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationTemplateViewWrapper.java
@@ -53,6 +53,9 @@
     private ImageView mIcon;
     protected ImageView mPicture;
 
+    /** Whether the icon needs to be forced grayscale when in dark mode. */
+    private boolean mIconForceGraysaleWhenDark;
+
     protected NotificationTemplateViewWrapper(Context ctx, View view) {
         super(view);
         mIconDarkAlpha = ctx.getResources().getInteger(R.integer.doze_small_icon_alpha);
@@ -73,11 +76,15 @@
         mIcon = resolveIcon(largeIcon, rightIcon);
         mPicture = resolvePicture(largeIcon);
         mIconBackgroundColor = resolveBackgroundColor(mIcon);
+
+        // If the icon already has a color filter, we assume that we already forced the icon to be
+        // white when we created the notification.
+        mIconForceGraysaleWhenDark = mIcon != null && mIcon.getDrawable().getColorFilter() != null;
     }
 
     private ImageView resolveIcon(ImageView largeIcon, ImageView rightIcon) {
         return largeIcon != null && largeIcon.getBackground() != null ? largeIcon
-                : rightIcon != null && rightIcon.getBackground() != null ? rightIcon
+                : rightIcon != null && rightIcon.getVisibility() == View.VISIBLE ? rightIcon
                 : null;
     }
 
@@ -118,9 +125,15 @@
             if (fade) {
                 fadeIconColorFilter(mIcon, dark, delay);
                 fadeIconAlpha(mIcon, dark, delay);
+                if (!mIconForceGraysaleWhenDark) {
+                    fadeGrayscale(mIcon, dark, delay);
+                }
             } else {
                 updateIconColorFilter(mIcon, dark);
                 updateIconAlpha(mIcon, dark);
+                if (!mIconForceGraysaleWhenDark) {
+                    updateGrayscale(mIcon, dark);
+                }
             }
         }
         setPictureGrayscale(dark, fade, delay);
@@ -196,8 +209,8 @@
         mIconColorFilter.setColor(color);
         Drawable background = target.getBackground();
 
-        // The notification might have been modified during the animation, so background might be
-        // null here.
+        // The background might be null for legacy notifications. Also, the notification might have
+        // been modified during the animation, so background might be null here.
         if (background != null) {
             background.mutate().setColorFilter(mIconColorFilter);
         }
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 499cff3..788b5d3 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -3949,6 +3949,7 @@
         notifyLockdownVpn(newNetwork);
         handleApplyDefaultProxy(newNetwork.linkProperties.getHttpProxy());
         updateTcpBufferSizes(newNetwork);
+        setDefaultDnsSystemProperties(newNetwork.linkProperties.getDnsServers());
     }
 
     // Handles a network appearing or improving its score.
@@ -3988,6 +3989,7 @@
         }
         boolean keep = newNetwork.isVPN();
         boolean isNewDefault = false;
+        NetworkAgentInfo oldDefaultNetwork = null;
         if (DBG) log("rematching " + newNetwork.name());
         // Find and migrate to this Network any NetworkRequests for
         // which this network is now the best.
@@ -4045,25 +4047,7 @@
                     sendUpdatedScoreToFactories(nri.request, newNetwork.getCurrentScore());
                     if (mDefaultRequest.requestId == nri.request.requestId) {
                         isNewDefault = true;
-                        // TODO: Remove following line.  It's redundant with makeDefault call.
-                        if (newNetwork.linkProperties != null) {
-                            updateTcpBufferSizes(newNetwork);
-                            setDefaultDnsSystemProperties(
-                                    newNetwork.linkProperties.getDnsServers());
-                        } else {
-                            setDefaultDnsSystemProperties(new ArrayList<InetAddress>());
-                        }
-                        // Maintain the illusion: since the legacy API only
-                        // understands one network at a time, we must pretend
-                        // that the current default network disconnected before
-                        // the new one connected.
-                        if (currentNetwork != null) {
-                            mLegacyTypeTracker.remove(currentNetwork.networkInfo.getType(),
-                                                      currentNetwork);
-                        }
-                        mDefaultInetConditionPublished = newNetwork.validated ? 100 : 0;
-                        mLegacyTypeTracker.add(newNetwork.networkInfo.getType(), newNetwork);
-                        notifyLockdownVpn(newNetwork);
+                        oldDefaultNetwork = currentNetwork;
                     }
                 }
             }
@@ -4104,6 +4088,17 @@
                                 1000);
                     }
                 }
+                // Maintain the illusion: since the legacy API only
+                // understands one network at a time, we must pretend
+                // that the current default network disconnected before
+                // the new one connected.
+                if (oldDefaultNetwork != null) {
+                    mLegacyTypeTracker.remove(oldDefaultNetwork.networkInfo.getType(),
+                                              oldDefaultNetwork);
+                }
+                mDefaultInetConditionPublished = newNetwork.validated ? 100 : 0;
+                mLegacyTypeTracker.add(newNetwork.networkInfo.getType(), newNetwork);
+                notifyLockdownVpn(newNetwork);
             }
 
             // Notify battery stats service about this network, both the normal
diff --git a/services/core/java/com/android/server/MmsServiceBroker.java b/services/core/java/com/android/server/MmsServiceBroker.java
index 83b1919..0de6a03 100644
--- a/services/core/java/com/android/server/MmsServiceBroker.java
+++ b/services/core/java/com/android/server/MmsServiceBroker.java
@@ -35,7 +35,7 @@
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.os.UserHandle;
-import android.provider.Telephony;
+import android.service.carrier.CarrierMessagingService;
 import android.telephony.TelephonyManager;
 import android.util.Slog;
 
@@ -230,7 +230,7 @@
                 return;
             }
             contentUri = adjustUriForUserAndGrantPermission(contentUri,
-                    Telephony.Mms.Intents.MMS_SEND_ACTION,
+                    CarrierMessagingService.SERVICE_INTERFACE,
                     Intent.FLAG_GRANT_READ_URI_PERMISSION);
             getServiceGuarded().sendMessage(subId, callingPkg, contentUri, locationUrl,
                     configOverrides, sentIntent);
@@ -248,7 +248,7 @@
                 return;
             }
             contentUri = adjustUriForUserAndGrantPermission(contentUri,
-                    Telephony.Mms.Intents.MMS_DOWNLOAD_ACTION,
+                    CarrierMessagingService.SERVICE_INTERFACE,
                     Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
 
             getServiceGuarded().downloadMessage(subId, callingPkg, locationUrl, contentUri,
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 650f0e2..825627f 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -927,7 +927,7 @@
                     Settings.Global.DEVICE_PROVISIONED, 0)) {
             mDisableNotificationEffects = true;
         }
-        mZenModeHelper.updateZenMode();
+        mZenModeHelper.readZenModeFromSetting();
 
         mUserProfiles.updateCache(getContext());
         listenForCallState();
diff --git a/services/core/java/com/android/server/notification/ZenModeHelper.java b/services/core/java/com/android/server/notification/ZenModeHelper.java
index 0f9a59b..841fc21 100644
--- a/services/core/java/com/android/server/notification/ZenModeHelper.java
+++ b/services/core/java/com/android/server/notification/ZenModeHelper.java
@@ -221,21 +221,26 @@
     }
 
     public void setZenMode(int zenMode, String reason) {
-        ZenLog.traceSetZenMode(zenMode, reason);
-        Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, zenMode);
+        setZenMode(zenMode, reason, true);
     }
 
-    public void updateZenMode() {
-        final int oldMode = mZenMode;
+    private void setZenMode(int zenMode, String reason, boolean setRingerMode) {
+        ZenLog.traceSetZenMode(zenMode, reason);
+        if (mZenMode == zenMode) return;
+        ZenLog.traceUpdateZenMode(mZenMode, zenMode);
+        mZenMode = zenMode;
+        Global.putInt(mContext.getContentResolver(), Global.ZEN_MODE, mZenMode);
+        if (setRingerMode) {
+            applyZenToRingerMode();
+        }
+        applyRestrictions();
+        mHandler.postDispatchOnZenModeChanged();
+    }
+
+    public void readZenModeFromSetting() {
         final int newMode = Global.getInt(mContext.getContentResolver(),
                 Global.ZEN_MODE, Global.ZEN_MODE_OFF);
-        if (oldMode != newMode) {
-            ZenLog.traceUpdateZenMode(oldMode, newMode);
-        }
-        mZenMode = newMode;
-        applyRestrictions();
-        onZenUpdated(oldMode, newMode);
-        dispatchOnZenModeChanged();
+        setZenMode(newMode, "setting");
     }
 
     private void applyRestrictions() {
@@ -297,18 +302,16 @@
         dispatchOnConfigChanged();
         final String val = Integer.toString(mConfig.hashCode());
         Global.putString(mContext.getContentResolver(), Global.ZEN_MODE_CONFIG_ETAG, val);
-        updateZenMode();
+        applyRestrictions();
         return true;
     }
 
-    private void onZenUpdated(int oldZen, int newZen) {
+    private void applyZenToRingerMode() {
         if (mAudioManager == null) return;
-        if (oldZen == newZen) return;
-
         // force the ringer mode into compliance
         final int ringerModeInternal = mAudioManager.getRingerModeInternal();
         int newRingerModeInternal = ringerModeInternal;
-        switch (newZen) {
+        switch (mZenMode) {
             case Global.ZEN_MODE_NO_INTERRUPTIONS:
                 if (ringerModeInternal != AudioManager.RINGER_MODE_SILENT) {
                     mPreviousRingerMode = ringerModeInternal;
@@ -337,7 +340,7 @@
         int ringerModeExternalOut = ringerModeNew;
 
         int newZen = -1;
-        switch(ringerModeNew) {
+        switch (ringerModeNew) {
             case AudioManager.RINGER_MODE_SILENT:
                 if (isChange) {
                     if (mZenMode != Global.ZEN_MODE_NO_INTERRUPTIONS) {
@@ -356,7 +359,7 @@
                 break;
         }
         if (newZen != -1) {
-            mHandler.postSetZenMode(newZen, "ringerModeInternal");
+            setZenMode(newZen, "ringerModeInternal", false /*setRingerMode*/);
         }
 
         if (isChange || newZen != -1 || ringerModeExternal != ringerModeExternalOut) {
@@ -374,7 +377,7 @@
         final boolean isVibrate = ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE;
 
         int newZen = -1;
-        switch(ringerModeNew) {
+        switch (ringerModeNew) {
             case AudioManager.RINGER_MODE_SILENT:
                 if (isChange) {
                     if (mZenMode == Global.ZEN_MODE_OFF) {
@@ -394,7 +397,7 @@
                 break;
         }
         if (newZen != -1) {
-            mHandler.postSetZenMode(newZen, "ringerModeExternal");
+            setZenMode(newZen, "ringerModeExternal", false /*setRingerMode*/);
         }
 
         ZenLog.traceSetRingerModeExternal(ringerModeOld, ringerModeNew, caller, ringerModeInternal,
@@ -516,27 +519,28 @@
 
         public void update(Uri uri) {
             if (ZEN_MODE.equals(uri)) {
-                updateZenMode();
+                readZenModeFromSetting();
             }
         }
     }
 
     private class H extends Handler {
-        private static final int MSG_SET_ZEN = 1;
+        private static final int MSG_DISPATCH = 1;
 
         private H(Looper looper) {
             super(looper);
         }
 
-        private void postSetZenMode(int zen, String reason) {
-            obtainMessage(MSG_SET_ZEN, zen, 0, reason).sendToTarget();
+        private void postDispatchOnZenModeChanged() {
+            removeMessages(MSG_DISPATCH);
+            sendEmptyMessage(MSG_DISPATCH);
         }
 
         @Override
         public void handleMessage(Message msg) {
-            switch(msg.what) {
-                case MSG_SET_ZEN:
-                    setZenMode(msg.arg1, (String) msg.obj);
+            switch (msg.what) {
+                case MSG_DISPATCH:
+                    dispatchOnZenModeChanged();
                     break;
             }
         }