Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf19e59d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "The Settings ANR when allowed network type never was loaded" into sc-dev am: 7dd50462

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/telephony/+/15372853

Change-Id: I5847a84f8a015cfc907609336b8c446b993f428e
parents 5b81ddfc 7dd50462
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -2315,7 +2315,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
     * Loads the allowed network type from subscription database.
     */
    public void loadAllowedNetworksFromSubscriptionDatabase() {
        mIsAllowedNetworkTypesLoadedFromDb = false;
        // Try to load ALLOWED_NETWORK_TYPES from SIMINFO.
        if (SubscriptionController.getInstance() == null) {
            return;
@@ -2324,6 +2323,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        String result = SubscriptionController.getInstance().getSubscriptionProperty(
                getSubId(),
                SubscriptionManager.ALLOWED_NETWORK_TYPES);
        // After fw load network type from DB, do unlock if subId is valid.
        mIsAllowedNetworkTypesLoadedFromDb = SubscriptionManager.isValidSubscriptionId(getSubId());
        if (result == null) {
            return;
        }
@@ -2355,7 +2356,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
                    }
                }
            }
            mIsAllowedNetworkTypesLoadedFromDb = true;
        } catch (NumberFormatException e) {
            Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e);
        }
@@ -2426,12 +2426,18 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        int subId = getSubId();
        if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
            loge("setAllowedNetworkTypes: Invalid allowed network type reason: " + reason);
            AsyncResult.forMessage(response, null,
                    new CommandException(CommandException.Error.INVALID_ARGUMENTS));
            response.sendToTarget();
            return;
        }
        if (!SubscriptionManager.isUsableSubscriptionId(subId)
                || !mIsAllowedNetworkTypesLoadedFromDb) {
            loge("setAllowedNetworkTypes: no sim or network type is not loaded. SubscriptionId: "
                    + subId + ", isNetworkTypeLoaded" + mIsAllowedNetworkTypesLoadedFromDb);
            AsyncResult.forMessage(response, null,
                    new CommandException(CommandException.Error.MISSING_RESOURCE));
            response.sendToTarget();
            return;
        }
        String mapAsString = "";
@@ -5037,4 +5043,16 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    private static String pii(String 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;
    }
}
+29 −0
Original line number Diff line number Diff line
@@ -1622,4 +1622,33 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        assertEquals(LinkCapacityEstimate.INVALID, lce3.getUplinkCapacityKbps());
        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());
    }
}