From 3a2226be63800910621bf7c8739253ffcdb5fd6a Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Tue, 23 Oct 2018 15:01:49 -0700 Subject: [PATCH 1/2] Recopy NetworkSelectSetting from phone to settings NetworkSelectSetting is changed during the migration, recopy it to make it up to date Following CL will refactor to reuse this fragment for all devices. Bug: 114749736 Test: Build Change-Id: Id43cb480cf31447a6e4a23eb3709f9ab972a2930 --- res/drawable/ic_signal_strength_4g.xml | 28 ++++ .../telephony/NetworkOperatorPreference.java | 28 ++-- .../telephony/NetworkSelectSettings.java | 152 +++++++++--------- 3 files changed, 126 insertions(+), 82 deletions(-) create mode 100644 res/drawable/ic_signal_strength_4g.xml diff --git a/res/drawable/ic_signal_strength_4g.xml b/res/drawable/ic_signal_strength_4g.xml new file mode 100644 index 00000000000..90620965752 --- /dev/null +++ b/res/drawable/ic_signal_strength_4g.xml @@ -0,0 +1,28 @@ + + + + + \ No newline at end of file diff --git a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java index 4b0061387f6..79ccf9cf329 100644 --- a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java +++ b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java @@ -26,13 +26,13 @@ import android.telephony.SignalStrength; import android.util.Log; import android.view.Gravity; +import androidx.preference.Preference; + import com.android.settings.R; import com.android.settingslib.graph.SignalDrawable; import java.util.List; -import androidx.preference.Preference; - /** * A Preference represents a network operator in the NetworkSelectSetting fragment. */ @@ -45,16 +45,18 @@ public class NetworkOperatorPreference extends Preference { private CellInfo mCellInfo; private List mForbiddenPlmns; private int mLevel = -1; + private boolean mShow4GForLTE; // The following constants are used to draw signal icon. private static final Drawable EMPTY_DRAWABLE = new ColorDrawable(Color.TRANSPARENT); private static final int NO_CELL_DATA_CONNECTED_ICON = 0; public NetworkOperatorPreference( - CellInfo cellinfo, Context context, List forbiddenPlmns) { + CellInfo cellinfo, Context context, List forbiddenPlmns, boolean show4GForLTE) { super(context); mCellInfo = cellinfo; mForbiddenPlmns = forbiddenPlmns; + mShow4GForLTE = show4GForLTE; refresh(); } @@ -87,15 +89,21 @@ public class NetworkOperatorPreference extends Preference { updateIcon(level); } - private static int getIconIdForCell(CellInfo ci) { + private int getIconIdForCell(CellInfo ci) { final int type = ci.getCellIdentity().getType(); switch (type) { - case CellInfo.TYPE_GSM: return R.drawable.signal_strength_g; + case CellInfo.TYPE_GSM: + return R.drawable.signal_strength_g; case CellInfo.TYPE_WCDMA: // fall through - case CellInfo.TYPE_TDSCDMA: return R.drawable.signal_strength_3g; - case CellInfo.TYPE_LTE: return R.drawable.signal_strength_lte; - case CellInfo.TYPE_CDMA: return R.drawable.signal_strength_1x; - default: return 0; + case CellInfo.TYPE_TDSCDMA: + return R.drawable.signal_strength_3g; + case CellInfo.TYPE_LTE: + return mShow4GForLTE + ? R.drawable.ic_signal_strength_4g : R.drawable.signal_strength_lte; + case CellInfo.TYPE_CDMA: + return R.drawable.signal_strength_1x; + default: + return 0; } } @@ -117,7 +125,7 @@ public class NetworkOperatorPreference extends Preference { iconType == NO_CELL_DATA_CONNECTED_ICON ? EMPTY_DRAWABLE : getContext() - .getResources().getDrawable(iconType, getContext().getTheme()); + .getResources().getDrawable(iconType, getContext().getTheme()); // Overlay the two drawables Drawable[] layers = {networkDrawable, signalDrawable}; diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java index 9205188085e..ec199e6f237 100644 --- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java +++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java @@ -15,13 +15,17 @@ */ package com.android.settings.network.telephony; +import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.MOBILE_NETWORK_SELECT; + import android.content.Context; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.os.PersistableBundle; import android.provider.SearchIndexableResource; import android.telephony.AccessNetworkConstants; +import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.CellInfo; import android.telephony.NetworkRegistrationState; @@ -30,6 +34,7 @@ import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.Log; import android.view.View; +import android.view.ViewGroup; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; @@ -50,6 +55,8 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; /** * "Choose network" settings UI for the Phone app. @@ -58,11 +65,9 @@ import java.util.Map; @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) public class NetworkSelectSettings extends DashboardFragment { - private static final String TAG = "NetworkSelectSetting"; + private static final String TAG = "NetworkSelectSettings"; private static final boolean DBG = true; - public static final String KEY_SUBSCRIPTION_ID = "subscription_id"; - private static final int EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE = 1; private static final int EVENT_NETWORK_SCAN_RESULTS = 2; private static final int EVENT_NETWORK_SCAN_ERROR = 3; @@ -81,36 +86,26 @@ public class NetworkSelectSettings extends DashboardFragment { private Preference mStatusMessagePreference; private List mCellInfoList; private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; + private ViewGroup mFrameLayout; private NetworkOperatorPreference mSelectedNetworkOperatorPreference; private TelephonyManager mTelephonyManager; private List mForbiddenPlmns; - //Flag indicating whether we have called bind on the service. - private boolean mShouldUnbind; + private boolean mShow4GForLTE = true; + private NetworkScanHelper mNetworkScanHelper; + private final ExecutorService mNetworkScanExecutor = Executors.newFixedThreadPool(1); private final Runnable mUpdateNetworkOperatorsRunnable = () -> { updateNetworkOperatorsPreferenceCategory(); }; - /** - * Create a new instance of this fragment. - */ - public static NetworkSelectSettings newInstance(int subId) { - Bundle args = new Bundle(); - args.putInt(KEY_SUBSCRIPTION_ID, subId); - NetworkSelectSettings - fragment = new NetworkSelectSettings(); - fragment.setArguments(args); - - return fragment; - } - @Override public void onCreate(Bundle icicle) { if (DBG) logd("onCreate"); super.onCreate(icicle); - mSubId = getArguments().getInt(KEY_SUBSCRIPTION_ID); + mSubId = getArguments().getInt(MobileSettingsActivity.KEY_SUBSCRIPTION_ID); + addPreferencesFromResource(R.xml.choose_network); mConnectedNetworkOperatorsPreference = (PreferenceCategory) findPreference(PREF_KEY_CONNECTED_NETWORK_OPERATOR); mNetworkOperatorsPreferences = @@ -118,21 +113,29 @@ public class NetworkSelectSettings extends DashboardFragment { mStatusMessagePreference = new Preference(getContext()); mSelectedNetworkOperatorPreference = null; mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(mSubId); + mNetworkScanHelper = new NetworkScanHelper( + mTelephonyManager, mCallback, mNetworkScanExecutor); + PersistableBundle bundle = ((CarrierConfigManager) getContext().getSystemService( + Context.CARRIER_CONFIG_SERVICE)).getConfigForSubId(mSubId); + if (bundle != null) { + mShow4GForLTE = bundle.getBoolean( + CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL); + } setRetainInstance(true); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { + if (DBG) logd("onViewCreated"); super.onViewCreated(view, savedInstanceState); - mProgressHeader = setPinnedHeaderView(R.layout.wifi_progress_header) - .findViewById(R.id.progress_bar_animation); - setProgressBarVisible(false); + // TODO(b/114749736): build the progress bar forceConfigConnectedNetworkOperatorsPreferenceCategory(); } @Override public void onStart() { + if (DBG) logd("onStart"); super.onStart(); new AsyncTask>() { @Override @@ -144,7 +147,7 @@ public class NetworkSelectSettings extends DashboardFragment { @Override protected void onPostExecute(List result) { mForbiddenPlmns = result; - bindNetworkQueryService(); + loadNetworksList(); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -199,7 +202,7 @@ public class NetworkSelectSettings extends DashboardFragment { ThreadUtils.postOnBackgroundThread(() -> { Message msg = mHandler.obtainMessage(EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE); msg.obj = mTelephonyManager.setNetworkSelectionModeManual( - operatorInfo.getOperatorNumeric(), true /* persistSelection */); + operatorInfo, true /* persistSelection */); msg.sendToTarget(); }); @@ -223,8 +226,6 @@ public class NetworkSelectSettings extends DashboardFragment { if (DBG) logd("onStop"); getView().removeCallbacks(mUpdateNetworkOperatorsRunnable); stopNetworkQuery(); - // Unbind the NetworkQueryService - unbindNetworkQueryService(); } @Override @@ -239,8 +240,7 @@ public class NetworkSelectSettings extends DashboardFragment { @Override public int getMetricsCategory() { - //TODO(b/114749736): add metrics id for this page - return 0; + return MOBILE_NETWORK_SELECT; } private final Handler mHandler = new Handler() { @@ -258,7 +258,6 @@ public class NetworkSelectSettings extends DashboardFragment { mSelectedNetworkOperatorPreference.setSummary(R.string.network_connected); } else { 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); @@ -297,6 +296,35 @@ public class NetworkSelectSettings extends DashboardFragment { } }; + private void loadNetworksList() { + if (DBG) logd("load networks list..."); + setProgressBarVisible(true); + mNetworkScanHelper.startNetworkScan( + NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS); + } + + private final NetworkScanHelper.NetworkScanCallback mCallback = + new NetworkScanHelper.NetworkScanCallback() { + public void onResults(List results) { + if (DBG) logd("get scan results."); + Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results); + msg.sendToTarget(); + } + + public void onComplete() { + if (DBG) logd("network scan completed."); + Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_COMPLETED); + msg.sendToTarget(); + } + + 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(); + } + }; + private void updateNetworkOperators() { if (DBG) logd("updateNetworkOperators"); if (getActivity() != null) { @@ -324,7 +352,7 @@ public class NetworkSelectSettings extends DashboardFragment { for (int index = 0; index < mCellInfoList.size(); index++) { if (!mCellInfoList.get(index).isRegistered()) { NetworkOperatorPreference pref = new NetworkOperatorPreference( - mCellInfoList.get(index), getContext(), mForbiddenPlmns); + mCellInfoList.get(index), getContext(), mForbiddenPlmns, mShow4GForLTE); pref.setKey(CellInfoUtil.getNetworkTitle(mCellInfoList.get(index))); pref.setOrder(index); mNetworkOperatorsPreferences.addPreference(pref); @@ -335,15 +363,15 @@ public class NetworkSelectSettings extends DashboardFragment { /** * Config the connected network operator preference when the page was created. When user get * into this page, the device might or might not have data connection. - * - If the device has data: - * 1. use {@code ServiceState#getNetworkRegistrationStates()} to get the currently - * registered cellIdentity, wrap it into a CellInfo; - * 2. set the signal strength level as strong; - * 3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the - * previously connected network operator, since the CellIdentity got from step 1 only has - * PLMN. - * - If the device has no data, we will remove the connected network operators list from the - * screen. + * - If the device has data: + * 1. use {@code ServiceState#getNetworkRegistrationStates()} to get the currently + * registered cellIdentity, wrap it into a CellInfo; + * 2. set the signal strength level as strong; + * 3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the + * previously connected network operator, since the CellIdentity got from step 1 only has + * PLMN. + * - If the device has no data, we will remove the connected network operators list from the + * screen. */ private void forceConfigConnectedNetworkOperatorsPreferenceCategory() { if (DBG) logd("Force config ConnectedNetworkOperatorsPreferenceCategory"); @@ -362,8 +390,8 @@ public class NetworkSelectSettings extends DashboardFragment { CellInfo cellInfo = CellInfoUtil.wrapCellInfoWithCellIdentity(cellIdentity); if (cellInfo != null) { if (DBG) logd("Currently registered cell: " + cellInfo.toString()); - NetworkOperatorPreference pref = - new NetworkOperatorPreference(cellInfo, getContext(), mForbiddenPlmns); + NetworkOperatorPreference pref = new NetworkOperatorPreference( + cellInfo, getContext(), mForbiddenPlmns, mShow4GForLTE); pref.setTitle(mTelephonyManager.getNetworkOperatorName()); pref.setSummary(R.string.network_connected); // Update the signal strength icon, since the default signalStrength value would be @@ -396,7 +424,7 @@ public class NetworkSelectSettings extends DashboardFragment { removeConnectedNetworkOperatorPreference(); } CellInfo connectedNetworkOperator = null; - for (CellInfo cellInfo : mCellInfoList) { + for (CellInfo cellInfo: mCellInfoList) { if (cellInfo.isRegistered()) { connectedNetworkOperator = cellInfo; break; @@ -443,8 +471,8 @@ public class NetworkSelectSettings extends DashboardFragment { if (DBG) logd("addConnectedNetworkOperatorPreference"); // Remove the current ConnectedNetworkOperatorsPreference removeConnectedNetworkOperatorPreference(); - final NetworkOperatorPreference pref = - new NetworkOperatorPreference(cellInfo, getContext(), mForbiddenPlmns); + final NetworkOperatorPreference pref = new NetworkOperatorPreference( + cellInfo, getContext(), mForbiddenPlmns, mShow4GForLTE); pref.setSummary(R.string.network_connected); mConnectedNetworkOperatorsPreference.addPreference(pref); PreferenceScreen preferenceScreen = getPreferenceScreen(); @@ -483,7 +511,7 @@ public class NetworkSelectSettings extends DashboardFragment { private List aggregateCellInfoList(List cellInfoList) { if (DBG) logd("before aggregate: " + cellInfoList.toString()); Map map = new HashMap<>(); - for (CellInfo cellInfo : cellInfoList) { + for (CellInfo cellInfo: cellInfoList) { String plmn = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo).getOperatorNumeric(); if (cellInfo.isRegistered() || !map.containsKey(plmn)) { map.put(plmn, cellInfo); @@ -501,36 +529,16 @@ public class NetworkSelectSettings extends DashboardFragment { return new ArrayList<>(map.values()); } - private void loadNetworksList() { - if (DBG) logd("load networks list..."); - setProgressBarVisible(true); - //TODO(b/114749736): load network list once b/115401728 is done - } - - private void bindNetworkQueryService() { - if (DBG) logd("bindNetworkQueryService"); - //TODO(b/114749736): bind service/manager once b/115401728 is done - mShouldUnbind = true; - } - - private void unbindNetworkQueryService() { - if (DBG) logd("unbindNetworkQueryService"); - if (mShouldUnbind) { - if (DBG) logd("mShouldUnbind is true"); - // unbind the service. - //TODO(b/114749736): unbind service/manager once b/115401728 is done - mShouldUnbind = false; + private void stopNetworkQuery() { + if (mNetworkScanHelper != null) { + mNetworkScanHelper.stopNetworkQuery(); } } - private void updateNetworkSelection() { - if (DBG) logd("Update notification about no service of user selected operator"); - //TODO(b/114749736): update network selection once b/115429509 is done - } - - private void stopNetworkQuery() { - // Stop the network query process - //TODO(b/114749736): stop service/manager query once b/115401728 is done + @Override + public void onDestroy() { + mNetworkScanExecutor.shutdown(); + super.onDestroy(); } private void logd(String msg) { From 227526a8acd875e32ccd876050e7792fe370cea0 Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Wed, 24 Oct 2018 10:10:49 -0700 Subject: [PATCH 2/2] Update NetworkSelectSettings page Clean it up and make it compatiable with all devices. Before this CL it only used in Pixel 3 with new moderm. Bug: 114749736 Test: RunSettingsRoboTests Change-Id: Iad3bc131e294d34cff90b9130715780182adccd7 --- .../telephony/NetworkOperatorPreference.java | 10 +- .../telephony/NetworkSelectSettings.java | 371 +++++------------- ...randfather_not_implementing_index_provider | 1 + .../telephony/NetworkSelectSettingsTest.java | 104 +++++ 4 files changed, 217 insertions(+), 269 deletions(-) create mode 100644 tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java diff --git a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java index 79ccf9cf329..ad0285f2ad3 100644 --- a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java +++ b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java @@ -22,6 +22,7 @@ import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.telephony.CellInfo; +import android.telephony.CellSignalStrength; import android.telephony.SignalStrength; import android.util.Log; import android.view.Gravity; @@ -40,11 +41,14 @@ public class NetworkOperatorPreference extends Preference { private static final String TAG = "NetworkOperatorPref"; private static final boolean DBG = false; + + private static final int LEVEL_NONE = -1; + // number of signal strength level public static final int NUMBER_OF_LEVELS = SignalStrength.NUM_SIGNAL_STRENGTH_BINS; private CellInfo mCellInfo; private List mForbiddenPlmns; - private int mLevel = -1; + private int mLevel = LEVEL_NONE; private boolean mShow4GForLTE; // The following constants are used to draw signal icon. @@ -74,7 +78,9 @@ public class NetworkOperatorPreference extends Preference { networkTitle += " " + getContext().getResources().getString(R.string.forbidden_network); } setTitle(networkTitle); - int level = mCellInfo.getCellSignalStrength().getLevel(); + + final CellSignalStrength signalStrength = mCellInfo.getCellSignalStrength(); + final int level = signalStrength != null ? signalStrength.getLevel() : LEVEL_NONE; if (DBG) Log.d(TAG, "refresh level: " + String.valueOf(level)); if (mLevel != level) { mLevel = level; diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java index ec199e6f237..830964bb43f 100644 --- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java +++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java @@ -17,13 +17,12 @@ package com.android.settings.network.telephony; import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.MOBILE_NETWORK_SELECT; +import android.app.Activity; import android.content.Context; -import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.PersistableBundle; -import android.provider.SearchIndexableResource; import android.telephony.AccessNetworkConstants; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; @@ -32,23 +31,18 @@ import android.telephony.NetworkRegistrationState; import android.telephony.ServiceState; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; -import android.util.Log; import android.view.View; -import android.view.ViewGroup; +import androidx.annotation.VisibleForTesting; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; -import androidx.preference.PreferenceScreen; -import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.telephony.OperatorInfo; import com.android.settings.R; import com.android.settings.dashboard.DashboardFragment; -import com.android.settings.search.BaseSearchIndexProvider; -import com.android.settings.search.Indexable; -import com.android.settingslib.search.SearchIndexable; -import com.android.settingslib.utils.ThreadUtils; +import com.android.settings.overlay.FeatureFactory; +import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import java.util.ArrayList; import java.util.Arrays; @@ -61,14 +55,10 @@ import java.util.concurrent.Executors; /** * "Choose network" settings UI for the Phone app. */ -//TODO(b/115429509): Add test for this file once b/115429509 is not blocked anymore -@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) public class NetworkSelectSettings extends DashboardFragment { private static final String TAG = "NetworkSelectSettings"; - private static final boolean DBG = true; - private static final int EVENT_SET_NETWORK_SELECTION_MANUALLY_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; @@ -77,41 +67,41 @@ public class NetworkSelectSettings extends DashboardFragment { "connected_network_operator_preference"; private static final String PREF_KEY_NETWORK_OPERATORS = "network_operators_preference"; - // used to add/remove NetworkOperatorsPreference. - private PreferenceCategory mNetworkOperatorsPreferences; - // used to add/remove connected NetworkOperatorPreference. - private PreferenceCategory mConnectedNetworkOperatorsPreference; - // manage the progress bar on the top of the page. + @VisibleForTesting + PreferenceCategory mPreferenceCategory; + @VisibleForTesting + PreferenceCategory mConnectedPreferenceCategory; + @VisibleForTesting + NetworkOperatorPreference mSelectedPreference; private View mProgressHeader; private Preference mStatusMessagePreference; - private List mCellInfoList; + @VisibleForTesting + List mCellInfoList; private int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; - private ViewGroup mFrameLayout; - private NetworkOperatorPreference mSelectedNetworkOperatorPreference; - private TelephonyManager mTelephonyManager; + @VisibleForTesting + TelephonyManager mTelephonyManager; private List mForbiddenPlmns; private boolean mShow4GForLTE = true; private NetworkScanHelper mNetworkScanHelper; private final ExecutorService mNetworkScanExecutor = Executors.newFixedThreadPool(1); - - private final Runnable mUpdateNetworkOperatorsRunnable = () -> { - updateNetworkOperatorsPreferenceCategory(); - }; + private MetricsFeatureProvider mMetricsFeatureProvider; + private boolean mUseNewApi; @Override public void onCreate(Bundle icicle) { - if (DBG) logd("onCreate"); super.onCreate(icicle); + mUseNewApi = getContext().getResources().getBoolean( + com.android.internal.R.bool.config_enableNewAutoSelectNetworkUI); mSubId = getArguments().getInt(MobileSettingsActivity.KEY_SUBSCRIPTION_ID); addPreferencesFromResource(R.xml.choose_network); - mConnectedNetworkOperatorsPreference = + mConnectedPreferenceCategory = (PreferenceCategory) findPreference(PREF_KEY_CONNECTED_NETWORK_OPERATOR); - mNetworkOperatorsPreferences = + mPreferenceCategory = (PreferenceCategory) findPreference(PREF_KEY_NETWORK_OPERATORS); mStatusMessagePreference = new Preference(getContext()); - mSelectedNetworkOperatorPreference = null; + mSelectedPreference = null; mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(mSubId); mNetworkScanHelper = new NetworkScanHelper( mTelephonyManager, mCallback, mNetworkScanExecutor); @@ -121,113 +111,81 @@ public class NetworkSelectSettings extends DashboardFragment { mShow4GForLTE = bundle.getBoolean( CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL); } - setRetainInstance(true); + + mMetricsFeatureProvider = FeatureFactory + .getFactory(getContext()).getMetricsFeatureProvider(); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { - if (DBG) logd("onViewCreated"); super.onViewCreated(view, savedInstanceState); - // TODO(b/114749736): build the progress bar - forceConfigConnectedNetworkOperatorsPreferenceCategory(); + final Activity activity = getActivity(); + if (activity != null) { + mProgressHeader = setPinnedHeaderView(R.layout.wifi_progress_header) + .findViewById(R.id.progress_bar_animation); + setProgressBarVisible(false); + } + forceUpdateConnectedPreferenceCategory(); } @Override public void onStart() { - if (DBG) logd("onStart"); super.onStart(); - new AsyncTask>() { - @Override - protected List doInBackground(Void... voids) { - String[] forbiddenPlmns = mTelephonyManager.getForbiddenPlmns(); - return forbiddenPlmns != null ? Arrays.asList(forbiddenPlmns) : null; - } - - @Override - protected void onPostExecute(List result) { - mForbiddenPlmns = result; - loadNetworksList(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - /** - * Invoked on each preference click in this hierarchy, overrides - * PreferenceActivity's implementation. Used to make sure we track the - * preference click events. - * Since the connected network operator is either faked (when no data connection) or already - * connected, we do not allow user to click the connected network operator. - */ - @Override - public boolean onPreferenceTreeClick(Preference preference) { - if (DBG) logd("User clicked the screen"); - stopNetworkQuery(); - setProgressBarVisible(false); - if (preference instanceof NetworkOperatorPreference) { - // Refresh the last selected item in case users reselect network. - if (mSelectedNetworkOperatorPreference != null) { - mSelectedNetworkOperatorPreference.setSummary(""); - } - - mSelectedNetworkOperatorPreference = (NetworkOperatorPreference) preference; - CellInfo cellInfo = mSelectedNetworkOperatorPreference.getCellInfo(); - if (DBG) logd("User click a NetworkOperatorPreference: " + cellInfo.toString()); - - // Send metrics event - MetricsLogger.action(getContext(), - MetricsEvent.ACTION_MOBILE_NETWORK_MANUAL_SELECT_NETWORK); - - // Connect to the network - if (SubscriptionManager.isValidSubscriptionId(mSubId)) { - if (DBG) { - logd("Connect to the network: " + CellInfoUtil.getNetworkTitle(cellInfo)); - } - // Set summary as "Connecting" to the selected network. - mSelectedNetworkOperatorPreference.setSummary(R.string.network_connecting); - - // Set summary as "Disconnected" to the previously connected network - if (mConnectedNetworkOperatorsPreference.getPreferenceCount() > 0) { - NetworkOperatorPreference connectedNetworkOperator = (NetworkOperatorPreference) - (mConnectedNetworkOperatorsPreference.getPreference(0)); - if (!CellInfoUtil.getNetworkTitle(cellInfo).equals( - CellInfoUtil.getNetworkTitle(connectedNetworkOperator.getCellInfo()))) { - connectedNetworkOperator.setSummary(R.string.network_disconnected); - } - } - - OperatorInfo operatorInfo = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo); - if (DBG) logd("manually selected network operator: " + operatorInfo.toString()); - - ThreadUtils.postOnBackgroundThread(() -> { - Message msg = mHandler.obtainMessage(EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE); - msg.obj = mTelephonyManager.setNetworkSelectionModeManual( - operatorInfo, true /* persistSelection */); - msg.sendToTarget(); - }); - - setProgressBarVisible(true); - return true; - } else { - loge("Error selecting network. Subscription Id is invalid."); - mSelectedNetworkOperatorPreference = null; - return false; - } + mForbiddenPlmns = Arrays.asList(mTelephonyManager.getForbiddenPlmns()); + setProgressBarVisible(true); + if (mUseNewApi) { + mNetworkScanHelper.startNetworkScan( + NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS); } else { - getPreferenceScreen().setEnabled(false); - return false; + mNetworkScanHelper.startNetworkScan( + NetworkScanHelper.NETWORK_SCAN_TYPE_WAIT_FOR_ALL_RESULTS); } } @Override public void onStop() { super.onStop(); - if (DBG) logd("onStop"); - getView().removeCallbacks(mUpdateNetworkOperatorsRunnable); stopNetworkQuery(); } + @Override + public boolean onPreferenceTreeClick(Preference preference) { + if (preference != mSelectedPreference) { + stopNetworkQuery(); + setProgressBarVisible(false); + // Refresh the last selected item in case users reselect network. + if (mSelectedPreference != null) { + mSelectedPreference.setSummary(null); + } + + mSelectedPreference = (NetworkOperatorPreference) preference; + CellInfo cellInfo = mSelectedPreference.getCellInfo(); + + mMetricsFeatureProvider.action(getContext(), + MetricsEvent.ACTION_MOBILE_NETWORK_MANUAL_SELECT_NETWORK); + + // Set summary as "Disconnected" to the previously connected network + if (mConnectedPreferenceCategory.getPreferenceCount() > 0) { + NetworkOperatorPreference connectedNetworkOperator = (NetworkOperatorPreference) + (mConnectedPreferenceCategory.getPreference(0)); + if (!CellInfoUtil.getNetworkTitle(cellInfo).equals( + CellInfoUtil.getNetworkTitle(connectedNetworkOperator.getCellInfo()))) { + connectedNetworkOperator.setSummary(R.string.network_disconnected); + } + } + + final OperatorInfo operatorInfo = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo); + final boolean isSuccess = mTelephonyManager.setNetworkSelectionModeManual( + operatorInfo, true /* persistSelection */); + mSelectedPreference.setSummary( + isSuccess ? R.string.network_connected : R.string.network_could_not_connect); + } + + return true; + } + @Override protected int getPreferenceScreenResId() { return R.xml.choose_network; @@ -247,29 +205,11 @@ public class NetworkSelectSettings extends DashboardFragment { @Override public void handleMessage(Message msg) { switch (msg.what) { - case EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE: - if (DBG) logd("network selection done: hide the progress header"); - setProgressBarVisible(false); - - boolean isSuccessed = (boolean) msg.obj; - if (isSuccessed) { - if (DBG) logd("manual network selection: succeeded! "); - // Set summary as "Connected" to the selected network. - mSelectedNetworkOperatorPreference.setSummary(R.string.network_connected); - } else { - if (DBG) logd("manual network selection: failed! "); - // Set summary as "Couldn't connect" to the selected network. - mSelectedNetworkOperatorPreference.setSummary( - R.string.network_could_not_connect); - } - break; - case EVENT_NETWORK_SCAN_RESULTS: List results = aggregateCellInfoList((List) msg.obj); mCellInfoList = new ArrayList<>(results); - if (DBG) logd("after aggregate: " + mCellInfoList.toString()); if (mCellInfoList != null && mCellInfoList.size() != 0) { - updateNetworkOperators(); + updateAllPreferenceCategory(); } else { addMessagePreference(R.string.empty_networks_list); } @@ -277,15 +217,12 @@ public class NetworkSelectSettings extends DashboardFragment { break; case EVENT_NETWORK_SCAN_ERROR: - int error = msg.arg1; - if (DBG) logd("error while querying available networks " + error); stopNetworkQuery(); addMessagePreference(R.string.network_query_error); break; case EVENT_NETWORK_SCAN_COMPLETED: stopNetworkQuery(); - if (DBG) logd("scan complete"); if (mCellInfoList == null) { // In case the scan timeout before getting any results addMessagePreference(R.string.empty_networks_list); @@ -296,47 +233,25 @@ public class NetworkSelectSettings extends DashboardFragment { } }; - private void loadNetworksList() { - if (DBG) logd("load networks list..."); - setProgressBarVisible(true); - mNetworkScanHelper.startNetworkScan( - NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS); - } - private final NetworkScanHelper.NetworkScanCallback mCallback = new NetworkScanHelper.NetworkScanCallback() { public void onResults(List results) { - if (DBG) logd("get scan results."); Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results); msg.sendToTarget(); } public void onComplete() { - if (DBG) logd("network scan completed."); Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_COMPLETED); msg.sendToTarget(); } 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(); } }; - private void updateNetworkOperators() { - if (DBG) logd("updateNetworkOperators"); - if (getActivity() != null) { - final View view = getView(); - final Handler handler = view.getHandler(); - if (handler != null && handler.hasCallbacks(mUpdateNetworkOperatorsRunnable)) { - return; - } - view.post(mUpdateNetworkOperatorsRunnable); - } - } - /** * Update the currently available network operators list, which only contains the unregistered * network operators. So if the device has no data and the network operator in the connected @@ -345,17 +260,18 @@ public class NetworkSelectSettings extends DashboardFragment { * network operator in the connected network operator category shows "Connected", it will not * exist in the available network category. */ - private void updateNetworkOperatorsPreferenceCategory() { - mNetworkOperatorsPreferences.removeAll(); + @VisibleForTesting + void updateAllPreferenceCategory() { + updateConnectedPreferenceCategory(); - configConnectedNetworkOperatorsPreferenceCategory(); + mPreferenceCategory.removeAll(); for (int index = 0; index < mCellInfoList.size(); index++) { if (!mCellInfoList.get(index).isRegistered()) { NetworkOperatorPreference pref = new NetworkOperatorPreference( mCellInfoList.get(index), getContext(), mForbiddenPlmns, mShow4GForLTE); pref.setKey(CellInfoUtil.getNetworkTitle(mCellInfoList.get(index))); pref.setOrder(index); - mNetworkOperatorsPreferences.addPreference(pref); + mPreferenceCategory.addPreference(pref); } } } @@ -363,33 +279,30 @@ public class NetworkSelectSettings extends DashboardFragment { /** * Config the connected network operator preference when the page was created. When user get * into this page, the device might or might not have data connection. - * - If the device has data: - * 1. use {@code ServiceState#getNetworkRegistrationStates()} to get the currently - * registered cellIdentity, wrap it into a CellInfo; - * 2. set the signal strength level as strong; - * 3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the - * previously connected network operator, since the CellIdentity got from step 1 only has - * PLMN. - * - If the device has no data, we will remove the connected network operators list from the - * screen. + * - If the device has data: + * 1. use {@code ServiceState#getNetworkRegistrationStates()} to get the currently + * registered cellIdentity, wrap it into a CellInfo; + * 2. set the signal strength level as strong; + * 3. use {@link TelephonyManager#getNetworkOperatorName()} to get the title of the + * previously connected network operator, since the CellIdentity got from step 1 only has + * PLMN. + * - If the device has no data, we will remove the connected network operators list from the + * screen. */ - private void forceConfigConnectedNetworkOperatorsPreferenceCategory() { - if (DBG) logd("Force config ConnectedNetworkOperatorsPreferenceCategory"); + private void forceUpdateConnectedPreferenceCategory() { if (mTelephonyManager.getDataState() == mTelephonyManager.DATA_CONNECTED) { // Try to get the network registration states ServiceState ss = mTelephonyManager.getServiceState(); List networkList = ss.getNetworkRegistrationStates(AccessNetworkConstants.TransportType.WWAN); if (networkList == null || networkList.size() == 0) { - loge("getNetworkRegistrationStates return null"); // Remove the connected network operators category - removeConnectedNetworkOperatorPreference(); + mConnectedPreferenceCategory.setVisible(false); return; } CellIdentity cellIdentity = networkList.get(0).getCellIdentity(); CellInfo cellInfo = CellInfoUtil.wrapCellInfoWithCellIdentity(cellIdentity); if (cellInfo != null) { - if (DBG) logd("Currently registered cell: " + cellInfo.toString()); NetworkOperatorPreference pref = new NetworkOperatorPreference( cellInfo, getContext(), mForbiddenPlmns, mShow4GForLTE); pref.setTitle(mTelephonyManager.getNetworkOperatorName()); @@ -397,17 +310,14 @@ public class NetworkSelectSettings extends DashboardFragment { // Update the signal strength icon, since the default signalStrength value would be // zero (it would be quite confusing why the connected network has no signal) pref.setIcon(NetworkOperatorPreference.NUMBER_OF_LEVELS - 1); - - mConnectedNetworkOperatorsPreference.addPreference(pref); + mConnectedPreferenceCategory.addPreference(pref); } else { - loge("Invalid CellIfno: " + cellInfo.toString()); // Remove the connected network operators category - removeConnectedNetworkOperatorPreference(); + mConnectedPreferenceCategory.setVisible(false); } } else { - if (DBG) logd("No currently registered cell"); // Remove the connected network operators category - removeConnectedNetworkOperatorPreference(); + mConnectedPreferenceCategory.setVisible(false); } } @@ -416,74 +326,27 @@ public class NetworkSelectSettings extends DashboardFragment { * configured if the category is currently empty or the operator network title of the previous * connected network is different from the new one. */ - private void configConnectedNetworkOperatorsPreferenceCategory() { - if (DBG) logd("config ConnectedNetworkOperatorsPreferenceCategory"); - // Remove the category if the CellInfo list is empty or does not have registered cell. - if (mCellInfoList.size() == 0) { - if (DBG) logd("empty cellinfo list"); - removeConnectedNetworkOperatorPreference(); - } + private void updateConnectedPreferenceCategory() { CellInfo connectedNetworkOperator = null; - for (CellInfo cellInfo: mCellInfoList) { + for (CellInfo cellInfo : mCellInfoList) { if (cellInfo.isRegistered()) { connectedNetworkOperator = cellInfo; break; } } - if (connectedNetworkOperator == null) { - if (DBG) logd("no registered network"); - removeConnectedNetworkOperatorPreference(); - return; - } - // config the category if it is empty. - if (mConnectedNetworkOperatorsPreference.getPreferenceCount() == 0) { - if (DBG) logd("ConnectedNetworkSelectList is empty, add one"); + if (connectedNetworkOperator != null) { addConnectedNetworkOperatorPreference(connectedNetworkOperator); - return; } - NetworkOperatorPreference previousConnectedNetworkOperator = (NetworkOperatorPreference) - (mConnectedNetworkOperatorsPreference.getPreference(0)); - - // config the category if the network title of the previous connected network is different - // from the new one. - String cTitle = CellInfoUtil.getNetworkTitle(connectedNetworkOperator); - String pTitle = CellInfoUtil.getNetworkTitle( - previousConnectedNetworkOperator.getCellInfo()); - if (!cTitle.equals(pTitle)) { - if (DBG) logd("reconfig the category: connected network changed"); - addConnectedNetworkOperatorPreference(connectedNetworkOperator); - return; - } - if (DBG) logd("same network operator is connected, only refresh the connected network"); - // Otherwise same network operator is connected, only refresh the connected network - // operator preference (first and the only one in this category). - ((NetworkOperatorPreference) mConnectedNetworkOperatorsPreference.getPreference(0)) - .refresh(); - return; } - /** - * Creates a Preference for the given {@link CellInfo} and adds it to the - * {@link #mConnectedNetworkOperatorsPreference}. - */ private void addConnectedNetworkOperatorPreference(CellInfo cellInfo) { - if (DBG) logd("addConnectedNetworkOperatorPreference"); - // Remove the current ConnectedNetworkOperatorsPreference - removeConnectedNetworkOperatorPreference(); + mConnectedPreferenceCategory.removeAll(); final NetworkOperatorPreference pref = new NetworkOperatorPreference( cellInfo, getContext(), mForbiddenPlmns, mShow4GForLTE); pref.setSummary(R.string.network_connected); - mConnectedNetworkOperatorsPreference.addPreference(pref); - PreferenceScreen preferenceScreen = getPreferenceScreen(); - preferenceScreen.addPreference(mConnectedNetworkOperatorsPreference); - } - - /** Removes all preferences and hide the {@link #mConnectedNetworkOperatorsPreference}. */ - private void removeConnectedNetworkOperatorPreference() { - mConnectedNetworkOperatorsPreference.removeAll(); - PreferenceScreen preferenceScreen = getPreferenceScreen(); - preferenceScreen.removePreference(mConnectedNetworkOperatorsPreference); + mConnectedPreferenceCategory.addPreference(pref); + mConnectedPreferenceCategory.setVisible(true); } protected void setProgressBarVisible(boolean visible) { @@ -493,14 +356,11 @@ public class NetworkSelectSettings extends DashboardFragment { } private void addMessagePreference(int messageId) { - if (DBG) logd("remove callback"); - getView().removeCallbacks(mUpdateNetworkOperatorsRunnable); setProgressBarVisible(false); - if (DBG) logd("addMessagePreference"); mStatusMessagePreference.setTitle(messageId); - removeConnectedNetworkOperatorPreference(); - mNetworkOperatorsPreferences.removeAll(); - mNetworkOperatorsPreferences.addPreference(mStatusMessagePreference); + mConnectedPreferenceCategory.setVisible(false); + mPreferenceCategory.removeAll(); + mPreferenceCategory.addPreference(mStatusMessagePreference); } /** @@ -509,9 +369,8 @@ public class NetworkSelectSettings extends DashboardFragment { * with the strongest signal strength. */ private List aggregateCellInfoList(List cellInfoList) { - if (DBG) logd("before aggregate: " + cellInfoList.toString()); Map map = new HashMap<>(); - for (CellInfo cellInfo: cellInfoList) { + for (CellInfo cellInfo : cellInfoList) { String plmn = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo).getOperatorNumeric(); if (cellInfo.isRegistered() || !map.containsKey(plmn)) { map.put(plmn, cellInfo); @@ -540,26 +399,4 @@ public class NetworkSelectSettings extends DashboardFragment { mNetworkScanExecutor.shutdown(); super.onDestroy(); } - - private void logd(String msg) { - Log.d(TAG, msg); - } - - private void loge(String msg) { - Log.e(TAG, msg); - } - - public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = - new BaseSearchIndexProvider() { - @Override - public List getXmlResourcesToIndex(Context context, - boolean enabled) { - final ArrayList result = new ArrayList<>(); - - final SearchIndexableResource sir = new SearchIndexableResource(context); - sir.xmlResId = R.xml.choose_network; - result.add(sir); - return result; - } - }; } diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider index 38108f7e04b..6f4deca9adc 100644 --- a/tests/robotests/assets/grandfather_not_implementing_index_provider +++ b/tests/robotests/assets/grandfather_not_implementing_index_provider @@ -50,6 +50,7 @@ com.android.settings.inputmethod.SpellCheckersSettings com.android.settings.localepicker.LocaleListEditor com.android.settings.network.ApnEditor com.android.settings.network.ApnSettings +com.android.settings.network.telephony.NetworkSelectSettings com.android.settings.notification.AppNotificationSettings com.android.settings.notification.ChannelGroupNotificationSettings com.android.settings.notification.ChannelNotificationSettings diff --git a/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java b/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java new file mode 100644 index 00000000000..3ebeba1b3fa --- /dev/null +++ b/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2018 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. + */ + +package com.android.settings.network.telephony; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import android.content.Context; +import android.telephony.CellInfo; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; + +import androidx.preference.PreferenceCategory; +import androidx.preference.PreferenceManager; + +import com.android.settings.testutils.SettingsRobolectricTestRunner; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RuntimeEnvironment; + +import java.util.Arrays; + +@RunWith(SettingsRobolectricTestRunner.class) +public class NetworkSelectSettingsTest { + private static final int SUB_ID = 2; + + @Mock + private TelephonyManager mTelephonyManager; + @Mock + private SubscriptionManager mSubscriptionManager; + @Mock + private CellInfo mCellInfo1; + @Mock + private CellInfo mCellInfo2; + @Mock + private PreferenceManager mPreferenceManager; + private Context mContext; + + private PreferenceCategory mConnectedPreferenceCategory; + private PreferenceCategory mPreferenceCategory; + + private NetworkSelectSettings mNetworkSelectSettings; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + + mContext = spy(RuntimeEnvironment.application); + when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager); + when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager); + when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager); + + when(mCellInfo1.isRegistered()).thenReturn(true); + when(mCellInfo2.isRegistered()).thenReturn(false); + + mConnectedPreferenceCategory = spy(new PreferenceCategory(mContext)); + doReturn(mPreferenceManager).when(mConnectedPreferenceCategory).getPreferenceManager(); + mPreferenceCategory = spy(new PreferenceCategory(mContext)); + doReturn(mPreferenceManager).when(mPreferenceCategory).getPreferenceManager(); + + mNetworkSelectSettings = spy(new NetworkSelectSettings()); + doReturn(mContext).when(mNetworkSelectSettings).getContext(); + mNetworkSelectSettings.mTelephonyManager = mTelephonyManager; + mNetworkSelectSettings.mConnectedPreferenceCategory = mConnectedPreferenceCategory; + mNetworkSelectSettings.mPreferenceCategory = mPreferenceCategory; + mNetworkSelectSettings.mCellInfoList = Arrays.asList(mCellInfo1, mCellInfo2); + } + + @Test + public void updateAllPreferenceCategory_containCorrectPreference() { + mNetworkSelectSettings.updateAllPreferenceCategory(); + + assertThat(mConnectedPreferenceCategory.getPreferenceCount()).isEqualTo(1); + final NetworkOperatorPreference connectedPreference = + (NetworkOperatorPreference) mConnectedPreferenceCategory.getPreference(0); + assertThat(connectedPreference.getCellInfo()).isEqualTo(mCellInfo1); + assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(1); + final NetworkOperatorPreference preference = + (NetworkOperatorPreference) mPreferenceCategory.getPreference(0); + assertThat(preference.getCellInfo()).isEqualTo(mCellInfo2); + } + +}