Clean cherry-pick 'Display Forbidden State during Manual Network scan."
Bug: 79561854
Test: maunal test
Change-Id: Iba82d5c39816e509823afa092a057e7ef53fab02
Merged-In: Iba82d5c39816e509823afa092a057e7ef53fab02
diff --git a/src/com/android/phone/CellInfoUtil.java b/src/com/android/phone/CellInfoUtil.java
index c0409d8..2c5f2a8 100644
--- a/src/com/android/phone/CellInfoUtil.java
+++ b/src/com/android/phone/CellInfoUtil.java
@@ -34,6 +34,8 @@
import com.android.internal.telephony.OperatorInfo;
+import java.util.List;
+
/**
* Add static Utility functions to get information from the CellInfo object.
* TODO: Modify {@link CellInfo} for simplify those functions
@@ -166,4 +168,10 @@
}
return oi;
}
+
+ /** Checks whether the network operator is forbidden. */
+ public static boolean isForbidden(CellInfo cellInfo, List<String> forbiddenPlmns) {
+ String plmn = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo).getOperatorNumeric();
+ return forbiddenPlmns != null && forbiddenPlmns.contains(plmn);
+ }
}
diff --git a/src/com/android/phone/NetworkOperatorPreference.java b/src/com/android/phone/NetworkOperatorPreference.java
index f29c038..85adf16 100644
--- a/src/com/android/phone/NetworkOperatorPreference.java
+++ b/src/com/android/phone/NetworkOperatorPreference.java
@@ -30,25 +30,30 @@
import com.android.settingslib.graph.SignalDrawable;
+import java.util.List;
+
/**
* A Preference represents a network operator in the NetworkSelectSetting fragment.
*/
public class NetworkOperatorPreference extends Preference {
private static final String TAG = "NetworkOperatorPref";
- private static final boolean DBG = true;
+ private static final boolean DBG = false;
// number of signal strength level
public static final int NUMBER_OF_LEVELS = SignalStrength.NUM_SIGNAL_STRENGTH_BINS;
private CellInfo mCellInfo;
+ private List<String> mForbiddenPlmns;
private int mLevel = -1;
// 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) {
+ public NetworkOperatorPreference(
+ CellInfo cellinfo, Context context, List<String> forbiddenPlmns) {
super(context);
mCellInfo = cellinfo;
+ mForbiddenPlmns = forbiddenPlmns;
refresh();
}
@@ -61,7 +66,11 @@
*/
public void refresh() {
if (DBG) Log.d(TAG, "refresh the network: " + CellInfoUtil.getNetworkTitle(mCellInfo));
- setTitle(CellInfoUtil.getNetworkTitle(mCellInfo));
+ String networkTitle = CellInfoUtil.getNetworkTitle(mCellInfo);
+ if (CellInfoUtil.isForbidden(mCellInfo, mForbiddenPlmns)) {
+ networkTitle += " " + getContext().getResources().getString(R.string.forbidden_network);
+ }
+ setTitle(networkTitle);
int level = CellInfoUtil.getLevel(mCellInfo);
if (DBG) Log.d(TAG, "refresh level: " + String.valueOf(level));
if (mLevel != level) {
diff --git a/src/com/android/phone/NetworkSelectListPreference.java b/src/com/android/phone/NetworkSelectListPreference.java
index 2a55839..5b31b68 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncResult;
+import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;
import android.os.Parcel;
@@ -47,6 +48,7 @@
import com.android.internal.telephony.PhoneFactory;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
@@ -76,6 +78,7 @@
private int mSubId;
private NetworkOperators mNetworkOperators;
+ private List<String> mForbiddenPlmns;
private ProgressDialog mProgressDialog;
public NetworkSelectListPreference(Context context, AttributeSet attrs) {
@@ -89,10 +92,21 @@
@Override
protected void onClick() {
- // 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();
+ showProgressDialog(DIALOG_NETWORK_LIST_LOAD);
+ TelephonyManager telephonyManager = (TelephonyManager)
+ getContext().getSystemService(Context.TELEPHONY_SERVICE);
+ new AsyncTask<Void, Void, List<String>>() {
+ @Override
+ protected List<String> doInBackground(Void... voids) {
+ return Arrays.asList(telephonyManager.getForbiddenPlmns());
+ }
+
+ @Override
+ protected void onPostExecute(List<String> result) {
+ mForbiddenPlmns = result;
+ loadNetworksList();
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
private final Handler mHandler = new Handler() {
@@ -155,7 +169,7 @@
/** 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.");
+ if (DBG) logd("get scan results: " + results.toString());
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results);
msg.sendToTarget();
}
@@ -283,9 +297,6 @@
private void loadNetworksList() {
if (DBG) logd("load networks list...");
-
- showProgressDialog(DIALOG_NETWORK_LIST_LOAD);
-
try {
if (mNetworkQueryService != null) {
mNetworkQueryService.startNetworkQuery(mCallback, mPhoneId, false);
@@ -325,6 +336,10 @@
// Display each operator name only once.
String networkTitle = getNetworkTitle(cellInfo);
if (!networkEntriesList.contains(networkTitle)) {
+ if (CellInfoUtil.isForbidden(cellInfo, mForbiddenPlmns)) {
+ networkTitle += " "
+ + getContext().getResources().getString(R.string.forbidden_network);
+ }
networkEntriesList.add(networkTitle);
networkEntryValuesList.add(getOperatorNumeric(cellInfo));
}
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index efa8684..71162bb 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -22,6 +22,7 @@
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.AsyncResult;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -50,6 +51,7 @@
import com.android.internal.telephony.PhoneFactory;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -60,7 +62,7 @@
public class NetworkSelectSetting extends PreferenceFragment {
private static final String TAG = "NetworkSelectSetting";
- private static final boolean DBG = false;
+ private static final boolean DBG = true;
private static final int EVENT_NETWORK_SELECTION_DONE = 1;
private static final int EVENT_NETWORK_SCAN_RESULTS = 2;
@@ -84,6 +86,7 @@
private NetworkOperatorPreference mSelectedNetworkOperatorPreference;
private TelephonyManager mTelephonyManager;
private NetworkOperators mNetworkOperators;
+ private List<String> mForbiddenPlmns;
private final Runnable mUpdateNetworkOperatorsRunnable = () -> {
updateNetworkOperatorsPreferenceCategory();
@@ -103,7 +106,7 @@
@Override
public void onCreate(Bundle icicle) {
- logd("onCreate");
+ if (DBG) logd("onCreate");
super.onCreate(icicle);
mPhoneId = getArguments().getInt(NetworkSelectSettingActivity.KEY_PHONE_ID);
@@ -123,7 +126,7 @@
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
- logd("onViewCreated");
+ if (DBG) logd("onViewCreated");
super.onViewCreated(view, savedInstanceState);
if (getListView() != null) {
@@ -154,9 +157,18 @@
public void onStart() {
if (DBG) logd("onStart");
super.onStart();
+ new AsyncTask<Void, Void, List<String>>() {
+ @Override
+ protected List<String> doInBackground(Void... voids) {
+ return Arrays.asList(mTelephonyManager.getForbiddenPlmns());
+ }
- // Bind the NetworkQueryService
- bindNetworkQueryService();
+ @Override
+ protected void onPostExecute(List<String> result) {
+ mForbiddenPlmns = result;
+ bindNetworkQueryService();
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
/**
@@ -382,8 +394,8 @@
configConnectedNetworkOperatorsPreferenceCategory();
for (int index = 0; index < mCellInfoList.size(); index++) {
if (!mCellInfoList.get(index).isRegistered()) {
- NetworkOperatorPreference pref =
- new NetworkOperatorPreference(mCellInfoList.get(index), getContext());
+ NetworkOperatorPreference pref = new NetworkOperatorPreference(
+ mCellInfoList.get(index), getContext(), mForbiddenPlmns);
pref.setKey(CellInfoUtil.getNetworkTitle(mCellInfoList.get(index)));
pref.setOrder(index);
mNetworkOperatorsPreferences.addPreference(pref);
@@ -422,7 +434,7 @@
if (cellInfo != null) {
if (DBG) logd("Currently registered cell: " + cellInfo.toString());
NetworkOperatorPreference pref =
- new NetworkOperatorPreference(cellInfo, getContext());
+ new NetworkOperatorPreference(cellInfo, getContext(), mForbiddenPlmns);
pref.setTitle(mTelephonyManager.getNetworkOperatorName());
pref.setSummary(R.string.network_connected);
// Update the signal strength icon, since the default signalStrength value would be
@@ -503,7 +515,7 @@
// Remove the current ConnectedNetworkOperatorsPreference
removeConnectedNetworkOperatorPreference();
final NetworkOperatorPreference pref =
- new NetworkOperatorPreference(cellInfo, getContext());
+ new NetworkOperatorPreference(cellInfo, getContext(), mForbiddenPlmns);
pref.setSummary(R.string.network_connected);
mConnectedNetworkOperatorsPreference.addPreference(pref);
PreferenceScreen preferenceScreen = getPreferenceScreen();