Update network select page
1. use getPrefContext() to make sure it has correct style
2. Move operation back to bg thread so it won't block UI
Bug: 114749736
Test: RunSettingsRoboTests
Change-Id: I7737ea8b21d44790617b9c4f13a8c4c41037fca4
diff --git a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
index ad0285f..fd57bf5 100644
--- a/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
+++ b/src/com/android/settings/network/telephony/NetworkOperatorPreference.java
@@ -116,14 +116,9 @@
private void updateIcon(int level) {
if (level < 0 || level >= NUMBER_OF_LEVELS) return;
Context context = getContext();
- // Make the signal strength drawable
- int iconId = 0;
- if (DBG) Log.d(TAG, "updateIcon level: " + String.valueOf(level));
- iconId = SignalDrawable.getState(level, NUMBER_OF_LEVELS, false /* cutOut */);
-
SignalDrawable signalDrawable = new SignalDrawable(getContext());
- signalDrawable.setLevel(iconId);
- signalDrawable.setDarkIntensity(0);
+ signalDrawable.setLevel(
+ SignalDrawable.getState(level, NUMBER_OF_LEVELS, false /* cutOut */));
// Make the network type drawable
int iconType = getIconIdForCell(mCellInfo);
@@ -134,7 +129,7 @@
.getResources().getDrawable(iconType, getContext().getTheme());
// Overlay the two drawables
- Drawable[] layers = {networkDrawable, signalDrawable};
+ final Drawable[] layers = {networkDrawable, signalDrawable};
final int iconSize =
context.getResources().getDimensionPixelSize(R.dimen.signal_strength_icon_size);
diff --git a/src/com/android/settings/network/telephony/NetworkSelectSettings.java b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
index 3e42c70..2e8e34f 100644
--- a/src/com/android/settings/network/telephony/NetworkSelectSettings.java
+++ b/src/com/android/settings/network/telephony/NetworkSelectSettings.java
@@ -43,6 +43,7 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
+import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Arrays;
@@ -59,6 +60,7 @@
private static final String TAG = "NetworkSelectSettings";
+ 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;
@@ -134,13 +136,10 @@
mForbiddenPlmns = Arrays.asList(mTelephonyManager.getForbiddenPlmns());
setProgressBarVisible(true);
- if (mUseNewApi) {
- mNetworkScanHelper.startNetworkScan(
- NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS);
- } else {
- mNetworkScanHelper.startNetworkScan(
- NetworkScanHelper.NETWORK_SCAN_TYPE_WAIT_FOR_ALL_RESULTS);
- }
+ mNetworkScanHelper.startNetworkScan(
+ mUseNewApi
+ ? NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS
+ : NetworkScanHelper.NETWORK_SCAN_TYPE_WAIT_FOR_ALL_RESULTS);
}
@Override
@@ -153,7 +152,6 @@
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);
@@ -161,6 +159,7 @@
mSelectedPreference = (NetworkOperatorPreference) preference;
CellInfo cellInfo = mSelectedPreference.getCellInfo();
+ mSelectedPreference.setSummary(R.string.network_connecting);
mMetricsFeatureProvider.action(getContext(),
MetricsEvent.ACTION_MOBILE_NETWORK_MANUAL_SELECT_NETWORK);
@@ -175,11 +174,17 @@
}
}
+ setProgressBarVisible(true);
+ // Disable the screen until network is manually set
+ getPreferenceScreen().setEnabled(false);
+
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);
+ ThreadUtils.postOnBackgroundThread(() -> {
+ Message msg = mHandler.obtainMessage(EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE);
+ msg.obj = mTelephonyManager.setNetworkSelectionModeManual(
+ operatorInfo, true /* persistSelection */);
+ msg.sendToTarget();
+ });
}
return true;
@@ -204,6 +209,15 @@
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
+ case EVENT_SET_NETWORK_SELECTION_MANUALLY_DONE:
+ setProgressBarVisible(false);
+ getPreferenceScreen().setEnabled(true);
+
+ boolean isSucceed = (boolean) msg.obj;
+ mSelectedPreference.setSummary(isSucceed
+ ? R.string.network_connected
+ : R.string.network_could_not_connect);
+ break;
case EVENT_NETWORK_SCAN_RESULTS:
List<CellInfo> results = aggregateCellInfoList((List<CellInfo>) msg.obj);
mCellInfoList = new ArrayList<>(results);
@@ -267,7 +281,7 @@
for (int index = 0; index < mCellInfoList.size(); index++) {
if (!mCellInfoList.get(index).isRegistered()) {
NetworkOperatorPreference pref = new NetworkOperatorPreference(
- mCellInfoList.get(index), getContext(), mForbiddenPlmns, mShow4GForLTE);
+ mCellInfoList.get(index), getPrefContext(), mForbiddenPlmns, mShow4GForLTE);
pref.setKey(CellInfoUtil.getNetworkTitle(mCellInfoList.get(index)));
pref.setOrder(index);
mPreferenceCategory.addPreference(pref);
@@ -303,7 +317,7 @@
CellInfo cellInfo = CellInfoUtil.wrapCellInfoWithCellIdentity(cellIdentity);
if (cellInfo != null) {
NetworkOperatorPreference pref = new NetworkOperatorPreference(
- cellInfo, getContext(), mForbiddenPlmns, mShow4GForLTE);
+ cellInfo, getPrefContext(), mForbiddenPlmns, mShow4GForLTE);
pref.setTitle(mTelephonyManager.getNetworkOperatorName());
pref.setSummary(R.string.network_connected);
// Update the signal strength icon, since the default signalStrength value would be
@@ -342,7 +356,7 @@
private void addConnectedNetworkOperatorPreference(CellInfo cellInfo) {
mConnectedPreferenceCategory.removeAll();
final NetworkOperatorPreference pref = new NetworkOperatorPreference(
- cellInfo, getContext(), mForbiddenPlmns, mShow4GForLTE);
+ cellInfo, getPrefContext(), mForbiddenPlmns, mShow4GForLTE);
pref.setSummary(R.string.network_connected);
mConnectedPreferenceCategory.addPreference(pref);
mConnectedPreferenceCategory.setVisible(true);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java b/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
index 3ebeba1..956b601 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java
@@ -81,6 +81,9 @@
mNetworkSelectSettings = spy(new NetworkSelectSettings());
doReturn(mContext).when(mNetworkSelectSettings).getContext();
+ doReturn(mPreferenceManager).when(mNetworkSelectSettings).getPreferenceManager();
+ doReturn(mContext).when(mPreferenceManager).getContext();
+
mNetworkSelectSettings.mTelephonyManager = mTelephonyManager;
mNetworkSelectSettings.mConnectedPreferenceCategory = mConnectedPreferenceCategory;
mNetworkSelectSettings.mPreferenceCategory = mPreferenceCategory;