Loading src/java/com/android/internal/telephony/Phone.java +20 −2 Original line number Original line Diff line number Diff line Loading @@ -2315,7 +2315,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { * Loads the allowed network type from subscription database. * Loads the allowed network type from subscription database. */ */ public void loadAllowedNetworksFromSubscriptionDatabase() { public void loadAllowedNetworksFromSubscriptionDatabase() { mIsAllowedNetworkTypesLoadedFromDb = false; // Try to load ALLOWED_NETWORK_TYPES from SIMINFO. // Try to load ALLOWED_NETWORK_TYPES from SIMINFO. if (SubscriptionController.getInstance() == null) { if (SubscriptionController.getInstance() == null) { return; return; Loading @@ -2324,6 +2323,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { String result = SubscriptionController.getInstance().getSubscriptionProperty( String result = SubscriptionController.getInstance().getSubscriptionProperty( getSubId(), getSubId(), SubscriptionManager.ALLOWED_NETWORK_TYPES); SubscriptionManager.ALLOWED_NETWORK_TYPES); // After fw load network type from DB, do unlock if subId is valid. mIsAllowedNetworkTypesLoadedFromDb = SubscriptionManager.isValidSubscriptionId(getSubId()); if (result == null) { if (result == null) { return; return; } } Loading Loading @@ -2355,7 +2356,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { } } } } } } mIsAllowedNetworkTypesLoadedFromDb = true; } catch (NumberFormatException e) { } catch (NumberFormatException e) { Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e); Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e); } } Loading Loading @@ -2426,12 +2426,18 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { int subId = getSubId(); int subId = getSubId(); if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { loge("setAllowedNetworkTypes: Invalid allowed network type reason: " + reason); loge("setAllowedNetworkTypes: Invalid allowed network type reason: " + reason); AsyncResult.forMessage(response, null, new CommandException(CommandException.Error.INVALID_ARGUMENTS)); response.sendToTarget(); return; return; } } if (!SubscriptionManager.isUsableSubscriptionId(subId) if (!SubscriptionManager.isUsableSubscriptionId(subId) || !mIsAllowedNetworkTypesLoadedFromDb) { || !mIsAllowedNetworkTypesLoadedFromDb) { loge("setAllowedNetworkTypes: no sim or network type is not loaded. SubscriptionId: " loge("setAllowedNetworkTypes: no sim or network type is not loaded. SubscriptionId: " + subId + ", isNetworkTypeLoaded" + mIsAllowedNetworkTypesLoadedFromDb); + subId + ", isNetworkTypeLoaded" + mIsAllowedNetworkTypesLoadedFromDb); AsyncResult.forMessage(response, null, new CommandException(CommandException.Error.MISSING_RESOURCE)); response.sendToTarget(); return; return; } } String mapAsString = ""; String mapAsString = ""; Loading Loading @@ -5037,4 +5043,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { private static String pii(String s) { private static String pii(String s) { return Rlog.pii(LOG_TAG, s); return Rlog.pii(LOG_TAG, s); } } /** * Used in unit tests to set whether the AllowedNetworkTypes is loaded from Db. Should not * be used otherwise. * * @return {@code true} if the AllowedNetworkTypes is loaded from Db, * {@code false} otherwise. */ @VisibleForTesting public boolean isAllowedNetworkTypesLoadedFromDb() { return mIsAllowedNetworkTypesLoadedFromDb; } } } tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java +29 −0 Original line number Original line Diff line number Diff line Loading @@ -1622,4 +1622,33 @@ public class GsmCdmaPhoneTest extends TelephonyTest { assertEquals(LinkCapacityEstimate.INVALID, lce3.getUplinkCapacityKbps()); assertEquals(LinkCapacityEstimate.INVALID, lce3.getUplinkCapacityKbps()); assertEquals(LinkCapacityEstimate.LCE_TYPE_COMBINED, lce3.getType()); assertEquals(LinkCapacityEstimate.LCE_TYPE_COMBINED, lce3.getType()); } } @Test @SmallTest public void testLoadAllowedNetworksFromSubscriptionDatabase_loadTheNullValue_isLoadedTrue() { int subId = 1; doReturn(subId).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); doReturn(null).when(mSubscriptionController).getSubscriptionProperty(anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES)); mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase(); assertEquals(true, mPhoneUT.isAllowedNetworkTypesLoadedFromDb()); } @Test @SmallTest public void testLoadAllowedNetworksFromSubscriptionDatabase_subIdNotValid_isLoadedFalse() { int subId = -1; doReturn(subId).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); when(mSubscriptionController.getSubscriptionProperty(anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES))).thenReturn(null); mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase(); assertEquals(false, mPhoneUT.isAllowedNetworkTypesLoadedFromDb()); } } } Loading
src/java/com/android/internal/telephony/Phone.java +20 −2 Original line number Original line Diff line number Diff line Loading @@ -2315,7 +2315,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { * Loads the allowed network type from subscription database. * Loads the allowed network type from subscription database. */ */ public void loadAllowedNetworksFromSubscriptionDatabase() { public void loadAllowedNetworksFromSubscriptionDatabase() { mIsAllowedNetworkTypesLoadedFromDb = false; // Try to load ALLOWED_NETWORK_TYPES from SIMINFO. // Try to load ALLOWED_NETWORK_TYPES from SIMINFO. if (SubscriptionController.getInstance() == null) { if (SubscriptionController.getInstance() == null) { return; return; Loading @@ -2324,6 +2323,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { String result = SubscriptionController.getInstance().getSubscriptionProperty( String result = SubscriptionController.getInstance().getSubscriptionProperty( getSubId(), getSubId(), SubscriptionManager.ALLOWED_NETWORK_TYPES); SubscriptionManager.ALLOWED_NETWORK_TYPES); // After fw load network type from DB, do unlock if subId is valid. mIsAllowedNetworkTypesLoadedFromDb = SubscriptionManager.isValidSubscriptionId(getSubId()); if (result == null) { if (result == null) { return; return; } } Loading Loading @@ -2355,7 +2356,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { } } } } } } mIsAllowedNetworkTypesLoadedFromDb = true; } catch (NumberFormatException e) { } catch (NumberFormatException e) { Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e); Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e); } } Loading Loading @@ -2426,12 +2426,18 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { int subId = getSubId(); int subId = getSubId(); if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { loge("setAllowedNetworkTypes: Invalid allowed network type reason: " + reason); loge("setAllowedNetworkTypes: Invalid allowed network type reason: " + reason); AsyncResult.forMessage(response, null, new CommandException(CommandException.Error.INVALID_ARGUMENTS)); response.sendToTarget(); return; return; } } if (!SubscriptionManager.isUsableSubscriptionId(subId) if (!SubscriptionManager.isUsableSubscriptionId(subId) || !mIsAllowedNetworkTypesLoadedFromDb) { || !mIsAllowedNetworkTypesLoadedFromDb) { loge("setAllowedNetworkTypes: no sim or network type is not loaded. SubscriptionId: " loge("setAllowedNetworkTypes: no sim or network type is not loaded. SubscriptionId: " + subId + ", isNetworkTypeLoaded" + mIsAllowedNetworkTypesLoadedFromDb); + subId + ", isNetworkTypeLoaded" + mIsAllowedNetworkTypesLoadedFromDb); AsyncResult.forMessage(response, null, new CommandException(CommandException.Error.MISSING_RESOURCE)); response.sendToTarget(); return; return; } } String mapAsString = ""; String mapAsString = ""; Loading Loading @@ -5037,4 +5043,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface { private static String pii(String s) { private static String pii(String s) { return Rlog.pii(LOG_TAG, s); return Rlog.pii(LOG_TAG, s); } } /** * Used in unit tests to set whether the AllowedNetworkTypes is loaded from Db. Should not * be used otherwise. * * @return {@code true} if the AllowedNetworkTypes is loaded from Db, * {@code false} otherwise. */ @VisibleForTesting public boolean isAllowedNetworkTypesLoadedFromDb() { return mIsAllowedNetworkTypesLoadedFromDb; } } }
tests/telephonytests/src/com/android/internal/telephony/GsmCdmaPhoneTest.java +29 −0 Original line number Original line Diff line number Diff line Loading @@ -1622,4 +1622,33 @@ public class GsmCdmaPhoneTest extends TelephonyTest { assertEquals(LinkCapacityEstimate.INVALID, lce3.getUplinkCapacityKbps()); assertEquals(LinkCapacityEstimate.INVALID, lce3.getUplinkCapacityKbps()); assertEquals(LinkCapacityEstimate.LCE_TYPE_COMBINED, lce3.getType()); assertEquals(LinkCapacityEstimate.LCE_TYPE_COMBINED, lce3.getType()); } } @Test @SmallTest public void testLoadAllowedNetworksFromSubscriptionDatabase_loadTheNullValue_isLoadedTrue() { int subId = 1; doReturn(subId).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); doReturn(null).when(mSubscriptionController).getSubscriptionProperty(anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES)); mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase(); assertEquals(true, mPhoneUT.isAllowedNetworkTypesLoadedFromDb()); } @Test @SmallTest public void testLoadAllowedNetworksFromSubscriptionDatabase_subIdNotValid_isLoadedFalse() { int subId = -1; doReturn(subId).when(mSubscriptionController).getSubIdUsingPhoneId(anyInt()); when(mSubscriptionController.getSubscriptionProperty(anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES))).thenReturn(null); mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase(); assertEquals(false, mPhoneUT.isAllowedNetworkTypesLoadedFromDb()); } } }