From 696c9b73352279952bf522d5311ab246465fb365 Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Tue, 1 Jun 2021 22:48:17 +0800 Subject: [PATCH] [Settings] Connected carrier should not be forbidden ones Manual network selection UI tried to display connected carrier as initial list prior to the initial response from network scan. However, the detection of connected carrier could be incorrect. Before having an architectural change for this part, adding a piece of code to avoid from displaying carriers which should be avoided. Bug: 165158590 Test: local Change-Id: If9c0804c706dd77a1c690555b245425dfeaf1fa9 --- .../telephony/NetworkOperatorPreference.java | 9 +++++- .../telephony/NetworkSelectSettings.java | 31 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java index 5b09e3d8380..397bf36a1c1 100644 --- a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java +++ b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java @@ -107,13 +107,20 @@ public class NetworkOperatorPreference extends Preference { return mCellId.equals(CellInfoUtil.getCellIdentity(cellinfo)); } + /** + * Return true when this preference is for forbidden network + */ + public boolean isForbiddenNetwork() { + return ((mForbiddenPlmns != null) && mForbiddenPlmns.contains(getOperatorNumeric())); + } + /** * Refresh the NetworkOperatorPreference by updating the title and the icon. */ public void refresh() { String networkTitle = getOperatorName(); - if ((mForbiddenPlmns != null) && mForbiddenPlmns.contains(getOperatorNumeric())) { + if (isForbiddenNetwork()) { if (DBG) Log.d(TAG, "refresh forbidden network: " + networkTitle); networkTitle += " " + getContext().getResources().getString(R.string.forbidden_network); diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java index 9a54084a1a7..76b6cbd9564 100644 --- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java +++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java @@ -471,19 +471,30 @@ public class NetworkSelectSettings extends DashboardFragment { if (networkList == null || networkList.size() == 0) { return; } + // Due to the aggregation of cell between carriers, it's possible to get CellIdentity + // containing forbidden PLMN. + // Getting current network from ServiceState is no longer a good idea. + // Add an additional rule to avoid from showing forbidden PLMN to the user. + if (mForbiddenPlmns == null) { + updateForbiddenPlmns(); + } for (NetworkRegistrationInfo regInfo : networkList) { final CellIdentity cellIdentity = regInfo.getCellIdentity(); - if (cellIdentity != null) { - final NetworkOperatorPreference pref = new NetworkOperatorPreference( - getPrefContext(), cellIdentity, mForbiddenPlmns, mShow4GForLTE); - pref.setSummary(R.string.network_connected); - // 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(SignalStrength.NUM_SIGNAL_STRENGTH_BINS - 1); - mPreferenceCategory.addPreference(pref); - break; + if (cellIdentity == null) { + continue; } + final NetworkOperatorPreference pref = new NetworkOperatorPreference( + getPrefContext(), cellIdentity, mForbiddenPlmns, mShow4GForLTE); + if (pref.isForbiddenNetwork()) { + continue; + } + pref.setSummary(R.string.network_connected); + // 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(SignalStrength.NUM_SIGNAL_STRENGTH_BINS - 1); + mPreferenceCategory.addPreference(pref); + break; } } }