Merge "Add a new flow for decryption checking." into lmp-mr1-dev
diff --git a/res/drawable-hdpi/wifi_assistant_card.png b/res/drawable-hdpi/wifi_assistant_card.png
deleted file mode 100644
index 5a7e6d1..0000000
--- a/res/drawable-hdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/wifi_assistant_card_tablet.png b/res/drawable-hdpi/wifi_assistant_card_tablet.png
deleted file mode 100644
index d309533..0000000
--- a/res/drawable-hdpi/wifi_assistant_card_tablet.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-hdpi/wifi_assistant_card.png b/res/drawable-ldrtl-hdpi/wifi_assistant_card.png
deleted file mode 100644
index 67a93b3..0000000
--- a/res/drawable-ldrtl-hdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-mdpi/wifi_assistant_card.png b/res/drawable-ldrtl-mdpi/wifi_assistant_card.png
deleted file mode 100644
index 578454c..0000000
--- a/res/drawable-ldrtl-mdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xhdpi/wifi_assistant_card.png b/res/drawable-ldrtl-xhdpi/wifi_assistant_card.png
deleted file mode 100644
index 8840a6a..0000000
--- a/res/drawable-ldrtl-xhdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xxhdpi/wifi_assistant_card.png b/res/drawable-ldrtl-xxhdpi/wifi_assistant_card.png
deleted file mode 100644
index 1273b73..0000000
--- a/res/drawable-ldrtl-xxhdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-ldrtl-xxxhdpi/wifi_assistant_card.png b/res/drawable-ldrtl-xxxhdpi/wifi_assistant_card.png
deleted file mode 100644
index 7c7bf0a..0000000
--- a/res/drawable-ldrtl-xxxhdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/wifi_assistant_card.png b/res/drawable-mdpi/wifi_assistant_card.png
deleted file mode 100644
index bb2114c..0000000
--- a/res/drawable-mdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/wifi_assistant_card_tablet.png b/res/drawable-mdpi/wifi_assistant_card_tablet.png
deleted file mode 100644
index 0ca411c..0000000
--- a/res/drawable-mdpi/wifi_assistant_card_tablet.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/wifi_assistant_card.png b/res/drawable-xhdpi/wifi_assistant_card.png
deleted file mode 100644
index 1f8a5b9..0000000
--- a/res/drawable-xhdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xhdpi/wifi_assistant_card_tablet.png b/res/drawable-xhdpi/wifi_assistant_card_tablet.png
deleted file mode 100644
index 570a663..0000000
--- a/res/drawable-xhdpi/wifi_assistant_card_tablet.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/wifi_assistant_card.png b/res/drawable-xxhdpi/wifi_assistant_card.png
deleted file mode 100644
index 65211cd..0000000
--- a/res/drawable-xxhdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxhdpi/wifi_assistant_card_tablet.png b/res/drawable-xxhdpi/wifi_assistant_card_tablet.png
deleted file mode 100644
index 2941b14..0000000
--- a/res/drawable-xxhdpi/wifi_assistant_card_tablet.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxxhdpi/wifi_assistant_card.png b/res/drawable-xxxhdpi/wifi_assistant_card.png
deleted file mode 100644
index e79330b..0000000
--- a/res/drawable-xxxhdpi/wifi_assistant_card.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-xxxhdpi/wifi_assistant_card_tablet.png b/res/drawable-xxxhdpi/wifi_assistant_card_tablet.png
deleted file mode 100644
index 54120fb..0000000
--- a/res/drawable-xxxhdpi/wifi_assistant_card_tablet.png
+++ /dev/null
Binary files differ
diff --git a/res/layout/wifi_assistant_card.xml b/res/layout/wifi_assistant_card.xml
deleted file mode 100644
index b7ab7b9..0000000
--- a/res/layout/wifi_assistant_card.xml
+++ /dev/null
@@ -1,81 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/wifi_assistant_card"
-    android:background="@android:color/transparent"
-    android:layout_width="fill_parent"
-    android:layout_height="wrap_content"
-    android:gravity="center_vertical"
-    android:orientation="vertical">
-
-    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="fill_parent"
-        android:layout_height="@dimen/wifi_assistant_height">
-
-        <ImageView
-            android:id="@+id/cardBackground"
-            android:background="@color/wifi_assistant_color_accent"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center"
-            android:src="@drawable/wifi_assistant_card" />
-
-        <TextView
-            android:id="@+id/backgroundText"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_marginLeft="@dimen/wifi_assistant_text_padding"
-            android:gravity="start"
-            android:paddingStart="@dimen/wifi_assistant_padding_start_end"
-            android:paddingTop="@dimen/wifi_assistant_padding_top_bottom"
-            android:text="@string/wifi_assistant_intro_setup"
-            style="@style/WifiAssistantText" />
-
-    </RelativeLayout>
-
-    <TextView
-        android:id="@+id/wifi_assistant_text"
-        android:background="@android:color/transparent"
-        android:layout_height="wrap_content"
-        android:layout_width="wrap_content"
-        android:layout_marginBottom="@dimen/wifi_assistant_padding_top_bottom"
-        android:layout_marginTop="@dimen/wifi_assistant_padding_top_bottom"
-        android:layout_marginLeft="@dimen/wifi_assistant_padding_start_end"
-        android:layout_marginRight="@dimen/wifi_assistant_padding_start_end"
-        android:gravity="start"
-        android:textAppearance="?android:attr/textAppearanceMedium" />
-
-    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:background="@android:color/transparent"
-        android:layout_height="wrap_content"
-        android:layout_width="fill_parent"
-        android:gravity="end"
-        android:orientation="horizontal">
-
-        <Button
-            android:id="@+id/no_thanks_button"
-            android:text="@string/wifi_assistant_no_thanks"
-            style="@style/WifiAssistantButton.Negative" />
-
-        <Button
-            android:id="@+id/setup"
-            android:text="@string/wifi_assistant_setup"
-            style="@style/WifiAssistantButton.Positive" />
-
-    </LinearLayout>
-
-</LinearLayout>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 6ccced2..961fb2f 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -45,8 +45,6 @@
     <color name="setup_wizard_wifi_color_dark">#ff00e4ff</color>
     <color name="setup_wizard_wifi_color_light">#ff0096a6</color>
 
-    <color name="wifi_assistant_color_accent">#ff009587</color>
-
     <color name="circle_avatar_frame_color">#ffffffff</color>
     <color name="circle_avatar_frame_shadow_color">#80000000</color>
     <color name="circle_avatar_frame_pressed_color">#ffffffff</color>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f66b44b..dc5f3fd 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1328,20 +1328,8 @@
     <!-- Bluetooth settings.  Dock Setting Dialog - Remember setting and don't ask user again -->
     <string name="bluetooth_dock_settings_remember">Remember settings</string>
 
-    <!-- Wifi Assistant title string.  [CHAR LIMIT=40] -->
-    <string name="wifi_assistant_intro_setup">Introducing\nWi\u2011Fi Assistant</string>
-    <!-- Wifi Assistant No, thanks string.  Text to say no to wifi assistant. [CHAR LIMIT=20] -->
-    <string name="wifi_assistant_no_thanks">NO, THANKS</string>
-    <!-- Wifi Assistant setup string.  Text to say yes to wifi assistant and begin setup. [CHAR LIMIT=20] -->
-    <string name="wifi_assistant_setup">SET UP</string>
-    <!-- Wifi Assistant card message.  [CHAR LIMIT=200] -->
-    <string name="wifi_assistant_card_message">Automatically connect to available networks with a Wi\u2011Fi Assistant.</string>
     <!-- Wifi Assistant title.  [CHAR LIMIT=40] -->
     <string name="wifi_assistant_title">Wi\u2011Fi Assistant</string>
-    <!-- Wifi Assistant title message.  First piece of text on the Wifi Assistant setup wizard.  [CHAR LIMIT=200] -->
-    <string name="wifi_assistant_title_message"><xliff:g id="wifi_assistant">%1$s</xliff:g> automatically connects you to the best available Wi\u2011Fi</string>
-    <!-- Wifi Assistant open app button text.  [CHAR LIMIT=40] -->
-    <string name="wifi_assistant_open_app">OPEN APP</string>
 
     <!-- Wifi Display settings. The title of the screen. [CHAR LIMIT=40] -->
     <string name="wifi_display_settings_title">Cast screen</string>
@@ -1505,6 +1493,8 @@
     <string name="wifi_menu_advanced">Advanced</string>
     <!-- Menu option to connect to a Wi-Fi network -->
     <string name="wifi_menu_connect">Connect to network</string>
+    <!-- Menu option to remember a temporary Wi-Fi network -->
+    <string name="wifi_menu_remember">Remember network</string>
     <!-- Menu option to delete a Wi-Fi network -->
     <string name="wifi_menu_forget">Forget network</string>
     <!-- Menu option to modify a Wi-Fi network configuration -->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index cd6883f..0e83d90 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -305,27 +305,6 @@
         <item name="android:textSize">18sp</item>
     </style>
 
-    <style name="WifiAssistantText">
-        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
-        <item name="android:textColor">@android:color/white</item>
-    </style>
-
-    <style name="WifiAssistantButton">
-        <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_width">wrap_content</item>
-        <item name="android:background">@android:color/white</item>
-        <item name="android:paddingStart">@dimen/wifi_assistant_text_padding</item>
-        <item name="android:paddingEnd">@dimen/wifi_assistant_text_padding</item>
-        <item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
-    </style>
-
-    <style name="WifiAssistantButton.Negative">
-    </style>
-
-    <style name="WifiAssistantButton.Positive">
-        <item name="android:textColor">@color/wifi_assistant_color_accent</item>
-    </style>
-
     <!-- Scrollbar style OUTSIDE_OVERLAY -->
     <integer name="preference_scrollbar_style">33554432</integer>
 
diff --git a/src/com/android/settings/sim/SimSettings.java b/src/com/android/settings/sim/SimSettings.java
index 958260b..f09fb2b 100644
--- a/src/com/android/settings/sim/SimSettings.java
+++ b/src/com/android/settings/sim/SimSettings.java
@@ -485,7 +485,7 @@
                 } else {
                     setTitle(mSubInfoRecord.getDisplayName());
                 }
-                setSummary(mSubInfoRecord.getNumber().toString());
+                setSummary(mSubInfoRecord.getNumber());
                 setEnabled(true);
             } else {
                 setSummary(R.string.sim_slot_empty);
diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java
index ffd4bf3..6b6175e 100644
--- a/src/com/android/settings/wifi/AccessPoint.java
+++ b/src/com/android/settings/wifi/AccessPoint.java
@@ -21,7 +21,9 @@
 import android.content.Context;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.StateListDrawable;
+import android.net.NetworkInfo;
 import android.net.NetworkInfo.DetailedState;
+import android.net.NetworkInfo.State;
 import android.net.wifi.ScanResult;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiConfiguration.KeyMgmt;
@@ -70,7 +72,7 @@
     public LruCache<String, ScanResult> mScanResultCache;
 
 
-    private static final String KEY_DETAILEDSTATE = "key_detailedstate";
+    private static final String KEY_NETWORKINFO = "key_networkinfo";
     private static final String KEY_WIFIINFO = "key_wifiinfo";
     private static final String KEY_SCANRESULT = "key_scanresult";
     private static final String KEY_CONFIG = "key_config";
@@ -113,7 +115,8 @@
     private long mSeen = 0;
 
     private WifiInfo mInfo;
-    private DetailedState mState;
+    private NetworkInfo mNetworkInfo;
+    private TextView mSummaryView;
 
     private static final int VISIBILITY_MAX_AGE_IN_MILLI = 1000000;
     private static final int VISIBILITY_OUTDATED_AGE_IN_MILLI = 20000;
@@ -211,18 +214,18 @@
             loadResult(mScanResult);
         }
         mInfo = (WifiInfo) savedState.getParcelable(KEY_WIFIINFO);
-        if (savedState.containsKey(KEY_DETAILEDSTATE)) {
-            mState = DetailedState.valueOf(savedState.getString(KEY_DETAILEDSTATE));
+        if (savedState.containsKey(KEY_NETWORKINFO)) {
+            mNetworkInfo = savedState.getParcelable(KEY_NETWORKINFO);
         }
-        update(mInfo, mState);
+        update(mInfo, mNetworkInfo);
     }
 
     public void saveWifiState(Bundle savedState) {
         savedState.putParcelable(KEY_CONFIG, mConfig);
         savedState.putParcelable(KEY_SCANRESULT, mScanResult);
         savedState.putParcelable(KEY_WIFIINFO, mInfo);
-        if (mState != null) {
-            savedState.putString(KEY_DETAILEDSTATE, mState.toString());
+        if (mNetworkInfo != null) {
+            savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo);
         }
     }
 
@@ -253,9 +256,8 @@
         super.onBindView(view);
         updateIcon(getLevel(), getContext());
 
-        final TextView summaryView = (TextView) view.findViewById(
-                com.android.internal.R.id.summary);
-        summaryView.setVisibility(showSummary ? View.VISIBLE : View.GONE);
+        mSummaryView = (TextView) view.findViewById(com.android.internal.R.id.summary);
+        mSummaryView.setVisibility(showSummary ? View.VISIBLE : View.GONE);
 
         notifyChanged();
     }
@@ -293,8 +295,8 @@
         }
         AccessPoint other = (AccessPoint) preference;
         // Active one goes first.
-        if (mInfo != null && other.mInfo == null) return -1;
-        if (mInfo == null && other.mInfo != null) return 1;
+        if (isActive() && !other.isActive()) return -1;
+        if (!isActive() && other.isActive()) return 1;
 
         // Reachable one goes before unreachable one.
         if (mRssi != Integer.MAX_VALUE && other.mRssi == Integer.MAX_VALUE) return -1;
@@ -361,19 +363,30 @@
         return false;
     }
 
-    void update(WifiInfo info, DetailedState state) {
+    /** Return whether the given {@link WifiInfo} is for this access point. */
+    private boolean isInfoForThisAccessPoint(WifiInfo info) {
+        if (networkId != WifiConfiguration.INVALID_NETWORK_ID) {
+            return networkId == info.getNetworkId();
+        } else {
+            // Might be an ephemeral connection with no WifiConfiguration. Try matching on SSID.
+            // (Note that we only do this if the WifiConfiguration explicitly equals INVALID).
+            // TODO: Handle hex string SSIDs.
+            return ssid.equals(removeDoubleQuotes(info.getSSID()));
+        }
+    }
+
+    void update(WifiInfo info, NetworkInfo networkInfo) {
         boolean reorder = false;
-        if (info != null && networkId != WifiConfiguration.INVALID_NETWORK_ID
-                && networkId == info.getNetworkId()) {
+        if (info != null && isInfoForThisAccessPoint(info)) {
             reorder = (mInfo == null);
             mRssi = info.getRssi();
             mInfo = info;
-            mState = state;
+            mNetworkInfo = networkInfo;
             refresh();
         } else if (mInfo != null) {
             reorder = true;
             mInfo = null;
-            mState = null;
+            mNetworkInfo = null;
             refresh();
         }
         if (reorder) {
@@ -396,8 +409,12 @@
         return mInfo;
     }
 
+    NetworkInfo getNetworkInfo() {
+        return mNetworkInfo;
+    }
+
     DetailedState getState() {
-        return mState;
+        return mNetworkInfo != null ? mNetworkInfo.getDetailedState() : null;
     }
 
     static String removeDoubleQuotes(String string) {
@@ -418,8 +435,11 @@
      *
      * @param showSummary true will show the summary, false will hide the summary
      */
-    public void setShowSummary(boolean showSummary){
+    public void setShowSummary(boolean showSummary) {
         this.showSummary = showSummary;
+        if (mSummaryView != null) {
+            mSummaryView.setVisibility(showSummary ? View.VISIBLE : View.GONE);
+        } // otherwise, will be handled in onBindView.
     }
 
     /**
@@ -571,6 +591,17 @@
     }
 
     /**
+     * Return whether this is the active connection.
+     * For ephemeral connections (networkId is invalid), this returns false if the network is
+     * disconnected.
+     */
+    private boolean isActive() {
+        return mNetworkInfo != null &&
+                (networkId != WifiConfiguration.INVALID_NETWORK_ID ||
+                 mNetworkInfo.getState() != State.DISCONNECTED);
+    }
+
+    /**
      * Updates the title and summary; may indirectly call notifyChanged().
      */
     private void refresh() {
@@ -585,8 +616,8 @@
         // Update to new summary
         StringBuilder summary = new StringBuilder();
 
-        if (mState != null) { // This is the active connection
-            summary.append(Summary.get(context, mState));
+        if (isActive()) {
+            summary.append(Summary.get(context, getState()));
         } else if (mConfig != null && mConfig.noInternetAccess) {
             summary.append(context.getString(R.string.wifi_no_internet));
         } else if (mConfig != null && ((mConfig.status == WifiConfiguration.Status.DISABLED &&
@@ -628,7 +659,7 @@
         if (WifiSettings.mVerboseLogging > 0) {
             //add RSSI/band information for this config, what was seen up to 6 seconds ago
             //verbose WiFi Logging is only turned on thru developers settings
-            if (mInfo != null && mState != null) { // This is the active connection
+            if (mInfo != null && mNetworkInfo != null) { // This is the active connection
                 summary.append(" f=" + Integer.toString(mInfo.getFrequency()));
             }
             summary.append(" " + getVisibilityStatus());
@@ -660,8 +691,9 @@
 
         if (summary.length() > 0) {
             setSummary(summary.toString());
+            setShowSummary(true);
         } else {
-            showSummary = false;
+            setShowSummary(false);
         }
     }
 
diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java
index 29056d7..c185142 100644
--- a/src/com/android/settings/wifi/AdvancedWifiSettings.java
+++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java
@@ -129,7 +129,7 @@
         pref.setIntent(intent);
 
         final Context context = getActivity();
-        NetworkScorerAppData scorer = WifiSettings.getWifiAssistantApp(context);
+        NetworkScorerAppData scorer = getWifiAssistantApp(context);
         SwitchPreference wifiAssistant = (SwitchPreference)findPreference(KEY_WIFI_ASSISTANT);
         if (scorer != null) {
             final boolean checked = NetworkScorerAppManager.getActiveScorer(context) != null;
@@ -265,7 +265,7 @@
                 return true;
             }
 
-            NetworkScorerAppData wifiAssistant = WifiSettings.getWifiAssistantApp(context);
+            NetworkScorerAppData wifiAssistant = getWifiAssistantApp(context);
             Intent intent = new Intent();
             if (wifiAssistant.mConfigurationActivityClassName != null) {
                 // App has a custom configuration activity; launch that.
@@ -316,6 +316,22 @@
         wifiIpAddressPref.setSelectable(false);
     }
 
+    /**
+     * Returns the Network Scorer for the Wifi Assistant App.
+     */
+    public static NetworkScorerAppData getWifiAssistantApp(Context context) {
+        Collection<NetworkScorerAppData> scorers =
+                NetworkScorerAppManager.getAllValidScorers(context);
+
+        if (scorers.isEmpty()) {
+            return null;
+        }
+
+        // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
+        // scorer on the system, we should allow the user to select one.
+        return scorers.iterator().next();
+    }
+
     /* Wrapper class for the WPS dialog to properly handle life cycle events like rotation. */
     public static class WpsFragment extends DialogFragment {
         private static int mWpsSetup;
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 1ef9cce..9dfd201 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -27,22 +27,18 @@
 import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.location.LocationManager;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.NetworkInfo.DetailedState;
-import android.net.NetworkScoreManager;
-import android.net.NetworkScorerAppManager;
-import android.net.NetworkScorerAppManager.NetworkScorerAppData;
+import android.net.NetworkInfo.State;
 import android.net.wifi.ScanResult;
 import android.net.wifi.WifiConfiguration;
 import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.net.wifi.WpsInfo;
-import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -52,14 +48,11 @@
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
-import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
-import android.view.View.OnClickListener;
 import android.widget.AdapterView.AdapterContextMenuInfo;
-import android.widget.Button;
 import android.widget.TextView;
 import android.widget.Toast;
 
@@ -90,8 +83,6 @@
 
     private static final String TAG = "WifiSettings";
 
-    private static final int REQUEST_ENABLE_WIFI_ASSISTANT = 1;
-
     /* package */ static final int MENU_ID_WPS_PBC = Menu.FIRST;
     private static final int MENU_ID_WPS_PIN = Menu.FIRST + 1;
     private static final int MENU_ID_SAVED_NETWORK = Menu.FIRST + 2;
@@ -103,8 +94,6 @@
     private static final int MENU_ID_MODIFY = Menu.FIRST + 8;
     private static final int MENU_ID_WRITE_NFC = Menu.FIRST + 9;
 
-    private static final String KEY_ASSISTANT_DISMISS_PLATFORM = "assistant_dismiss_platform";
-
     public static final int WIFI_DIALOG_ID = 1;
     /* package */ static final int WPS_PBC_DIALOG_ID = 2;
     private static final int WPS_PIN_DIALOG_ID = 3;
@@ -132,7 +121,7 @@
     // An access point being editted is stored here.
     private AccessPoint mSelectedAccessPoint;
 
-    private DetailedState mLastState;
+    private NetworkInfo mLastNetworkInfo;
     private WifiInfo mLastInfo;
 
     private final AtomicBoolean mConnected = new AtomicBoolean(false);
@@ -156,8 +145,6 @@
     private boolean mDlgEdit;
     private AccessPoint mDlgAccessPoint;
     private Bundle mAccessPointSavedState;
-    private View mWifiAssistantCard;
-    private NetworkScorerAppData mWifiAssistantApp;
 
     /** verbose logging flag. this flag is set thru developer debugging options
      * and used so as to assist with in-the-field WiFi connectivity debugging  */
@@ -324,8 +311,6 @@
 
         addPreferencesFromResource(R.xml.wifi_settings);
 
-        prepareWifiAssistantCard();
-
         mEmptyView = initEmptyView();
         registerForContextMenu(getListView());
         setHasOptionsMenu(true);
@@ -349,19 +334,6 @@
     }
 
     @Override
-    public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
-        if (requestCode == REQUEST_ENABLE_WIFI_ASSISTANT) {
-            if (resultCode == Activity.RESULT_OK) {
-                disableWifiAssistantCardUntilPlatformUpgrade();
-                getListView().removeHeaderView(mWifiAssistantCard);
-                mWifiAssistantApp = null;
-            }
-        } else {
-            super.onActivityResult(requestCode, resultCode, resultData);
-        }
-    }
-
-    @Override
     public void onDestroyView() {
         super.onDestroyView();
 
@@ -529,9 +501,22 @@
             if (preference instanceof AccessPoint) {
                 mSelectedAccessPoint = (AccessPoint) preference;
                 menu.setHeaderTitle(mSelectedAccessPoint.ssid);
-                if (mSelectedAccessPoint.getLevel() != -1
-                        && mSelectedAccessPoint.getState() == null) {
-                    menu.add(Menu.NONE, MENU_ID_CONNECT, 0, R.string.wifi_menu_connect);
+                if (mSelectedAccessPoint.getLevel() != -1) {
+                    int connectStringRes = 0;
+                    if (mSelectedAccessPoint.getState() == null) {
+                        connectStringRes = R.string.wifi_menu_connect;
+                    } else if (mSelectedAccessPoint.networkId == INVALID_NETWORK_ID &&
+                            mSelectedAccessPoint.getNetworkInfo().getState()
+                                != State.DISCONNECTED) {
+                        // State is non-null (and not disconnected) but this network has no
+                        // configuration, which means it is ephemeral. Allow the user to save the
+                        // configuration permanently (but still issue this as a CONNECT command).
+                        connectStringRes = R.string.wifi_menu_remember;
+                    }
+
+                    if (connectStringRes != 0) {
+                        menu.add(Menu.NONE, MENU_ID_CONNECT, 0, connectStringRes);
+                    }
                 }
                 if (mSelectedAccessPoint.networkId != INVALID_NETWORK_ID) {
                     if (ActivityManager.getCurrentUser() == UserHandle.USER_OWNER) {
@@ -671,17 +656,13 @@
             case WifiManager.WIFI_STATE_ENABLED:
                 // AccessPoints are automatically sorted with TreeSet.
                 final Collection<AccessPoint> accessPoints =
-                        constructAccessPoints(getActivity(), mWifiManager, mLastInfo, mLastState);
+                        constructAccessPoints(getActivity(), mWifiManager, mLastInfo,
+                                mLastNetworkInfo);
                 getPreferenceScreen().removeAll();
                 if (accessPoints.size() == 0) {
                     addMessagePreference(R.string.wifi_empty_list_wifi_on);
                 }
 
-                getListView().removeHeaderView(mWifiAssistantCard);
-                if (mWifiAssistantApp != null) {
-                    getListView().addHeaderView(mWifiAssistantCard);
-                }
-
                 for (AccessPoint accessPoint : accessPoints) {
                     // Ignore access points that are out of range.
                     if (accessPoint.getLevel() != -1) {
@@ -704,102 +685,6 @@
         }
     }
 
-    /**
-     * Returns the Network Scorer for the Wifi Assistant App.
-     */
-    public static NetworkScorerAppData getWifiAssistantApp(Context context) {
-        Collection<NetworkScorerAppData> scorers =
-                NetworkScorerAppManager.getAllValidScorers(context);
-
-        if (scorers.isEmpty()) {
-            return null;
-        }
-
-        // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
-        // scorer on the system, we should allow the user to select one.
-        return scorers.iterator().next();
-    }
-
-    private void prepareWifiAssistantCard() {
-        if (getActivity() instanceof WifiPickerActivity) {
-            return;
-        }
-
-        if (NetworkScorerAppManager.getActiveScorer(getActivity()) != null) {
-            // A scorer is already enabled; don't show the card.
-            return;
-        }
-
-        Collection<NetworkScorerAppData> scorers =
-                NetworkScorerAppManager.getAllValidScorers(getActivity());
-        if (scorers.isEmpty()) {
-            // No scorers are available to enable; don't show the card.
-            return;
-        }
-
-        SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
-        int lastDismissPlatform = sharedPreferences.getInt(KEY_ASSISTANT_DISMISS_PLATFORM, 0);
-
-        if (Build.VERSION.SDK_INT <= lastDismissPlatform) {
-            // User has dismissed the Wi-Fi assistant card on this SDK release. Suppress the card
-            // until the next major platform upgrade.
-            return;
-        }
-
-        // TODO: b/13780935 - Implement proper scorer selection. Rather than pick the first
-        // scorer on the system, we should allow the user to select one.
-        mWifiAssistantApp = scorers.iterator().next();
-
-        if (mWifiAssistantCard == null) {
-            mWifiAssistantCard = LayoutInflater.from(getActivity())
-                    .inflate(R.layout.wifi_assistant_card, getListView(), false);
-            Button setup = (Button) mWifiAssistantCard.findViewById(R.id.setup);
-            Button noThanks = (Button) mWifiAssistantCard.findViewById(R.id.no_thanks_button);
-            TextView assistantText =
-                (TextView) mWifiAssistantCard.findViewById(R.id.wifi_assistant_text);
-            assistantText.setText(getResources().getString(
-                    R.string.wifi_assistant_title_message, mWifiAssistantApp.mScorerName));
-
-            if (setup != null && noThanks != null) {
-                setup.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        Intent intent = new Intent();
-                        if (mWifiAssistantApp.mConfigurationActivityClassName != null) {
-                            // App has a custom configuration activity; launch that.
-                            // This custom activity will be responsible for launching the system
-                            // dialog.
-                            intent.setClassName(mWifiAssistantApp.mPackageName,
-                                    mWifiAssistantApp.mConfigurationActivityClassName);
-                        } else {
-                            // Fall back on the system dialog.
-                            intent.setAction(NetworkScoreManager.ACTION_CHANGE_ACTIVE);
-                            intent.putExtra(NetworkScoreManager.EXTRA_PACKAGE_NAME,
-                                    mWifiAssistantApp.mPackageName);
-                        }
-                        startActivityForResult(intent, REQUEST_ENABLE_WIFI_ASSISTANT);
-                    }
-                });
-
-                noThanks.setOnClickListener(new OnClickListener() {
-                    @Override
-                    public void onClick(View v) {
-                        disableWifiAssistantCardUntilPlatformUpgrade();
-                        getListView().removeHeaderView(mWifiAssistantCard);
-                        mWifiAssistantApp = null;
-                    }
-                });
-            }
-        }
-    }
-
-    private void disableWifiAssistantCardUntilPlatformUpgrade() {
-        SharedPreferences sharedPreferences = getPreferenceScreen().getSharedPreferences();
-        SharedPreferences.Editor editor = sharedPreferences.edit();
-        editor.putInt(KEY_ASSISTANT_DISMISS_PLATFORM, Build.VERSION.SDK_INT);
-        editor.apply();
-    }
-
     protected TextView initEmptyView() {
         TextView emptyView = (TextView) getActivity().findViewById(android.R.id.empty);
         getListView().setEmptyView(emptyView);
@@ -833,7 +718,7 @@
 
     /** Returns sorted list of access points */
     private static List<AccessPoint> constructAccessPoints(Context context,
-            WifiManager wifiManager, WifiInfo lastInfo, DetailedState lastState) {
+            WifiManager wifiManager, WifiInfo lastInfo, NetworkInfo lastNetworkInfo) {
         ArrayList<AccessPoint> accessPoints = new ArrayList<AccessPoint>();
         /** Lookup table to more quickly update AccessPoints by only considering objects with the
          * correct SSID.  Maps SSID -> List of AccessPoints with the given SSID.  */
@@ -853,8 +738,8 @@
                     continue;
                 }
                 AccessPoint accessPoint = new AccessPoint(context, config);
-                if (lastInfo != null && lastState != null) {
-                    accessPoint.update(lastInfo, lastState);
+                if (lastInfo != null && lastNetworkInfo != null) {
+                    accessPoint.update(lastInfo, lastNetworkInfo);
                 }
                 accessPoints.add(accessPoint);
                 apMap.put(accessPoint.ssid, accessPoint);
@@ -877,6 +762,9 @@
                 }
                 if (!found) {
                     AccessPoint accessPoint = new AccessPoint(context, result);
+                    if (lastInfo != null && lastNetworkInfo != null) {
+                        accessPoint.update(lastInfo, lastNetworkInfo);
+                    }
                     accessPoints.add(accessPoint);
                     apMap.put(accessPoint.ssid, accessPoint);
                 }
@@ -903,28 +791,29 @@
             mConnected.set(info.isConnected());
             changeNextButtonState(info.isConnected());
             updateAccessPoints();
-            updateConnectionState(info.getDetailedState());
+            updateNetworkInfo(info);
         } else if (WifiManager.RSSI_CHANGED_ACTION.equals(action)) {
-            updateConnectionState(null);
+            updateNetworkInfo(null);
         }
     }
 
-    private void updateConnectionState(DetailedState state) {
+    private void updateNetworkInfo(NetworkInfo networkInfo) {
         /* sticky broadcasts can call this when wifi is disabled */
         if (!mWifiManager.isWifiEnabled()) {
             mScanner.pause();
             return;
         }
 
-        if (state == DetailedState.OBTAINING_IPADDR) {
+        if (networkInfo != null &&
+                networkInfo.getDetailedState() == DetailedState.OBTAINING_IPADDR) {
             mScanner.pause();
         } else {
             mScanner.resume();
         }
 
         mLastInfo = mWifiManager.getConnectionInfo();
-        if (state != null) {
-            mLastState = state;
+        if (networkInfo != null) {
+            mLastNetworkInfo = networkInfo;
         }
 
         for (int i = getPreferenceScreen().getPreferenceCount() - 1; i >= 0; --i) {
@@ -932,7 +821,7 @@
             Preference preference = getPreferenceScreen().getPreference(i);
             if (preference instanceof AccessPoint) {
                 final AccessPoint accessPoint = (AccessPoint) preference;
-                accessPoint.update(mLastInfo, mLastState);
+                accessPoint.update(mLastInfo, mLastNetworkInfo);
             }
         }
     }
@@ -958,7 +847,7 @@
         }
 
         mLastInfo = null;
-        mLastState = null;
+        mLastNetworkInfo = null;
         mScanner.pause();
     }