Handle invalid subIds in Enable2gPreferenceController.

Implements improved handling of invalid subIds in the
"Allow 2G" controller + unit tests.

Bug: 185264531
Test: m & atest -c Enable2gPreferenceControllerTest
Change-Id: I7587f1a2a8150bbc6cc0864c9a13d0d910a26682
This commit is contained in:
Yomna Nasser
2021-04-17 01:16:29 +00:00
parent 976c6ac56d
commit e43f26294d
2 changed files with 20 additions and 1 deletions

View File

@@ -72,7 +72,7 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
public int getAvailabilityStatus(int subId) {
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(subId);
boolean visible =
subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
SubscriptionManager.isUsableSubscriptionId(subId)
&& carrierConfig != null
&& !carrierConfig.getBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G)
&& mTelephonyManager.isRadioInterfaceCapabilitySupported(
@@ -89,6 +89,9 @@ public class Enable2gPreferenceController extends TelephonyTogglePreferenceContr
@Override
public boolean setChecked(boolean isChecked) {
if (!SubscriptionManager.isUsableSubscriptionId(mSubId)) {
return false;
}
long currentlyAllowedNetworkTypes = mTelephonyManager.getAllowedNetworkTypesForReason(
mTelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G);
boolean enabled = (currentlyAllowedNetworkTypes & BITMASK_2G) != 0;