Merge "Disable accessibility focus on the instruction video in magnification gesture screen." into nyc-mr1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d83ac19..78fa324 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -385,6 +385,10 @@
                 <action android:name="android.net.conn.PROMPT_UNVALIDATED" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>
+            <intent-filter>
+                <action android:name="android.net.conn.PROMPT_LOST_VALIDATION" />
+                <category android:name="android.intent.category.DEFAULT" />
+            </intent-filter>
             <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
                 android:value="true" />
         </activity>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 341e4a3..86b8140 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1747,6 +1747,13 @@
     <string name="no_internet_access_text">This network has no Internet access. Stay connected?</string>
     <string name="no_internet_access_remember">Don\u2019t ask again for this network</string>
 
+    <!-- Dialog text to tell the user that the selected network has lost Internet access, and asking the user whether they want to avoid this network. -->
+    <string name="lost_internet_access_title">Wi\u2011Fi has no Internet access</string>
+    <string name="lost_internet_access_text">Your device can automatically switch to other saved Wi\u2011Fi networks or cellular data. Cellular charges may apply.</string>
+    <string name="lost_internet_access_switch">Switch networks</string>
+    <string name="lost_internet_access_cancel">Cancel</string>
+
+
     <!-- Button label to connect to a Wi-Fi network -->
     <string name="wifi_connect">Connect</string>
     <!-- Failured notification for connect -->
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 944a1f2..1229b9e 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -60,6 +60,16 @@
     public AppRow loadAppRow(Context context, PackageManager pm, PackageInfo app) {
         final AppRow row = loadAppRow(context, pm, app.applicationInfo);
         row.systemApp = Utils.isSystemPackage(context.getResources(), pm, app);
+        final String[] nonBlockablePkgs = context.getResources().getStringArray(
+                    com.android.internal.R.array.config_nonBlockableNotificationPackages);
+        if (nonBlockablePkgs != null) {
+            int N = nonBlockablePkgs.length;
+            for (int i = 0; i < N; i++) {
+                if (app.packageName.equals(nonBlockablePkgs[i])) {
+                    row.systemApp = true;
+                }
+            }
+        }
         return row;
     }
 
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index bce42eb..3469cc0 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -154,13 +154,13 @@
         }
     }
 
-    protected void setupImportancePrefs(boolean isSystemApp, int importance, boolean banned) {
+    protected void setupImportancePrefs(boolean notBlockable, int importance, boolean banned) {
         if (mShowSlider) {
             setVisible(mBlock, false);
             setVisible(mSilent, false);
             mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
             mImportance.setMinimumProgress(
-                    isSystemApp ? Ranking.IMPORTANCE_MIN : Ranking.IMPORTANCE_NONE);
+                    notBlockable ? Ranking.IMPORTANCE_MIN : Ranking.IMPORTANCE_NONE);
             mImportance.setMax(Ranking.IMPORTANCE_MAX);
             mImportance.setProgress(importance);
             mImportance.setAutoOn(importance == Ranking.IMPORTANCE_UNSPECIFIED);
@@ -175,7 +175,7 @@
             });
         } else {
             setVisible(mImportance, false);
-            if (isSystemApp) {
+            if (notBlockable) {
                 setVisible(mBlock, false);
             } else {
                 boolean blocked = importance == Ranking.IMPORTANCE_NONE || banned;
@@ -191,20 +191,20 @@
                         return true;
                     }
                 });
-
-                mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
-                    @Override
-                    public boolean onPreferenceChange(Preference preference, Object newValue) {
-                        final boolean silenced = (Boolean) newValue;
-                        final int importance =
-                                silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED;
-                        mBackend.setImportance(mPkgInfo.packageName, mUid, importance);
-                        updateDependents(importance);
-                        return true;
-                    }
-                });
-                updateDependents(banned ? Ranking.IMPORTANCE_NONE : importance);
             }
+            mSilent.setChecked(importance == Ranking.IMPORTANCE_LOW);
+            mSilent.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+                @Override
+                public boolean onPreferenceChange(Preference preference, Object newValue) {
+                    final boolean silenced = (Boolean) newValue;
+                    final int importance =
+                            silenced ? Ranking.IMPORTANCE_LOW : Ranking.IMPORTANCE_UNSPECIFIED;
+                    mBackend.setImportance(mPkgInfo.packageName, mUid, importance);
+                    updateDependents(importance);
+                    return true;
+                }
+            });
+            updateDependents(banned ? Ranking.IMPORTANCE_NONE : importance);
         }
     }
 
diff --git a/src/com/android/settings/wifi/WifiNoInternetDialog.java b/src/com/android/settings/wifi/WifiNoInternetDialog.java
index b655344..289e0fc 100644
--- a/src/com/android/settings/wifi/WifiNoInternetDialog.java
+++ b/src/com/android/settings/wifi/WifiNoInternetDialog.java
@@ -26,6 +26,7 @@
 import android.net.NetworkInfo;
 import android.net.NetworkRequest;
 import android.os.Bundle;
+import android.provider.Settings;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -35,6 +36,8 @@
 import com.android.internal.app.AlertController;
 import com.android.settings.R;
 
+import static android.net.ConnectivityManager.ACTION_PROMPT_LOST_VALIDATION;
+import static android.net.ConnectivityManager.ACTION_PROMPT_UNVALIDATED;
 import static android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED;
 
 public final class WifiNoInternetDialog extends AlertActivity implements
@@ -46,20 +49,26 @@
     private String mNetworkName;
     private ConnectivityManager.NetworkCallback mNetworkCallback;
     private CheckBox mAlwaysAllow;
+    private String mAction;
+
+    private boolean isKnownAction(Intent intent) {
+        return intent.getAction().equals(ACTION_PROMPT_UNVALIDATED) ||
+                intent.getAction().equals(ACTION_PROMPT_LOST_VALIDATION);
+    }
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
         final Intent intent = getIntent();
-        if (intent == null ||
-                !intent.getAction().equals(ConnectivityManager.ACTION_PROMPT_UNVALIDATED) ||
-                !"netId".equals(intent.getScheme())) {
+        if (intent == null || !isKnownAction(intent) || !"netId".equals(intent.getScheme())) {
             Log.e(TAG, "Unexpected intent " + intent + ", exiting");
             finish();
             return;
         }
 
+        mAction = intent.getAction();
+
         try {
             mNetwork = new Network(Integer.parseInt(intent.getData().getSchemeSpecificPart()));
         } catch (NullPointerException|NumberFormatException e) {
@@ -115,20 +124,29 @@
         mAlert.setIcon(R.drawable.ic_settings_wireless);
 
         final AlertController.AlertParams ap = mAlertParams;
-        ap.mTitle = mNetworkName;
-        ap.mMessage = getString(R.string.no_internet_access_text);
-        ap.mPositiveButtonText = getString(R.string.yes);
-        ap.mNegativeButtonText = getString(R.string.no);
+        if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
+            ap.mTitle = mNetworkName;
+            ap.mMessage = getString(R.string.no_internet_access_text);
+            ap.mPositiveButtonText = getString(R.string.yes);
+            ap.mNegativeButtonText = getString(R.string.no);
+        } else {
+            ap.mTitle = getString(R.string.lost_internet_access_title);
+            ap.mMessage = getString(R.string.lost_internet_access_text);
+            ap.mPositiveButtonText = getString(R.string.lost_internet_access_switch);
+            ap.mNegativeButtonText = getString(R.string.lost_internet_access_cancel);
+        }
         ap.mPositiveButtonListener = this;
         ap.mNegativeButtonListener = this;
 
-        final LayoutInflater inflater = LayoutInflater.from(ap.mContext);
-        final View checkbox = inflater.inflate(
-                com.android.internal.R.layout.always_use_checkbox, null);
-        ap.mView = checkbox;
+        if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
+            final LayoutInflater inflater = LayoutInflater.from(ap.mContext);
+            final View checkbox = inflater.inflate(
+                    com.android.internal.R.layout.always_use_checkbox, null);
+            ap.mView = checkbox;
 
-        mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse);
-        mAlwaysAllow.setText(getString(R.string.no_internet_access_remember));
+            mAlwaysAllow = (CheckBox) checkbox.findViewById(com.android.internal.R.id.alwaysUse);
+            mAlwaysAllow.setText(getString(R.string.no_internet_access_remember));
+        }
 
         setupAlert();
     }
@@ -143,18 +161,20 @@
     }
 
     public void onClick(DialogInterface dialog, int which) {
+        if (which != BUTTON_NEGATIVE && which != BUTTON_POSITIVE) return;
         final boolean accept = (which == BUTTON_POSITIVE);
-        final String action = (accept ? "Connect" : "Ignore");
-        final boolean always = mAlwaysAllow.isChecked();
 
-        switch (which) {
-            case BUTTON_POSITIVE:
-            case BUTTON_NEGATIVE:
-                mCM.setAcceptUnvalidated(mNetwork, accept, always);
-                Log.d(TAG, action +  " network=" + mNetwork + (always ? " and remember" : ""));
-                break;
-            default:
-                break;
+        if (ACTION_PROMPT_UNVALIDATED.equals(mAction)) {
+            final String action = (accept ? "Connect" : "Ignore");
+            final boolean always = mAlwaysAllow.isChecked();
+            mCM.setAcceptUnvalidated(mNetwork, accept, always);
+            Log.d(TAG, "NO_INTERNET: " + action +  " network=" + mNetwork +
+                    (always ? " and remember" : ""));
+        } else {
+            final String action = (accept ? "Switch" : "Cancel");
+            Log.d(TAG, "LOST_INTERNET: " + action);
+            Settings.Global.putInt(mAlertParams.mContext.getContentResolver(),
+                    Settings.Global.NETWORK_AVOID_BAD_WIFI, accept ? 1 : 0);
         }
     }
 }