Merge changes from topic "rtt-settings-change-cp"

* changes:
  Remove the RTT info panel when not needed
  Add space in RTT setting title.
  Add more information text into RTT settings.
  Add strings for RTT settings UI.
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index f6d1b79..42f9563 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -110,4 +110,7 @@
     <dimen name="floating_action_button_margin_bottom">32dp</dimen>
 
     <dimen name="signal_strength_icon_size">24dp</dimen>
+
+    <!-- The size of the "emergency calling unavailable" message shown in the emergency dialer -->
+    <dimen name="emergency_call_warning_size">16sp</dimen>
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f1c586b..e7e2571 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1131,6 +1131,9 @@
     <string name="dial_emergency_error">Can\'t call. <xliff:g id="non_emergency_number">%s</xliff:g> is not an emergency number.</string>
     <!-- Emergency dialer: message displayed in an error dialog -->
     <string name="dial_emergency_empty_error">Can\'t call. Dial an emergency number.</string>
+    <!-- Message displayed over top of the emergency dialer dialpad indicating to the user that
+         emergency calling is not currently available. -->
+    <string name="dial_emergency_calling_not_available">Emergency calling not available</string>
 
     <!-- Displayed in the text entry box in the dialer when in landscape mode to guide the user
          to dial using the physical keyboard -->
diff --git a/src/com/android/phone/EmergencyDialer.java b/src/com/android/phone/EmergencyDialer.java
index a98c201..31e1958 100644
--- a/src/com/android/phone/EmergencyDialer.java
+++ b/src/com/android/phone/EmergencyDialer.java
@@ -16,10 +16,11 @@
 
 package com.android.phone;
 
+import static android.telephony.ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
+
 import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.Dialog;
-import android.app.StatusBarManager;
 import android.app.WallpaperManager;
 import android.content.BroadcastReceiver;
 import android.content.Context;
@@ -29,6 +30,7 @@
 import android.media.AudioManager;
 import android.media.ToneGenerator;
 import android.net.Uri;
+import android.os.AsyncTask;
 import android.os.Bundle;
 import android.os.PersistableBundle;
 import android.provider.Settings;
@@ -36,7 +38,9 @@
 import android.telecom.TelecomManager;
 import android.telephony.CarrierConfigManager;
 import android.telephony.PhoneNumberUtils;
+import android.telephony.ServiceState;
 import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
 import android.text.Editable;
 import android.text.InputType;
 import android.text.Spannable;
@@ -46,19 +50,20 @@
 import android.text.method.DialerKeyListener;
 import android.text.style.TtsSpan;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.HapticFeedbackConstants;
 import android.view.KeyEvent;
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.WindowManager;
-import android.widget.EditText;
 
 import com.android.internal.colorextraction.ColorExtractor;
 import com.android.internal.colorextraction.ColorExtractor.GradientColors;
 import com.android.internal.colorextraction.drawable.GradientDrawable;
 import com.android.phone.common.dialpad.DialpadKeyButton;
 import com.android.phone.common.util.ViewUtil;
+import com.android.phone.common.widget.ResizingTextEditText;
 
 /**
  * EmergencyDialer is a special dialer that is used ONLY for dialing emergency calls.
@@ -111,7 +116,7 @@
     /** 90% opacity, different from other gradients **/
     private static final int BACKGROUND_GRADIENT_ALPHA = 230;
 
-    EditText mDigits;
+    ResizingTextEditText mDigits;
     private View mDialButton;
     private View mDelete;
 
@@ -140,6 +145,9 @@
     private GradientDrawable mBackgroundGradient;
     private boolean mSupportsDarkText;
 
+    private boolean mIsWfcEmergencyCallingWarningEnabled;
+    private float mDefaultDigitsTextSize;
+
     @Override
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
         // Do nothing
@@ -147,7 +155,7 @@
 
     @Override
     public void onTextChanged(CharSequence input, int start, int before, int changeCount) {
-        // Do nothing
+        maybeChangeHintSize();
     }
 
     @Override
@@ -191,12 +199,13 @@
 
         setContentView(R.layout.emergency_dialer);
 
-        mDigits = (EditText) findViewById(R.id.digits);
+        mDigits = (ResizingTextEditText) findViewById(R.id.digits);
         mDigits.setKeyListener(DialerKeyListener.getInstance());
         mDigits.setOnClickListener(this);
         mDigits.setOnKeyListener(this);
         mDigits.setLongClickable(false);
         mDigits.setInputType(InputType.TYPE_NULL);
+        mDefaultDigitsTextSize = mDigits.getScaledTextSize();
         maybeAddNumberFormatting();
 
         mBackgroundGradient = new GradientDrawable(this);
@@ -226,11 +235,16 @@
                 (CarrierConfigManager) getSystemService(Context.CARRIER_CONFIG_SERVICE);
         PersistableBundle carrierConfig =
                 configMgr.getConfigForSubId(SubscriptionManager.getDefaultVoiceSubscriptionId());
+
         if (carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_ONSCREEN_DIAL_BUTTON_BOOL)) {
             mDialButton.setOnClickListener(this);
         } else {
             mDialButton.setVisibility(View.GONE);
         }
+        mIsWfcEmergencyCallingWarningEnabled = carrierConfig.getInt(
+                CarrierConfigManager.KEY_EMERGENCY_NOTIFICATION_DELAY_INT) > -1;
+        maybeShowWfcEmergencyCallingWarning();
+
         ViewUtil.setupFloatingActionButton(mDialButton, getResources());
 
         if (icicle != null) {
@@ -522,13 +536,6 @@
     @Override
     public void onPause() {
         super.onPause();
-
-        synchronized (mToneGeneratorLock) {
-            if (mToneGenerator != null) {
-                mToneGenerator.release();
-                mToneGenerator = null;
-            }
-        }
     }
 
     @Override
@@ -662,7 +669,7 @@
 
             // blur stuff behind the dialog
             dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
-            dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
+            setShowWhenLocked(true);
         }
         return dialog;
     }
@@ -726,4 +733,68 @@
             updateTheme(colors.supportsDarkText());
         }
     }
+
+    /**
+     * Where a carrier requires a warning that emergency calling is not available while on WFC,
+     * add hint text above the dial pad which warns the user of this case.
+     */
+    private void maybeShowWfcEmergencyCallingWarning() {
+        if (!mIsWfcEmergencyCallingWarningEnabled) {
+            Log.i(LOG_TAG, "maybeShowWfcEmergencyCallingWarning: warning disabled by carrier.");
+            return;
+        }
+
+        // Use an async task rather than calling into Telephony on UI thread.
+        AsyncTask<Void, Void, Boolean> showWfcWarningTask = new AsyncTask<Void, Void, Boolean>() {
+            @Override
+            protected Boolean doInBackground(Void... voids) {
+                TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
+                boolean isWfcAvailable = tm.isWifiCallingAvailable();
+                ServiceState ss = tm.getServiceState();
+                boolean isCellAvailable =
+                        ss.getRilVoiceRadioTechnology() != RIL_RADIO_TECHNOLOGY_UNKNOWN;
+                Log.i(LOG_TAG, "showWfcWarningTask: isWfcAvailable=" + isWfcAvailable
+                                + " isCellAvailable=" + isCellAvailable
+                                + "(rat=" + ss.getRilVoiceRadioTechnology() + ")");
+                return isWfcAvailable && !isCellAvailable;
+            }
+
+            @Override
+            protected void onPostExecute(Boolean result) {
+                if (result.booleanValue()) {
+                    Log.i(LOG_TAG, "showWfcWarningTask: showing ecall warning");
+                    mDigits.setHint(R.string.dial_emergency_calling_not_available);
+                } else {
+                    Log.i(LOG_TAG, "showWfcWarningTask: hiding ecall warning");
+                    mDigits.setHint("");
+                }
+                maybeChangeHintSize();
+            }
+        };
+        showWfcWarningTask.execute((Void) null);
+    }
+
+    /**
+     * Where a hint is applied and there are no digits dialed, disable autoresize of the dial digits
+     * edit view and set the font size to a smaller size appropriate for the emergency calling
+     * warning.
+     */
+    private void maybeChangeHintSize() {
+        if (TextUtils.isEmpty(mDigits.getHint())
+                || !TextUtils.isEmpty(mDigits.getText().toString())) {
+            // No hint or there are dialed digits, so use default size.
+            mDigits.setTextSize(TypedValue.COMPLEX_UNIT_SP, mDefaultDigitsTextSize);
+            // By default, the digits view auto-resizes to fit the text it contains, so
+            // enable that now.
+            mDigits.setResizeEnabled(true);
+            Log.i(LOG_TAG, "no hint - setting to " + mDigits.getScaledTextSize());
+        } else {
+            // Hint present and no dialed digits, set custom font size appropriate for the warning.
+            mDigits.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(
+                    R.dimen.emergency_call_warning_size));
+            // Since we're populating this with a static text string, disable auto-resize.
+            mDigits.setResizeEnabled(false);
+            Log.i(LOG_TAG, "hint - setting to " + mDigits.getScaledTextSize());
+        }
+    }
 }
diff --git a/src/com/android/phone/NetworkOperators.java b/src/com/android/phone/NetworkOperators.java
index babd283..44af267 100644
--- a/src/com/android/phone/NetworkOperators.java
+++ b/src/com/android/phone/NetworkOperators.java
@@ -88,9 +88,9 @@
         mChooseNetwork = findPreference(BUTTON_CHOOSE_NETWORK_KEY);
         mNetworkSelect = (NetworkSelectListPreference) findPreference(BUTTON_NETWORK_SELECT_KEY);
         if (mEnableNewManualSelectNetworkUI) {
-            this.removePreference(mNetworkSelect);
+            removePreference(mNetworkSelect);
         } else {
-            this.removePreference(mChooseNetwork);
+            removePreference(mChooseNetwork);
         }
         mProgressDialog = new ProgressDialog(getContext());
     }
@@ -113,7 +113,7 @@
             if (mChooseNetwork != null) {
                 TelephonyManager telephonyManager = (TelephonyManager)
                         getContext().getSystemService(Context.TELEPHONY_SERVICE);
-                logd("data connection status " + telephonyManager.getDataState());
+                if (DBG) logd("data connection status " + telephonyManager.getDataState());
                 if (telephonyManager.getDataState() == telephonyManager.DATA_CONNECTED) {
                     mChooseNetwork.setSummary(telephonyManager.getNetworkOperatorName());
                 } else {
@@ -139,7 +139,7 @@
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         if (preference == mAutoSelect) {
             boolean autoSelect = (Boolean) newValue;
-            logd("onPreferenceChange autoSelect: " + String.valueOf(autoSelect));
+            if (DBG) logd("onPreferenceChange autoSelect: " + String.valueOf(autoSelect));
             selectNetworkAutomatic(autoSelect);
             MetricsLogger.action(getContext(),
                     MetricsEvent.ACTION_MOBILE_NETWORK_AUTO_SELECT_NETWORK_TOGGLE, autoSelect);
@@ -196,7 +196,6 @@
                         }
                     }
             }
-
             return;
         }
     };
@@ -241,7 +240,7 @@
     }
 
     private void selectNetworkAutomatic(boolean autoSelect) {
-        logd("selectNetworkAutomatic: " + String.valueOf(autoSelect));
+        if (DBG) logd("selectNetworkAutomatic: " + String.valueOf(autoSelect));
         if (mEnableNewManualSelectNetworkUI) {
             if (mChooseNetwork != null) {
                 mChooseNetwork.setEnabled(!autoSelect);
@@ -309,7 +308,7 @@
 
     protected boolean preferenceTreeClick(Preference preference) {
         if (mEnableNewManualSelectNetworkUI) {
-            logd("enable New AutoSelectNetwork UI");
+            if (DBG) logd("enable New AutoSelectNetwork UI");
             if (preference == mChooseNetwork) {
                 openChooseNetworkPage();
             }
diff --git a/src/com/android/phone/NetworkSelectListPreference.java b/src/com/android/phone/NetworkSelectListPreference.java
index a8f29c9..4bb03b0 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -33,11 +33,6 @@
 import android.telephony.CellInfoGsm;
 import android.telephony.CellInfoLte;
 import android.telephony.CellInfoWcdma;
-import android.telephony.CellSignalStrengthCdma;
-import android.telephony.CellSignalStrengthGsm;
-import android.telephony.CellSignalStrengthLte;
-import android.telephony.CellSignalStrengthWcdma;
-import android.telephony.NetworkScan;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.text.BidiFormatter;
@@ -70,8 +65,7 @@
 
     private static final int EVENT_NETWORK_SELECTION_DONE = 1;
     private static final int EVENT_NETWORK_SCAN_RESULTS = 2;
-    private static final int EVENT_NETWORK_SCAN_ERROR = 3;
-    private static final int EVENT_NETWORK_SCAN_COMPLETED = 4;
+    private static final int EVENT_NETWORK_SCAN_COMPLETED = 3;
 
     //dialog ids
     private static final int DIALOG_NETWORK_SELECTION = 100;
@@ -83,7 +77,6 @@
 
     private int mSubId;
     private NetworkOperators mNetworkOperators;
-    private boolean mNeedScanAgain;
 
     private ProgressDialog mProgressDialog;
     public NetworkSelectListPreference(Context context, AttributeSet attrs) {
@@ -98,8 +91,10 @@
     @Override
     protected void onClick() {
         sendMetricsEvent(null);
-        // Scan the network with setting the isIncrementalResult as true via TelephonyManager first.
-        loadNetworksList(true);
+        // Start the one-time network scan via {@link Phone#getAvailableNetworks()}.
+        // {@link NetworkQueryService will return a {@link onResults()} callback first with a list
+        // of CellInfo, and then will return a {@link onComplete} indicating the scan completed.
+        loadNetworksList();
     }
 
     private final Handler mHandler = new Handler() {
@@ -132,86 +127,22 @@
                 case EVENT_NETWORK_SCAN_RESULTS:
                     List<CellInfo> results = (List<CellInfo>) msg.obj;
                     results.removeIf(cellInfo -> cellInfo == null);
-                    if (results.size() > 0) {
-                        boolean isInvalidCellInfoList = true;
-                        // Regard the list as invalid only if all the elements in the list are
-                        // invalid.
-                        for (CellInfo cellInfo : results) {
-                            if (!isInvalidCellInfo(cellInfo)) {
-                                isInvalidCellInfoList = false;
-                                break;
-                            }
-                        }
-                        if (isInvalidCellInfoList) {
-                            mNeedScanAgain = true;
-                            if (DBG) {
-                                logd("Invalid cell info. Stop current network scan "
-                                        + "and start a new one via old API");
-                            }
-                            // Stop current network scan flow. This behavior will result in a
-                            // onComplete() callback, after which we will start a new network query
-                            // via Phone.getAvailableNetworks(). This behavior might also result in
-                            // a onError() callback if the modem did not stop network query
-                            // successfully. In this case we will display network query failed
-                            // instead of resending a new request.
-                            try {
-                                if (mNetworkQueryService != null) {
-                                    mNetworkQueryService.stopNetworkQuery();
-                                }
-                            } catch (RemoteException e) {
-                                loge("exception from stopNetworkQuery " + e);
-                            }
-                        } else {
-                            // TODO(b/70530820): Display the scan results incrementally after
-                            // finalizing the UI desing on Mobile Network Setting page. For now,
-                            // just update the CellInfo list when received the onResult callback,
-                            // and display the scan result when received the onComplete callback
-                            // in the end.
-                            mCellInfoList = new ArrayList<>(results);
-                            if (DBG) logd("CALLBACK_SCAN_RESULTS" + mCellInfoList.toString());
-                        }
-                    }
+                    mCellInfoList = new ArrayList<>(results);
+                    if (DBG) logd("CALLBACK_SCAN_RESULTS" + mCellInfoList.toString());
 
                     break;
 
-                case EVENT_NETWORK_SCAN_ERROR:
-                    int error = msg.arg1;
-                    if (DBG) logd("error while querying available networks " + error);
-                    if (error == NetworkScan.ERROR_UNSUPPORTED) {
-                        if (DBG) {
-                            logd("Modem does not support: try to scan network again via Phone");
-                        }
-                        loadNetworksList(false);
-                    } else {
-                        try {
-                            if (mNetworkQueryService != null) {
-                                mNetworkQueryService.unregisterCallback(mCallback);
-                            }
-                        } catch (RemoteException e) {
-                            loge("onError: exception from unregisterCallback " + e);
-                        }
-                        displayNetworkQueryFailed(error);
-                    }
-                    break;
-
                 case EVENT_NETWORK_SCAN_COMPLETED:
-                    if (mNeedScanAgain) {
-                        logd("CellInfo is invalid to display. Start a new scan via Phone. ");
-                        loadNetworksList(false);
-                        mNeedScanAgain = false;
-                    } else {
-                        try {
-                            if (mNetworkQueryService != null) {
-                                mNetworkQueryService.unregisterCallback(mCallback);
-                            }
-                        } catch (RemoteException e) {
-                            loge("onComplete: exception from unregisterCallback " + e);
+                    try {
+                        if (mNetworkQueryService != null) {
+                            mNetworkQueryService.unregisterCallback(mCallback);
                         }
-                        if (DBG) logd("scan complete, load the cellInfosList");
-                        // Modify UI to indicate users that the scan has completed.
-                        networksListLoaded();
+                    } catch (RemoteException e) {
+                        loge("onComplete: exception from unregisterCallback " + e);
                     }
-                    break;
+                    if (DBG) logd("scan complete, load the cellInfosList");
+                    // Modify UI to indicate users that the scan has completed.
+                    networksListLoaded();
             }
             return;
         }
@@ -224,7 +155,7 @@
      */
     private final INetworkQueryServiceCallback mCallback = new INetworkQueryServiceCallback.Stub() {
 
-        /** Returns the scan results to the user, this callback will be called at lease one time. */
+        /** Returns the scan results to the user, this callback will be called only one time. */
         public void onResults(List<CellInfo> results) {
             if (DBG) logd("get scan results.");
             Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results);
@@ -244,16 +175,9 @@
         }
 
         /**
-         * Informs the user that there is some error about the scan.
-         *
-         * This callback will be called whenever there is any error about the scan, and the scan
-         * will be terminated. onComplete() will NOT be called.
+         * This callback will not be called, since the old Scan API won't send this callback.
          */
-        public void onError(int error) {
-            if (DBG) logd("get onError callback with error code: " + error);
-            Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_ERROR, error, 0 /* arg2 */);
-            msg.sendToTarget();
-        }
+        public void onError(int error) {}
     };
 
     @Override
@@ -298,7 +222,6 @@
         mNetworkOperators = networkOperators;
         // This preference should share the same progressDialog with networkOperators category.
         mProgressDialog = progressDialog;
-        mNeedScanAgain = false;
 
         if (SubscriptionManager.isValidSubscriptionId(mSubId)) {
             mPhoneId = SubscriptionManager.getPhoneId(mSubId);
@@ -361,17 +284,14 @@
                 NotificationMgr.NETWORK_SELECTION_NOTIFICATION, status);
     }
 
-    private void loadNetworksList(boolean isIncrementalResult) {
+    private void loadNetworksList() {
         if (DBG) logd("load networks list...");
 
-        if (!mNeedScanAgain) {
-            // Avoid blinking while showing the dialog again.
-            showProgressDialog(DIALOG_NETWORK_LIST_LOAD);
-        }
+        showProgressDialog(DIALOG_NETWORK_LIST_LOAD);
 
         try {
             if (mNetworkQueryService != null) {
-                mNetworkQueryService.startNetworkQuery(mCallback, mPhoneId, isIncrementalResult);
+                mNetworkQueryService.startNetworkQuery(mCallback, mPhoneId, false);
             } else {
                 displayNetworkQueryFailed(NetworkQueryService.QUERY_EXCEPTION);
             }
@@ -399,7 +319,6 @@
         }
 
         setEnabled(true);
-
         if (mCellInfoList != null) {
             // create a preference for each item in the list.
             // just use the operator name instead of the mildly
@@ -554,46 +473,6 @@
         return oi;
     }
 
-
-    /**
-     * Check if the CellInfo is valid to display. If a CellInfo has signal strength but does
-     * not have operator info, it is invalid to display.
-     */
-    private boolean isInvalidCellInfo(CellInfo cellInfo) {
-        if (DBG) logd("Check isInvalidCellInfo: " + cellInfo.toString());
-        CharSequence al = null;
-        CharSequence as = null;
-        boolean hasSignalStrength = false;
-        if (cellInfo instanceof CellInfoLte) {
-            CellInfoLte lte = (CellInfoLte) cellInfo;
-            al = lte.getCellIdentity().getOperatorAlphaLong();
-            as = lte.getCellIdentity().getOperatorAlphaShort();
-            hasSignalStrength = !lte.getCellSignalStrength().equals(new CellSignalStrengthLte());
-        } else if (cellInfo instanceof CellInfoWcdma) {
-            CellInfoWcdma wcdma = (CellInfoWcdma) cellInfo;
-            al = wcdma.getCellIdentity().getOperatorAlphaLong();
-            as = wcdma.getCellIdentity().getOperatorAlphaShort();
-            hasSignalStrength = !wcdma.getCellSignalStrength().equals(
-                    new CellSignalStrengthWcdma());
-        } else if (cellInfo instanceof CellInfoGsm) {
-            CellInfoGsm gsm = (CellInfoGsm) cellInfo;
-            al = gsm.getCellIdentity().getOperatorAlphaLong();
-            as = gsm.getCellIdentity().getOperatorAlphaShort();
-            hasSignalStrength = !gsm.getCellSignalStrength().equals(new CellSignalStrengthGsm());
-        } else if (cellInfo instanceof CellInfoCdma) {
-            CellInfoCdma cdma = (CellInfoCdma) cellInfo;
-            al = cdma.getCellIdentity().getOperatorAlphaLong();
-            as = cdma.getCellIdentity().getOperatorAlphaShort();
-            hasSignalStrength = !cdma.getCellSignalStrength().equals(new CellSignalStrengthCdma());
-        } else {
-            return true;
-        }
-        if (TextUtils.isEmpty(al) && TextUtils.isEmpty(as) && hasSignalStrength) {
-            return true;
-        }
-        return false;
-    }
-
     @Override
     protected Parcelable onSaveInstanceState() {
         final Parcelable superState = super.onSaveInstanceState();
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index 7ef3dea..ff918e2 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -15,6 +15,7 @@
  */
 package com.android.phone;
 
+import android.app.ActionBar;
 import android.app.Activity;
 import android.content.ComponentName;
 import android.content.Context;
@@ -60,7 +61,7 @@
 public class NetworkSelectSetting extends PreferenceFragment {
 
     private static final String TAG = "NetworkSelectSetting";
-    private static final boolean DBG = true;
+    private static final boolean DBG = false;
 
     private static final int EVENT_NETWORK_SELECTION_DONE = 1;
     private static final int EVENT_NETWORK_SCAN_RESULTS = 2;
@@ -132,6 +133,12 @@
         // Inflate progress bar
         final Activity activity = getActivity();
         if (activity != null) {
+            ActionBar actionBar = activity.getActionBar();
+            if (actionBar != null) {
+                // android.R.id.home will be triggered in
+                // {@link NetworkSelectSettingAcitivity#onOptionsItemSelected()}
+                actionBar.setDisplayHomeAsUpEnabled(true);
+            }
             mFrameLayout = activity.findViewById(R.id.choose_network_content);
             final LayoutInflater inflater = activity.getLayoutInflater();
             final View pinnedHeader =
@@ -256,13 +263,13 @@
 
                     ar = (AsyncResult) msg.obj;
                     if (ar.exception != null) {
-                        mNetworkOperators.displayNetworkSelectionFailed(ar.exception);
+                        if (DBG) logd("manual network selection: failed! ");
+                        updateNetworkSelection();
                         // Set summary as "Couldn't connect" to the selected network.
                         mSelectedNetworkOperatorPreference.setSummary(
                                 R.string.network_could_not_connect);
                     } else {
                         if (DBG) logd("manual network selection: succeeded! ");
-                        mNetworkOperators.displayNetworkSelectionSucceeded(msg.arg1);
                         // Set summary as "Connected" to the selected network.
                         mSelectedNetworkOperatorPreference.setSummary(R.string.network_connected);
                     }
@@ -290,7 +297,6 @@
                 case EVENT_NETWORK_SCAN_COMPLETED:
                     stopNetworkQuery();
                     if (DBG) logd("scan complete");
-                    setProgressBarVisible(false);
                     if (mCellInfoList == null) {
                         // In case the scan timeout before getting any results
                         addMessagePreference(R.string.empty_networks_list);
@@ -611,6 +617,22 @@
         }
     }
 
+    /**
+     * Call {@link NotificationMgr#updateNetworkSelection(int, int)} to send notification about
+     * no service of user selected operator
+     */
+    private void updateNetworkSelection() {
+        if (DBG) logd("Update notification about no service of user selected operator");
+        final PhoneGlobals app = PhoneGlobals.getInstance();
+        Phone phone = PhoneFactory.getPhone(mPhoneId);
+        if (phone != null) {
+            ServiceState ss = mTelephonyManager.getServiceStateForSubscriber(phone.getSubId());
+            if (ss != null) {
+                app.notificationMgr.updateNetworkSelection(ss.getState(), phone.getSubId());
+            }
+        }
+    }
+
     private void stopNetworkQuery() {
         // Stop the network query process
         try {
diff --git a/src/com/android/phone/NetworkSelectSettingActivity.java b/src/com/android/phone/NetworkSelectSettingActivity.java
index 2f730ad..a151c81 100644
--- a/src/com/android/phone/NetworkSelectSettingActivity.java
+++ b/src/com/android/phone/NetworkSelectSettingActivity.java
@@ -23,6 +23,7 @@
 import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
+import android.view.MenuItem;
 
 
 /**
@@ -57,4 +58,14 @@
                     .commit();
         }
     }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        final int itemId = item.getItemId();
+        if (itemId == android.R.id.home) {
+            onBackPressed();
+            return true;
+        }
+        return super.onOptionsItemSelected(item);
+    }
 }
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index de41481..e7f28d7 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -2135,10 +2135,7 @@
      */
     @Override
     public int getVoiceActivationState(int subId, String callingPackage) {
-        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
-                mApp, subId, callingPackage, "getVoiceActivationStateForSubscriber")) {
-            return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
-        }
+        enforceReadPrivilegedPermission();
         final Phone phone = getPhone(subId);
         if (phone != null) {
             return phone.getVoiceActivationState();
@@ -2152,10 +2149,7 @@
      */
     @Override
     public int getDataActivationState(int subId, String callingPackage) {
-        if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
-                mApp, subId, callingPackage, "getDataActivationStateForSubscriber")) {
-            return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
-        }
+        enforceReadPrivilegedPermission();
         final Phone phone = getPhone(subId);
         if (phone != null) {
             return phone.getDataActivationState();
diff --git a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
index 6ddebb8..3d83a4c 100644
--- a/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
+++ b/testapps/EmbmsServiceTestApp/src/com/android/phone/testapps/embmsmw/EmbmsSampleDownloadService.java
@@ -271,7 +271,8 @@
     }
 
     private void sendFdRequest(DownloadRequest request, FrontendAppIdentifier appKey) {
-        int numFds = getNumFdsNeededForRequest(request);
+        // Request twice as many as needed to exercise the post-download cleanup mechanism
+        int numFds = getNumFdsNeededForRequest(request) * 2;
         // Compose the FILE_DESCRIPTOR_REQUEST_INTENT
         Intent requestIntent = new Intent(VendorUtils.ACTION_FILE_DESCRIPTOR_REQUEST);
         requestIntent.putExtra(VendorUtils.EXTRA_SERVICE_ID, request.getFileServiceId());
@@ -309,8 +310,8 @@
                 .getFileServiceInfoForId(request.getFileServiceId())
                 .getFiles();
 
-        if (tempFiles.size() != filesToDownload.size()) {
-            Log.w(LOG_TAG, "Different numbers of temp files and files to download...");
+        if (tempFiles.size() != filesToDownload.size() * 2) {
+            Log.w(LOG_TAG, "Incorrect numbers of temp files and files to download...");
         }
 
         if (!mActiveDownloadRequests.containsKey(appKey)) {
@@ -320,28 +321,29 @@
 
         // Go through the files one-by-one and send them to the frontend app with a delay between
         // each one.
-        for (int i = 0; i < tempFiles.size(); i++) {
-            if (i >= filesToDownload.size()) {
+        for (int i = 0; i < tempFiles.size(); i += 2) {
+            if (i >= filesToDownload.size() * 2) {
                 break;
             }
             UriPathPair tempFile = tempFiles.get(i);
+            UriPathPair extraTempFile = tempFiles.get(i + 1);
             addTempFileInUse(appKey, request.getFileServiceId(),
                     tempFile.getFilePathUri());
-            FileInfo fileToDownload = filesToDownload.get(i);
+            FileInfo fileToDownload = filesToDownload.get(i / 2);
             mHandler.postDelayed(() -> {
                 if (mActiveDownloadRequests.get(appKey) == null ||
                         !mActiveDownloadRequests.get(appKey).contains(request)) {
                     return;
                 }
-                downloadSingleFile(appKey, request, tempFile, fileToDownload);
+                downloadSingleFile(appKey, request, tempFile, extraTempFile, fileToDownload);
                 removeTempFileInUse(appKey, request.getFileServiceId(),
                         tempFile.getFilePathUri());
-            }, FILE_SEPARATION_DELAY * i * mDownloadDelayFactor);
+            }, FILE_SEPARATION_DELAY * i * mDownloadDelayFactor / 2);
         }
     }
 
     private void downloadSingleFile(FrontendAppIdentifier appKey, DownloadRequest request,
-            UriPathPair tempFile, FileInfo fileToDownload) {
+            UriPathPair tempFile, UriPathPair extraTempFile, FileInfo fileToDownload) {
         int result = MbmsDownloadSession.RESULT_SUCCESSFUL;
         // Test Callback
         DownloadStatusListener statusListener = mDownloadStatusCallbacks.get(request);
@@ -393,9 +395,10 @@
         downloadResultIntent.putExtra(MbmsDownloadSession.EXTRA_MBMS_FILE_INFO, fileToDownload);
         downloadResultIntent.putExtra(VendorUtils.EXTRA_TEMP_FILE_ROOT,
                 mAppTempFileRoots.get(appKey));
-        ArrayList<Uri> tempFileList = new ArrayList<>(1);
+        ArrayList<Uri> tempFileList = new ArrayList<>(2);
         tempFileList.add(tempFile.getFilePathUri());
-        downloadResultIntent.getExtras().putParcelableArrayList(
+        tempFileList.add(extraTempFile.getFilePathUri());
+        downloadResultIntent.putParcelableArrayListExtra(
                 VendorUtils.EXTRA_TEMP_LIST, tempFileList);
         downloadResultIntent.putExtra(MbmsDownloadSession.EXTRA_MBMS_DOWNLOAD_RESULT, result);
         downloadResultIntent.setComponent(mAppReceivers.get(appKey));
diff --git a/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java b/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java
index acdbdcb..78fa34f 100644
--- a/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java
+++ b/testapps/EmbmsTestDownloadApp/src/com/android/phone/testapps/embmsdownload/EmbmsTestDownloadApp.java
@@ -427,7 +427,7 @@
         if (info.getServiceId().contains("2")) {
             sourceUriBuilder.path("/*");
         } else {
-            sourceUriBuilder.path("/image.png");
+            sourceUriBuilder.path("/sunAndTree.png");
         }
 
         Intent completionIntent = new Intent(DOWNLOAD_DONE_ACTION);