Update "Allow 2G" toggle summary wording.

Update "Allow 2G" toggle summary wording to be more clear regarding
the purpose of the toggle and why it may be disabled.

Bug: b/193693810
Bug: b/196183458
Test: manual & atest -c Enable2gPreferenceControllerTest
Change-Id: Iffef8f4f44105de30392c30ffd44c1d62cd066b8
This commit is contained in:
Yomna Nasser
2021-12-15 04:09:58 +00:00
parent c0572ddaa7
commit 91036f8945
3 changed files with 43 additions and 4 deletions

View File

@@ -13642,7 +13642,10 @@
<!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=40] --> <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=40] -->
<string name="enable_2g_title">Allow 2G</string> <string name="enable_2g_title">Allow 2G</string>
<!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] --> <!-- Title for toggle if user wants to enable 2G [CHAR LIMIT=NONE] -->
<string name="enable_2g_summary">Use 2G cellular connections. For emergency calls, 2G is always turned on.</string> <string name="enable_2g_summary">2G is less secure, but may improve your connection in some locations. For emergency calls, 2G is always allowed.</string>
<!-- Title for if toggle access is disabled by carrier [CHAR LIMIT=NONE] -->
<string name="enable_2g_summary_disabled_carrier"><xliff:g id="carrier_name_2g" example="Google Fi">%1$s</xliff:g> requires 2G to be available</string>
<!-- Label for extra app info settings for a specific app [CHAR LIMIT=40] --> <!-- Label for extra app info settings for a specific app [CHAR LIMIT=40] -->
<string name="extra_app_info_label" translatable="false"></string> <string name="extra_app_info_label" translatable="false"></string>

View File

@@ -19,10 +19,15 @@ import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.network.SubscriptionUtil;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -41,6 +46,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
private final MetricsFeatureProvider mMetricsFeatureProvider; private final MetricsFeatureProvider mMetricsFeatureProvider;
private CarrierConfigManager mCarrierConfigManager; private CarrierConfigManager mCarrierConfigManager;
private SubscriptionManager mSubscriptionManager;
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
/** /**
@@ -53,6 +59,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
super(context, key); super(context, key);
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class); mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
} }
/** /**
@@ -68,6 +75,36 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
return this; return this;
} }
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (preference == null || !SubscriptionManager.isUsableSubscriptionId(mSubId)) {
return;
}
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
boolean isDisabledByCarrier =
carrierConfig != null
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G);
preference.setEnabled(!isDisabledByCarrier);
String summary;
if (isDisabledByCarrier) {
summary = mContext.getString(R.string.enable_2g_summary_disabled_carrier,
getCarrierName());
} else {
summary = mContext.getString(R.string.enable_2g_summary);
}
preference.setSummary(summary);
}
private String getCarrierName() {
SubscriptionInfo subInfo = SubscriptionUtil.getSubById(mSubscriptionManager, mSubId);
if (subInfo == null) {
return "";
}
final String carrierName = subInfo.getCarrierName().toString();
return carrierName;
}
@Override @Override
public int getAvailabilityStatus(int subId) { public int getAvailabilityStatus(int subId) {
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId); final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
@@ -78,7 +115,6 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
boolean visible = boolean visible =
SubscriptionManager.isUsableSubscriptionId(subId) SubscriptionManager.isUsableSubscriptionId(subId)
&& carrierConfig != null && carrierConfig != null
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G)
&& mTelephonyManager.isRadioInterfaceCapabilitySupported( && mTelephonyManager.isRadioInterfaceCapabilitySupported(
mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK); mTelephonyManager.CAPABILITY_USES_ALLOWED_NETWORK_TYPES_BITMASK);
return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; return visible ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;

View File

@@ -45,12 +45,12 @@ import org.mockito.MockitoAnnotations;
public final class Enable2gPreferenceControllerTest { public final class Enable2gPreferenceControllerTest {
private static final int SUB_ID = 2; private static final int SUB_ID = 2;
@Mock
private CarrierConfigManager mCarrierConfigManager;
@Mock @Mock
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
@Mock @Mock
private TelephonyManager mInvalidTelephonyManager; private TelephonyManager mInvalidTelephonyManager;
@Mock
private CarrierConfigManager mCarrierConfigManager;
private PersistableBundle mPersistableBundle; private PersistableBundle mPersistableBundle;
private Enable2gPreferenceController mController; private Enable2gPreferenceController mController;