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

Commit 6342c215 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...

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

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

Change-Id: I1724bf8be412796ec4c3d4d77d98bf48583800a6
parents 724bbea7 cf19e59d
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -2311,7 +2311,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;
@@ -2320,6 +2319,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;
        }
@@ -2351,7 +2352,6 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
                    }
                }
            }
            mIsAllowedNetworkTypesLoadedFromDb = true;
        } catch (NumberFormatException e) {
            Rlog.e(LOG_TAG, "allowedNetworkTypes NumberFormat exception" + e);
        }
@@ -2422,12 +2422,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 = "";
@@ -5033,4 +5039,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());
    }
}