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

Commit 3e8eebd1 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ensure We Never Serialize Bad allowed_network_types_for_reason Keys Into Sim DB"

parents 92804a32 50fe189f
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -2446,7 +2446,7 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
                }
                int key = convertAllowedNetworkTypeDbNameToMapIndex(networkTypesValues[0]);
                long value = Long.parseLong(networkTypesValues[1]);
                if (key != INVALID_ALLOWED_NETWORK_TYPES
                if (TelephonyManager.isValidAllowedNetworkTypesReason(key)
                        && value != INVALID_ALLOWED_NETWORK_TYPES) {
                    synchronized (mAllowedNetworkTypesForReasons) {
                        mAllowedNetworkTypesForReasons.put(key, value);
@@ -2484,7 +2484,8 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        }
    }

    private String convertAllowedNetworkTypeMapIndexToDbName(int reason) {
    private String convertAllowedNetworkTypeMapIndexToDbName(
            @TelephonyManager.AllowedNetworkTypesReason int reason) {
        switch (reason) {
            case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER:
                return ALLOWED_NETWORK_TYPES_TEXT_USER;
@@ -2495,7 +2496,10 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
            case TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G:
                return ALLOWED_NETWORK_TYPES_TEXT_ENABLE_2G;
            default:
                return Integer.toString(INVALID_ALLOWED_NETWORK_TYPES);
                throw new IllegalArgumentException(
                        "No DB name conversion available for allowed network type reason: " + reason
                                + ". Did you forget to add an ALLOWED_NETWORK_TYPE_TEXT entry for"
                                + " a new reason?");
        }
    }

+69 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import android.telephony.CellIdentityCdma;
import android.telephony.CellIdentityGsm;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionInfo;
@@ -1565,6 +1566,74 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        assertEquals(false, mPhoneUT.isAllowedNetworkTypesLoadedFromDb());
    }

    @Test
    public void testLoadAllowedNetworksFromSubscriptionDatabase_allValidData() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());

        // 13 == TelephonyManager.NETWORK_TYPE_LTE
        // NR_BITMASK == 4096 == 1 << (13 - 1)
        String validSerializedNetworkMap = "user=4096,power=4096,carrier=4096,enable_2g=4096";
        doReturn(validSerializedNetworkMap).when(mSubscriptionController).getSubscriptionProperty(
                anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));

        assertFalse(mPhoneUT.isAllowedNetworkTypesLoadedFromDb());
        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();
        assertTrue(mPhoneUT.isAllowedNetworkTypesLoadedFromDb());

        for (int i = 0; i < 4; ++i) {
            assertEquals(TelephonyManager.NETWORK_TYPE_BITMASK_LTE,
                    mPhoneUT.getAllowedNetworkTypes(i));
        }
    }

    @Test
    public void testLoadAllowedNetworksFromSubscriptionDatabase_invalidKeys() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());

        // 13 == TelephonyManager.NETWORK_TYPE_LTE
        // NR_BITMASK == 4096 == 1 << (13 - 1)
        String validSerializedNetworkMap =
                "user=4096,power=4096,carrier=4096,enable_2g=4096,-1=4096";
        doReturn(validSerializedNetworkMap).when(mSubscriptionController).getSubscriptionProperty(
                anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));

        assertFalse(mPhoneUT.isAllowedNetworkTypesLoadedFromDb());
        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();
        assertTrue(mPhoneUT.isAllowedNetworkTypesLoadedFromDb());

        for (int i = 0; i < 4; ++i) {
            assertEquals(TelephonyManager.NETWORK_TYPE_BITMASK_LTE,
                    mPhoneUT.getAllowedNetworkTypes(i));
        }
    }

    @Test
    public void testLoadAllowedNetworksFromSubscriptionDatabase_invalidValues() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());

        // 19 == TelephonyManager.NETWORK_TYPE_NR
        // NR_BITMASK == 524288 == 1 << 19
        String validSerializedNetworkMap = "user=4096,power=4096,carrier=4096,enable_2g=-1";
        doReturn(validSerializedNetworkMap).when(mSubscriptionController).getSubscriptionProperty(
                anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));

        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();

        for (int i = 0; i < 3; ++i) {
            assertEquals(TelephonyManager.NETWORK_TYPE_BITMASK_LTE,
                    mPhoneUT.getAllowedNetworkTypes(i));
        }

        long defaultAllowedNetworkTypes = RadioAccessFamily.getRafFromNetworkType(
                RILConstants.PREFERRED_NETWORK_MODE);
        assertEquals(defaultAllowedNetworkTypes, mPhoneUT.getAllowedNetworkTypes(
                TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G));

    }

    /**
     * Verifies that an emergency call placed on a SIM which does NOT explicitly define a number as
     * an emergency call will still be placed as an emergency call.